@tricoteuses/assemblee 3.6.1 → 3.7.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/eliasse-CP5wde9Z.js +275 -0
- package/lib/eliasse-details.d.ts +14 -0
- package/lib/eliasse-details.test.d.ts +1 -0
- package/lib/eliasse-retry.d.ts +54 -0
- package/lib/eliasse-retry.test.d.ts +1 -0
- package/lib/eliasse-socket.d.ts +22 -0
- package/lib/eliasse-socket.js +62 -8
- package/lib/eliasse-sync.d.ts +31 -3
- package/lib/eliasse-sync.js +116 -46
- package/lib/eliasse.d.ts +1 -0
- package/lib/eliasse.js +2 -150
- package/lib/parsers.js +44 -39
- package/lib/scripts/prepare_targeted_documents.d.ts +1 -0
- package/lib/scripts/retrieve_documents.d.ts +4 -0
- package/lib/scripts/validate_targeted_document_content.d.ts +1 -0
- package/lib/targeted_documents.d.ts +14 -0
- package/lib/targeted_documents.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { t as e } from "./zod_errors-qS8sQ67W.js";
|
|
2
|
+
import { z as t } from "zod";
|
|
3
|
+
//#region src/eliasse-retry.ts
|
|
4
|
+
var n = class extends Error {
|
|
5
|
+
constructor(e, t) {
|
|
6
|
+
super(`Eliasse ${e.kind}${e.status === void 0 ? "" : ` (${e.status})`}${e.code ? ` [${e.code}]` : ""}: ${e.message} ${t}`), this.failure = e, this.url = t, this.name = "EliasseRequestError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function r(e) {
|
|
10
|
+
if (e instanceof n || e instanceof Error && e.name === "EliasseRequestError" && "failure" in e) return e.failure;
|
|
11
|
+
let t = e instanceof Error ? e.name : "", r = e?.cause;
|
|
12
|
+
return {
|
|
13
|
+
code: typeof r?.code == "string" ? r.code : void 0,
|
|
14
|
+
kind: t === "TimeoutError" || t === "AbortError" ? "timeout" : "network",
|
|
15
|
+
message: e instanceof Error ? e.message : String(e)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function i(e, t, n, r = {}) {
|
|
19
|
+
let i = (e?.attempts ?? 0) + 1, a = r.baseMs ?? 6e4, o = r.maxMs ?? 36e5, s = .8 + .4 * (r.random?.() ?? Math.random()), c = Math.min(o, a * 2 ** Math.min(i - 1, 20) * s);
|
|
20
|
+
return {
|
|
21
|
+
...e,
|
|
22
|
+
attempts: i,
|
|
23
|
+
firstFailureAt: e?.attempts ? e.firstFailureAt ?? n : n,
|
|
24
|
+
lastFailureAt: n,
|
|
25
|
+
lastAttemptAt: n,
|
|
26
|
+
failure: t,
|
|
27
|
+
nextRetryAt: n + Math.max(c, t.retryAfterMs ?? 0)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var a = class extends Error {
|
|
31
|
+
constructor(e, t) {
|
|
32
|
+
super(`Eliasse retry deferred for ${e} until ${new Date(t.nextRetryAt).toISOString()}`), this.key = e, this.state = t, this.name = "EliasseRetryDeferredError";
|
|
33
|
+
}
|
|
34
|
+
}, o = class {
|
|
35
|
+
constructor(e, t = {}) {
|
|
36
|
+
this.store = e, this.options = t;
|
|
37
|
+
}
|
|
38
|
+
async run(e, t, n = !1) {
|
|
39
|
+
let o = this.options.now?.() ?? Date.now(), s = await this.store.load(e) ?? { attempts: 0 };
|
|
40
|
+
if (n && !s.active && s.failure?.kind !== "rate-limit" && !s.failure?.retryAfterMs && (s = {
|
|
41
|
+
...s,
|
|
42
|
+
nextRetryAt: void 0
|
|
43
|
+
}), s = {
|
|
44
|
+
...s,
|
|
45
|
+
active: n,
|
|
46
|
+
lastSeenAt: o
|
|
47
|
+
}, (s.nextRetryAt ?? 0) > o) throw await this.store.save(e, s), new a(e, s);
|
|
48
|
+
s.lastAttemptAt = o;
|
|
49
|
+
let c;
|
|
50
|
+
try {
|
|
51
|
+
c = await t();
|
|
52
|
+
} catch (t) {
|
|
53
|
+
let a = r(t), o = i(s, a, this.options.now?.() ?? Date.now(), {
|
|
54
|
+
baseMs: n ? 15e3 : 6e4,
|
|
55
|
+
maxMs: n ? 15e3 : 36e5,
|
|
56
|
+
random: this.options.random
|
|
57
|
+
});
|
|
58
|
+
throw await this.store.save(e, o), t;
|
|
59
|
+
}
|
|
60
|
+
return await this.store.save(e, {
|
|
61
|
+
attempts: 0,
|
|
62
|
+
active: n,
|
|
63
|
+
lastSeenAt: o,
|
|
64
|
+
lastAttemptAt: o,
|
|
65
|
+
lastSuccessAt: this.options.now?.() ?? Date.now()
|
|
66
|
+
}), c;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
async function s(e, t, n) {
|
|
70
|
+
if (!Number.isInteger(t) || t < 1) throw Error("Concurrency must be a positive integer");
|
|
71
|
+
let r = Array(e.length), i = 0;
|
|
72
|
+
return await Promise.all(Array.from({ length: Math.min(t, e.length) }, async () => {
|
|
73
|
+
for (; i < e.length;) {
|
|
74
|
+
let t = i++;
|
|
75
|
+
try {
|
|
76
|
+
r[t] = {
|
|
77
|
+
status: "fulfilled",
|
|
78
|
+
value: await n(e[t])
|
|
79
|
+
};
|
|
80
|
+
} catch (e) {
|
|
81
|
+
r[t] = {
|
|
82
|
+
status: "rejected",
|
|
83
|
+
reason: e
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})), r;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/eliasse.ts
|
|
91
|
+
var c = "https://eliasse.assemblee-nationale.fr/api-eliasse/", l = t.object({
|
|
92
|
+
uid: t.string(),
|
|
93
|
+
abreviation: t.string(),
|
|
94
|
+
libelle: t.string(),
|
|
95
|
+
libelleAbrege: t.string(),
|
|
96
|
+
libelleAbregeRaccourci: t.string(),
|
|
97
|
+
dateFin: t.string().nullable()
|
|
98
|
+
}), u = t.object({
|
|
99
|
+
codeMinefi: t.string().nullable().optional(),
|
|
100
|
+
libelle: t.string().nullable().optional(),
|
|
101
|
+
missionLibelle: t.string().nullable().optional(),
|
|
102
|
+
nombreAmendementsMissionTotal: t.number().nullable().optional(),
|
|
103
|
+
nombreAmendementsMissionExamines: t.number().nullable().optional(),
|
|
104
|
+
nombreAmendementsMissionRestants: t.number().nullable().optional()
|
|
105
|
+
}), d = t.object({
|
|
106
|
+
uid: t.string(),
|
|
107
|
+
organeRef: t.string(),
|
|
108
|
+
statut: t.string(),
|
|
109
|
+
texte: t.object({
|
|
110
|
+
uid: t.string(),
|
|
111
|
+
libelle: t.string(),
|
|
112
|
+
bibard: t.string(),
|
|
113
|
+
partie: t.number()
|
|
114
|
+
}),
|
|
115
|
+
estSecondeDeliberation: t.boolean(),
|
|
116
|
+
missions: t.array(u)
|
|
117
|
+
}), f = t.object({
|
|
118
|
+
uidOrgane: t.string(),
|
|
119
|
+
uidTexte: t.string(),
|
|
120
|
+
uidExamen: t.string(),
|
|
121
|
+
uidAmendement: t.string().nullable()
|
|
122
|
+
}), p = t.object({ libelle: t.string() }), m = t.object({
|
|
123
|
+
id: t.string(),
|
|
124
|
+
uid: t.string(),
|
|
125
|
+
numero: t.string(),
|
|
126
|
+
estSousAmendement: t.boolean(),
|
|
127
|
+
sort: t.string().nullable(),
|
|
128
|
+
ordre: t.string(),
|
|
129
|
+
auteur: p,
|
|
130
|
+
positionDiscussionIdentique: t.string().nullable(),
|
|
131
|
+
positionDiscussionCommune: t.string().nullable(),
|
|
132
|
+
positionDiscussionIdentiqueSousAmendement: t.string().nullable(),
|
|
133
|
+
positionDiscussionCommuneSousAmendement: t.string().nullable(),
|
|
134
|
+
estVisible: t.boolean(),
|
|
135
|
+
codeMinefi: t.string().nullable(),
|
|
136
|
+
numeroParent: t.string().nullable().optional(),
|
|
137
|
+
amendementParentRef: t.string().nullable().optional()
|
|
138
|
+
}), h = t.object({
|
|
139
|
+
places: t.array(t.object({
|
|
140
|
+
id: t.string(),
|
|
141
|
+
libelle: t.string(),
|
|
142
|
+
amendements: t.array(m)
|
|
143
|
+
})),
|
|
144
|
+
version: t.number()
|
|
145
|
+
}), g = t.object({
|
|
146
|
+
divisionRef: t.string().nullable(),
|
|
147
|
+
titre: t.string().nullable(),
|
|
148
|
+
articleDesignationCourte: t.string().nullable(),
|
|
149
|
+
articleDesignation: t.string().nullable(),
|
|
150
|
+
type: t.string().nullable(),
|
|
151
|
+
avantApres: t.string().nullable(),
|
|
152
|
+
urlDivisionTexteVise: t.string().nullable(),
|
|
153
|
+
estArticleAdditionnel: t.boolean(),
|
|
154
|
+
estChapitreAdditionnel: t.boolean(),
|
|
155
|
+
contenuHtml: t.string().nullable()
|
|
156
|
+
}), _ = t.object({
|
|
157
|
+
typeAuteur: t.string().nullable(),
|
|
158
|
+
ref: t.string().nullable(),
|
|
159
|
+
libelle: t.string(),
|
|
160
|
+
urlPhoto: t.string().nullable(),
|
|
161
|
+
urlFicheActeur: t.string().nullable()
|
|
162
|
+
}), v = t.object({
|
|
163
|
+
uid: t.string(),
|
|
164
|
+
libelle: t.string(),
|
|
165
|
+
prenom: t.string().nullable(),
|
|
166
|
+
nom: t.string().nullable(),
|
|
167
|
+
civilite: t.string().nullable(),
|
|
168
|
+
urlPhoto: t.string().nullable(),
|
|
169
|
+
urlFicheActeur: t.string().nullable()
|
|
170
|
+
}), y = t.object({
|
|
171
|
+
uid: t.string(),
|
|
172
|
+
numero: t.string(),
|
|
173
|
+
numeroParent: t.string().nullable(),
|
|
174
|
+
amendementParentRef: t.string().nullable(),
|
|
175
|
+
estSousAmendement: t.boolean(),
|
|
176
|
+
sort: t.string().nullable(),
|
|
177
|
+
ordre: t.string(),
|
|
178
|
+
division: g.nullable(),
|
|
179
|
+
auteur: _.nullable(),
|
|
180
|
+
auteurParent: _.nullable(),
|
|
181
|
+
cosignataires: t.array(v),
|
|
182
|
+
cosignatairesSuffixe: t.string().nullable(),
|
|
183
|
+
cosignatairesLibelle: t.string().nullable(),
|
|
184
|
+
positionDiscussionIdentique: t.string().nullable(),
|
|
185
|
+
positionDiscussionCommune: t.string().nullable(),
|
|
186
|
+
positionDiscussionIdentiqueSousAmendement: t.string().nullable(),
|
|
187
|
+
positionDiscussionCommuneSousAmendement: t.string().nullable(),
|
|
188
|
+
dispositif: t.string().nullable(),
|
|
189
|
+
exposeSommaire: t.string().nullable(),
|
|
190
|
+
contenuHtmlDuTexteDeReference: t.string().nullable(),
|
|
191
|
+
missionLibelle: t.string().nullable()
|
|
192
|
+
}), b = t.object({
|
|
193
|
+
codeMinefi: t.string().nullable().optional(),
|
|
194
|
+
missionLibelle: t.string().nullable().optional(),
|
|
195
|
+
nombreAmendementsMissionTotal: t.number().nullable().optional(),
|
|
196
|
+
nombreAmendementsMissionExamines: t.number().nullable().optional(),
|
|
197
|
+
nombreAmendementsMissionRestants: t.number().nullable().optional()
|
|
198
|
+
}), x = t.object({
|
|
199
|
+
nombreAmendementsTotal: t.number(),
|
|
200
|
+
nombreAmendementsExamines: t.number(),
|
|
201
|
+
nombreAmendementsRestants: t.number(),
|
|
202
|
+
missions: t.array(b)
|
|
203
|
+
});
|
|
204
|
+
function S(e) {
|
|
205
|
+
let t = /L(\d+)/.exec(e);
|
|
206
|
+
return t === null ? void 0 : Number(t[1]);
|
|
207
|
+
}
|
|
208
|
+
async function C(t, i, a, o) {
|
|
209
|
+
let s = o?.baseUrl ?? "https://eliasse.assemblee-nationale.fr/api-eliasse/", c = new URL(t, s.endsWith("/") ? s : `${s}/`), l;
|
|
210
|
+
try {
|
|
211
|
+
l = await fetch(c, {
|
|
212
|
+
headers: { Accept: "application/json" },
|
|
213
|
+
signal: o?.signal
|
|
214
|
+
});
|
|
215
|
+
} catch (e) {
|
|
216
|
+
throw new n(r(e), String(c));
|
|
217
|
+
}
|
|
218
|
+
if (!l.ok) {
|
|
219
|
+
let e = l.headers.get("retry-after"), t = e === null ? void 0 : /^\d+$/.test(e) ? Number(e) * 1e3 : Math.max(0, Date.parse(e) - Date.now());
|
|
220
|
+
throw new n({
|
|
221
|
+
kind: l.status === 404 ? "not-found" : l.status === 429 ? "rate-limit" : "http",
|
|
222
|
+
status: l.status,
|
|
223
|
+
message: l.statusText,
|
|
224
|
+
retryAfterMs: Number.isFinite(t) ? t : void 0
|
|
225
|
+
}, String(c));
|
|
226
|
+
}
|
|
227
|
+
let u;
|
|
228
|
+
try {
|
|
229
|
+
u = await l.text();
|
|
230
|
+
} catch (e) {
|
|
231
|
+
throw new n(r(e), String(c));
|
|
232
|
+
}
|
|
233
|
+
if (u.trim() === "") throw new n({
|
|
234
|
+
kind: "empty",
|
|
235
|
+
status: l.status,
|
|
236
|
+
message: "Empty response body"
|
|
237
|
+
}, String(c));
|
|
238
|
+
let d;
|
|
239
|
+
try {
|
|
240
|
+
d = JSON.parse(u);
|
|
241
|
+
} catch {
|
|
242
|
+
throw new n({
|
|
243
|
+
kind: "invalid",
|
|
244
|
+
status: l.status,
|
|
245
|
+
message: "Invalid JSON response"
|
|
246
|
+
}, String(c));
|
|
247
|
+
}
|
|
248
|
+
let f = i.safeParse(d);
|
|
249
|
+
if (!f.success) throw new n({
|
|
250
|
+
kind: "invalid",
|
|
251
|
+
status: l.status,
|
|
252
|
+
message: e(a, f.error, d)
|
|
253
|
+
}, String(c));
|
|
254
|
+
return d;
|
|
255
|
+
}
|
|
256
|
+
function w(e) {
|
|
257
|
+
return C("organes", t.array(l), "organes", e);
|
|
258
|
+
}
|
|
259
|
+
function T(e) {
|
|
260
|
+
return C("examens", t.array(d), "examens", e);
|
|
261
|
+
}
|
|
262
|
+
function E(e) {
|
|
263
|
+
return C("prochainadiscuter", t.array(f), "prochains à discuter", e);
|
|
264
|
+
}
|
|
265
|
+
function D(e, t) {
|
|
266
|
+
return C(`examens/${encodeURIComponent(e)}/derouleur`, h, "dérouleur", t);
|
|
267
|
+
}
|
|
268
|
+
function O(e, t) {
|
|
269
|
+
return C(`examens/${encodeURIComponent(e)}/statistiques`, x, "statistiques", t);
|
|
270
|
+
}
|
|
271
|
+
function k(e, n, r, i) {
|
|
272
|
+
return C(`textes/${encodeURIComponent(e)}/examens/${encodeURIComponent(n)}/amendements/${encodeURIComponent(r)}/with_neighbors`, t.array(y), "amendements", i);
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { o as C, i as D, s as E, n as S, r as T, D as _, m as a, E as b, g as c, l as d, f, k as g, S as h, c as i, d as l, x as m, y as n, p as o, b as p, v as r, h as s, _ as t, u, T as v, a as w, O as x, w as y };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EliasseAmendement } from './eliasse.js';
|
|
2
|
+
import { EliasseFailure } from './eliasse-retry.js';
|
|
3
|
+
export interface EliasseDetailBatch {
|
|
4
|
+
details: Map<string, EliasseAmendement>;
|
|
5
|
+
failures: Map<string, EliasseFailure>;
|
|
6
|
+
rateLimit?: EliasseFailure;
|
|
7
|
+
}
|
|
8
|
+
/** Windowed, bounded detail recovery. The first target (usually current) is
|
|
9
|
+
* requested first. Missing neighbors get individual recovery; partial successes
|
|
10
|
+
* survive later failures. Unattempted targets are deferred, never unavailable. */
|
|
11
|
+
export declare function fetchEliasseDetailBatch(uids: string[], readWindow: (uid: string, signal: AbortSignal) => Promise<EliasseAmendement[]>, options?: {
|
|
12
|
+
budgetMs?: number;
|
|
13
|
+
requestTimeoutMs?: number;
|
|
14
|
+
}): Promise<EliasseDetailBatch>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Browser-safe error classification, durable route backoff and bounded workers. */
|
|
2
|
+
export type EliasseFailureKind = "not-found" | "empty" | "invalid" | "rate-limit" | "http" | "timeout" | "network" | "deferred";
|
|
3
|
+
export interface EliasseFailure {
|
|
4
|
+
kind: EliasseFailureKind;
|
|
5
|
+
message: string;
|
|
6
|
+
status?: number;
|
|
7
|
+
retryAfterMs?: number;
|
|
8
|
+
code?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class EliasseRequestError extends Error {
|
|
11
|
+
readonly failure: EliasseFailure;
|
|
12
|
+
readonly url: string;
|
|
13
|
+
constructor(failure: EliasseFailure, url: string);
|
|
14
|
+
}
|
|
15
|
+
export declare function classifyEliasseFailure(error: unknown): EliasseFailure;
|
|
16
|
+
export interface EliasseRetryState {
|
|
17
|
+
attempts: number;
|
|
18
|
+
firstFailureAt?: number;
|
|
19
|
+
lastFailureAt?: number;
|
|
20
|
+
failure?: EliasseFailure;
|
|
21
|
+
nextRetryAt?: number;
|
|
22
|
+
lastAttemptAt?: number;
|
|
23
|
+
lastSuccessAt?: number;
|
|
24
|
+
lastSeenAt?: number;
|
|
25
|
+
active?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function nextEliasseRetry(previous: EliasseRetryState | undefined, failure: EliasseFailure, now: number, options?: {
|
|
28
|
+
baseMs?: number;
|
|
29
|
+
maxMs?: number;
|
|
30
|
+
random?: () => number;
|
|
31
|
+
}): EliasseRetryState;
|
|
32
|
+
export declare class EliasseRetryDeferredError extends Error {
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly state: EliasseRetryState;
|
|
35
|
+
constructor(key: string, state: EliasseRetryState);
|
|
36
|
+
}
|
|
37
|
+
export interface EliasseRetryStore {
|
|
38
|
+
load(key: string): Promise<EliasseRetryState | undefined>;
|
|
39
|
+
save(key: string, state: EliasseRetryState): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** A key must identify a single route. Calls for that key are serialized by the
|
|
42
|
+
* caller (the synchronizer does this per examen). Deferred calls update liveness
|
|
43
|
+
* but do not issue HTTP. Current targets recover rapidly, except Retry-After. */
|
|
44
|
+
export declare class EliasseRequestScheduler {
|
|
45
|
+
private store;
|
|
46
|
+
private options;
|
|
47
|
+
constructor(store: EliasseRetryStore, options?: {
|
|
48
|
+
now?: () => number;
|
|
49
|
+
random?: () => number;
|
|
50
|
+
});
|
|
51
|
+
run<T>(key: string, request: () => Promise<T>, active?: boolean): Promise<T>;
|
|
52
|
+
}
|
|
53
|
+
/** Stable result ordering; slow or rejected jobs do not stop other workers. */
|
|
54
|
+
export declare function mapEliasseConcurrent<T, R>(items: T[], concurrency: number, work: (item: T) => Promise<R>): Promise<PromiseSettledResult<R>[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/eliasse-socket.d.ts
CHANGED
|
@@ -41,14 +41,30 @@ interface WebSocketLike {
|
|
|
41
41
|
reason?: string;
|
|
42
42
|
}) => void) | null;
|
|
43
43
|
onerror: ((event?: unknown) => void) | null;
|
|
44
|
+
addEventListener?(type: "message", listener: () => void): void;
|
|
44
45
|
}
|
|
45
46
|
type WebSocketConstructor = new (url: string | URL, protocols?: string | string[]) => WebSocketLike;
|
|
46
47
|
export type EliasseSocketStatus = "connecting" | "connected" | "disconnected";
|
|
48
|
+
export interface EliasseSocketDiagnostic {
|
|
49
|
+
type: "connected" | "closed" | "heartbeat-lost" | "keepalive";
|
|
50
|
+
at: number;
|
|
51
|
+
heartbeat?: string;
|
|
52
|
+
code?: number;
|
|
53
|
+
reason?: string;
|
|
54
|
+
wasClean?: boolean;
|
|
55
|
+
intentional?: boolean;
|
|
56
|
+
connectedForMs?: number;
|
|
57
|
+
receiveIdleMs?: number;
|
|
58
|
+
sendIdleMs?: number;
|
|
59
|
+
}
|
|
47
60
|
export interface EliasseSocketOptions {
|
|
48
61
|
socketUrl?: string;
|
|
49
62
|
/** Requested heart-beat period; negotiation is handled by stompjs. */
|
|
50
63
|
heartbeatMs?: number;
|
|
51
64
|
reconnectDelayMs?: number;
|
|
65
|
+
/** Optional STOMP newline to keep an idle transport open when the broker
|
|
66
|
+
* negotiates 0,0. Disabled by default; this does not require incoming beats. */
|
|
67
|
+
keepAliveMs?: number;
|
|
52
68
|
WebSocket?: WebSocketConstructor;
|
|
53
69
|
}
|
|
54
70
|
/** Browser-safe STOMP client. Framing, subscription routing, negotiated
|
|
@@ -59,6 +75,12 @@ export declare class EliasseSocket {
|
|
|
59
75
|
readonly reconnectDelayMs: number;
|
|
60
76
|
onStatusChange?: (status: EliasseSocketStatus) => void;
|
|
61
77
|
onError?: (error: Error) => void;
|
|
78
|
+
onDiagnostic?: (event: EliasseSocketDiagnostic) => void;
|
|
79
|
+
private connectedAt?;
|
|
80
|
+
private lastReceivedAt?;
|
|
81
|
+
private lastSentAt?;
|
|
82
|
+
private stopping;
|
|
83
|
+
private keepAliveTimer?;
|
|
62
84
|
private client;
|
|
63
85
|
private statusValue;
|
|
64
86
|
private subscriptionCounter;
|
package/lib/eliasse-socket.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./zod_errors-qS8sQ67W.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a as t, f as n, m as r } from "./eliasse-CP5wde9Z.js";
|
|
3
3
|
import { z as i } from "zod";
|
|
4
4
|
import { Client as a } from "@stomp/stompjs";
|
|
5
5
|
//#region src/eliasse-socket.ts
|
|
@@ -58,25 +58,78 @@ function f(e, t) {
|
|
|
58
58
|
}
|
|
59
59
|
var p = class {
|
|
60
60
|
constructor(e = {}) {
|
|
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;
|
|
61
|
+
if (this.stopping = !1, 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, !Number.isFinite(e.keepAliveMs ?? 0) || (e.keepAliveMs ?? 0) < 0) throw Error("keepAliveMs must be nonnegative");
|
|
62
62
|
let t = e.WebSocket ?? globalThis.WebSocket;
|
|
63
63
|
if (t === void 0) throw Error("WebSocket is not available: use a browser or Node.js >= 22, or provide options.WebSocket.");
|
|
64
64
|
this.client = new a({
|
|
65
|
-
webSocketFactory: () =>
|
|
65
|
+
webSocketFactory: () => {
|
|
66
|
+
let e = new t(this.socketUrl, ["v12.stomp"]), n = e.send.bind(e);
|
|
67
|
+
if (e.send = (e) => {
|
|
68
|
+
n(e), this.lastSentAt = Date.now();
|
|
69
|
+
}, e.addEventListener) e.addEventListener("message", () => {
|
|
70
|
+
this.lastReceivedAt = Date.now();
|
|
71
|
+
});
|
|
72
|
+
else {
|
|
73
|
+
let t = e.onmessage;
|
|
74
|
+
Object.defineProperty(e, "onmessage", {
|
|
75
|
+
configurable: !0,
|
|
76
|
+
get: () => t,
|
|
77
|
+
set: (n) => {
|
|
78
|
+
t = n === null ? null : (t) => {
|
|
79
|
+
this.lastReceivedAt = Date.now(), n.call(e, t);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return e;
|
|
85
|
+
},
|
|
66
86
|
connectHeaders: { host: new URL(this.socketUrl).hostname },
|
|
67
87
|
reconnectDelay: this.reconnectDelayMs,
|
|
68
88
|
connectionTimeout: 15e3,
|
|
69
89
|
heartbeatIncoming: this.heartbeatMs,
|
|
70
90
|
heartbeatOutgoing: this.heartbeatMs,
|
|
71
|
-
beforeConnect: () =>
|
|
72
|
-
|
|
91
|
+
beforeConnect: () => {
|
|
92
|
+
this.connectedAt = this.lastReceivedAt = this.lastSentAt = void 0, this.setStatus("connecting");
|
|
93
|
+
},
|
|
94
|
+
onConnect: (t) => {
|
|
95
|
+
this.connectedAt = Date.now(), this.onDiagnostic?.({
|
|
96
|
+
type: "connected",
|
|
97
|
+
at: this.connectedAt,
|
|
98
|
+
heartbeat: t.headers["heart-beat"]
|
|
99
|
+
});
|
|
73
100
|
for (let [e, t] of this.subscriptions) this.subscribe(e, t);
|
|
74
|
-
this.setStatus("connected")
|
|
101
|
+
this.setStatus("connected"), e.keepAliveMs && (this.keepAliveTimer = setInterval(() => {
|
|
102
|
+
if (!(this.statusValue !== "connected" || Date.now() - (this.lastSentAt ?? 0) < e.keepAliveMs)) try {
|
|
103
|
+
this.client.webSocket?.send("\n"), this.lastSentAt = Date.now(), this.onDiagnostic?.({
|
|
104
|
+
type: "keepalive",
|
|
105
|
+
at: this.lastSentAt
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
this.onError?.(/* @__PURE__ */ Error("Eliasse keepalive send failed"));
|
|
109
|
+
}
|
|
110
|
+
}, e.keepAliveMs));
|
|
75
111
|
},
|
|
76
|
-
onWebSocketClose: () => {
|
|
112
|
+
onWebSocketClose: (e) => {
|
|
113
|
+
clearInterval(this.keepAliveTimer), this.keepAliveTimer = void 0;
|
|
114
|
+
let t = Date.now();
|
|
115
|
+
this.onDiagnostic?.({
|
|
116
|
+
type: "closed",
|
|
117
|
+
at: t,
|
|
118
|
+
code: e.code,
|
|
119
|
+
reason: e.reason,
|
|
120
|
+
wasClean: e.wasClean,
|
|
121
|
+
intentional: this.stopping,
|
|
122
|
+
connectedForMs: this.connectedAt === void 0 ? void 0 : t - this.connectedAt,
|
|
123
|
+
receiveIdleMs: this.lastReceivedAt === void 0 ? void 0 : t - this.lastReceivedAt,
|
|
124
|
+
sendIdleMs: this.lastSentAt === void 0 ? void 0 : t - this.lastSentAt
|
|
125
|
+
});
|
|
77
126
|
for (let e of this.subscriptions.values()) e.active = void 0;
|
|
78
127
|
this.setStatus("disconnected");
|
|
79
128
|
},
|
|
129
|
+
onHeartbeatLost: () => this.onDiagnostic?.({
|
|
130
|
+
type: "heartbeat-lost",
|
|
131
|
+
at: Date.now()
|
|
132
|
+
}),
|
|
80
133
|
onWebSocketError: () => this.onError?.(/* @__PURE__ */ Error("Eliasse WebSocket transport error")),
|
|
81
134
|
onStompError: (e) => this.onError?.(/* @__PURE__ */ Error(`STOMP ERROR (${e.headers.message ?? ""}): ${e.body}`))
|
|
82
135
|
});
|
|
@@ -88,9 +141,10 @@ var p = class {
|
|
|
88
141
|
return this.client.webSocket;
|
|
89
142
|
}
|
|
90
143
|
connect() {
|
|
91
|
-
this.client.activate();
|
|
144
|
+
this.stopping = !1, this.client.activate();
|
|
92
145
|
}
|
|
93
146
|
async disconnect() {
|
|
147
|
+
this.stopping = !0, clearInterval(this.keepAliveTimer), this.keepAliveTimer = void 0;
|
|
94
148
|
let e = setTimeout(() => {
|
|
95
149
|
this.client.deactivate({ force: !0 });
|
|
96
150
|
}, 1e3);
|
package/lib/eliasse-sync.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { EliasseAmendement, EliasseDerouleur, EliasseDerouleurAmendement, EliasseStatistiques } from './eliasse.js';
|
|
2
2
|
import { EliasseDerouleurUpdate } from './eliasse-socket.js';
|
|
3
|
+
import { EliasseFailure, EliasseRetryState } from './eliasse-retry.js';
|
|
4
|
+
export * from './eliasse-retry.js';
|
|
5
|
+
export * from './eliasse-details.js';
|
|
3
6
|
export interface EliasseSyncTarget {
|
|
4
7
|
uidExamen: string;
|
|
5
8
|
uidTexte: string;
|
|
@@ -20,6 +23,9 @@ export interface EliasseStoredAmendement {
|
|
|
20
23
|
detailPending: boolean;
|
|
21
24
|
detailFetchedAt?: number;
|
|
22
25
|
detailRetryAt?: number;
|
|
26
|
+
detailAttempts?: number;
|
|
27
|
+
detailPendingSince?: number;
|
|
28
|
+
detailRetry?: EliasseRetryState;
|
|
23
29
|
}
|
|
24
30
|
export interface EliasseSyncState {
|
|
25
31
|
/** Optional opaque optimistic-concurrency token managed by the repository. */
|
|
@@ -34,21 +40,43 @@ export interface EliasseSyncCounts {
|
|
|
34
40
|
/** Actual open data changes, not attempted writes. */
|
|
35
41
|
patched: number;
|
|
36
42
|
pendingDetails: number;
|
|
43
|
+
pendingCurrentDetails?: number;
|
|
44
|
+
pendingHistoricalDetails?: number;
|
|
45
|
+
outcomes?: Array<{
|
|
46
|
+
uid: string;
|
|
47
|
+
before: string | null;
|
|
48
|
+
after: string | null;
|
|
49
|
+
}>;
|
|
50
|
+
rowsChanged?: number;
|
|
51
|
+
detailsChanged?: number;
|
|
52
|
+
membershipsChanged?: number;
|
|
53
|
+
referencesChanged?: number;
|
|
54
|
+
retriesChanged?: number;
|
|
55
|
+
receivedAt?: number;
|
|
37
56
|
}
|
|
38
57
|
export interface EliasseSyncRepository {
|
|
39
58
|
load(uidExamen: string): Promise<EliasseSyncState>;
|
|
40
59
|
/** Must be atomic; a rejection must leave the previous checkpoint intact. */
|
|
41
|
-
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques
|
|
42
|
-
|
|
60
|
+
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques, context?: {
|
|
61
|
+
source: "http" | "patch";
|
|
62
|
+
snapshotReceivedAt?: number;
|
|
63
|
+
statisticsReceivedAt?: number;
|
|
64
|
+
}): Promise<Pick<EliasseSyncCounts, "stored" | "patched" | "outcomes" | "rowsChanged" | "detailsChanged" | "membershipsChanged" | "referencesChanged" | "retriesChanged">>;
|
|
65
|
+
saveStatistics(uidExamen: string, statistiques: EliasseStatistiques, receivedAt?: number): Promise<void>;
|
|
43
66
|
}
|
|
44
67
|
export interface EliasseSynchronizerOptions {
|
|
45
68
|
repository: EliasseSyncRepository;
|
|
46
69
|
fetchDerouleur(target: EliasseSyncTarget): Promise<EliasseDerouleur>;
|
|
47
70
|
fetchStatistiques(target: EliasseSyncTarget): Promise<EliasseStatistiques>;
|
|
48
|
-
fetchDetails(target: EliasseSyncTarget, uids: string[]): Promise<Map<string, EliasseAmendement
|
|
71
|
+
fetchDetails(target: EliasseSyncTarget, uids: string[]): Promise<Map<string, EliasseAmendement> | {
|
|
72
|
+
details: Map<string, EliasseAmendement>;
|
|
73
|
+
failures: Map<string, EliasseFailure>;
|
|
74
|
+
}>;
|
|
49
75
|
limit?: number;
|
|
50
76
|
detailRefreshMs?: number;
|
|
51
77
|
retryMs?: number;
|
|
78
|
+
historicalRetryMaxMs?: number;
|
|
79
|
+
random?: () => number;
|
|
52
80
|
now?: () => number;
|
|
53
81
|
onError?: (error: unknown) => void;
|
|
54
82
|
}
|
package/lib/eliasse-sync.js
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as e, D as t, E as n, S as r, T as i, w as a } from "./eliasse-CP5wde9Z.js";
|
|
2
|
+
import { applyEliasseDerouleurUpdate as o, compareEliasseOrdre as s } from "./eliasse-socket.js";
|
|
3
|
+
//#region src/eliasse-details.ts
|
|
4
|
+
async function c(e, t, n = {}) {
|
|
5
|
+
let r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = new Set(e), s = /* @__PURE__ */ new Set(), c = AbortSignal.timeout(n.budgetMs ?? 5e3), l = !1, u, d = e.length ? [.../* @__PURE__ */ new Set([e[0], ...e.filter((e, t) => t % 5 == 2)])] : [];
|
|
6
|
+
for (let f of [...d, ...e]) if (!(r.has(f) || s.has(f))) {
|
|
7
|
+
if (c.aborted || l) break;
|
|
8
|
+
s.add(f);
|
|
9
|
+
try {
|
|
10
|
+
let e = await t(f, AbortSignal.any([c, AbortSignal.timeout(n.requestTimeoutMs ?? 15e3)]));
|
|
11
|
+
for (let t of e) o.has(t.uid) && r.set(t.uid, t);
|
|
12
|
+
r.has(f) || a.set(f, {
|
|
13
|
+
kind: "empty",
|
|
14
|
+
message: "Requested UID absent from neighbor window"
|
|
15
|
+
});
|
|
16
|
+
} catch (e) {
|
|
17
|
+
let t = i(e);
|
|
18
|
+
a.set(f, t), l = [
|
|
19
|
+
"network",
|
|
20
|
+
"timeout",
|
|
21
|
+
"rate-limit"
|
|
22
|
+
].includes(t.kind), t.kind === "rate-limit" && (u = t);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (let t of e) !r.has(t) && !s.has(t) && a.set(t, {
|
|
26
|
+
kind: "deferred",
|
|
27
|
+
message: "Batch interrupted before requesting this UID"
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
details: r,
|
|
31
|
+
failures: a,
|
|
32
|
+
rateLimit: u
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
2
36
|
//#region src/eliasse-sync.ts
|
|
3
|
-
function
|
|
37
|
+
function l(e) {
|
|
4
38
|
return e != null && e !== "" && e !== "Aucun";
|
|
5
39
|
}
|
|
6
|
-
function
|
|
40
|
+
function u(e) {
|
|
7
41
|
return JSON.stringify(e, (e, t) => typeof t != "object" || !t || Array.isArray(t) ? t : Object.fromEntries(Object.entries(t).sort(([e], [t]) => e < t ? -1 : +(e > t))));
|
|
8
42
|
}
|
|
9
|
-
var
|
|
43
|
+
var d = class {
|
|
10
44
|
constructor(e) {
|
|
11
45
|
this.options = e, this.tails = /* @__PURE__ */ new Map();
|
|
12
46
|
}
|
|
@@ -16,22 +50,24 @@ var i = class {
|
|
|
16
50
|
synchronize(e) {
|
|
17
51
|
return this.enqueue(e.uidExamen, () => this.http(e));
|
|
18
52
|
}
|
|
19
|
-
applyUpdate(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
53
|
+
applyUpdate(e, t) {
|
|
54
|
+
let n = this.options.now?.() ?? Date.now();
|
|
55
|
+
return this.enqueue(e.uidExamen, async () => {
|
|
56
|
+
let r = await this.options.repository.load(e.uidExamen);
|
|
57
|
+
if (r.derouleur === void 0 || t.version !== r.derouleur.version + 1) return this.http(e);
|
|
58
|
+
let i = t.places.flatMap((e) => e.amendements.map((t) => ({
|
|
24
59
|
amendement: t,
|
|
25
60
|
place: {
|
|
26
61
|
id: e.id,
|
|
27
62
|
libelle: e.libelle ?? r.derouleur.places.find((t) => t.id === e.id)?.libelle
|
|
28
63
|
}
|
|
29
64
|
})));
|
|
30
|
-
return this.process(
|
|
65
|
+
return this.process(e, r, o(r.derouleur, t), i, void 0, "patch", n);
|
|
31
66
|
});
|
|
32
67
|
}
|
|
33
68
|
saveStatistics(e, t) {
|
|
34
|
-
|
|
69
|
+
let n = this.options.now?.() ?? Date.now();
|
|
70
|
+
return this.enqueue(e, () => this.options.repository.saveStatistics(e, t, n));
|
|
35
71
|
}
|
|
36
72
|
enqueue(e, t) {
|
|
37
73
|
let n = (this.tails.get(e) ?? Promise.resolve()).catch(() => void 0).then(t);
|
|
@@ -40,66 +76,100 @@ var i = class {
|
|
|
40
76
|
}).catch(() => void 0), n;
|
|
41
77
|
}
|
|
42
78
|
async http(e) {
|
|
43
|
-
let t = await this.options.repository.load(e.uidExamen), [n, r] = await Promise.all([this.options.fetchDerouleur(e)
|
|
79
|
+
let t = await this.options.repository.load(e.uidExamen), [n, r] = await Promise.all([this.options.fetchDerouleur(e).then((e) => ({
|
|
80
|
+
value: e,
|
|
81
|
+
at: this.options.now?.() ?? Date.now()
|
|
82
|
+
})), this.options.fetchStatistiques(e).then((e) => ({
|
|
83
|
+
value: e,
|
|
84
|
+
at: this.options.now?.() ?? Date.now()
|
|
85
|
+
})).catch((e) => {
|
|
44
86
|
this.options.onError?.(e);
|
|
45
87
|
})]);
|
|
46
|
-
return this.process(e, t, n, [], r);
|
|
88
|
+
return this.process(e, t, n.value, [], r?.value, "http", n.at, r?.at);
|
|
47
89
|
}
|
|
48
|
-
async process(e,
|
|
49
|
-
let
|
|
90
|
+
async process(e, n, r, a, o, c = "http", d, f) {
|
|
91
|
+
let p = this.options.now?.() ?? Date.now(), m = new Map(n.amendements.map((e) => [e.uid, { ...e }])), h = r.places.flatMap((e) => e.amendements.map((t) => ({
|
|
50
92
|
amendement: t,
|
|
51
93
|
place: {
|
|
52
94
|
id: e.id,
|
|
53
95
|
libelle: e.libelle
|
|
54
96
|
}
|
|
55
97
|
})));
|
|
56
|
-
|
|
57
|
-
let
|
|
58
|
-
for (let e of [...
|
|
59
|
-
let t = e.amendement.uid,
|
|
60
|
-
|
|
61
|
-
...
|
|
98
|
+
h.sort((e, t) => s(e.amendement.ordre, t.amendement.ordre));
|
|
99
|
+
let g = new Set(h.filter((e) => e.amendement.estVisible !== !1).map((e) => e.amendement.uid)), _ = new Set(h.filter((e) => e.amendement.estVisible !== !1 && !l(e.amendement.sort)).slice(0, this.options.limit ?? 25).map((e) => e.amendement.uid)), v = e.uidAmendement ?? void 0;
|
|
100
|
+
for (let e of [...h, ...a]) {
|
|
101
|
+
let t = e.amendement.uid, n = m.get(t), r = u(n?.row) !== u(e), i = l(e.amendement.sort) || t === v || _.has(t) || n?.present === !0 && !g.has(t);
|
|
102
|
+
m.set(t, {
|
|
103
|
+
...n,
|
|
62
104
|
uid: t,
|
|
63
105
|
row: e,
|
|
64
|
-
present:
|
|
65
|
-
detailPending:
|
|
66
|
-
detailRetryAt:
|
|
106
|
+
present: g.has(t),
|
|
107
|
+
detailPending: n?.detailPending === !0 || i && (n?.detail === void 0 || r || (t === v || _.has(t)) && p - (n?.detailFetchedAt ?? 0) >= (this.options.detailRefreshMs ?? 6e4)),
|
|
108
|
+
detailRetryAt: r || n?.present === !1 && g.has(t) ? void 0 : n?.detailRetryAt,
|
|
109
|
+
detailRetry: r || n?.present === !1 && g.has(t) ? void 0 : n?.detailRetry
|
|
67
110
|
});
|
|
68
111
|
}
|
|
69
|
-
for (let e of
|
|
70
|
-
|
|
71
|
-
uid:
|
|
112
|
+
for (let e of m.values()) g.has(e.uid) || (e.present && (e.detailPending = !0, e.detailRetryAt = void 0), e.present = !1);
|
|
113
|
+
v !== void 0 && !m.has(v) && m.set(v, {
|
|
114
|
+
uid: v,
|
|
72
115
|
present: !1,
|
|
73
116
|
detailPending: !0
|
|
74
117
|
});
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
118
|
+
let y = v === void 0 ? void 0 : m.get(v);
|
|
119
|
+
y !== void 0 && p - (y.detailFetchedAt ?? 0) >= (this.options.detailRefreshMs ?? 6e4) && (y.detailPending = !0), y?.detailRetryAt !== void 0 && (y.detailRetryAt = Math.min(y.detailRetryAt, p + Math.min(this.options.retryMs ?? 6e4, 15e3)));
|
|
120
|
+
for (let e of m.values()) e.detailPending && e.detailPendingSince === void 0 && (e.detailPendingSince = p);
|
|
121
|
+
let b = new Set(n.amendements.filter((e) => e.present && !g.has(e.uid)).map((e) => e.uid)), x = (e) => e.uid === v ? 0 : l(e.row?.amendement.sort) ? 1 : b.has(e.uid) ? 2 : _.has(e.uid) ? 3 : e.present ? 4 : 5, S = [...m.values()].filter((e) => e.detailPending && (e.detailRetryAt ?? 0) <= p).sort((e, t) => x(e) - x(t) || (e.detailFetchedAt ?? 0) - (t.detailFetchedAt ?? 0) || s(e.row?.amendement.ordre ?? "", t.row?.amendement.ordre ?? "")).slice(0, Math.max(0, this.options.limit ?? 25)), C = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map();
|
|
122
|
+
if (S.length > 0) try {
|
|
123
|
+
let t = await this.options.fetchDetails(e, S.map((e) => e.uid));
|
|
124
|
+
t instanceof Map ? C = t : (C = t.details, w = t.failures);
|
|
80
125
|
} catch (e) {
|
|
81
|
-
this.options.onError?.(e);
|
|
126
|
+
this.options.onError?.(e), w = new Map(S.map((t) => [t.uid, i(e)]));
|
|
82
127
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
128
|
+
let T = this.options.now?.() ?? Date.now();
|
|
129
|
+
for (let e of S) {
|
|
130
|
+
if (w.get(e.uid)?.kind === "deferred") {
|
|
131
|
+
e.detailRetryAt = T + (e.uid === v ? Math.min(this.options.retryMs ?? 6e4, 15e3) : this.options.retryMs ?? 6e4);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
e.detailAttempts = (e.detailAttempts ?? 0) + 1;
|
|
135
|
+
let n = C.get(e.uid);
|
|
136
|
+
if (n !== void 0) e.detail = n, e.detailFetchedAt = T, e.detailPending = !1, e.detailPendingSince = void 0, e.detailRetryAt = void 0, e.detailRetry = e.detailRetry === void 0 ? void 0 : {
|
|
137
|
+
...e.detailRetry,
|
|
138
|
+
attempts: 0,
|
|
139
|
+
nextRetryAt: void 0,
|
|
140
|
+
lastSuccessAt: T
|
|
141
|
+
};
|
|
86
142
|
else {
|
|
87
|
-
let
|
|
88
|
-
e.
|
|
143
|
+
let n = this.options.retryMs ?? 6e4;
|
|
144
|
+
e.detailRetry = t(e.detailRetry, w.get(e.uid) ?? {
|
|
145
|
+
kind: "empty",
|
|
146
|
+
message: "Requested UID absent from detail response"
|
|
147
|
+
}, T, {
|
|
148
|
+
baseMs: e.uid === v ? Math.min(n, 15e3) : n,
|
|
149
|
+
maxMs: e.uid === v ? Math.min(n, 15e3) : e.present ? n : this.options.historicalRetryMaxMs ?? 216e5,
|
|
150
|
+
random: this.options.random
|
|
151
|
+
}), e.detailRetryAt = e.detailRetry.nextRetryAt;
|
|
89
152
|
}
|
|
90
153
|
}
|
|
91
|
-
let
|
|
92
|
-
revision:
|
|
93
|
-
derouleur:
|
|
94
|
-
amendements: [...
|
|
154
|
+
let E = {
|
|
155
|
+
revision: n.revision,
|
|
156
|
+
derouleur: r,
|
|
157
|
+
amendements: [...m.values()]
|
|
95
158
|
};
|
|
96
159
|
return {
|
|
97
|
-
...await this.options.repository.commit(e,
|
|
160
|
+
...await this.options.repository.commit(e, E, o, {
|
|
161
|
+
source: c,
|
|
162
|
+
snapshotReceivedAt: d,
|
|
163
|
+
statisticsReceivedAt: f
|
|
164
|
+
}),
|
|
98
165
|
source: c,
|
|
99
|
-
version:
|
|
100
|
-
|
|
166
|
+
version: r.version,
|
|
167
|
+
receivedAt: d,
|
|
168
|
+
pendingDetails: E.amendements.filter((e) => e.detailPending).length,
|
|
169
|
+
pendingCurrentDetails: E.amendements.filter((e) => e.detailPending && e.present).length,
|
|
170
|
+
pendingHistoricalDetails: E.amendements.filter((e) => e.detailPending && !e.present).length
|
|
101
171
|
};
|
|
102
172
|
}
|
|
103
173
|
};
|
|
104
174
|
//#endregion
|
|
105
|
-
export {
|
|
175
|
+
export { r as EliasseRequestError, e as EliasseRequestScheduler, a as EliasseRetryDeferredError, d as EliasseSynchronizer, i as classifyEliasseFailure, c as fetchEliasseDetailBatch, l as isEliasseKnownSort, n as mapEliasseConcurrent, t as nextEliasseRetry };
|
package/lib/eliasse.d.ts
CHANGED
|
@@ -151,6 +151,7 @@ export declare const eliasseStatistiquesSchema: z.ZodType<EliasseStatistiques>;
|
|
|
151
151
|
* amendements), eg. `17` for `EXANR5L17PO419610B3058P0D1`.
|
|
152
152
|
*/
|
|
153
153
|
export declare function eliasseUidLegislature(uid: string): number | undefined;
|
|
154
|
+
export { EliasseRequestError, classifyEliasseFailure } from './eliasse-retry.js';
|
|
154
155
|
export declare function fetchEliasseOrganes(options?: EliasseFetchOptions): Promise<EliasseOrgane[]>;
|
|
155
156
|
export declare function fetchEliasseExamens(options?: EliasseFetchOptions): Promise<EliasseExamen[]>;
|
|
156
157
|
export declare function fetchEliasseProchainsADiscuter(options?: EliasseFetchOptions): Promise<EliasseProchainADiscuter[]>;
|
package/lib/eliasse.js
CHANGED
|
@@ -1,150 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/eliasse.ts
|
|
4
|
-
var n = "https://eliasse.assemblee-nationale.fr/api-eliasse/", r = t.object({
|
|
5
|
-
uid: t.string(),
|
|
6
|
-
abreviation: t.string(),
|
|
7
|
-
libelle: t.string(),
|
|
8
|
-
libelleAbrege: t.string(),
|
|
9
|
-
libelleAbregeRaccourci: t.string(),
|
|
10
|
-
dateFin: t.string().nullable()
|
|
11
|
-
}), i = t.object({
|
|
12
|
-
codeMinefi: t.string().nullable().optional(),
|
|
13
|
-
libelle: t.string().nullable().optional(),
|
|
14
|
-
missionLibelle: t.string().nullable().optional(),
|
|
15
|
-
nombreAmendementsMissionTotal: t.number().nullable().optional(),
|
|
16
|
-
nombreAmendementsMissionExamines: t.number().nullable().optional(),
|
|
17
|
-
nombreAmendementsMissionRestants: t.number().nullable().optional()
|
|
18
|
-
}), a = t.object({
|
|
19
|
-
uid: t.string(),
|
|
20
|
-
organeRef: t.string(),
|
|
21
|
-
statut: t.string(),
|
|
22
|
-
texte: t.object({
|
|
23
|
-
uid: t.string(),
|
|
24
|
-
libelle: t.string(),
|
|
25
|
-
bibard: t.string(),
|
|
26
|
-
partie: t.number()
|
|
27
|
-
}),
|
|
28
|
-
estSecondeDeliberation: t.boolean(),
|
|
29
|
-
missions: t.array(i)
|
|
30
|
-
}), o = t.object({
|
|
31
|
-
uidOrgane: t.string(),
|
|
32
|
-
uidTexte: t.string(),
|
|
33
|
-
uidExamen: t.string(),
|
|
34
|
-
uidAmendement: t.string().nullable()
|
|
35
|
-
}), s = t.object({ libelle: t.string() }), c = t.object({
|
|
36
|
-
id: t.string(),
|
|
37
|
-
uid: t.string(),
|
|
38
|
-
numero: t.string(),
|
|
39
|
-
estSousAmendement: t.boolean(),
|
|
40
|
-
sort: t.string().nullable(),
|
|
41
|
-
ordre: t.string(),
|
|
42
|
-
auteur: s,
|
|
43
|
-
positionDiscussionIdentique: t.string().nullable(),
|
|
44
|
-
positionDiscussionCommune: t.string().nullable(),
|
|
45
|
-
positionDiscussionIdentiqueSousAmendement: t.string().nullable(),
|
|
46
|
-
positionDiscussionCommuneSousAmendement: t.string().nullable(),
|
|
47
|
-
estVisible: t.boolean(),
|
|
48
|
-
codeMinefi: t.string().nullable(),
|
|
49
|
-
numeroParent: t.string().nullable().optional(),
|
|
50
|
-
amendementParentRef: t.string().nullable().optional()
|
|
51
|
-
}), l = t.object({
|
|
52
|
-
places: t.array(t.object({
|
|
53
|
-
id: t.string(),
|
|
54
|
-
libelle: t.string(),
|
|
55
|
-
amendements: t.array(c)
|
|
56
|
-
})),
|
|
57
|
-
version: t.number()
|
|
58
|
-
}), u = t.object({
|
|
59
|
-
divisionRef: t.string().nullable(),
|
|
60
|
-
titre: t.string().nullable(),
|
|
61
|
-
articleDesignationCourte: t.string().nullable(),
|
|
62
|
-
articleDesignation: t.string().nullable(),
|
|
63
|
-
type: t.string().nullable(),
|
|
64
|
-
avantApres: t.string().nullable(),
|
|
65
|
-
urlDivisionTexteVise: t.string().nullable(),
|
|
66
|
-
estArticleAdditionnel: t.boolean(),
|
|
67
|
-
estChapitreAdditionnel: t.boolean(),
|
|
68
|
-
contenuHtml: t.string().nullable()
|
|
69
|
-
}), d = t.object({
|
|
70
|
-
typeAuteur: t.string().nullable(),
|
|
71
|
-
ref: t.string().nullable(),
|
|
72
|
-
libelle: t.string(),
|
|
73
|
-
urlPhoto: t.string().nullable(),
|
|
74
|
-
urlFicheActeur: t.string().nullable()
|
|
75
|
-
}), f = t.object({
|
|
76
|
-
uid: t.string(),
|
|
77
|
-
libelle: t.string(),
|
|
78
|
-
prenom: t.string().nullable(),
|
|
79
|
-
nom: t.string().nullable(),
|
|
80
|
-
civilite: t.string().nullable(),
|
|
81
|
-
urlPhoto: t.string().nullable(),
|
|
82
|
-
urlFicheActeur: t.string().nullable()
|
|
83
|
-
}), p = t.object({
|
|
84
|
-
uid: t.string(),
|
|
85
|
-
numero: t.string(),
|
|
86
|
-
numeroParent: t.string().nullable(),
|
|
87
|
-
amendementParentRef: t.string().nullable(),
|
|
88
|
-
estSousAmendement: t.boolean(),
|
|
89
|
-
sort: t.string().nullable(),
|
|
90
|
-
ordre: t.string(),
|
|
91
|
-
division: u.nullable(),
|
|
92
|
-
auteur: d.nullable(),
|
|
93
|
-
auteurParent: d.nullable(),
|
|
94
|
-
cosignataires: t.array(f),
|
|
95
|
-
cosignatairesSuffixe: t.string().nullable(),
|
|
96
|
-
cosignatairesLibelle: t.string().nullable(),
|
|
97
|
-
positionDiscussionIdentique: t.string().nullable(),
|
|
98
|
-
positionDiscussionCommune: t.string().nullable(),
|
|
99
|
-
positionDiscussionIdentiqueSousAmendement: t.string().nullable(),
|
|
100
|
-
positionDiscussionCommuneSousAmendement: t.string().nullable(),
|
|
101
|
-
dispositif: t.string().nullable(),
|
|
102
|
-
exposeSommaire: t.string().nullable(),
|
|
103
|
-
contenuHtmlDuTexteDeReference: t.string().nullable(),
|
|
104
|
-
missionLibelle: t.string().nullable()
|
|
105
|
-
}), m = t.object({
|
|
106
|
-
codeMinefi: t.string().nullable().optional(),
|
|
107
|
-
missionLibelle: t.string().nullable().optional(),
|
|
108
|
-
nombreAmendementsMissionTotal: t.number().nullable().optional(),
|
|
109
|
-
nombreAmendementsMissionExamines: t.number().nullable().optional(),
|
|
110
|
-
nombreAmendementsMissionRestants: t.number().nullable().optional()
|
|
111
|
-
}), h = t.object({
|
|
112
|
-
nombreAmendementsTotal: t.number(),
|
|
113
|
-
nombreAmendementsExamines: t.number(),
|
|
114
|
-
nombreAmendementsRestants: t.number(),
|
|
115
|
-
missions: t.array(m)
|
|
116
|
-
});
|
|
117
|
-
function g(e) {
|
|
118
|
-
let t = /L(\d+)/.exec(e);
|
|
119
|
-
return t === null ? void 0 : Number(t[1]);
|
|
120
|
-
}
|
|
121
|
-
async function _(t, n, r, i) {
|
|
122
|
-
let a = i?.baseUrl ?? "https://eliasse.assemblee-nationale.fr/api-eliasse/", o = new URL(t, a.endsWith("/") ? a : `${a}/`), s = await fetch(o, {
|
|
123
|
-
headers: { Accept: "application/json" },
|
|
124
|
-
signal: i?.signal
|
|
125
|
-
});
|
|
126
|
-
if (!s.ok) throw Error(`Eliasse request failed: ${s.status} ${s.statusText} ${o}`);
|
|
127
|
-
let c = await s.json(), l = n.safeParse(c);
|
|
128
|
-
if (!l.success) throw Error(`Invalid Eliasse ${r} received from ${o}:\n${e(r, l.error, c)}`);
|
|
129
|
-
return c;
|
|
130
|
-
}
|
|
131
|
-
function v(e) {
|
|
132
|
-
return _("organes", t.array(r), "organes", e);
|
|
133
|
-
}
|
|
134
|
-
function y(e) {
|
|
135
|
-
return _("examens", t.array(a), "examens", e);
|
|
136
|
-
}
|
|
137
|
-
function b(e) {
|
|
138
|
-
return _("prochainadiscuter", t.array(o), "prochains à discuter", e);
|
|
139
|
-
}
|
|
140
|
-
function x(e, t) {
|
|
141
|
-
return _(`examens/${encodeURIComponent(e)}/derouleur`, l, "dérouleur", t);
|
|
142
|
-
}
|
|
143
|
-
function S(e, t) {
|
|
144
|
-
return _(`examens/${encodeURIComponent(e)}/statistiques`, h, "statistiques", t);
|
|
145
|
-
}
|
|
146
|
-
function C(e, n, r, i) {
|
|
147
|
-
return _(`textes/${encodeURIComponent(e)}/examens/${encodeURIComponent(n)}/amendements/${encodeURIComponent(r)}/with_neighbors`, t.array(p), "amendements", i);
|
|
148
|
-
}
|
|
149
|
-
//#endregion
|
|
150
|
-
export { d as eliasseAmendementAuteurSchema, p as eliasseAmendementSchema, f as eliasseCosignataireSchema, n as eliasseDefaultBaseUrl, c as eliasseDerouleurAmendementSchema, s as eliasseDerouleurAuteurSchema, l as eliasseDerouleurSchema, u as eliasseDivisionSchema, a as eliasseExamenSchema, i as eliasseMissionSchema, r as eliasseOrganeSchema, o as eliasseProchainADiscuterSchema, m as eliasseStatistiquesMissionSchema, h as eliasseStatistiquesSchema, g as eliasseUidLegislature, C as fetchEliasseAmendementWithNeighbors, x as fetchEliasseDerouleur, y as fetchEliasseExamens, v as fetchEliasseOrganes, b as fetchEliasseProchainsADiscuter, S as fetchEliasseStatistiques };
|
|
1
|
+
import { S as e, T as t, _ as n, a as r, b as i, c as a, d as o, f as s, g as c, h as l, i as u, l as d, m as f, n as p, o as m, p as h, r as g, s as _, t as v, u as y, v as b, x, y as S } from "./eliasse-CP5wde9Z.js";
|
|
2
|
+
export { e as EliasseRequestError, t as classifyEliasseFailure, v as eliasseAmendementAuteurSchema, p as eliasseAmendementSchema, g as eliasseCosignataireSchema, u as eliasseDefaultBaseUrl, r as eliasseDerouleurAmendementSchema, m as eliasseDerouleurAuteurSchema, _ as eliasseDerouleurSchema, a as eliasseDivisionSchema, d as eliasseExamenSchema, y as eliasseMissionSchema, o as eliasseOrganeSchema, s as eliasseProchainADiscuterSchema, h as eliasseStatistiquesMissionSchema, f as eliasseStatistiquesSchema, l as eliasseUidLegislature, c as fetchEliasseAmendementWithNeighbors, n as fetchEliasseDerouleur, b as fetchEliasseExamens, S as fetchEliasseOrganes, i as fetchEliasseProchainsADiscuter, x as fetchEliasseStatistiques };
|
package/lib/parsers.js
CHANGED
|
@@ -8181,7 +8181,7 @@ function Fu(e) {
|
|
|
8181
8181
|
let t = Nu(e.prop("outerHTML") || ""), n = "";
|
|
8182
8182
|
return t("tr").each((e, r) => {
|
|
8183
8183
|
t(r).find("td, th").each((e, r) => {
|
|
8184
|
-
n += t(r).text().trim() + " ";
|
|
8184
|
+
n += t(r).text().replace(/\u00A0/g, " ").trim() + " ";
|
|
8185
8185
|
}), n += "\n";
|
|
8186
8186
|
}), n.trim();
|
|
8187
8187
|
}
|
|
@@ -8546,13 +8546,13 @@ var ed = [
|
|
|
8546
8546
|
"Section"
|
|
8547
8547
|
];
|
|
8548
8548
|
function td(e) {
|
|
8549
|
-
let t = Nu(Pu(e)), n = [], r = [], i = "generalExpose", a = null, o = null, s = t("h1, h2, h3, h4, h5, h6, p.assnatFPFexpogentitre1, p.assnatFPFexpogentexte, li.assnatFPFprojetloiartexte, p.assnatFPFfinartexte, table, img").toArray(), c = () => {
|
|
8549
|
+
let t = Nu(Pu(e)), n = [], r = [], i = "generalExpose", a = null, o = null, s = t("h1, h2, h3, h4, h5, h6, p.assnatFPFexpogentitre1, p.assnatFPFexpogentexte, li.assnatFPFexpogentexte, li.assnatFPFprojetloiartexte, p.assnatFPFprojetloiartexte, p.assnatFPFfinartexte, table, img").toArray(), c = () => {
|
|
8550
8550
|
o && (n.push(o), o = null);
|
|
8551
8551
|
};
|
|
8552
8552
|
for (let e of s) {
|
|
8553
8553
|
if (i === "done") break;
|
|
8554
|
-
let s = t(e), g = Q(s.text()), _ =
|
|
8555
|
-
if (!(v && g.length === 0)) {
|
|
8554
|
+
let s = t(e), g = Q(s.text()), _ = rd(s), v = _ !== null, y = _ !== null && _ >= 2 && _ <= 5, b = s.hasClass("assnatFPFexpogentitre1"), x = s.hasClass("assnatFPFexpogentexte"), S = s.hasClass("assnatFPFprojetloiartexte"), te = s.hasClass("assnatFPFfinartexte"), ne = s.is("table"), re = s.is("img"), ie = s.find("img").length > 0;
|
|
8555
|
+
if (!(v && g.length === 0) && !(ne && s.find("p.assnatFARTT08Bleu").length > 0) && !(ne && nd(s)) && !(x && g.length === 0)) {
|
|
8556
8556
|
if (i === "generalExpose") {
|
|
8557
8557
|
if (_ === 1) {
|
|
8558
8558
|
let e = g.toLowerCase();
|
|
@@ -8564,7 +8564,7 @@ function td(e) {
|
|
|
8564
8564
|
}
|
|
8565
8565
|
if (y && (a && n.push(a), a = null, i = "hierarchy"), a) {
|
|
8566
8566
|
if (re) {
|
|
8567
|
-
let e =
|
|
8567
|
+
let e = od(s);
|
|
8568
8568
|
if (e) {
|
|
8569
8569
|
var l;
|
|
8570
8570
|
(l = a).alineas ?? (l.alineas = []), a.alineas.push(e);
|
|
@@ -8573,7 +8573,7 @@ function td(e) {
|
|
|
8573
8573
|
var u;
|
|
8574
8574
|
(u = a).titres ?? (u.titres = []), a.titres.push($(s));
|
|
8575
8575
|
} else if (b || x) {
|
|
8576
|
-
let e = ie ?
|
|
8576
|
+
let e = ie ? id(s) : $(s);
|
|
8577
8577
|
if (e) {
|
|
8578
8578
|
var d;
|
|
8579
8579
|
(d = a).alineas ?? (d.alineas = []), a.alineas.push(e);
|
|
@@ -8607,6 +8607,7 @@ function td(e) {
|
|
|
8607
8607
|
}
|
|
8608
8608
|
if (S && i === "articleBody" && o) {
|
|
8609
8609
|
var p;
|
|
8610
|
+
if (g.length === 0) continue;
|
|
8610
8611
|
(p = o).alineas ?? (p.alineas = []), o.alineas.push($(s));
|
|
8611
8612
|
continue;
|
|
8612
8613
|
}
|
|
@@ -8641,10 +8642,14 @@ function td(e) {
|
|
|
8641
8642
|
return c(), a && n.push(a), { subdivisions: n };
|
|
8642
8643
|
}
|
|
8643
8644
|
function nd(e) {
|
|
8645
|
+
let t = e.children("tbody").children("tr").add(e.children("tr"));
|
|
8646
|
+
return t.length === 1 && t.children("td").length === 1 && e.find("h6, .assnatFPFexpogentexte").length > 0;
|
|
8647
|
+
}
|
|
8648
|
+
function rd(e) {
|
|
8644
8649
|
for (let t = 1; t <= 6; t++) if (e.is(`h${t}`)) return t;
|
|
8645
8650
|
return null;
|
|
8646
8651
|
}
|
|
8647
|
-
function
|
|
8652
|
+
function id(e) {
|
|
8648
8653
|
let t = e.clone();
|
|
8649
8654
|
t.find("img").remove();
|
|
8650
8655
|
let n = Q(t.text());
|
|
@@ -8653,14 +8658,14 @@ function rd(e) {
|
|
|
8653
8658
|
html: Q(t.html())
|
|
8654
8659
|
} : null;
|
|
8655
8660
|
}
|
|
8656
|
-
function
|
|
8661
|
+
function ad(e) {
|
|
8657
8662
|
if (!e || !/^\d+$/.test(e)) return;
|
|
8658
8663
|
let t = Number(e);
|
|
8659
8664
|
return t > 0 ? t : void 0;
|
|
8660
8665
|
}
|
|
8661
|
-
function
|
|
8666
|
+
function od(e) {
|
|
8662
8667
|
if (!e.attr("src")) return null;
|
|
8663
|
-
let t =
|
|
8668
|
+
let t = ad(e.attr("width")), n = ad(e.attr("height"));
|
|
8664
8669
|
return t === 15 && n === 15 || t === 2 && n === 138 ? null : {
|
|
8665
8670
|
texte: Q(e.attr("alt") ?? ""),
|
|
8666
8671
|
html: e.prop("outerHTML") || ""
|
|
@@ -8668,7 +8673,7 @@ function ad(e) {
|
|
|
8668
8673
|
}
|
|
8669
8674
|
//#endregion
|
|
8670
8675
|
//#region src/parsers/plf/later_stage.ts
|
|
8671
|
-
function
|
|
8676
|
+
function sd(e) {
|
|
8672
8677
|
let t = Nu(Pu(e)), n = [], r = [], i = null, a = null, o = null, s = !1, c = t("p.assnat2PartieNum, p.assnat2PartieIntit, p.assnat4TitreNum, p.assnat4TitreNum0, p.assnat4TitreIntit, p.assnat9ArticleNum, p.assnatLoiTexte, p.assnat1TomeNum, table, p.assnat5ChapitreIntit, p.assnat5ChapitreIntit0, p.assnat5ChapitreNum, p.assnat5ChapitreNum0, p.assnat6SectionIntit, p.assnat6SectionIntit0, p.assnat6SectionNum, p.assnat6SectionNum0").toArray();
|
|
8673
8678
|
for (let e of c) {
|
|
8674
8679
|
let c = t(e), l = Q(c.text());
|
|
@@ -8677,7 +8682,7 @@ function od(e) {
|
|
|
8677
8682
|
if (d) {
|
|
8678
8683
|
for (i && (n.push(i), i = null); r.length > 0 && r[r.length - 1] >= 0;) r.pop();
|
|
8679
8684
|
r.push(0);
|
|
8680
|
-
let e =
|
|
8685
|
+
let e = cd(a, $(c));
|
|
8681
8686
|
a = null, o = null;
|
|
8682
8687
|
let t = Zu(`D_${Xu(e.texte ?? l)}`, "Partie", 1, r.length);
|
|
8683
8688
|
t.titres = [e], n.push(t);
|
|
@@ -8690,7 +8695,7 @@ function od(e) {
|
|
|
8690
8695
|
if (p) {
|
|
8691
8696
|
for (i && (n.push(i), i = null); r.length > 0 && r[r.length - 1] >= 1;) r.pop();
|
|
8692
8697
|
r.push(1);
|
|
8693
|
-
let e =
|
|
8698
|
+
let e = cd(o, $(c));
|
|
8694
8699
|
o = null;
|
|
8695
8700
|
let t = Zu(`D_${Xu(e.texte ?? l)}`, "Titre", 2, r.length);
|
|
8696
8701
|
t.titres = [e], n.push(t);
|
|
@@ -8728,7 +8733,7 @@ function od(e) {
|
|
|
8728
8733
|
}
|
|
8729
8734
|
return i && n.push(i), { subdivisions: n };
|
|
8730
8735
|
}
|
|
8731
|
-
function
|
|
8736
|
+
function cd(e, t) {
|
|
8732
8737
|
return e === null ? t : {
|
|
8733
8738
|
texte: `${e.texte} : ${t.texte}`,
|
|
8734
8739
|
html: `${e.html} : ${t.html}`
|
|
@@ -8736,20 +8741,20 @@ function sd(e, t) {
|
|
|
8736
8741
|
}
|
|
8737
8742
|
//#endregion
|
|
8738
8743
|
//#region src/parsers/plf/variant_detection.ts
|
|
8739
|
-
var
|
|
8744
|
+
var ld = [
|
|
8740
8745
|
"assnatFPFexpogentexte",
|
|
8741
8746
|
"assnatFPFexpogentitre1",
|
|
8742
8747
|
"assnatFPFexpogentitre2",
|
|
8743
8748
|
"assnatFPFexpogentitre3",
|
|
8744
8749
|
"assnatFPFexpogentitre4"
|
|
8745
8750
|
];
|
|
8746
|
-
function
|
|
8751
|
+
function ud(e) {
|
|
8747
8752
|
let t = Nu(Pu(e));
|
|
8748
|
-
return t("h1, h2, h3, h4, h5, h6").toArray().some((e) => Q(t(e).text()).normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().includes("expose general des motifs")) || t(
|
|
8753
|
+
return t("h1, h2, h3, h4, h5, h6").toArray().some((e) => Q(t(e).text()).normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().includes("expose general des motifs")) || t(ld.map((e) => `.${e}`).join(", ")).length > 0 ? "depot" : "laterStage";
|
|
8749
8754
|
}
|
|
8750
8755
|
//#endregion
|
|
8751
8756
|
//#region src/parsers/plf/credits.ts
|
|
8752
|
-
var
|
|
8757
|
+
var dd = {
|
|
8753
8758
|
bg: {
|
|
8754
8759
|
budgetType: "budgetGeneral",
|
|
8755
8760
|
libelle: "Budget général"
|
|
@@ -8767,15 +8772,15 @@ var ud = {
|
|
|
8767
8772
|
libelle: "Comptes de concours financiers"
|
|
8768
8773
|
}
|
|
8769
8774
|
};
|
|
8770
|
-
function
|
|
8775
|
+
function fd(e) {
|
|
8771
8776
|
if (!e) return [];
|
|
8772
|
-
let t = Nu(Pu(e)), n =
|
|
8777
|
+
let t = Nu(Pu(e)), n = vd(t);
|
|
8773
8778
|
if (n.length === 0) return [];
|
|
8774
8779
|
let r = [];
|
|
8775
8780
|
for (let e of n) {
|
|
8776
8781
|
let n = [], i;
|
|
8777
8782
|
for (let r of e.tableEls) {
|
|
8778
|
-
let e =
|
|
8783
|
+
let e = gd(t, r);
|
|
8779
8784
|
n.push(...e.missions), e.total && (i = e.total);
|
|
8780
8785
|
}
|
|
8781
8786
|
n.length === 0 && !e.estConformeVersionPrecedente || r.push({
|
|
@@ -8791,7 +8796,7 @@ function dd(e) {
|
|
|
8791
8796
|
}
|
|
8792
8797
|
return r;
|
|
8793
8798
|
}
|
|
8794
|
-
function
|
|
8799
|
+
function pd(e) {
|
|
8795
8800
|
let t = Q(e).replace(/[\u2212\u2011]/g, "-").replace(/\s/g, "").replace(/[^0-9,.-]/g, ""), n = (t.match(/,/g) ?? []).length;
|
|
8796
8801
|
if (n > 1) return;
|
|
8797
8802
|
let r = n === 1 ? t.replace(/\./g, "").replace(",", ".") : t;
|
|
@@ -8799,23 +8804,23 @@ function fd(e) {
|
|
|
8799
8804
|
let i = Number(r);
|
|
8800
8805
|
return Number.isNaN(i) ? void 0 : i;
|
|
8801
8806
|
}
|
|
8802
|
-
function
|
|
8807
|
+
function md(e) {
|
|
8803
8808
|
let t = Q(e);
|
|
8804
8809
|
if (!/\(\s*ligne\s+supprim(?:ée|ee)\s*\)\s*$/i.test(t)) return t.replace(/\s*\(\s*ligne\s+nouvelle\s*\)\s*$/i, "").trim();
|
|
8805
8810
|
}
|
|
8806
|
-
function
|
|
8807
|
-
let n =
|
|
8811
|
+
function hd(e, t) {
|
|
8812
|
+
let n = pd(t(e[1]).text()), r = pd(t(e[2]).text());
|
|
8808
8813
|
return e.length >= 5 ? {
|
|
8809
8814
|
autorisationEngagement: n,
|
|
8810
8815
|
creditPaiement: r,
|
|
8811
|
-
autorisationEngagementAnnule:
|
|
8812
|
-
creditPaiementAnnule:
|
|
8816
|
+
autorisationEngagementAnnule: pd(t(e[3]).text()),
|
|
8817
|
+
creditPaiementAnnule: pd(t(e[4]).text())
|
|
8813
8818
|
} : {
|
|
8814
8819
|
autorisationEngagement: n,
|
|
8815
8820
|
creditPaiement: r
|
|
8816
8821
|
};
|
|
8817
8822
|
}
|
|
8818
|
-
function
|
|
8823
|
+
function gd(e, t) {
|
|
8819
8824
|
let n = [], r = null, i = null, a, o = e(t).find("tbody tr").toArray(), s = o.some((t) => {
|
|
8820
8825
|
let n = (e(t).find("td").first().attr("style") || "").replace(/[\n\t]/g, " ");
|
|
8821
8826
|
return /border-top/.test(n);
|
|
@@ -8825,7 +8830,7 @@ function hd(e, t) {
|
|
|
8825
8830
|
if (o.length < 3) continue;
|
|
8826
8831
|
let c = e(o[0]), l = (c.attr("style") || "").replace(/[\n\t]/g, " "), u = Q(c.text());
|
|
8827
8832
|
if (!u) continue;
|
|
8828
|
-
let d = /^total/i.test(u), f =
|
|
8833
|
+
let d = /^total/i.test(u), f = hd(o, e);
|
|
8829
8834
|
if (d) {
|
|
8830
8835
|
a = f;
|
|
8831
8836
|
continue;
|
|
@@ -8839,7 +8844,7 @@ function hd(e, t) {
|
|
|
8839
8844
|
}
|
|
8840
8845
|
if (s ? /border-top/.test(l) : /border-bottom/.test(l)) {
|
|
8841
8846
|
r && n.push(r);
|
|
8842
|
-
let e =
|
|
8847
|
+
let e = md(c.text());
|
|
8843
8848
|
if (e === void 0) {
|
|
8844
8849
|
r = null, i = null;
|
|
8845
8850
|
continue;
|
|
@@ -8853,7 +8858,7 @@ function hd(e, t) {
|
|
|
8853
8858
|
continue;
|
|
8854
8859
|
}
|
|
8855
8860
|
if (r) {
|
|
8856
|
-
let e =
|
|
8861
|
+
let e = md(c.text());
|
|
8857
8862
|
if (e === void 0) {
|
|
8858
8863
|
i = null;
|
|
8859
8864
|
continue;
|
|
@@ -8869,11 +8874,11 @@ function hd(e, t) {
|
|
|
8869
8874
|
total: a
|
|
8870
8875
|
};
|
|
8871
8876
|
}
|
|
8872
|
-
function
|
|
8877
|
+
function _d(e, t) {
|
|
8873
8878
|
let n = e(t).find("tr").slice(0, 3).find("th, td").toArray().map((t) => Q(e(t).text()).toLocaleLowerCase("fr"));
|
|
8874
8879
|
return n.some((e) => e.includes("mission / programme")) && n.some((e) => e.includes("autorisation") && e.includes("engagement")) && n.some((e) => e.includes("crédit") && e.includes("paiement"));
|
|
8875
8880
|
}
|
|
8876
|
-
function
|
|
8881
|
+
function vd(e) {
|
|
8877
8882
|
let t, n, r = !1, i = /* @__PURE__ */ new Map(), a = e("p, h1, h2, h3, h4, h5, h6, a:not([href]), table").toArray().filter((t) => e(t).parents("table").length === 0);
|
|
8878
8883
|
for (let o of a) {
|
|
8879
8884
|
let a = e(o);
|
|
@@ -8890,7 +8895,7 @@ function _d(e) {
|
|
|
8890
8895
|
for (let t of e) {
|
|
8891
8896
|
let e = i.get(t);
|
|
8892
8897
|
e ? e.estConformeVersionPrecedente = !0 : i.set(t, {
|
|
8893
|
-
...
|
|
8898
|
+
...dd[t],
|
|
8894
8899
|
tableEls: [],
|
|
8895
8900
|
estConformeVersionPrecedente: !0
|
|
8896
8901
|
});
|
|
@@ -8906,7 +8911,7 @@ function _d(e) {
|
|
|
8906
8911
|
s !== /COMPTES\s+DE\s+CONCOURS\s+FINANCIERS/i.test(e) && (n = s ? "cas" : "ccf");
|
|
8907
8912
|
continue;
|
|
8908
8913
|
}
|
|
8909
|
-
if (!
|
|
8914
|
+
if (!_d(e, o)) continue;
|
|
8910
8915
|
let s = t === "B" ? "bg" : t === "C" ? "ba" : t === "D" ? n : void 0;
|
|
8911
8916
|
if (!s) continue;
|
|
8912
8917
|
r = !0;
|
|
@@ -8916,7 +8921,7 @@ function _d(e) {
|
|
|
8916
8921
|
continue;
|
|
8917
8922
|
}
|
|
8918
8923
|
i.set(s, {
|
|
8919
|
-
...
|
|
8924
|
+
...dd[s],
|
|
8920
8925
|
tableEls: [o],
|
|
8921
8926
|
estConformeVersionPrecedente: !1
|
|
8922
8927
|
});
|
|
@@ -8925,8 +8930,8 @@ function _d(e) {
|
|
|
8925
8930
|
}
|
|
8926
8931
|
//#endregion
|
|
8927
8932
|
//#region src/parsers/plf/index.ts
|
|
8928
|
-
function
|
|
8929
|
-
return e ?
|
|
8933
|
+
function yd(e) {
|
|
8934
|
+
return e ? ud(e) === "depot" ? td(e) : sd(e) : { subdivisions: [] };
|
|
8930
8935
|
}
|
|
8931
8936
|
//#endregion
|
|
8932
|
-
export { Ju as iterRechercheAmendements, Yu as iterRechercheRawAmendements,
|
|
8937
|
+
export { Ju as iterRechercheAmendements, Yu as iterRechercheRawAmendements, yd as parsePlf, fd as parsePlfCredits, Wu as parseTexte };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -20,6 +20,10 @@ declare const retrieveDocumentsParser: import('zod-opts').Parser<{
|
|
|
20
20
|
description: string;
|
|
21
21
|
type: z.ZodDefault<z.ZodNumber>;
|
|
22
22
|
};
|
|
23
|
+
forceFetchDocuments: {
|
|
24
|
+
description: string;
|
|
25
|
+
type: z.ZodDefault<z.ZodBoolean>;
|
|
26
|
+
};
|
|
23
27
|
forceParseDocuments: {
|
|
24
28
|
description: string;
|
|
25
29
|
type: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface TargetedDocumentEntry {
|
|
2
|
+
document: unknown;
|
|
3
|
+
sourceUrl: string;
|
|
4
|
+
note?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function requestedDocumentUids(value: string, legislature: number): string[];
|
|
7
|
+
export declare function prepareTargetedDocuments({ dataDir, outputDir, legislature, documentUids, metadataFile, persistMetadata, }: {
|
|
8
|
+
dataDir: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
legislature: number;
|
|
11
|
+
documentUids: string;
|
|
12
|
+
metadataFile?: string;
|
|
13
|
+
persistMetadata?: boolean;
|
|
14
|
+
}): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|