@tricoteuses/senat 3.1.2 → 3.1.4

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 (87) hide show
  1. package/lib/src/rich_types/dosleg.js +13 -3
  2. package/lib/src/rich_types/sens.d.ts +2 -0
  3. package/lib/src/scripts/data-download.js +16 -9
  4. package/lib/src/scripts/retrieve_open_data.js +4 -2
  5. package/lib/src/scripts/shared/make_generate_zod_schemas.js +6 -2
  6. package/lib/src/server/databases_postgres.js +2 -1
  7. package/lib/src/server/documents.js +2 -2
  8. package/lib/src/server/dosleg.js +2 -2
  9. package/lib/src/server/sens.js +70 -0
  10. package/lib/src/utils/reunion_parsing.js +1 -1
  11. package/package.json +3 -1
  12. package/lib/src/config.d.ts +0 -43
  13. package/lib/src/config.js +0 -37
  14. package/lib/src/conversion_textes.d.ts +0 -11
  15. package/lib/src/conversion_textes.js +0 -320
  16. package/lib/src/databases_postgres.d.ts +0 -4
  17. package/lib/src/databases_postgres.js +0 -23
  18. package/lib/src/datasets.d.ts +0 -38
  19. package/lib/src/datasets.js +0 -247
  20. package/lib/src/git.d.ts +0 -27
  21. package/lib/src/git.js +0 -251
  22. package/lib/src/loaders.d.ts +0 -52
  23. package/lib/src/loaders.js +0 -260
  24. package/lib/src/model/agenda.d.ts +0 -6
  25. package/lib/src/model/agenda.js +0 -148
  26. package/lib/src/model/ameli.d.ts +0 -67
  27. package/lib/src/model/ameli.js +0 -150
  28. package/lib/src/model/commission.d.ts +0 -19
  29. package/lib/src/model/commission.js +0 -269
  30. package/lib/src/model/debats.d.ts +0 -39
  31. package/lib/src/model/debats.js +0 -112
  32. package/lib/src/model/documents.d.ts +0 -32
  33. package/lib/src/model/documents.js +0 -182
  34. package/lib/src/model/dosleg.d.ts +0 -144
  35. package/lib/src/model/dosleg.js +0 -468
  36. package/lib/src/model/index.d.ts +0 -7
  37. package/lib/src/model/index.js +0 -7
  38. package/lib/src/model/questions.d.ts +0 -54
  39. package/lib/src/model/questions.js +0 -91
  40. package/lib/src/model/scrutins.d.ts +0 -48
  41. package/lib/src/model/scrutins.js +0 -121
  42. package/lib/src/model/seance.d.ts +0 -3
  43. package/lib/src/model/seance.js +0 -267
  44. package/lib/src/model/sens.d.ts +0 -112
  45. package/lib/src/model/sens.js +0 -385
  46. package/lib/src/model/util.d.ts +0 -1
  47. package/lib/src/model/util.js +0 -15
  48. package/lib/src/raw_types/ameli.d.ts +0 -1762
  49. package/lib/src/raw_types/ameli.js +0 -1074
  50. package/lib/src/raw_types/debats.d.ts +0 -380
  51. package/lib/src/raw_types/debats.js +0 -266
  52. package/lib/src/raw_types/dosleg.d.ts +0 -2954
  53. package/lib/src/raw_types/dosleg.js +0 -2005
  54. package/lib/src/raw_types/questions.d.ts +0 -699
  55. package/lib/src/raw_types/questions.js +0 -493
  56. package/lib/src/raw_types/sens.d.ts +0 -7843
  57. package/lib/src/raw_types/sens.js +0 -4691
  58. package/lib/src/raw_types_schemats/ameli.d.ts +0 -541
  59. package/lib/src/raw_types_schemats/ameli.js +0 -2
  60. package/lib/src/raw_types_schemats/debats.d.ts +0 -127
  61. package/lib/src/raw_types_schemats/debats.js +0 -2
  62. package/lib/src/raw_types_schemats/dosleg.d.ts +0 -977
  63. package/lib/src/raw_types_schemats/dosleg.js +0 -2
  64. package/lib/src/raw_types_schemats/questions.d.ts +0 -237
  65. package/lib/src/raw_types_schemats/questions.js +0 -2
  66. package/lib/src/raw_types_schemats/sens.d.ts +0 -2709
  67. package/lib/src/raw_types_schemats/sens.js +0 -2
  68. package/lib/src/types/agenda.d.ts +0 -45
  69. package/lib/src/types/agenda.js +0 -1
  70. package/lib/src/types/ameli.d.ts +0 -5
  71. package/lib/src/types/ameli.js +0 -1
  72. package/lib/src/types/compte_rendu.d.ts +0 -83
  73. package/lib/src/types/compte_rendu.js +0 -1
  74. package/lib/src/types/debats.d.ts +0 -2
  75. package/lib/src/types/debats.js +0 -1
  76. package/lib/src/types/dosleg.d.ts +0 -70
  77. package/lib/src/types/dosleg.js +0 -1
  78. package/lib/src/types/questions.d.ts +0 -2
  79. package/lib/src/types/questions.js +0 -1
  80. package/lib/src/types/sens.d.ts +0 -8
  81. package/lib/src/types/sens.js +0 -1
  82. package/lib/src/types/sessions.d.ts +0 -6
  83. package/lib/src/types/sessions.js +0 -19
  84. package/lib/src/types/texte.d.ts +0 -72
  85. package/lib/src/types/texte.js +0 -15
  86. package/lib/src/validators/config.d.ts +0 -9
  87. package/lib/src/validators/config.js +0 -10
