@tricoteuses/senat 3.1.6 → 3.1.7

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.
Files changed (80) hide show
  1. package/lib/src/config.d.ts +43 -0
  2. package/lib/src/config.js +37 -0
  3. package/lib/src/conversion_textes.d.ts +11 -0
  4. package/lib/src/conversion_textes.js +320 -0
  5. package/lib/src/databases_postgres.d.ts +4 -0
  6. package/lib/src/databases_postgres.js +23 -0
  7. package/lib/src/datasets.d.ts +38 -0
  8. package/lib/src/datasets.js +247 -0
  9. package/lib/src/git.d.ts +27 -0
  10. package/lib/src/git.js +251 -0
  11. package/lib/src/loaders.d.ts +52 -0
  12. package/lib/src/loaders.js +260 -0
  13. package/lib/src/model/agenda.d.ts +6 -0
  14. package/lib/src/model/agenda.js +148 -0
  15. package/lib/src/model/ameli.d.ts +67 -0
  16. package/lib/src/model/ameli.js +150 -0
  17. package/lib/src/model/commission.d.ts +19 -0
  18. package/lib/src/model/commission.js +269 -0
  19. package/lib/src/model/debats.d.ts +39 -0
  20. package/lib/src/model/debats.js +112 -0
  21. package/lib/src/model/documents.d.ts +32 -0
  22. package/lib/src/model/documents.js +182 -0
  23. package/lib/src/model/dosleg.d.ts +144 -0
  24. package/lib/src/model/dosleg.js +468 -0
  25. package/lib/src/model/index.d.ts +7 -0
  26. package/lib/src/model/index.js +7 -0
  27. package/lib/src/model/questions.d.ts +54 -0
  28. package/lib/src/model/questions.js +91 -0
  29. package/lib/src/model/scrutins.d.ts +48 -0
  30. package/lib/src/model/scrutins.js +121 -0
  31. package/lib/src/model/seance.d.ts +3 -0
  32. package/lib/src/model/seance.js +267 -0
  33. package/lib/src/model/sens.d.ts +112 -0
  34. package/lib/src/model/sens.js +385 -0
  35. package/lib/src/model/util.d.ts +1 -0
  36. package/lib/src/model/util.js +15 -0
  37. package/lib/src/raw_types/ameli.d.ts +1762 -0
  38. package/lib/src/raw_types/ameli.js +1074 -0
  39. package/lib/src/raw_types/debats.d.ts +380 -0
  40. package/lib/src/raw_types/debats.js +266 -0
  41. package/lib/src/raw_types/dosleg.d.ts +2954 -0
  42. package/lib/src/raw_types/dosleg.js +2005 -0
  43. package/lib/src/raw_types/questions.d.ts +699 -0
  44. package/lib/src/raw_types/questions.js +493 -0
  45. package/lib/src/raw_types/sens.d.ts +7843 -0
  46. package/lib/src/raw_types/sens.js +4691 -0
  47. package/lib/src/raw_types_schemats/ameli.d.ts +541 -0
  48. package/lib/src/raw_types_schemats/ameli.js +2 -0
  49. package/lib/src/raw_types_schemats/debats.d.ts +127 -0
  50. package/lib/src/raw_types_schemats/debats.js +2 -0
  51. package/lib/src/raw_types_schemats/dosleg.d.ts +977 -0
  52. package/lib/src/raw_types_schemats/dosleg.js +2 -0
  53. package/lib/src/raw_types_schemats/questions.d.ts +237 -0
  54. package/lib/src/raw_types_schemats/questions.js +2 -0
  55. package/lib/src/raw_types_schemats/sens.d.ts +2709 -0
  56. package/lib/src/raw_types_schemats/sens.js +2 -0
  57. package/lib/src/scripts/convert_data.js +7 -5
  58. package/lib/src/scripts/debug_dosleg_query.d.ts +6 -0
  59. package/lib/src/scripts/debug_dosleg_query.js +50 -0
  60. package/lib/src/types/agenda.d.ts +45 -0
  61. package/lib/src/types/agenda.js +1 -0
  62. package/lib/src/types/ameli.d.ts +5 -0
  63. package/lib/src/types/ameli.js +1 -0
  64. package/lib/src/types/compte_rendu.d.ts +83 -0
  65. package/lib/src/types/compte_rendu.js +1 -0
  66. package/lib/src/types/debats.d.ts +2 -0
  67. package/lib/src/types/debats.js +1 -0
  68. package/lib/src/types/dosleg.d.ts +70 -0
  69. package/lib/src/types/dosleg.js +1 -0
  70. package/lib/src/types/questions.d.ts +2 -0
  71. package/lib/src/types/questions.js +1 -0
  72. package/lib/src/types/sens.d.ts +8 -0
  73. package/lib/src/types/sens.js +1 -0
  74. package/lib/src/types/sessions.d.ts +6 -0
  75. package/lib/src/types/sessions.js +19 -0
  76. package/lib/src/types/texte.d.ts +72 -0
  77. package/lib/src/types/texte.js +15 -0
  78. package/lib/src/validators/config.d.ts +9 -0
  79. package/lib/src/validators/config.js +10 -0
  80. package/package.json +1 -1
