@tricoteuses/senat 3.0.0 → 3.0.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 (77) hide show
  1. package/lib/add-js-extensions-v2.d.ts +1 -0
  2. package/lib/add-js-extensions-v2.js +23 -0
  3. package/lib/add-js-extensions.d.ts +1 -0
  4. package/lib/add-js-extensions.js +17 -0
  5. package/lib/src/databases_postgres.js +1 -1
  6. package/lib/src/index.d.ts +24 -24
  7. package/lib/src/index.js +6 -6
  8. package/lib/src/loaders.d.ts +12 -12
  9. package/lib/src/loaders.js +4 -4
  10. package/lib/src/model/agenda.d.ts +1 -1
  11. package/lib/src/model/agenda.js +1 -1
  12. package/lib/src/model/ameli.js +1 -1
  13. package/lib/src/model/commission.d.ts +2 -2
  14. package/lib/src/model/commission.js +4 -4
  15. package/lib/src/model/debats.js +1 -1
  16. package/lib/src/model/documents.js +1 -1
  17. package/lib/src/model/dosleg.js +1 -1
  18. package/lib/src/model/index.d.ts +7 -7
  19. package/lib/src/model/index.js +7 -7
  20. package/lib/src/model/questions.js +1 -1
  21. package/lib/src/model/scrutins.js +1 -1
  22. package/lib/src/model/seance.d.ts +1 -1
  23. package/lib/src/model/seance.js +4 -4
  24. package/lib/src/model/sens.js +1 -1
  25. package/lib/src/parsers/texte.d.ts +1 -1
  26. package/lib/src/parsers/texte.js +2 -2
  27. package/lib/src/raw_types/ameli.js +235 -977
  28. package/lib/src/raw_types/debats.js +73 -324
  29. package/lib/src/raw_types/dosleg.js +702 -3051
  30. package/lib/src/raw_types/questions.js +276 -1086
  31. package/lib/src/raw_types/sens.js +1547 -7285
  32. package/lib/src/scripts/convert_data.js +10 -10
  33. package/lib/src/scripts/convert_xml_to_html.js +1 -1
  34. package/lib/src/scripts/datautil.d.ts +1 -1
  35. package/lib/src/scripts/retrieve_agenda.js +9 -9
  36. package/lib/src/scripts/retrieve_cr_commission.js +8 -8
  37. package/lib/src/scripts/retrieve_cr_seance.d.ts +1 -1
  38. package/lib/src/scripts/retrieve_cr_seance.js +8 -8
  39. package/lib/src/scripts/retrieve_documents.d.ts +1 -1
  40. package/lib/src/scripts/retrieve_documents.js +7 -7
  41. package/lib/src/scripts/retrieve_open_data.js +9 -9
  42. package/lib/src/scripts/retrieve_senateurs_photos.js +4 -4
  43. package/lib/src/scripts/retrieve_videos.js +9 -9
  44. package/lib/src/scripts/shared/incremental_import_sql.js +1 -1
  45. package/lib/src/scripts/shared/make_generate_zod_schemas.d.ts +20 -0
  46. package/lib/src/scripts/shared/make_generate_zod_schemas.js +300 -0
  47. package/lib/src/scripts/shared/staging_import.d.ts +1 -1
  48. package/lib/src/scripts/validate_prefixed_tables.js +4 -4
  49. package/lib/src/types/ameli.d.ts +2 -2
  50. package/lib/src/types/dosleg.d.ts +4 -4
  51. package/lib/src/types/questions.d.ts +1 -1
  52. package/lib/src/types/texte.d.ts +1 -1
  53. package/lib/src/utils/cr_spliting.d.ts +1 -1
  54. package/lib/src/utils/cr_spliting.js +4 -4
  55. package/lib/src/utils/nvs-parsing.js +2 -2
  56. package/lib/src/utils/reunion_odj_building.d.ts +2 -2
  57. package/lib/src/utils/reunion_odj_building.js +2 -2
  58. package/lib/src/utils/reunion_parsing.d.ts +2 -2
  59. package/lib/src/utils/reunion_parsing.js +2 -2
  60. package/lib/src/utils/scoring.d.ts +3 -3
  61. package/lib/src/utils/scoring.js +2 -2
  62. package/lib/src/videos/config.d.ts +1 -1
  63. package/lib/src/videos/index.d.ts +5 -5
  64. package/lib/src/videos/index.js +5 -5
  65. package/lib/src/videos/match.d.ts +2 -2
  66. package/lib/src/videos/match.js +5 -5
  67. package/lib/src/videos/pipeline.d.ts +2 -2
  68. package/lib/src/videos/pipeline.js +4 -4
  69. package/lib/src/videos/search.d.ts +2 -2
  70. package/lib/src/videos/search.js +2 -2
  71. package/lib/tests/incrementalImportSql.test.js +4 -4
  72. package/lib/tests/prefixedTables.test.js +1 -1
  73. package/lib/tests/schemaVersion.test.js +1 -1
  74. package/lib/tests/test_iter_load.test.js +1 -1
  75. package/lib/tests/validatePrefixedTables.test.js +2 -2
  76. package/lib/tests/videoMatching.test.js +4 -4
  77. package/package.json +1 -4
