@tricoteuses/senat 3.1.18 → 3.1.19

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 (65) hide show
  1. package/lib/src/config.d.ts +0 -22
  2. package/lib/src/config.js +7 -17
  3. package/lib/src/conversion_textes.js +1 -5
  4. package/lib/src/databases.d.ts +2 -0
  5. package/lib/src/databases.js +26 -0
  6. package/lib/src/datasets.d.ts +0 -4
  7. package/lib/src/datasets.js +2 -16
  8. package/lib/src/git.d.ts +0 -1
  9. package/lib/src/git.js +11 -45
  10. package/lib/src/loaders.d.ts +12 -12
  11. package/lib/src/loaders.js +8 -14
  12. package/lib/src/model/agenda.d.ts +1 -1
  13. package/lib/src/model/agenda.js +3 -3
  14. package/lib/src/model/ameli.d.ts +52 -64
  15. package/lib/src/model/ameli.js +145 -147
  16. package/lib/src/model/commission.d.ts +4 -5
  17. package/lib/src/model/commission.js +6 -6
  18. package/lib/src/model/debats.d.ts +66 -38
  19. package/lib/src/model/debats.js +93 -110
  20. package/lib/src/model/documents.d.ts +12 -32
  21. package/lib/src/model/documents.js +130 -171
  22. package/lib/src/model/dosleg.d.ts +5 -142
  23. package/lib/src/model/dosleg.js +156 -298
  24. package/lib/src/model/index.d.ts +7 -7
  25. package/lib/src/model/index.js +7 -7
  26. package/lib/src/model/questions.d.ts +45 -54
  27. package/lib/src/model/questions.js +87 -89
  28. package/lib/src/model/scrutins.d.ts +13 -48
  29. package/lib/src/model/scrutins.js +111 -118
  30. package/lib/src/model/seance.d.ts +1 -1
  31. package/lib/src/model/seance.js +7 -7
  32. package/lib/src/model/sens.d.ts +179 -109
  33. package/lib/src/model/sens.js +484 -384
  34. package/lib/src/model/util.d.ts +8 -0
  35. package/lib/src/model/util.js +23 -0
  36. package/lib/src/raw_types/ameli.d.ts +800 -1648
  37. package/lib/src/raw_types/ameli.js +5 -1074
  38. package/lib/src/raw_types/debats.d.ts +180 -353
  39. package/lib/src/raw_types/debats.js +5 -266
  40. package/lib/src/raw_types/dosleg.d.ts +1523 -2858
  41. package/lib/src/raw_types/dosleg.js +5 -2005
  42. package/lib/src/raw_types/questions.d.ts +395 -671
  43. package/lib/src/raw_types/questions.js +5 -493
  44. package/lib/src/raw_types/senat.d.ts +11372 -0
  45. package/lib/src/raw_types/senat.js +5 -0
  46. package/lib/src/raw_types/sens.d.ts +8148 -7743
  47. package/lib/src/raw_types/sens.js +5 -4691
  48. package/lib/src/raw_types_schemats/ameli.d.ts +2 -4
  49. package/lib/src/raw_types_schemats/debats.d.ts +2 -2
  50. package/lib/src/raw_types_schemats/dosleg.d.ts +2 -2
  51. package/lib/src/raw_types_schemats/questions.d.ts +2 -2
  52. package/lib/src/raw_types_schemats/sens.d.ts +4235 -29
  53. package/lib/src/scripts/test_iter_load.d.ts +1 -0
  54. package/lib/src/scripts/test_iter_load.js +12 -0
  55. package/lib/src/types/ameli.d.ts +4 -4
  56. package/lib/src/types/dosleg.d.ts +39 -39
  57. package/lib/src/types/questions.d.ts +2 -2
  58. package/lib/src/types/sens.d.ts +2 -0
  59. package/lib/src/types/texte.d.ts +2 -2
  60. package/lib/src/utils/reunion_odj_building.js +27 -11
  61. package/package.json +1 -1
  62. package/lib/src/databases_postgres.d.ts +0 -4
  63. package/lib/src/databases_postgres.js +0 -23
  64. package/lib/src/scripts/debug_dosleg_query.d.ts +0 -6
  65. package/lib/src/scripts/debug_dosleg_query.js +0 -50
