@tricoteuses/senat 3.1.7 → 3.1.8

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/server/sens.js +49 -29
  2. package/package.json +1 -1
  3. package/lib/src/config.d.ts +0 -43
  4. package/lib/src/config.js +0 -37
  5. package/lib/src/conversion_textes.d.ts +0 -11
  6. package/lib/src/conversion_textes.js +0 -320
  7. package/lib/src/databases_postgres.d.ts +0 -4
  8. package/lib/src/databases_postgres.js +0 -23
  9. package/lib/src/datasets.d.ts +0 -38
  10. package/lib/src/datasets.js +0 -247
  11. package/lib/src/git.d.ts +0 -27
  12. package/lib/src/git.js +0 -251
  13. package/lib/src/loaders.d.ts +0 -52
  14. package/lib/src/loaders.js +0 -260
  15. package/lib/src/model/agenda.d.ts +0 -6
  16. package/lib/src/model/agenda.js +0 -148
  17. package/lib/src/model/ameli.d.ts +0 -67
  18. package/lib/src/model/ameli.js +0 -150
  19. package/lib/src/model/commission.d.ts +0 -19
  20. package/lib/src/model/commission.js +0 -269
  21. package/lib/src/model/debats.d.ts +0 -39
  22. package/lib/src/model/debats.js +0 -112
  23. package/lib/src/model/documents.d.ts +0 -32
  24. package/lib/src/model/documents.js +0 -182
  25. package/lib/src/model/dosleg.d.ts +0 -144
  26. package/lib/src/model/dosleg.js +0 -468
  27. package/lib/src/model/index.d.ts +0 -7
  28. package/lib/src/model/index.js +0 -7
  29. package/lib/src/model/questions.d.ts +0 -54
  30. package/lib/src/model/questions.js +0 -91
  31. package/lib/src/model/scrutins.d.ts +0 -48
  32. package/lib/src/model/scrutins.js +0 -121
  33. package/lib/src/model/seance.d.ts +0 -3
  34. package/lib/src/model/seance.js +0 -267
  35. package/lib/src/model/sens.d.ts +0 -112
  36. package/lib/src/model/sens.js +0 -385
  37. package/lib/src/model/util.d.ts +0 -1
  38. package/lib/src/model/util.js +0 -15
  39. package/lib/src/raw_types/ameli.d.ts +0 -1762
  40. package/lib/src/raw_types/ameli.js +0 -1074
  41. package/lib/src/raw_types/debats.d.ts +0 -380
  42. package/lib/src/raw_types/debats.js +0 -266
  43. package/lib/src/raw_types/dosleg.d.ts +0 -2954
  44. package/lib/src/raw_types/dosleg.js +0 -2005
  45. package/lib/src/raw_types/questions.d.ts +0 -699
  46. package/lib/src/raw_types/questions.js +0 -493
  47. package/lib/src/raw_types/sens.d.ts +0 -7843
  48. package/lib/src/raw_types/sens.js +0 -4691
  49. package/lib/src/raw_types_schemats/ameli.d.ts +0 -541
  50. package/lib/src/raw_types_schemats/ameli.js +0 -2
  51. package/lib/src/raw_types_schemats/debats.d.ts +0 -127
  52. package/lib/src/raw_types_schemats/debats.js +0 -2
  53. package/lib/src/raw_types_schemats/dosleg.d.ts +0 -977
  54. package/lib/src/raw_types_schemats/dosleg.js +0 -2
  55. package/lib/src/raw_types_schemats/questions.d.ts +0 -237
  56. package/lib/src/raw_types_schemats/questions.js +0 -2
  57. package/lib/src/raw_types_schemats/sens.d.ts +0 -2709
  58. package/lib/src/raw_types_schemats/sens.js +0 -2
  59. package/lib/src/scripts/debug_dosleg_query.d.ts +0 -6
  60. package/lib/src/scripts/debug_dosleg_query.js +0 -50
  61. package/lib/src/types/agenda.d.ts +0 -45
  62. package/lib/src/types/agenda.js +0 -1
  63. package/lib/src/types/ameli.d.ts +0 -5
  64. package/lib/src/types/ameli.js +0 -1
  65. package/lib/src/types/compte_rendu.d.ts +0 -83
  66. package/lib/src/types/compte_rendu.js +0 -1
  67. package/lib/src/types/debats.d.ts +0 -2
  68. package/lib/src/types/debats.js +0 -1
  69. package/lib/src/types/dosleg.d.ts +0 -70
  70. package/lib/src/types/dosleg.js +0 -1
  71. package/lib/src/types/questions.d.ts +0 -2
  72. package/lib/src/types/questions.js +0 -1
  73. package/lib/src/types/sens.d.ts +0 -8
  74. package/lib/src/types/sens.js +0 -1
  75. package/lib/src/types/sessions.d.ts +0 -6
  76. package/lib/src/types/sessions.js +0 -19
  77. package/lib/src/types/texte.d.ts +0 -72
  78. package/lib/src/types/texte.js +0 -15
  79. package/lib/src/validators/config.d.ts +0 -9
  80. package/lib/src/validators/config.js +0 -10
