@tricoteuses/senat 1.3.1 → 1.3.2

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 (253) hide show
  1. package/lib/config.d.ts +1 -0
  2. package/lib/config.js +14 -45
  3. package/lib/databases.js +86 -143
  4. package/lib/datasets.js +78 -83
  5. package/lib/index.d.ts +7 -4
  6. package/lib/index.js +42 -419
  7. package/lib/loaders.js +149 -654
  8. package/lib/model/ameli.js +83 -21
  9. package/lib/model/debats.js +0 -1
  10. package/lib/model/dosleg.d.ts +1 -1
  11. package/lib/model/dosleg.js +179 -73
  12. package/lib/model/index.d.ts +3 -3
  13. package/lib/model/index.js +12 -46
  14. package/lib/model/questions.js +68 -39
  15. package/lib/model/sens.js +383 -113
  16. package/lib/model/texte.js +220 -290
  17. package/lib/model/util.js +9 -26
  18. package/lib/raw_types/ameli.js +5 -6
  19. package/lib/raw_types/debats.js +5 -6
  20. package/lib/raw_types/dosleg.js +5 -6
  21. package/lib/raw_types/questions.js +5 -6
  22. package/lib/raw_types/sens.js +5 -6
  23. package/lib/raw_types_schemats/ameli.js +1 -43
  24. package/lib/raw_types_schemats/debats.js +1 -22
  25. package/lib/raw_types_schemats/dosleg.js +1 -96
  26. package/lib/raw_types_schemats/questions.js +1 -22
  27. package/lib/raw_types_schemats/sens.js +1 -112
  28. package/lib/scripts/convert_data.js +181 -631
  29. package/lib/scripts/datautil.js +17 -60
  30. package/lib/scripts/parse_textes.js +46 -129
  31. package/lib/scripts/retrieve_documents.js +247 -513
  32. package/lib/scripts/retrieve_open_data.js +211 -368
  33. package/lib/scripts/retrieve_senateurs_photos.js +144 -239
  34. package/lib/scripts/shared/cli_helpers.js +30 -30
  35. package/lib/scripts/shared/util.js +28 -94
  36. package/lib/strings.js +20 -45
  37. package/lib/types/ameli.d.ts +1 -1
  38. package/lib/types/ameli.js +14 -25
  39. package/lib/types/debats.d.ts +1 -1
  40. package/lib/types/debats.js +3 -21
  41. package/lib/types/dosleg.d.ts +1 -1
  42. package/lib/types/dosleg.js +152 -119
  43. package/lib/types/questions.d.ts +1 -1
  44. package/lib/types/questions.js +1 -13
  45. package/lib/types/sens.d.ts +1 -1
  46. package/lib/types/sens.js +1 -13
  47. package/lib/types/sessions.js +44 -49
  48. package/lib/types/texte.js +17 -22
  49. package/lib/validators/config.js +47 -111
  50. package/lib/validators/senat.js +1 -5
  51. package/package.json +16 -38
  52. package/lib/aggregates.d.ts +0 -52
  53. package/lib/aggregates.mjs +0 -930
  54. package/lib/aggregates.ts +0 -833
  55. package/lib/config.mjs +0 -16
  56. package/lib/config.ts +0 -26
  57. package/lib/data/legislatures.json +0 -38
  58. package/lib/databases.mjs +0 -57
  59. package/lib/databases.ts +0 -71
  60. package/lib/datasets.mjs +0 -78
  61. package/lib/datasets.ts +0 -118
  62. package/lib/fields.d.ts +0 -10
  63. package/lib/fields.mjs +0 -68
  64. package/lib/fields.ts +0 -29
  65. package/lib/index.mjs +0 -4
  66. package/lib/index.ts +0 -42
  67. package/lib/inserters.d.ts +0 -98
  68. package/lib/inserters.mjs +0 -500
  69. package/lib/inserters.ts +0 -521
  70. package/lib/loaders.mjs +0 -158
  71. package/lib/loaders.ts +0 -271
  72. package/lib/model/ameli.mjs +0 -84
  73. package/lib/model/ameli.ts +0 -100
  74. package/lib/model/debats.mjs +0 -1
  75. package/lib/model/debats.ts +0 -0
  76. package/lib/model/dosleg.mjs +0 -196
  77. package/lib/model/dosleg.ts +0 -240
  78. package/lib/model/index.mjs +0 -4
  79. package/lib/model/index.ts +0 -14
  80. package/lib/model/questions.mjs +0 -71
  81. package/lib/model/questions.ts +0 -93
  82. package/lib/model/sens.mjs +0 -415
  83. package/lib/model/sens.ts +0 -516
  84. package/lib/model/texte.mjs +0 -208
  85. package/lib/model/texte.ts +0 -229
  86. package/lib/model/util.mjs +0 -19
  87. package/lib/model/util.ts +0 -32
  88. package/lib/raw_types/ameli.mjs +0 -5
  89. package/lib/raw_types/ameli.ts +0 -951
  90. package/lib/raw_types/debats.mjs +0 -5
  91. package/lib/raw_types/debats.ts +0 -222
  92. package/lib/raw_types/dosleg.mjs +0 -5
  93. package/lib/raw_types/dosleg.ts +0 -3625
  94. package/lib/raw_types/questions.mjs +0 -5
  95. package/lib/raw_types/questions.ts +0 -427
  96. package/lib/raw_types/sens.mjs +0 -5
  97. package/lib/raw_types/sens.ts +0 -4499
  98. package/lib/raw_types_kysely/ameli.d.ts +0 -6
  99. package/lib/raw_types_kysely/ameli.mjs +0 -7
  100. package/lib/raw_types_kysely/ameli.ts +0 -6
  101. package/lib/raw_types_kysely/debats.d.ts +0 -6
  102. package/lib/raw_types_kysely/debats.mjs +0 -7
  103. package/lib/raw_types_kysely/debats.ts +0 -6
  104. package/lib/raw_types_kysely/dosleg.d.ts +0 -6
  105. package/lib/raw_types_kysely/dosleg.mjs +0 -7
  106. package/lib/raw_types_kysely/dosleg.ts +0 -6
  107. package/lib/raw_types_kysely/questions.d.ts +0 -6
  108. package/lib/raw_types_kysely/questions.mjs +0 -7
  109. package/lib/raw_types_kysely/questions.ts +0 -6
  110. package/lib/raw_types_kysely/sens.d.ts +0 -6
  111. package/lib/raw_types_kysely/sens.mjs +0 -7
  112. package/lib/raw_types_kysely/sens.ts +0 -6
  113. package/lib/raw_types_kysely/texte.d.ts +0 -45
  114. package/lib/raw_types_kysely/texte.mjs +0 -7
  115. package/lib/raw_types_kysely/texte.ts +0 -53
  116. package/lib/raw_types_schemats/ameli.mjs +0 -2
  117. package/lib/raw_types_schemats/ameli.ts +0 -601
  118. package/lib/raw_types_schemats/debats.mjs +0 -2
  119. package/lib/raw_types_schemats/debats.ts +0 -145
  120. package/lib/raw_types_schemats/dosleg.mjs +0 -2
  121. package/lib/raw_types_schemats/dosleg.ts +0 -2195
  122. package/lib/raw_types_schemats/questions.mjs +0 -2
  123. package/lib/raw_types_schemats/questions.ts +0 -251
  124. package/lib/raw_types_schemats/sens.mjs +0 -2
  125. package/lib/raw_types_schemats/sens.ts +0 -2907
  126. package/lib/scripts/convert_data.mjs +0 -181
  127. package/lib/scripts/convert_data.ts +0 -243
  128. package/lib/scripts/datautil.mjs +0 -16
  129. package/lib/scripts/datautil.ts +0 -19
  130. package/lib/scripts/images/transparent_150x192.jpg +0 -0
  131. package/lib/scripts/images/transparent_155x225.jpg +0 -0
  132. package/lib/scripts/parse_textes.mjs +0 -46
  133. package/lib/scripts/parse_textes.ts +0 -65
  134. package/lib/scripts/retrieve_documents.mjs +0 -249
  135. package/lib/scripts/retrieve_documents.ts +0 -298
  136. package/lib/scripts/retrieve_open_data.mjs +0 -217
  137. package/lib/scripts/retrieve_open_data.ts +0 -274
  138. package/lib/scripts/retrieve_senateurs_photos.mjs +0 -147
  139. package/lib/scripts/retrieve_senateurs_photos.ts +0 -177
  140. package/lib/scripts/retrieve_textes.d.ts +0 -1
  141. package/lib/scripts/retrieve_textes.mjs +0 -328
  142. package/lib/scripts/retrieve_textes.ts +0 -143
  143. package/lib/scripts/shared/cli_helpers.ts +0 -36
  144. package/lib/scripts/shared/util.ts +0 -33
  145. package/lib/src/aggregates.d.ts +0 -52
  146. package/lib/src/aggregates.mjs +0 -726
  147. package/lib/src/config.d.ts +0 -2
  148. package/lib/src/config.mjs +0 -16
  149. package/lib/src/databases.d.ts +0 -18
  150. package/lib/src/databases.mjs +0 -55
  151. package/lib/src/datasets.d.ts +0 -28
  152. package/lib/src/datasets.mjs +0 -78
  153. package/lib/src/fields.d.ts +0 -10
  154. package/lib/src/fields.mjs +0 -22
  155. package/lib/src/index.d.ts +0 -8
  156. package/lib/src/index.mjs +0 -7
  157. package/lib/src/inserters.d.ts +0 -98
  158. package/lib/src/inserters.mjs +0 -360
  159. package/lib/src/loaders.d.ts +0 -36
  160. package/lib/src/loaders.mjs +0 -107
  161. package/lib/src/model/ameli.d.ts +0 -4
  162. package/lib/src/model/ameli.js +0 -57
  163. package/lib/src/model/debats.d.ts +0 -4
  164. package/lib/src/model/debats.js +0 -43
  165. package/lib/src/model/dosleg.d.ts +0 -197
  166. package/lib/src/model/dosleg.js +0 -169
  167. package/lib/src/model/index.d.ts +0 -4
  168. package/lib/src/model/index.js +0 -4
  169. package/lib/src/model/questions.d.ts +0 -89
  170. package/lib/src/model/questions.js +0 -76
  171. package/lib/src/model/sens.d.ts +0 -390
  172. package/lib/src/model/sens.js +0 -339
  173. package/lib/src/model/texte.d.ts +0 -7
  174. package/lib/src/model/texte.js +0 -183
  175. package/lib/src/raw_types_kysely/ameli.d.ts +0 -915
  176. package/lib/src/raw_types_kysely/ameli.js +0 -5
  177. package/lib/src/raw_types_kysely/debats.d.ts +0 -207
  178. package/lib/src/raw_types_kysely/debats.js +0 -5
  179. package/lib/src/raw_types_kysely/dosleg.d.ts +0 -3532
  180. package/lib/src/raw_types_kysely/dosleg.js +0 -5
  181. package/lib/src/raw_types_kysely/questions.d.ts +0 -414
  182. package/lib/src/raw_types_kysely/questions.js +0 -5
  183. package/lib/src/raw_types_kysely/sens.d.ts +0 -4394
  184. package/lib/src/raw_types_kysely/sens.js +0 -5
  185. package/lib/src/raw_types_schemats/ameli.d.ts +0 -541
  186. package/lib/src/raw_types_schemats/ameli.js +0 -2
  187. package/lib/src/raw_types_schemats/debats.d.ts +0 -127
  188. package/lib/src/raw_types_schemats/debats.js +0 -2
  189. package/lib/src/raw_types_schemats/dosleg.d.ts +0 -2027
  190. package/lib/src/raw_types_schemats/dosleg.js +0 -2
  191. package/lib/src/raw_types_schemats/questions.d.ts +0 -231
  192. package/lib/src/raw_types_schemats/questions.js +0 -2
  193. package/lib/src/raw_types_schemats/sens.d.ts +0 -2709
  194. package/lib/src/raw_types_schemats/sens.js +0 -2
  195. package/lib/src/scripts/convert_data.d.ts +0 -1
  196. package/lib/src/scripts/convert_data.js +0 -95
  197. package/lib/src/scripts/datautil.d.ts +0 -5
  198. package/lib/src/scripts/datautil.js +0 -16
  199. package/lib/src/scripts/parse_textes.d.ts +0 -1
  200. package/lib/src/scripts/parse_textes.js +0 -47
  201. package/lib/src/scripts/retrieve_documents.d.ts +0 -1
  202. package/lib/src/scripts/retrieve_documents.js +0 -258
  203. package/lib/src/scripts/retrieve_open_data.d.ts +0 -1
  204. package/lib/src/scripts/retrieve_open_data.js +0 -214
  205. package/lib/src/scripts/retrieve_senateurs_photos.d.ts +0 -1
  206. package/lib/src/scripts/retrieve_senateurs_photos.js +0 -147
  207. package/lib/src/scripts/shared/cli_helpers.d.ts +0 -44
  208. package/lib/src/scripts/shared/cli_helpers.js +0 -32
  209. package/lib/src/scripts/shared/util.d.ts +0 -3
  210. package/lib/src/scripts/shared/util.js +0 -28
  211. package/lib/src/strings.d.ts +0 -1
  212. package/lib/src/strings.mjs +0 -18
  213. package/lib/src/types/ameli.d.ts +0 -10
  214. package/lib/src/types/ameli.js +0 -13
  215. package/lib/src/types/debats.d.ts +0 -4
  216. package/lib/src/types/debats.js +0 -2
  217. package/lib/src/types/dosleg.d.ts +0 -98
  218. package/lib/src/types/dosleg.js +0 -151
  219. package/lib/src/types/questions.d.ts +0 -2
  220. package/lib/src/types/questions.js +0 -1
  221. package/lib/src/types/sens.d.ts +0 -10
  222. package/lib/src/types/sens.js +0 -1
  223. package/lib/src/types/sessions.d.ts +0 -42
  224. package/lib/src/types/sessions.js +0 -43
  225. package/lib/src/types/texte.d.ts +0 -61
  226. package/lib/src/types/texte.js +0 -16
  227. package/lib/src/validators/config.d.ts +0 -1
  228. package/lib/src/validators/config.js +0 -54
  229. package/lib/src/validators/senat.d.ts +0 -0
  230. package/lib/src/validators/senat.js +0 -24
  231. package/lib/strings.mjs +0 -18
  232. package/lib/strings.ts +0 -26
  233. package/lib/types/ameli.mjs +0 -13
  234. package/lib/types/ameli.ts +0 -21
  235. package/lib/types/debats.mjs +0 -2
  236. package/lib/types/debats.ts +0 -6
  237. package/lib/types/dosleg.mjs +0 -151
  238. package/lib/types/dosleg.ts +0 -284
  239. package/lib/types/questions.mjs +0 -1
  240. package/lib/types/questions.ts +0 -3
  241. package/lib/types/sens.mjs +0 -1
  242. package/lib/types/sens.ts +0 -12
  243. package/lib/types/sessions.mjs +0 -43
  244. package/lib/types/sessions.ts +0 -42
  245. package/lib/types/texte.mjs +0 -16
  246. package/lib/types/texte.ts +0 -76
  247. package/lib/typings/windows-1252.d.js +0 -2
  248. package/lib/typings/windows-1252.d.mjs +0 -2
  249. package/lib/typings/windows-1252.d.ts +0 -11
  250. package/lib/validators/config.mjs +0 -54
  251. package/lib/validators/config.ts +0 -79
  252. package/lib/validators/senat.mjs +0 -24
  253. package/lib/validators/senat.ts +0 -26
