@tricoteuses/senat 1.1.1 → 1.3.1

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 (259) hide show
  1. package/README.md +53 -15
  2. package/lib/aggregates.d.ts +4 -6
  3. package/lib/aggregates.mjs +908 -780
  4. package/lib/aggregates.ts +8 -122
  5. package/lib/data/legislatures.json +38 -0
  6. package/lib/databases.d.ts +9 -0
  7. package/lib/databases.js +41 -11
  8. package/lib/databases.mjs +32 -1
  9. package/lib/databases.ts +40 -1
  10. package/lib/fields.mjs +64 -18
  11. package/lib/index.d.ts +5 -6
  12. package/lib/index.js +8 -99
  13. package/lib/index.mjs +4 -6
  14. package/lib/index.ts +9 -26
  15. package/lib/inserters.d.ts +0 -4
  16. package/lib/inserters.mjs +461 -337
  17. package/lib/inserters.ts +0 -24
  18. package/lib/legislatures.json +38 -0
  19. package/lib/loaders.d.ts +64 -0
  20. package/lib/loaders.js +682 -0
  21. package/lib/loaders.mjs +158 -0
  22. package/lib/loaders.ts +271 -0
  23. package/lib/model/ameli.d.ts +105 -4
  24. package/lib/model/ameli.js +20 -160
  25. package/lib/model/ameli.mjs +84 -57
  26. package/lib/model/ameli.ts +94 -80
  27. package/lib/model/debats.d.ts +0 -4
  28. package/lib/model/debats.js +1 -122
  29. package/lib/model/debats.mjs +1 -43
  30. package/lib/model/debats.ts +0 -68
  31. package/lib/model/dosleg.d.ts +227 -29
  32. package/lib/model/dosleg.js +92 -832
  33. package/lib/model/dosleg.mjs +196 -337
  34. package/lib/model/dosleg.ts +213 -531
  35. package/lib/model/index.d.ts +4 -5
  36. package/lib/model/index.js +14 -15
  37. package/lib/model/index.mjs +4 -5
  38. package/lib/model/index.ts +8 -5
  39. package/lib/model/questions.d.ts +88 -2
  40. package/lib/model/questions.js +40 -45
  41. package/lib/model/questions.mjs +71 -8
  42. package/lib/model/questions.ts +90 -11
  43. package/lib/model/sens.d.ts +524 -2
  44. package/lib/model/sens.js +172 -49
  45. package/lib/model/sens.mjs +415 -9
  46. package/lib/model/sens.ts +514 -16
  47. package/lib/model/texte.d.ts +7 -0
  48. package/lib/model/texte.js +321 -0
  49. package/lib/model/texte.mjs +208 -0
  50. package/lib/model/texte.ts +229 -0
  51. package/lib/model/util.d.ts +7 -1
  52. package/lib/model/util.js +37 -53
  53. package/lib/model/util.mjs +19 -10
  54. package/lib/model/util.ts +30 -14
  55. package/lib/raw_types/ameli.d.ts +912 -538
  56. package/lib/raw_types/ameli.js +1 -39
  57. package/lib/raw_types/ameli.mjs +4 -1
  58. package/lib/raw_types/ameli.ts +947 -597
  59. package/lib/raw_types/debats.d.ts +204 -124
  60. package/lib/raw_types/debats.js +1 -18
  61. package/lib/raw_types/debats.mjs +4 -1
  62. package/lib/raw_types/debats.ts +218 -141
  63. package/lib/raw_types/dosleg.d.ts +3533 -2024
  64. package/lib/raw_types/dosleg.js +1 -92
  65. package/lib/raw_types/dosleg.mjs +4 -1
  66. package/lib/raw_types/dosleg.ts +3621 -2189
  67. package/lib/raw_types/questions.d.ts +404 -220
  68. package/lib/raw_types/questions.js +1 -18
  69. package/lib/raw_types/questions.mjs +4 -1
  70. package/lib/raw_types/questions.ts +404 -226
  71. package/lib/raw_types/sens.d.ts +4391 -2706
  72. package/lib/raw_types/sens.js +1 -108
  73. package/lib/raw_types/sens.mjs +4 -1
  74. package/lib/raw_types/sens.ts +4495 -2903
  75. package/lib/raw_types_kysely/ameli.d.ts +6 -0
  76. package/lib/raw_types_kysely/ameli.mjs +7 -0
  77. package/lib/raw_types_kysely/ameli.ts +6 -0
  78. package/lib/raw_types_kysely/debats.d.ts +6 -0
  79. package/lib/raw_types_kysely/debats.mjs +7 -0
  80. package/lib/raw_types_kysely/debats.ts +6 -0
  81. package/lib/raw_types_kysely/dosleg.d.ts +6 -0
  82. package/lib/raw_types_kysely/dosleg.mjs +7 -0
  83. package/lib/raw_types_kysely/dosleg.ts +6 -0
  84. package/lib/raw_types_kysely/questions.d.ts +6 -0
  85. package/lib/raw_types_kysely/questions.mjs +7 -0
  86. package/lib/raw_types_kysely/questions.ts +6 -0
  87. package/lib/raw_types_kysely/sens.d.ts +6 -0
  88. package/lib/raw_types_kysely/sens.mjs +7 -0
  89. package/lib/raw_types_kysely/sens.ts +6 -0
  90. package/lib/raw_types_kysely/texte.d.ts +45 -0
  91. package/lib/raw_types_kysely/texte.mjs +7 -0
  92. package/lib/raw_types_kysely/texte.ts +53 -0
  93. package/lib/raw_types_schemats/ameli.d.ts +541 -0
  94. package/lib/raw_types_schemats/ameli.js +45 -0
  95. package/lib/raw_types_schemats/ameli.mjs +2 -0
  96. package/lib/raw_types_schemats/ameli.ts +601 -0
  97. package/lib/raw_types_schemats/debats.d.ts +127 -0
  98. package/lib/raw_types_schemats/debats.js +24 -0
  99. package/lib/raw_types_schemats/debats.mjs +2 -0
  100. package/lib/raw_types_schemats/debats.ts +145 -0
  101. package/lib/raw_types_schemats/dosleg.d.ts +2029 -0
  102. package/lib/raw_types_schemats/dosleg.js +98 -0
  103. package/lib/raw_types_schemats/dosleg.mjs +2 -0
  104. package/lib/raw_types_schemats/dosleg.ts +2195 -0
  105. package/lib/raw_types_schemats/questions.d.ts +233 -0
  106. package/lib/raw_types_schemats/questions.js +24 -0
  107. package/lib/raw_types_schemats/questions.mjs +2 -0
  108. package/lib/raw_types_schemats/questions.ts +251 -0
  109. package/lib/raw_types_schemats/sens.d.ts +2709 -0
  110. package/lib/raw_types_schemats/sens.js +114 -0
  111. package/lib/raw_types_schemats/sens.mjs +2 -0
  112. package/lib/raw_types_schemats/sens.ts +2907 -0
  113. package/lib/scripts/convert_data.js +574 -215
  114. package/lib/scripts/convert_data.mjs +134 -99
  115. package/lib/scripts/convert_data.ts +173 -112
  116. package/lib/scripts/datautil.d.ts +5 -0
  117. package/lib/scripts/datautil.js +64 -0
  118. package/lib/scripts/datautil.mjs +16 -0
  119. package/lib/scripts/datautil.ts +19 -0
  120. package/lib/scripts/parse_textes.js +132 -0
  121. package/lib/scripts/parse_textes.mjs +46 -0
  122. package/lib/scripts/parse_textes.ts +65 -0
  123. package/lib/scripts/retrieve_documents.d.ts +1 -0
  124. package/lib/scripts/retrieve_documents.js +521 -0
  125. package/lib/scripts/retrieve_documents.mjs +249 -0
  126. package/lib/scripts/retrieve_documents.ts +298 -0
  127. package/lib/scripts/retrieve_open_data.js +77 -69
  128. package/lib/scripts/retrieve_open_data.mjs +48 -49
  129. package/lib/scripts/retrieve_open_data.ts +74 -58
  130. package/lib/scripts/retrieve_senateurs_photos.js +45 -63
  131. package/lib/scripts/retrieve_senateurs_photos.mjs +4 -21
  132. package/lib/scripts/retrieve_senateurs_photos.ts +6 -29
  133. package/lib/scripts/retrieve_textes.mjs +325 -74
  134. package/lib/scripts/retrieve_textes.ts +111 -63
  135. package/lib/scripts/shared/cli_helpers.d.ts +44 -0
  136. package/lib/scripts/shared/cli_helpers.js +35 -0
  137. package/lib/scripts/shared/cli_helpers.ts +36 -0
  138. package/lib/scripts/shared/util.d.ts +3 -0
  139. package/lib/scripts/shared/util.js +102 -0
  140. package/lib/scripts/shared/util.ts +33 -0
  141. package/lib/src/aggregates.d.ts +52 -0
  142. package/lib/src/aggregates.mjs +726 -0
  143. package/lib/src/config.d.ts +2 -0
  144. package/lib/src/config.mjs +16 -0
  145. package/lib/src/databases.d.ts +18 -0
  146. package/lib/src/databases.mjs +55 -0
  147. package/lib/src/datasets.d.ts +28 -0
  148. package/lib/src/datasets.mjs +78 -0
  149. package/lib/src/fields.d.ts +10 -0
  150. package/lib/src/fields.mjs +22 -0
  151. package/lib/src/index.d.ts +8 -0
  152. package/lib/src/index.mjs +7 -0
  153. package/lib/src/inserters.d.ts +98 -0
  154. package/lib/src/inserters.mjs +360 -0
  155. package/lib/src/loaders.d.ts +36 -0
  156. package/lib/src/loaders.mjs +107 -0
  157. package/lib/src/model/ameli.d.ts +4 -0
  158. package/lib/src/model/ameli.js +57 -0
  159. package/lib/src/model/debats.d.ts +4 -0
  160. package/lib/src/model/debats.js +43 -0
  161. package/lib/src/model/dosleg.d.ts +197 -0
  162. package/lib/src/model/dosleg.js +169 -0
  163. package/lib/src/model/index.d.ts +4 -0
  164. package/lib/src/model/index.js +4 -0
  165. package/lib/src/model/questions.d.ts +89 -0
  166. package/lib/src/model/questions.js +76 -0
  167. package/lib/src/model/sens.d.ts +390 -0
  168. package/lib/src/model/sens.js +339 -0
  169. package/lib/src/model/texte.d.ts +7 -0
  170. package/lib/src/model/texte.js +183 -0
  171. package/lib/src/raw_types_kysely/ameli.d.ts +915 -0
  172. package/lib/src/raw_types_kysely/ameli.js +5 -0
  173. package/lib/src/raw_types_kysely/debats.d.ts +207 -0
  174. package/lib/src/raw_types_kysely/debats.js +5 -0
  175. package/lib/src/raw_types_kysely/dosleg.d.ts +3532 -0
  176. package/lib/src/raw_types_kysely/dosleg.js +5 -0
  177. package/lib/src/raw_types_kysely/questions.d.ts +414 -0
  178. package/lib/src/raw_types_kysely/questions.js +5 -0
  179. package/lib/src/raw_types_kysely/sens.d.ts +4394 -0
  180. package/lib/src/raw_types_kysely/sens.js +5 -0
  181. package/lib/src/raw_types_schemats/ameli.d.ts +541 -0
  182. package/lib/src/raw_types_schemats/ameli.js +2 -0
  183. package/lib/src/raw_types_schemats/debats.d.ts +127 -0
  184. package/lib/src/raw_types_schemats/debats.js +2 -0
  185. package/lib/src/raw_types_schemats/dosleg.d.ts +2027 -0
  186. package/lib/src/raw_types_schemats/dosleg.js +2 -0
  187. package/lib/src/raw_types_schemats/questions.d.ts +231 -0
  188. package/lib/src/raw_types_schemats/questions.js +2 -0
  189. package/lib/src/raw_types_schemats/sens.d.ts +2709 -0
  190. package/lib/src/raw_types_schemats/sens.js +2 -0
  191. package/lib/src/scripts/convert_data.d.ts +1 -0
  192. package/lib/src/scripts/convert_data.js +95 -0
  193. package/lib/src/scripts/datautil.d.ts +5 -0
  194. package/lib/src/scripts/datautil.js +16 -0
  195. package/lib/src/scripts/parse_textes.d.ts +1 -0
  196. package/lib/src/scripts/parse_textes.js +47 -0
  197. package/lib/src/scripts/retrieve_documents.d.ts +1 -0
  198. package/lib/src/scripts/retrieve_documents.js +258 -0
  199. package/lib/src/scripts/retrieve_open_data.d.ts +1 -0
  200. package/lib/src/scripts/retrieve_open_data.js +214 -0
  201. package/lib/src/scripts/retrieve_senateurs_photos.d.ts +1 -0
  202. package/lib/src/scripts/retrieve_senateurs_photos.js +147 -0
  203. package/lib/src/scripts/shared/cli_helpers.d.ts +44 -0
  204. package/lib/src/scripts/shared/cli_helpers.js +32 -0
  205. package/lib/src/scripts/shared/util.d.ts +3 -0
  206. package/lib/src/scripts/shared/util.js +28 -0
  207. package/lib/src/strings.d.ts +1 -0
  208. package/lib/src/strings.mjs +18 -0
  209. package/lib/src/types/ameli.d.ts +10 -0
  210. package/lib/src/types/ameli.js +13 -0
  211. package/lib/src/types/debats.d.ts +4 -0
  212. package/lib/src/types/debats.js +2 -0
  213. package/lib/src/types/dosleg.d.ts +98 -0
  214. package/lib/src/types/dosleg.js +151 -0
  215. package/lib/src/types/questions.d.ts +2 -0
  216. package/lib/src/types/questions.js +1 -0
  217. package/lib/src/types/sens.d.ts +10 -0
  218. package/lib/src/types/sens.js +1 -0
  219. package/lib/src/types/sessions.d.ts +42 -0
  220. package/lib/src/types/sessions.js +43 -0
  221. package/lib/src/types/texte.d.ts +61 -0
  222. package/lib/src/types/texte.js +16 -0
  223. package/lib/src/validators/config.d.ts +1 -0
  224. package/lib/src/validators/config.js +54 -0
  225. package/lib/src/validators/senat.d.ts +0 -0
  226. package/lib/src/validators/senat.js +24 -0
  227. package/lib/types/ameli.d.ts +1 -1
  228. package/lib/types/ameli.js +2 -2
  229. package/lib/types/ameli.ts +1 -1
  230. package/lib/types/debats.d.ts +1 -1
  231. package/lib/types/debats.js +2 -2
  232. package/lib/types/debats.ts +1 -1
  233. package/lib/types/dosleg.d.ts +2 -2
  234. package/lib/types/dosleg.js +2 -2
  235. package/lib/types/dosleg.ts +2 -2
  236. package/lib/types/questions.d.ts +1 -1
  237. package/lib/types/questions.js +2 -2
  238. package/lib/types/questions.ts +1 -1
  239. package/lib/types/sens.d.ts +1 -3
  240. package/lib/types/sens.js +2 -5
  241. package/lib/types/sens.mjs +1 -23
  242. package/lib/types/sens.ts +1 -25
  243. package/lib/types/sessions.d.ts +42 -0
  244. package/lib/types/sessions.js +51 -0
  245. package/lib/types/sessions.mjs +43 -0
  246. package/lib/types/sessions.ts +42 -0
  247. package/lib/types/texte.d.ts +65 -0
  248. package/lib/types/texte.js +24 -0
  249. package/lib/types/texte.mjs +16 -0
  250. package/lib/types/texte.ts +76 -0
  251. package/package.json +35 -10
  252. package/lib/aggregates.js +0 -1122
  253. package/lib/fields.js +0 -68
  254. package/lib/inserters.js +0 -518
  255. package/lib/scripts/fix_db.js +0 -144
  256. package/lib/scripts/fix_db.mjs +0 -64
  257. package/lib/scripts/fix_db.ts +0 -75
  258. package/lib/scripts/retrieve_textes.js +0 -179
  259. /package/lib/scripts/{fix_db.d.ts → parse_textes.d.ts} +0 -0