@@ -70,9 +70,9 @@ export async function* findAll() {
70
70
  sql `to_char(memcom.memcomdatdeb, 'YYYY-MM-DD')`.as("date_debut"),
71
71
  sql `to_char(memcom.memcomdatfin, 'YYYY-MM-DD')`.as("date_fin"),
72
72
  "memcom.temvalcod as etat",
73
- "com2.comlilmin as libelle",
73
+ sql `nullif(btrim(com2.comlilmin), '')`.as("libelle"),
74
74
  "com2.typorgcod as type_code_organisme",
75
- "typorg.typorglib as type_organisme",
75
+ sql `nullif(btrim(typorg.typorglib), '')`.as("type_organisme"),
76
76
  "memcom.memcomdatdeb as order_date",
77
77
  // Fonctions dans la commission
78
78
  jsonArrayFrom(eb2
@@ -83,9 +83,9 @@ export async function* findAll() {
83
83
  sql `to_char(fonmemcom.fonmemcomdatdeb, 'YYYY-MM-DD')`.as("date_debut"),
84
84
  sql `to_char(fonmemcom.fonmemcomdatfin, 'YYYY-MM-DD')`.as("date_fin"),
85
85
  sql `coalesce(
86
- nullif(foncom.foncomlib, ''),
87
- nullif(foncom.foncomlil, ''),
88
- nullif(foncom.foncomlic, ''))`.as("libelle"),
86
+ nullif(btrim(foncom.foncomlib), ''),
87
+ nullif(btrim(foncom.foncomlil), ''),
88
+ nullif(btrim(foncom.foncomlic), ''))`.as("libelle"),
89
89
  "fonmemcom.fonmemcomdatdeb as order_date",
90
90
  ])
91
91
  .whereRef("fonmemcom.memcomid", "=", "memcom.memcomid")
@@ -105,9 +105,9 @@ export async function* findAll() {
105
105
  sql `to_char(memdelega.memdelegadatdeb, 'YYYY-MM-DD')`.as("date_debut"),
106
106
  sql `to_char(memdelega.memdelegadatfin, 'YYYY-MM-DD')`.as("date_fin"),
107
107
  "memdelega.temvalcod as etat",
108
- "delega.evelib as libelle",
108
+ sql `nullif(btrim(delega.evelib), '')`.as("libelle"),
109
109
  "delega.typorgcod as type_code_organisme",
110
- "typorg2.typorglib as type_organisme",
110
+ sql `nullif(btrim(typorg2.typorglib), '')`.as("type_organisme"),
111
111
  "memdelega.memdelegadatdeb as order_date",
112
112
  // Fonctions dans la délégation
113
113
  jsonArrayFrom(eb2
@@ -118,9 +118,9 @@ export async function* findAll() {
118
118
  sql `to_char(fonmemdelega.fonmemdeldatdeb, 'YYYY-MM-DD')`.as("date_debut"),
119
119
  sql `to_char(fonmemdelega.fonmemdeldatfin, 'YYYY-MM-DD')`.as("date_fin"),
120
120
  sql `coalesce(
121
- nullif(fondelega.fondellib, ''),
122
- nullif(fondelega.fondellil, ''),
123
- nullif(fondelega.fondellic, ''))`.as("libelle"),
121
+ nullif(btrim(fondelega.fondellib), ''),
122
+ nullif(btrim(fondelega.fondellil), ''),
123
+ nullif(btrim(fondelega.fondellic), ''))`.as("libelle"),
124
124
  "fonmemdelega.fonmemdeldatdeb as order_date",
125
125
  ])
126
126
  .whereRef("fonmemdelega.memdelegaid", "=", "memdelega.memdelegaid")