@@ -1,150 +1,148 @@
1
- import { streamUnsafeQuery } from "../databases_postgres.js";
2
- function buildFindAllAmendementsQuery(fromSession) {
3
- const params = [];
4
- const whereSession = fromSession === undefined ? "" : "where ses.ann >= $1";
5
- if (fromSession !== undefined) {
6
- params.push(fromSession);
7
- }
8
- return {
9
- params,
10
- query: `
11
- select
12
- ses.ann::text as session,
13
- ses.lil as session_libelle,
14
- typses.lib as type_session,
15
- txt_ameli.doslegsignet as signet_dossier_legislatif,
16
- nat.libcourt as nature_texte,
17
- nat.lib as nature_texte_libelle,
18
- txt_ameli.numabs as numero_texte,
19
- txt_ameli.numado as numero_adoption_texte,
20
- txt_ameli.int as intitule_texte,
21
- etatxt.lic as etat_texte,
22
- etatxt.lib as etat_texte_libelle,
23
- etatxt.txttyp as type_texte,
24
- lec_ameli.lib as lecture,
25
- case amd.typ
26
- when 'A' then 'Amendement'
27
- when 'M' then 'Motion'
28
- when 'S' then 'Sous-amendement'
29
- else ''
30
- end as nature,
31
- amd.id,
32
- amd.amdperid as parent_id,
33
- amd.ideid as identique_id,
34
- amd.discomid as discussion_commune_id,
35
- amd.num as numero,
36
- amd.numabs as numero_absolu,
37
- amd.ord as ordre,
38
- amd.accgou as accepte_gouvernement,
39
- amd.txtid as texte_id,
40
- sub.lib as subdivision_libelle,
41
- sub.lic as subdivision_libelle_court,
42
- sub.pos as subdivision_position_texte,
43
- sub.posder as subdivision_position_discussion,
44
- sub.merid as subdivision_mere_id,
45
- sub.sig as subdivision_signet,
46
- sub.comdelid as subdivision_commission_id,
47
- sub.dupl as subdivision_dupliquee,
48
- typsub.lib as subdivision_type,
49
- amd.alinea,
50
- amd.obs as observations,
51
- amd.mot as observations_additionnelles,
52
- to_char(amd.datdep, 'YYYY-MM-DD') as date_depot,
53
- amd.dis as dispositif,
54
- amd.obj as objet,
55
- typrect.lib as type_rectification,
56
- mot.lib as motion_libelle,
57
- case amd.etaid
58
- when 7 then 'Diffusé'
59
- when 8 then 'Retiré avant réunion ou séance'
60
- when 9 then 'Examiné en commission ou séance'
61
- when 10 then 'Irrecevable'
62
- when 11 then 'Irrecevable'
63
- else ''
64
- end as etat,
65
- avicom.lib as avis_commission,
66
- avigvt.lib as avis_gouvernement,
67
- coalesce(sor.lib, irr.libirr) as sort,
68
- amd.rev as revision,
69
- (
70
- case
71
- when amd.num like '%COM%' then 'https://www.senat.fr/amendements/commissions/'
72
- else 'https://www.senat.fr/amendements/'
73
- end ||
74
- ses.ann::text || '-' ||
75
- (ses.ann + 1)::text || '/' ||
76
- txt_ameli.numabs || '/Amdt_' ||
77
- amd.num || '.html'
78
- ) as url,
79
- grppol_ameli.lilcou as au_nom_de_groupe_politique,
80
- rtrim(com_ameli.lil) as au_nom_de_commission,
81
- rtrim(com_ameli.cod) as code_commission,
82
- (cab.entid is not null) as auteur_est_gouvernement,
83
- (
84
- select amescr.scrnum::text
85
- from senat.dosleg_amescr as amescr
86
- left join senat.dosleg_scr as scr
87
- on amescr.scrnum = scr.scrnum
88
- and amescr.sesann = scr.sesann
89
- left join senat.dosleg_date_seance as date_seance on scr.code = date_seance.code
90
- where amescr.amescrnum = amd.num
91
- and amescr.sesann = ses.ann
92
- and date_seance.lecidt = texte.lecassidt
93
- limit 1
94
- ) as scrutin_num,
95
- (
96
- select coalesce(json_agg(author_rows order by author_rows.rang nulls last), '[]'::json)
97
- from (
98
- select
99
- amdsen.prenomuse as prenom,
100
- amdsen.hom as homonyme,
101
- amdsen.nomuse as nom,
102
- amdsen.qua as qualite,
103
- amdsen.rng::text as rang,
104
- sen_ameli.mat as matricule,
105
- amdsen.grpid as groupe_politique_id,
106
- grppol_ameli.cod as group_politique_code,
107
- grppol_ameli.libcou as groupe_politique_libelle_court,
108
- grppol_ameli.lilcou as groupe_politique_libelle
109
- from senat.ameli_amdsen as amdsen
110
- left join senat.ameli_sen_ameli as sen_ameli on amdsen.senid = sen_ameli.entid
111
- left join senat.ameli_grppol_ameli as grppol_ameli on amdsen.grpid = grppol_ameli.entid
112
- where amdsen.amdid = amd.id
113
- order by amdsen.rng asc
114
- ) as author_rows
115
- ) as auteurs
116
- from senat.ameli_amd as amd
117
- left join senat.ameli_sub as sub on amd.subid = sub.id
118
- left join senat.ameli_typsub as typsub on sub.typid = typsub.id
119
- left join senat.ameli_typrect as typrect on amd.typrectid = typrect.id
120
- left join senat.ameli_txt_ameli as txt_ameli on amd.txtid = txt_ameli.id
121
- left join senat.ameli_etatxt as etatxt on txt_ameli.txtetaid = etatxt.id
122
- left join senat.ameli_ses as ses on txt_ameli.sesdepid = ses.id
123
- left join senat.ameli_typses as typses on typses.id = ses.typid
124
- left join senat.ameli_nat as nat on txt_ameli.natid = nat.id
125
- left join senat.ameli_lec_ameli as lec_ameli on txt_ameli.lecid = lec_ameli.id
126
- left join senat.dosleg_texte as texte
127
- on ses.ann = texte.sesann
128
- and txt_ameli.numabs = texte.texnum
129
- left join senat.dosleg_lecass as lecass on texte.lecassidt = lecass.lecassidt
130
- left join senat.ameli_mot as mot on amd.motid = mot.id
131
- left join senat.ameli_avicom as avicom on amd.avcid = avicom.id
132
- left join senat.ameli_avigvt as avigvt on amd.avgid = avigvt.id
133
- left join senat.ameli_sor as sor on amd.sorid = sor.id
134
- left join senat.ameli_irr as irr on amd.irrid = irr.id
135
- left join senat.ameli_grppol_ameli as grppol_ameli on amd.nomentid = grppol_ameli.entid
136
- left join senat.ameli_com_ameli as com_ameli on amd.nomentid = com_ameli.entid
137
- left join senat.ameli_cab as cab on amd.nomentid = cab.entid
138
- ${whereSession}
139
- `,
140
- };
1
+ import { sql } from "kysely";
2
+ import { jsonArrayFrom } from "kysely/helpers/postgres";
3
+ import { dbSenat } from "../databases";
4
+ import { concat, rtrim, toDateString } from "./util";
5
+ function auteurs(amendementId) {
6
+ return jsonArrayFrom(dbSenat
7
+ .selectFrom("ameli.amdsen")
8
+ .leftJoin("ameli.sen_ameli", "ameli.amdsen.senid", "ameli.sen_ameli.entid")
9
+ .leftJoin("ameli.grppol_ameli", "ameli.amdsen.grpid", "ameli.grppol_ameli.entid")
10
+ .where("ameli.amdsen.amdid", "=", amendementId)
11
+ .select([
12
+ "ameli.amdsen.prenomuse as prenom",
13
+ "ameli.amdsen.hom as homonyme",
14
+ "ameli.amdsen.nomuse as nom",
15
+ "ameli.amdsen.qua as qualite",
16
+ "ameli.amdsen.rng as rang",
17
+ "ameli.sen_ameli.mat as matricule",
18
+ "ameli.amdsen.grpid as groupe_politique_id",
19
+ "ameli.grppol_ameli.cod as group_politique_code",
20
+ "ameli.grppol_ameli.libcou as groupe_politique_libelle_court",
21
+ "ameli.grppol_ameli.lilcou as groupe_politique_libelle",
22
+ ])
23
+ .orderBy("ameli.amdsen.rng", "asc"));
141
24
  }
142
- export async function* findAllAmendements(fromSession) {
143
- const { query, params } = buildFindAllAmendementsQuery(fromSession);
144
- for await (const row of streamUnsafeQuery(query, params)) {
145
- yield {
146
- ...row,
147
- auteurs: row.auteurs ?? [],
148
- };
25
+ function scrutin(amendementNum, sesann, lecassidt) {
26
+ return dbSenat
27
+ .selectFrom("dosleg.amescr")
28
+ .leftJoin("dosleg.scr", (join) => join
29
+ .onRef("dosleg.amescr.scrnum", "=", "dosleg.scr.scrnum")
30
+ .onRef("dosleg.amescr.sesann", "=", "dosleg.scr.sesann"))
31
+ .leftJoin("dosleg.date_seance", "dosleg.scr.code", "dosleg.date_seance.code")
32
+ .where("dosleg.amescr.amescrnum", "=", amendementNum)
33
+ .where("dosleg.amescr.sesann", "=", sesann)
34
+ .where("dosleg.date_seance.lecidt", "=", lecassidt)
35
+ .select(["dosleg.amescr.scrnum as scrutin_num"])
36
+ .limit(1)
37
+ .as("scrutin_num");
38
+ }
39
+ const findAllAmendementsQuery = dbSenat
40
+ .selectFrom("ameli.amd")
41
+ .leftJoin("ameli.sub", "ameli.amd.subid", "ameli.sub.id")
42
+ .leftJoin("ameli.typsub", "ameli.sub.typid", "ameli.typsub.id")
43
+ .leftJoin("ameli.typrect", "ameli.amd.typrectid", "ameli.typrect.id")
44
+ .leftJoin("ameli.txt_ameli", "ameli.amd.txtid", "ameli.txt_ameli.id")
45
+ .leftJoin("ameli.etatxt", "ameli.txt_ameli.txtetaid", "ameli.etatxt.id")
46
+ .leftJoin("ameli.ses", "ameli.txt_ameli.sesdepid", "ameli.ses.id")
47
+ .leftJoin("ameli.typses", "ameli.typses.id", "ameli.ses.typid")
48
+ .leftJoin("ameli.nat", "ameli.txt_ameli.natid", "ameli.nat.id")
49
+ .leftJoin("ameli.lec_ameli", "ameli.txt_ameli.lecid", "ameli.lec_ameli.id")
50
+ .leftJoin("dosleg.texte", (join) => join.onRef("ameli.ses.ann", "=", "dosleg.texte.sesann").onRef("ameli.txt_ameli.numabs", "=", "dosleg.texte.texnum"))
51
+ .leftJoin("dosleg.lecass", "dosleg.texte.lecassidt", "dosleg.lecass.lecassidt")
52
+ .leftJoin("ameli.mot", "ameli.amd.motid", "ameli.mot.id")
53
+ .leftJoin("ameli.avicom", "ameli.amd.avcid", "ameli.avicom.id")
54
+ .leftJoin("ameli.avigvt", "ameli.amd.avgid", "ameli.avigvt.id")
55
+ .leftJoin("ameli.sor", "ameli.amd.sorid", "ameli.sor.id")
56
+ .leftJoin("ameli.irr", "ameli.amd.irrid", "ameli.irr.id")
57
+ .leftJoin("ameli.grppol_ameli", "ameli.amd.nomentid", "ameli.grppol_ameli.entid")
58
+ .leftJoin("ameli.com_ameli", "ameli.amd.nomentid", "ameli.com_ameli.entid")
59
+ .leftJoin("ameli.cab", "ameli.amd.nomentid", "ameli.cab.entid")
60
+ .select(({ eb, ref, val }) => [
61
+ "ameli.ses.ann as session",
62
+ "ameli.ses.lil as session_libelle",
63
+ "ameli.typses.lib as type_session",
64
+ "ameli.txt_ameli.doslegsignet as signet_dossier_legislatif",
65
+ "ameli.nat.libcourt as nature_texte",
66
+ "ameli.nat.lib as nature_texte_libelle",
67
+ "ameli.txt_ameli.numabs as numero_texte",
68
+ "ameli.txt_ameli.numado as numero_adoption_texte",
69
+ "ameli.txt_ameli.int as intitule_texte",
70
+ "ameli.etatxt.lic as etat_texte",
71
+ "ameli.etatxt.lib as etat_texte_libelle",
72
+ "ameli.etatxt.txttyp as type_texte",
73
+ "ameli.lec_ameli.lib as lecture",
74
+ eb
75
+ .case()
76
+ .when("ameli.amd.typ", "=", "A")
77
+ .then(val("Amendement"))
78
+ .when("ameli.amd.typ", "=", "M")
79
+ .then(val("Motion"))
80
+ .when("ameli.amd.typ", "=", "S")
81
+ .then(val("Sous-amendement"))
82
+ .else("")
83
+ .end()
84
+ .as("nature"),
85
+ "ameli.amd.id as id",
86
+ "ameli.amd.amdperid as parent_id",
87
+ "ameli.amd.ideid as identique_id",
88
+ "ameli.amd.discomid as discussion_commune_id",
89
+ "ameli.amd.num as numero",
90
+ "ameli.amd.numabs as numero_absolu",
91
+ "ameli.amd.ord as ordre",
92
+ "ameli.amd.accgou as accepte_gouvernement",
93
+ "ameli.amd.txtid as texte_id",
94
+ "ameli.sub.lib as subdivision_libelle",
95
+ "ameli.sub.lic as subdivision_libelle_court",
96
+ "ameli.sub.pos as subdivision_position_texte",
97
+ "ameli.sub.posder as subdivision_position_discussion",
98
+ "ameli.sub.merid as subdivision_mere_id",
99
+ "ameli.sub.sig as subdivision_signet",
100
+ "ameli.sub.comdelid as subdivision_commission_id",
101
+ "ameli.sub.dupl as subdivision_dupliquee",
102
+ "ameli.typsub.lib as subdivision_type",
103
+ "ameli.amd.alinea as alinea",
104
+ "ameli.amd.obs as observations",
105
+ "ameli.amd.mot as observations_additionnelles",
106
+ toDateString(ref("ameli.amd.datdep")).as("date_depot"),
107
+ "ameli.amd.dis as dispositif",
108
+ "ameli.amd.obj as objet",
109
+ "ameli.typrect.lib as type_rectification",
110
+ "ameli.mot.lib as motion_libelle",
111
+ eb
112
+ .case()
113
+ .when("ameli.amd.etaid", "=", 7)
114
+ .then(val("Diffusé"))
115
+ .when("ameli.amd.etaid", "=", 8)
116
+ .then(val("Retiré avant réunion ou séance"))
117
+ .when("ameli.amd.etaid", "=", 9)
118
+ .then(val("Examiné en commission ou séance"))
119
+ .when("ameli.amd.etaid", "=", 10)
120
+ .then(val("Irrecevable"))
121
+ .when("ameli.amd.etaid", "=", 11)
122
+ .then(val("Irrecevable"))
123
+ .else("")
124
+ .end()
125
+ .as("etat"),
126
+ "ameli.avicom.lib as avis_commission",
127
+ "ameli.avigvt.lib as avis_gouvernement",
128
+ eb.fn.coalesce("ameli.sor.lib", "ameli.irr.libirr").as("sort"),
129
+ "ameli.amd.rev as revision",
130
+ concat(eb
131
+ .case()
132
+ .when("ameli.amd.num", "like", "%COM%")
133
+ .then(val("https://www.senat.fr/amendements/commissions/"))
134
+ .else(val("https://www.senat.fr/amendements/"))
135
+ .end(), ref("ameli.ses.ann"), val("-"), sql `(ameli.ses.ann + 1)`, val("/"), ref("ameli.txt_ameli.numabs"), val("/Amdt_"), ref("ameli.amd.num"), val(".html")).as("url"),
136
+ "ameli.grppol_ameli.lilcou as au_nom_de_groupe_politique",
137
+ rtrim(ref("ameli.com_ameli.lil")).as("au_nom_de_commission"),
138
+ rtrim(ref("ameli.com_ameli.cod")).as("code_commission"),
139
+ eb.case().when("ameli.cab.entid", "is not", null).then(true).else(false).end().as("auteur_est_gouvernement"),
140
+ scrutin(ref("ameli.amd.num"), ref("ameli.ses.ann"), ref("dosleg.texte.lecassidt")),
141
+ auteurs(ref("ameli.amd.id")).as("auteurs"),
142
+ ]);
143
+ export function findAllAmendements(fromSession) {
144
+ if (fromSession !== undefined) {
145
+ return findAllAmendementsQuery.where("ameli.ses.ann", ">=", fromSession).stream();
149
146
  }
147
+ return findAllAmendementsQuery.stream();
150
148
  }
@@ -1,11 +1,10 @@
1
1
  import * as cheerio from "cheerio";
2
- import type { AnyNode } from "domhandler";
3
- import { CompteRendu } from "../types/compte_rendu.js";
4
- import { Reunion } from "../types/agenda.js";
5
- export declare function getRemainingTextAfterSpeakerHeader($: cheerio.CheerioAPI, $p: cheerio.Cheerio<AnyNode>): string;
2
+ import { CompteRendu } from "../types/compte_rendu";
3
+ import { Reunion } from "../types/agenda";
4
+ export declare function getRemainingTextAfterSpeakerHeader($: cheerio.CheerioAPI, $p: cheerio.Cheerio<any>): string;
6
5
  export type DaySection = {
7
6
  title: string;
8
- $start: cheerio.Cheerio<AnyNode>;
7
+ $start: cheerio.Cheerio<any>;
9
8
  time?: string;
10
9
  };
11
10
  export declare function cleanTitle(t: string): string;
@@ -1,9 +1,9 @@
1
1
  import * as cheerio from "cheerio";
2
2
  import path from "path";
3
- import { makeReunionUid } from "../utils/reunion_parsing.js";
4
- import { norm } from "../utils/string_cleaning.js";
5
- import { frDateToISO, hourShortToStartTime } from "../utils/date.js";
6
- import { toCRDate } from "./util.js";
3
+ import { makeReunionUid } from "../utils/reunion_parsing";
4
+ import { norm } from "../utils/string_cleaning";
5
+ import { frDateToISO, hourShortToStartTime } from "../utils/date";
6
+ import { toCRDate } from "./util";
7
7
  const PARA_h3_SEL = "p.sh_justify, p.sh_center, p.sh_marge, p[align], li, h3";
8
8
  function findDayRoot($, targetISO) {
9
9
  let $root = $();
@@ -39,7 +39,7 @@ function collectLeadingHeaderStrongEls($, $clone) {
39
39
  }
40
40
  if ($n.is("a") && $n.children("strong, b").length) {
41
41
  $n.children("strong, b").each((_, el) => {
42
- els.push(el);
42
+ els.push($(el));
43
43
  });
44
44
  continue;
45
45
  }
@@ -68,7 +68,7 @@ function buildPointsFromParagraphs($, paras) {
68
68
  const normSpeaker = (s) => s
69
69
  .normalize("NFKC")
70
70
  .replace(/\s+/g, " ")
71
- .replace(/[.:]\s*$/, "")
71
+ .replace(/[:\.]\s*$/, "")
72
72
  .trim();
73
73
  const normQual = (s) => s
74
74
  .normalize("NFKC")
@@ -1,39 +1,67 @@
1
- export interface DebatAuteurRow {
2
- code: string | null;
3
- matricule: string | null;
4
- nom: string | null;
5
- prenom: string | null;
6
- }
7
- export interface DebatInterventionRow {
8
- analyse: string | null;
9
- auteur: DebatAuteurRow | null;
10
- auteur_code: string;
11
- fonction_intervenant: string | null;
12
- id: string | null;
13
- url: string | null;
14
- }
15
- export interface DebatSectionRow {
16
- categorie: string | null;
17
- id?: string | null;
18
- interventions: DebatInterventionRow[];
19
- lecture_id?: string | null;
20
- libelle?: string | null;
21
- numero?: string | null;
22
- objet: string | null;
23
- type: string | null;
24
- url?: string | null;
25
- }
26
- export interface DebatLectureRow {
1
+ import { InferResult } from "kysely";
2
+ export type DebatResult = InferResult<typeof findAllQuery>[0];
3
+ declare const findAllQuery: import("kysely").SelectQueryBuilder<any, "debats.debats", {
4
+ [x: string]: any;
27
5
  id: string;
28
- }
29
- export interface DebatResult {
30
- date_seance: string | null;
31
- etat_synchronisation: string | null;
32
- id: string | null;
33
- lectures: DebatLectureRow[];
34
- numero: string | null;
35
- sections: DebatSectionRow[];
36
- sections_divers: DebatSectionRow[];
37
- url: string | null;
38
- }
39
- export declare function findAll(): AsyncGenerator<DebatResult, void, unknown>;
6
+ date_seance: string;
7
+ sections: {
8
+ [x: string]: any;
9
+ interventions: {
10
+ [x: string]: any;
11
+ auteur: {
12
+ code: any;
13
+ nom: any;
14
+ prenom: any;
15
+ matricule: any;
16
+ };
17
+ }[];
18
+ }[];
19
+ sections_divers: {
20
+ [x: string]: any;
21
+ interventions: {
22
+ [x: string]: any;
23
+ auteur: {
24
+ code: any;
25
+ nom: any;
26
+ prenom: any;
27
+ matricule: any;
28
+ };
29
+ }[];
30
+ }[];
31
+ lectures: {
32
+ id: any;
33
+ }[];
34
+ }>;
35
+ export declare function findAll(fromSession?: number): AsyncIterableIterator<{
36
+ [x: string]: any;
37
+ id: string;
38
+ date_seance: string;
39
+ sections: {
40
+ [x: string]: any;
41
+ interventions: {
42
+ [x: string]: any;
43
+ auteur: {
44
+ code: any;
45
+ nom: any;
46
+ prenom: any;
47
+ matricule: any;
48
+ };
49
+ }[];
50
+ }[];
51
+ sections_divers: {
52
+ [x: string]: any;
53
+ interventions: {
54
+ [x: string]: any;
55
+ auteur: {
56
+ code: any;
57
+ nom: any;
58
+ prenom: any;
59
+ matricule: any;
60
+ };
61
+ }[];
62
+ }[];
63
+ lectures: {
64
+ id: any;
65
+ }[];
66
+ }>;
67
+ export {};
@@ -1,112 +1,95 @@
1
- import { streamUnsafeQuery } from "../databases_postgres.js";
2
- function buildFindAllDebatsQuery() {
3
- return {
4
- params: [],
5
- query: `
6
- select
7
- to_char(debats.datsea, 'YYYYMMDD') as id,
8
- to_char(debats.datsea, 'YYYY-MM-DD') as date_seance,
9
- debats.numero::text as numero,
10
- debats.deburl as url,
11
- debats.debsyn as etat_synchronisation,
12
- (
13
- select coalesce(json_agg(section_rows order by section_rows.section_order nulls last), '[]'::json)
14
- from (
15
- select
16
- secdis.secdisordid::text as id,
17
- secdis.secdisnum as numero,
18
- secdis.secdisobj as objet,
19
- secdis.secdisurl as url,
20
- typsec.typseclib as type,
21
- typsec.typseccat as categorie,
22
- secdis.lecassidt as lecture_id,
23
- secdis.secdisordid as section_order,
24
- (
25
- select coalesce(
26
- json_agg(intervention_rows order by intervention_rows.intervention_order nulls last),
27
- '[]'::json
28
- )
29
- from (
30
- select
31
- intpjl.intordid::text as id,
32
- intpjl.autcod as auteur_code,
33
- intpjl.intfon as fonction_intervenant,
34
- intpjl.inturl as url,
35
- intpjl.intana as analyse,
36
- json_build_object(
37
- 'code', auteur.autcod,
38
- 'nom', auteur.nomuse,
39
- 'prenom', auteur.prenom,
40
- 'matricule', auteur.autmat
41
- ) as auteur,
42
- intpjl.intordid as intervention_order
43
- from senat.debats_intpjl as intpjl
44
- left join senat.dosleg_auteur as auteur on intpjl.autcod = auteur.autcod
45
- where intpjl.secdiscle = secdis.secdiscle
46
- ) as intervention_rows
47
- ) as interventions
48
- from senat.debats_secdis as secdis
49
- left join senat.debats_typsec as typsec on secdis.typseccod = typsec.typseccod
50
- where secdis.datsea = debats.datsea
51
- ) as section_rows
52
- ) as sections,
53
- (
54
- select coalesce(json_agg(section_rows), '[]'::json)
55
- from (
56
- select
57
- secdivers.secdiverslibelle as libelle,
58
- secdivers.secdiversobj as objet,
59
- typsec.typseclib as type,
60
- typsec.typseccat as categorie,
61
- (
62
- select coalesce(
63
- json_agg(intervention_rows order by intervention_rows.intervention_order nulls last),
64
- '[]'::json
65
- )
66
- from (
67
- select
68
- intdivers.intdiversordid::text as id,
69
- intdivers.autcod as auteur_code,
70
- intdivers.intfon as fonction_intervenant,
71
- intdivers.inturl as url,
72
- intdivers.intana as analyse,
73
- json_build_object(
74
- 'code', auteur.autcod,
75
- 'nom', auteur.nomuse,
76
- 'prenom', auteur.prenom,
77
- 'matricule', auteur.autmat
78
- ) as auteur,
79
- intdivers.intdiversordid as intervention_order
80
- from senat.debats_intdivers as intdivers
81
- left join senat.dosleg_auteur as auteur on intdivers.autcod = auteur.autcod
82
- where intdivers.secdiverscle = secdivers.secdiverscle
83
- ) as intervention_rows
84
- ) as interventions
85
- from senat.debats_secdivers as secdivers
86
- left join senat.debats_typsec as typsec on secdivers.typseccod = typsec.typseccod
87
- where secdivers.datsea = debats.datsea
88
- ) as section_rows
89
- ) as sections_divers,
90
- (
91
- select coalesce(json_agg(lecture_rows), '[]'::json)
92
- from (
93
- select lecassdeb.lecassidt as id
94
- from senat.debats_lecassdeb as lecassdeb
95
- where lecassdeb.datsea = debats.datsea
96
- ) as lecture_rows
97
- ) as lectures
98
- from senat.debats_debats as debats
99
- `,
100
- };
1
+ import { jsonArrayFrom, jsonBuildObject } from "kysely/helpers/postgres";
2
+ import { dbSenat } from "../databases";
3
+ import { ID_DATE_FORMAT } from "../scripts/datautil";
4
+ import { toDateString } from "./util";
5
+ function sectionsLegislatives(dateSeance) {
6
+ return jsonArrayFrom(dbSenat
7
+ .selectFrom("debats.secdis")
8
+ .leftJoin("debats.typsec", "debats.secdis.typseccod", "debats.typsec.typseccod")
9
+ .where("debats.secdis.datsea", "=", dateSeance)
10
+ .select(({ ref }) => [
11
+ "debats.secdis.secdisordid as id",
12
+ "debats.secdis.secdisnum as numero",
13
+ "debats.secdis.secdisobj as objet",
14
+ "debats.secdis.secdisurl as url",
15
+ "debats.typsec.typseclib as type",
16
+ "debats.typsec.typseccat as categorie",
17
+ interventionsLegislatives(ref("debats.secdis.secdiscle")).as("interventions"),
18
+ "debats.secdis.lecassidt as lecture_id",
19
+ ])
20
+ .orderBy("debats.secdis.secdisordid", "asc"));
101
21
  }
102
- export async function* findAll() {
103
- const { query, params } = buildFindAllDebatsQuery();
104
- for await (const row of streamUnsafeQuery(query, params)) {
105
- yield {
106
- ...row,
107
- lectures: row.lectures ?? [],
108
- sections: row.sections ?? [],
109
- sections_divers: row.sections_divers ?? [],
110
- };
111
- }
22
+ function interventionsLegislatives(sectionId) {
23
+ return jsonArrayFrom(dbSenat
24
+ .selectFrom("debats.intpjl")
25
+ .leftJoin("dosleg.auteur", "debats.intpjl.autcod", "dosleg.auteur.autcod")
26
+ .where("debats.intpjl.secdiscle", "=", sectionId)
27
+ .select(({ ref, val, fn }) => [
28
+ "debats.intpjl.intordid as id",
29
+ "debats.intpjl.autcod as auteur_code",
30
+ "debats.intpjl.intfon as fonction_intervenant",
31
+ "debats.intpjl.inturl as url",
32
+ "debats.intpjl.intana as analyse",
33
+ jsonBuildObject({
34
+ code: ref("dosleg.auteur.autcod"),
35
+ nom: ref("dosleg.auteur.nomuse"),
36
+ prenom: ref("dosleg.auteur.prenom"),
37
+ matricule: ref("dosleg.auteur.autmat"),
38
+ }).as("auteur"),
39
+ ])
40
+ .orderBy("debats.intpjl.intordid", "asc"));
41
+ }
42
+ function sectionsNonLegislatives(dateSeance) {
43
+ return jsonArrayFrom(dbSenat
44
+ .selectFrom("debats.secdivers")
45
+ .leftJoin("debats.typsec", "debats.secdivers.typseccod", "debats.typsec.typseccod")
46
+ .where("debats.secdivers.datsea", "=", dateSeance)
47
+ .select(({ ref }) => [
48
+ "debats.secdivers.secdiverslibelle as libelle",
49
+ "debats.secdivers.secdiversobj as objet",
50
+ "debats.typsec.typseclib as type",
51
+ "debats.typsec.typseccat as categorie",
52
+ interventionsNonLegislatives(ref("debats.secdivers.secdiverscle")).as("interventions"),
53
+ ]));
54
+ }
55
+ function interventionsNonLegislatives(sectionId) {
56
+ return jsonArrayFrom(dbSenat
57
+ .selectFrom("debats.intdivers")
58
+ .leftJoin("dosleg.auteur", "debats.intdivers.autcod", "dosleg.auteur.autcod")
59
+ .where("debats.intdivers.intdiverscle", "=", sectionId)
60
+ .select(({ ref, val }) => [
61
+ "debats.intdivers.intdiversordid as id",
62
+ "debats.intdivers.autcod as auteur_code",
63
+ "debats.intdivers.intfon as fonction_intervenant",
64
+ "debats.intdivers.inturl as url",
65
+ "debats.intdivers.intana as analyse",
66
+ jsonBuildObject({
67
+ code: ref("dosleg.auteur.autcod"),
68
+ nom: ref("dosleg.auteur.nomuse"),
69
+ prenom: ref("dosleg.auteur.prenom"),
70
+ matricule: ref("dosleg.auteur.autmat"),
71
+ }).as("auteur"),
72
+ ])
73
+ .orderBy("debats.intdivers.intdiversordid", "asc"));
74
+ }
75
+ function lecturesAssemblee(dateSeance) {
76
+ return jsonArrayFrom(dbSenat
77
+ .selectFrom("debats.lecassdeb")
78
+ .where("debats.lecassdeb.datsea", "=", dateSeance)
79
+ .select("debats.lecassdeb.lecassidt as id"));
80
+ }
81
+ const findAllQuery = dbSenat
82
+ .selectFrom("debats.debats")
83
+ .select(({ ref, val }) => [
84
+ toDateString(ref("debats.debats.datsea"), val(ID_DATE_FORMAT)).as("id"),
85
+ toDateString(ref("debats.debats.datsea")).as("date_seance"),
86
+ "debats.debats.numero as numero",
87
+ "debats.debats.deburl as url",
88
+ "debats.debats.debsyn as etat_synchronisation",
89
+ sectionsLegislatives(ref("debats.debats.datsea")).as("sections"),
90
+ sectionsNonLegislatives(ref("debats.debats.datsea")).as("sections_divers"),
91
+ lecturesAssemblee(ref("debats.debats.datsea")).as("lectures"),
92
+ ]);
93
+ export function findAll(fromSession) {
94
+ return findAllQuery.stream();
112
95
  }