@logux/server 0.14.0 → 0.15.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright 2016 Andrey Sitnik <andrey@sitnik.ru>
3
+ Copyright 2016 Andrey Sitnik <andrey@sitnik.es>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Logux Server [![Cult Of Martians][cult-img]][cult]
1
+ # Logux Server
2
2
 
3
3
  <img align="right" width="95" height="148" title="Logux logotype"
4
4
  src="https://logux.org/branding/logotype.svg">
@@ -7,25 +7,22 @@ Logux is a new way to connect client and server. Instead of sending
7
7
  HTTP requests (e.g., AJAX and GraphQL) it synchronizes log of operations
8
8
  between client, server, and other clients.
9
9
 
10
- * **[Guide, recipes, and API](https://logux.org/)**
11
- * **[Issues](https://github.com/logux/logux/issues)**
10
+ - **[Guide, recipes, and API](https://logux.org/)**
11
+ - **[Issues](https://github.com/logux/logux/issues)**
12
12
  and **[roadmap](https://github.com/orgs/logux/projects/1)**
13
- * **[Projects](https://logux.org/guide/architecture/parts/)**
13
+ - **[Projects](https://logux.org/guide/architecture/parts/)**
14
14
  inside Logux ecosystem
15
15
 
16
16
  This repository contains Logux server with:
17
17
 
18
- * Framework to write own server.
19
- * Proxy between WebSocket and HTTP server on any other language.
18
+ - Framework to write own server.
19
+ - Proxy between WebSocket and HTTP server on any other language.
20
20
 
21
- <a href="https://evilmartians.com/?utm_source=logux-server">
22
- <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
23
- alt="Sponsored by Evil Martians" width="236" height="54">
24
- </a>
21
+ ---
25
22
 
26
- [cult-img]: http://cultofmartians.com/assets/badges/badge.svg
27
- [cult]: http://cultofmartians.com/done.html
23
+ <img src="https://cdn.evilmartians.com/badges/logo-no-label.svg" alt="" width="22" height="16" />  Logux Server is built by <b><a href="https://evilmartians.com/">Evil Martians</a></b>, an American design and engineering consultancy for <b>developer tools, AI, and cybersecurity startups</b>.
28
24
 
25
+ ---
29
26
 
30
27
  ### Logux Server as Framework
31
28
 
@@ -48,23 +45,23 @@ server.auth(async ({ userId, token }) => {
48
45
  })
49
46
 
50
47
  server.channel('user/:id', {
51
- access (ctx, action, meta) {
48
+ access(ctx, action, meta) {
52
49
  return ctx.params.id === ctx.userId
53
50
  },
54
- async load (ctx, action, meta) {
51
+ async load(ctx, action, meta) {
55
52
  const user = await db.loadUser(ctx.params.id)
56
53
  return { type: 'USER_NAME', name: user.name }
57
54
  }
58
55
  })
59
56
 
60
57
  server.type('CHANGE_NAME', {
61
- access (ctx, action, meta) {
58
+ access(ctx, action, meta) {
62
59
  return action.user === ctx.userId
63
60
  },
64
- resend (ctx, action, meta) {
65
- return { channel: `user/${ ctx.userId }` }
61
+ resend(ctx, action, meta) {
62
+ return { channel: `user/${ctx.userId}` }
66
63
  },
67
- async process (ctx, action, meta) {
64
+ async process(ctx, action, meta) {
68
65
  if (isFirstOlder(lastNameChange(action.user), meta)) {
69
66
  await db.changeUserName({ id: action.user, name: action.name })
70
67
  }
@@ -1,36 +1,44 @@
1
- <!DOCTYPE html><html>
2
- <head>
3
- <meta charset="UTF-8">
4
- <title>Logux Server</title>
5
- <style>
6
- html {
7
- height: 100%;
8
- }
9
- body {
10
- display: flex;
11
- align-items: center;
12
- justify-content: center;
13
- min-height: 100%;
14
- margin: 0;
15
- }
16
- svg {
17
- height: 25vh;
18
- }
19
- </style>
20
- </head>
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>Logux Server</title>
6
+ <style>
7
+ html {
8
+ height: 100%;
9
+ }
10
+ body {
11
+ display: flex;
12
+ align-items: center;
13
+ justify-content: center;
14
+ min-height: 100%;
15
+ margin: 0;
16
+ }
17
+ svg {
18
+ height: 25vh;
19
+ }
20
+ </style>
21
+ </head>
21
22
  <body>
22
23
  <a href="https://logux.org/">
23
24
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 75 117">
24
25
  <g fill="none" fill-rule="evenodd">
25
26
  <path d="M-1 0h78v117H-1z" />
26
27
  <g fill-rule="nonzero">
27
- <path fill="#1F1F1F"
28
- d="M2.239 40.258a12.83 12.83 0 00-.237.351C-.01 43.745-.515 46.634.71 50.4c1.484 4.565 3.865 6.346 9.045 7.98 5.705 1.8 7.064 2.346 10.02 4.481a23.387 23.387 0 013.3 2.885l4.198-1.394a28.632 28.632 0 00-1.907-2.072 27.455 27.455 0 00-3.196-2.697c-3.434-2.48-5.054-3.132-11.182-5.065-4.052-1.279-5.4-2.287-6.4-5.364-.69-2.121-.605-3.62.245-5.313L2.24 40.259zm4.91-7.089a22.975 22.975 0 001.72-3.977c1.038-3.18 1.217-5.458 1.078-9.74-.107-3.276-.06-4.527.422-6.218.648-2.273 2.042-4.164 4.406-5.87 2.658-1.918 5.15-2.604 7.865-2.292a14.85 14.85 0 012.38.491L22.371 9.12a22.74 22.74 0 01-.2-.022c-1.679-.193-3.155.214-5.002 1.546-2.923 2.11-3.317 3.494-3.149 8.678.153 4.713-.057 7.394-1.276 11.123a27.342 27.342 0 01-2.995 6.317l-2.6-3.592zm21.16 39.381c2.508 3.086 5.035 4.444 9.219 4.45 4.565.007 7.157-1.607 9.898-5.325.343-.465 1.837-2.598 2.27-3.184.928-1.257 1.795-2.288 2.783-3.27a23.18 23.18 0 012.784-2.36c1.364-.986 2.405-1.636 3.689-2.22l.023-4.394c-2.399.892-3.9 1.74-6.107 3.335a27.246 27.246 0 00-3.27 2.772c-1.15 1.143-2.145 2.328-3.187 3.74-.472.639-1.968 2.773-2.271 3.185-2.037 2.762-3.501 3.674-6.606 3.669-2.252-.003-3.644-.484-5.016-1.796L28.31 72.55zm38.808-14.716c3.919-1.472 5.9-3.358 7.234-7.431 1.29-3.939.765-6.885-1.353-10.092-.589-.892-2.979-4.007-3.421-4.634-1.48-2.097-2.532-4.081-3.317-6.485-.492-1.506-.799-2.81-.98-4.225l-4.217-1.334c.15 2.408.528 4.384 1.32 6.811.922 2.82 2.16 5.154 3.858 7.56.52.738 2.858 3.785 3.35 4.53 1.47 2.226 1.77 3.91.885 6.614-.716 2.185-1.57 3.35-3.336 4.265l-.023 4.421zm-2.09-41.45c-.22-4.341-1.311-6.541-4.74-9.019-2.339-1.69-4.597-2.387-7.035-2.254-1.101.06-2.206.28-3.518.666-.497.145-1.005.309-1.688.537.011-.003-1.32.446-1.709.575-3.303 1.09-5.743 1.588-8.806 1.588-1.515 0-2.87-.126-4.248-.39l-2.646 3.552c2.286.6 4.406.89 6.894.89 3.57 0 6.408-.579 10.09-1.794 4.765-1.573 4.538-1.506 5.854-1.578 1.481-.08 2.82.332 4.416 1.485 1.811 1.31 2.611 2.37 2.927 4.41l4.21 1.331z" />
29
- <path fill="#F5A623"
30
- d="M72.859 36.742c.095-.137.175-.256.236-.351 2.014-3.136 2.517-6.025 1.294-9.79-1.484-4.565-3.865-6.346-9.046-7.98-5.705-1.8-7.063-2.346-10.019-4.481a23.387 23.387 0 01-3.3-2.885l-4.198 1.394a28.632 28.632 0 001.907 2.072c.975.96 2.03 1.855 3.196 2.697 3.434 2.48 5.054 3.132 11.182 5.065 4.052 1.279 5.4 2.287 6.4 5.364.69 2.121.605 3.62-.245 5.313l2.593 3.582zm-4.91 7.089a22.975 22.975 0 00-1.72 3.977c-1.039 3.18-1.217 5.458-1.078 9.74.106 3.276.06 4.527-.423 6.218-.647 2.273-2.042 4.164-4.406 5.87-2.657 1.918-5.15 2.604-7.864 2.292a14.85 14.85 0 01-2.38-.491l2.649-3.556.2.022c1.678.193 3.155-.214 5.002-1.546 2.923-2.11 3.317-3.494 3.149-8.678-.154-4.713.057-7.394 1.276-11.123a27.342 27.342 0 012.994-6.317l2.6 3.592zM46.788 4.45C44.28 1.364 41.754.006 37.57 0c-4.566-.007-7.157 1.607-9.899 5.325-.343.465-1.837 2.598-2.27 3.184-.928 1.257-1.794 2.288-2.783 3.27a23.18 23.18 0 01-2.784 2.36c-1.363.986-2.404 1.636-3.688 2.22l-.023 4.394c2.398-.892 3.899-1.74 6.107-3.335a27.246 27.246 0 003.27-2.772c1.15-1.143 2.145-2.328 3.187-3.74.472-.639 1.967-2.773 2.271-3.185 2.036-2.762 3.5-3.674 6.606-3.669 2.252.003 3.644.484 5.015 1.796l4.209-1.398zM7.98 19.166c-3.918 1.472-5.899 3.358-7.233 7.431-1.29 3.939-.765 6.885 1.352 10.092.59.892 2.98 4.007 3.422 4.634C7 43.42 8.052 45.404 8.838 47.808c.492 1.506.798 2.81.979 4.225l4.218 1.334c-.15-2.408-.528-4.384-1.321-6.811-.922-2.82-2.16-5.154-3.857-7.56-.521-.738-2.859-3.785-3.351-4.53-1.47-2.226-1.77-3.91-.884-6.614.715-2.185 1.57-3.35 3.335-4.265l.023-4.421zm2.09 41.45c.22 4.341 1.312 6.541 4.74 9.019 2.34 1.69 4.598 2.387 7.036 2.254 1.1-.06 2.205-.28 3.518-.666a45.704 45.704 0 001.687-.537c-.01.003 1.32-.446 1.71-.575 3.303-1.09 5.743-1.588 8.806-1.588 1.515 0 2.87.126 4.248.39l2.646-3.552c-2.286-.6-4.406-.89-6.894-.89-3.57 0-6.409.579-10.09 1.794-4.766 1.573-4.538 1.506-5.854 1.578-1.482.08-2.82-.332-4.417-1.485-1.81-1.31-2.61-2.37-2.926-4.41l-4.21-1.331z" />
28
+ <path
29
+ fill="#1F1F1F"
30
+ d="M2.239 40.258a12.83 12.83 0 00-.237.351C-.01 43.745-.515 46.634.71 50.4c1.484 4.565 3.865 6.346 9.045 7.98 5.705 1.8 7.064 2.346 10.02 4.481a23.387 23.387 0 013.3 2.885l4.198-1.394a28.632 28.632 0 00-1.907-2.072 27.455 27.455 0 00-3.196-2.697c-3.434-2.48-5.054-3.132-11.182-5.065-4.052-1.279-5.4-2.287-6.4-5.364-.69-2.121-.605-3.62.245-5.313L2.24 40.259zm4.91-7.089a22.975 22.975 0 001.72-3.977c1.038-3.18 1.217-5.458 1.078-9.74-.107-3.276-.06-4.527.422-6.218.648-2.273 2.042-4.164 4.406-5.87 2.658-1.918 5.15-2.604 7.865-2.292a14.85 14.85 0 012.38.491L22.371 9.12a22.74 22.74 0 01-.2-.022c-1.679-.193-3.155.214-5.002 1.546-2.923 2.11-3.317 3.494-3.149 8.678.153 4.713-.057 7.394-1.276 11.123a27.342 27.342 0 01-2.995 6.317l-2.6-3.592zm21.16 39.381c2.508 3.086 5.035 4.444 9.219 4.45 4.565.007 7.157-1.607 9.898-5.325.343-.465 1.837-2.598 2.27-3.184.928-1.257 1.795-2.288 2.783-3.27a23.18 23.18 0 012.784-2.36c1.364-.986 2.405-1.636 3.689-2.22l.023-4.394c-2.399.892-3.9 1.74-6.107 3.335a27.246 27.246 0 00-3.27 2.772c-1.15 1.143-2.145 2.328-3.187 3.74-.472.639-1.968 2.773-2.271 3.185-2.037 2.762-3.501 3.674-6.606 3.669-2.252-.003-3.644-.484-5.016-1.796L28.31 72.55zm38.808-14.716c3.919-1.472 5.9-3.358 7.234-7.431 1.29-3.939.765-6.885-1.353-10.092-.589-.892-2.979-4.007-3.421-4.634-1.48-2.097-2.532-4.081-3.317-6.485-.492-1.506-.799-2.81-.98-4.225l-4.217-1.334c.15 2.408.528 4.384 1.32 6.811.922 2.82 2.16 5.154 3.858 7.56.52.738 2.858 3.785 3.35 4.53 1.47 2.226 1.77 3.91.885 6.614-.716 2.185-1.57 3.35-3.336 4.265l-.023 4.421zm-2.09-41.45c-.22-4.341-1.311-6.541-4.74-9.019-2.339-1.69-4.597-2.387-7.035-2.254-1.101.06-2.206.28-3.518.666-.497.145-1.005.309-1.688.537.011-.003-1.32.446-1.709.575-3.303 1.09-5.743 1.588-8.806 1.588-1.515 0-2.87-.126-4.248-.39l-2.646 3.552c2.286.6 4.406.89 6.894.89 3.57 0 6.408-.579 10.09-1.794 4.765-1.573 4.538-1.506 5.854-1.578 1.481-.08 2.82.332 4.416 1.485 1.811 1.31 2.611 2.37 2.927 4.41l4.21 1.331z"
31
+ />
32
+ <path
33
+ fill="#F5A623"
34
+ d="M72.859 36.742c.095-.137.175-.256.236-.351 2.014-3.136 2.517-6.025 1.294-9.79-1.484-4.565-3.865-6.346-9.046-7.98-5.705-1.8-7.063-2.346-10.019-4.481a23.387 23.387 0 01-3.3-2.885l-4.198 1.394a28.632 28.632 0 001.907 2.072c.975.96 2.03 1.855 3.196 2.697 3.434 2.48 5.054 3.132 11.182 5.065 4.052 1.279 5.4 2.287 6.4 5.364.69 2.121.605 3.62-.245 5.313l2.593 3.582zm-4.91 7.089a22.975 22.975 0 00-1.72 3.977c-1.039 3.18-1.217 5.458-1.078 9.74.106 3.276.06 4.527-.423 6.218-.647 2.273-2.042 4.164-4.406 5.87-2.657 1.918-5.15 2.604-7.864 2.292a14.85 14.85 0 01-2.38-.491l2.649-3.556.2.022c1.678.193 3.155-.214 5.002-1.546 2.923-2.11 3.317-3.494 3.149-8.678-.154-4.713.057-7.394 1.276-11.123a27.342 27.342 0 012.994-6.317l2.6 3.592zM46.788 4.45C44.28 1.364 41.754.006 37.57 0c-4.566-.007-7.157 1.607-9.899 5.325-.343.465-1.837 2.598-2.27 3.184-.928 1.257-1.794 2.288-2.783 3.27a23.18 23.18 0 01-2.784 2.36c-1.363.986-2.404 1.636-3.688 2.22l-.023 4.394c2.398-.892 3.899-1.74 6.107-3.335a27.246 27.246 0 003.27-2.772c1.15-1.143 2.145-2.328 3.187-3.74.472-.639 1.967-2.773 2.271-3.185 2.036-2.762 3.5-3.674 6.606-3.669 2.252.003 3.644.484 5.015 1.796l4.209-1.398zM7.98 19.166c-3.918 1.472-5.899 3.358-7.233 7.431-1.29 3.939-.765 6.885 1.352 10.092.59.892 2.98 4.007 3.422 4.634C7 43.42 8.052 45.404 8.838 47.808c.492 1.506.798 2.81.979 4.225l4.218 1.334c-.15-2.408-.528-4.384-1.321-6.811-.922-2.82-2.16-5.154-3.857-7.56-.521-.738-2.859-3.785-3.351-4.53-1.47-2.226-1.77-3.91-.884-6.614.715-2.185 1.57-3.35 3.335-4.265l.023-4.421zm2.09 41.45c.22 4.341 1.312 6.541 4.74 9.019 2.34 1.69 4.598 2.387 7.036 2.254 1.1-.06 2.205-.28 3.518-.666a45.704 45.704 0 001.687-.537c-.01.003 1.32-.446 1.71-.575 3.303-1.09 5.743-1.588 8.806-1.588 1.515 0 2.87.126 4.248.39l2.646-3.552c-2.286-.6-4.406-.89-6.894-.89-3.57 0-6.409.579-10.09 1.794-4.766 1.573-4.538 1.506-5.854 1.578-1.482.08-2.82-.332-4.417-1.485-1.81-1.31-2.61-2.37-2.926-4.41l-4.21-1.331z"
35
+ />
31
36
  </g>
32
- <path fill="#1F1F1F" fill-rule="nonzero"
33
- d="M10.889 117v-4H6.944V89H3v28h7.889zm11.833-14c0 .547-.194 1.017-.582 1.41-.387.393-.85.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41c0-.547.194-1.017.582-1.41.387-.393.85-.59 1.39-.59.54 0 1.003.197 1.39.59.388.393.582.863.582 1.41zm-7.889 0c0 1.653.579 3.067 1.736 4.24s2.55 1.76 4.181 1.76c1.63 0 3.024-.587 4.181-1.76s1.736-2.587 1.736-4.24-.579-3.067-1.736-4.24S22.381 97 20.75 97c-1.63 0-3.024.587-4.181 1.76s-1.736 2.587-1.736 4.24zm11.834-14H14.833v4h11.834v-4zm0 24H14.833v4h11.834v-4zM38.5 95c0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41c0-.547.193-1.017.581-1.41.388-.393.852-.59 1.39-.59.54 0 1.003.197 1.391.59.388.393.582.863.582 1.41zm-3.944 16v-2.32c.618.213 1.275.32 1.972.32 1.63 0 3.024-.587 4.18-1.76 1.158-1.173 1.736-2.587 1.736-4.24 0-1.547-.506-2.88-1.518-4 1.012-1.12 1.518-2.453 1.518-4 0-1.653-.578-3.067-1.735-4.24S38.159 89 36.528 89c-1.63 0-3.024.587-4.181 1.76S30.61 93.347 30.61 95s.579 3.067 1.736 4.24 2.55 1.76 4.18 1.76c.54 0 1.003.197 1.391.59.388.393.582.863.582 1.41 0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41H30.61v8c0 1.653.579 3.067 1.736 4.24s2.55 1.76 4.18 1.76c1.631 0 3.025-.587 4.182-1.76 1.157-1.173 1.735-2.587 1.735-4.24H38.5c0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41zm11.833 0c0 1.653.578 3.067 1.735 4.24s2.551 1.76 4.182 1.76c1.63 0 3.024-.587 4.18-1.76 1.158-1.173 1.736-2.587 1.736-4.24V89h-3.944v22c0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.583-1.41V89H46.39v22zM74 89H62.167v4H74v-4zm-3.116 14l2.78-2.82-2.8-2.82-2.78 2.82-2.782-2.82-2.8 2.82 2.8 2.82-2.8 2.84 2.8 2.82 2.781-2.82 2.781 2.82 2.8-2.82-2.78-2.84zM74 113H62.167v4H74v-4z" />
37
+ <path
38
+ fill="#1F1F1F"
39
+ fill-rule="nonzero"
40
+ d="M10.889 117v-4H6.944V89H3v28h7.889zm11.833-14c0 .547-.194 1.017-.582 1.41-.387.393-.85.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41c0-.547.194-1.017.582-1.41.387-.393.85-.59 1.39-.59.54 0 1.003.197 1.39.59.388.393.582.863.582 1.41zm-7.889 0c0 1.653.579 3.067 1.736 4.24s2.55 1.76 4.181 1.76c1.63 0 3.024-.587 4.181-1.76s1.736-2.587 1.736-4.24-.579-3.067-1.736-4.24S22.381 97 20.75 97c-1.63 0-3.024.587-4.181 1.76s-1.736 2.587-1.736 4.24zm11.834-14H14.833v4h11.834v-4zm0 24H14.833v4h11.834v-4zM38.5 95c0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41c0-.547.193-1.017.581-1.41.388-.393.852-.59 1.39-.59.54 0 1.003.197 1.391.59.388.393.582.863.582 1.41zm-3.944 16v-2.32c.618.213 1.275.32 1.972.32 1.63 0 3.024-.587 4.18-1.76 1.158-1.173 1.736-2.587 1.736-4.24 0-1.547-.506-2.88-1.518-4 1.012-1.12 1.518-2.453 1.518-4 0-1.653-.578-3.067-1.735-4.24S38.159 89 36.528 89c-1.63 0-3.024.587-4.181 1.76S30.61 93.347 30.61 95s.579 3.067 1.736 4.24 2.55 1.76 4.18 1.76c.54 0 1.003.197 1.391.59.388.393.582.863.582 1.41 0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41H30.61v8c0 1.653.579 3.067 1.736 4.24s2.55 1.76 4.18 1.76c1.631 0 3.025-.587 4.182-1.76 1.157-1.173 1.735-2.587 1.735-4.24H38.5c0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.582-1.41zm11.833 0c0 1.653.578 3.067 1.735 4.24s2.551 1.76 4.182 1.76c1.63 0 3.024-.587 4.18-1.76 1.158-1.173 1.736-2.587 1.736-4.24V89h-3.944v22c0 .547-.194 1.017-.582 1.41-.388.393-.851.59-1.39.59-.54 0-1.003-.197-1.39-.59a1.938 1.938 0 01-.583-1.41V89H46.39v22zM74 89H62.167v4H74v-4zm-3.116 14l2.78-2.82-2.8-2.82-2.78 2.82-2.782-2.82-2.8 2.82 2.8 2.82-2.8 2.84 2.8 2.82 2.781-2.82 2.781 2.82 2.8-2.82-2.78-2.84zM74 113H62.167v4H74v-4z"
41
+ />
34
42
  </g>
35
43
  </svg>
36
44
  </a>
@@ -54,9 +54,7 @@ export function ChangedAt<Value extends SyncMapTypes | SyncMapTypes[]>(
54
54
  */
55
55
  export function NoConflictResolution<
56
56
  Value extends SyncMapTypes | SyncMapTypes[]
57
- >(
58
- value: Value
59
- ): WithTime<Value>
57
+ >(value: Value): WithTime<Value>
60
58
 
61
59
  interface SyncMapActionFilter<Value extends SyncMapValues> {
62
60
  (
@@ -46,10 +46,9 @@ function buildFilter(filter) {
46
46
  }
47
47
  if (action.type.endsWith('/changed')) {
48
48
  for (let key in filter) {
49
- if (
50
- key in action.fields &&
51
- action.fields[key] !== filter[key]
52
- ) return false
49
+ if (key in action.fields && action.fields[key] !== filter[key]) {
50
+ return false
51
+ }
53
52
  }
54
53
  }
55
54
  return true
@@ -112,12 +111,7 @@ export function addSyncMap(server, plural, operations) {
112
111
  meta
113
112
  )
114
113
  if (data !== false) {
115
- await sendMap(
116
- server,
117
- changedType,
118
- data,
119
- since
120
- )
114
+ await sendMap(server, changedType, data, since)
121
115
  }
122
116
  }
123
117
  })
@@ -19,6 +19,7 @@ import type {
19
19
  IncomingMessage,
20
20
  ServerResponse
21
21
  } from 'node:http'
22
+ import type { WebSocket } from 'ws'
22
23
 
23
24
  import type {
24
25
  ChannelContext,
@@ -56,13 +57,13 @@ interface ConnectLoader<Headers extends object = unknown> {
56
57
  | Promise<
57
58
  [
58
59
  Action,
59
- Partial<Pick<ServerMeta, 'subprotocol'>> &
60
+ Partial<Pick<ServerMeta, 'added' | 'subprotocol'>> &
60
61
  Pick<ServerMeta, 'id' | 'time'>
61
62
  ][]
62
63
  >
63
64
  }
64
65
 
65
- type ServerNodeConstructor = new (...args: any[]) => ServerNode
66
+ type ServerNodeConstructor = new (...args: unknown[]) => ServerNode
66
67
 
67
68
  export interface ServerMeta extends Meta {
68
69
  /**
@@ -237,6 +238,14 @@ export interface BaseServerOptions {
237
238
  */
238
239
  subprotocol?: number
239
240
 
241
+ /**
242
+ * How many actions could be sent in a single message. `100` by default.
243
+ *
244
+ * Actions from a single `Server#log.add()` call (or from `ctx.sendBack()`
245
+ * with an array) are sent together and will be split by this limit.
246
+ */
247
+ syncBatch?: number
248
+
240
249
  /**
241
250
  * Test time to test server.
242
251
  */
@@ -249,8 +258,11 @@ export interface BaseServerOptions {
249
258
  timeout?: number
250
259
  }
251
260
 
252
- export interface AuthenticatorOptions<Headers extends object> {
253
- client: ServerClient
261
+ export interface AuthenticatorOptions<
262
+ Headers extends object,
263
+ ClientData extends object
264
+ > {
265
+ client: ServerClient<ClientData>
254
266
  cookie: Record<string, string>
255
267
  headers: Headers
256
268
  token: string
@@ -258,9 +270,8 @@ export interface AuthenticatorOptions<Headers extends object> {
258
270
  }
259
271
 
260
272
  export type SendBackActions =
261
- | [Action, Partial<Meta>][]
273
+ | (Action | [Action, Partial<Meta>])[]
262
274
  | Action
263
- | Action[]
264
275
  | void
265
276
 
266
277
  /**
@@ -271,8 +282,11 @@ export type SendBackActions =
271
282
  * @param client Client object.
272
283
  * @returns `true` if credentials was correct
273
284
  */
274
- interface ServerAuthenticator<Headers extends object> {
275
- (user: AuthenticatorOptions<Headers>): boolean | Promise<boolean>
285
+ interface ServerAuthenticator<
286
+ Headers extends object,
287
+ ClientData extends object
288
+ > {
289
+ (user: AuthenticatorOptions<Headers, ClientData>): boolean | Promise<boolean>
276
290
  }
277
291
 
278
292
  /**
@@ -479,10 +493,7 @@ type ActionCallbacks<
479
493
  TypeAction extends Action,
480
494
  Data extends object,
481
495
  Headers extends object
482
- > = {
483
- finally?: ActionFinally<TypeAction, Data, Headers>
484
- resend?: Resender<TypeAction, Data, Headers>
485
- } & (
496
+ > = (
486
497
  | {
487
498
  access: Authorizer<TypeAction, Data, Headers>
488
499
  process?: Processor<TypeAction, Data, Headers>
@@ -490,18 +501,17 @@ type ActionCallbacks<
490
501
  | {
491
502
  accessAndProcess: Processor<TypeAction, Data, Headers>
492
503
  }
493
- )
504
+ ) & {
505
+ finally?: ActionFinally<TypeAction, Data, Headers>
506
+ resend?: Resender<TypeAction, Data, Headers>
507
+ }
494
508
 
495
509
  type ChannelCallbacks<
496
510
  SubscribeAction extends Action,
497
511
  Data extends object,
498
512
  ChannelParams extends object | string[],
499
513
  Headers extends object
500
- > = {
501
- filter?: FilterCreator<SubscribeAction, Data, ChannelParams, Headers>
502
- finally?: ChannelFinally<SubscribeAction, Data, ChannelParams, Headers>
503
- unsubscribe?: ChannelUnsubscribe<Data, ChannelParams, Headers>
504
- } & (
514
+ > = (
505
515
  | {
506
516
  access: ChannelAuthorizer<SubscribeAction, Data, ChannelParams, Headers>
507
517
  load?: ChannelLoader<SubscribeAction, Data, ChannelParams, Headers>
@@ -514,7 +524,11 @@ type ChannelCallbacks<
514
524
  Headers
515
525
  >
516
526
  }
517
- )
527
+ ) & {
528
+ filter?: FilterCreator<SubscribeAction, Data, ChannelParams, Headers>
529
+ finally?: ChannelFinally<SubscribeAction, Data, ChannelParams, Headers>
530
+ unsubscribe?: ChannelUnsubscribe<Data, ChannelParams, Headers>
531
+ }
518
532
 
519
533
  interface ActionReporter {
520
534
  action: Readonly<Action>
@@ -646,7 +660,8 @@ export function wasNot403(cb: () => Promise<void>): Promise<boolean>
646
660
  */
647
661
  export class BaseServer<
648
662
  Headers extends object = unknown,
649
- ServerLog extends Log = Log<ServerMeta>
663
+ ServerLog extends Log = Log<ServerMeta>,
664
+ ClientData extends object = unknown
650
665
  > {
651
666
  /**
652
667
  * Connected client by client ID.
@@ -654,7 +669,7 @@ export class BaseServer<
654
669
  * Do not rely on this data, when you have multiple Logux servers.
655
670
  * Each server will have a different list.
656
671
  */
657
- clientIds: Map<string, ServerClient>
672
+ clientIds: Map<string, ServerClient<ClientData>>
658
673
 
659
674
  /**
660
675
  * Connected clients.
@@ -665,7 +680,7 @@ export class BaseServer<
665
680
  * }
666
681
  * ```
667
682
  */
668
- connected: Map<string, ServerClient>
683
+ connected: Map<string, ServerClient<ClientData>>
669
684
 
670
685
  /**
671
686
  * Production or development mode.
@@ -722,7 +737,7 @@ export class BaseServer<
722
737
  * Do not rely on this data, when you have multiple Logux servers.
723
738
  * Each server will have a different list.
724
739
  */
725
- nodeIds: Map<string, ServerClient>
740
+ nodeIds: Map<string, ServerClient<ClientData>>
726
741
 
727
742
  /**
728
743
  * Server options.
@@ -754,7 +769,7 @@ export class BaseServer<
754
769
  * Do not rely on this data, when you have multiple Logux servers.
755
770
  * Each server will have a different list.
756
771
  */
757
- userIds: Map<string, ServerClient[]>
772
+ userIds: Map<string, ServerClient<ClientData>[]>
758
773
 
759
774
  /**
760
775
  * @param opts Server options.
@@ -787,7 +802,7 @@ export class BaseServer<
787
802
  *
788
803
  * @param authenticator The authentication callback.
789
804
  */
790
- auth(authenticator: ServerAuthenticator<Headers>): void
805
+ auth(authenticator: ServerAuthenticator<Headers, ClientData>): void
791
806
 
792
807
  /**
793
808
  * Define the channel.
@@ -863,6 +878,38 @@ export class BaseServer<
863
878
  */
864
879
  destroy(): Promise<void>
865
880
 
881
+ /**
882
+ * Wait until the client will confirm all actions, which were sent to it.
883
+ *
884
+ * Use it to send a long history without loading it all into the memory:
885
+ * the client’s speed will limit how fast you read the database.
886
+ *
887
+ * ```js
888
+ * while (await server.drain(clientId)) {
889
+ * let page = await cursor.next(100)
890
+ * if (!page.length) break
891
+ * server.log.add(page.map(i => [i.action, { clients: [clientId] }]))
892
+ * }
893
+ * ```
894
+ *
895
+ * @param clientId Client ID.
896
+ * @returns Promise with `false` if the client was disconnected.
897
+ */
898
+ drain(clientId: string): Promise<boolean>
899
+
900
+ /**
901
+ * Handle WebSocket connection explicitly
902
+ *
903
+ * This is a low-level method allowing to integrate Logux server with an existing server
904
+ *
905
+ * ```js
906
+ * fastify.get('/', { websocket: true }, (socket, req) => {
907
+ * loguxServer.handleClient(socket, req)
908
+ * })
909
+ * ```
910
+ */
911
+ handleClient(ws: WebSocket, req: IncomingMessage): void
912
+
866
913
  /**
867
914
  * Add non-WebSocket HTTP request processor.
868
915
  *
@@ -940,7 +987,7 @@ export class BaseServer<
940
987
  */
941
988
  on(
942
989
  event: 'connected' | 'disconnected',
943
- listener: (client: ServerClient) => void
990
+ listener: (client: ServerClient<ClientData>) => void
944
991
  ): Unsubscribe
945
992
  /**
946
993
  * Subscribe for synchronization events. It implements nanoevents API.
@@ -991,7 +1038,10 @@ export class BaseServer<
991
1038
  */
992
1039
  on(
993
1040
  event: 'authenticated' | 'unauthenticated',
994
- listener: (client: ServerClient, latencyMilliseconds: number) => void
1041
+ listener: (
1042
+ client: ServerClient<ClientData>,
1043
+ latencyMilliseconds: number
1044
+ ) => void
995
1045
  ): Unsubscribe
996
1046
  /**
997
1047
  * @param event The event name.
@@ -1092,8 +1142,8 @@ export class BaseServer<
1092
1142
  * @param meta Action’s meta.
1093
1143
  * @returns Promise until new action will be resend to clients and processed.
1094
1144
  */
1095
- process(
1096
- action: AnyAction,
1145
+ process<TypeAction extends Action = AnyAction>(
1146
+ action: TypeAction,
1097
1147
  meta?: Partial<ServerMeta>
1098
1148
  ): Promise<Readonly<ServerMeta>>
1099
1149
 
@@ -1126,9 +1176,17 @@ export class BaseServer<
1126
1176
  * })
1127
1177
  * ```
1128
1178
  *
1179
+ * Actions should be returned from the newest one to the oldest one.
1180
+ * The list will be split into messages by the `syncBatch` option, but it
1181
+ * is loaded into the memory as a whole. For a big history send it by
1182
+ * pages with `Context#sendBack()` and `Context#drain()` instead.
1183
+ *
1184
+ * Set `meta.added` to let the client ask only for newer actions after
1185
+ * the reconnect: the biggest `added` will be sent as the sync position.
1186
+ *
1129
1187
  * @param loader Callback which loads list of actions and meta.
1130
1188
  */
1131
- sendOnConnect(loader: ConnectLoader<Headers>)
1189
+ sendOnConnect(loader: ConnectLoader<Headers>): void
1132
1190
 
1133
1191
  /**
1134
1192
  * Send `logux/subscribed` if client was not already subscribed.