@tricoteuses/senat 3.1.19 → 3.1.21

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 (108) hide show
  1. package/LICENSE.md +32 -32
  2. package/README.md +326 -326
  3. package/lib/src/other_types/collaborateurs.d.ts +5 -0
  4. package/lib/src/other_types/manifest.d.ts +11 -0
  5. package/lib/src/parsers/collaborateurs.d.ts +44 -0
  6. package/lib/src/parsers/collaborateurs.js +157 -0
  7. package/lib/src/scripts/retrieve_agenda.js +38 -4
  8. package/lib/src/scripts/retrieve_collaborateurs.js +166 -0
  9. package/lib/src/scripts/retrieve_videos.js +5 -1
  10. package/lib/src/scripts/shared/incremental_import_sql.js +859 -859
  11. package/lib/src/scripts/shared/schema_version.js +84 -84
  12. package/lib/src/scripts/shared/staging_metadata_sql.js +214 -214
  13. package/lib/src/scripts/validate_prefixed_tables.js +12 -12
  14. package/lib/src/server/ameli.js +11 -11
  15. package/lib/src/server/conversion_textes.js +106 -106
  16. package/lib/src/server/debats.js +10 -10
  17. package/lib/src/server/documents.js +22 -22
  18. package/lib/src/server/dosleg.js +33 -33
  19. package/lib/src/server/questions.js +10 -10
  20. package/lib/src/server/scrutins.js +3 -3
  21. package/lib/src/server/sens.js +19 -19
  22. package/lib/src/utils/manifest.d.ts +6 -0
  23. package/lib/src/utils/manifest.js +37 -0
  24. package/lib/src/utils/reunion_deletion.d.ts +2 -0
  25. package/lib/src/utils/reunion_deletion.js +27 -0
  26. package/lib/src/videos/match.js +4 -4
  27. package/lib/tests/collaborateurs.test.js +115 -0
  28. package/package.json +117 -117
  29. package/lib/src/config.d.ts +0 -21
  30. package/lib/src/config.js +0 -27
  31. package/lib/src/conversion_textes.d.ts +0 -11
  32. package/lib/src/conversion_textes.js +0 -316
  33. package/lib/src/databases.d.ts +0 -2
  34. package/lib/src/databases.js +0 -26
  35. package/lib/src/datasets.d.ts +0 -34
  36. package/lib/src/datasets.js +0 -233
  37. package/lib/src/git.d.ts +0 -26
  38. package/lib/src/git.js +0 -217
  39. package/lib/src/loaders.d.ts +0 -52
  40. package/lib/src/loaders.js +0 -254
  41. package/lib/src/model/agenda.d.ts +0 -6
  42. package/lib/src/model/agenda.js +0 -148
  43. package/lib/src/model/ameli.d.ts +0 -55
  44. package/lib/src/model/ameli.js +0 -148
  45. package/lib/src/model/commission.d.ts +0 -18
  46. package/lib/src/model/commission.js +0 -269
  47. package/lib/src/model/debats.d.ts +0 -67
  48. package/lib/src/model/debats.js +0 -95
  49. package/lib/src/model/documents.d.ts +0 -12
  50. package/lib/src/model/documents.js +0 -141
  51. package/lib/src/model/dosleg.d.ts +0 -7
  52. package/lib/src/model/dosleg.js +0 -326
  53. package/lib/src/model/index.d.ts +0 -7
  54. package/lib/src/model/index.js +0 -7
  55. package/lib/src/model/questions.d.ts +0 -45
  56. package/lib/src/model/questions.js +0 -89
  57. package/lib/src/model/scrutins.d.ts +0 -13
  58. package/lib/src/model/scrutins.js +0 -114
  59. package/lib/src/model/seance.d.ts +0 -3
  60. package/lib/src/model/seance.js +0 -267
  61. package/lib/src/model/sens.d.ts +0 -182
  62. package/lib/src/model/sens.js +0 -485
  63. package/lib/src/model/util.d.ts +0 -9
  64. package/lib/src/model/util.js +0 -38
  65. package/lib/src/raw_types/ameli.d.ts +0 -914
  66. package/lib/src/raw_types/ameli.js +0 -5
  67. package/lib/src/raw_types/debats.d.ts +0 -207
  68. package/lib/src/raw_types/debats.js +0 -5
  69. package/lib/src/raw_types/dosleg.d.ts +0 -1619
  70. package/lib/src/raw_types/dosleg.js +0 -5
  71. package/lib/src/raw_types/questions.d.ts +0 -423
  72. package/lib/src/raw_types/questions.js +0 -5
  73. package/lib/src/raw_types/senat.d.ts +0 -11372
  74. package/lib/src/raw_types/senat.js +0 -5
  75. package/lib/src/raw_types/sens.d.ts +0 -8248
  76. package/lib/src/raw_types/sens.js +0 -5
  77. package/lib/src/raw_types_schemats/ameli.d.ts +0 -539
  78. package/lib/src/raw_types_schemats/ameli.js +0 -2
  79. package/lib/src/raw_types_schemats/debats.d.ts +0 -127
  80. package/lib/src/raw_types_schemats/debats.js +0 -2
  81. package/lib/src/raw_types_schemats/dosleg.d.ts +0 -977
  82. package/lib/src/raw_types_schemats/dosleg.js +0 -2
  83. package/lib/src/raw_types_schemats/questions.d.ts +0 -237
  84. package/lib/src/raw_types_schemats/questions.js +0 -2
  85. package/lib/src/raw_types_schemats/sens.d.ts +0 -6915
  86. package/lib/src/raw_types_schemats/sens.js +0 -2
  87. package/lib/src/scripts/test_iter_load.js +0 -12
  88. package/lib/src/types/agenda.d.ts +0 -45
  89. package/lib/src/types/ameli.d.ts +0 -5
  90. package/lib/src/types/compte_rendu.d.ts +0 -83
  91. package/lib/src/types/debats.d.ts +0 -2
  92. package/lib/src/types/debats.js +0 -1
  93. package/lib/src/types/dosleg.d.ts +0 -70
  94. package/lib/src/types/dosleg.js +0 -1
  95. package/lib/src/types/questions.d.ts +0 -2
  96. package/lib/src/types/questions.js +0 -1
  97. package/lib/src/types/sens.d.ts +0 -10
  98. package/lib/src/types/sens.js +0 -1
  99. package/lib/src/types/sessions.d.ts +0 -6
  100. package/lib/src/types/sessions.js +0 -19
  101. package/lib/src/types/texte.d.ts +0 -72
  102. package/lib/src/types/texte.js +0 -15
  103. package/lib/src/validators/config.d.ts +0 -9
  104. package/lib/src/validators/config.js +0 -10
  105. /package/lib/src/{scripts/test_iter_load.d.ts → other_types/collaborateurs.js} +0 -0
  106. /package/lib/src/{types/agenda.js → other_types/manifest.js} +0 -0
  107. /package/lib/src/{types/ameli.js → scripts/retrieve_collaborateurs.d.ts} +0 -0
  108. /package/lib/{src/types/compte_rendu.js → tests/collaborateurs.test.d.ts} +0 -0
