@pluv/io 3.1.1 → 3.1.2
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/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +8 -0
- package/README.md +11 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -11
- package/dist/index.mjs +20 -11
- package/package.json +5 -5
- package/src/PluvIO.ts +21 -14
- package/src/PluvServer.ts +11 -5
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@3.1.
|
|
2
|
+
> @pluv/io@3.1.2 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> pnpm run version && tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @pluv/io@3.1.
|
|
6
|
+
> @pluv/io@3.1.2 version /home/runner/work/pluv/pluv/packages/io
|
|
7
7
|
> genversion ./src/version.generated.ts --esm
|
|
8
8
|
|
|
9
9
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
[34mCLI[39m Target: es6
|
|
13
13
|
[34mESM[39m Build start
|
|
14
14
|
[34mCJS[39m Build start
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m52.
|
|
16
|
-
[32mESM[39m ⚡️ Build success in
|
|
17
|
-
[32mCJS[39m [1mdist/index.js [22m[32m54.
|
|
18
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m52.78 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 109ms
|
|
17
|
+
[32mCJS[39m [1mdist/index.js [22m[32m54.96 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 109ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m33.
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m33.
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4267ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m33.98 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m33.98 KB[39m
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -38,9 +38,19 @@ Create your pluv.io backend
|
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
40
|
// backend
|
|
41
|
-
const io = createIO(
|
|
41
|
+
const io = createIO(
|
|
42
|
+
platformNode({
|
|
43
|
+
context: () => ({ db }),
|
|
44
|
+
crdt: yjs,
|
|
45
|
+
})
|
|
46
|
+
);
|
|
42
47
|
|
|
43
48
|
export const ioServer = io.server({
|
|
49
|
+
getInitialStorage: async ({ context: { db }, room }) => {
|
|
50
|
+
return await db.room
|
|
51
|
+
.findUnique({ where: { id: room } })
|
|
52
|
+
.then((result) => result?.encodedState ?? null);
|
|
53
|
+
},
|
|
44
54
|
router: io.router({
|
|
45
55
|
sendGreeting: io.procedure
|
|
46
56
|
.input(z.object({ message: z.string() }))
|
package/dist/index.d.mts
CHANGED
|
@@ -477,6 +477,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = Abstract
|
|
|
477
477
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>);
|
|
478
478
|
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
479
479
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
480
|
+
private _getInitialStorage;
|
|
480
481
|
private _getListeners;
|
|
481
482
|
private _logDebug;
|
|
482
483
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -477,6 +477,7 @@ declare class PluvServer<TPlatform extends AbstractPlatform<any, any> = Abstract
|
|
|
477
477
|
constructor(options: PluvServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>);
|
|
478
478
|
createRoom(room: string, ...options: CreateRoomOptions<TPlatform, TAuthorize, TContext, TEvents>): IORoom<TPlatform, TAuthorize, TContext, TCrdt, TEvents>;
|
|
479
479
|
createToken(params: JWTEncodeParams<InferIOAuthorizeUser<InferIOAuthorize<this>>, TPlatform>): Promise<string>;
|
|
480
|
+
private _getInitialStorage;
|
|
480
481
|
private _getListeners;
|
|
481
482
|
private _logDebug;
|
|
482
483
|
}
|
package/dist/index.js
CHANGED
|
@@ -1170,12 +1170,17 @@ var IORoom = class {
|
|
|
1170
1170
|
};
|
|
1171
1171
|
|
|
1172
1172
|
// src/version.generated.ts
|
|
1173
|
-
var version = "3.1.
|
|
1173
|
+
var version = "3.1.2";
|
|
1174
1174
|
|
|
1175
1175
|
// src/PluvServer.ts
|
|
1176
1176
|
var PluvServer = class {
|
|
1177
1177
|
constructor(options) {
|
|
1178
1178
|
this.version = version;
|
|
1179
|
+
this._getInitialStorage = (...args) => {
|
|
1180
|
+
var _a;
|
|
1181
|
+
const getInitialStorage = typeof this._config.getInitialStorage !== "string" ? (_a = this._config.getInitialStorage) != null ? _a : () => null : () => null;
|
|
1182
|
+
return getInitialStorage(...args);
|
|
1183
|
+
};
|
|
1179
1184
|
this._config = __spreadValues({
|
|
1180
1185
|
crdt: import_crdt2.noop,
|
|
1181
1186
|
debug: false,
|
|
@@ -1261,8 +1266,7 @@ var PluvServer = class {
|
|
|
1261
1266
|
const oldState = yield platform.persistence.getStorageState(room);
|
|
1262
1267
|
const update = data == null ? void 0 : data.update;
|
|
1263
1268
|
if (!oldState) {
|
|
1264
|
-
const
|
|
1265
|
-
const loadedState = yield getInitialStorage({ context, room });
|
|
1269
|
+
const loadedState = yield this._getInitialStorage({ context, room });
|
|
1266
1270
|
if (!!loadedState) {
|
|
1267
1271
|
doc.applyEncodedState({ update: loadedState }).getEncodedState();
|
|
1268
1272
|
}
|
|
@@ -1462,15 +1466,17 @@ var PluvIO = class {
|
|
|
1462
1466
|
const user = params.user;
|
|
1463
1467
|
const parsed = !!ioAuthorize ? ioAuthorize.user.parse(user) : user;
|
|
1464
1468
|
if (!!this._limits.userIdMaxLength && user.id.length > this._limits.userIdMaxLength) {
|
|
1465
|
-
throw new Error(
|
|
1466
|
-
|
|
1467
|
-
|
|
1469
|
+
throw new Error(oneLine`
|
|
1470
|
+
createToken was called with a long user id. User ID must be at
|
|
1471
|
+
most 128 characters. Current length: ${user.id.length.toLocaleString()}
|
|
1472
|
+
`);
|
|
1468
1473
|
}
|
|
1469
1474
|
const bytes = new TextEncoder().encode(JSON.stringify(parsed)).length;
|
|
1470
1475
|
if (!!this._limits.userMaxSize && bytes > this._limits.userMaxSize) {
|
|
1471
|
-
throw new Error(
|
|
1472
|
-
|
|
1473
|
-
|
|
1476
|
+
throw new Error(oneLine`
|
|
1477
|
+
createToken called with large payload. User must be at most 512
|
|
1478
|
+
bytes. Current size: ${bytes.toLocaleString()}
|
|
1479
|
+
`);
|
|
1474
1480
|
}
|
|
1475
1481
|
const platform = this._platform();
|
|
1476
1482
|
if (platform._createToken) {
|
|
@@ -1489,13 +1495,16 @@ var PluvIO = class {
|
|
|
1489
1495
|
router(events) {
|
|
1490
1496
|
const invalidName = Object.keys(events).find((name) => name.includes("$"));
|
|
1491
1497
|
if (typeof invalidName === "string") {
|
|
1492
|
-
throw new Error(`
|
|
1498
|
+
throw new Error(oneLine`
|
|
1499
|
+
Invalid event name. Event names must not contain $: "${invalidName}"
|
|
1500
|
+
`);
|
|
1493
1501
|
}
|
|
1494
1502
|
return new PluvRouter(events);
|
|
1495
1503
|
}
|
|
1496
1504
|
server(...config) {
|
|
1497
1505
|
var _a, _b;
|
|
1498
|
-
|
|
1506
|
+
const serverConfig = (_a = config[0]) != null ? _a : {};
|
|
1507
|
+
return new PluvServer(__spreadProps(__spreadValues({}, serverConfig), {
|
|
1499
1508
|
authorize: (_b = this._authorize) != null ? _b : void 0,
|
|
1500
1509
|
context: this._context,
|
|
1501
1510
|
crdt: this._crdt,
|
package/dist/index.mjs
CHANGED
|
@@ -1128,12 +1128,17 @@ var IORoom = class {
|
|
|
1128
1128
|
};
|
|
1129
1129
|
|
|
1130
1130
|
// src/version.generated.ts
|
|
1131
|
-
var version = "3.1.
|
|
1131
|
+
var version = "3.1.2";
|
|
1132
1132
|
|
|
1133
1133
|
// src/PluvServer.ts
|
|
1134
1134
|
var PluvServer = class {
|
|
1135
1135
|
constructor(options) {
|
|
1136
1136
|
this.version = version;
|
|
1137
|
+
this._getInitialStorage = (...args) => {
|
|
1138
|
+
var _a;
|
|
1139
|
+
const getInitialStorage = typeof this._config.getInitialStorage !== "string" ? (_a = this._config.getInitialStorage) != null ? _a : () => null : () => null;
|
|
1140
|
+
return getInitialStorage(...args);
|
|
1141
|
+
};
|
|
1137
1142
|
this._config = __spreadValues({
|
|
1138
1143
|
crdt: noop2,
|
|
1139
1144
|
debug: false,
|
|
@@ -1219,8 +1224,7 @@ var PluvServer = class {
|
|
|
1219
1224
|
const oldState = yield platform.persistence.getStorageState(room);
|
|
1220
1225
|
const update = data == null ? void 0 : data.update;
|
|
1221
1226
|
if (!oldState) {
|
|
1222
|
-
const
|
|
1223
|
-
const loadedState = yield getInitialStorage({ context, room });
|
|
1227
|
+
const loadedState = yield this._getInitialStorage({ context, room });
|
|
1224
1228
|
if (!!loadedState) {
|
|
1225
1229
|
doc.applyEncodedState({ update: loadedState }).getEncodedState();
|
|
1226
1230
|
}
|
|
@@ -1420,15 +1424,17 @@ var PluvIO = class {
|
|
|
1420
1424
|
const user = params.user;
|
|
1421
1425
|
const parsed = !!ioAuthorize ? ioAuthorize.user.parse(user) : user;
|
|
1422
1426
|
if (!!this._limits.userIdMaxLength && user.id.length > this._limits.userIdMaxLength) {
|
|
1423
|
-
throw new Error(
|
|
1424
|
-
|
|
1425
|
-
|
|
1427
|
+
throw new Error(oneLine`
|
|
1428
|
+
createToken was called with a long user id. User ID must be at
|
|
1429
|
+
most 128 characters. Current length: ${user.id.length.toLocaleString()}
|
|
1430
|
+
`);
|
|
1426
1431
|
}
|
|
1427
1432
|
const bytes = new TextEncoder().encode(JSON.stringify(parsed)).length;
|
|
1428
1433
|
if (!!this._limits.userMaxSize && bytes > this._limits.userMaxSize) {
|
|
1429
|
-
throw new Error(
|
|
1430
|
-
|
|
1431
|
-
|
|
1434
|
+
throw new Error(oneLine`
|
|
1435
|
+
createToken called with large payload. User must be at most 512
|
|
1436
|
+
bytes. Current size: ${bytes.toLocaleString()}
|
|
1437
|
+
`);
|
|
1432
1438
|
}
|
|
1433
1439
|
const platform = this._platform();
|
|
1434
1440
|
if (platform._createToken) {
|
|
@@ -1447,13 +1453,16 @@ var PluvIO = class {
|
|
|
1447
1453
|
router(events) {
|
|
1448
1454
|
const invalidName = Object.keys(events).find((name) => name.includes("$"));
|
|
1449
1455
|
if (typeof invalidName === "string") {
|
|
1450
|
-
throw new Error(`
|
|
1456
|
+
throw new Error(oneLine`
|
|
1457
|
+
Invalid event name. Event names must not contain $: "${invalidName}"
|
|
1458
|
+
`);
|
|
1451
1459
|
}
|
|
1452
1460
|
return new PluvRouter(events);
|
|
1453
1461
|
}
|
|
1454
1462
|
server(...config) {
|
|
1455
1463
|
var _a, _b;
|
|
1456
|
-
|
|
1464
|
+
const serverConfig = (_a = config[0]) != null ? _a : {};
|
|
1465
|
+
return new PluvServer(__spreadProps(__spreadValues({}, serverConfig), {
|
|
1457
1466
|
authorize: (_b = this._authorize) != null ? _b : void 0,
|
|
1458
1467
|
context: this._context,
|
|
1459
1468
|
crdt: this._crdt,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"jose": "^5.10.0",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.5",
|
|
24
|
-
"@pluv/crdt": "^3.1.
|
|
25
|
-
"@pluv/types": "^3.1.
|
|
24
|
+
"@pluv/crdt": "^3.1.2",
|
|
25
|
+
"@pluv/types": "^3.1.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^9.27.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
31
|
"typescript": "^5.8.3",
|
|
32
|
-
"@pluv/tsconfig": "^3.1.
|
|
33
|
-
"eslint-config-pluv": "^3.1.
|
|
32
|
+
"@pluv/tsconfig": "^3.1.2",
|
|
33
|
+
"eslint-config-pluv": "^3.1.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/PluvIO.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
PluvIORouter,
|
|
25
25
|
ResolvedPluvIOAuthorize,
|
|
26
26
|
} from "./types";
|
|
27
|
+
import { oneLine } from "./utils";
|
|
27
28
|
import { __PLUV_VERSION } from "./version";
|
|
28
29
|
|
|
29
30
|
export type PluvIOConfig<
|
|
@@ -151,17 +152,19 @@ export class PluvIO<
|
|
|
151
152
|
const parsed = !!ioAuthorize ? ioAuthorize.user.parse(user) : user;
|
|
152
153
|
|
|
153
154
|
if (!!this._limits.userIdMaxLength && user.id.length > this._limits.userIdMaxLength) {
|
|
154
|
-
throw new Error(
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
throw new Error(oneLine`
|
|
156
|
+
createToken was called with a long user id. User ID must be at
|
|
157
|
+
most 128 characters. Current length: ${user.id.length.toLocaleString()}
|
|
158
|
+
`);
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
const bytes = new TextEncoder().encode(JSON.stringify(parsed)).length;
|
|
160
162
|
|
|
161
163
|
if (!!this._limits.userMaxSize && bytes > this._limits.userMaxSize) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
throw new Error(oneLine`
|
|
165
|
+
createToken called with large payload. User must be at most 512
|
|
166
|
+
bytes. Current size: ${bytes.toLocaleString()}
|
|
167
|
+
`);
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
const platform = this._platform();
|
|
@@ -197,7 +200,9 @@ export class PluvIO<
|
|
|
197
200
|
const invalidName = Object.keys(events).find((name) => name.includes("$"));
|
|
198
201
|
|
|
199
202
|
if (typeof invalidName === "string") {
|
|
200
|
-
throw new Error(`
|
|
203
|
+
throw new Error(oneLine`
|
|
204
|
+
Invalid event name. Event names must not contain $: "${invalidName}"
|
|
205
|
+
`);
|
|
201
206
|
}
|
|
202
207
|
|
|
203
208
|
return new PluvRouter<TPlatform, TAuthorize, TContext, TEvents>(events);
|
|
@@ -206,14 +211,16 @@ export class PluvIO<
|
|
|
206
211
|
public server<TEvents extends PluvRouterEventConfig<TPlatform, TAuthorize, TContext> = {}>(
|
|
207
212
|
...config: ServerConfig<TPlatform, TAuthorize, TContext, TCrdt, TEvents>
|
|
208
213
|
): PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents> {
|
|
214
|
+
const serverConfig = (config[0] ?? {}) as PluvServerConfig<
|
|
215
|
+
TPlatform,
|
|
216
|
+
TAuthorize,
|
|
217
|
+
TContext,
|
|
218
|
+
TCrdt,
|
|
219
|
+
TEvents
|
|
220
|
+
>;
|
|
221
|
+
|
|
209
222
|
return new PluvServer<TPlatform, TAuthorize, TContext, TCrdt, TEvents>({
|
|
210
|
-
...
|
|
211
|
-
TPlatform,
|
|
212
|
-
TAuthorize,
|
|
213
|
-
TContext,
|
|
214
|
-
TCrdt,
|
|
215
|
-
TEvents
|
|
216
|
-
>),
|
|
223
|
+
...serverConfig,
|
|
217
224
|
authorize: this._authorize ?? undefined,
|
|
218
225
|
context: this._context,
|
|
219
226
|
crdt: this._crdt,
|
package/src/PluvServer.ts
CHANGED
|
@@ -209,11 +209,7 @@ export class PluvServer<
|
|
|
209
209
|
const update = (data as any)?.update as Maybe<string>;
|
|
210
210
|
|
|
211
211
|
if (!oldState) {
|
|
212
|
-
const
|
|
213
|
-
typeof this._config.getInitialStorage === "function"
|
|
214
|
-
? this._config.getInitialStorage
|
|
215
|
-
: () => null;
|
|
216
|
-
const loadedState = await getInitialStorage({ context, room });
|
|
212
|
+
const loadedState = await this._getInitialStorage({ context, room });
|
|
217
213
|
|
|
218
214
|
if (!!loadedState) {
|
|
219
215
|
doc.applyEncodedState({ update: loadedState }).getEncodedState();
|
|
@@ -463,6 +459,16 @@ export class PluvServer<
|
|
|
463
459
|
return await this._config.io.createToken(params);
|
|
464
460
|
}
|
|
465
461
|
|
|
462
|
+
private _getInitialStorage: GetInitialStorageFn<TContext> = (...args) => {
|
|
463
|
+
const getInitialStorage =
|
|
464
|
+
typeof this._config.getInitialStorage !== "string"
|
|
465
|
+
? (this._config.getInitialStorage ??
|
|
466
|
+
((() => null) as GetInitialStorageFn<TContext>))
|
|
467
|
+
: ((() => null) as GetInitialStorageFn<TContext>);
|
|
468
|
+
|
|
469
|
+
return getInitialStorage(...args);
|
|
470
|
+
};
|
|
471
|
+
|
|
466
472
|
private _getListeners(): BasePluvIOListeners<TPlatform, TAuthorize, TContext, TEvents> {
|
|
467
473
|
return (this as any)._listeners;
|
|
468
474
|
}
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '3.1.
|
|
2
|
+
export const version = '3.1.2'
|