@@ -0,0 +1,43 @@
1
+ import "dotenv/config";
2
+ import { z } from "zod";
3
+ export declare const dbSchema: z.ZodObject<{
4
+ host: z.ZodString;
5
+ name: z.ZodString;
6
+ password: z.ZodString;
7
+ port: z.ZodCoercedNumber<unknown>;
8
+ user: z.ZodString;
9
+ }, z.core.$strip>;
10
+ export type DbConfig = z.infer<typeof dbSchema>;
11
+ export declare const configSchema: z.ZodObject<{
12
+ db: z.ZodObject<{
13
+ host: z.ZodString;
14
+ name: z.ZodString;
15
+ password: z.ZodString;
16
+ port: z.ZodCoercedNumber<unknown>;
17
+ user: z.ZodString;
18
+ }, z.core.$strip>;
19
+ stagingDb: z.ZodObject<{
20
+ host: z.ZodString;
21
+ name: z.ZodString;
22
+ password: z.ZodString;
23
+ port: z.ZodCoercedNumber<unknown>;
24
+ user: z.ZodString;
25
+ }, z.core.$strip>;
26
+ }, z.core.$strip>;
27
+ declare const _default: {
28
+ db: {
29
+ host: string;
30
+ name: string;
31
+ password: string;
32
+ port: number;
33
+ user: string;
34
+ };
35
+ stagingDb: {
36
+ host: string;
37
+ name: string;
38
+ password: string;
39
+ port: number;
40
+ user: string;
41
+ };
42
+ };
43
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import "dotenv/config";
2
+ import { z } from "zod";
3
+ export const dbSchema = z.object({
4
+ host: z.string().trim().min(1, "Must not be empty"),
5
+ name: z.string().trim().min(1, "Must not be empty"),
6
+ password: z.string().trim().min(1, "Must not be empty"),
7
+ port: z.coerce.number().int().min(0).max(65535),
8
+ user: z.string().trim().min(1, "Must not be empty"),
9
+ });
10
+ export const configSchema = z.object({
11
+ db: dbSchema,
12
+ stagingDb: dbSchema,
13
+ });
14
+ const config = {
15
+ db: {
16
+ host: process.env["DB_HOST"] || "localhost",
17
+ name: process.env["DB_NAME"] || "senat",
18
+ password: process.env["DB_PASSWORD"] || "opendata",
19
+ port: process.env["DB_PORT"] || 5432,
20
+ user: process.env["DB_USER"] || "opendata",
21
+ },
22
+ stagingDb: {
23
+ host: process.env["STAGING_DB_HOST"] || process.env["DB_HOST"] || "localhost",
24
+ name: process.env["STAGING_DB_NAME"] || "senat_staging",
25
+ password: process.env["STAGING_DB_PASSWORD"] || process.env["DB_PASSWORD"] || "opendata",
26
+ port: process.env["STAGING_DB_PORT"] || process.env["DB_PORT"] || 5432,
27
+ user: process.env["STAGING_DB_USER"] || process.env["DB_USER"] || "opendata",
28
+ },
29
+ };
30
+ const result = configSchema.safeParse(config);
31
+ if (!result.success) {
32
+ const issues = JSON.stringify(result.error.issues, null, 2);
33
+ const serializedConfig = JSON.stringify(config, null, 2);
34
+ console.error(`Error in configuration:\n${serializedConfig}\nError:\n${issues}`);
35
+ process.exit(-1);
36
+ }
37
+ export default result.data;
@@ -0,0 +1,11 @@
1
+ export interface SenatMetadata {
2
+ number: string | null;
3
+ session: string | null;
4
+ date: string | null;
5
+ type: string | null;
6
+ authors: string | null;
7
+ title: string | null;
8
+ commission: string | null;
9
+ }
10
+ export declare function extractMetadata(xmlDoc: Document): SenatMetadata;
11
+ export declare function convertSenatXmlToHtml(texteXml: string, outputFilePath: string): Promise<void>;
@@ -0,0 +1,320 @@
1
+ import { JSDOM } from "jsdom";
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+ import { DateTime } from "luxon";
5
+ export function extractMetadata(xmlDoc) {
6
+ const metadata = {
7
+ number: null,
8
+ session: null,
9
+ date: null,
10
+ type: null,
11
+ authors: null,
12
+ title: xmlDoc.querySelector("docTitle")?.textContent?.trim() || null,
13
+ commission: null,
14
+ };
15
+ // Extract Number
16
+ const docIdAlias = xmlDoc.querySelector('FRBRalias[name="signet-dossier-legislatif-senat"]');
17
+ if (docIdAlias) {
18
+ const value = docIdAlias.getAttribute("value");
19
+ if (value) {
20
+ const match = value.match(/\d+$/);
21
+ if (match)
22
+ metadata.number = match[0];
23
+ }
24
+ }
25
+ // Extract Session
26
+ const sessionUri = xmlDoc.querySelector("FRBRExpression > FRBRuri")?.getAttribute("value");
27
+ if (sessionUri) {
28
+ const match = sessionUri.match(/\d{4}-\d{4}/);
29
+ if (match)
30
+ metadata.session = match[0];
31
+ }
32
+ // Extract Date
33
+ const depotDate = xmlDoc.querySelector('FRBRdate[name="#depot"]')?.getAttribute("date");
34
+ if (depotDate) {
35
+ metadata.date = DateTime.fromISO(depotDate).setLocale("fr").toFormat("d MMMM yyyy");
36
+ }
37
+ else {
38
+ const presentationDate = xmlDoc.querySelector('FRBRdate[name="#presentation"]')?.getAttribute("date");
39
+ if (presentationDate) {
40
+ metadata.date = DateTime.fromISO(presentationDate).setLocale("fr").toFormat("d MMMM yyyy");
41
+ }
42
+ }
43
+ // Extract Type
44
+ const bill = xmlDoc.querySelector("bill");
45
+ const typeCode = bill?.getAttribute("name");
46
+ if (typeCode === "ppl") {
47
+ metadata.type = "PROPOSITION DE LOI";
48
+ }
49
+ else if (typeCode === "pjl") {
50
+ metadata.type = "PROJET DE LOI";
51
+ }
52
+ // Extract Authors
53
+ const authorRef = xmlDoc.querySelector('FRBRWork > FRBRauthor[as="#auteur"]')?.getAttribute("href");
54
+ if (authorRef) {
55
+ const authorId = authorRef.replace(/^#/, "");
56
+ const authorPerson = xmlDoc.querySelector(`TLCPerson[eId="${authorId}"]`);
57
+ if (authorPerson) {
58
+ const showAs = authorPerson.getAttribute("showAs");
59
+ if (showAs) {
60
+ metadata.authors = showAs.replace(/, Sénateurs$/, ", Sénateurs et Sénatrices");
61
+ }
62
+ }
63
+ }
64
+ // Extract Commission
65
+ const commissionNode = xmlDoc.querySelector('TLCOrganization[eId="commission-senat"]') ||
66
+ xmlDoc.querySelector('TLCOrganization[eId^="commission-"]:not([eId*="assemblee"])');
67
+ if (commissionNode) {
68
+ metadata.commission = commissionNode.getAttribute("showAs");
69
+ }
70
+ return metadata;
71
+ }
72
+ export async function convertSenatXmlToHtml(texteXml, outputFilePath) {
73
+ let xmlDoc;
74
+ try {
75
+ xmlDoc = new JSDOM(texteXml, { contentType: "text/xml" }).window.document;
76
+ }
77
+ catch (err) {
78
+ if (await fs.pathExists(outputFilePath)) {
79
+ await fs.remove(outputFilePath);
80
+ }
81
+ throw err;
82
+ }
83
+ const metadata = extractMetadata(xmlDoc);
84
+ const xmlBody = xmlDoc.querySelector("body");
85
+ const style = `
86
+ body {
87
+ font-family: "URW Bookman", "Bookman Old Style", serif;
88
+ max-width: 800px;
89
+ margin: 40px auto;
90
+ line-height: 1.5;
91
+ color: #333;
92
+ }
93
+ .header {
94
+ text-align: center;
95
+ margin-bottom: 40px;
96
+ border-bottom: 2px solid #333;
97
+ padding-bottom: 20px;
98
+ }
99
+ .header-top {
100
+ font-weight: bold;
101
+ font-size: 1.2em;
102
+ margin-bottom: 10px;
103
+ }
104
+ .header-session {
105
+ text-transform: uppercase;
106
+ font-size: 0.9em;
107
+ margin-bottom: 5px;
108
+ }
109
+ .header-date {
110
+ font-size: 0.9em;
111
+ margin-bottom: 5px;
112
+ }
113
+ .header-number {
114
+ font-weight: bold;
115
+ font-size: 1.1em;
116
+ margin-bottom: 20px;
117
+ }
118
+ .header-type {
119
+ font-weight: bold;
120
+ font-size: 1.5em;
121
+ margin-top: 20px;
122
+ }
123
+ .header-authors {
124
+ margin-top: 20px;
125
+ font-style: italic;
126
+ }
127
+ .header-commission {
128
+ margin-top: 15px;
129
+ font-size: 0.9em;
130
+ }
131
+ h1 {
132
+ text-align: center;
133
+ font-size: 1.8em;
134
+ margin-top: 10px;
135
+ }
136
+ p {
137
+ margin: 0.6em 0;
138
+ }
139
+ p.has-alinea {
140
+ position: relative;
141
+ padding-left: 2.5em;
142
+ }
143
+ .alinea {
144
+ position: absolute;
145
+ left: 0;
146
+ top: 0.15em;
147
+ display: inline-flex;
148
+ align-items: center;
149
+ justify-content: center;
150
+ min-width: 1.5em;
151
+ height: 1.5em;
152
+ padding: 0 0.3em;
153
+ margin-right: 0.3em;
154
+ font-size: 0.75em;
155
+ font-weight: bold;
156
+ color: #555;
157
+ background-color: #f0f0f0;
158
+ border: 1px solid #ccc;
159
+ border-radius: 1em;
160
+ }
161
+ .num {
162
+ font-weight: bold;
163
+ margin-right: 0.2em;
164
+ }
165
+ .article {
166
+ margin-top: 2em;
167
+ }
168
+ .article h3 {
169
+ border-bottom: 1px solid #eee;
170
+ padding-bottom: 5px;
171
+ }
172
+ `;
173
+ const htmlDocTemplate = `<!DOCTYPE html>
174
+ <html lang="fr">
175
+ <head>
176
+ <meta charset="utf-8">
177
+ <title>${metadata.title || "Document Sénat"}</title>
178
+ <style>${style}</style>
179
+ </head>
180
+ <body>
181
+ <div class="header">
182
+ <div class="header-top">SÉNAT</div>
183
+ <div class="header-session">SESSION ORDINAIRE DE ${metadata.session || "...."}</div>
184
+ ${metadata.date ? `<div class="header-date">Enregistré à la Présidence du Sénat le ${metadata.date}</div>` : ""}
185
+ <div class="header-number">N° ${metadata.number || "...."}</div>
186
+ <div class="header-type">${metadata.type || ""}</div>
187
+ <div class="header-authors">${metadata.authors || ""}</div>
188
+ ${metadata.commission
189
+ ? [
190
+ `<div class="header-commission">Envoyée à la ${metadata.commission.toLowerCase()},`,
191
+ "sous réserve de la constitution éventuelle d'une commission spéciale dans les conditions prévues",
192
+ "par le Règlement.</div>",
193
+ ].join(" ")
194
+ : ""}
195
+ </div>
196
+ <h1>${metadata.title || ""}</h1>
197
+ </body>
198
+ </html>`;
199
+ const { document: htmlDoc } = new JSDOM(htmlDocTemplate).window;
200
+ const body = htmlDoc.body;
201
+ if (xmlBody) {
202
+ const processNode = (xmlNode, htmlParent, alineaData = null) => {
203
+ const children = Array.from(xmlNode.childNodes);
204
+ const alineaChildren = [];
205
+ const otherChildren = [];
206
+ for (const child of children) {
207
+ if (child.nodeType === 1 && child.tagName.toLowerCase() === "alinea") {
208
+ alineaChildren.push(child);
209
+ }
210
+ else {
211
+ otherChildren.push(child);
212
+ }
213
+ }
214
+ for (const child of otherChildren) {
215
+ if (child.nodeType === 3) {
216
+ htmlParent.appendChild(htmlDoc.createTextNode(child.textContent || ""));
217
+ }
218
+ else if (child.nodeType === 1) {
219
+ const element = child;
220
+ const tagName = element.tagName.toLowerCase();
221
+ let htmlElement = null;
222
+ switch (tagName) {
223
+ case "article": {
224
+ htmlElement = htmlDoc.createElement("div");
225
+ htmlElement.className = "article";
226
+ const artId = element.getAttribute("eId");
227
+ if (artId)
228
+ htmlElement.id = artId;
229
+ const artGuid = element.getAttribute("GUID");
230
+ if (artGuid)
231
+ htmlElement.setAttribute("data-guid", artGuid);
232
+ break;
233
+ }
234
+ case "num": {
235
+ const parentTagName = element.parentElement?.tagName.toLowerCase();
236
+ if (parentTagName === "alinea" && alineaData) {
237
+ alineaData.numText = element.textContent?.trim();
238
+ continue;
239
+ }
240
+ htmlElement = htmlDoc.createElement("span");
241
+ htmlElement.className = "num";
242
+ break;
243
+ }
244
+ case "heading":
245
+ htmlElement = htmlDoc.createElement("h4");
246
+ break;
247
+ case "p":
248
+ htmlElement = htmlDoc.createElement("p");
249
+ if (alineaData) {
250
+ htmlElement.classList.add("has-alinea");
251
+ if (alineaData.id)
252
+ htmlElement.id = alineaData.id;
253
+ if (alineaData.guid)
254
+ htmlElement.setAttribute("data-guid", alineaData.guid);
255
+ const pastille = alineaData.pastille;
256
+ if (pastille) {
257
+ htmlElement.setAttribute("data-pastille", pastille);
258
+ if (!alineaData.pastilleApplied) {
259
+ const span = htmlDoc.createElement("span");
260
+ span.className = "alinea";
261
+ span.setAttribute("data-alinea", pastille);
262
+ span.textContent = pastille;
263
+ htmlElement.appendChild(span);
264
+ alineaData.pastilleApplied = true;
265
+ }
266
+ }
267
+ if (alineaData.numText) {
268
+ const xmlPText = element.textContent || "";
269
+ const normalize = (s) => s.replace(/[\\s\\u00A0]+/g, " ").trim();
270
+ const normalizedNum = normalize(alineaData.numText);
271
+ const normalizedP = normalize(xmlPText);
272
+ if (normalizedNum && !normalizedP.startsWith(normalizedNum)) {
273
+ const numSpan = htmlDoc.createElement("span");
274
+ numSpan.className = "num";
275
+ numSpan.textContent = alineaData.numText + " ";
276
+ htmlElement.appendChild(numSpan);
277
+ }
278
+ alineaData.numText = null;
279
+ }
280
+ }
281
+ break;
282
+ case "content":
283
+ processNode(element, htmlParent, alineaData);
284
+ continue;
285
+ case "doctitle":
286
+ continue;
287
+ case "i":
288
+ case "b":
289
+ case "u":
290
+ case "sup":
291
+ case "sub":
292
+ htmlElement = htmlDoc.createElement(tagName);
293
+ break;
294
+ default:
295
+ htmlElement = htmlDoc.createElement("span");
296
+ htmlElement.setAttribute("data-xml-tag", tagName);
297
+ break;
298
+ }
299
+ if (htmlElement) {
300
+ htmlParent.appendChild(htmlElement);
301
+ processNode(element, htmlElement, alineaData);
302
+ }
303
+ }
304
+ }
305
+ for (const element of alineaChildren) {
306
+ const nextAlineaData = {
307
+ id: element.getAttribute("eId"),
308
+ guid: element.getAttribute("GUID"),
309
+ pastille: element.getAttribute("data:pastille"),
310
+ pastilleApplied: false,
311
+ };
312
+ processNode(element, htmlParent, nextAlineaData);
313
+ }
314
+ };
315
+ processNode(xmlBody, body);
316
+ }
317
+ const htmlContent = "<!DOCTYPE html>\n" + htmlDoc.documentElement.outerHTML;
318
+ await fs.ensureDir(path.dirname(outputFilePath));
319
+ await fs.outputFile(outputFilePath, htmlContent);
320
+ }
@@ -0,0 +1,4 @@
1
+ import postgres from "postgres";
2
+ export type SqlValue = postgres.ParameterOrJSON<never>;
3
+ export declare const sql: postgres.Sql<{}>;
4
+ export declare function streamUnsafeQuery<T>(query: string, params?: readonly unknown[], batchSize?: number): AsyncGenerator<T, void, unknown>;
@@ -0,0 +1,23 @@
1
+ import postgres from "postgres";
2
+ import config from "./config.js";
3
+ export const sql = postgres({
4
+ database: config.db.name,
5
+ host: config.db.host,
6
+ password: config.db.password,
7
+ port: config.db.port,
8
+ transform: {
9
+ undefined: null,
10
+ },
11
+ user: config.db.user,
12
+ });
13
+ function toSqlValue(value) {
14
+ return value;
15
+ }
16
+ export async function* streamUnsafeQuery(query, params = [], batchSize = 100) {
17
+ const values = params.map(toSqlValue);
18
+ for await (const rows of sql.unsafe(query, values).cursor(batchSize)) {
19
+ for (const row of rows) {
20
+ yield row;
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,38 @@
1
+ export interface Dataset {
2
+ database: string;
3
+ repairEncoding: boolean;
4
+ repairZip?: (dataset: Dataset, dataDir: string) => void;
5
+ title: string;
6
+ url: string;
7
+ indexes?: {
8
+ [table: string]: Array<{
9
+ name: string;
10
+ columns: string[];
11
+ }>;
12
+ };
13
+ mergeKeys?: {
14
+ [table: string]: string[];
15
+ };
16
+ rowMultisetMergeTables?: string[];
17
+ }
18
+ export interface Datasets {
19
+ ameli: Dataset;
20
+ debats: Dataset;
21
+ dosleg: Dataset;
22
+ questions: Dataset;
23
+ sens: Dataset;
24
+ }
25
+ export declare enum EnabledDatasets {
26
+ None = 0,
27
+ Ameli = 1,
28
+ Debats = 2,
29
+ DosLeg = 4,
30
+ Questions = 8,
31
+ Sens = 16,
32
+ PhotosSenateurs = 32,
33
+ Agenda = 64,
34
+ All = 127
35
+ }
36
+ export declare const datasets: Datasets;
37
+ export declare function getEnabledDatasets(categories: string[]): EnabledDatasets;
38
+ export declare function getChosenDatasets(enabledDatasets: EnabledDatasets): Dataset[];