@@ -140,9 +140,9 @@ export async function* findAll() {
140
140
  sql `to_char(memgrppol.memgrppoldatdeb, 'YYYY-MM-DD')`.as("date_debut"),
141
141
  sql `to_char(memgrppol.memgrppoldatfin, 'YYYY-MM-DD')`.as("date_fin"),
142
142
  "memgrppol.temvalcod as etat",
143
- "grppol2.grppollibcou as libelle",
143
+ sql `nullif(btrim(grppol2.grppollibcou), '')`.as("libelle"),
144
144
  "grppol2.typorgcod as type_code_organisme",
145
- "typorg3.typorglib as type_organisme",
145
+ sql `nullif(btrim(typorg3.typorglib), '')`.as("type_organisme"),
146
146
  "memgrppol.memgrppoldatdeb as order_date",
147
147
  // Fonctions dans le groupe politique
148
148
  jsonArrayFrom(eb2
@@ -153,9 +153,9 @@ export async function* findAll() {
153
153
  sql `to_char(fonmemgrppol.fonmemgrppoldatdeb, 'YYYY-MM-DD')`.as("date_debut"),
154
154
  sql `to_char(fonmemgrppol.fonmemgrppoldatfin, 'YYYY-MM-DD')`.as("date_fin"),
155
155
  sql `coalesce(
156
- nullif(fongrppol.fongrppollib, ''),
157
- nullif(fongrppol.fongrppollil, ''),
158
- nullif(fongrppol.fongrppollic, ''))`.as("libelle"),
156
+ nullif(btrim(fongrppol.fongrppollib), ''),
157
+ nullif(btrim(fongrppol.fongrppollil), ''),
158
+ nullif(btrim(fongrppol.fongrppollic), ''))`.as("libelle"),
159
159
  "fonmemgrppol.fonmemgrppoldatdeb as order_date",
160
160
  ])
161
161
  .whereRef("fonmemgrppol.memgrppolid", "=", "memgrppol.memgrppolid")
@@ -174,9 +174,9 @@ export async function* findAll() {
174
174
  sql `to_char(memorg.memorgdatdeb, 'YYYY-MM-DD')`.as("date_debut"),
175
175
  sql `to_char(memorg.memorgdatfin, 'YYYY-MM-DD')`.as("date_fin"),
176
176
  "memorg.temvalcod as etat",
177
- "org.evelib as libelle",
177
+ sql `nullif(btrim(org.evelib), '')`.as("libelle"),
178
178
  "org.typorgcod as type_code_organisme",
179
- "typorg4.typorglib as type_organisme",
179
+ sql `nullif(btrim(typorg4.typorglib), '')`.as("type_organisme"),
180
180
  "memorg.memorgdatdeb as order_date",
181
181
  // Fonctions dans l'organisme
182
182
  jsonArrayFrom(eb2
@@ -187,9 +187,9 @@ export async function* findAll() {
187
187
  sql `to_char(fonmemorg.fonmemorgdatdeb, 'YYYY-MM-DD')`.as("date_debut"),
188
188
  sql `to_char(fonmemorg.fonmemorgdatfin, 'YYYY-MM-DD')`.as("date_fin"),
189
189
  sql `coalesce(
190
- nullif(fonorg.fonorglib, ''),
191
- nullif(fonorg.fonorglil, ''),
192
- nullif(fonorg.fonorglic, ''))`.as("libelle"),
190
+ nullif(btrim(fonorg.fonorglib), ''),
191
+ nullif(btrim(fonorg.fonorglil), ''),
192
+ nullif(btrim(fonorg.fonorglic), ''))`.as("libelle"),
193
193
  "fonmemorg.fonmemorgdatdeb as order_date",
194
194
  ])
195
195
  .whereRef("fonmemorg.memorgid", "=", "memorg.memorgid")