package/lib/loaders.ts DELETED
@@ -1,271 +0,0 @@
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,84 +0,0 @@
1
- import { jsonArrayFrom } from "kysely/helpers/postgres";
2
- import { dbAmeli } from "../databases";
3
- import { concat, toDateString } from "./util";
4
- function auteurs(amendementId) {
5
- return jsonArrayFrom(dbAmeli.selectFrom("amdsen")
6
- .leftJoin("sen_ameli", "amdsen.senid", "sen_ameli.entid")
7
- .where("amdsen.amdid", "=", amendementId)
8
- .select([
9
- "amdsen.prenomuse as prenom",
10
- "amdsen.nomuse as nom",
11
- "sen_ameli.mat as matricule",
12
- ])
13
- .orderBy("amdsen.rng asc"));
14
- }
15
- const findAllQuery = dbAmeli
16
- .selectFrom("amd")
17
- .leftJoin("sub", "amd.subid", "sub.id")
18
- .leftJoin("typsub", "sub.typid", "typsub.id")
19
- .leftJoin("txt_ameli", "amd.txtid", "txt_ameli.id")
20
- .leftJoin("ses", "txt_ameli.sesdepid", "ses.id")
21
- .leftJoin("nat", "txt_ameli.natid", "nat.id")
22
- .leftJoin("lec_ameli", "txt_ameli.lecid", "lec_ameli.id")
23
- .leftJoin("avicom", "amd.avcid", "avicom.id")
24
- .leftJoin("avigvt", "amd.avgid", "avigvt.id")
25
- .leftJoin("sor", "amd.sorid", "sor.id")
26
- .leftJoin("irr", "amd.irrid", "irr.id")
27
- .leftJoin("grppol_ameli", "amd.nomentid", "grppol_ameli.entid")
28
- .leftJoin("com_ameli", "amd.nomentid", "com_ameli.entid")
29
- .leftJoin("cab", "amd.nomentid", "cab.entid")
30
- .select(({ eb, ref, val }) => [
31
- "ses.ann as session",
32
- "txt_ameli.doslegsignet as signet_dossier_legislatif",
33
- "nat.libcourt as nature_texte",
34
- "txt_ameli.numabs as numero_texte",
35
- "txt_ameli.int as intitule_texte",
36
- "lec_ameli.lib as lecture",
37
- eb.case()
38
- .when("amd.typ", "=", "A")
39
- .then(val("Amendement"))
40
- .when("amd.typ", "=", "M")
41
- .then(val("Motion"))
42
- .when("amd.typ", "=", "S")
43
- .then(val("Sous-amendement"))
44
- .else("'")
45
- .end()
46
- .as("nature"),
47
- "amd.id as id",
48
- "amd.amdperid as parent_id",
49
- "amd.num as numero",
50
- "amd.numabs as numero_absolu",
51
- "amd.ord as ordre",
52
- "sub.lib as subdivision_libelle",
53
- "sub.lic as subdivision_libelle_court",
54
- "typsub.lib as subdivision_type",
55
- "amd.alinea as alinea",
56
- toDateString(ref("amd.datdep")).as("date_depot"),
57
- eb.case()
58
- .when("amd.etaid", "=", 8)
59
- .then(val("Cet amendement a été retiré avant séance."))
60
- .else(ref("amd.dis"))
61
- .end()
62
- .as("dispositif"),
63
- "amd.obj as objet",
64
- "amd.etaid as etat_id",
65
- "avicom.lib as avis_commission",
66
- "avigvt.lib as avis_gouvernement",
67
- eb.fn.coalesce("sor.lib", "irr.libirr").as("sort"),
68
- "amd.rev as revision",
69
- concat(val("https://www.senat.fr/amendements/"), ref("ses.lil"), val("/"), ref("txt_ameli.numabs"), val("/Amdt_"), ref("amd.numabs"), val(".html")).as("url"),
70
- "grppol_ameli.lilcou as au_nom_de_groupe_politique",
71
- "com_ameli.lil as au_nom_de_commission",
72
- eb.case()
73
- .when("cab.entid", "is not", null)
74
- .then(true)
75
- .else(false)
76
- .end()
77
- .as("auteur_est_gouvernement"),
78
- ])
79
- .select(({ ref }) => [
80
- auteurs(ref("amd.id")).as("auteurs"),
81
- ]);
82
- export function findAll() {
83
- return findAllQuery.stream();
84
- }
@@ -1,100 +0,0 @@
1
- import { Expression, InferResult } from "kysely"
2
- import { jsonArrayFrom } from "kysely/helpers/postgres"
3
- import { dbAmeli } from "../databases"
4
- import { concat, toDateString } from "./util"
5
-
6
- function auteurs (amendementId: Expression<number>) {
7
- return jsonArrayFrom(
8
- dbAmeli.selectFrom("amdsen")
9
- .leftJoin("sen_ameli", "amdsen.senid", "sen_ameli.entid")
10
- .where("amdsen.amdid", "=", amendementId)
11
- .select([
12
- "amdsen.prenomuse as prenom",
13
- "amdsen.nomuse as nom",
14
- "sen_ameli.mat as matricule",
15
- ])
16
- .orderBy("amdsen.rng asc"),
17
- )
18
- }
19
-
20
- const findAllQuery = dbAmeli
21
- .selectFrom("amd")
22
- .leftJoin("sub", "amd.subid", "sub.id")
23
- .leftJoin("typsub", "sub.typid", "typsub.id")
24
- .leftJoin("txt_ameli", "amd.txtid", "txt_ameli.id")
25
- .leftJoin("ses", "txt_ameli.sesdepid", "ses.id")
26
- .leftJoin("nat", "txt_ameli.natid", "nat.id")
27
- .leftJoin("lec_ameli", "txt_ameli.lecid", "lec_ameli.id")
28
- .leftJoin("avicom", "amd.avcid", "avicom.id")
29
- .leftJoin("avigvt", "amd.avgid", "avigvt.id")
30
- .leftJoin("sor", "amd.sorid", "sor.id")
31
- .leftJoin("irr", "amd.irrid", "irr.id")
32
- .leftJoin("grppol_ameli", "amd.nomentid", "grppol_ameli.entid")
33
- .leftJoin("com_ameli", "amd.nomentid", "com_ameli.entid")
34
- .leftJoin("cab", "amd.nomentid", "cab.entid")
35
- .select(({ eb, ref, val }) => [
36
- "ses.ann as session",
37
- "txt_ameli.doslegsignet as signet_dossier_legislatif",
38
- "nat.libcourt as nature_texte",
39
- "txt_ameli.numabs as numero_texte",
40
- "txt_ameli.int as intitule_texte",
41
- "lec_ameli.lib as lecture",
42
- eb.case()
43
- .when("amd.typ", "=", "A")
44
- .then(val("Amendement"))
45
- .when("amd.typ", "=", "M")
46
- .then(val("Motion"))
47
- .when("amd.typ", "=", "S")
48
- .then(val("Sous-amendement"))
49
- .else("'")
50
- .end()
51
- .as("nature"),
52
- "amd.id as id",
53
- "amd.amdperid as parent_id",
54
- "amd.num as numero",
55
- "amd.numabs as numero_absolu",
56
- "amd.ord as ordre",
57
- "sub.lib as subdivision_libelle",
58
- "sub.lic as subdivision_libelle_court",
59
- "typsub.lib as subdivision_type",
60
- "amd.alinea as alinea",
61
- toDateString(ref("amd.datdep")).as("date_depot"),
62
- eb.case()
63
- .when("amd.etaid", "=", 8)
64
- .then(val("Cet amendement a été retiré avant séance."))
65
- .else(ref("amd.dis"))
66
- .end()
67
- .as("dispositif"),
68
- "amd.obj as objet",
69
- "amd.etaid as etat_id",
70
- "avicom.lib as avis_commission",
71
- "avigvt.lib as avis_gouvernement",
72
- eb.fn.coalesce("sor.lib", "irr.libirr").as("sort"),
73
- "amd.rev as revision",
74
- concat(
75
- val("https://www.senat.fr/amendements/"),
76
- ref("ses.lil"),
77
- val("/"),
78
- ref("txt_ameli.numabs"),
79
- val("/Amdt_"),
80
- ref("amd.numabs"),
81
- val(".html")
82
- ).as("url"),
83
- "grppol_ameli.lilcou as au_nom_de_groupe_politique",
84
- "com_ameli.lil as au_nom_de_commission",
85
- eb.case()
86
- .when("cab.entid", "is not", null)
87
- .then(true)
88
- .else(false)
89
- .end()
90
- .as("auteur_est_gouvernement"),
91
- ])
92
- .select(({ ref }) => [
93
- auteurs(ref("amd.id")).as("auteurs"),
94
- ])
95
-
96
- export type AmendementResult = InferResult<typeof findAllQuery>[0]
97
-
98
- export function findAll () {
99
- return findAllQuery.stream()
100
- }
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1,196 +0,0 @@
1
- import { sql } from "kysely";
2
- import { jsonArrayFrom } from "kysely/helpers/postgres";
3
- import { dbDosleg } from "../databases";
4
- import { concat, removeSubstring, rtrim, toDateString } from "./util";
5
- function orderOrdreOrigineTexte(expr) {
6
- return sql `array_position(array['0','2','1'], ${expr})`;
7
- }
8
- function datesSeances(lectureAssembleeId) {
9
- return jsonArrayFrom(dbDosleg.selectFrom("date_seance")
10
- .where("date_seance.lecidt", "=", lectureAssembleeId)
11
- .select(({ ref }) => [
12
- toDateString(ref("date_seance.date_s")).as("date"),
13
- ]));
14
- }
15
- function organismesRapport(rapportId) {
16
- return jsonArrayFrom(dbDosleg.selectFrom("org")
17
- .leftJoin("raporg", "raporg.orgcod", "org.orgcod")
18
- .where("raporg.rapcod", "=", rapportId)
19
- .select([
20
- "org.orgnom as libelle",
21
- ]));
22
- }
23
- function auteursRapport(rapportId) {
24
- return jsonArrayFrom(dbDosleg.selectFrom("auteur")
25
- .leftJoin("ecr", "ecr.autcod", "auteur.autcod")
26
- .where("ecr.rapcod", "=", rapportId)
27
- .select([
28
- "auteur.prenom as prenom",
29
- "auteur.nomuse as nom_usuel",
30
- "auteur.autmat as matricule",
31
- ])
32
- .orderBy("ecr.ecrnumtri", "asc"));
33
- }
34
- function rapports(lectureAssembleeId) {
35
- return jsonArrayFrom(dbDosleg.selectFrom("rap")
36
- .leftJoin("lecassrap", "lecassrap.rapcod", "rap.rapcod")
37
- .leftJoin("denrap", "denrap.coddenrap", "rap.coddenrap")
38
- .where("lecassrap.lecassidt", "=", lectureAssembleeId)
39
- .select(({ eb, ref, val }) => [
40
- "rap.rapnum as numero",
41
- rtrim(ref("denrap.libdenrap")).as("type_rapport"),
42
- eb.case()
43
- .when("rap.typurl", "=", "I")
44
- .then(concat(val("https://www.senat.fr/rap/"), rtrim(ref("rap.rapurl"))))
45
- .else(rtrim(ref("rap.rapurl")))
46
- .end()
47
- .as("url"),
48
- toDateString(ref("rap.date_depot")).as("date_depot"),
49
- auteursRapport(ref("rap.rapcod")).as("auteurs"),
50
- organismesRapport(ref("rap.rapcod")).as("organismes"),
51
- ]));
52
- }
53
- function auteursTexte(texteId) {
54
- return jsonArrayFrom(dbDosleg.selectFrom("auteur")
55
- .leftJoin("ecr", "ecr.autcod", "auteur.autcod")
56
- .where("ecr.texcod", "=", texteId)
57
- .select([
58
- "auteur.prenom as prenom",
59
- "auteur.nomuse as nom_usuel",
60
- "auteur.autmat as matricule",
61
- ])
62
- .orderBy("ecr.ecrnumtri", "asc"));
63
- }
64
- function textes(lectureAssembleeId) {
65
- return jsonArrayFrom(dbDosleg.selectFrom("texte")
66
- .leftJoin("oritxt", "oritxt.oritxtcod", "texte.oritxtcod")
67
- .leftJoin("typtxt", "typtxt.typtxtcod", "texte.typtxtcod")
68
- .where("texte.lecassidt", "=", lectureAssembleeId)
69
- .select(({ eb, ref, val }) => [
70
- "texte.texnum as numero",
71
- eb.case()
72
- .when("texte.typurl", "=", "I")
73
- .then(removeSubstring(ref("texte.texurl"), val(".html")))
74
- .else(null)
75
- .end()
76
- .as("id"),
77
- eb.case()
78
- .when("texte.typurl", "=", "I")
79
- .then(concat(val("https://www.senat.fr/leg/"), rtrim(ref("texte.texurl"))))
80
- .else(rtrim(ref("texte.texurl")))
81
- .end()
82
- .as("url"),
83
- rtrim(ref("oritxt.oritxtlib")).as("origine_texte"),
84
- rtrim(ref("typtxt.typtxtlib")).as("type_texte"),
85
- toDateString(ref("texte.txtoritxtdat")).as("date"),
86
- "sesann as session",
87
- auteursTexte(ref("texte.texcod")).as("auteurs"),
88
- ])
89
- .orderBy(({ ref }) => orderOrdreOrigineTexte(ref("oritxt.oriordre"))));
90
- }
91
- function lecturesAssemblee(lectureId) {
92
- return jsonArrayFrom(dbDosleg.selectFrom("lecass")
93
- .where("lecass.lecidt", "=", lectureId)
94
- .leftJoin("ass", "ass.codass", "lecass.codass")
95
- .leftJoin("org", "org.orgcod", "lecass.orgcod")
96
- .select(({ ref }) => [
97
- rtrim(ref("ass.libass")).as("assemblee"),
98
- "org.orgnom as libelle_organisme",
99
- "org.orgcod as code_organisme",
100
- "lecass.ordreass as ordre_lecture_assemblee",
101
- textes(ref("lecass.lecassidt")).as("textes"),
102
- rapports(ref("lecass.lecassidt")).as("rapports"),
103
- datesSeances(ref("lecass.lecassidt")).as("dates_seances"),
104
- ])
105
- .orderBy("lecass.ordreass", "asc"));
106
- }
107
- function lectures(loiId) {
108
- return jsonArrayFrom(dbDosleg.selectFrom("lecture")
109
- .leftJoin("typlec", "typlec.typleccod", "lecture.typleccod")
110
- .where("lecture.loicod", "=", loiId)
111
- .select(({ ref }) => [
112
- rtrim(ref("typlec.typleclib")).as("type_lecture"),
113
- rtrim(ref("lecture.leccom")).as("libelle"),
114
- "typlec.typlecord as ordre_lecture",
115
- lecturesAssemblee(ref("lecture.lecidt")).as("lectures_assemblee"),
116
- ])
117
- .orderBy("typlec.typlecord", "asc"));
118
- }
119
- function themes(loiId) {
120
- return jsonArrayFrom(dbDosleg.selectFrom("the")
121
- .leftJoin("loithe", "loithe.thecle", "the.thecle")
122
- .where("loithe.loicod", "=", loiId)
123
- .select([
124
- "the.thelib as libelle",
125
- ]));
126
- }
127
- const findAllQuery = dbDosleg
128
- .selectFrom("loi")
129
- .leftJoin("typloi", "typloi.typloicod", "loi.typloicod")
130
- .leftJoin("etaloi", "etaloi.etaloicod", "loi.etaloicod")
131
- .select(({ eb, ref, val }) => [
132
- "loi.signet as signet",
133
- concat(val("https://www.senat.fr/dossier-legislatif/"), ref("loi.signet"), val(".html")).as("url"),
134
- concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loitit"))).as("titre"),
135
- rtrim(ref("loi.loient")).as("titre_court"),
136
- rtrim(ref("typloi.groupe")).as("code_nature_dossier"),
137
- rtrim(ref("typloi.typloilib")).as("libelle_type_dossier"),
138
- rtrim(ref("etaloi.etaloilib")).as("etat_dossier"),
139
- "loi.url_an as url_dossier_assemblee_nationale",
140
- toDateString(ref("loi.date_decision")).as("date_decision_CoC"),
141
- "loi.num_decision as num_decision_CoC",
142
- "loi.deccocurl as url_decision_CoC",
143
- toDateString(ref("loi.saisine_date")).as("date_saisine_CoC"),
144
- "loi.saisine_par as condition_saisine_CoC",
145
- toDateString(ref("loi.date_loi")).as("date_promulgation"),
146
- "loi.numero as numero_loi",
147
- eb.case()
148
- .when("loi.loititjo", "is not", null)
149
- .then(concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loititjo"))))
150
- .else("")
151
- .end()
152
- .as("titre_JO"),
153
- toDateString(ref("loi.loidatjo")).as("date_publication_JO"),
154
- "loi.loinumjo as numero_JO",
155
- "loi.url_jo as url_JO",
156
- lectures(ref("loi.loicod")).as("lectures"),
157
- themes(ref("loi.loicod")).as("themes"),
158
- ])
159
- .$narrowType();
160
- export function findAll() {
161
- return findAllQuery.stream();
162
- }
163
- export function findSenatTexteUrls(sessions = []) {
164
- return dbDosleg
165
- .selectFrom("texte")
166
- .where("texurl", "is not", null)
167
- .where("typurl", "=", "I")
168
- .$if(sessions.length > 0, (qb) => qb
169
- .where("sesann", "in", sessions))
170
- .select(({ eb, ref }) => [
171
- "sesann as session",
172
- rtrim(ref("texurl")).as("url"),
173
- eb.case()
174
- .when("oritxtcod", "=", "1")
175
- .then(true)
176
- .else(false)
177
- .end()
178
- .as("hasExposeDesMotifs"),
179
- ])
180
- .$narrowType()
181
- .stream();
182
- }
183
- export function findSenatRapportUrls(sessions = []) {
184
- return dbDosleg
185
- .selectFrom("rap")
186
- .where("rapurl", "is not", null)
187
- .where("typurl", "=", "I")
188
- .$if(sessions.length > 0, (qb) => qb
189
- .where("sesann", "in", sessions))
190
- .select(({ ref }) => [
191
- rtrim(ref("rapurl")).as("url"),
192
- "sesann as session",
193
- ])
194
- .$narrowType()
195
- .stream();
196
- }