@@ -1,141 +0,0 @@
1
- import { sql } from "kysely";
2
- import { dbSenat } from "../databases";
3
- import { concat, rtrim, toDateString } from "./util";
4
- import { jsonArrayFrom } from "kysely/helpers/postgres";
5
- function stripTrailingHashes(expr) {
6
- return sql `regexp_replace(${expr}, '#+$', '')`;
7
- }
8
- function orderOrdreOrigineTexte(expr) {
9
- return sql `array_position(array['0','2','1'], ${expr})`;
10
- }
11
- function auteursRapport(rapportId) {
12
- return jsonArrayFrom(dbSenat
13
- .withSchema("dosleg")
14
- .selectFrom("dosleg.auteur")
15
- .leftJoin("dosleg.ecr", "dosleg.ecr.autcod", "dosleg.auteur.autcod")
16
- .leftJoin("dosleg.rolsig", "dosleg.rolsig.signataire", "dosleg.ecr.signataire")
17
- .where("dosleg.ecr.rapcod", "=", rapportId)
18
- .select([
19
- "dosleg.auteur.prenom as prenom",
20
- "dosleg.auteur.nomuse as nom_usuel",
21
- "dosleg.auteur.autmat as matricule",
22
- "dosleg.ecr.ecrnumtri as ordre",
23
- "dosleg.rolsig.rolsiglib as role",
24
- "dosleg.ecr.ecrqua as qualite",
25
- ])
26
- .orderBy("dosleg.ecr.ecrnumtri", "asc"));
27
- }
28
- function documentsAttaches(rapportId) {
29
- return jsonArrayFrom(dbSenat
30
- .withSchema("dosleg")
31
- .selectFrom("docatt")
32
- .leftJoin("typatt", "docatt.typattcod", "typatt.typattcod")
33
- .where("docatt.rapcod", "=", rapportId)
34
- .select(["docatt.docatturl as url", "typatt.typattlib as type_document"]));
35
- }
36
- function selectRapportAttributes({ eb, ref, val }) {
37
- return [
38
- "rap.rapnum as numero",
39
- "raporg.orgcod as code_organisme",
40
- eb
41
- .case()
42
- .when("rap.rapurl", "is not", null)
43
- .then(stripTrailingHashes(sql `regexp_replace(trim(${ref("rap.rapurl")}), '^(.*/)?(.*?)(\\.html)?$', '\\2')`))
44
- .else(null)
45
- .end()
46
- .as("id"),
47
- eb
48
- .case()
49
- .when("rap.typurl", "=", "I")
50
- .then(stripTrailingHashes(concat(val("https://www.senat.fr/rap/"), rtrim(ref("rap.rapurl")))))
51
- .else(stripTrailingHashes(rtrim(ref("rap.rapurl"))))
52
- .end()
53
- .as("url"),
54
- rtrim(ref("denrap.libdenrap")).as("type"),
55
- rtrim(rtrim(ref("rap.raptil"))).as("titre"),
56
- rtrim(rtrim(ref("rap.rapsoustit"))).as("sous_titre"),
57
- toDateString(ref("rap.date_depot")).as("date"),
58
- "rap.sesann as session",
59
- auteursRapport(ref("rap.rapcod")).as("auteurs"),
60
- documentsAttaches(ref("rap.rapcod")).as("documents_annexes"),
61
- ];
62
- }
63
- const baseQueryRapports = dbSenat
64
- .withSchema("dosleg")
65
- .selectFrom("rap")
66
- .leftJoin("raporg", "raporg.rapcod", "rap.rapcod")
67
- .leftJoin("denrap", "denrap.coddenrap", "rap.coddenrap")
68
- .leftJoin("lecassrap", "lecassrap.rapcod", "rap.rapcod");
69
- const queryRapports = baseQueryRapports
70
- .leftJoin("lecass", "lecass.lecassidt", "lecassrap.lecassidt")
71
- .leftJoin("lecture", "lecture.lecidt", "lecass.lecidt")
72
- .leftJoin("loi", "loi.loicod", "lecture.loicod")
73
- .select((args) => ["loi.signet as signet_dossier", ...selectRapportAttributes(args)]);
74
- export function rapports(lectureAssembleeId) {
75
- return jsonArrayFrom(baseQueryRapports.select(selectRapportAttributes).where("lecassrap.lecassidt", "=", lectureAssembleeId));
76
- }
77
- function auteursTexte(texteId) {
78
- return jsonArrayFrom(dbSenat
79
- .withSchema("dosleg")
80
- .selectFrom("auteur")
81
- .leftJoin("ecr", "ecr.autcod", "auteur.autcod")
82
- .leftJoin("rolsig", "rolsig.signataire", "ecr.signataire")
83
- .where("ecr.texcod", "=", texteId)
84
- .select([
85
- "auteur.prenom as prenom",
86
- "auteur.nomuse as nom_usuel",
87
- "auteur.autmat as matricule",
88
- "ecr.ecrnumtri as ordre",
89
- "rolsig.rolsiglib as role",
90
- "ecr.ecrqua as qualite",
91
- ])
92
- .orderBy("ecr.ecrnumtri", "asc"));
93
- }
94
- function selectTexteAttributes({ eb, ref, val }) {
95
- return [
96
- "texte.texnum as numero",
97
- "texte.orgcod as code_organisme",
98
- eb
99
- .case()
100
- .when("texte.texurl", "is not", null)
101
- .then(stripTrailingHashes(sql `regexp_replace(trim(${ref("texte.texurl")}), '^(.*/)?(.*?)(\\.html)?$', '\\2')`))
102
- .else(null)
103
- .end()
104
- .as("id"),
105
- eb
106
- .case()
107
- .when("texte.typurl", "=", "I")
108
- .then(stripTrailingHashes(concat(val("https://www.senat.fr/leg/"), rtrim(ref("texte.texurl")))))
109
- .else(stripTrailingHashes(rtrim(ref("texte.texurl"))))
110
- .end()
111
- .as("url"),
112
- rtrim(ref("oritxt.oritxtlib")).as("origine"),
113
- "oritxt.oriordre as ordre_origine",
114
- "oritxt.oritxtado as code_adoption",
115
- "oritxt.oritxtmod as modification",
116
- rtrim(ref("typtxt.typtxtlib")).as("type"),
117
- toDateString(ref("texte.txtoritxtdat")).as("date"),
118
- "texte.sesann as session",
119
- auteursTexte(ref("texte.texcod")).as("auteurs"),
120
- ];
121
- }
122
- const baseQueryTextes = dbSenat
123
- .withSchema("dosleg")
124
- .selectFrom("texte")
125
- .leftJoin("oritxt", "oritxt.oritxtcod", "texte.oritxtcod")
126
- .leftJoin("typtxt", "typtxt.typtxtcod", "texte.typtxtcod")
127
- .orderBy(({ ref }) => orderOrdreOrigineTexte(ref("oritxt.oriordre")));
128
- const queryTextes = baseQueryTextes
129
- .leftJoin("lecass", "lecass.lecassidt", "texte.lecassidt")
130
- .leftJoin("lecture", "lecture.lecidt", "lecass.lecidt")
131
- .leftJoin("loi", "loi.loicod", "lecture.loicod")
132
- .select((args) => ["loi.signet as signet_dossier", ...selectTexteAttributes(args)]);
133
- export function textes(lectureAssembleeId) {
134
- return jsonArrayFrom(baseQueryTextes.select(selectTexteAttributes).where("texte.lecassidt", "=", lectureAssembleeId));
135
- }
136
- export function findAllTextes() {
137
- return queryTextes.stream();
138
- }
139
- export function findAllRapports() {
140
- return queryRapports.stream();
141
- }
@@ -1,7 +0,0 @@
1
- import { InferResult, SelectQueryBuilder } from "kysely";
2
- declare const findAllDossiersQuery: SelectQueryBuilder<any, any, any>;
3
- export declare function findAllDossiers(): AsyncIterableIterator<DossierLegislatifResult>;
4
- export declare function getCodeActeLecture(codeNatureDossier: string, typeLecture: string, assemblee: string): string | null;
5
- export type DossierLegislatifResult = InferResult<typeof findAllDossiersQuery>[0];
6
- export declare function buildActesLegislatifs(dossier: any): any[];
7
- export {};
@@ -1,326 +0,0 @@
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
- import { textes, rapports } from "./documents";
6
- function datesSeances(lectureAssembleeId) {
7
- return jsonArrayFrom(dbSenat
8
- .withSchema("dosleg")
9
- .selectFrom("dosleg.date_seance")
10
- .where("dosleg.date_seance.lecidt", "=", lectureAssembleeId)
11
- .select(({ ref }) => [toDateString(ref("dosleg.date_seance.date_s")).as("date")]));
12
- }
13
- function lecturesAssemblee(lectureId) {
14
- return jsonArrayFrom(dbSenat
15
- .withSchema("dosleg")
16
- .selectFrom("lecass")
17
- .where("lecass.lecidt", "=", lectureId)
18
- .leftJoin("ass", "ass.codass", "lecass.codass")
19
- .leftJoin("org", "org.orgcod", "lecass.orgcod")
20
- .leftJoin("orippr", "orippr.oripprcod", "lecass.orippr")
21
- .select(({ ref }) => [
22
- rtrim(ref("ass.libass")).as("assemblee"),
23
- "org.orgnom as libelle_organisme",
24
- "org.senorgcod as code_organisme",
25
- "lecass.ordreass as ordre_lecture_assemblee",
26
- "lecass.sesann as session",
27
- "orippr.oripprlib as origine_proposition",
28
- "lecass.ptlnum as numero_petite_loi",
29
- "lecass.ptlurl as url_petite_loi",
30
- "lecass.loiintmod as loi_intitule_modifie",
31
- "lecass.debatsurl as url_cr_debats",
32
- toDateString(ref("lecass.lecassamecomdat")).as("date_publication_amendements_commission"),
33
- toDateString(ref("lecass.lecassamedat")).as("date_publication_amendements_seance"),
34
- textes(ref("lecass.lecassidt")).as("textes"),
35
- rapports(ref("lecass.lecassidt")).as("rapports"),
36
- datesSeances(ref("lecass.lecassidt")).as("dates_seances"),
37
- ])
38
- .orderBy("lecass.ordreass", "asc"));
39
- }
40
- function lectures(loiId) {
41
- return jsonArrayFrom(dbSenat
42
- .withSchema("dosleg")
43
- .selectFrom("lecture")
44
- .leftJoin("typlec", "typlec.typleccod", "lecture.typleccod")
45
- .where("lecture.loicod", "=", loiId)
46
- .select(({ ref }) => [
47
- rtrim(ref("typlec.typleclib")).as("type_lecture"),
48
- rtrim(ref("lecture.leccom")).as("libelle"),
49
- "typlec.typlecord as ordre_lecture",
50
- lecturesAssemblee(ref("lecture.lecidt")).as("lectures_assemblee"),
51
- ])
52
- .orderBy("typlec.typlecord", "asc"));
53
- }
54
- function themes(loiId) {
55
- return jsonArrayFrom(dbSenat
56
- .withSchema("dosleg")
57
- .selectFrom("the")
58
- .leftJoin("loithe", "loithe.thecle", "the.thecle")
59
- .where("loithe.loicod", "=", loiId)
60
- .select(["the.thelib as libelle"]));
61
- }
62
- const findAllDossiersQuery = dbSenat
63
- .withSchema("dosleg")
64
- .selectFrom("loi")
65
- .leftJoin("typloi", "typloi.typloicod", "loi.typloicod")
66
- .leftJoin("etaloi", "etaloi.etaloicod", "loi.etaloicod")
67
- .leftJoin("deccoc", "deccoc.deccoccod", "loi.deccoccod")
68
- .select(({ eb, ref, val }) => [
69
- rtrim(ref("loi.loicod")).as("code"),
70
- "loi.numero as numero",
71
- "loi.signet as signet",
72
- sql `NULLIF(regexp_replace(loi.url_an, '^.*\\/(DL[^\\/]+)\\.asp$', '\\1'), '')`.as("code_dossier_an"),
73
- "loi.signetalt as signet_alternatif",
74
- rtrim(ref("loi.motclef")).as("mot_cle"),
75
- rtrim(ref("loi.loient")).as("titre_court"),
76
- concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loitit"))).as("titre"),
77
- concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loiint"))).as("titre_long"),
78
- concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loiintori"))).as("titre_long_original"),
79
- concat(val("https://www.senat.fr/dossier-legislatif/"), ref("loi.signet"), val(".html")).as("url"),
80
- "loi.urgence as urgence",
81
- rtrim(ref("typloi.groupe")).as("code_nature_dossier"),
82
- rtrim(ref("typloi.typloilib")).as("libelle_type_dossier"),
83
- rtrim(ref("etaloi.etaloilib")).as("etat_dossier"),
84
- "loi.url_an as url_dossier_assemblee_nationale",
85
- "loi.url_presart as url_presentation_articles",
86
- "loi.url_ordonnance as url_ordonnance",
87
- "loi.orgcod as code_organisme_resolution",
88
- "deccoc.deccoclib as libelle_decision_CoC",
89
- toDateString(ref("loi.date_decision")).as("date_decision_CoC"),
90
- "loi.num_decision as num_decision_CoC",
91
- "loi.deccocurl as url_decision_CoC",
92
- "loi.doscocurl as url_dossier_CoC",
93
- toDateString(ref("loi.saisine_date")).as("date_saisine_CoC"),
94
- "loi.saisine_par as condition_saisine_CoC",
95
- toDateString(ref("loi.proaccdat")).as("date_procedure_acceleree"),
96
- toDateString(ref("loi.proaccoppdat")).as("date_opposition_procedure_acceleree"),
97
- toDateString(ref("loi.retproaccdat")).as("date_retrait_procedure_acceleree"),
98
- toDateString(ref("loi.date_loi")).as("date_promulgation"),
99
- eb
100
- .case()
101
- .when("loi.loititjo", "is not", null)
102
- .then(concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loititjo"))))
103
- .else("")
104
- .end()
105
- .as("titre_JO"),
106
- toDateString(ref("loi.loidatjo")).as("date_publication_JO"),
107
- "loi.loinumjo as numero_JO",
108
- "loi.url_jo as url_JO",
109
- toDateString(ref("loi.loidatjo2")).as("date_publication_JO_correctif_1"),
110
- "loi.loinumjo2 as numero_JO_correctif_1",
111
- "loi.url_jo2 as url_JO_correctif_1",
112
- toDateString(ref("loi.loidatjo3")).as("date_publication_JO_correctif_2"),
113
- "loi.loinumjo3 as numero_JO_correctif_2",
114
- "loi.url_jo3 as url_JO_correctif_2",
115
- lectures(ref("loi.loicod")).as("lectures"),
116
- themes(ref("loi.loicod")).as("themes"),
117
- ])
118
- .$narrowType();
119
- export function findAllDossiers() {
120
- return findAllDossiersQuery.stream();
121
- }
122
- export function getCodeActeLecture(codeNatureDossier, typeLecture, assemblee) {
123
- const codeAssemblee = assemblee === "Sénat" ? "SN" : assemblee === "Assemblée nationale" ? "AN" : null;
124
- if (typeLecture === "Commission mixte paritaire") {
125
- return "CMP";
126
- }
127
- if (!codeAssemblee) {
128
- return null;
129
- }
130
- if (["ppl", "pjl", "cvn"].includes(codeNatureDossier) && typeLecture === "Première lecture") {
131
- return `${codeAssemblee}1`;
132
- }
133
- if (["ppl", "pjl", "cvn"].includes(codeNatureDossier) && typeLecture === "Deuxième lecture") {
134
- return `${codeAssemblee}2`;
135
- }
136
- if (["ppl", "pjl", "cvn"].includes(codeNatureDossier) && typeLecture === "Troisième lecture") {
137
- return `${codeAssemblee}3`;
138
- }
139
- if (["ppl", "pjl", "cvn"].includes(codeNatureDossier) && typeLecture === "Quatrième lecture") {
140
- return `${codeAssemblee}4`;
141
- }
142
- if (["ppl", "pjl", "cvn"].includes(codeNatureDossier) && typeLecture === "Nouvelle lecture") {
143
- return `${codeAssemblee}NLEC`;
144
- }
145
- if (["ppl", "pjl", "cvn"].includes(codeNatureDossier) && typeLecture === "Lecture définitive") {
146
- return `${codeAssemblee}LDEF`;
147
- }
148
- if (["ppr"].includes(codeNatureDossier) && typeLecture === "Première lecture") {
149
- return `${codeAssemblee}LUNI`;
150
- }
151
- return null;
152
- }
153
- // Helper pour déterminer le code de phase (SN1, SN2, CMP...)
154
- function getPhasePrefix(lecture, assemblee) {
155
- if (assemblee !== "Sénat")
156
- return null;
157
- const typeLibelle = (lecture.type_lecture || "").toLowerCase();
158
- if (typeLibelle.includes("cmp") || typeLibelle.includes("mixte"))
159
- return "CMP";
160
- if (typeLibelle.includes("nouvelle lecture"))
161
- return "SNNLEC";
162
- if (typeLibelle.includes("d\u00e9finitive"))
163
- return "SNLDEF";
164
- if (typeLibelle.includes("unique"))
165
- return "SNLUNI";
166
- if (lecture.ordre_lecture) {
167
- return `SN${lecture.ordre_lecture}`;
168
- }
169
- if (typeLibelle.includes("premi\u00e8re"))
170
- return "SN1";
171
- if (typeLibelle.includes("deuxi\u00e8me") || typeLibelle.includes("seconde"))
172
- return "SN2";
173
- return "SN1";
174
- }
175
- export function buildActesLegislatifs(dossier) {
176
- const actes = [];
177
- const loiSignet = dossier.signet;
178
- const lectures = dossier.lectures || [];
179
- for (const lecture of lectures) {
180
- const lecturesAssemblee = lecture.lectures_assemblee || [];
181
- for (const lecAss of lecturesAssemblee) {
182
- // On ne traite que la partie SÉNAT
183
- if (lecAss.assemblee !== "Sénat")
184
- continue;
185
- const phasePrefix = getPhasePrefix(lecture, lecAss.assemblee);
186
- if (!phasePrefix)
187
- continue;
188
- // Préparation des textes (tri chronologique)
189
- const textes = lecAss.textes || [];
190
- const textesTries = [...textes].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
191
- // =================================================================
192
- // A. DÉPÔT
193
- // =================================================================
194
- const depotTexte = textesTries.find((t) => (t.origine || "").toLowerCase().includes("déposé") ||
195
- (t.origine || "").toLowerCase().includes("transmis") ||
196
- t.ordre_origine === "0");
197
- if (depotTexte && depotTexte.date) {
198
- actes.push({
199
- code_acte: `${phasePrefix}-DEPOT`,
200
- date: depotTexte.date,
201
- libelle: `Dépôt du texte n°${depotTexte.numero}`,
202
- id: depotTexte.id,
203
- numero: depotTexte.numero,
204
- uid: `${loiSignet}-${phasePrefix}-DEPOT`,
205
- session: lecAss.session,
206
- chambre: "SN",
207
- signet_dossier: loiSignet,
208
- texte_url: depotTexte.url,
209
- code_organisme: null,
210
- });
211
- }
212
- // =================================================================
213
- // B. COMMISSION (Rapports)
214
- // =================================================================
215
- const rapports = lecAss.rapports || [];
216
- for (const rap of rapports) {
217
- if (rap.date) {
218
- actes.push({
219
- code_acte: `${phasePrefix}-COM-FOND`,
220
- date: rap.date,
221
- libelle: `Rapport n°${rap.numero} de la commission`,
222
- id: rap.id,
223
- numero: rap.numero,
224
- code_organisme: rap.code_organisme,
225
- adoption: rap.adoption,
226
- uid: `${loiSignet}-${phasePrefix}-COM`,
227
- session: lecAss.session,
228
- chambre: "SN",
229
- signet_dossier: loiSignet,
230
- texte_url: rap.url,
231
- });
232
- }
233
- }
234
- // =================================================================
235
- // C. SÉANCE PUBLIQUE
236
- // =================================================================
237
- const datesSeances = lecAss.dates_seances || [];
238
- if (datesSeances.length > 0) {
239
- // Tri des objets dates
240
- datesSeances.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
241
- const premiereSeance = datesSeances[0];
242
- if (premiereSeance && premiereSeance.date) {
243
- actes.push({
244
- // Champs pour buildParlementActeLegislatif
245
- code_acte: `${phasePrefix}-DEBATS-SEANCE`,
246
- date: premiereSeance.date,
247
- libelle: `Discussion en séance publique`,
248
- uid: `${loiSignet}-${phasePrefix}-DEBATS-SEANCE`,
249
- session: lecAss.session,
250
- chambre: "SN",
251
- signet_dossier: loiSignet,
252
- code_organisme: null,
253
- });
254
- }
255
- }
256
- // =================================================================
257
- // D. DÉCISION / VOTE
258
- // =================================================================
259
- const texteFinal = [...textesTries].reverse().find((t) => {
260
- const origine = (t.origine || "").toLowerCase();
261
- return (origine.includes("adopté") ||
262
- origine.includes("rejeté") ||
263
- origine.includes("devenu résolution") ||
264
- t.code_adoption === "O");
265
- });
266
- if (texteFinal && texteFinal.date) {
267
- const origine = (texteFinal.origine || "").toLowerCase();
268
- let libelleStatut = "Adopté";
269
- if (origine.includes("rejeté")) {
270
- libelleStatut = "Rejeté";
271
- }
272
- else if (origine.includes("devenue résolution")) {
273
- libelleStatut = "Adopté";
274
- }
275
- actes.push({
276
- code_acte: `${phasePrefix}-DEBATS-DEC`,
277
- date: texteFinal.date,
278
- libelle: `${libelleStatut === "Adopté" ? "Adoption" : "Rejet"} (Texte n°${texteFinal.numero})`,
279
- id: texteFinal.id,
280
- numero: texteFinal.numero,
281
- adoption: libelleStatut,
282
- uid: `${loiSignet}-DEC-${texteFinal.numero}`,
283
- session: lecAss.session,
284
- chambre: "SN",
285
- signet_dossier: loiSignet,
286
- texte_url: texteFinal.url,
287
- code_organisme: null,
288
- });
289
- }
290
- }
291
- }
292
- // =================================================================
293
- // E. HORS LECTURE (CC & PROMULGATION)
294
- // =================================================================
295
- if (dossier.date_decision_CoC) {
296
- actes.push({
297
- code_acte: "CC",
298
- date: dossier.date_decision_CoC,
299
- libelle: `Décision du Conseil constitutionnel`,
300
- id: dossier.url_decision_CoC,
301
- uid: `${loiSignet}-CC`,
302
- chambre: "AN",
303
- signet_dossier: loiSignet,
304
- texte_url: dossier.url_decision_CoC || dossier.url_dossier_CoC,
305
- });
306
- }
307
- if (dossier.date_promulgation) {
308
- actes.push({
309
- code_acte: "PROM",
310
- date: dossier.date_promulgation,
311
- libelle: `Promulgation de la loi`,
312
- date_publication_JO: dossier.date_publication_JO,
313
- numero_JO: dossier.numero_JO,
314
- url_legifrance: dossier.url_JO,
315
- id: dossier.url_JO,
316
- uid: `${loiSignet}-PROM`,
317
- chambre: "AN",
318
- signet_dossier: loiSignet,
319
- });
320
- }
321
- return actes.sort((a, b) => {
322
- const dateA = new Date(a.date).getTime();
323
- const dateB = new Date(b.date).getTime();
324
- return dateA - dateB;
325
- });
326
- }
@@ -1,7 +0,0 @@
1
- export { findAllAmendements } from "./ameli";
2
- export { findAll as findAllDebats } from "./debats";
3
- export { findAllDossiers } from "./dosleg";
4
- export { findAllTextes, findAllRapports } from "./documents";
5
- export { findAllScrutins } from "./scrutins";
6
- export { findAll as findAllQuestions } from "./questions";
7
- export { findAll as findAllSens, findAllCirconscriptions, findAllOrganismes } from "./sens";
@@ -1,7 +0,0 @@
1
- export { findAllAmendements } from "./ameli";
2
- export { findAll as findAllDebats } from "./debats";
3
- export { findAllDossiers } from "./dosleg";
4
- export { findAllTextes, findAllRapports } from "./documents";
5
- export { findAllScrutins } from "./scrutins";
6
- export { findAll as findAllQuestions } from "./questions";
7
- export { findAll as findAllSens, findAllCirconscriptions, findAllOrganismes } from "./sens";
@@ -1,45 +0,0 @@
1
- import { InferResult } from "kysely";
2
- export type QuestionResult = InferResult<typeof findAllQuery>[0];
3
- declare const findAllQuery: import("kysely").SelectQueryBuilder<{
4
- [x: string]: any;
5
- [x: number]: any;
6
- [x: symbol]: any;
7
- }, "tam_questions" | "sortquestion" | "etatquestion" | "tam_ministeres" | "naturequestion", {
8
- [x: string]: any;
9
- date_publication_JO: string;
10
- ministere_depot: string;
11
- ministere_depot_date_debut: string;
12
- date_transmission: string;
13
- date_reponse_JO: string;
14
- date_erratum_JO: string;
15
- date_cloture: string;
16
- date_signalement: string;
17
- themes: {
18
- libelle: any;
19
- }[];
20
- reponses: {
21
- [x: string]: any;
22
- date_reponse_JO: string;
23
- date_erratum_JO: string;
24
- }[];
25
- }>;
26
- export declare function findAll(): AsyncIterableIterator<{
27
- [x: string]: any;
28
- date_publication_JO: string;
29
- ministere_depot: string;
30
- ministere_depot_date_debut: string;
31
- date_transmission: string;
32
- date_reponse_JO: string;
33
- date_erratum_JO: string;
34
- date_cloture: string;
35
- date_signalement: string;
36
- themes: {
37
- libelle: any;
38
- }[];
39
- reponses: {
40
- [x: string]: any;
41
- date_reponse_JO: string;
42
- date_erratum_JO: string;
43
- }[];
44
- }>;
45
- export {};
@@ -1,89 +0,0 @@
1
- import { jsonArrayFrom } from "kysely/helpers/postgres";
2
- import { dbSenat } from "../databases";
3
- import { expandToRows, rtrim, toDateString } from "./util";
4
- function reponses(questionId) {
5
- return jsonArrayFrom(dbSenat
6
- .withSchema("questions")
7
- .selectFrom("tam_reponses")
8
- .where("tam_reponses.idque", "=", questionId)
9
- .select(({ ref }) => [
10
- toDateString(ref("tam_reponses.datejorep")).as("date_reponse_JO"),
11
- "tam_reponses.pagejorep as page_JO",
12
- toDateString(ref("tam_reponses.errdate")).as("date_erratum_JO"),
13
- "tam_reponses.minreplib as ministere_reponse",
14
- "tam_reponses.minrepid as ministere_reponse_id",
15
- "tam_reponses.urlrep as url",
16
- "tam_reponses.txtrep as texte",
17
- "tam_reponses.txterrrep as texte_erratum",
18
- ])
19
- .orderBy("tam_reponses.datejorep", "asc"));
20
- }
21
- function themes(questionId) {
22
- return jsonArrayFrom(dbSenat
23
- .withSchema("questions")
24
- .with("question_theme", (db) => db
25
- .selectFrom("tam_questions")
26
- .select(({ eb, ref, val }) => [
27
- "id as question_id",
28
- eb.cast(expandToRows(ref("tam_questions.themes"), val("#(\\d+)")), "smallint").as("theme_id"),
29
- ]))
30
- .selectFrom("the")
31
- .leftJoin("question_theme", "the.thenouidt", "question_theme.theme_id")
32
- .where("question_theme.question_id", "=", questionId)
33
- .select("the.thelib as libelle")
34
- .orderBy("the.thenouidt", "asc"));
35
- }
36
- const findAllQuery = dbSenat
37
- .withSchema("questions")
38
- .selectFrom("tam_questions")
39
- .leftJoin("tam_ministeres", "tam_questions.mindepotid", "tam_ministeres.minid")
40
- .leftJoin("sortquestion", (join) => join.onRef("tam_questions.sorquecod", "=", (eb) => eb.cast("sortquestion.sorquecod", "bigint")))
41
- .leftJoin("naturequestion", "tam_questions.natquecod", "naturequestion.natquecod")
42
- .leftJoin("etatquestion", (join) => join.onRef("tam_questions.etaquecod", "=", (eb) => eb.cast("etatquestion.etaquecod", "bigint")))
43
- .select(({ ref }) => [
44
- "tam_questions.repub as republique",
45
- "tam_questions.legislature as legislature",
46
- "tam_questions.natquecod as nature",
47
- "naturequestion.natquelib as nature_libelle",
48
- "tam_questions.numero as numero",
49
- "tam_questions.reference as reference",
50
- "tam_questions.titre as titre",
51
- "tam_questions.nom as nom",
52
- "tam_questions.prenom as prenom",
53
- "tam_questions.nomtechnique as nom_technique",
54
- "tam_questions.codequalite as civilite",
55
- "tam_questions.matricule as matricule",
56
- "tam_questions.cirnum as circonscription_numero",
57
- "tam_questions.circonscription as circonscription",
58
- "tam_questions.groupe as groupe",
59
- "tam_questions.ratgrp as type_appartenance",
60
- toDateString(ref("tam_questions.datejodepot")).as("date_publication_JO"),
61
- "tam_questions.pagejodepot as page_JO",
62
- rtrim(ref("tam_questions.mindepotlib")).as("ministere_depot"),
63
- "tam_questions.mindepotid as ministere_depot_id",
64
- toDateString(ref("tam_ministeres.datedebut")).as("ministere_depot_date_debut"),
65
- toDateString(ref("tam_questions.datejotran")).as("date_transmission"),
66
- "tam_questions.mintranlib as ministere_transmission",
67
- toDateString(ref("tam_questions.datejorep1")).as("date_reponse_JO"),
68
- toDateString(ref("tam_questions.dateerr")).as("date_erratum_JO"),
69
- "tam_questions.pageerr as page_erratum_JO",
70
- "tam_questions.minreplib1 as ministere_reponse",
71
- toDateString(ref("tam_questions.datecloture")).as("date_cloture"),
72
- toDateString(ref("tam_questions.datesignal")).as("date_signalement"),
73
- "tam_questions.refquerappelee as reference_question_rappelee",
74
- //"tam_questions.url as url", // TODO ?
75
- "tam_questions.txtque as texte",
76
- "tam_questions.txterrque as texte_erratum",
77
- "tam_questions.rubrique as rubrique",
78
- "sortquestion.sorquelib as sort",
79
- "sortquestion.sorquecod as sort_code",
80
- "sortquestion.sorquenumtri as sort_tri",
81
- "etatquestion.etaquelib as etat_libelle",
82
- "etatquestion.etaquecod as etat_code",
83
- "etatquestion.etaquenumtri as etat_tri",
84
- themes(ref("tam_questions.id")).as("themes"),
85
- reponses(ref("tam_questions.id")).as("reponses"),
86
- ]);
87
- export function findAll() {
88
- return findAllQuery.stream();
89
- }
@@ -1,13 +0,0 @@
1
- import { InferResult } from "kysely";
2
- export type ScrutinResult = InferResult<typeof findAllScrutinsQuery>[0];
3
- declare const findAllScrutinsQuery: import("kysely").SelectQueryBuilder<{
4
- [x: string]: any;
5
- [x: number]: any;
6
- [x: symbol]: any;
7
- }, "date_seance" | "lecass" | "lecture" | "loi" | "scr" | "typlec", {
8
- [x: string]: any;
9
- }>;
10
- export declare function findAllScrutins(fromSession?: number): AsyncIterableIterator<{
11
- [x: string]: any;
12
- }>;
13
- export {};