@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
@@ -1,558 +1,240 @@
1
- import {
2
- Ass, assFieldsToTrim,
3
- Aud, audFieldsToTrim,
4
- Auteur, auteurFieldsToTrim,
5
- DateSeance, dateSeanceFieldsToTrim,
6
- DecCoc, deccocFieldsToTrim,
7
- DenRap, denrapFieldsToTrim,
8
- DocAtt, docattFieldsToParseInt, docattFieldsToTrim,
9
- Ecr, ecrFieldsToTrim,
10
- EtaLoi, etaloiFieldsToTrim,
11
- LecAss, lecassFieldsToTrim,
12
- LecAssRap, lecassrapFieldsToTrim,
13
- Lecture, lectureFieldsToTrim,
14
- Loi, loiFieldsToTrim,
15
- Org, orgFieldsToTrim,
16
- OriTxt, oritxtFieldsToTrim,
17
- Qua, quaFieldsToTrim,
18
- Rap, rapFieldsToParseInt, rapFieldsToTrim,
19
- RapOrg, raporgFieldsToTrim,
20
- Scr, scrFieldsToTrim,
21
- Texte, texteFieldsToParseInt, texteFieldsToTrim,
22
- TypAtt, typattFieldsToTrim,
23
- TypLec, typlecFieldsToTrim,
24
- TypLoi, typloiFieldsToTrim,
25
- TypTxt, typtxtFieldsToTrim,
26
- TypUrl, typurlFieldsToTrim,
27
- } from '../types/dosleg'
28
- import { dbByName } from "../databases"
29
- import { parseIntFields, trimFieldsRight } from '../fields'
1
+ import { Expression, InferResult, NotNull, sql } from "kysely"
2
+ import { jsonArrayFrom } from "kysely/helpers/postgres"
30
3
 
31
- export const getAsss = async (ids: string[]): Promise<Ass[]> => {
32
- if (ids.length === 0) {
33
- return []
34
- }
35
- return (
36
- await dbByName.dosleg.any(
37
- `
38
- SELECT *
39
- FROM ass
40
- WHERE codass IN ($<ids:list>)
41
- `,
42
- {
43
- ids,
44
- },
45
- )
46
- ).map((ass: Ass) => trimFieldsRight(assFieldsToTrim, ass))
47
- }
4
+ import { dbDosleg } from "../databases"
5
+ import { concat, removeSubstring, rtrim, toDateString } from "./util"
48
6
 