@@ -2,16 +2,16 @@ import commandLineArgs from "command-line-args";
2
2
  import fs from "fs-extra";
3
3
  import path from "path";
4
4
  import pLimit from "p-limit";
5
- import * as git from "../git";
6
- import { datasets, EnabledDatasets, getEnabledDatasets } from "../datasets";
7
- import { DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER, DOCUMENT_METADATA_FILE, DOSLEG_DOSSIERS_FOLDER, SCRUTINS_FOLDER, RAPPORT_FOLDER, SENS_CIRCONSCRIPTIONS_FOLDER, SENS_ORGANISMES_FOLDER, SENS_SENATEURS_FOLDER, TEXTE_FOLDER, ENRICHED_TEXTE_FOLDER, } from "../loaders";
8
- import { findAllAmendements, findAllCirconscriptions, findAllDebats, findAllDossiers, findAllScrutins, findAllOrganismes, findAllQuestions, findAllSens, findAllTextes, findAllRapports, } from "../model";
9
- import { processRapport, processTexte } from "./retrieve_documents";
10
- import { buildActesLegislatifs } from "../model/dosleg";
11
- import { UNDEFINED_SESSION } from "../types/sessions";
12
- import { getSessionFromDate, getSessionFromSignet } from "./datautil";
13
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
14
- import { ensureAndClearDir } from "./shared/util";
5
+ import * as git from "../git.js";
6
+ import { datasets, EnabledDatasets, getEnabledDatasets } from "../datasets.js";
7
+ import { DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER, DOCUMENT_METADATA_FILE, DOSLEG_DOSSIERS_FOLDER, SCRUTINS_FOLDER, RAPPORT_FOLDER, SENS_CIRCONSCRIPTIONS_FOLDER, SENS_ORGANISMES_FOLDER, SENS_SENATEURS_FOLDER, TEXTE_FOLDER, ENRICHED_TEXTE_FOLDER, } from "../loaders.js";
8
+ import { findAllAmendements, findAllCirconscriptions, findAllDebats, findAllDossiers, findAllScrutins, findAllOrganismes, findAllQuestions, findAllSens, findAllTextes, findAllRapports, } from "../model/index.js";
9
+ import { processRapport, processTexte } from "./retrieve_documents.js";
10
+ import { buildActesLegislatifs } from "../model/dosleg.js";
11
+ import { UNDEFINED_SESSION } from "../types/sessions.js";
12
+ import { getSessionFromDate, getSessionFromSignet } from "./datautil.js";
13
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
14
+ import { ensureAndClearDir } from "./shared/util.js";
15
15
  let exitCode = 10; // 0: some data changed, 10: no modification
16
16
  const optionsDefinitions = [...commonOptions];
17
17
  const options = commandLineArgs(optionsDefinitions);
@@ -1,7 +1,7 @@
1
1
  import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import commandLineArgs from "command-line-args";
