@tricoteuses/assemblee 3.4.0 → 3.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.
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { EliasseDerouleur, EliasseDerouleurAmendement, EliasseProchainADiscuter, EliasseStatistiques } from './eliasse.js';
|
|
2
|
+
export declare const eliasseDefaultSocketUrl = "wss://eliasse.assemblee-nationale.fr/ws-eliasse";
|
|
3
|
+
export interface EliasseDerouleurUpdatePlace {
|
|
4
|
+
id: string;
|
|
5
|
+
libelle?: string;
|
|
6
|
+
amendements: EliasseDerouleurAmendement[];
|
|
7
|
+
}
|
|
8
|
+
export interface EliasseDerouleurUpdate {
|
|
9
|
+
version: number;
|
|
10
|
+
places: EliasseDerouleurUpdatePlace[];
|
|
11
|
+
}
|
|
12
|
+
interface WebSocketLike {
|
|
13
|
+
send(data: string): void;
|
|
14
|
+
close(code?: number, reason?: string): void;
|
|
15
|
+
onopen: (() => void) | null;
|
|
16
|
+
onmessage: ((event: {
|
|
17
|
+
data: unknown;
|
|
18
|
+
}) => void) | null;
|
|
19
|
+
onclose: ((event: {
|
|
20
|
+
code?: number;
|
|
21
|
+
reason?: string;
|
|
22
|
+
}) => void) | null;
|
|
23
|
+
onerror: ((event?: unknown) => void) | null;
|
|
24
|
+
}
|
|
25
|
+
type WebSocketConstructor = new (url: string | URL, protocols?: string | string[]) => WebSocketLike;
|
|
26
|
+
export type EliasseSocketStatus = "connecting" | "connected" | "disconnected";
|
|
27
|
+
export interface EliasseSocketOptions {
|
|
28
|
+
socketUrl?: string;
|
|
29
|
+
heartbeatMs?: number;
|
|
30
|
+
reconnectDelayMs?: number;
|
|
31
|
+
WebSocket?: WebSocketConstructor;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compare two dérouleur `ordre` keys exactly like the Eliasse front end
|
|
35
|
+
* (`localeCompare` with locale "fr" and numeric ordering).
|
|
36
|
+
*/
|
|
37
|
+
export declare function compareEliasseOrdre(left: string, right: string): number;
|
|
38
|
+
/**
|
|
39
|
+
* Merge a partial dérouleur update (a WebSocket
|
|
40
|
+
* `/topic/get-derouleur-update/{uidExamen}` payload) into the current state:
|
|
41
|
+
*
|
|
42
|
+
* - places are matched by `id`, amendements by `uid`;
|
|
43
|
+
* - an amendement sent with `estVisible: false` is removed;
|
|
44
|
+
* - a place left without amendement is removed;
|
|
45
|
+
* - places and amendements are sorted by `ordre`, like the front end;
|
|
46
|
+
* - the resulting `version` is the one of the update.
|
|
47
|
+
*/
|
|
48
|
+
export declare function applyEliasseDerouleurUpdate(current: EliasseDerouleur, update: EliasseDerouleurUpdate): EliasseDerouleur;
|
|
49
|
+
export declare class EliasseSocket {
|
|
50
|
+
readonly socketUrl: string;
|
|
51
|
+
readonly heartbeatMs: number;
|
|
52
|
+
readonly reconnectDelayMs: number;
|
|
53
|
+
onStatusChange?: (status: EliasseSocketStatus) => void;
|
|
54
|
+
onError?: (error: Error) => void;
|
|
55
|
+
private WebSocketConstructor;
|
|
56
|
+
private ws?;
|
|
57
|
+
private buffer;
|
|
58
|
+
private statusValue;
|
|
59
|
+
private userClosed;
|
|
60
|
+
private subscriptions;
|
|
61
|
+
private subscriptionCounter;
|
|
62
|
+
private disconnectReceipt?;
|
|
63
|
+
private outgoingHeartbeat?;
|
|
64
|
+
private incomingWatchdog?;
|
|
65
|
+
constructor(options?: EliasseSocketOptions);
|
|
66
|
+
get status(): EliasseSocketStatus;
|
|
67
|
+
get webSocket(): WebSocketLike | undefined;
|
|
68
|
+
connect(): void;
|
|
69
|
+
disconnect(): Promise<void>;
|
|
70
|
+
watchProchainsADiscuter(handler: (prochains: EliasseProchainADiscuter[]) => void): () => void;
|
|
71
|
+
watchDerouleur(uidExamen: string, handler: (update: EliasseDerouleurUpdate) => void): () => void;
|
|
72
|
+
watchStatistiques(uidExamen: string, handler: (statistiques: EliasseStatistiques) => void): () => void;
|
|
73
|
+
watch<T>(destination: string, handler: (body: T) => void): () => void;
|
|
74
|
+
private setStatus;
|
|
75
|
+
private sendSubscribe;
|
|
76
|
+
private handleData;
|
|
77
|
+
private handleFrame;
|
|
78
|
+
private startHeartbeats;
|
|
79
|
+
private stopHeartbeats;
|
|
80
|
+
private resetIncomingWatchdog;
|
|
81
|
+
private handleClose;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
//#region src/eliasse-socket.ts
|
|
2
|
+
var e = "wss://eliasse.assemblee-nationale.fr/ws-eliasse", t = "\0";
|
|
3
|
+
function n(e) {
|
|
4
|
+
return e.replace(/\\/g, "\\\\").replace(/:/g, "\\c").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
|
|
5
|
+
}
|
|
6
|
+
function r(e) {
|
|
7
|
+
return e.replace(/\\r/g, "\r").replace(/\\n/g, "\n").replace(/\\c/g, ":").replace(/\\\\/g, "\\");
|
|
8
|
+
}
|
|
9
|
+
function i(e, r, i = "") {
|
|
10
|
+
let a = [e];
|
|
11
|
+
for (let [e, t] of Object.entries(r)) a.push(`${n(e)}:${n(t)}`);
|
|
12
|
+
return `${a.join("\n")}\n\n${i}${t}`;
|
|
13
|
+
}
|
|
14
|
+
function a(e) {
|
|
15
|
+
let t = e.startsWith("\n") ? e.slice(1) : e;
|
|
16
|
+
if (t.trim() === "") return;
|
|
17
|
+
let n = t.indexOf("\n\n"), i = n === -1 ? t : t.slice(0, n), a = n === -1 ? "" : t.slice(n + 2), o = i.split("\n"), s = o[0] ?? "";
|
|
18
|
+
if (s === "") return;
|
|
19
|
+
let c = {};
|
|
20
|
+
for (let e of o.slice(1)) {
|
|
21
|
+
let t = e.indexOf(":");
|
|
22
|
+
t !== -1 && (c[r(e.slice(0, t))] = r(e.slice(t + 1)));
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
command: s,
|
|
26
|
+
headers: c,
|
|
27
|
+
body: a
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var o = new Intl.Collator("fr", { numeric: !0 });
|
|
31
|
+
function s(e, t) {
|
|
32
|
+
return o.compare(e, t);
|
|
33
|
+
}
|
|
34
|
+
function c(e, t) {
|
|
35
|
+
return s(e.ordre ?? "", t.ordre ?? "");
|
|
36
|
+
}
|
|
37
|
+
function l(e, t) {
|
|
38
|
+
let n = new Map(e.places.map((e) => [e.id, e]));
|
|
39
|
+
for (let e of t.places) {
|
|
40
|
+
let t = n.get(e.id);
|
|
41
|
+
if (t === void 0) {
|
|
42
|
+
let t = (e.amendements ?? []).filter((e) => e.estVisible !== !1).sort(c);
|
|
43
|
+
t.length > 0 && n.set(e.id, {
|
|
44
|
+
...e,
|
|
45
|
+
amendements: t
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
let r = new Map(t.amendements.map((e) => [e.uid, e]));
|
|
49
|
+
for (let t of e.amendements ?? []) t.estVisible === !1 ? r.delete(t.uid) : r.set(t.uid, t);
|
|
50
|
+
let i = [...r.values()].sort(c);
|
|
51
|
+
i.length > 0 ? n.set(t.id, {
|
|
52
|
+
...t,
|
|
53
|
+
amendements: i
|
|
54
|
+
}) : n.delete(t.id);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let r = [...n.values()].sort((e, t) => {
|
|
58
|
+
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 : s(n.ordre, r.ordre);
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
...e,
|
|
63
|
+
version: t.version,
|
|
64
|
+
places: r
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var u = class {
|
|
68
|
+
constructor(e = {}) {
|
|
69
|
+
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
|
+
let t = e.WebSocket ?? globalThis.WebSocket;
|
|
71
|
+
if (t === void 0) throw Error("WebSocket is not available: use a browser or Node.js >= 22, or provide options.WebSocket.");
|
|
72
|
+
this.WebSocketConstructor = t;
|
|
73
|
+
}
|
|
74
|
+
get status() {
|
|
75
|
+
return this.statusValue;
|
|
76
|
+
}
|
|
77
|
+
get webSocket() {
|
|
78
|
+
return this.ws;
|
|
79
|
+
}
|
|
80
|
+
connect() {
|
|
81
|
+
if (this.ws !== void 0 && d(this.ws)) return;
|
|
82
|
+
this.userClosed = !1, this.buffer = "", this.setStatus("connecting");
|
|
83
|
+
let e = new this.WebSocketConstructor(this.socketUrl);
|
|
84
|
+
this.ws = e, e.onopen = () => {
|
|
85
|
+
e.send(i("CONNECT", {
|
|
86
|
+
"accept-version": "1.2",
|
|
87
|
+
"heart-beat": `${this.heartbeatMs},${this.heartbeatMs}`
|
|
88
|
+
}));
|
|
89
|
+
}, e.onmessage = (e) => {
|
|
90
|
+
this.handleData(typeof e.data == "string" ? e.data : "");
|
|
91
|
+
}, e.onclose = () => {
|
|
92
|
+
this.handleClose();
|
|
93
|
+
}, e.onerror = () => {};
|
|
94
|
+
}
|
|
95
|
+
async disconnect() {
|
|
96
|
+
this.userClosed = !0, this.stopHeartbeats();
|
|
97
|
+
let e = this.ws;
|
|
98
|
+
if (e === void 0) {
|
|
99
|
+
this.setStatus("disconnected");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
let t = new Promise((t) => {
|
|
103
|
+
let n = e.onclose;
|
|
104
|
+
e.onclose = (e) => {
|
|
105
|
+
n?.(e), t();
|
|
106
|
+
};
|
|
107
|
+
}), n = `eliasse-disconnect-${++this.subscriptionCounter}`;
|
|
108
|
+
this.disconnectReceipt = n;
|
|
109
|
+
try {
|
|
110
|
+
e.send(i("DISCONNECT", { receipt: n }));
|
|
111
|
+
} catch {}
|
|
112
|
+
let r = new Promise((e) => setTimeout(e, 1e3));
|
|
113
|
+
await Promise.race([t, r]);
|
|
114
|
+
try {
|
|
115
|
+
e.close();
|
|
116
|
+
} catch {}
|
|
117
|
+
this.ws === e && (this.ws = void 0), this.setStatus("disconnected");
|
|
118
|
+
}
|
|
119
|
+
watchProchainsADiscuter(e) {
|
|
120
|
+
return this.watch("/topic/get-all-prochains-a-discuter", e);
|
|
121
|
+
}
|
|
122
|
+
watchDerouleur(e, t) {
|
|
123
|
+
return this.watch(`/topic/get-derouleur-update/${e}`, t);
|
|
124
|
+
}
|
|
125
|
+
watchStatistiques(e, t) {
|
|
126
|
+
return this.watch(`/topic/get-statistiques-update/${e}`, t);
|
|
127
|
+
}
|
|
128
|
+
watch(e, t) {
|
|
129
|
+
let n = `eliasse-sub-${++this.subscriptionCounter}`;
|
|
130
|
+
return this.subscriptions.set(n, {
|
|
131
|
+
destination: e,
|
|
132
|
+
handler: t
|
|
133
|
+
}), this.statusValue === "connected" && this.sendSubscribe(n, e), () => {
|
|
134
|
+
this.subscriptions.delete(n), this.statusValue === "connected" && this.ws !== void 0 && this.ws.send(i("UNSUBSCRIBE", { id: n }));
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
setStatus(e) {
|
|
138
|
+
this.statusValue !== e && (this.statusValue = e, this.onStatusChange?.(e));
|
|
139
|
+
}
|
|
140
|
+
sendSubscribe(e, t) {
|
|
141
|
+
this.ws?.send(i("SUBSCRIBE", {
|
|
142
|
+
id: e,
|
|
143
|
+
destination: t,
|
|
144
|
+
ack: "auto"
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
handleData(e) {
|
|
148
|
+
if (this.resetIncomingWatchdog(), e.trim() === "") return;
|
|
149
|
+
this.buffer += e;
|
|
150
|
+
let n;
|
|
151
|
+
for (; (n = this.buffer.indexOf(t)) !== -1;) {
|
|
152
|
+
let e = this.buffer.slice(0, n);
|
|
153
|
+
this.buffer = this.buffer.slice(n + 1);
|
|
154
|
+
let t = a(e);
|
|
155
|
+
t !== void 0 && this.handleFrame(t);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
handleFrame(e) {
|
|
159
|
+
switch (e.command) {
|
|
160
|
+
case "CONNECTED":
|
|
161
|
+
this.startHeartbeats(e.headers["heart-beat"]), this.setStatus("connected");
|
|
162
|
+
for (let [e, t] of this.subscriptions) this.sendSubscribe(e, t.destination);
|
|
163
|
+
break;
|
|
164
|
+
case "MESSAGE": {
|
|
165
|
+
let t = this.subscriptions.get(e.headers.id ?? "");
|
|
166
|
+
if (t === void 0) break;
|
|
167
|
+
let n;
|
|
168
|
+
try {
|
|
169
|
+
n = JSON.parse(e.body);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
this.onError?.(/* @__PURE__ */ Error(`Invalid JSON received from ${t.destination}: ${e instanceof Error ? e.message : e}`));
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
t.handler(n);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "ERROR": {
|
|
178
|
+
let t = e.headers.message ?? "";
|
|
179
|
+
this.onError?.(/* @__PURE__ */ Error(`STOMP ERROR${t === "" ? "" : ` (${t})`}: ${e.body}`));
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "RECEIPT":
|
|
183
|
+
this.disconnectReceipt !== void 0 && e.headers["receipt-id"] === this.disconnectReceipt && this.ws?.close();
|
|
184
|
+
break;
|
|
185
|
+
default: break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
startHeartbeats(e) {
|
|
189
|
+
let [t = 0, n = 0] = (e ?? "0,0").split(",").map((e) => Number(e.trim())), r = this.heartbeatMs > 0 && n > 0 ? Math.max(this.heartbeatMs, n) : 0, i = this.heartbeatMs > 0 && t > 0 ? Math.max(this.heartbeatMs, t) * 2 : 0;
|
|
190
|
+
r > 0 && (this.outgoingHeartbeat = setInterval(() => {
|
|
191
|
+
try {
|
|
192
|
+
this.ws?.send("\n");
|
|
193
|
+
} catch {}
|
|
194
|
+
}, r)), i > 0 && (this.incomingWatchdog = setTimeout(() => {
|
|
195
|
+
this.ws?.close();
|
|
196
|
+
}, i));
|
|
197
|
+
}
|
|
198
|
+
stopHeartbeats() {
|
|
199
|
+
this.outgoingHeartbeat !== void 0 && (clearInterval(this.outgoingHeartbeat), this.outgoingHeartbeat = void 0), this.incomingWatchdog !== void 0 && (clearTimeout(this.incomingWatchdog), this.incomingWatchdog = void 0);
|
|
200
|
+
}
|
|
201
|
+
resetIncomingWatchdog() {
|
|
202
|
+
this.incomingWatchdog !== void 0 && (clearTimeout(this.incomingWatchdog), this.incomingWatchdog = setTimeout(() => {
|
|
203
|
+
this.ws?.close();
|
|
204
|
+
}, this.heartbeatMs * 2));
|
|
205
|
+
}
|
|
206
|
+
handleClose() {
|
|
207
|
+
this.stopHeartbeats(), this.disconnectReceipt = void 0, this.ws !== void 0 && (this.ws = void 0), this.setStatus("disconnected"), this.userClosed || setTimeout(() => {
|
|
208
|
+
this.userClosed || this.connect();
|
|
209
|
+
}, this.reconnectDelayMs);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
function d(e) {
|
|
213
|
+
let t = e.readyState;
|
|
214
|
+
return t === void 0 || t === 0 || t === 1;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
export { u as EliasseSocket, l as applyEliasseDerouleurUpdate, s as compareEliasseOrdre, e as eliasseDefaultSocketUrl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/parsers.js
CHANGED
|
@@ -4,7 +4,7 @@ import o from "node:assert";
|
|
|
4
4
|
import s from "fs-extra";
|
|
5
5
|
import c from "node:path";
|
|
6
6
|
import l from "deep-equal";
|
|
7
|
-
import u from "js-yaml";
|
|
7
|
+
import * as u from "js-yaml";
|
|
8
8
|
import { parse as d } from "node-html-parser";
|
|
9
9
|
//#region \0rolldown/runtime.js
|
|
10
10
|
var f = Object.create, p = Object.defineProperty, ee = Object.getOwnPropertyDescriptor, m = Object.getOwnPropertyNames, h = Object.getPrototypeOf, g = Object.prototype.hasOwnProperty, _ = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), v = (e, t) => {
|
|
@@ -29,6 +29,10 @@ declare const retrieveDocumentsParser: import('zod-opts').Parser<{
|
|
|
29
29
|
description: string;
|
|
30
30
|
type: z.ZodOptional<z.ZodString>;
|
|
31
31
|
};
|
|
32
|
+
documentUids: {
|
|
33
|
+
description: string;
|
|
34
|
+
type: z.ZodOptional<z.ZodString>;
|
|
35
|
+
};
|
|
32
36
|
categories: {
|
|
33
37
|
alias: string;
|
|
34
38
|
description: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tricoteuses/assemblee",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Retrieve, clean up & handle French Assemblée nationale's open data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Assemblée nationale",
|
|
@@ -58,6 +58,11 @@
|
|
|
58
58
|
"import": "./lib/eliasse.js",
|
|
59
59
|
"types": "./lib/eliasse.d.ts"
|
|
60
60
|
},
|
|
61
|
+
"./eliasse-socket": {
|
|
62
|
+
"typedoc": "./src/eliasse-socket.ts",
|
|
63
|
+
"import": "./lib/eliasse-socket.js",
|
|
64
|
+
"types": "./lib/eliasse-socket.d.ts"
|
|
65
|
+
},
|
|
61
66
|
"./git": {
|
|
62
67
|
"typedoc": "./src/git.ts",
|
|
63
68
|
"import": "./lib/git.js",
|