@@ -0,0 +1,158 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import legislatures from "./legislatures.json";
4
+ import { datasets } from "./datasets";
5
+ import { UNDEFINED_SESSION } from "./scripts/datautil";
6
+ export { EnabledDatasets } from "./datasets";
7
+ export const DOSLEG_DOSSIERS_FOLDER = "dossiers";
8
+ export const SENS_CIRCONSCRIPTIONS_FOLDER = "circonscriptions";
9
+ export const SENS_ORGANISMES_FOLDER = "organismes";
10
+ export const SENS_SENATEURS_FOLDER = "senateurs";
11
+ export const TEXTE_FOLDER = "leg";
12
+ export const TEXTE_ORIGINAL_FOLDER = "original";
13
+ export const TEXTE_TRANSFORMED_FOLDER = "transformed";
14
+ export const DOCUMENT_METADATA_FILE = "metadata.json";
15
+ export const RAPPORT_FOLDER = "rap";
16
+ export function* iterFilePaths(dirPath) {
17
+ if (dirPath && fs.existsSync(dirPath)) {
18
+ const files = fs.readdirSync(dirPath, { withFileTypes: true, recursive: true });
19
+ for (const file of files) {
20
+ if (file.isFile()) {
21
+ yield path.join(file.parentPath, file.name);
22
+ }
23
+ }
24
+ }
25
+ }
26
+ function* iterLoadSenatItems(dataDir, dataset, legislatureOrSession, subDir, { log = false } = {}) {
27
+ let itemsDir = path.join(dataDir, dataset.database);
28
+ if (subDir) {
29
+ itemsDir = path.join(itemsDir, subDir);
30
+ }
31
+ if (legislatureOrSession) {
32
+ itemsDir = path.join(itemsDir, String(legislatureOrSession));
33
+ }
34
+ for (const filePath of iterFilePaths(itemsDir)) {
35
+ if (log) {
36
+ console.log(`Loading file: ${filePath}…`);
37
+ }
38
+ const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
39
+ const item = JSON.parse(itemJson);
40
+ const filePathFromDataset = filePath.substring(filePath.indexOf(dataset.database) + dataset.database.length);
41
+ yield {
42
+ item,
43
+ filePathFromDataset,
44
+ legislature: legislatureOrSession,
45
+ };
46
+ }
47
+ }
48
+ export function* iterLoadSenatAmendements(dataDir, session, options = {}) {
49
+ for (const amendementItem of iterLoadSenatItems(dataDir, datasets.ameli, session, undefined, options)) {
50
+ yield amendementItem;
51
+ }
52
+ }
53
+ export function* iterLoadSenatDossiersLegislatifs(dataDir, session, options = {}) {
54
+ for (const dossierLegislatifItem of iterLoadSenatItems(dataDir, datasets.dosleg, session, DOSLEG_DOSSIERS_FOLDER, options)) {
55
+ yield dossierLegislatifItem;
56
+ }
57
+ }
58
+ export function* iterLoadSenatDossiersLegislatifsTexteUrls(dataDir, session) {
59
+ let itemsDir = path.join(dataDir, TEXTE_FOLDER, TEXTE_ORIGINAL_FOLDER);
60
+ if (session) {
61
+ itemsDir = path.join(itemsDir, session.toString());
62
+ }
63
+ for (const filePath of iterFilePaths(itemsDir)) {
64
+ const parsedFilePath = path.parse(filePath);
65
+ if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
66
+ const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
67
+ const item = JSON.parse(itemJson);
68
+ yield {
69
+ item,
70
+ };
71
+ }
72
+ }
73
+ }
74
+ export function* iterLoadSenatDossiersLegislatifsRapportUrls(dataDir, session) {
75
+ let itemsDir = path.join(dataDir, RAPPORT_FOLDER);
76
+ if (session) {
77
+ itemsDir = path.join(itemsDir, session.toString());
78
+ }
79
+ for (const filePath of iterFilePaths(itemsDir)) {
80
+ const parsedFilePath = path.parse(filePath);
81
+ if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
82
+ const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
83
+ const item = JSON.parse(itemJson);
84
+ yield {
85
+ item,
86
+ };
87
+ }
88
+ }
89
+ }
90
+ export function* iterLoadSenatDossiersLegislatifsTextes(dataDir, session, options = {}) {
91
+ for (const { item: dossierLegislatif } of iterLoadSenatDossiersLegislatifs(dataDir, session, options)) {
92
+ for (const lecture of dossierLegislatif.lectures) {
93
+ const lecturesSenat = lecture.lectures_assemblee
94
+ .filter(lectureAssemblee => lectureAssemblee.assemblee === "Sénat");
95
+ for (const lectureSenat of lecturesSenat) {
96
+ for (const texte of lectureSenat.textes) {
97
+ const enrichedTexte = {
98
+ signet_dossier: dossierLegislatif.signet,
99
+ url_dossier_senat: dossierLegislatif.url,
100
+ url_dossier_assemblee_nationale: dossierLegislatif.url_dossier_assemblee_nationale,
101
+ type_lecture: lecture.type_lecture,
102
+ libelle_lecture: lecture.libelle,
103
+ libelle_organisme: lectureSenat.libelle_organisme,
104
+ ...texte,
105
+ };
106
+ const texteItem = {
107
+ item: enrichedTexte,
108
+ };
109
+ if (texte.url) {
110
+ const texteName = path.parse(texte.url).name;
111
+ texteItem.filePathFromDataset
112
+ = path.join(`${texte.session ?? UNDEFINED_SESSION}`, texteName, `${texteName}.pdf`);
113
+ }
114
+ yield texteItem;
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ export function loadSenatTexteContent(dataDir, textePathFromDataset) {
121
+ const parsedTextePath = path.parse(textePathFromDataset);
122
+ const jsonTexteName = `${parsedTextePath.name}.json`;
123
+ const fullTextePath = path.join(dataDir, TEXTE_FOLDER, TEXTE_TRANSFORMED_FOLDER, parsedTextePath.dir, jsonTexteName);
124
+ if (!fs.existsSync(fullTextePath)) {
125
+ return { item: null };
126
+ }
127
+ const texteJson = fs.readFileSync(fullTextePath, { encoding: "utf8" });
128
+ return { item: JSON.parse(texteJson) };
129
+ }
130
+ export function* iterLoadSenatOrganismes(dataDir, options = {}) {
131
+ for (const organismeItem of iterLoadSenatItems(dataDir, datasets.sens, undefined, SENS_ORGANISMES_FOLDER, options)) {
132
+ yield organismeItem;
133
+ }
134
+ }
135
+ export function* iterLoadSenatSenateurs(dataDir, legislature, options = {}) {
136
+ const dateDebutLegislatureStr = legislatures
137
+ .find(legislatureInfo => legislatureInfo.numero === legislature)
138
+ ?.date_debut;
139
+ const dateDebutLegislature = new Date(dateDebutLegislatureStr);
140
+ for (const senateurItem of iterLoadSenatItems(dataDir, datasets.sens, undefined, SENS_SENATEURS_FOLDER, options)) {
141
+ const dateFinMandatSenateur = senateurItem.item.mandats_senateur[0]?.date_fin ?
142
+ new Date(senateurItem.item.mandats_senateur[0]?.date_fin) : null;
143
+ if (dateFinMandatSenateur && dateFinMandatSenateur < dateDebutLegislature) {
144
+ continue;
145
+ }
146
+ yield senateurItem;
147
+ }
148
+ }
149
+ export function* iterLoadSenatCirconscriptions(dataDir, options = {}) {
150
+ for (const circonscriptionItem of iterLoadSenatItems(dataDir, datasets.sens, undefined, SENS_CIRCONSCRIPTIONS_FOLDER, options)) {
151
+ yield circonscriptionItem;
152
+ }
153
+ }
154
+ export function* iterLoadSenatQuestions(dataDir, legislature, options = {}) {
155
+ for (const questionItem of iterLoadSenatItems(dataDir, datasets.questions, legislature, undefined, options)) {
156
+ yield questionItem;
157
+ }
158
+ }
package/lib/loaders.ts ADDED
@@ -0,0 +1,271 @@
1
+ import fs from "fs"
2
+ import path from "path"
3
+
4
+ import legislatures from "./legislatures.json"
5
+
6
+ import { Dataset, datasets } from "./datasets"
7
+ import { AmendementResult } from "./model/ameli"
8
+ import { DossierLegislatifResult } from "./model/dosleg"
9
+ import { QuestionResult } from "./model/questions"
10
+ import { CirconscriptionResult, OrganismeResult, SenateurResult } from "./model/sens"
11
+ import { UNDEFINED_SESSION } from "./scripts/datautil"
12
+ import { FlatTexte } from "./types/texte"
13
+
14
+ export { EnabledDatasets } from "./datasets"
15
+
16
+ export const DOSLEG_DOSSIERS_FOLDER = "dossiers"
17
+ export const SENS_CIRCONSCRIPTIONS_FOLDER = "circonscriptions"
18
+ export const SENS_ORGANISMES_FOLDER = "organismes"
19
+ export const SENS_SENATEURS_FOLDER = "senateurs"
20
+ export const TEXTE_FOLDER = "leg"
21
+ export const TEXTE_ORIGINAL_FOLDER = "original"
22
+ export const TEXTE_TRANSFORMED_FOLDER = "transformed"
23
+ export const DOCUMENT_METADATA_FILE = "metadata.json"
24
+ export const RAPPORT_FOLDER = "rap"
25
+
26
+ type IterItem<T> = {
27
+ item: T
28
+ filePathFromDataset?: string,
29
+ legislature?: number
30
+ }
31
+
32
+ export interface TexteMetadata {
33
+ name: string,
34
+ session: string | null | undefined,
35
+ url_expose_des_motifs?: URL,
36
+ url_xml: URL,
37
+ url_html: URL,
38
+ url_pdf: URL,
39
+ }
40
+
41
+ export interface RapportMetadata {
42
+ name: string,
43
+ session: string | null | undefined,
44
+ url_html: URL,
45
+ url_pdf: URL,
46
+ }
47
+
48
+ export interface DossierLegislatifTexteResult {
49
+ signet_dossier: string,
50
+ url_dossier_senat: string,
51
+ url_dossier_assemblee_nationale: string | null,
52
+ type_lecture: string
53
+ libelle_lecture: string
54
+ libelle_organisme: string | null
55
+ numero: string | null
56
+ url: string
57
+ origine_texte: string
58
+ type_texte: string
59
+ date: string
60
+ session: string | null
61
+ auteurs: {
62
+ prenom: string | null
63
+ nom_usuel: string
64
+ matricule: string | null
65
+ }[]
66
+ }
67
+
68
+ export function * iterFilePaths (dirPath: string): Generator<string> {
69
+ if (dirPath && fs.existsSync(dirPath)) {
70
+ const files = fs.readdirSync(dirPath, { withFileTypes: true, recursive: true })
71
+ for (const file of files) {
72
+ if (file.isFile()) {
73
+ yield path.join(file.parentPath, file.name)
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ function * iterLoadSenatItems<T> (
80
+ dataDir: string,
81
+ dataset: Dataset,
82
+ legislatureOrSession?: number,
83
+ subDir?: string,
84
+ { log = false } = {},
85
+ ): Generator<IterItem<T>> {
86
+ let itemsDir = path.join(dataDir, dataset.database)
87
+ if (subDir) {
88
+ itemsDir = path.join(itemsDir, subDir)
89
+ }
90
+ if (legislatureOrSession) {
91
+ itemsDir = path.join(itemsDir, String(legislatureOrSession))
92
+ }
93
+ for (const filePath of iterFilePaths(itemsDir)) {
94
+ if (log) {
95
+ console.log(`Loading file: ${filePath}…`)
96
+ }
97
+
98
+ const itemJson = fs.readFileSync(filePath, { encoding: "utf8" })
99
+ const item: T = JSON.parse(itemJson)
100
+
101
+ const filePathFromDataset = filePath.substring(filePath.indexOf(dataset.database) + dataset.database.length)
102
+
103
+ yield {
104
+ item,
105
+ filePathFromDataset,
106
+ legislature: legislatureOrSession,
107
+ }
108
+ }
109
+ }
110
+
111
+ export function * iterLoadSenatAmendements (
112
+ dataDir: string,
113
+ session: number | undefined,
114
+ options = {},
115
+ ): Generator<IterItem<AmendementResult>> {
116
+ for (const amendementItem
117
+ of iterLoadSenatItems<AmendementResult>(dataDir, datasets.ameli, session, undefined, options)
118
+ ) {
119
+ yield amendementItem
120
+ }
121
+ }
122
+
123
+ export function * iterLoadSenatDossiersLegislatifs (
124
+ dataDir: string,
125
+ session: number | undefined,
126
+ options = {},
127
+ ): Generator<IterItem<DossierLegislatifResult>> {
128
+ for (const dossierLegislatifItem
129
+ of iterLoadSenatItems<DossierLegislatifResult>(dataDir, datasets.dosleg, session, DOSLEG_DOSSIERS_FOLDER, options)
130
+ ) {
131
+ yield dossierLegislatifItem
132
+ }
133
+ }
134
+
135
+ export function * iterLoadSenatDossiersLegislatifsTexteUrls (
136
+ dataDir: string,
137
+ session: number | undefined,
138
+ ): Generator<IterItem<TexteMetadata>> {
139
+ let itemsDir = path.join(dataDir, TEXTE_FOLDER, TEXTE_ORIGINAL_FOLDER)
140
+ if (session) {
141
+ itemsDir = path.join(itemsDir, session.toString())
142
+ }
143
+ for (const filePath of iterFilePaths(itemsDir)) {
144
+ const parsedFilePath = path.parse(filePath)
145
+ if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
146
+ const itemJson = fs.readFileSync(filePath, { encoding: "utf8" })
147
+ const item = JSON.parse(itemJson)
148
+ yield {
149
+ item,
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ export function * iterLoadSenatDossiersLegislatifsRapportUrls (
156
+ dataDir: string,
157
+ session: number | undefined,
158
+ ): Generator<IterItem<RapportMetadata>> {
159
+ let itemsDir = path.join(dataDir, RAPPORT_FOLDER)
160
+ if (session) {
161
+ itemsDir = path.join(itemsDir, session.toString())
162
+ }
163
+ for (const filePath of iterFilePaths(itemsDir)) {
164
+ const parsedFilePath = path.parse(filePath)
165
+ if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
166
+ const itemJson = fs.readFileSync(filePath, { encoding: "utf8" })
167
+ const item = JSON.parse(itemJson)
168
+ yield {
169
+ item,
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ export function * iterLoadSenatDossiersLegislatifsTextes (
176
+ dataDir: string,
177
+ session: number | undefined,
178
+ options = {},
179
+ ): Generator<IterItem<DossierLegislatifTexteResult>> {
180
+ for (const { item: dossierLegislatif } of iterLoadSenatDossiersLegislatifs(dataDir, session, options)) {
181
+ for (const lecture of dossierLegislatif.lectures) {
182
+ const lecturesSenat = lecture.lectures_assemblee
183
+ .filter(lectureAssemblee => lectureAssemblee.assemblee === "Sénat")
184
+ for (const lectureSenat of lecturesSenat) {
185
+ for (const texte of lectureSenat.textes) {
186
+ const enrichedTexte = {
187
+ signet_dossier: dossierLegislatif.signet,
188
+ url_dossier_senat: dossierLegislatif.url,
189
+ url_dossier_assemblee_nationale: dossierLegislatif.url_dossier_assemblee_nationale,
190
+ type_lecture: lecture.type_lecture,
191
+ libelle_lecture: lecture.libelle,
192
+ libelle_organisme: lectureSenat.libelle_organisme,
193
+ ...texte,
194
+ }
195
+ const texteItem: IterItem<DossierLegislatifTexteResult> = {
196
+ item: enrichedTexte,
197
+ }
198
+ if (texte.url) {
199
+ const texteName = path.parse(texte.url).name
200
+ texteItem.filePathFromDataset
201
+ = path.join(`${texte.session ?? UNDEFINED_SESSION}`, texteName, `${texteName}.pdf`)
202
+ }
203
+ yield texteItem
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+
210
+ export function loadSenatTexteContent (
211
+ dataDir: string,
212
+ textePathFromDataset: string,
213
+ ): IterItem<FlatTexte | null> {
214
+ const parsedTextePath = path.parse(textePathFromDataset)
215
+ const jsonTexteName = `${parsedTextePath.name}.json`
216
+ const fullTextePath = path.join(dataDir, TEXTE_FOLDER, TEXTE_TRANSFORMED_FOLDER, parsedTextePath.dir, jsonTexteName)
217
+ if (!fs.existsSync(fullTextePath)) {
218
+ return { item: null }
219
+ }
220
+ const texteJson = fs.readFileSync(fullTextePath, { encoding: "utf8" })
221
+ return { item: JSON.parse(texteJson) }
222
+ }
223
+
224
+ export function * iterLoadSenatOrganismes (
225
+ dataDir: string,
226
+ options = {},
227
+ ): Generator<IterItem<OrganismeResult>> {
228
+ for (const organismeItem of iterLoadSenatItems<OrganismeResult>(dataDir, datasets.sens, undefined, SENS_ORGANISMES_FOLDER, options)) {
229
+ yield organismeItem
230
+ }
231
+ }
232
+
233
+ export function * iterLoadSenatSenateurs (
234
+ dataDir: string,
235
+ legislature: number,
236
+ options = {},
237
+ ): Generator<IterItem<SenateurResult>> {
238
+ const dateDebutLegislatureStr = legislatures
239
+ .find(legislatureInfo => legislatureInfo.numero === legislature)
240
+ ?.date_debut
241
+ const dateDebutLegislature = new Date(dateDebutLegislatureStr!)
242
+ for (const senateurItem of iterLoadSenatItems<SenateurResult>(dataDir, datasets.sens, undefined, SENS_SENATEURS_FOLDER, options)) {
243
+ const dateFinMandatSenateur = senateurItem.item.mandats_senateur[0]?.date_fin ?
244
+ new Date(senateurItem.item.mandats_senateur[0]?.date_fin) : null
245
+ if (dateFinMandatSenateur && dateFinMandatSenateur < dateDebutLegislature) {
246
+ continue
247
+ }
248
+ yield senateurItem
249
+ }
250
+ }
251
+
252
+ export function * iterLoadSenatCirconscriptions (
253
+ dataDir: string,
254
+ options = {},
255
+ ): Generator<IterItem<CirconscriptionResult>> {
256
+ for (const circonscriptionItem of iterLoadSenatItems<CirconscriptionResult>(dataDir, datasets.sens, undefined, SENS_CIRCONSCRIPTIONS_FOLDER, options)) {
257
+ yield circonscriptionItem
258
+ }
259
+ }
260
+
261
+ export function * iterLoadSenatQuestions (
262
+ dataDir: string,
263
+ legislature: number,
264
+ options = {},
265
+ ): Generator<IterItem<QuestionResult>> {
266
+ for (const questionItem
267
+ of iterLoadSenatItems<QuestionResult>(dataDir, datasets.questions, legislature, undefined, options)
268
+ ) {
269
+ yield questionItem
270
+ }
271
+ }
@@ -1,4 +1,105 @@
1
- import { Ses, Sub, TxtAmeli } from '../types/ameli';
2
- export declare const getSessFromAnns: (ids: string[]) => Promise<Ses[]>;
3
- export declare const getSubsFromTxtids: (ids: string[]) => Promise<Sub[]>;
4
- export declare const getTxtsAmeliBySesannNumJoins: (ids: string[]) => Promise<TxtAmeli[]>;
1
+ import { InferResult } from "kysely";
2
+ declare const findAllQuery: import("kysely").SelectQueryBuilder<{
3
+ sub: import("kysely").Nullable<import("../raw_types/ameli").Sub>;
4
+ amdsen: import("../raw_types/ameli").Amdsen;
5
+ amd: import("../raw_types/ameli").Amd;
6
+ avicom: import("kysely").Nullable<import("../raw_types/ameli").Avicom>;
7
+ avigvt: import("kysely").Nullable<import("../raw_types/ameli").Avigvt>;
8
+ cab: import("kysely").Nullable<import("../raw_types/ameli").Cab>;
9
+ com_ameli: import("kysely").Nullable<import("../raw_types/ameli").ComAmeli>;
10
+ ent: import("../raw_types/ameli").Ent;
11
+ etatxt: import("../raw_types/ameli").Etatxt;
12
+ fbu: import("../raw_types/ameli").Fbu;
13
+ grppol_ameli: import("kysely").Nullable<import("../raw_types/ameli").GrppolAmeli>;
14
+ gvt: import("../raw_types/ameli").Gvt;
15
+ intora: import("../raw_types/ameli").Intora;
16
+ irr: import("kysely").Nullable<import("../raw_types/ameli").Irr>;
17
+ lec_ameli: import("kysely").Nullable<import("../raw_types/ameli").LecAmeli>;
18
+ mot: import("../raw_types/ameli").Mot;
19
+ nat: import("kysely").Nullable<import("../raw_types/ameli").Nat>;
20
+ orarol: import("../raw_types/ameli").Orarol;
21
+ sai: import("../raw_types/ameli").Sai;
22
+ saisen: import("../raw_types/ameli").Saisen;
23
+ sea: import("../raw_types/ameli").Sea;
24
+ sen_ameli: import("../raw_types/ameli").SenAmeli;
25
+ ses: import("kysely").Nullable<import("../raw_types/ameli").Ses>;
26
+ sor: import("kysely").Nullable<import("../raw_types/ameli").Sor>;
27
+ txt_ameli: import("kysely").Nullable<import("../raw_types/ameli").TxtAmeli>;
28
+ typrect: import("../raw_types/ameli").Typrect;
29
+ typses: import("../raw_types/ameli").Typses;
30
+ typsub: import("kysely").Nullable<import("../raw_types/ameli").Typsub>;
31
+ w_nivrec: import("../raw_types/ameli").WNivrec;
32
+ }, "sub" | "amd" | "avicom" | "avigvt" | "cab" | "com_ameli" | "grppol_ameli" | "irr" | "lec_ameli" | "nat" | "ses" | "sor" | "txt_ameli" | "typsub", {
33
+ session: string | null;
34
+ signet_dossier_legislatif: string | null;
35
+ nature_texte: string | null;
36
+ numero_texte: number | null;
37
+ intitule_texte: string | null;
38
+ lecture: string | null;
39
+ nature: string;
40
+ id: number;
41
+ parent_id: number | null;
42
+ numero: string | null;
43
+ numero_absolu: string | null;
44
+ ordre: string | null;
45
+ subdivision_libelle: string | null;
46
+ subdivision_libelle_court: string | null;
47
+ subdivision_type: string | null;
48
+ alinea: number | null;
49
+ date_depot: string;
50
+ dispositif: string | null;
51
+ objet: string | null;
52
+ etat_id: number;
53
+ avis_commission: string | null;
54
+ avis_gouvernement: string | null;
55
+ sort: string | null;
56
+ revision: string;
57
+ url: string;
58
+ au_nom_de_groupe_politique: string | null;
59
+ au_nom_de_commission: string | null;
60
+ auteur_est_gouvernement: boolean;
61
+ } & {
62
+ auteurs: {
63
+ prenom: string | null;
64
+ nom: string | null;
65
+ matricule: string | null;
66
+ }[];
67
+ }>;
68
+ export type AmendementResult = InferResult<typeof findAllQuery>[0];
69
+ export declare function findAll(): AsyncIterableIterator<{
70
+ session: string | null;
71
+ signet_dossier_legislatif: string | null;
72
+ nature_texte: string | null;
73
+ numero_texte: number | null;
74
+ intitule_texte: string | null;
75
+ lecture: string | null;
76
+ nature: string;
77
+ id: number;
78
+ parent_id: number | null;
79
+ numero: string | null;
80
+ numero_absolu: string | null;
81
+ ordre: string | null;
82
+ subdivision_libelle: string | null;
83
+ subdivision_libelle_court: string | null;
84
+ subdivision_type: string | null;
85
+ alinea: number | null;
86
+ date_depot: string;
87
+ dispositif: string | null;
88
+ objet: string | null;
89
+ etat_id: number;
90
+ avis_commission: string | null;
91
+ avis_gouvernement: string | null;
92
+ sort: string | null;
93
+ revision: string;
94
+ url: string;
95
+ au_nom_de_groupe_politique: string | null;
96
+ au_nom_de_commission: string | null;
97
+ auteur_est_gouvernement: boolean;
98
+ } & {
99
+ auteurs: {
100
+ prenom: string | null;
101
+ nom: string | null;
102
+ matricule: string | null;
103
+ }[];
104
+ }>;
105
+ export {};