@tricoteuses/assemblee 3.5.0 → 3.6.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/lib/{amendements-D2X2TneW.js → amendements-BYKlEcWb.js} +1 -1
- package/lib/{amendements-DSXfagiR.js → amendements-CvlD2dI4.js} +10 -12
- package/lib/cleaners.js +3 -3
- package/lib/derouleur.js +1 -1
- package/lib/eliasse-socket.d.ts +30 -34
- package/lib/eliasse-socket.js +92 -157
- package/lib/eliasse-sync.d.ts +65 -0
- package/lib/eliasse-sync.js +100 -0
- package/lib/eliasse-sync.test.d.ts +1 -0
- package/lib/eliasse.js +1 -1
- package/lib/git.js +1 -1
- package/lib/index.js +3 -6
- package/lib/{loaders-DYFDjudN.js → loaders-BNXs79lC.js} +2 -2
- package/lib/loaders.js +1 -1
- package/lib/parsers/dossier_annexes.d.ts +36 -0
- package/lib/parsers/dossier_annexes.test.d.ts +1 -0
- package/lib/parsers.js +425 -469
- package/lib/registries.d.ts +8 -8
- package/lib/schemas/clean/acteurs_et_organes.d.ts +37 -37
- package/lib/schemas/clean/amendements.d.ts +12 -12
- package/lib/schemas/clean/debats.d.ts +26 -26
- package/lib/schemas/clean/dossiers_legislatifs.d.ts +16 -16
- package/lib/schemas/clean/questions.d.ts +122 -122
- package/lib/schemas/clean/scrutins.d.ts +2 -2
- package/lib/schemas/enriched/acteurs_et_organes.d.ts +2 -2
- package/lib/schemas/enriched/amendements.d.ts +9 -9
- package/lib/schemas/enriched/dossiers_legislatifs.d.ts +12 -12
- package/lib/schemas/enriched/questions.d.ts +108 -108
- package/lib/schemas/enriched/scrutins.d.ts +2 -2
- package/lib/schemas/raw/acteurs_et_organes.d.ts +132 -132
- package/lib/schemas/raw/agendas.d.ts +97 -97
- package/lib/schemas/raw/amendements.d.ts +83 -83
- package/lib/schemas/raw/debats.d.ts +51 -51
- package/lib/schemas/raw/dossiers_legislatifs.d.ts +171 -171
- package/lib/schemas/raw/questions.d.ts +222 -222
- package/lib/schemas/raw/scrutins.d.ts +164 -164
- package/lib/scripts/retrieve_dossier_annexes.d.ts +110 -0
- package/lib/scripts/shared/utils.d.ts +9 -0
- package/lib/{scrutins-CGHd_VPY.js → scrutins-BUVxV-QV.js} +2 -2
- package/lib/zod_errors-qS8sQ67W.js +32 -0
- package/package.json +8 -1
- package/lib/zod_errors-DCnjCNGy.js +0 -34
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as e } from "./zod_errors-
|
|
1
|
+
import { t as e } from "./zod_errors-qS8sQ67W.js";
|
|
2
2
|
import { z as t } from "zod";
|
|
3
3
|
//#region node_modules/date-fns/locale/en-US/_lib/formatDistance.js
|
|
4
4
|
var n = {
|
|
@@ -502,7 +502,7 @@ function p() {
|
|
|
502
502
|
}
|
|
503
503
|
//#endregion
|
|
504
504
|
//#region node_modules/date-fns/constants.js
|
|
505
|
-
var re = 365.2425, ie = 6048e5, ae = 864e5, oe = 6e4, m = 36e5, se = 1e3, ce =
|
|
505
|
+
var re = 365.2425, ie = 6048e5, ae = 864e5, oe = 6e4, m = 36e5, se = 1e3, ce = 86400;
|
|
506
506
|
ce * 7, ce * re / 12 * 3;
|
|
507
507
|
var le = Symbol.for("constructDateFrom");
|
|
508
508
|
//#endregion
|
|
@@ -519,7 +519,7 @@ function g(e, t) {
|
|
|
519
519
|
//#region node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js
|
|
520
520
|
function _(e) {
|
|
521
521
|
let t = g(e), n = new Date(Date.UTC(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), t.getMilliseconds()));
|
|
522
|
-
return n.setUTCFullYear(t.getFullYear()), e -
|
|
522
|
+
return n.setUTCFullYear(t.getFullYear()), +e - n;
|
|
523
523
|
}
|
|
524
524
|
//#endregion
|
|
525
525
|
//#region node_modules/date-fns/_lib/normalizeDates.js
|
|
@@ -584,7 +584,7 @@ function ge(e, t) {
|
|
|
584
584
|
//#endregion
|
|
585
585
|
//#region node_modules/date-fns/getISOWeek.js
|
|
586
586
|
function _e(e, t) {
|
|
587
|
-
let n = g(e, t?.in), r = y(n) -
|
|
587
|
+
let n = g(e, t?.in), r = +y(n) - ge(n);
|
|
588
588
|
return Math.round(r / ie) + 1;
|
|
589
589
|
}
|
|
590
590
|
//#endregion
|
|
@@ -606,7 +606,7 @@ function ve(e, t) {
|
|
|
606
606
|
//#endregion
|
|
607
607
|
//#region node_modules/date-fns/getWeek.js
|
|
608
608
|
function ye(e, t) {
|
|
609
|
-
let n = g(e, t?.in), r = v(n, t) -
|
|
609
|
+
let n = g(e, t?.in), r = +v(n, t) - ve(n, t);
|
|
610
610
|
return Math.round(r / ie) + 1;
|
|
611
611
|
}
|
|
612
612
|
//#endregion
|
|
@@ -1058,9 +1058,7 @@ var Ce = (e, t) => {
|
|
|
1058
1058
|
case "PPP":
|
|
1059
1059
|
a = t.dateTime({ width: "long" });
|
|
1060
1060
|
break;
|
|
1061
|
-
default:
|
|
1062
|
-
a = t.dateTime({ width: "full" });
|
|
1063
|
-
break;
|
|
1061
|
+
default: a = t.dateTime({ width: "full" });
|
|
1064
1062
|
}
|
|
1065
1063
|
return a.replace("{{date}}", Ce(r, t)).replace("{{time}}", we(i, t));
|
|
1066
1064
|
}
|
|
@@ -1565,7 +1563,7 @@ function $e(e) {
|
|
|
1565
1563
|
return typeof e == "function" && e.prototype?.constructor === e;
|
|
1566
1564
|
}
|
|
1567
1565
|
//#endregion
|
|
1568
|
-
//#region \0@oxc-project+runtime@0.
|
|
1566
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
|
|
1569
1567
|
function k(e) {
|
|
1570
1568
|
"@babel/helpers - typeof";
|
|
1571
1569
|
return k = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
@@ -1575,7 +1573,7 @@ function k(e) {
|
|
|
1575
1573
|
}, k(e);
|
|
1576
1574
|
}
|
|
1577
1575
|
//#endregion
|
|
1578
|
-
//#region \0@oxc-project+runtime@0.
|
|
1576
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPrimitive.js
|
|
1579
1577
|
function et(e, t) {
|
|
1580
1578
|
if (k(e) != "object" || !e) return e;
|
|
1581
1579
|
var n = e[Symbol.toPrimitive];
|
|
@@ -1587,13 +1585,13 @@ function et(e, t) {
|
|
|
1587
1585
|
return (t === "string" ? String : Number)(e);
|
|
1588
1586
|
}
|
|
1589
1587
|
//#endregion
|
|
1590
|
-
//#region \0@oxc-project+runtime@0.
|
|
1588
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPropertyKey.js
|
|
1591
1589
|
function tt(e) {
|
|
1592
1590
|
var t = et(e, "string");
|
|
1593
1591
|
return k(t) == "symbol" ? t : t + "";
|
|
1594
1592
|
}
|
|
1595
1593
|
//#endregion
|
|
1596
|
-
//#region \0@oxc-project+runtime@0.
|
|
1594
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/defineProperty.js
|
|
1597
1595
|
function A(e, t, n) {
|
|
1598
1596
|
return (t = tt(t)) in e ? Object.defineProperty(e, t, {
|
|
1599
1597
|
value: n,
|
package/lib/cleaners.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { At as e, cr as t, tr as n } from "./scrutins-
|
|
2
|
-
import { i as r, n as i, r as a, t as o } from "./amendements-
|
|
3
|
-
import "./loaders-
|
|
1
|
+
import { At as e, cr as t, tr as n } from "./scrutins-BUVxV-QV.js";
|
|
2
|
+
import { i as r, n as i, r as a, t as o } from "./amendements-BYKlEcWb.js";
|
|
3
|
+
import "./loaders-BNXs79lC.js";
|
|
4
4
|
import s from "node:assert";
|
|
5
5
|
import "fs-extra";
|
|
6
6
|
import "node:path";
|
package/lib/derouleur.js
CHANGED
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,25 @@ 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>;
|
|
15
|
+
/**
|
|
16
|
+
* Compare two dérouleur `ordre` keys exactly like the Eliasse front end
|
|
17
|
+
* (`localeCompare` with locale "fr" and numeric ordering).
|
|
18
|
+
*/
|
|
19
|
+
export declare function compareEliasseOrdre(left: string, right: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Merge a partial dérouleur update (a WebSocket
|
|
22
|
+
* `/topic/get-derouleur-update/{uidExamen}` payload) into the current state:
|
|
23
|
+
*
|
|
24
|
+
* - places are matched by `id`, amendements by `uid`;
|
|
25
|
+
* - an amendement sent with `estVisible: false` is removed;
|
|
26
|
+
* - a place left without amendement is removed;
|
|
27
|
+
* - places and amendements are sorted by `ordre`, like the front end;
|
|
28
|
+
* - the resulting `version` is the one of the update.
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyEliasseDerouleurUpdate(current: EliasseDerouleur, update: EliasseDerouleurUpdate): EliasseDerouleur;
|
|
31
|
+
/** Minimal WebSocket shape accepted by the constructor override. */
|
|
12
32
|
interface WebSocketLike {
|
|
13
33
|
send(data: string): void;
|
|
14
34
|
close(code?: number, reason?: string): void;
|
|
@@ -26,58 +46,34 @@ type WebSocketConstructor = new (url: string | URL, protocols?: string | string[
|
|
|
26
46
|
export type EliasseSocketStatus = "connecting" | "connected" | "disconnected";
|
|
27
47
|
export interface EliasseSocketOptions {
|
|
28
48
|
socketUrl?: string;
|
|
49
|
+
/** Requested heart-beat period; negotiation is handled by stompjs. */
|
|
29
50
|
heartbeatMs?: number;
|
|
30
51
|
reconnectDelayMs?: number;
|
|
31
52
|
WebSocket?: WebSocketConstructor;
|
|
32
53
|
}
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
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;
|
|
54
|
+
/** Browser-safe STOMP client. Framing, subscription routing, negotiated
|
|
55
|
+
* heart-beats, connection timeouts and reconnection are handled by stompjs. */
|
|
49
56
|
export declare class EliasseSocket {
|
|
50
57
|
readonly socketUrl: string;
|
|
51
58
|
readonly heartbeatMs: number;
|
|
52
59
|
readonly reconnectDelayMs: number;
|
|
53
60
|
onStatusChange?: (status: EliasseSocketStatus) => void;
|
|
54
61
|
onError?: (error: Error) => void;
|
|
55
|
-
private
|
|
56
|
-
private ws?;
|
|
57
|
-
private buffer;
|
|
62
|
+
private client;
|
|
58
63
|
private statusValue;
|
|
59
|
-
private userClosed;
|
|
60
|
-
private subscriptions;
|
|
61
64
|
private subscriptionCounter;
|
|
62
|
-
private
|
|
63
|
-
private outgoingHeartbeat?;
|
|
64
|
-
private incomingWatchdog?;
|
|
65
|
+
private subscriptions;
|
|
65
66
|
constructor(options?: EliasseSocketOptions);
|
|
66
67
|
get status(): EliasseSocketStatus;
|
|
67
68
|
get webSocket(): WebSocketLike | undefined;
|
|
68
69
|
connect(): void;
|
|
69
70
|
disconnect(): Promise<void>;
|
|
70
|
-
watchProchainsADiscuter(handler: (
|
|
71
|
-
watchDerouleur(uidExamen: string, handler: (
|
|
72
|
-
watchStatistiques(uidExamen: string, handler: (
|
|
71
|
+
watchProchainsADiscuter(handler: (body: EliasseProchainADiscuter[]) => void): () => void;
|
|
72
|
+
watchDerouleur(uidExamen: string, handler: (body: EliasseDerouleurUpdate) => void): () => void;
|
|
73
|
+
watchStatistiques(uidExamen: string, handler: (body: EliasseStatistiques) => void): () => void;
|
|
74
|
+
private validatingHandler;
|
|
73
75
|
watch<T>(destination: string, handler: (body: T) => void): () => void;
|
|
76
|
+
private subscribe;
|
|
74
77
|
private setStatus;
|
|
75
|
-
private sendSubscribe;
|
|
76
|
-
private handleData;
|
|
77
|
-
private handleFrame;
|
|
78
|
-
private startHeartbeats;
|
|
79
|
-
private stopHeartbeats;
|
|
80
|
-
private resetIncomingWatchdog;
|
|
81
|
-
private handleClose;
|
|
82
78
|
}
|
|
83
79
|
export {};
|
package/lib/eliasse-socket.js
CHANGED
|
@@ -1,45 +1,36 @@
|
|
|
1
|
+
import { t as e } from "./zod_errors-qS8sQ67W.js";
|
|
2
|
+
import { eliasseDerouleurAmendementSchema as t, eliasseProchainADiscuterSchema as n, eliasseStatistiquesSchema as r } from "./eliasse.js";
|
|
3
|
+
import { z as i } from "zod";
|
|
4
|
+
import { Client as a } from "@stomp/stompjs";
|
|
1
5
|
//#region src/eliasse-socket.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
var o = "wss://eliasse.assemblee-nationale.fr/ws-eliasse", s = i.object({
|
|
7
|
+
id: i.string(),
|
|
8
|
+
libelle: i.string().optional(),
|
|
9
|
+
amendements: i.array(t)
|
|
10
|
+
}), c = i.object({
|
|
11
|
+
version: i.number(),
|
|
12
|
+
places: i.array(s)
|
|
13
|
+
}), l = new Intl.Collator("fr", { numeric: !0 });
|
|
14
|
+
function u(e, t) {
|
|
15
|
+
return l.compare(e, t);
|
|
5
16
|
}
|
|
6
|
-
function
|
|
7
|
-
return e.
|
|
17
|
+
function d(e, t) {
|
|
18
|
+
return u(e.ordre ?? "", t.ordre ?? "");
|
|
8
19
|
}
|
|
9
|
-
function
|
|
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) {
|
|
20
|
+
function f(e, t) {
|
|
38
21
|
let n = new Map(e.places.map((e) => [e.id, e]));
|
|
22
|
+
for (let e of t.places) for (let t of e.amendements) for (let [r, i] of n) {
|
|
23
|
+
if (r === e.id || !i.amendements.some((e) => e.uid === t.uid)) continue;
|
|
24
|
+
let a = i.amendements.filter((e) => e.uid !== t.uid);
|
|
25
|
+
a.length === 0 ? n.delete(r) : n.set(r, {
|
|
26
|
+
...i,
|
|
27
|
+
amendements: a
|
|
28
|
+
});
|
|
29
|
+
}
|
|
39
30
|
for (let e of t.places) {
|
|
40
31
|
let t = n.get(e.id);
|
|
41
32
|
if (t === void 0) {
|
|
42
|
-
let t = (e.amendements ?? []).filter((e) => e.estVisible !== !1).sort(
|
|
33
|
+
let t = (e.amendements ?? []).filter((e) => e.estVisible !== !1).sort(d);
|
|
43
34
|
t.length > 0 && n.set(e.id, {
|
|
44
35
|
...e,
|
|
45
36
|
amendements: t
|
|
@@ -47,16 +38,17 @@ function l(e, t) {
|
|
|
47
38
|
} else {
|
|
48
39
|
let r = new Map(t.amendements.map((e) => [e.uid, e]));
|
|
49
40
|
for (let t of e.amendements ?? []) t.estVisible === !1 ? r.delete(t.uid) : r.set(t.uid, t);
|
|
50
|
-
let i = [...r.values()].sort(
|
|
41
|
+
let i = [...r.values()].sort(d);
|
|
51
42
|
i.length > 0 ? n.set(t.id, {
|
|
52
43
|
...t,
|
|
44
|
+
...e,
|
|
53
45
|
amendements: i
|
|
54
46
|
}) : n.delete(t.id);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
let r = [...n.values()].sort((e, t) => {
|
|
58
50
|
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 :
|
|
51
|
+
return n === void 0 && r === void 0 ? 0 : n === void 0 ? 1 : r === void 0 ? -1 : u(n.ordre, r.ordre);
|
|
60
52
|
});
|
|
61
53
|
return {
|
|
62
54
|
...e,
|
|
@@ -64,154 +56,97 @@ function l(e, t) {
|
|
|
64
56
|
places: r
|
|
65
57
|
};
|
|
66
58
|
}
|
|
67
|
-
var
|
|
59
|
+
var p = class {
|
|
68
60
|
constructor(e = {}) {
|
|
69
|
-
this.
|
|
61
|
+
this.statusValue = "disconnected", this.subscriptionCounter = 0, this.subscriptions = /* @__PURE__ */ new Map(), this.socketUrl = e.socketUrl ?? "wss://eliasse.assemblee-nationale.fr/ws-eliasse", this.heartbeatMs = e.heartbeatMs ?? 4e3, this.reconnectDelayMs = e.reconnectDelayMs ?? 5e3;
|
|
70
62
|
let t = e.WebSocket ?? globalThis.WebSocket;
|
|
71
63
|
if (t === void 0) throw Error("WebSocket is not available: use a browser or Node.js >= 22, or provide options.WebSocket.");
|
|
72
|
-
this.
|
|
64
|
+
this.client = new a({
|
|
65
|
+
webSocketFactory: () => new t(this.socketUrl, ["v12.stomp"]),
|
|
66
|
+
connectHeaders: { host: new URL(this.socketUrl).hostname },
|
|
67
|
+
reconnectDelay: this.reconnectDelayMs,
|
|
68
|
+
connectionTimeout: 15e3,
|
|
69
|
+
heartbeatIncoming: this.heartbeatMs,
|
|
70
|
+
heartbeatOutgoing: this.heartbeatMs,
|
|
71
|
+
beforeConnect: () => this.setStatus("connecting"),
|
|
72
|
+
onConnect: () => {
|
|
73
|
+
for (let [e, t] of this.subscriptions) this.subscribe(e, t);
|
|
74
|
+
this.setStatus("connected");
|
|
75
|
+
},
|
|
76
|
+
onWebSocketClose: () => {
|
|
77
|
+
for (let e of this.subscriptions.values()) e.active = void 0;
|
|
78
|
+
this.setStatus("disconnected");
|
|
79
|
+
},
|
|
80
|
+
onWebSocketError: () => this.onError?.(/* @__PURE__ */ Error("Eliasse WebSocket transport error")),
|
|
81
|
+
onStompError: (e) => this.onError?.(/* @__PURE__ */ Error(`STOMP ERROR (${e.headers.message ?? ""}): ${e.body}`))
|
|
82
|
+
});
|
|
73
83
|
}
|
|
74
84
|
get status() {
|
|
75
85
|
return this.statusValue;
|
|
76
86
|
}
|
|
77
87
|
get webSocket() {
|
|
78
|
-
return this.
|
|
88
|
+
return this.client.webSocket;
|
|
79
89
|
}
|
|
80
90
|
connect() {
|
|
81
|
-
|
|
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 = () => {};
|
|
91
|
+
this.client.activate();
|
|
94
92
|
}
|
|
95
93
|
async disconnect() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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]);
|
|
94
|
+
let e = setTimeout(() => {
|
|
95
|
+
this.client.deactivate({ force: !0 });
|
|
96
|
+
}, 1e3);
|
|
114
97
|
try {
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
98
|
+
await this.client.deactivate();
|
|
99
|
+
} finally {
|
|
100
|
+
clearTimeout(e), this.setStatus("disconnected");
|
|
101
|
+
}
|
|
118
102
|
}
|
|
119
103
|
watchProchainsADiscuter(e) {
|
|
120
|
-
return this.watch("/topic/get-all-prochains-a-discuter", e);
|
|
104
|
+
return this.watch("/topic/get-all-prochains-a-discuter", this.validatingHandler("prochains à discuter", i.array(n), e));
|
|
121
105
|
}
|
|
122
106
|
watchDerouleur(e, t) {
|
|
123
|
-
return this.watch(`/topic/get-derouleur-update/${e}`, t);
|
|
107
|
+
return this.watch(`/topic/get-derouleur-update/${e}`, this.validatingHandler("dérouleur update", c, t));
|
|
124
108
|
}
|
|
125
109
|
watchStatistiques(e, t) {
|
|
126
|
-
return this.watch(`/topic/get-statistiques-update/${e}`, t);
|
|
110
|
+
return this.watch(`/topic/get-statistiques-update/${e}`, this.validatingHandler("statistiques", r, t));
|
|
111
|
+
}
|
|
112
|
+
validatingHandler(t, n, r) {
|
|
113
|
+
return (i) => {
|
|
114
|
+
let a = n.safeParse(i);
|
|
115
|
+
if (!a.success) {
|
|
116
|
+
this.onError?.(/* @__PURE__ */ Error(`Unexpected Eliasse WebSocket ${t} structure:\n${e(t, a.error, i)}`));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
r(i);
|
|
120
|
+
};
|
|
127
121
|
}
|
|
128
122
|
watch(e, t) {
|
|
129
|
-
let n = `eliasse-sub-${++this.subscriptionCounter}
|
|
130
|
-
return this.subscriptions.set(n, {
|
|
123
|
+
let n = `eliasse-sub-${++this.subscriptionCounter}`, r = {
|
|
131
124
|
destination: e,
|
|
132
125
|
handler: t
|
|
133
|
-
}
|
|
134
|
-
|
|
126
|
+
};
|
|
127
|
+
return this.subscriptions.set(n, r), this.client.connected && this.subscribe(n, r), () => {
|
|
128
|
+
this.subscriptions.get(n)?.active?.unsubscribe(), this.subscriptions.delete(n);
|
|
135
129
|
};
|
|
136
130
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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;
|
|
131
|
+
subscribe(e, t) {
|
|
132
|
+
t.active = this.client.subscribe(t.destination, (e) => {
|
|
133
|
+
let n;
|
|
134
|
+
try {
|
|
135
|
+
n = JSON.parse(e.body);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
this.onError?.(/* @__PURE__ */ Error(`Invalid JSON received from ${t.destination}: ${String(e)}`));
|
|
138
|
+
return;
|
|
181
139
|
}
|
|
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
140
|
try {
|
|
192
|
-
|
|
193
|
-
} catch {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
},
|
|
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));
|
|
141
|
+
t.handler(n);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
this.onError?.(e instanceof Error ? e : Error(String(e)));
|
|
144
|
+
}
|
|
145
|
+
}, { id: e });
|
|
205
146
|
}
|
|
206
|
-
|
|
207
|
-
this.
|
|
208
|
-
this.userClosed || this.connect();
|
|
209
|
-
}, this.reconnectDelayMs);
|
|
147
|
+
setStatus(e) {
|
|
148
|
+
this.statusValue !== e && (this.statusValue = e, this.onStatusChange?.(e));
|
|
210
149
|
}
|
|
211
150
|
};
|
|
212
|
-
function d(e) {
|
|
213
|
-
let t = e.readyState;
|
|
214
|
-
return t === void 0 || t === 0 || t === 1;
|
|
215
|
-
}
|
|
216
151
|
//#endregion
|
|
217
|
-
export {
|
|
152
|
+
export { p as EliasseSocket, f as applyEliasseDerouleurUpdate, u as compareEliasseOrdre, o as eliasseDefaultSocketUrl, s as eliasseDerouleurUpdatePlaceSchema, c as eliasseDerouleurUpdateSchema };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { EliasseAmendement, EliasseDerouleur, EliasseDerouleurAmendement, EliasseStatistiques } from './eliasse.js';
|
|
2
|
+
import { EliasseDerouleurUpdate } from './eliasse-socket.js';
|
|
3
|
+
export interface EliasseSyncTarget {
|
|
4
|
+
uidExamen: string;
|
|
5
|
+
uidTexte: string;
|
|
6
|
+
uidAmendement?: string | null;
|
|
7
|
+
}
|
|
8
|
+
export interface EliasseSyncRow {
|
|
9
|
+
amendement: EliasseDerouleurAmendement;
|
|
10
|
+
place: {
|
|
11
|
+
id: string;
|
|
12
|
+
libelle?: string | null;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface EliasseStoredAmendement {
|
|
16
|
+
uid: string;
|
|
17
|
+
row?: EliasseSyncRow;
|
|
18
|
+
detail?: EliasseAmendement;
|
|
19
|
+
present: boolean;
|
|
20
|
+
detailPending: boolean;
|
|
21
|
+
detailFetchedAt?: number;
|
|
22
|
+
detailRetryAt?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface EliasseSyncState {
|
|
25
|
+
/** Optional opaque optimistic-concurrency token managed by the repository. */
|
|
26
|
+
revision?: string;
|
|
27
|
+
derouleur?: EliasseDerouleur;
|
|
28
|
+
amendements: EliasseStoredAmendement[];
|
|
29
|
+
}
|
|
30
|
+
export interface EliasseSyncCounts {
|
|
31
|
+
stored: number;
|
|
32
|
+
/** Actual open data changes, not attempted writes. */
|
|
33
|
+
patched: number;
|
|
34
|
+
pendingDetails: number;
|
|
35
|
+
}
|
|
36
|
+
export interface EliasseSyncRepository {
|
|
37
|
+
load(uidExamen: string): Promise<EliasseSyncState>;
|
|
38
|
+
/** Must be atomic; a rejection must leave the previous checkpoint intact. */
|
|
39
|
+
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques): Promise<Omit<EliasseSyncCounts, "pendingDetails">>;
|
|
40
|
+
saveStatistics(uidExamen: string, statistiques: EliasseStatistiques): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface EliasseSynchronizerOptions {
|
|
43
|
+
repository: EliasseSyncRepository;
|
|
44
|
+
fetchDerouleur(target: EliasseSyncTarget): Promise<EliasseDerouleur>;
|
|
45
|
+
fetchStatistiques(target: EliasseSyncTarget): Promise<EliasseStatistiques>;
|
|
46
|
+
fetchDetails(target: EliasseSyncTarget, uids: string[]): Promise<Map<string, EliasseAmendement>>;
|
|
47
|
+
limit?: number;
|
|
48
|
+
detailRefreshMs?: number;
|
|
49
|
+
retryMs?: number;
|
|
50
|
+
now?: () => number;
|
|
51
|
+
onError?: (error: unknown) => void;
|
|
52
|
+
}
|
|
53
|
+
export declare function isEliasseKnownSort(sort: string | null | undefined): sort is string;
|
|
54
|
+
export declare class EliasseSynchronizer {
|
|
55
|
+
private options;
|
|
56
|
+
private tails;
|
|
57
|
+
constructor(options: EliasseSynchronizerOptions);
|
|
58
|
+
idle(): Promise<void>;
|
|
59
|
+
synchronize(target: EliasseSyncTarget): Promise<EliasseSyncCounts>;
|
|
60
|
+
applyUpdate(target: EliasseSyncTarget, update: EliasseDerouleurUpdate): Promise<EliasseSyncCounts>;
|
|
61
|
+
saveStatistics(uidExamen: string, statistiques: EliasseStatistiques): Promise<void>;
|
|
62
|
+
private enqueue;
|
|
63
|
+
private http;
|
|
64
|
+
private process;
|
|
65
|
+
}
|