@@ -200,7 +200,24 @@ export async function* findAll() {
200
200
  // Groupes sénatoriaux (groupes d'amitié)
201
201
  jsonArrayFrom(eb
202
202
  .withSchema("senat")
203
- .selectFrom("sens_memgrpsen as memgrpsen")
203
+ .selectFrom(eb
204
+ .withSchema("senat")
205
+ .selectFrom("sens_memgrpsen as memgrpsen_raw")
206
+ .select([
207
+ "memgrpsen_raw.orgcod as orgcod",
208
+ "memgrpsen_raw.memgrpsendatent as memgrpsendatent",
209
+ "memgrpsen_raw.memgrpsendatsor as memgrpsendatsor",
210
+ "memgrpsen_raw.temvalcod as temvalcod",
211
+ sql `min(memgrpsen_raw.memgrpsenid)`.as("memgrpsenid"),
212
+ ])
213
+ .whereRef("memgrpsen_raw.senmat", "=", "sen.senmat")
214
+ .groupBy([
215
+ "memgrpsen_raw.orgcod",
216
+ "memgrpsen_raw.memgrpsendatent",
217
+ "memgrpsen_raw.memgrpsendatsor",
218
+ "memgrpsen_raw.temvalcod",
219
+ ])
220
+ .as("memgrpsen"))
204
221
  .leftJoin("sens_grpsenami as grpsenami", "grpsenami.orgcod", "memgrpsen.orgcod")
205
222
  .leftJoin("sens_typorg as typorg5", "typorg5.typorgcod", "grpsenami.typorgcod")
206
223
  .select((eb2) => [
@@ -208,9 +225,9 @@ export async function* findAll() {
208
225
  sql `to_char(memgrpsen.memgrpsendatent, 'YYYY-MM-DD')`.as("date_debut"),
209
226
  sql `to_char(memgrpsen.memgrpsendatsor, 'YYYY-MM-DD')`.as("date_fin"),
210
227
  "memgrpsen.temvalcod as etat",
211
- "grpsenami.evelib as libelle",
228
+ sql `nullif(btrim(grpsenami.evelib), '')`.as("libelle"),
212
229
  "grpsenami.typorgcod as type_code_organisme",
213
- "typorg5.typorglib as type_organisme",
230
+ sql `nullif(btrim(typorg5.typorglib), '')`.as("type_organisme"),
214
231
  "memgrpsen.memgrpsendatent as order_date",
215
232
  // Fonctions dans le groupe sénatorial
216
233
  jsonArrayFrom(eb2
@@ -221,15 +238,14 @@ export async function* findAll() {
221
238
  sql `to_char(fonmemgrpsen.fonmemgrpsendatdeb, 'YYYY-MM-DD')`.as("date_debut"),
222
239
  sql `to_char(fonmemgrpsen.fonmemgrpsendatfin, 'YYYY-MM-DD')`.as("date_fin"),
223
240
  sql `coalesce(
224
- nullif(fongrpsen.fongrpsenlib, ''),
225
- nullif(fongrpsen.fongrpsenlil, ''),
226
- nullif(fongrpsen.fongrpsenlic, ''))`.as("libelle"),
241
+ nullif(btrim(fongrpsen.fongrpsenlib), ''),
242
+ nullif(btrim(fongrpsen.fongrpsenlil), ''),
243
+ nullif(btrim(fongrpsen.fongrpsenlic), ''))`.as("libelle"),
227
244
  "fonmemgrpsen.fonmemgrpsendatdeb as order_date",
228
245
  ])
229
246
  .whereRef("fonmemgrpsen.memgrpsenid", "=", "memgrpsen.memgrpsenid")
230
247
  .orderBy("fonmemgrpsen.fonmemgrpsendatdeb", (ob) => ob.desc().nullsLast())).as("fonctions"),
231
248
  ])
232
- .whereRef("memgrpsen.senmat", "=", "sen.senmat")
233
249
  .orderBy("memgrpsen.memgrpsendatent", (ob) => ob.desc().nullsLast())).as("groupes_senatoriaux"),
234
250
  // Fonctions au bureau du Sénat
235
251
  jsonArrayFrom(eb
@@ -239,7 +255,11 @@ export async function* findAll() {
239
255
  .select([
240
256
  sql `to_char(senbur.senburdatdeb, 'YYYY-MM-DD')`.as("date_debut"),
241
257
  sql `to_char(senbur.senburdatfin, 'YYYY-MM-DD')`.as("date_fin"),
242
- sql `coalesce(nullif(bur.burlib, ''), nullif(bur.burlil, ''), nullif(bur.burlic, ''))`.as("libelle"),
258
+ sql `coalesce(
259
+ nullif(btrim(bur.burlib), ''),
260
+ nullif(btrim(bur.burlil), ''),
261
+ nullif(btrim(bur.burlic), '')
262
+ )`.as("libelle"),
243
263
  "senbur.senburdatdeb as order_date",
244
264
  ])
245
265
  .whereRef("senbur.senmat", "=", "sen.senmat")
@@ -251,7 +271,7 @@ export async function* findAll() {
251
271
  .select((eb2) => [
252
272
  sql `poicon.poiconid::text`.as("id"),
253
273
  "poicon.typpoiconcod as type",
254
- "poicon.poiconlib as libelle",
274
+ sql `nullif(btrim(poicon.poiconlib), '')`.as("libelle"),
255
275
  "poicon.poiconnumtri as order_num",
256
276
  // Adresses
257
277
  jsonArrayFrom(eb2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tricoteuses/senat",
3
- "version": "3.1.7",
3
+ "version": "3.1.8",
4
4
  "description": "Handle French Sénat's open data",
5
5
  "keywords": [
6
6
  "France",
@@ -1,43 +0,0 @@
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;
package/lib/src/config.js DELETED
@@ -1,37 +0,0 @@
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;
@@ -1,11 +0,0 @@
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>;
@@ -1,320 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
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>;
@@ -1,23 +0,0 @@
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
- }
@@ -1,38 +0,0 @@
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[];