package/lib/src/git.js DELETED
@@ -1,251 +0,0 @@
1
- import { execSync } from "node:child_process";
2
- import fs from "fs-extra";
3
- import path from "node:path";
4
- const MAXBUFFER = 50 * 1024 * 1024;
5
- const GIT_LOCK_RETRY_DELAY_MS = 1000;
6
- const GIT_LOCK_RETRY_COUNT = 5;
7
- const GIT_LOCK_STALE_AFTER_MS = 2 * 60 * 1000;
8
- function asExecSyncError(error) {
9
- return error;
10
- }
11
- function outputToString(output) {
12
- if (output == null) {
13
- return "";
14
- }
15
- return Buffer.isBuffer(output) ? output.toString("utf-8") : output;
16
- }
17
- function sleep(ms) {
18
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
19
- }
20
- function getIndexLockPath(repositoryDir) {
21
- return path.join(repositoryDir, ".git", "index.lock");
22
- }
23
- function isIndexLockError(error) {
24
- const stderr = error instanceof Error ? outputToString(asExecSyncError(error).stderr) : "";
25
- return /index\.lock': File exists\./.test(stderr);
26
- }
27
- function removeStaleIndexLock(repositoryDir) {
28
- const lockPath = getIndexLockPath(repositoryDir);
29
- if (!fs.existsSync(lockPath)) {
30
- return false;
31
- }
32
- const stats = fs.statSync(lockPath);
33
- const ageMs = Date.now() - stats.mtimeMs;
34
- if (ageMs < GIT_LOCK_STALE_AFTER_MS) {
35
- return false;
36
- }
37
- fs.removeSync(lockPath);
38
- return true;
39
- }
40
- function execGitWithIndexLockRecovery(command, repositoryDir, options) {
41
- let lockRemoved = false;
42
- for (let attempt = 1; attempt <= GIT_LOCK_RETRY_COUNT; attempt++) {
43
- try {
44
- execSync(command, {
45
- cwd: repositoryDir,
46
- ...options,
47
- });
48
- return;
49
- }
50
- catch (error) {
51
- if (!isIndexLockError(error)) {
52
- throw error;
53
- }
54
- if (!lockRemoved && removeStaleIndexLock(repositoryDir)) {
55
- lockRemoved = true;
56
- continue;
57
- }
58
- if (attempt === GIT_LOCK_RETRY_COUNT) {
59
- throw error;
60
- }
61
- sleep(GIT_LOCK_RETRY_DELAY_MS);
62
- }
63
- }
64
- }
65
- export function initRepo(repositoryDir) {
66
- if (!fs.existsSync(path.join(repositoryDir, ".git"))) {
67
- fs.ensureDirSync(repositoryDir);
68
- execSync("git init", {
69
- cwd: repositoryDir,
70
- env: process.env,
71
- encoding: "utf-8",
72
- stdio: ["ignore", "ignore", "pipe"],
73
- });
74
- }
75
- }
76
- export function commit(repositoryDir, message) {
77
- initRepo(repositoryDir);
78
- execGitWithIndexLockRecovery("git add .", repositoryDir, {
79
- env: process.env,
80
- encoding: "utf-8",
81
- stdio: ["ignore", "ignore", "pipe"],
82
- maxBuffer: MAXBUFFER,
83
- });
84
- try {
85
- execSync(`git commit -m "${message}" --quiet`, {
86
- cwd: repositoryDir,
87
- env: process.env,
88
- encoding: "utf-8",
89
- stdio: ["ignore", "pipe", "pipe"],
90
- });
91
- return true;
92
- }
93
- catch (error) {
94
- const childProcess = asExecSyncError(error);
95
- if (childProcess.stdout === null || !/nothing to commit|rien à valider/.test(outputToString(childProcess.stdout))) {
96
- console.error(childProcess.output);
97
- throw childProcess;
98
- }
99
- return false;
100
- }
101
- }
102
- export function commitAndPush(repositoryDir, message, remotes) {
103
- let exitCode = 0;
104
- if (commit(repositoryDir, message)) {
105
- for (const remote of remotes || []) {
106
- try {
107
- execSync(`git push ${remote} master`, {
108
- cwd: repositoryDir,
109
- env: process.env,
110
- encoding: "utf-8",
111
- stdio: ["ignore", "ignore", "pipe"],
112
- });
113
- }
114
- catch (error) {
115
- const childProcess = asExecSyncError(error);
116
- // Don't stop when push fails.
117
- console.error(childProcess.output);
118
- exitCode = childProcess.status ?? 1;
119
- }
120
- }
121
- }
122
- else {
123
- // There was nothing to commit.
124
- exitCode = 10;
125
- }
126
- return exitCode;
127
- }
128
- export function pull(repositoryDir, remote = "origin", branch = "master") {
129
- initRepo(repositoryDir);
130
- const statusOutput = execSync("git status --porcelain", {
131
- cwd: repositoryDir,
132
- env: process.env,
133
- encoding: "utf-8",
134
- stdio: ["ignore", "pipe", "pipe"],
135
- maxBuffer: MAXBUFFER,
136
- }).trim();
137
- if (statusOutput.length > 0) {
138
- return false;
139
- }
140
- execSync(`git pull --rebase ${remote} ${branch}`, {
141
- cwd: repositoryDir,
142
- env: process.env,
143
- encoding: "utf-8",
144
- stdio: ["ignore", "ignore", "pipe"],
145
- maxBuffer: MAXBUFFER,
146
- });
147
- return true;
148
- }
149
- export function resetAndPull(gitDir) {
150
- execSync("git reset --hard origin/master", {
151
- cwd: gitDir,
152
- env: process.env,
153
- encoding: "utf-8",
154
- stdio: ["ignore", "ignore", "pipe"],
155
- });
156
- execSync("git pull --rebase", {
157
- cwd: gitDir,
158
- env: process.env,
159
- encoding: "utf-8",
160
- stdio: ["ignore", "ignore", "pipe"],
161
- });
162
- return true;
163
- }
164
- export function clone(gitGroupUrl, gitName, workingDir) {
165
- if (gitGroupUrl !== undefined) {
166
- execSync(`git clone ${gitGroupUrl}/${gitName}.git`, {
167
- cwd: workingDir,
168
- env: process.env,
169
- encoding: "utf-8",
170
- stdio: ["ignore", "ignore", "pipe"],
171
- });
172
- }
173
- }
174
- export function run(repositoryDir, args, verbose) {
175
- try {
176
- if (verbose)
177
- console.log(`git -C ${repositoryDir} ${args}`);
178
- const output = execSync(`git ${args}`, {
179
- cwd: repositoryDir,
180
- maxBuffer: MAXBUFFER,
181
- })
182
- .toString()
183
- .trim();
184
- if (verbose)
185
- console.log(output);
186
- return output;
187
- }
188
- catch (error) {
189
- const childProcess = asExecSyncError(error);
190
- for (const output of ["stdout", "stderr"]) {
191
- console.error(`${output}: ${outputToString(childProcess[output])}`);
192
- }
193
- throw childProcess;
194
- }
195
- }
196
- export function test(repositoryDir, args, verbose) {
197
- try {
198
- if (verbose)
199
- console.log(`git -C ${repositoryDir} ${args}`);
200
- const output = execSync(`git ${args}`, {
201
- cwd: repositoryDir,
202
- stdio: ["ignore", "pipe", "pipe"],
203
- maxBuffer: MAXBUFFER,
204
- })
205
- .toString()
206
- .trim();
207
- if (verbose)
208
- console.log(output);
209
- return true;
210
- }
211
- catch (error) {
212
- const childProcess = asExecSyncError(error);
213
- if (childProcess.status !== 0)
214
- return false;
215
- throw childProcess;
216
- }
217
- }
218
- /**
219
- * Get the list of files that have changed since a specific commit in a git repository.
220
- * @param repositoryDir The directory of the git repository
221
- * @param sinceCommit The commit hash to compare against (e.g., "HEAD~1", "abc123", etc.)
222
- * @param options Options for filtering
223
- * @param options.diffFilter Git diff-filter string (default: "AMR").
224
- * A=Added, M=Modified, D=Deleted, R=Renamed, C=Copied, T=Type changed, U=Unmerged
225
- * @returns A Map of file paths to their git status
226
- */
227
- export function getChangedFilesSinceCommit(repositoryDir, sinceCommit, options = {}) {
228
- const { diffFilter } = options;
229
- try {
230
- // Using diff-filter: A = Added, M = Modified, R = Renamed, D = Deleted, etc.
231
- // Default to AMR (excludes deleted files to prevent loading errors)
232
- const filter = diffFilter ?? "AMR";
233
- const output = run(repositoryDir, `diff --name-status --diff-filter=${filter} ${sinceCommit}`, false);
234
- const changedFiles = new Map();
235
- for (const line of output.split("\n")) {
236
- if (line.trim().length === 0)
237
- continue;
238
- const parts = line.split("\t");
239
- if (parts.length >= 2) {
240
- const status = parts[0].charAt(0);
241
- const path = parts[1];
242
- changedFiles.set(path, status);
243
- }
244
- }
245
- return changedFiles;
246
- }
247
- catch (error) {
248
- console.error(`Error getting changed files since commit ${sinceCommit}:`, error);
249
- return new Map();
250
- }
251
- }
@@ -1,52 +0,0 @@
1
- import { AmendementResult } from "./model/ameli.js";
2
- import { DebatResult } from "./model/debats.js";
3
- import { DossierLegislatifResult } from "./model/dosleg.js";
4
- import { QuestionResult } from "./model/questions.js";
5
- import { ScrutinResult } from "./model/scrutins.js";
6
- import { CirconscriptionResult, OrganismeResult, SenateurResult } from "./model/sens.js";
7
- import { Reunion } from "./types/agenda.js";
8
- import { FlatTexte, DocumentMetadata } from "./types/texte.js";
9
- import { CompteRendu } from "./types/compte_rendu.js";
10
- import { DocumentResult } from "./model/documents.js";
11
- export { EnabledDatasets } from "./datasets.js";
12
- export type { DocumentResult } from "./model/documents.js";
13
- export declare const AGENDA_FOLDER = "agenda";
14
- export declare const COMPTES_RENDUS_FOLDER = "seances";
15
- export declare const COMMISSION_FOLDER = "commissions";
16
- export declare const DOSLEG_DOSSIERS_FOLDER = "dossiers";
17
- export declare const ENRICHED_TEXTE_FOLDER = "leg_enrichi";
18
- export declare const SCRUTINS_FOLDER = "scrutins";
19
- export declare const SENS_CIRCONSCRIPTIONS_FOLDER = "circonscriptions";
20
- export declare const SENS_ORGANISMES_FOLDER = "organismes";
21
- export declare const SENS_SENATEURS_FOLDER = "senateurs";
22
- export declare const TEXTE_FOLDER = "leg";
23
- export declare const RAPPORT_FOLDER = "rap";
24
- export declare const DATA_ORIGINAL_FOLDER = "original";
25
- export declare const DATA_TRANSFORMED_FOLDER = "transformed";
26
- export declare const DOCUMENT_METADATA_FILE = "metadata.json";
27
- export type IterItem<T> = {
28
- item: T;
29
- filePathFromDataset?: string;
30
- legislature?: number;
31
- gitStatus?: "A" | "M" | "D" | "R" | "C" | "T" | "U";
32
- };
33
- export declare function iterFilePaths(dirPath: string): Generator<string>;
34
- export declare function iterLoadSenatAmendements(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<AmendementResult>>;
35
- export declare function iterLoadSenatDebats(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<DebatResult>>;
36
- export declare function iterLoadSenatComptesRendusSeances(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<CompteRendu>>;
37
- export declare function iterLoadSenatComptesRendusCommissions(dataDir: string, session: number, options?: {}): Generator<IterItem<CompteRendu>>;
38
- export declare function iterLoadSenatDossiersLegislatifs(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<DossierLegislatifResult>>;
39
- export declare function iterLoadSenatRapportUrls(dataDir: string, session: number | undefined): Generator<IterItem<DocumentMetadata>>;
40
- export declare function iterLoadSenatTexteUrls(dataDir: string, session: number | undefined): Generator<IterItem<DocumentMetadata>>;
41
- export declare function iterLoadSenatRapports(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<DocumentResult>>;
42
- export declare function iterLoadSenatTextes(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<DocumentResult & Partial<FlatTexte>>>;
43
- export declare function loadSenatTexteContent(dataDir: string, session: number | string | null | undefined, texteId: string): IterItem<FlatTexte | null>;
44
- export declare function loadSenatCompteRenduContent(dataDir: string, session: number, debatId: string | number): {
45
- item: CompteRendu | null;
46
- };
47
- export declare function iterLoadSenatAgendas(dataDir: string, session: number | undefined): Generator<IterItem<Reunion>>;
48
- export declare function iterLoadSenatCirconscriptions(dataDir: string, options?: {}): Generator<IterItem<CirconscriptionResult>>;
49
- export declare function iterLoadSenatOrganismes(dataDir: string, options?: {}): Generator<IterItem<OrganismeResult>>;
50
- export declare function iterLoadSenatSenateurs(dataDir: string, options?: {}): Generator<IterItem<SenateurResult>>;
51
- export declare function iterLoadSenatQuestions(dataDir: string, legislature: number, options?: {}): Generator<IterItem<QuestionResult>>;
52
- export declare function iterLoadSenatScrutins(dataDir: string, session: number | undefined, options?: {}): Generator<IterItem<ScrutinResult>>;
@@ -1,260 +0,0 @@
1
- import fsex from "fs-extra";
2
- import fs from "fs";
3
- import path from "path";
4
- import * as git from "./git.js";
5
- import { datasets } from "./datasets.js";
6
- import { UNDEFINED_SESSION } from "./types/sessions.js";
7
- export { EnabledDatasets } from "./datasets.js";
8
- export const AGENDA_FOLDER = "agenda";
9
- export const COMPTES_RENDUS_FOLDER = "seances";
10
- export const COMMISSION_FOLDER = "commissions";
11
- export const DOSLEG_DOSSIERS_FOLDER = "dossiers";
12
- export const ENRICHED_TEXTE_FOLDER = "leg_enrichi";
13
- export const SCRUTINS_FOLDER = "scrutins";
14
- export const SENS_CIRCONSCRIPTIONS_FOLDER = "circonscriptions";
15
- export const SENS_ORGANISMES_FOLDER = "organismes";
16
- export const SENS_SENATEURS_FOLDER = "senateurs";
17
- export const TEXTE_FOLDER = "leg";
18
- export const RAPPORT_FOLDER = "rap";
19
- export const DATA_ORIGINAL_FOLDER = "original";
20
- export const DATA_TRANSFORMED_FOLDER = "transformed";
21
- export const DOCUMENT_METADATA_FILE = "metadata.json";
22
- export function* iterFilePaths(dirPath) {
23
- if (dirPath && fs.existsSync(dirPath)) {
24
- const files = fs.readdirSync(dirPath, {
25
- withFileTypes: true,
26
- recursive: true,
27
- });
28
- for (const file of files) {
29
- if (file.isFile()) {
30
- yield path.join(file.parentPath, file.name);
31
- }
32
- }
33
- }
34
- }
35
- function* iterLoadSenatItems(dataDir, dataName, legislatureOrSession, subDir, { log = false, sinceCommit } = {}) {
36
- let itemsDir = path.join(dataDir, dataName);
37
- if (subDir) {
38
- itemsDir = path.join(itemsDir, subDir);
39
- }
40
- if (legislatureOrSession) {
41
- itemsDir = path.join(itemsDir, String(legislatureOrSession));
42
- }
43
- // Get changed files if sinceCommit is specified (excluding deleted files)
44
- const changedFiles = sinceCommit
45
- ? git.getChangedFilesSinceCommit(itemsDir, sinceCommit, {
46
- diffFilter: "AMR", // Added, Modified, Renamed
47
- })
48
- : null;
49
- if (log && sinceCommit) {
50
- console.log(`Filtering files changed since commit ${sinceCommit} in ${itemsDir}`);
51
- console.log(`Found ${changedFiles?.size || 0} changed files (AMR)`);
52
- }
53
- for (const filePath of iterFilePaths(itemsDir)) {
54
- if (!filePath.endsWith(".json")) {
55
- continue;
56
- }
57
- const relativePath = path.relative(path.join(dataDir, dataName), filePath);
58
- const gitStatus = changedFiles?.get(relativePath);
59
- // Filter by changed files if sinceCommit is specified
60
- if (changedFiles && !gitStatus) {
61
- // Skip files not in the change set
62
- continue;
63
- }
64
- if (log) {
65
- console.log(`Loading file: ${filePath}…${gitStatus ? ` (${gitStatus})` : ""}`);
66
- }
67
- let item;
68
- try {
69
- const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
70
- item = JSON.parse(itemJson);
71
- }
72
- catch (error) {
73
- const err = error;
74
- console.warn(`[iterLoadSenatItems] skipped invalid JSON: ${filePath} (${err.message})`);
75
- continue;
76
- }
77
- const filePathFromDataset = filePath.substring(filePath.indexOf(dataName) + dataName.length);
78
- yield {
79
- item,
80
- filePathFromDataset,
81
- legislature: legislatureOrSession,
82
- ...(gitStatus && { gitStatus }), // Include gitStatus
83
- };
84
- }
85
- // Yield deleted files at the end if sinceCommit is specified
86
- if (sinceCommit) {
87
- const deletedFiles = git.getChangedFilesSinceCommit(itemsDir, sinceCommit, {
88
- diffFilter: "D", // Deleted
89
- });
90
- if (log) {
91
- console.log(`Found ${deletedFiles.size || 0} deleted files (D)`);
92
- }
93
- for (const [relativePath, status] of deletedFiles.entries()) {
94
- const deletedFilePath = path.join(itemsDir, relativePath);
95
- if (log) {
96
- console.log(`Deleted file: ${deletedFilePath}`);
97
- }
98
- // Extract UID from filename (remove extension) for the placeholder item
99
- const fileExtension = path.extname(relativePath) || ".json"; // Assuming files use an extension like .json
100
- const filename = path.basename(relativePath, fileExtension);
101
- const fakeItem = { uid: filename }; // Placeholder item using uid constraint
102
- const filePathFromDataset = deletedFilePath.substring(deletedFilePath.indexOf(dataName) + dataName.length);
103
- yield {
104
- item: fakeItem,
105
- filePathFromDataset,
106
- legislature: legislatureOrSession,
107
- gitStatus: status,
108
- };
109
- }
110
- }
111
- }
112
- export function* iterLoadSenatAmendements(dataDir, session, options = {}) {
113
- for (const amendementItem of iterLoadSenatItems(dataDir, datasets.ameli.database, session, undefined, options)) {
114
- yield amendementItem;
115
- }
116
- }
117
- export function* iterLoadSenatDebats(dataDir, session, options = {}) {
118
- for (const debatItem of iterLoadSenatItems(dataDir, datasets.debats.database, session, undefined, options)) {
119
- yield debatItem;
120
- }
121
- }
122
- export function* iterLoadSenatComptesRendusSeances(dataDir, session, options = {}) {
123
- for (const compteRenduItem of iterLoadSenatItems(dataDir, COMPTES_RENDUS_FOLDER, session, DATA_TRANSFORMED_FOLDER, options)) {
124
- yield compteRenduItem;
125
- }
126
- }
127
- export function* iterLoadSenatComptesRendusCommissions(dataDir, session, options = {}) {
128
- for (const compteRenduItem of iterLoadSenatItems(dataDir, COMMISSION_FOLDER, session, DATA_TRANSFORMED_FOLDER, options)) {
129
- yield compteRenduItem;
130
- }
131
- }
132
- export function* iterLoadSenatDossiersLegislatifs(dataDir, session, options = {}) {
133
- for (const dossierLegislatifItem of iterLoadSenatItems(dataDir, datasets.dosleg.database, session, DOSLEG_DOSSIERS_FOLDER, options)) {
134
- yield dossierLegislatifItem;
135
- }
136
- }
137
- export function* iterLoadSenatRapportUrls(dataDir, session) {
138
- let itemsDir = path.join(dataDir, RAPPORT_FOLDER, DATA_ORIGINAL_FOLDER);
139
- if (session) {
140
- itemsDir = path.join(itemsDir, session.toString());
141
- }
142
- for (const filePath of iterFilePaths(itemsDir)) {
143
- const parsedFilePath = path.parse(filePath);
144
- if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
145
- const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
146
- const item = JSON.parse(itemJson);
147
- yield {
148
- item,
149
- };
150
- }
151
- }
152
- }
153
- export function* iterLoadSenatTexteUrls(dataDir, session) {
154
- let itemsDir = path.join(dataDir, TEXTE_FOLDER, DATA_ORIGINAL_FOLDER);
155
- if (session) {
156
- itemsDir = path.join(itemsDir, session.toString());
157
- }
158
- for (const filePath of iterFilePaths(itemsDir)) {
159
- const parsedFilePath = path.parse(filePath);
160
- if (parsedFilePath.base === DOCUMENT_METADATA_FILE) {
161
- const itemJson = fs.readFileSync(filePath, { encoding: "utf8" });
162
- const item = JSON.parse(itemJson);
163
- yield {
164
- item,
165
- };
166
- }
167
- }
168
- }
169
- export function* iterLoadSenatRapports(dataDir, session, options = {}) {
170
- for (const iterItem of iterLoadSenatItems(dataDir, RAPPORT_FOLDER, session, "original", options)) {
171
- if (iterItem.item?.["id"]) {
172
- yield iterItem;
173
- }
174
- }
175
- }
176
- export function* iterLoadSenatTextes(dataDir, session, options = {}) {
177
- for (const iterItem of iterLoadSenatItems(dataDir, TEXTE_FOLDER, session, DATA_ORIGINAL_FOLDER, options)) {
178
- if (!iterItem.item?.["id"]) {
179
- continue;
180
- }
181
- const texteItem = iterItem;
182
- const texte = texteItem.item;
183
- const texteId = texte["id"];
184
- if (!texteId) {
185
- continue;
186
- }
187
- const { item: texteContent } = loadSenatTexteContent(dataDir, texte["session"], texteId);
188
- if (texteContent) {
189
- texteItem.item = { ...texteContent, ...texteItem.item };
190
- }
191
- yield texteItem;
192
- }
193
- }
194
- export function loadSenatTexteContent(dataDir, session, texteId) {
195
- const fullTextePath = path.join(dataDir, TEXTE_FOLDER, DATA_TRANSFORMED_FOLDER, String(session ?? UNDEFINED_SESSION), texteId, `${texteId}.json`);
196
- if (!fs.existsSync(fullTextePath)) {
197
- return { item: null };
198
- }
199
- const texteJson = fs.readFileSync(fullTextePath, { encoding: "utf8" });
200
- return { item: JSON.parse(texteJson) };
201
- }
202
- export function loadSenatCompteRenduContent(dataDir, session, debatId) {
203
- const fullPath = path.join(dataDir, COMPTES_RENDUS_FOLDER, DATA_TRANSFORMED_FOLDER, String(session), `${debatId}.json`);
204
- if (!fs.existsSync(fullPath)) {
205
- return { item: null };
206
- }
207
- const json = fs.readFileSync(fullPath, { encoding: "utf8" });
208
- return { item: JSON.parse(json) };
209
- }
210
- export function* iterLoadSenatAgendas(dataDir, session) {
211
- const baseDir = path.join(dataDir, AGENDA_FOLDER, DATA_TRANSFORMED_FOLDER, String(session ?? ""));
212
- if (!fs.existsSync(baseDir))
213
- return;
214
- const files = (fs.readdirSync(baseDir) || []).filter((f) => f.startsWith("RUSN") && f.endsWith(".json")).sort();
215
- for (const fileName of files) {
216
- const filePath = path.join(baseDir, fileName);
217
- let raw;
218
- try {
219
- raw = fsex.readJSONSync(filePath);
220
- }
221
- catch {
222
- continue; // JSON invalide
223
- }
224
- if (!raw || typeof raw !== "object")
225
- continue;
226
- const gr = raw;
227
- if (!gr.uid || !gr.date || !gr.titre)
228
- continue;
229
- const reunion = {
230
- ...gr,
231
- events: Array.isArray(gr.events) ? gr.events : [],
232
- };
233
- yield { item: reunion };
234
- }
235
- }
236
- export function* iterLoadSenatCirconscriptions(dataDir, options = {}) {
237
- for (const circonscriptionItem of iterLoadSenatItems(dataDir, datasets.sens.database, undefined, SENS_CIRCONSCRIPTIONS_FOLDER, options)) {
238
- yield circonscriptionItem;
239
- }
240
- }
241
- export function* iterLoadSenatOrganismes(dataDir, options = {}) {
242
- for (const organismeItem of iterLoadSenatItems(dataDir, datasets.sens.database, undefined, SENS_ORGANISMES_FOLDER, options)) {
243
- yield organismeItem;
244
- }
245
- }
246
- export function* iterLoadSenatSenateurs(dataDir, options = {}) {
247
- for (const senateurItem of iterLoadSenatItems(dataDir, datasets.sens.database, undefined, SENS_SENATEURS_FOLDER, options)) {
248
- yield senateurItem;
249
- }
250
- }
251
- export function* iterLoadSenatQuestions(dataDir, legislature, options = {}) {
252
- for (const questionItem of iterLoadSenatItems(dataDir, datasets.questions.database, legislature, undefined, options)) {
253
- yield questionItem;
254
- }
255
- }
256
- export function* iterLoadSenatScrutins(dataDir, session, options = {}) {
257
- for (const scrutinItem of iterLoadSenatItems(dataDir, "scrutins", session, undefined, options)) {
258
- yield scrutinItem;
259
- }
260
- }
@@ -1,6 +0,0 @@
1
- import { AgendaEvent } from "../types/agenda.js";
2
- export declare function getStartAndEndTimes(timeStr: string | null | undefined, dateISO: string): {
3
- startTime: string | null;
4
- endTime: string | null;
5
- };
6
- export declare function parseAgendaFromFile(htmlFilePath: string): Promise<AgendaEvent[] | null>;