4
- import { convertSenatXmlToHtml } from "../conversion_textes";
4
+ import { convertSenatXmlToHtml } from "../conversion_textes.js";
5
5
  const optionDefinitions = [
6
6
  { name: "input", alias: "i", type: String, defaultOption: true },
7
7
  { name: "output", alias: "o", type: String },
@@ -1,4 +1,4 @@
1
- import { Session } from "../types/sessions";
1
+ import { Session } from "../types/sessions.js";
2
2
  export declare const STANDARD_DATE_FORMAT = "yyyy-MM-dd";
3
3
  export declare const ID_DATE_FORMAT = "yyyyMMdd";
4
4
  export declare const AKN_IDENTIFICATION_STRUCTURE_REGEXP: RegExp;
@@ -2,15 +2,15 @@ import commandLineArgs from "command-line-args";
2
2
  import fs from "fs-extra";
3
3
  import { DateTime } from "luxon";
4
4
  import path from "path";
5
- import * as git from "../git";
6
- import { AGENDA_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders";
7
- import { parseAgendaFromFile } from "../model/agenda";
8
- import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions";
9
- import { ID_DATE_FORMAT } from "./datautil";
10
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
11
- import { fetchWithRetry } from "./shared/util";
12
- import { buildReunionsByBucket } from "../utils/reunion_parsing";
13
- import { buildSenatDossierIndex } from "../utils/reunion_odj_building";
5
+ import * as git from "../git.js";
6
+ import { AGENDA_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders.js";
7
+ import { parseAgendaFromFile } from "../model/agenda.js";
8
+ import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions.js";
9
+ import { ID_DATE_FORMAT } from "./datautil.js";
10
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
11
+ import { fetchWithRetry } from "./shared/util.js";
12
+ import { buildReunionsByBucket } from "../utils/reunion_parsing.js";
13
+ import { buildSenatDossierIndex } from "../utils/reunion_odj_building.js";
14
14
  const optionsDefinitions = [
15
15
  ...commonOptions,
16
16
  {
@@ -1,15 +1,15 @@
1
1
  import fs, { ensureDir } from "fs-extra";
2
2
  import path from "path";
3
3
  import * as cheerio from "cheerio";
4
- import { COMMISSION_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders";
5
- import { loadAgendaForDate, parseCommissionMetadataFromHtml, linkCRtoCommissionGroup } from "../utils/cr_spliting";
6
- import { cleanTitle, extractDayH3Sections, parseCommissionCRSectionFromDom } from "../model/commission";
4
+ import { COMMISSION_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders.js";
5
+ import { loadAgendaForDate, parseCommissionMetadataFromHtml, linkCRtoCommissionGroup } from "../utils/cr_spliting.js";
6
+ import { cleanTitle, extractDayH3Sections, parseCommissionCRSectionFromDom } from "../model/commission.js";
7
7
  import commandLineArgs from "command-line-args";
8
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
9
- import { sessionStartYearFromDate } from "../model/seance";
10
- import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions";
11
- import { ensureAndClearDir, fetchWithRetry } from "./shared/util";
12
- import { jaccard, jaccardTokenSim } from "../utils/scoring";
8
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
9
+ import { sessionStartYearFromDate } from "../model/seance.js";
10
+ import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions.js";
11
+ import { ensureAndClearDir, fetchWithRetry } from "./shared/util.js";
12
+ import { jaccard, jaccardTokenSim } from "../utils/scoring.js";
13
13
  import * as git from "../git.js";
14
14
  class CommissionCRDownloadError extends Error {
15
15
  constructor(message, url) {
@@ -3,7 +3,7 @@
3
3
  * - downloads the ZIP of comptes-rendus des débats (CRI) from data.senat.fr
4
4
  * - extracts XML files, distributes them by session/year
5
5
  */
6
- import { Session } from "../types/sessions";
6
+ import { Session } from "../types/sessions.js";
7
7
  import { CommandLineOptions } from "command-line-args";
8
8
  type RetrieveCriOptions = CommandLineOptions & {
9
9
  commit?: boolean;
@@ -8,14 +8,14 @@ import fs, { ensureDirSync } from "fs-extra";
8
8
  import path from "path";
9
9
  import StreamZip from "node-stream-zip";
10
10
  import * as cheerio from "cheerio";
11
- import { AGENDA_FOLDER, COMPTES_RENDUS_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders";
12
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
13
- import { parseCompteRenduIntervalFromFile, sessionStartYearFromDate } from "../model/seance";
14
- import { extractSommaireBlocks, makeReunionUid } from "../utils/reunion_parsing";
15
- import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions";
16
- import { ensureAndClearDir, fetchWithRetry } from "./shared/util";
17
- import { isNoiseBlock, scoreSommaireBlockForEvent } from "../utils/scoring";
18
- import { parseYYYYMMDD } from "../utils/date";
11
+ import { AGENDA_FOLDER, COMPTES_RENDUS_FOLDER, DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER } from "../loaders.js";
12
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
13
+ import { parseCompteRenduIntervalFromFile, sessionStartYearFromDate } from "../model/seance.js";
14
+ import { extractSommaireBlocks, makeReunionUid } from "../utils/reunion_parsing.js";
15
+ import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions.js";
16
+ import { ensureAndClearDir, fetchWithRetry } from "./shared/util.js";
17
+ import { isNoiseBlock, scoreSommaireBlockForEvent } from "../utils/scoring.js";
18
+ import { parseYYYYMMDD } from "../utils/date.js";
19
19
  import * as git from "../git.js";
20
20
  const optionsDefinitions = [
21
21
  ...commonOptions,
@@ -1,4 +1,4 @@
1
- import { DocumentMetadata } from "../types/texte";
1
+ import { DocumentMetadata } from "../types/texte.js";
2
2
  type DownloadOptions = {
3
3
  force?: boolean;
4
4
  formats?: string[];
@@ -2,13 +2,13 @@ import commandLineArgs from "command-line-args";
2
2
  import fs from "fs-extra";
3
3
  import { DateTime } from "luxon";
4
4
  import path from "path";
5
- import { convertSenatXmlToHtml } from "../conversion_textes";
6
- import * as git from "../git";
7
- import { DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER, ENRICHED_TEXTE_FOLDER, iterLoadSenatRapportUrls, iterLoadSenatTexteUrls, RAPPORT_FOLDER, TEXTE_FOLDER, } from "../loaders";
8
- import { parseExposeDesMotifs, parseTexte, parseTexteFromFile } from "../parsers/texte";
9
- import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions";
10
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
11
- import { ensureAndClearDir, fetchWithRetry, isOptionEmptyOrHasValue } from "./shared/util";
5
+ import { convertSenatXmlToHtml } from "../conversion_textes.js";
6
+ import * as git from "../git.js";
7
+ import { DATA_ORIGINAL_FOLDER, DATA_TRANSFORMED_FOLDER, ENRICHED_TEXTE_FOLDER, iterLoadSenatRapportUrls, iterLoadSenatTexteUrls, RAPPORT_FOLDER, TEXTE_FOLDER, } from "../loaders.js";
8
+ import { parseExposeDesMotifs, parseTexte, parseTexteFromFile } from "../parsers/texte.js";
9
+ import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions.js";
10
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
11
+ import { ensureAndClearDir, fetchWithRetry, isOptionEmptyOrHasValue } from "./shared/util.js";
12
12
  let exitCode = 10; // 0: some data changed, 10: no modification
13
13
  const optionsDefinitions = [
14
14
  ...commonOptions,
@@ -3,21 +3,21 @@ import { execFileSync } from "child_process";
3
3
  import commandLineArgs from "command-line-args";
4
4
  import fs from "fs-extra";
5
5
  import { formatWithPrettier, makePgTsGenerator, markAsGenerated, processDatabase } from "kanel";
6
- import { makeGenerateZodSchemas } from "kanel-zod";
7
6
  import path from "path";
8
7
  import StreamZip from "node-stream-zip";
9
8
  import readline from "readline";
10
9
  import { pipeline, Readable } from "stream";
11
10
  import { promisify } from "util";
12
11
  import * as windows1252 from "windows-1252";
13
- import config from "../config";
14
- import { getChosenDatasets, getEnabledDatasets } from "../datasets";
15
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
16
- import { buildIncrementalDatasetImportSql, buildNormalizeStagingSchemaSql } from "./shared/incremental_import_sql";
17
- import { buildGeneratedTableManifest, getGeneratedDefinitionPath, getGeneratedTableManifestPath, prefixedName, rawTypesDir, senatSchemaName, stagingSchemaName, stripDatasetPrefix, } from "./shared/prefixed_tables";
18
- import { buildEnsureSchemaVersionTableSql, buildIncrementSchemaVersionSql, buildSchemaStructureFingerprintQuery, } from "./shared/schema_version";
19
- import { buildExportStagingMetadataStatementsQuery } from "./shared/staging_metadata_sql";
20
- import { isCopyFromStdinLine, rewriteLineForStagingImport } from "./shared/staging_import";
12
+ import config from "../config.js";
13
+ import { getChosenDatasets, getEnabledDatasets } from "../datasets.js";
14
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
15
+ import { buildIncrementalDatasetImportSql, buildNormalizeStagingSchemaSql } from "./shared/incremental_import_sql.js";
16
+ import { buildGeneratedTableManifest, getGeneratedDefinitionPath, getGeneratedTableManifestPath, prefixedName, rawTypesDir, senatSchemaName, stagingSchemaName, stripDatasetPrefix, } from "./shared/prefixed_tables.js";
17
+ import { buildEnsureSchemaVersionTableSql, buildIncrementSchemaVersionSql, buildSchemaStructureFingerprintQuery, } from "./shared/schema_version.js";
18
+ import { makeGenerateZodSchemas } from "./shared/make_generate_zod_schemas.js";
19
+ import { buildExportStagingMetadataStatementsQuery } from "./shared/staging_metadata_sql.js";
20
+ import { isCopyFromStdinLine, rewriteLineForStagingImport } from "./shared/staging_import.js";
21
21
  const badWindows1252CharacterRegex = /[\u0080-\u009f]/g;
22
22
  const optionsDefinitions = [
23
23
  ...commonOptions,
@@ -6,10 +6,10 @@ import path from "path";
6
6
  import { fileURLToPath } from "url";
7
7
  // import stream from "stream"
8
8
  // import util from "util"
9
- import * as git from "../git";
10
- import { findActif as findActifSenateurs } from "../model/sens";
11
- import { slugify } from "../strings";
12
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
9
+ import * as git from "../git.js";
10
+ import { findActif as findActifSenateurs } from "../model/sens.js";
11
+ import { slugify } from "../strings.js";
12
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
13
13
  const optionsDefinitions = [
14
14
  ...commonOptions,
15
15
  {
@@ -4,16 +4,16 @@ import fs from "fs-extra";
4
4
  import fsp from "fs/promises";
5
5
  import path from "path";
6
6
  import * as git from "../git.js";
7
- import { AGENDA_FOLDER, iterLoadSenatAgendas } from "../loaders";
8
- import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions";
9
- import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers";
10
- import { getAgendaSegmentTimecodes, buildSenatVodMasterM3u8FromNvs } from "../utils/nvs-parsing";
11
- import { epochToParisDateTime, isAmbiguousTimeOriginal, toTargetEpoch } from "../utils/date";
7
+ import { AGENDA_FOLDER, iterLoadSenatAgendas } from "../loaders.js";
8
+ import { getSessionsFromStart, UNDEFINED_SESSION } from "../types/sessions.js";
9
+ import { assertExistingDirectory, commonOptions } from "./shared/cli_helpers.js";
10
+ import { getAgendaSegmentTimecodes, buildSenatVodMasterM3u8FromNvs } from "../utils/nvs-parsing.js";
11
+ import { epochToParisDateTime, isAmbiguousTimeOriginal, toTargetEpoch } from "../utils/date.js";
12
12
  import { pathToFileURL } from "url";
13
- import { fetchCandidatesForAgenda, fetchText } from "../videos/search";
14
- import { matchAgendaToVideo } from "../videos/match";
15
- import { SENAT_DATAS_ROOT, STATS, VIDEOS_ROOT_FOLDER, weights } from "../videos/config";
16
- import { processBisIfNeeded, processOneReunionMatch, writeIfChanged } from "../videos";
13
+ import { fetchCandidatesForAgenda, fetchText } from "../videos/search.js";
14
+ import { matchAgendaToVideo } from "../videos/match.js";
15
+ import { SENAT_DATAS_ROOT, STATS, VIDEOS_ROOT_FOLDER, weights } from "../videos/config.js";
16
+ import { processBisIfNeeded, processOneReunionMatch, writeIfChanged } from "../videos/index.js";
17
17
  const optionsDefinitions = [...commonOptions];
18
18
  const options = commandLineArgs(optionsDefinitions);
19
19
  let exitCode = 10; // 0: some data changed, 10: no modification
@@ -1,4 +1,4 @@
1
- import { prefixedName, senatSchemaName, stagingSchemaName } from "./prefixed_tables";
1
+ import { prefixedName, senatSchemaName, stagingSchemaName } from "./prefixed_tables.js";
2
2
  function escapeSqlLiteral(value) {
3
3
  return value.replace(/'/g, "''");
4
4
  }
@@ -0,0 +1,20 @@
1
+ import type { TableColumn, TableDetails } from "extract-pg-schema";
2
+ import { type Details, type Path, type PgTsGeneratorContext, type PgTsPreRenderHook, type TypeMap } from "kanel";
3
+ type GenerateFor = "selector" | "initializer" | "mutator" | undefined;
4
+ type ZodSchemaMetadata = {
5
+ comment?: string[];
6
+ name: string;
7
+ path: Path;
8
+ };
9
+ type ZodIdentifierMetadata = {
10
+ comment?: string[];
11
+ name: string;
12
+ };
13
+ type GenerateZodSchemasConfig = {
14
+ castToSchema?: boolean;
15
+ getZodIdentifierMetadata?: (column: TableColumn, details: TableDetails, context: PgTsGeneratorContext) => ZodIdentifierMetadata;
16
+ getZodSchemaMetadata?: (details: Details, generateFor: GenerateFor, context: PgTsGeneratorContext) => ZodSchemaMetadata;
17
+ zodTypeMap?: TypeMap;
18
+ };
19
+ export declare function makeGenerateZodSchemas(config?: GenerateZodSchemasConfig): PgTsPreRenderHook;
20
+ export {};
@@ -0,0 +1,300 @@
1
+ import { escapeName, resolveType, useKanelContext, } from "kanel";
2
+ import { defaultGetZodIdentifierMetadata, defaultGetZodSchemaMetadata, defaultZodTypeMap } from "kanel-zod";
3
+ const zImport = {
4
+ asName: undefined,
5
+ importAsType: false,
6
+ isAbsolute: true,
7
+ isDefault: false,
8
+ name: "z",
9
+ path: "zod",
10
+ };
11
+ function appendTsDeclaration(output, path, declaration) {
12
+ const file = output[path];
13
+ if (!file || file.fileType !== "typescript") {
14
+ throw new Error(`Path ${path} is not a typescript file`);
15
+ }
16
+ file.declarations.push(declaration);
17
+ }
18
+ function toMetaQualifier(comment) {
19
+ if (!comment || comment.length === 0) {
20
+ return undefined;
21
+ }
22
+ const description = comment.join(" ").replace(/\n/g, " ");
23
+ return `meta({ description: ${JSON.stringify(description)} })`;
24
+ }
25
+ function generateProperties(details, generateFor, nonCompositeTypeImports, compositeTypeImports, identifierTypeImports, zodTypeMap, context) {
26
+ const properties = details.kind === "compositeType" ? [...details.attributes] : [...details.columns];
27
+ const sortedProperties = context.propertySortFunction ? properties.sort(context.propertySortFunction) : properties;
28
+ return sortedProperties.map((property) => {
29
+ const { comment, name, nullableOverride, optionalOverride, typeOverride } = context.getPropertyMetadata(property, details, generateFor);
30
+ const canBeOptional = property.isNullable || property.defaultValue || property.isIdentity;
31
+ const resolvedType = typeOverride ?? resolveType(property, details);
32
+ let zodType = "z.unknown()";
33
+ const typeImports = [];
34
+ if (typeof resolvedType !== "string" && `${details.schemaName}.${resolvedType.name}` in identifierTypeImports) {
35
+ const typeImport = identifierTypeImports[`${details.schemaName}.${resolvedType.name}`];
36
+ typeImports.push(typeImport);
37
+ zodType = typeImport.name;
38
+ }
39
+ else if (property.type.fullName in zodTypeMap) {
40
+ const mappedType = zodTypeMap[property.type.fullName];
41
+ if (typeof mappedType === "string") {
42
+ zodType = mappedType;
43
+ if ("dimensions" in property) {
44
+ for (let i = property.dimensions || 0; i > 0; i -= 1) {
45
+ zodType = `${zodType}.array()`;
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ zodType = mappedType.name;
51
+ typeImports.push(...mappedType.typeImports);
52
+ }
53
+ }
54
+ else if (property.type.fullName in nonCompositeTypeImports) {
55
+ const typeImport = nonCompositeTypeImports[property.type.fullName];
56
+ typeImports.push(typeImport);
57
+ zodType = typeImport.name;
58
+ }
59
+ else if (property.type.fullName in compositeTypeImports) {
60
+ const typeImport = compositeTypeImports[property.type.fullName];
61
+ typeImports.push(typeImport);
62
+ zodType = typeImport.name;
63
+ if (property.isArray) {
64
+ zodType = `${zodType}.array()`;
65
+ }
66
+ if (property.isNullable) {
67
+ zodType = `${zodType}.nullable()`;
68
+ }
69
+ }
70
+ else {
71
+ console.error(`kanel-zod: Unknown type for ${name}.${property.name}: ${property.type.fullName}`);
72
+ }
73
+ let isOptional;
74
+ if (optionalOverride === undefined) {
75
+ switch (generateFor) {
76
+ case "selector":
77
+ isOptional = false;
78
+ break;
79
+ case "initializer":
80
+ isOptional = Boolean(canBeOptional);
81
+ break;
82
+ case "mutator":
83
+ isOptional = true;
84
+ break;
85
+ }
86
+ }
87
+ else {
88
+ isOptional = optionalOverride;
89
+ }
90
+ const qualifiers = [];
91
+ if (isOptional) {
92
+ qualifiers.push("optional()");
93
+ }
94
+ if (nullableOverride ?? property.isNullable) {
95
+ qualifiers.push("nullable()");
96
+ }
97
+ const metaQualifier = toMetaQualifier(comment);
98
+ if (metaQualifier) {
99
+ qualifiers.push(metaQualifier);
100
+ }
101
+ return {
102
+ name,
103
+ typeImports,
104
+ value: qualifiers.length > 0 ? `${zodType}.${qualifiers.join(".")}` : zodType,
105
+ };
106
+ });
107
+ }
108
+ function buildCompositeDeclaration(details, generateFor, nonCompositeTypeImports, compositeTypeImports, identifierTypeImports, getZodSchemaMetadata, zodTypeMap, castToSchema, context) {
109
+ const { comment, name } = getZodSchemaMetadata(details, generateFor, context);
110
+ const { name: typescriptTypeName } = context.getMetadata(details, generateFor);
111
+ const properties = generateProperties(details, generateFor, nonCompositeTypeImports, compositeTypeImports, identifierTypeImports, zodTypeMap, context);
112
+ const typeImports = [zImport];
113
+ const value = ["z.object({", ...properties.map((property) => ` ${escapeName(property.name)}: ${property.value},`)];
114
+ if (castToSchema) {
115
+ value.push(`}) as unknown as z.Schema<${typescriptTypeName}>`);
116
+ }
117
+ else {
118
+ value.push("})");
119
+ }
120
+ properties.forEach((property) => {
121
+ typeImports.push(...property.typeImports);
122
+ });
123
+ return {
124
+ comment,
125
+ declarationType: "constant",
126
+ exportAs: "named",
127
+ name,
128
+ type: undefined,
129
+ typeImports,
130
+ value,
131
+ };
132
+ }
133
+ function buildIdentifierDeclarations(details, getZodIdentifierMetadata, zodTypeMap, castToSchema, nonCompositeTypeImports, context) {
134
+ if (!context.generateIdentifierType) {
135
+ return [];
136
+ }
137
+ const generateIdentifierType = context.generateIdentifierType;
138
+ return details.columns
139
+ .filter((column) => column.isPrimaryKey && !column.reference)
140
+ .map((column) => {
141
+ const typescriptDeclaration = generateIdentifierType(column, details);
142
+ const { comment, name } = getZodIdentifierMetadata(column, details, context);
143
+ let zodType = "z.unknown()";
144
+ const typeImports = [zImport];
145
+ if (column.type.fullName in zodTypeMap) {
146
+ const mappedType = zodTypeMap[column.type.fullName];
147
+ if (typeof mappedType === "string") {
148
+ zodType = mappedType;
149
+ }
150
+ else {
151
+ zodType = mappedType.name;
152
+ typeImports.push(...mappedType.typeImports);
153
+ }
154
+ }
155
+ else if (column.type.fullName in nonCompositeTypeImports) {
156
+ const typeImport = nonCompositeTypeImports[column.type.fullName];
157
+ zodType = typeImport.name;
158
+ typeImports.push(typeImport);
159
+ }
160
+ return {
161
+ declaration: {
162
+ comment,
163
+ declarationType: "constant",
164
+ exportAs: "named",
165
+ name,
166
+ type: undefined,
167
+ typeImports,
168
+ value: castToSchema
169
+ ? `${zodType} as unknown as z.Schema<${typescriptDeclaration.name}>`
170
+ : `${zodType}.transform(value => value as ${typescriptDeclaration.name})`,
171
+ },
172
+ name,
173
+ originalName: typescriptDeclaration.name,
174
+ };
175
+ });
176
+ }
177
+ export function makeGenerateZodSchemas(config = {}) {
178
+ return async (outputAcc, context) => {
179
+ const kanelContext = useKanelContext();
180
+ const output = { ...outputAcc };
181
+ const getZodSchemaMetadata = config.getZodSchemaMetadata ?? defaultGetZodSchemaMetadata;
182
+ const getZodIdentifierMetadata = config.getZodIdentifierMetadata ?? defaultGetZodIdentifierMetadata;
183
+ const zodTypeMap = { ...defaultZodTypeMap, ...(config.zodTypeMap ?? {}) };
184
+ const castToSchema = config.castToSchema ?? true;
185
+ const nonCompositeTypeImports = {};
186
+ const identifierTypeImports = {};
187
+ const compositeTypeImports = {};
188
+ for (const schema of Object.values(kanelContext.schemas)) {
189
+ schema.enums?.forEach((enumDetails) => {
190
+ const { name, path } = getZodSchemaMetadata(enumDetails, undefined, context);
191
+ appendTsDeclaration(output, path, {
192
+ comment: [`Zod schema for ${enumDetails.name}`],
193
+ declarationType: "constant",
194
+ exportAs: "named",
195
+ name,
196
+ type: undefined,
197
+ typeImports: [zImport],
198
+ value: ["z.enum([", ...enumDetails.values.map((value) => ` '${value}',`), "])"],
199
+ });
200
+ nonCompositeTypeImports[`${enumDetails.schemaName}.${enumDetails.name}`] = {
201
+ asName: undefined,
202
+ importAsType: false,
203
+ isAbsolute: false,
204
+ isDefault: false,
205
+ name,
206
+ path,
207
+ };
208
+ });
209
+ schema.ranges?.forEach((rangeDetails) => {
210
+ const { name, path } = getZodSchemaMetadata(rangeDetails, undefined, context);
211
+ appendTsDeclaration(output, path, {
212
+ comment: [`Zod schema for ${rangeDetails.name}`],
213
+ declarationType: "constant",
214
+ exportAs: "named",
215
+ name,
216
+ type: undefined,
217
+ typeImports: [zImport],
218
+ value: "z.string()",
219
+ });
220
+ nonCompositeTypeImports[`${rangeDetails.schemaName}.${rangeDetails.name}`] = {
221
+ asName: undefined,
222
+ importAsType: false,
223
+ isAbsolute: false,
224
+ isDefault: false,
225
+ name,
226
+ path,
227
+ };
228
+ });
229
+ schema.domains?.forEach((domainDetails) => {
230
+ const { name, path } = getZodSchemaMetadata(domainDetails, undefined, context);
231
+ const domainType = zodTypeMap[domainDetails.innerType] ?? "z.unknown()";
232
+ appendTsDeclaration(output, path, {
233
+ comment: [`Zod schema for ${domainDetails.name}`],
234
+ declarationType: "constant",
235
+ exportAs: "named",
236
+ name,
237
+ type: undefined,
238
+ typeImports: [zImport, ...(typeof domainType === "string" ? [] : domainType.typeImports)],
239
+ value: typeof domainType === "string" ? domainType : domainType.name,
240
+ });
241
+ nonCompositeTypeImports[`${domainDetails.schemaName}.${domainDetails.name}`] = {
242
+ asName: undefined,
243
+ importAsType: false,
244
+ isAbsolute: false,
245
+ isDefault: false,
246
+ name,
247
+ path,
248
+ };
249
+ });
250
+ schema.tables?.forEach((tableDetails) => {
251
+ const { path } = getZodSchemaMetadata(tableDetails, undefined, context);
252
+ const declarations = buildIdentifierDeclarations(tableDetails, getZodIdentifierMetadata, zodTypeMap, castToSchema, nonCompositeTypeImports, context);
253
+ declarations.forEach(({ declaration, name, originalName }) => {
254
+ appendTsDeclaration(output, path, declaration);
255
+ identifierTypeImports[`${tableDetails.schemaName}.${originalName}`] = {
256
+ asName: undefined,
257
+ importAsType: false,
258
+ isAbsolute: false,
259
+ isDefault: false,
260
+ name,
261
+ path,
262
+ };
263
+ });
264
+ });
265
+ [
266
+ ...(schema.tables ?? []),
267
+ ...(schema.views ?? []),
268
+ ...(schema.materializedViews ?? []),
269
+ ...(schema.compositeTypes ?? []),
270
+ ].forEach((compositeDetails) => {
271
+ const { name, path } = getZodSchemaMetadata(compositeDetails, undefined, context);
272
+ compositeTypeImports[`${compositeDetails.schemaName}.${compositeDetails.name}`] = {
273
+ asName: undefined,
274
+ importAsType: false,
275
+ isAbsolute: false,
276
+ isDefault: false,
277
+ name,
278
+ path,
279
+ };
280
+ });
281
+ }
282
+ for (const schema of Object.values(kanelContext.schemas)) {
283
+ ;
284
+ [
285
+ ...(schema.tables ?? []),
286
+ ...(schema.views ?? []),
287
+ ...(schema.materializedViews ?? []),
288
+ ...(schema.compositeTypes ?? []),
289
+ ].forEach((compositeDetails) => {
290
+ const { path } = getZodSchemaMetadata(compositeDetails, undefined, context);
291
+ appendTsDeclaration(output, path, buildCompositeDeclaration(compositeDetails, "selector", nonCompositeTypeImports, compositeTypeImports, identifierTypeImports, getZodSchemaMetadata, zodTypeMap, castToSchema, context));
292
+ if (compositeDetails.kind === "table") {
293
+ appendTsDeclaration(output, path, buildCompositeDeclaration(compositeDetails, "initializer", nonCompositeTypeImports, compositeTypeImports, identifierTypeImports, getZodSchemaMetadata, zodTypeMap, castToSchema, context));
294
+ appendTsDeclaration(output, path, buildCompositeDeclaration(compositeDetails, "mutator", nonCompositeTypeImports, compositeTypeImports, identifierTypeImports, getZodSchemaMetadata, zodTypeMap, castToSchema, context));
295
+ }
296
+ });
297
+ }
298
+ return output;
299
+ };
300
+ }
@@ -1,3 +1,3 @@
1
- import type { Dataset } from "../../datasets";
1
+ import type { Dataset } from "../../datasets.js";
2
2
  export declare function isCopyFromStdinLine(line: string): boolean;
3
3
  export declare function rewriteLineForStagingImport(line: string, dataset: Dataset, stagingSchema: string, inCopyData?: boolean): string;
@@ -1,9 +1,9 @@
1
1
  import commandLineArgs from "command-line-args";
2
2
  import fs from "fs-extra";
3
- import { sql } from "../databases_postgres";
4
- import { getChosenDatasets, getEnabledDatasets } from "../datasets";
5
- import { categoriesOption, silentOption } from "./shared/cli_helpers";
6
- import { extractPrefixedTableNamesFromGeneratedManifest, getGeneratedTableManifestPath, senatSchemaName, } from "./shared/prefixed_tables";
3
+ import { sql } from "../databases_postgres.js";
4
+ import { getChosenDatasets, getEnabledDatasets } from "../datasets.js";
5
+ import { categoriesOption, silentOption } from "./shared/cli_helpers.js";
6
+ import { extractPrefixedTableNamesFromGeneratedManifest, getGeneratedTableManifestPath, senatSchemaName, } from "./shared/prefixed_tables.js";
7
7
  const optionsDefinitions = [categoriesOption, silentOption];
8
8
  const options = commandLineArgs(optionsDefinitions);
9
9
  async function listPrefixedSenatTables(dataset) {
@@ -1,5 +1,5 @@
1
- import { TxtAmeli } from "../raw_types/ameli";
2
- import { Sub } from "../raw_types/ameli";
1
+ import { TxtAmeli } from "../raw_types/ameli.js";
2
+ import { Sub } from "../raw_types/ameli.js";
3
3
  export interface TxtAmeliCustom extends TxtAmeli {
4
4
  subids?: Sub["id"][];
5
5
  }
@@ -1,7 +1,7 @@
1
- import { Ass, Aud as AudRaw, Auteur as AuteurRaw, DateSeance as DateSeanceRaw, Deccoc, Denrap, Docatt as DocattRaw, Ecr as EcrRaw, Etaloi, Lecass as LecassRaw, Lecassrap as LecassrapRaw, Lecture as LectureRaw, Loi as LoiRaw, Org, Oritxt, Qua, Rap as RapRaw, Raporg, Scr, Texte as TexteRaw, Typatt, Typlec, Typloi, Typtxt, Typurl } from "../raw_types/dosleg";
2
- import { TxtAmeli } from "../raw_types/ameli";
3
- import { Debats } from "../raw_types/debats";
4
- import { TxtAmeliCustom } from "./ameli";
1
+ import { Ass, Aud as AudRaw, Auteur as AuteurRaw, DateSeance as DateSeanceRaw, Deccoc, Denrap, Docatt as DocattRaw, Ecr as EcrRaw, Etaloi, Lecass as LecassRaw, Lecassrap as LecassrapRaw, Lecture as LectureRaw, Loi as LoiRaw, Org, Oritxt, Qua, Rap as RapRaw, Raporg, Scr, Texte as TexteRaw, Typatt, Typlec, Typloi, Typtxt, Typurl } from "../raw_types/dosleg.js";
2
+ import { TxtAmeli } from "../raw_types/ameli.js";
3
+ import { Debats } from "../raw_types/debats.js";
4
+ import { TxtAmeliCustom } from "./ameli.js";
5
5
  export type { Deccoc as DecCoc, Denrap as DenRap, Etaloi as EtaLoi, Oritxt as OriTxt, Raporg as RapOrg, Typatt as TypAtt, Typlec as TypLec, Typloi as TypLoi, Typtxt as TypTxt, Typurl as TypUrl, };
6
6
  export interface Aud extends AudRaw {
7
7
  org?: Org;
@@ -1,2 +1,2 @@
1
- import { TamQuestions } from "../raw_types/questions";
1
+ import { TamQuestions } from "../raw_types/questions.js";
2
2
  export type { TamQuestions as Question };
@@ -1,4 +1,4 @@
1
- import { DocumentResult } from "../loaders";
1
+ import { DocumentResult } from "../loaders.js";
2
2
  export declare enum DivisionType {
3
3
  tome = 1,
4
4
  part = 2,
@@ -1,4 +1,4 @@
1
- import { Reunion } from "../types/agenda";
1
+ import { Reunion } from "../types/agenda.js";
2
2
  type MetadataDay = {
3
3
  date: string;
4
4
  openTime?: string;