@tricoteuses/assemblee 3.5.0 → 3.5.1
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/lib/eliasse-socket.d.ts +4 -0
- package/lib/eliasse-socket.js +58 -42
- package/package.json +1 -1
package/lib/eliasse-socket.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EliasseDerouleur, EliasseDerouleurAmendement, EliasseProchainADiscuter, EliasseStatistiques } from './eliasse.js';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
export declare const eliasseDefaultSocketUrl = "wss://eliasse.assemblee-nationale.fr/ws-eliasse";
|
|
3
4
|
export interface EliasseDerouleurUpdatePlace {
|
|
4
5
|
id: string;
|
|
@@ -9,6 +10,8 @@ export interface EliasseDerouleurUpdate {
|
|
|
9
10
|
version: number;
|
|
10
11
|
places: EliasseDerouleurUpdatePlace[];
|
|
11
12
|
}
|
|
13
|
+
export declare const eliasseDerouleurUpdatePlaceSchema: z.ZodType<EliasseDerouleurUpdatePlace>;
|
|
14
|
+
export declare const eliasseDerouleurUpdateSchema: z.ZodType<EliasseDerouleurUpdate>;
|
|
12
15
|
interface WebSocketLike {
|
|
13
16
|
send(data: string): void;
|
|
14
17
|
close(code?: number, reason?: string): void;
|
|
@@ -70,6 +73,7 @@ export declare class EliasseSocket {
|
|
|
70
73
|
watchProchainsADiscuter(handler: (prochains: EliasseProchainADiscuter[]) => void): () => void;
|
|
71
74
|
watchDerouleur(uidExamen: string, handler: (update: EliasseDerouleurUpdate) => void): () => void;
|
|
72
75
|
watchStatistiques(uidExamen: string, handler: (statistiques: EliasseStatistiques) => void): () => void;
|
|
76
|
+
private validatingHandler;
|
|
73
77
|
watch<T>(destination: string, handler: (body: T) => void): () => void;
|
|
74
78
|
private setStatus;
|
|
75
79
|
private sendSubscribe;
|
package/lib/eliasse-socket.js
CHANGED
|
@@ -1,45 +1,55 @@
|
|
|
1
|
+
import { t as e } from "./zod_errors-DCnjCNGy.js";
|
|
2
|
+
import { eliasseDerouleurAmendementSchema as t, eliasseProchainADiscuterSchema as n, eliasseStatistiquesSchema as r } from "./eliasse.js";
|
|
3
|
+
import { z as i } from "zod";
|
|
1
4
|
//#region src/eliasse-socket.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
5
|
+
var a = "wss://eliasse.assemblee-nationale.fr/ws-eliasse", o = i.object({
|
|
6
|
+
id: i.string(),
|
|
7
|
+
libelle: i.string().optional(),
|
|
8
|
+
amendements: i.array(t)
|
|
9
|
+
}), s = i.object({
|
|
10
|
+
version: i.number(),
|
|
11
|
+
places: i.array(o)
|
|
12
|
+
}), c = "\0";
|
|
13
|
+
function l(e) {
|
|
4
14
|
return e.replace(/\\/g, "\\\\").replace(/:/g, "\\c").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
5
15
|
}
|
|
6
|
-
function
|
|
16
|
+
function u(e) {
|
|
7
17
|
return e.replace(/\\r/g, "\r").replace(/\\n/g, "\n").replace(/\\c/g, ":").replace(/\\\\/g, "\\");
|
|
8
18
|
}
|
|
9
|
-
function
|
|
10
|
-
let
|
|
11
|
-
for (let [e,
|
|
12
|
-
return `${
|
|
19
|
+
function d(e, t, n = "") {
|
|
20
|
+
let r = [e];
|
|
21
|
+
for (let [e, n] of Object.entries(t)) r.push(`${l(e)}:${l(n)}`);
|
|
22
|
+
return `${r.join("\n")}\n\n${n}${c}`;
|
|
13
23
|
}
|
|
14
|
-
function
|
|
24
|
+
function f(e) {
|
|
15
25
|
let t = e.startsWith("\n") ? e.slice(1) : e;
|
|
16
26
|
if (t.trim() === "") return;
|
|
17
|
-
let n = t.indexOf("\n\n"),
|
|
18
|
-
if (
|
|
19
|
-
let
|
|
20
|
-
for (let e of
|
|
27
|
+
let n = t.indexOf("\n\n"), r = n === -1 ? t : t.slice(0, n), i = n === -1 ? "" : t.slice(n + 2), a = r.split("\n"), o = a[0] ?? "";
|
|
28
|
+
if (o === "") return;
|
|
29
|
+
let s = {};
|
|
30
|
+
for (let e of a.slice(1)) {
|
|
21
31
|
let t = e.indexOf(":");
|
|
22
|
-
t !== -1 && (
|
|
32
|
+
t !== -1 && (s[u(e.slice(0, t))] = u(e.slice(t + 1)));
|
|
23
33
|
}
|
|
24
34
|
return {
|
|
25
|
-
command:
|
|
26
|
-
headers:
|
|
27
|
-
body:
|
|
35
|
+
command: o,
|
|
36
|
+
headers: s,
|
|
37
|
+
body: i
|
|
28
38
|
};
|
|
29
39
|
}
|
|
30
|
-
var
|
|
31
|
-
function
|
|
32
|
-
return
|
|
40
|
+
var p = new Intl.Collator("fr", { numeric: !0 });
|
|
41
|
+
function m(e, t) {
|
|
42
|
+
return p.compare(e, t);
|
|
33
43
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
44
|
+
function h(e, t) {
|
|
45
|
+
return m(e.ordre ?? "", t.ordre ?? "");
|
|
36
46
|
}
|
|
37
|
-
function
|
|
47
|
+
function g(e, t) {
|
|
38
48
|
let n = new Map(e.places.map((e) => [e.id, e]));
|
|
39
49
|
for (let e of t.places) {
|
|
40
50
|
let t = n.get(e.id);
|
|
41
51
|
if (t === void 0) {
|
|
42
|
-
let t = (e.amendements ?? []).filter((e) => e.estVisible !== !1).sort(
|
|
52
|
+
let t = (e.amendements ?? []).filter((e) => e.estVisible !== !1).sort(h);
|
|
43
53
|
t.length > 0 && n.set(e.id, {
|
|
44
54
|
...e,
|
|
45
55
|
amendements: t
|
|
@@ -47,7 +57,7 @@ function l(e, t) {
|
|
|
47
57
|
} else {
|
|
48
58
|
let r = new Map(t.amendements.map((e) => [e.uid, e]));
|
|
49
59
|
for (let t of e.amendements ?? []) t.estVisible === !1 ? r.delete(t.uid) : r.set(t.uid, t);
|
|
50
|
-
let i = [...r.values()].sort(
|
|
60
|
+
let i = [...r.values()].sort(h);
|
|
51
61
|
i.length > 0 ? n.set(t.id, {
|
|
52
62
|
...t,
|
|
53
63
|
amendements: i
|
|
@@ -56,7 +66,7 @@ function l(e, t) {
|
|
|
56
66
|
}
|
|
57
67
|
let r = [...n.values()].sort((e, t) => {
|
|
58
68
|
let n = e.amendements[0], r = t.amendements[0];
|
|
59
|
-
return n === void 0 && r === void 0 ? 0 : n === void 0 ? 1 : r === void 0 ? -1 :
|
|
69
|
+
return n === void 0 && r === void 0 ? 0 : n === void 0 ? 1 : r === void 0 ? -1 : m(n.ordre, r.ordre);
|
|
60
70
|
});
|
|
61
71
|
return {
|
|
62
72
|
...e,
|
|
@@ -64,7 +74,7 @@ function l(e, t) {
|
|
|
64
74
|
places: r
|
|
65
75
|
};
|
|
66
76
|
}
|
|
67
|
-
var
|
|
77
|
+
var _ = class {
|
|
68
78
|
constructor(e = {}) {
|
|
69
79
|
this.buffer = "", this.statusValue = "disconnected", this.userClosed = !1, this.subscriptions = /* @__PURE__ */ new Map(), this.subscriptionCounter = 0, this.socketUrl = e.socketUrl ?? "wss://eliasse.assemblee-nationale.fr/ws-eliasse", this.heartbeatMs = e.heartbeatMs ?? 4e3, this.reconnectDelayMs = e.reconnectDelayMs ?? 5e3;
|
|
70
80
|
let t = e.WebSocket ?? globalThis.WebSocket;
|
|
@@ -78,11 +88,11 @@ var u = class {
|
|
|
78
88
|
return this.ws;
|
|
79
89
|
}
|
|
80
90
|
connect() {
|
|
81
|
-
if (this.ws !== void 0 &&
|
|
91
|
+
if (this.ws !== void 0 && v(this.ws)) return;
|
|
82
92
|
this.userClosed = !1, this.buffer = "", this.setStatus("connecting");
|
|
83
93
|
let e = new this.WebSocketConstructor(this.socketUrl);
|
|
84
94
|
this.ws = e, e.onopen = () => {
|
|
85
|
-
e.send(
|
|
95
|
+
e.send(d("CONNECT", {
|
|
86
96
|
"accept-version": "1.2",
|
|
87
97
|
"heart-beat": `${this.heartbeatMs},${this.heartbeatMs}`
|
|
88
98
|
}));
|
|
@@ -107,7 +117,7 @@ var u = class {
|
|
|
107
117
|
}), n = `eliasse-disconnect-${++this.subscriptionCounter}`;
|
|
108
118
|
this.disconnectReceipt = n;
|
|
109
119
|
try {
|
|
110
|
-
e.send(
|
|
120
|
+
e.send(d("DISCONNECT", { receipt: n }));
|
|
111
121
|
} catch {}
|
|
112
122
|
let r = new Promise((e) => setTimeout(e, 1e3));
|
|
113
123
|
await Promise.race([t, r]);
|
|
@@ -117,13 +127,19 @@ var u = class {
|
|
|
117
127
|
this.ws === e && (this.ws = void 0), this.setStatus("disconnected");
|
|
118
128
|
}
|
|
119
129
|
watchProchainsADiscuter(e) {
|
|
120
|
-
return this.watch("/topic/get-all-prochains-a-discuter", e);
|
|
130
|
+
return this.watch("/topic/get-all-prochains-a-discuter", this.validatingHandler("prochains à discuter", i.array(n), e));
|
|
121
131
|
}
|
|
122
132
|
watchDerouleur(e, t) {
|
|
123
|
-
return this.watch(`/topic/get-derouleur-update/${e}`, t);
|
|
133
|
+
return this.watch(`/topic/get-derouleur-update/${e}`, this.validatingHandler("dérouleur update", s, t));
|
|
124
134
|
}
|
|
125
135
|
watchStatistiques(e, t) {
|
|
126
|
-
return this.watch(`/topic/get-statistiques-update/${e}`, t);
|
|
136
|
+
return this.watch(`/topic/get-statistiques-update/${e}`, this.validatingHandler("statistiques", r, t));
|
|
137
|
+
}
|
|
138
|
+
validatingHandler(t, n, r) {
|
|
139
|
+
return (i) => {
|
|
140
|
+
let a = n.safeParse(i);
|
|
141
|
+
a.success || this.onError?.(/* @__PURE__ */ Error(`Unexpected Eliasse WebSocket ${t} structure:\n${e(t, a.error, i)}`)), r(i);
|
|
142
|
+
};
|
|
127
143
|
}
|
|
128
144
|
watch(e, t) {
|
|
129
145
|
let n = `eliasse-sub-${++this.subscriptionCounter}`;
|
|
@@ -131,14 +147,14 @@ var u = class {
|
|
|
131
147
|
destination: e,
|
|
132
148
|
handler: t
|
|
133
149
|
}), this.statusValue === "connected" && this.sendSubscribe(n, e), () => {
|
|
134
|
-
this.subscriptions.delete(n), this.statusValue === "connected" && this.ws !== void 0 && this.ws.send(
|
|
150
|
+
this.subscriptions.delete(n), this.statusValue === "connected" && this.ws !== void 0 && this.ws.send(d("UNSUBSCRIBE", { id: n }));
|
|
135
151
|
};
|
|
136
152
|
}
|
|
137
153
|
setStatus(e) {
|
|
138
154
|
this.statusValue !== e && (this.statusValue = e, this.onStatusChange?.(e));
|
|
139
155
|
}
|
|
140
156
|
sendSubscribe(e, t) {
|
|
141
|
-
this.ws?.send(
|
|
157
|
+
this.ws?.send(d("SUBSCRIBE", {
|
|
142
158
|
id: e,
|
|
143
159
|
destination: t,
|
|
144
160
|
ack: "auto"
|
|
@@ -147,12 +163,12 @@ var u = class {
|
|
|
147
163
|
handleData(e) {
|
|
148
164
|
if (this.resetIncomingWatchdog(), e.trim() === "") return;
|
|
149
165
|
this.buffer += e;
|
|
150
|
-
let
|
|
151
|
-
for (; (
|
|
152
|
-
let e = this.buffer.slice(0,
|
|
153
|
-
this.buffer = this.buffer.slice(
|
|
154
|
-
let
|
|
155
|
-
|
|
166
|
+
let t;
|
|
167
|
+
for (; (t = this.buffer.indexOf(c)) !== -1;) {
|
|
168
|
+
let e = this.buffer.slice(0, t);
|
|
169
|
+
this.buffer = this.buffer.slice(t + 1);
|
|
170
|
+
let n = f(e);
|
|
171
|
+
n !== void 0 && this.handleFrame(n);
|
|
156
172
|
}
|
|
157
173
|
}
|
|
158
174
|
handleFrame(e) {
|
|
@@ -209,9 +225,9 @@ var u = class {
|
|
|
209
225
|
}, this.reconnectDelayMs);
|
|
210
226
|
}
|
|
211
227
|
};
|
|
212
|
-
function
|
|
228
|
+
function v(e) {
|
|
213
229
|
let t = e.readyState;
|
|
214
230
|
return t === void 0 || t === 0 || t === 1;
|
|
215
231
|
}
|
|
216
232
|
//#endregion
|
|
217
|
-
export {
|
|
233
|
+
export { _ as EliasseSocket, g as applyEliasseDerouleurUpdate, m as compareEliasseOrdre, a as eliasseDefaultSocketUrl, o as eliasseDerouleurUpdatePlaceSchema, s as eliasseDerouleurUpdateSchema };
|