49
- export const getAudsFromLecassidts = async (ids: string[]): Promise<Aud[]> => {
50
- if (ids.length === 0) {
51
- return []
52
- }
53
- return (
54
- await dbByName.dosleg.any(
55
- `
56
- SELECT *
57
- FROM aud
58
- WHERE lecassidt IN ($<ids:list>)
59
- `,
60
- {
61
- ids,
62
- },
63
- )
64
- ).map((aud: Aud) => trimFieldsRight(audFieldsToTrim, aud))
7
+ function orderOrdreOrigineTexte (expr: Expression<string | null | undefined>) {
8
+ return sql`array_position(array['0','2','1'], ${expr})`
65
9
  }
66
10
 
67
- export const getAuteurs = async (ids: string[]): Promise<Auteur[]> => {
68
- if (ids.length === 0) {
69
- return []
70
- }
71
- return (
72
- await dbByName.dosleg.any(
73
- `
74
- SELECT *
75
- FROM auteur
76
- WHERE autcod IN ($<ids:list>)
77
- `,
78
- {
79
- ids,
80
- },
81
- )
82
- ).map((auteur: Auteur) => trimFieldsRight(auteurFieldsToTrim, auteur))
83
- }
84
-
85
- export const getDatesSeancesFromLecassidts = async (
86
- ids: string[],
87
- ): Promise<DateSeance[]> => {
88
- if (ids.length === 0) {
89
- return []
90
- }
91
- return (
92
- await dbByName.dosleg.any(
93
- `
94
- SELECT *
95
- FROM date_seance
96
- WHERE lecidt IN ($<ids:list>)
97
- `,
98
- {
99
- ids,
100
- },
101
- )
102
- ).map((dateSeance: DateSeance) =>
103
- trimFieldsRight(dateSeanceFieldsToTrim, dateSeance),
11
+ function datesSeances (lectureAssembleeId: Expression<string>) {
12
+ return jsonArrayFrom(
13
+ dbDosleg.selectFrom("date_seance")
14
+ .where("date_seance.lecidt", "=", lectureAssembleeId)
15
+ .select(({ ref }) => [
16
+ toDateString(ref("date_seance.date_s")).as("date"),
17
+ ]),
104
18
  )
105
19
  }
106
20
 
107
- export const getDeccocs = async (ids: string[]): Promise<DecCoc[]> => {
108
- if (ids.length === 0) {
109
- return []
110
- }
111
- return (
112
- await dbByName.dosleg.any(
113
- `
114
- SELECT *
115
- FROM deccoc
116
- WHERE deccoccod IN ($<ids:list>)
117
- `,
118
- {
119
- ids,
120
- },
121
- )
122
- ).map((deccoc: DecCoc) => trimFieldsRight(deccocFieldsToTrim, deccoc))
123
- }
124
-
125
- export const getDenraps = async (ids: string[]): Promise<DenRap[]> => {
126
- if (ids.length === 0) {
127
- return []
128
- }
129
- return (
130
- await dbByName.dosleg.any(
131
- `
132
- SELECT *
133
- FROM denrap
134
- WHERE coddenrap IN ($<ids:list>)
135
- `,
136
- {
137
- ids,
138
- },
139
- )
140
- ).map((denrap: DenRap) => trimFieldsRight(denrapFieldsToTrim, denrap))
141
- }
142
-
143
- export const getDocattsFromRapcods = async (
144
- ids: string[],
145
- ): Promise<DocAtt[]> => {
146
- if (ids.length === 0) {
147
- return []
148
- }
149
- return (
150
- await dbByName.dosleg.any(
151
- `
152
- SELECT *
153
- FROM docatt
154
- WHERE rapcod IN($<ids:list>)
155
- `,
156
- {
157
- ids,
158
- },
159
- )
160
- ).map((docatt: DocAtt) =>
161
- parseIntFields(
162
- docattFieldsToParseInt,
163
- trimFieldsRight(docattFieldsToTrim, docatt),
164
- ),
21
+ function organismesRapport (rapportId: Expression<string>) {
22
+ return jsonArrayFrom(
23
+ dbDosleg.selectFrom("org")
24
+ .leftJoin("raporg", "raporg.orgcod", "org.orgcod")
25
+ .where("raporg.rapcod", "=", rapportId)
26
+ .select([
27
+ "org.orgnom as libelle",
28
+ ]),
165
29
  )
166
30
  }
167
31
 
168
- export const getEcrsFromRapcods = async (ids: string[]): Promise<Ecr[]> => {
169
- if (ids.length === 0) {
170
- return []
171
- }
172
- return (
173
- await dbByName.dosleg.any(
174
- `
175
- SELECT *
176
- FROM ecr
177
- WHERE rapcod IN($<ids:list>)
178
- `,
179
- {
180
- ids,
181
- },
182
- )
183
- ).map((ecr: Ecr) => trimFieldsRight(ecrFieldsToTrim, ecr))
184
- }
185
-
186
- export const getEcrsFromTexcods = async (ids: string[]): Promise<Ecr[]> => {
187
- if (ids.length === 0) {
188
- return []
189
- }
190
- return (
191
- await dbByName.dosleg.any(
192
- `
193
- SELECT *
194
- FROM ecr
195
- WHERE texcod IN($<ids:list>)
196
- `,
197
- {
198
- ids,
199
- },
200
- )
201
- ).map((ecr: Ecr) => trimFieldsRight(ecrFieldsToTrim, ecr))
202
- }
203
-
204
- export const getEtalois = async (ids: string[]): Promise<EtaLoi[]> => {
205
- if (ids.length === 0) {
206
- return []
207
- }
208
- return (
209
- await dbByName.dosleg.any(
210
- `
211
- SELECT *
212
- FROM etaloi
213
- WHERE etaloicod IN ($<ids:list>)
214
- `,
215
- {
216
- ids,
217
- },
218
- )
219
- ).map((etaloi: EtaLoi) => trimFieldsRight(etaloiFieldsToTrim, etaloi))
220
- }
221
-
222
- export const getLecasssFromLecidts = async (
223
- ids: string[],
224
- ): Promise<LecAss[]> => {
225
- if (ids.length === 0) {
226
- return []
227
- }
228
- return (
229
- await dbByName.dosleg.any(
230
- `
231
- SELECT *
232
- FROM lecass
233
- WHERE lecidt IN ($<ids:list>)
234
- `,
235
- {
236
- ids,
237
- },
238
- )
239
- ).map((lecass: LecAss) => trimFieldsRight(lecassFieldsToTrim, lecass))
240
- }
241
-
242
- export const getLecassrapsFromLecassidts = async (
243
- ids: string[],
244
- ): Promise<LecAssRap[]> => {
245
- if (ids.length === 0) {
246
- return []
247
- }
248
- return (
249
- await dbByName.dosleg.any(
250
- `
251
- SELECT *
252
- FROM lecassrap
253
- WHERE lecassidt IN ($<ids:list>)
254
- `,
255
- {
256
- ids,
257
- },
258
- )
259
- ).map((lecassrap: LecAssRap) =>
260
- trimFieldsRight(lecassrapFieldsToTrim, lecassrap),
32
+ function auteursRapport (rapportId: Expression<string>) {
33
+ return jsonArrayFrom(
34
+ dbDosleg.selectFrom("auteur")
35
+ .leftJoin("ecr", "ecr.autcod", "auteur.autcod")
36
+ .where("ecr.rapcod", "=", rapportId)
37
+ .select([
38
+ "auteur.prenom as prenom",
39
+ "auteur.nomuse as nom_usuel",
40
+ "auteur.autmat as matricule",
41
+ ])
42
+ .orderBy("ecr.ecrnumtri", "asc"),
261
43
  )
262
44
  }
263
45
 
264
- export const getLecturesFromLoicods = async (
265
- ids: string[],
266
- ): Promise<Lecture[]> => {
267
- if (ids.length === 0) {
268
- return []
269
- }
270
- return (
271
- await dbByName.dosleg.any(
272
- `
273
- SELECT *
274
- FROM lecture
275
- WHERE loicod IN ($<ids:list>)
276
- `,
277
- {
278
- ids,
279
- },
280
- )
281
- ).map((lecture: Lecture) => trimFieldsRight(lectureFieldsToTrim, lecture))
282
- }
283
-
284
- export const getLois = async (ids: string[]): Promise<Loi[]> => {
285
- if (ids.length === 0) {
286
- return []
287
- }
288
- return (
289
- await dbByName.dosleg.any(
290
- `
291
- SELECT *
292
- FROM loi
293
- WHERE loicod IN ($<ids:list>)
294
- `,
295
- {
296
- ids,
297
- },
298
- )
299
- ).map((loi: Loi) => trimFieldsRight(loiFieldsToTrim, loi))
300
- }
301
-
302
- export const getAllLois = async (): Promise<Loi[]> => {
303
- return (
304
- await dbByName.dosleg.any(
305
- `
306
- SELECT *
307
- FROM loi
308
- `
309
- )
310
- ).map((loi: Loi) => trimFieldsRight(loiFieldsToTrim, loi))
311
- }
312
-
313
- export const getOrgs = async (ids: string[]): Promise<Org[]> => {
314
- if (ids.length === 0) {
315
- return []
316
- }
317
- return (
318
- await dbByName.dosleg.any(
319
- `
320
- SELECT *
321
- FROM org
322
- WHERE orgcod IN ($<ids:list>)
323
- `,
324
- {
325
- ids,
326
- },
327
- )
328
- ).map((org: Org) => trimFieldsRight(orgFieldsToTrim, org))
329
- }
330
-
331
- export const getOrgsFromRapcods = async (ids: string[]): Promise<Org[]> => {
332
- if (ids.length === 0) {
333
- return []
334
- }
335
- return (
336
- await dbByName.dosleg.any(
337
- `
338
- SELECT *
339
- FROM org
340
- WHERE orgcod IN (
341
- SELECT orgcod
342
- FROM raporg
343
- WHERE rapcod IN ($<ids:list>)
344
- )
345
- `,
346
- {
347
- ids,
348
- },
349
- )
350
- ).map((org: Org) => trimFieldsRight(orgFieldsToTrim, org))
351
- }
352
-
353
- export const getRaporgsFromOrgcods = async (ids: string[]): Promise<RapOrg[]> => {
354
- if (ids.length === 0) {
355
- return []
356
- }
357
- return (
358
- await dbByName.dosleg.any(
359
- `
360
- SELECT *
361
- FROM raporg
362
- WHERE orgcod IN ($<ids:list>)
363
- `,
364
- {
365
- ids,
366
- },
367
- )
368
- ).map((raporg: RapOrg) => trimFieldsRight(raporgFieldsToTrim, raporg))
369
- }
370
-
371
- export const getOritxts = async (ids: string[]): Promise<OriTxt[]> => {
372
- if (ids.length === 0) {
373
- return []
374
- }
375
- return (
376
- await dbByName.dosleg.any(
377
- `
378
- SELECT *
379
- FROM oritxt
380
- WHERE oritxtcod IN ($<ids:list>)
381
- `,
382
- {
383
- ids,
384
- },
385
- )
386
- ).map((oritxt: OriTxt) => trimFieldsRight(oritxtFieldsToTrim, oritxt))
387
- }
388
-
389
- export const getQuas = async (ids: string[]): Promise<Qua[]> => {
390
- if (ids.length === 0) {
391
- return []
392
- }
393
- return (
394
- await dbByName.dosleg.any(
395
- `
396
- SELECT *
397
- FROM qua
398
- WHERE quacod IN ($<ids:list>)
399
- `,
400
- {
401
- ids,
402
- },
403
- )
404
- ).map((qua: Qua) => trimFieldsRight(quaFieldsToTrim, qua))
405
- }
406
-
407
- export const getRaps = async (ids: string[]): Promise<Rap[]> => {
408
- if (ids.length === 0) {
409
- return []
410
- }
411
- return (
412
- await dbByName.dosleg.any(
413
- `
414
- SELECT *
415
- FROM rap
416
- WHERE rapcod IN ($<ids:list>)
417
- `,
418
- {
419
- ids,
420
- },
421
- )
422
- ).map((rap: Rap) =>
423
- parseIntFields(rapFieldsToParseInt, trimFieldsRight(rapFieldsToTrim, rap)),
46
+ function rapports (lectureAssembleeId: Expression<string>) {
47
+ return jsonArrayFrom(
48
+ dbDosleg.selectFrom("rap")
49
+ .leftJoin("lecassrap", "lecassrap.rapcod", "rap.rapcod")
50
+ .leftJoin("denrap", "denrap.coddenrap", "rap.coddenrap")
51
+ .where("lecassrap.lecassidt", "=", lectureAssembleeId)
52
+ .select(({ eb, ref, val }) => [
53
+ "rap.rapnum as numero",
54
+ rtrim(ref("denrap.libdenrap")).as("type_rapport"),
55
+ eb.case()
56
+ .when("rap.typurl", "=", "I")
57
+ .then(concat(val("https://www.senat.fr/rap/"), rtrim(ref("rap.rapurl"))))
58
+ .else(rtrim(ref("rap.rapurl")))
59
+ .end()
60
+ .as("url"),
61
+ toDateString(ref("rap.date_depot")).as("date_depot"),
62
+ auteursRapport(ref("rap.rapcod")).as("auteurs"),
63
+ organismesRapport(ref("rap.rapcod")).as("organismes"),
64
+ ]),
424
65
  )
425
66
  }
426
67
 
427
- export const getScrsFromCodes = async (ids: string[]): Promise<Scr[]> => {
428
- if (ids.length === 0) {
429
- return []
430
- }
431
- return (
432
- await dbByName.dosleg.any(
433
- `
434
- SELECT *
435
- FROM scr
436
- WHERE code IN ($<ids:list>)
437
- `,
438
- {
439
- ids,
440
- },
441
- )
442
- ).map((scr: Scr) => trimFieldsRight(scrFieldsToTrim, scr))
443
- }
444
-
445
- export const getTextesFromLecassidts = async (
446
- ids: string[],
447
- ): Promise<Texte[]> => {
448
- if (ids.length === 0) {
449
- return []
450
- }
451
- return (
452
- await dbByName.dosleg.any(
453
- `
454
- SELECT *
455
- FROM texte
456
- WHERE lecassidt IN ($<ids:list>)
457
- `,
458
- {
459
- ids,
460
- },
461
- )
462
- ).map((texte: Texte) =>
463
- parseIntFields(
464
- texteFieldsToParseInt,
465
- trimFieldsRight(texteFieldsToTrim, texte),
466
- ),
68
+ function auteursTexte (texteId: Expression<string>) {
69
+ return jsonArrayFrom(
70
+ dbDosleg.selectFrom("auteur")
71
+ .leftJoin("ecr", "ecr.autcod", "auteur.autcod")
72
+ .where("ecr.texcod", "=", texteId)
73
+ .select([
74
+ "auteur.prenom as prenom",
75
+ "auteur.nomuse as nom_usuel",
76
+ "auteur.autmat as matricule",
77
+ ])
78
+ .orderBy("ecr.ecrnumtri", "asc"),
467
79
  )
468
80
  }
469
81
 
470
- export const getTypatts = async (ids: string[]): Promise<TypAtt[]> => {
471
- if (ids.length === 0) {
472
- return []
473
- }
474
- return (
475
- await dbByName.dosleg.any(
476
- `
477
- SELECT *
478
- FROM typatt
479
- WHERE typattcod IN ($<ids:list>)
480
- `,
481
- {
482
- ids,
483
- },
484
- )
485
- ).map((typatt: TypAtt) => trimFieldsRight(typattFieldsToTrim, typatt))
82
+ function textes (lectureAssembleeId: Expression<string>) {
83
+ return jsonArrayFrom(
84
+ dbDosleg.selectFrom("texte")
85
+ .leftJoin("oritxt", "oritxt.oritxtcod", "texte.oritxtcod")
86
+ .leftJoin("typtxt", "typtxt.typtxtcod", "texte.typtxtcod")
87
+ .where("texte.lecassidt", "=", lectureAssembleeId)
88
+ .select(({ eb, ref, val }) => [
89
+ "texte.texnum as numero",
90
+ eb.case()
91
+ .when("texte.typurl", "=", "I")
92
+ .then(removeSubstring(ref("texte.texurl"), val(".html")))
93
+ .else(null)
94
+ .end()
95
+ .as("id"),
96
+ eb.case()
97
+ .when("texte.typurl", "=", "I")
98
+ .then(concat(val("https://www.senat.fr/leg/"), rtrim(ref("texte.texurl"))))
99
+ .else(rtrim(ref("texte.texurl")))
100
+ .end()
101
+ .as("url"),
102
+ rtrim(ref("oritxt.oritxtlib")).as("origine_texte"),
103
+ rtrim(ref("typtxt.typtxtlib")).as("type_texte"),
104
+ toDateString(ref("texte.txtoritxtdat")).as("date"),
105
+ "sesann as session",
106
+ auteursTexte(ref("texte.texcod")).as("auteurs"),
107
+ ])
108
+ .orderBy(({ ref }) => orderOrdreOrigineTexte(ref("oritxt.oriordre")))
109
+ )
486
110
  }
487
111
 
488
- export const getTyplecs = async (ids: string[]): Promise<TypLec[]> => {
489
- if (ids.length === 0) {
490
- return []
491
- }
492
- return (
493
- await dbByName.dosleg.any(
494
- `
495
- SELECT *
496
- FROM typlec
497
- WHERE typleccod IN ($<ids:list>)
498
- `,
499
- {
500
- ids,
501
- },
502
- )
503
- ).map((typlec: TypLec) => trimFieldsRight(typlecFieldsToTrim, typlec))
112
+ function lecturesAssemblee (lectureId: Expression<string>) {
113
+ return jsonArrayFrom(
114
+ dbDosleg.selectFrom("lecass")
115
+ .where("lecass.lecidt", "=", lectureId)
116
+ .leftJoin("ass", "ass.codass", "lecass.codass")
117
+ .leftJoin("org", "org.orgcod", "lecass.orgcod")
118
+ .select(({ ref }) => [
119
+ rtrim(ref("ass.libass")).as("assemblee"),
120
+ "org.orgnom as libelle_organisme",
121
+ "org.orgcod as code_organisme",
122
+ "lecass.ordreass as ordre_lecture_assemblee",
123
+ textes(ref("lecass.lecassidt")).as("textes"),
124
+ rapports(ref("lecass.lecassidt")).as("rapports"),
125
+ datesSeances(ref("lecass.lecassidt")).as("dates_seances"),
126
+ ])
127
+ .orderBy("lecass.ordreass", "asc"),
128
+ )
504
129
  }
505
130
 
506
- export const getTyplois = async (ids: string[]): Promise<TypLoi[]> => {
507
- if (ids.length === 0) {
508
- return []
509
- }
510
- return (
511
- await dbByName.dosleg.any(
512
- `
513
- SELECT *
514
- FROM typloi
515
- WHERE typloicod IN ($<ids:list>)
516
- `,
517
- {
518
- ids,
519
- },
520
- )
521
- ).map((typloi: TypLoi) => trimFieldsRight(typloiFieldsToTrim, typloi))
131
+ function lectures (loiId: Expression<string>) {
132
+ return jsonArrayFrom(
133
+ dbDosleg.selectFrom("lecture")
134
+ .leftJoin("typlec", "typlec.typleccod", "lecture.typleccod")
135
+ .where("lecture.loicod", "=", loiId)
136
+ .select(({ ref }) => [
137
+ rtrim(ref("typlec.typleclib")).as("type_lecture"),
138
+ rtrim(ref("lecture.leccom")).as("libelle"),
139
+ "typlec.typlecord as ordre_lecture",
140
+ lecturesAssemblee(ref("lecture.lecidt")).as("lectures_assemblee"),
141
+ ])
142
+ .orderBy("typlec.typlecord", "asc"),
143
+ )
522
144
  }
523
145
 
524
- export const getTyptxts = async (ids: string[]): Promise<TypTxt[]> => {
525
- if (ids.length === 0) {
526
- return []
527
- }
528
- return (
529
- await dbByName.dosleg.any(
530
- `
531
- SELECT *
532
- FROM typtxt
533
- WHERE typtxtcod IN ($<ids:list>)
534
- `,
535
- {
536
- ids,
537
- },
538
- )
539
- ).map((typtxt: TypTxt) => trimFieldsRight(typtxtFieldsToTrim, typtxt))
146
+ function themes (loiId: Expression<string>) {
147
+ return jsonArrayFrom(
148
+ dbDosleg.selectFrom("the")
149
+ .leftJoin("loithe", "loithe.thecle", "the.thecle")
150
+ .where("loithe.loicod", "=", loiId)
151
+ .select([
152
+ "the.thelib as libelle",
153
+ ]),
154
+ )
540
155
  }
541
156
 
542
- export const getTypurls = async (ids: string[]): Promise<TypUrl[]> => {
543
- if (ids.length === 0) {
544
- return []
545
- }
546
- return (
547
- await dbByName.dosleg.any(
548
- `
549
- SELECT *
550
- FROM typurl
551
- WHERE typurl IN ($<ids:list>)
552
- `,
553
- {
554
- ids,
555
- },
556
- )
557
- ).map((typurl: TypUrl) => trimFieldsRight(typurlFieldsToTrim, typurl))
558
- }
157
+ const findAllQuery = dbDosleg
158
+ .selectFrom("loi")
159
+ .leftJoin("typloi", "typloi.typloicod", "loi.typloicod")
160
+ .leftJoin("etaloi", "etaloi.etaloicod", "loi.etaloicod")
161
+ .select(({ eb, ref, val }) => [
162
+ "loi.signet as signet",
163
+ concat(val("https://www.senat.fr/dossier-legislatif/"), ref("loi.signet"), val(".html")).as("url"),
164
+ concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loitit"))).as("titre"),
165
+ rtrim(ref("loi.loient")).as("titre_court"),
166
+ rtrim(ref("typloi.groupe")).as("code_nature_dossier"),
167
+ rtrim(ref("typloi.typloilib")).as("libelle_type_dossier"),
168
+ rtrim(ref("etaloi.etaloilib")).as("etat_dossier"),
169
+ "loi.url_an as url_dossier_assemblee_nationale",
170
+ toDateString(ref("loi.date_decision")).as("date_decision_CoC"),
171
+ "loi.num_decision as num_decision_CoC",
172
+ "loi.deccocurl as url_decision_CoC",
173
+ toDateString(ref("loi.saisine_date")).as("date_saisine_CoC"),
174
+ "loi.saisine_par as condition_saisine_CoC",
175
+ toDateString(ref("loi.date_loi")).as("date_promulgation"),
176
+ "loi.numero as numero_loi",
177
+ eb.case()
178
+ .when("loi.loititjo", "is not", null)
179
+ .then(concat(rtrim(ref("typloi.typloiden")), val(" "), rtrim(ref("loi.loititjo"))))
180
+ .else("")
181
+ .end()
182
+ .as("titre_JO"),
183
+ toDateString(ref("loi.loidatjo")).as("date_publication_JO"),
184
+ "loi.loinumjo as numero_JO",
185
+ "loi.url_jo as url_JO",
186
+ lectures(ref("loi.loicod")).as("lectures"),
187
+ themes(ref("loi.loicod")).as("themes"),
188
+ ])
189
+ .$narrowType<{ signet: NotNull }>()
190
+
191
+ export function findAll () {
192
+ return findAllQuery.stream()
193
+ }
194
+
195
+ export function findSenatTexteUrls (sessions: string[] = []): AsyncIterableIterator<{
196
+ session: string | null | undefined,
197
+ url: string,
198
+ hasExposeDesMotifs: boolean,
199
+ }> {
200
+ return dbDosleg
201
+ .selectFrom("texte")
202
+ .where("texurl", "is not", null)
203
+ .where("typurl", "=", "I")
204
+ .$if(sessions.length > 0, (qb) => qb
205
+ .where("sesann", "in", sessions),
206
+ )
207
+ .select(({ eb, ref }) => [
208
+ "sesann as session",
209
+ rtrim(ref("texurl")).as("url"),
210
+ eb.case()
211
+ .when("oritxtcod", "=", "1")
212
+ .then(true)
213
+ .else(false)
214
+ .end()
215
+ .as("hasExposeDesMotifs"),
216
+ ])
217
+ .$narrowType<{ url: NotNull }>()
218
+ .stream()
219
+ }
220
+
221
+ export function findSenatRapportUrls (sessions: string[] = []): AsyncIterableIterator<{
222
+ url: string,
223
+ session: string | null | undefined
224
+ }> {
225
+ return dbDosleg
226
+ .selectFrom("rap")
227
+ .where("rapurl", "is not", null)
228
+ .where("typurl", "=", "I")
229
+ .$if(sessions.length > 0, (qb) => qb
230
+ .where("sesann", "in", sessions),
231
+ )
232
+ .select(({ ref }) => [
233
+ rtrim(ref("rapurl")).as("url"),
234
+ "sesann as session",
235
+ ])
236
+ .$narrowType<{ url: NotNull }>()
237
+ .stream()
238
+ }
239
+
240
+ export type DossierLegislatifResult = InferResult<typeof findAllQuery>[0]