From 98f7fd4e83dd4ec23df1864d5788a3dd70491171 Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Tue, 14 Feb 2023 18:20:40 +0100 Subject: [PATCH] Validate JORF TEXTE_VERSION & TEXTELR --- src/lib/auditors/jorf/index.ts | 2 + src/lib/auditors/jorf/jo.ts | 1 + src/lib/auditors/jorf/texte_version.ts | 916 +++++++++++++++++++++++++ src/lib/auditors/jorf/textelr.ts | 666 ++++++++++++++++++ src/lib/auditors/legi/articles.ts | 15 +- src/lib/index.ts | 51 +- src/lib/legal/index.ts | 36 +- src/lib/legal/jorf.ts | 527 +++++++++++++- src/lib/legal/legi.ts | 9 +- src/lib/legal/shared.ts | 4 + src/scripts/import_jorf.ts | 59 +- 11 files changed, 2244 insertions(+), 42 deletions(-) create mode 100644 src/lib/auditors/jorf/texte_version.ts create mode 100644 src/lib/auditors/jorf/textelr.ts create mode 100644 src/lib/legal/shared.ts diff --git a/src/lib/auditors/jorf/index.ts b/src/lib/auditors/jorf/index.ts index bd35cdc..bebaefd 100644 --- a/src/lib/auditors/jorf/index.ts +++ b/src/lib/auditors/jorf/index.ts @@ -1,3 +1,5 @@ export { auditJo, joStats } from "./jo" export { auditJorfArticle, jorfArticleStats } from "./articles" export { auditJorfSectionTa, jorfSectionTaStats } from "./section_ta" +export { auditJorfTextelr, jorfTextelrStats } from "./textelr" +export { auditJorfTexteVersion, jorfTexteVersionStats } from "./texte_version" diff --git a/src/lib/auditors/jorf/jo.ts b/src/lib/auditors/jorf/jo.ts index efb4c84..e77676a 100644 --- a/src/lib/auditors/jorf/jo.ts +++ b/src/lib/auditors/jorf/jo.ts @@ -39,6 +39,7 @@ export function auditJo( const data = { ...dataUnknown } const errors: { [key: string]: unknown } = {} const remainingKeys = new Set(Object.keys(data)) + audit.attribute( data, "META", diff --git a/src/lib/auditors/jorf/texte_version.ts b/src/lib/auditors/jorf/texte_version.ts new file mode 100644 index 0000000..7b01390 --- /dev/null +++ b/src/lib/auditors/jorf/texte_version.ts @@ -0,0 +1,916 @@ +import { + auditCleanArray, + auditDateIso8601String, + auditEmptyToNull, + auditFunction, + auditHttpUrl, + auditInteger, + auditNullish, + auditNumber, + auditOptions, + auditRequire, + auditSwitch, + auditTrimString, + type Audit, +} from "@auditors/core" + +import { + allJorfTexteVersionLienNaturesMutable, + allJorfTexteVersionLienTypesMutable, + allJorfTexteVersionNaturesMutable, + allJorfTexteVersionOriginesMutable, + allSensMutable, +} from "$lib/legal" + +export const jorfTexteVersionStats: { + countByLienNature: { [nature: string]: number } + countByLienType: { [type: string]: number } + countByNature: { [nature: string]: number } + countByOrigine: { [origine: string]: number } +} = { + countByLienNature: {}, + countByLienType: {}, + countByNature: {}, + countByOrigine: {}, +} + +function auditAbro(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditDatesEffet( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "DATE_EFFET", + true, + errors, + remainingKeys, + auditFunction((date) => (Array.isArray(date) ? date : [date])), + auditCleanArray(auditDateIso8601String, auditRequire), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditDomaines(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "DOMAINE", + true, + errors, + remainingKeys, + auditFunction((domaine) => (Array.isArray(domaine) ? domaine : [domaine])), + auditCleanArray(auditTrimString, auditEmptyToNull, auditRequire), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditEliAlias(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "ID_ELI_ALIAS", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditHttpUrl, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditEntreprise( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "@texte_entreprise", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditOptions(["non", "oui"]), + auditRequire, + ) + audit.attribute( + data, + "DATES_EFFET", + true, + errors, + remainingKeys, + auditSwitch( + [auditTrimString, auditEmptyToNull, auditNullish], + auditDatesEffet, + ), + ) + audit.attribute( + data, + "DOMAINES", + true, + errors, + remainingKeys, + auditSwitch( + [auditTrimString, auditEmptyToNull, auditNullish], + auditDomaines, + ), + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +export function auditJorfTexteVersion( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "ABRO", + true, + errors, + remainingKeys, + auditAbro, + auditEmptyToNull, + ) + audit.attribute( + data, + "ENTREPRISE", + true, + errors, + remainingKeys, + auditEntreprise, + auditEmptyToNull, + ) + audit.attribute( + data, + "META", + true, + errors, + remainingKeys, + auditMeta, + auditRequire, + ) + audit.attribute( + data, + "NOTICE", + true, + errors, + remainingKeys, + auditNotice, + auditEmptyToNull, + ) + audit.attribute( + data, + "RECT", + true, + errors, + remainingKeys, + auditRect, + auditEmptyToNull, + ) + audit.attribute( + data, + "SIGNATAIRES", + true, + errors, + remainingKeys, + auditSignataires, + auditEmptyToNull, + ) + audit.attribute( + data, + "SM", + true, + errors, + remainingKeys, + auditSm, + auditEmptyToNull, + ) + audit.attribute( + data, + "TP", + true, + errors, + remainingKeys, + auditTp, + auditEmptyToNull, + ) + audit.attribute( + data, + "VISAS", + true, + errors, + remainingKeys, + auditVisas, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "#text", + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditFunction((num) => num.toString())], + [auditTrimString, auditEmptyToNull], + ), + ) + for (const key of ["@cidtexte", "@id"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + audit.attribute( + data, + "@datesignatexte", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditDateIso8601String, + ) + audit.attribute( + data, + "@naturetexte", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((nature) => { + // jorfTexteVersionStats.countByLienNature[nature] = + // (jorfTexteVersionStats.countByLienNature[nature] ?? 0) + 1 + // return nature + // }), + auditOptions(allJorfTexteVersionLienNaturesMutable), + ) + for (const key of ["@num", "@nortexte", "@numtexte"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + audit.attribute( + data, + "@sens", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditOptions(allSensMutable), + auditRequire, + ) + audit.attribute( + data, + "@typelien", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((type) => { + // jorfTexteVersionStats.countByLienType[type] = + // (jorfTexteVersionStats.countByLienType[type] ?? 0) + 1 + // return type + // }), + auditOptions(allJorfTexteVersionLienTypesMutable), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditLiens(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "LIEN", + true, + errors, + remainingKeys, + auditFunction((lien) => (Array.isArray(lien) ? lien : [lien])), + auditCleanArray(auditLien, auditRequire), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +/// Mots-clés du texte +function auditMcsTxt(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "MC", + true, + errors, + remainingKeys, + auditFunction((lien) => (Array.isArray(lien) ? lien : [lien])), + auditCleanArray( + auditSwitch( + [auditNumber, auditFunction((num) => num.toString())], + [auditTrimString, auditEmptyToNull], + ), + ), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMeta(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "META_COMMUN", + true, + errors, + remainingKeys, + auditMetaCommun, + auditRequire, + ) + audit.attribute( + data, + "META_SPEC", + true, + errors, + remainingKeys, + auditMetaSpec, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaCommun( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "ANCIEN_ID", + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditFunction((id) => id.toString())], + [auditTrimString, auditEmptyToNull], + ), + ) + audit.attribute(data, "ELI_ALIAS", true, errors, remainingKeys, auditEliAlias) + for (const key of ["ID", "URL"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + audit.attribute( + data, + "ID_ELI", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditHttpUrl, + ) + audit.attribute( + data, + "NATURE", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((nature) => { + // jorfTexteVersionStats.countByNature[nature] = + // (jorfTexteVersionStats.countByNature[nature] ?? 0) + 1 + // return nature + // }), + auditOptions(allJorfTexteVersionNaturesMutable), + ) + audit.attribute( + data, + "ORIGINE", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((origine) => { + // jorfTexteVersionStats.countByOrigine[origine] = + // (jorfTexteVersionStats.countByOrigine[origine] ?? 0) + 1 + // return origine + // }), + auditOptions(allJorfTexteVersionOriginesMutable), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaSpec(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "META_TEXTE_CHRONICLE", + true, + errors, + remainingKeys, + auditMetaTexteChronicle, + auditRequire, + ) + audit.attribute( + data, + "META_TEXTE_VERSION", + true, + errors, + remainingKeys, + auditMetaTexteVersion, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaTexteChronicle( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + for (const key of ["CID"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + for (const key of ["DATE_PUBLI", "DATE_TEXTE"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditFunction((date) => date.replace(/^11992-12-27$/, "1992-12-27")), + auditDateIso8601String, + auditRequire, + ) + } + for (const key of ["NOR", "NUM"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditFunction((num) => num.toString())], + [auditTrimString, auditEmptyToNull], + ), + ) + } + for (const key of [ + "NUM_PARUTION", + "NUM_SEQUENCE", + "PAGE_DEB_PUBLI", + "PAGE_FIN_PUBLI", + ]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditInteger], + [auditTrimString, auditEmptyToNull, auditNullish], + ), + ) + } + for (const key of ["ORIGINE_PUBLI"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaTexteVersion( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + for (const key of ["AUTORITE", "MINISTERE", "TITRE"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + for (const key of ["DATE_DEBUT", "DATE_FIN"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditDateIso8601String, + ) + } + audit.attribute( + data, + "LIENS", + true, + errors, + remainingKeys, + auditSwitch(auditTrimString, auditLiens), + auditEmptyToNull, + ) + audit.attribute( + data, + "MCS_TXT", + true, + errors, + remainingKeys, + auditSwitch([auditTrimString, auditEmptyToNull, auditNullish], auditMcsTxt), + ) + for (const key of ["TITREFULL"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditNotice(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditRect(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditSignataires( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditSm(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditFunction((num) => num.toString())], + [auditTrimString, auditEmptyToNull], + ), + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditTp(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditVisas(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "CONTENU", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} diff --git a/src/lib/auditors/jorf/textelr.ts b/src/lib/auditors/jorf/textelr.ts new file mode 100644 index 0000000..8a6a53e --- /dev/null +++ b/src/lib/auditors/jorf/textelr.ts @@ -0,0 +1,666 @@ +import { + auditCleanArray, + auditDateIso8601String, + auditEmptyToNull, + auditFunction, + auditHttpUrl, + auditInteger, + auditNullish, + auditNumber, + auditOptions, + auditRequire, + auditStringToNumber, + auditSwitch, + auditTrimString, + type Audit, +} from "@auditors/core" + +import { + allJorfTextelrEtatsMutable, + allJorfTextelrLienArtEtatsMutable, + // allJorfTextelrLienArtNaturesMutable, + allJorfTextelrLienArtOriginesMutable, + allJorfTextelrNaturesMutable, + allJorfTextelrOriginesMutable, +} from "$lib/legal" + +export const jorfTextelrStats: { + countByEtat: { [etat: string]: number } + countByLienArtEtat: { [etat: string]: number } + countByLienArtNature: { [nature: string]: number } + countByLienArtOrigine: { [origine: string]: number } + countByNature: { [nature: string]: number } + countByOrigine: { [origine: string]: number } +} = { + countByEtat: {}, + countByLienArtEtat: {}, + countByLienArtNature: {}, + countByLienArtOrigine: {}, + countByNature: {}, + countByOrigine: {}, +} + +function auditEliAlias(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "ID_ELI_ALIAS", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditHttpUrl, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +export function auditJorfTextelr( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "META", + true, + errors, + remainingKeys, + auditMeta, + auditRequire, + ) + audit.attribute( + data, + "STRUCT", + true, + errors, + remainingKeys, + auditSwitch([auditTrimString, auditEmptyToNull, auditNullish], auditStruct), + ) + audit.attribute( + data, + "VERSIONS", + true, + errors, + remainingKeys, + auditVersions, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditLienArt(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + for (const key of ["@debut", "@fin"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditDateIso8601String, + auditRequire, + ) + } + audit.attribute( + data, + "@etat", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((etat) => { + // jorfTextelrStats.countByLienArtEtat[etat] = + // (jorfTextelrStats.countByLienArtEtat[etat] ?? 0) + 1 + // return etat + // }), + auditOptions(allJorfTextelrLienArtEtatsMutable), + ) + for (const key of ["@id"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + audit.attribute( + data, + "@nature", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((nature) => { + // jorfTextelrStats.countByLienArtNature[nature] = + // (jorfTextelrStats.countByLienArtNature[nature] ?? 0) + 1 + // return nature + // }), + // auditOptions(allJorfTextelrLienArtNaturesMutable), + auditNullish, + ) + for (const key of ["@num"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + audit.attribute( + data, + "@origine", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((origine) => { + // jorfTextelrStats.countByLienArtOrigine[origine] = + // (jorfTextelrStats.countByLienArtOrigine[origine] ?? 0) + 1 + // return origine + // }), + auditOptions(allJorfTextelrLienArtOriginesMutable), + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditLienSectionTa( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + for (const key of ["#text"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + for (const key of ["@cid", "@id", "@url"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + for (const key of ["@debut", "@fin"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditDateIso8601String, + auditRequire, + ) + } + audit.attribute( + data, + "@etat", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditNullish, + // auditFunction((etat) => { + // jorfSectionTaStats.countByLienSectionTaEtat[etat] = + // (jorfSectionTaStats.countByLienSectionTaEtat[etat] ?? 0) + 1 + // return etat + // }), + // auditOptions(allJorfSectionTaLienSectionTaEtatsMutable), + ) + audit.attribute( + data, + "@niv", + true, + errors, + remainingKeys, + auditStringToNumber, + auditInteger, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditLienTxt(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + for (const key of ["@debut", "@fin"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditDateIso8601String, + auditRequire, + ) + } + for (const key of ["@id"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + for (const key of ["@num"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMeta(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "META_COMMUN", + true, + errors, + remainingKeys, + auditMetaCommun, + auditRequire, + ) + audit.attribute( + data, + "META_SPEC", + true, + errors, + remainingKeys, + auditMetaSpec, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaCommun( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "ANCIEN_ID", + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditFunction((id) => id.toString())], + [auditTrimString, auditEmptyToNull], + ), + ) + audit.attribute(data, "ELI_ALIAS", true, errors, remainingKeys, auditEliAlias) + for (const key of ["ID", "URL"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + audit.attribute( + data, + "ID_ELI", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditHttpUrl, + ) + audit.attribute( + data, + "NATURE", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((nature) => { + // jorfTextelrStats.countByNature[nature] = + // (jorfTextelrStats.countByNature[nature] ?? 0) + 1 + // return nature + // }), + auditOptions(allJorfTextelrNaturesMutable), + ) + audit.attribute( + data, + "ORIGINE", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((origine) => { + // jorfTextelrStats.countByOrigine[origine] = + // (jorfTextelrStats.countByOrigine[origine] ?? 0) + 1 + // return origine + // }), + auditOptions(allJorfTextelrOriginesMutable), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaSpec(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "META_TEXTE_CHRONICLE", + true, + errors, + remainingKeys, + auditMetaTexteChronicle, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditMetaTexteChronicle( + audit: Audit, + dataUnknown: unknown, +): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + for (const key of ["CID"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + auditRequire, + ) + } + for (const key of ["DATE_PUBLI", "DATE_TEXTE"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditFunction((date) => date.replace(/^11992-12-27$/, "1992-12-27")), + auditDateIso8601String, + auditRequire, + ) + } + for (const key of ["NOR", "NUM"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditFunction((num) => num.toString())], + [auditTrimString, auditEmptyToNull], + ), + ) + } + for (const key of [ + "NUM_PARUTION", + "NUM_SEQUENCE", + "PAGE_DEB_PUBLI", + "PAGE_FIN_PUBLI", + ]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditSwitch( + [auditNumber, auditInteger], + [auditTrimString, auditEmptyToNull, auditNullish], + ), + ) + } + for (const key of ["ORIGINE_PUBLI"]) { + audit.attribute( + data, + key, + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + ) + } + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditStruct(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "LIEN_ART", + true, + errors, + remainingKeys, + auditFunction((lien) => (Array.isArray(lien) ? lien : [lien])), + auditCleanArray(auditLienArt, auditRequire), + ) + audit.attribute( + data, + "LIEN_SECTION_TA", + true, + errors, + remainingKeys, + auditFunction((lien) => (Array.isArray(lien) ? lien : [lien])), + auditCleanArray(auditLienSectionTa, auditRequire), + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditVersion(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "@etat", + true, + errors, + remainingKeys, + auditTrimString, + auditEmptyToNull, + // auditFunction((etat) => { + // jorfTextelrStats.countByEtat[etat] = + // (jorfTextelrStats.countByEtat[etat] ?? 0) + 1 + // return etat + // }), + auditOptions(allJorfTextelrEtatsMutable), + ) + audit.attribute( + data, + "LIEN_TXT", + true, + errors, + remainingKeys, + auditLienTxt, + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} + +function auditVersions(audit: Audit, dataUnknown: unknown): [unknown, unknown] { + if (dataUnknown == null) { + return [dataUnknown, null] + } + if (typeof dataUnknown !== "object") { + return audit.unexpectedType(dataUnknown, "object") + } + + const data = { ...dataUnknown } + const errors: { [key: string]: unknown } = {} + const remainingKeys = new Set(Object.keys(data)) + + audit.attribute( + data, + "VERSION", + true, + errors, + remainingKeys, + auditFunction((version) => (Array.isArray(version) ? version : [version])), + auditCleanArray(auditVersion, auditRequire), + auditRequire, + ) + + return audit.reduceRemaining(data, errors, remainingKeys) +} diff --git a/src/lib/auditors/legi/articles.ts b/src/lib/auditors/legi/articles.ts index ea2cee5..2a6f674 100644 --- a/src/lib/auditors/legi/articles.ts +++ b/src/lib/auditors/legi/articles.ts @@ -16,12 +16,12 @@ import { import { allLegiArticleEtatsMutable, allLegiArticleLienNaturesMutable, - allLegiArticleLienSensMutable, allLegiArticleLienTypesMutable, allLegiArticleNaturesMutable, allLegiArticleOriginesMutable, allLegiArticleTexteNaturesMutable, allLegiArticleTypesMutable, + allSensMutable, } from "$lib/legal" export const legiArticleStats: { @@ -189,7 +189,7 @@ function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] { [auditTrimString, auditEmptyToNull], ), ) - for (const key of ["@cidtexte", "@id", "@nortexte", "@num"]) { + for (const key of ["@cidtexte", "@id", "@nortexte", "@num", "@numtexte"]) { audit.attribute( data, key, @@ -225,15 +225,6 @@ function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] { // }), auditOptions(allLegiArticleLienNaturesMutable), ) - audit.attribute( - data, - "@numtexte", - true, - errors, - remainingKeys, - auditTrimString, - auditEmptyToNull, - ) audit.attribute( data, "@sens", @@ -242,7 +233,7 @@ function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] { remainingKeys, auditTrimString, auditEmptyToNull, - auditOptions(allLegiArticleLienSensMutable), + auditOptions(allSensMutable), auditRequire, ) audit.attribute( diff --git a/src/lib/index.ts b/src/lib/index.ts index 172c7fb..949e12e 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -36,14 +36,40 @@ export { allJorfArticleTexteNaturesMutable, allJorfArticleTypes, allJorfArticleTypesMutable, + allJorfSectionTaLienArtEtats, + allJorfSectionTaLienArtEtatsMutable, + allJorfSectionTaLienArtOrigines, + allJorfSectionTaLienArtOriginesMutable, + allJorfSectionTaLienSectionTaEtats, + allJorfSectionTaLienSectionTaEtatsMutable, + allJorfSectionTaTexteNatures, + allJorfSectionTaTexteNaturesMutable, + allJorfTextelrEtats, + allJorfTextelrEtatsMutable, + allJorfTextelrLienArtEtats, + allJorfTextelrLienArtEtatsMutable, + allJorfTextelrLienArtNatures, + allJorfTextelrLienArtNaturesMutable, + allJorfTextelrLienArtOrigines, + allJorfTextelrLienArtOriginesMutable, + allJorfTextelrNatures, + allJorfTextelrNaturesMutable, + allJorfTextelrOrigines, + allJorfTextelrOriginesMutable, + allJorfTexteVersionLienNatures, + allJorfTexteVersionLienNaturesMutable, + allJorfTexteVersionLienTypes, + allJorfTexteVersionLienTypesMutable, + allJorfTexteVersionNatures, + allJorfTexteVersionNaturesMutable, + allJorfTexteVersionOrigines, + allJorfTexteVersionOriginesMutable, allLegiArticleEtats, allLegiArticleEtatsMutable, allLegiArticleLienArticleOrigines, allLegiArticleLienArticleOriginesMutable, allLegiArticleLienNatures, allLegiArticleLienNaturesMutable, - allLegiArticleLienSens, - allLegiArticleLienSensMutable, allLegiArticleNatures, allLegiArticleNaturesMutable, allLegiArticleOrigines, @@ -52,7 +78,10 @@ export { allLegiArticleTexteNaturesMutable, allLegiArticleTypes, allLegiArticleTypesMutable, + allSens, + allSensMutable, type DossierLegislatif, + type Jo, type JoNature, type JoOrigine, type JorfArticle, @@ -62,15 +91,30 @@ export { type JorfArticleOrigine, type JorfArticleTexteNature, type JorfArticleType, + type JorfSectionTa, + type JorfSectionTaLienArtEtat, + type JorfSectionTaTexteNature, + type JorfTextelr, + type JorfTextelrEtat, + type JorfTextelrLienArtEtat, + type JorfTextelrLienArtNature, + type JorfTextelrLienArtOrigine, + type JorfTextelrNature, + type JorfTextelrOrigine, + type JorfTexteVersion, + type JorfTexteVersionLienNature, + type JorfTexteVersionLienType, + type JorfTexteVersionNature, + type JorfTexteVersionOrigine, type LegiArticle, type LegiArticleEtat, type LegiArticleLienArticleOrigine, type LegiArticleLienNature, - type LegiArticleLienSens, type LegiArticleNature, type LegiArticleOrigine, type LegiArticleTexteNature, type LegiArticleType, + type Sens, } from "./legal" export { @@ -80,7 +124,6 @@ export { type Contexte, type Etat, type Idcc, - type Jo, type LegalObject, type LegalObjectType, type Lien, diff --git a/src/lib/legal/index.ts b/src/lib/legal/index.ts index c833c1e..c898eff 100644 --- a/src/lib/legal/index.ts +++ b/src/lib/legal/index.ts @@ -30,6 +30,26 @@ export { allJorfSectionTaLienSectionTaEtatsMutable, allJorfSectionTaTexteNatures, allJorfSectionTaTexteNaturesMutable, + allJorfTextelrEtats, + allJorfTextelrEtatsMutable, + allJorfTextelrLienArtEtats, + allJorfTextelrLienArtEtatsMutable, + allJorfTextelrLienArtNatures, + allJorfTextelrLienArtNaturesMutable, + allJorfTextelrLienArtOrigines, + allJorfTextelrLienArtOriginesMutable, + allJorfTextelrNatures, + allJorfTextelrNaturesMutable, + allJorfTextelrOrigines, + allJorfTextelrOriginesMutable, + allJorfTexteVersionLienNatures, + allJorfTexteVersionLienNaturesMutable, + allJorfTexteVersionLienTypes, + allJorfTexteVersionLienTypesMutable, + allJorfTexteVersionNatures, + allJorfTexteVersionNaturesMutable, + allJorfTexteVersionOrigines, + allJorfTexteVersionOriginesMutable, type Jo, type JoNature, type JoOrigine, @@ -43,6 +63,18 @@ export { type JorfSectionTa, type JorfSectionTaLienArtEtat, type JorfSectionTaTexteNature, + type JorfTextelr, + type JorfTextelrEtat, + type JorfTextelrLienArtEtat, + type JorfTextelrLienArtNature, + type JorfTextelrLienArtOrigine, + type JorfTextelrNature, + type JorfTextelrOrigine, + type JorfTexteVersion, + type JorfTexteVersionLienNature, + type JorfTexteVersionLienType, + type JorfTexteVersionNature, + type JorfTexteVersionOrigine, } from "./jorf" export { allLegiArticleEtats, @@ -51,8 +83,6 @@ export { allLegiArticleLienArticleOriginesMutable, allLegiArticleLienNatures, allLegiArticleLienNaturesMutable, - allLegiArticleLienSens, - allLegiArticleLienSensMutable, allLegiArticleLienTypes, allLegiArticleLienTypesMutable, allLegiArticleNatures, @@ -67,13 +97,13 @@ export { type LegiArticleEtat, type LegiArticleLienArticleOrigine, type LegiArticleLienNature, - type LegiArticleLienSens, type LegiArticleLienType, type LegiArticleNature, type LegiArticleOrigine, type LegiArticleTexteNature, type LegiArticleType, } from "./legi" +export { allSens, allSensMutable, type Sens } from "./shared" export interface Article { META: { diff --git a/src/lib/legal/jorf.ts b/src/lib/legal/jorf.ts index afe53cb..754e988 100644 --- a/src/lib/legal/jorf.ts +++ b/src/lib/legal/jorf.ts @@ -1,3 +1,5 @@ +import type { Sens } from "./shared" + export interface Jo { META: { META_COMMUN: { @@ -116,9 +118,9 @@ export interface JorfArticleTm { export type JorfArticleType = (typeof allJorfArticleTypes)[number] export interface JorfSectionTa { + ID: string COMMENTAIRE?: string CONTEXTE: { - ID: string TEXTE: { "@autorite"?: string "@cid": string @@ -184,6 +186,120 @@ interface JorfSectionTaTm { TM?: JorfSectionTaTm } +export interface JorfTextelr { + // TODO +} + +export type JorfTextelrEtat = (typeof allJorfTextelrEtats)[number] + +export type JorfTextelrLienArtEtat = (typeof allJorfTextelrLienArtEtats)[number] + +export type JorfTextelrLienArtNature = + (typeof allJorfTextelrLienArtNatures)[number] + +export type JorfTextelrLienArtOrigine = + (typeof allJorfTextelrLienArtOrigines)[number] + +export type JorfTextelrNature = (typeof allJorfTextelrNatures)[number] + +export type JorfTextelrOrigine = (typeof allJorfTextelrOrigines)[number] + +export interface JorfTexteVersion { + ABRO?: { + CONTENU: string // HTML + } + ENTREPRISE?: { + "@texte_entreprise": "non" | "oui" + DATES_EFFET?: { + DATE_EFFET: string[] + } + DOMAINES?: { + DOMAINE: string[] + } + } + META: { + META_COMMUN: { + ANCIEN_ID?: string + ELI_ALIAS?: { + ID_ELI_ALIAS: string + } + ID: string + ID_ELI?: string + NATURE?: JorfTexteVersionNature + ORIGINE: JorfTexteVersionOrigine + URL: string + } + META_SPEC: { + META_TEXTE_CHRONICLE: { + CID: string + DATE_PUBLI: string + DATE_TEXTE: string + NOR?: string + NUM?: string + NUM_PARUTION?: number + NUM_SEQUENCE?: number + ORIGINE_PUBLI?: string + PAGE_DEB_PUBLI?: number + PAGE_FIN_PUBLI?: number + } + META_TEXTE_VERSION: { + AUTORITE?: string + DATE_DEBUT: string + DATE_FIN: string + LIENS?: { + LIEN: { + "#text"?: string + "@cidtexte"?: string + "@datesignatexte"?: string + "@id"?: string + "@naturetexte"?: JorfTexteVersionLienNature + "@num"?: string + "@nortexte"?: string + "@numtexte"?: string + "@sens": Sens + "@typelien": JorfTexteVersionLienType + } + } + MCS_TXT?: { + MC: string[] + } + MINISTERE?: string + TITRE: string + TITREFULL: string + } + } + } + NOTICE?: { + CONTENU: string // HTML + } + RECT?: { + CONTENU: string // HTML + } + SIGNATAIRES?: { + CONTENU: string // HTML + } + SM?: { + CONTENU: string // HTML + } + TP?: { + CONTENU: string // HTML + } + VISAS?: { + CONTENU: string // HTML + } +} + +export type JorfTexteVersionLienNature = + (typeof allJorfTexteVersionLienNatures)[number] + +export type JorfTexteVersionLienType = + (typeof allJorfTexteVersionLienTypes)[number] + +export type JorfTexteVersionNature = (typeof allJorfTexteVersionNatures)[number] + +export type JorfTexteVersionOrigine = + (typeof allJorfTexteVersionOrigines)[number] + /// Table des matières (TM) d'un Journal officiel export interface JoTm { "@niv": number @@ -199,15 +315,15 @@ export const allJoOrigines = ["JORF"] as const export const allJoOriginesMutable = [...allJoOrigines] export const allJorfArticleEtats = [ - "ABROGE", "ABROGE_DIFF", + "ABROGE", "ANNULE", - "MODIFIE", "MODIFIE_MORT_NE", + "MODIFIE", "PERIME", "TRANSFERE", - "VIGUEUR", "VIGUEUR_DIFF", + "VIGUEUR", ] as const export const allJorfArticleEtatsMutable = [...allJorfArticleEtats] @@ -353,3 +469,406 @@ export const allJorfSectionTaTexteNatures = [ export const allJorfSectionTaTexteNaturesMutable = [ ...allJorfSectionTaTexteNatures, ] + +export const allJorfTextelrEtats = [ + "ABROGE_DIFF", // 129 + "ABROGE", // 21890 + "ANNULE", // 199 + "MODIFIE_MORT_NE", // 24 + "MODIFIE", // 3008 + "PERIME", // 3127 + "VIGUEUR_DIFF", // 103 + "VIGUEUR", // 98711 +] as const +export const allJorfTextelrEtatsMutable = [...allJorfTextelrEtats] + +export const allJorfTextelrLienArtEtats = ["VIGUEUR"] as const +export const allJorfTextelrLienArtEtatsMutable = [...allJorfTextelrLienArtEtats] + +export const allJorfTextelrLienArtNatures = [] as const +export const allJorfTextelrLienArtNaturesMutable = [ + ...allJorfTextelrLienArtNatures, +] + +export const allJorfTextelrLienArtOrigines = ["JORF"] as const +export const allJorfTextelrLienArtOriginesMutable = [ + ...allJorfTextelrLienArtOrigines, +] + +export const allJorfTextelrNatures = [ + "ABROGATION", // 8 + "Accord multilatéral", // 1 + "ACCORD_FONCTION_PUBLIQUE", // 4 + "ACCORD", // 46 + "ACTE", // 3 + "ADDITIF", // 131 + "ANNEXE", // 1 + "ANNONCES", // 756 + "ARRANGEMENT", // 1 + "ARRET", // 65 + "ARRETE", // 615239 + "ARRETEAVIS", // 1 + "ARRETEEURO", // 14 + "ARRETEURO", // 556 + "ATTESTATION", // 1 + "AVENANT", // 186 + "AVIS", // 97999 + "AVISEURO", // 4618 + "CANDIDAT", // 2 + "CHARTE", // 1 + "CIRCULAIRE", // 3532 + "CITATION", // 494 + "CODE", // 58 + "COMMUNIQUE", // 17 + "COMPLEMENT", // 2 + "COMPOSITION", // 9 + "CONSTITUTION", // 4 + "CONTRAT", // 2 + "CONVENTION", // 151 + "DATE", // 1 + "DECISION_CC", // 96 + "DECISION_EURO", // 550 + "DECISION", // 67164 + "DECLARATION", // 20 + "DECLARATIONEURO", // 18 + "DECRET_LOI", // 660 + "DECRET", // 209363 + "DELEGATION", // 1 + "DELIBERATION", // 3993 + "DELIBERATIONEURO", // 36 + "DEUXIEME", // 5 + "DIRECTIVE_EURO", // 4249 + "DIRECTIVE", // 13 + "DISPOSITIONS", // 1 + "ELECTION", // 1 + "ELECTIONDUPRESIDENTDELAREPUBLIQU", // 2 + "EXEQUATUR", // 174 + "INFORMATION", // 106 + "INFORMATIONEURO", // 1 + "INFORMATIONS_CESE", // 285 + "INFORMATIONS_DIVERSES", // 524 + "INFORMATIONS_PARLEMENTAIRES", // 6042 + "INSTRUCTION", // 158 + "INSTRUCTIONEURO", // 524 + "LETTRE", // 13 + "LETTREEURO", // 15 + "LISTE", // 5552 + "LOI_CONSTIT", // 12 + "LOI_ORGANIQUE", // 105 + "LOI_PROGRAMME", // 2 + "LOI", // 12859 + "MEMOIRE", // 63 + "MESSAGE", // 2 + "MODIFICATION", // 497 + "NOTE", // 3 + "OBSERVATION", // 288 + "ORDONNANCE", // 3282 + "PREMIER", // 1 + "PROCLAMATION", // 3 + "PROJET", // 3 + "PROPOSITION", // 6 + "PROTOCOLE", // 16 + "PUBLICATION", // 2 + "RAPPORT", // 1968 + "RECOMMANDATION", // 126 + "RECTIFICATIF", // 3 + "REGLEMENT", // 902 + "REGLEMENTEUROPEEN", // 571 + "RELEVE", // 3 + "REMISE", // 121 + "RESULTATS", // 14479 + "SAISINE", // 392 + "SENATUS", // 2 + "SUSPENSION", // 1 + "TABLEAU", // 1092 + "TRAITE", // 5 + "TROISIEME", // 2 + "VOCABULAIRE", // 169 +] as const +export const allJorfTextelrNaturesMutable = [...allJorfTextelrNatures] + +export const allJorfTextelrOrigines = ["JORF"] as const +export const allJorfTextelrOriginesMutable = [...allJorfTextelrOrigines] + +export const allJorfTexteVersionLienNatures = [ + "ABROGATION", // 5 + "Accord autonome", // 3 + "ACCORD CADRE", // 1 + "Accord collectif national sectoriel", // 7 + "Accord collectif national", // 50 + "ACCORD COLLECTIF NATIONAL", // 57 + "Accord collectif", // 6 + "ACCORD DE BRANCHE", // 1 + "Accord de branche", // 24 + "Accord de champ", // 1 + "Accord de convergence", // 3 + "Accord de méthode", // 23 + "Accord de rattachement", // 1 + "Accord de substitution", // 12 + "Accord du", // 1 + "Accord interbranches", // 5 + "Accord interprétatif", // 3 + "Accord interprofessionnel départemental", // 1 + "Accord interprofessionnel", // 8 + "Accord national de branche", // 45 + "Accord national interprofessionnel", // 6 + "ACCORD NATIONAL PARITAIRE", // 16 + "Accord national professionnel", // 1 + "ACCORD NATIONAL PROFESSIONNEL", // 11 + "ACCORD NATIONAL", // 101 + "Accord national", // 20 + "Accord paritaire national", // 4 + "ACCORD PARITAIRE", // 5 + "Accord paritaire", // 8 + "ACCORD PROFESSIONNEL", // 4 + "Accord professionnel", // 56 + "Accord régional", // 2 + "ACCORD_FONCTION_PUBLIQUE", // 12 + "Accord-cadre interbranches", // 2 + "ACCORD-CADRE", // 20 + "Accord-cadre", // 7 + "Accord-type", // 1 + "ACCORD", // 1048 + "accord", // 130 + "Accord", // 22442 + "ACTE", // 5 + "Additif", // 24 + "ADDITIF", // 39 + "Adhésion par lettre", // 8 + "Adhésion", // 1 + "Annexe spécifique", // 2 + "ANNEXE", // 149 + "Annexe", // 367 + "ANNEXES", // 3 + "ANNONCES", // 4 + "ARRET", // 48 + "ARRETE", // 547820 + "ARRETEEURO", // 15 + "ARRETEURO", // 599 + "ATTESTATION", // 2 + "Avenant de révision", // 36 + "Avenant rectificatif", // 1 + "Avenant", // 18057 + "avenant", // 185 + "AVENANT", // 858 + "AVIS D'INTERPRETATION", // 2 + "Avis d'interprétation", // 8 + "Avis interprétatif", // 4 + "AVIS", // 30500 + "AVISEURO", // 3645 + "CIRCULAIRE", // 4362 + "CODE", // 535600 + "COMMUNIQUE", // 4 + "COMPOSITION", // 7 + "CONSTITUTION", // 13896 + "Convention collective de travail", // 4 + "Convention collective départementale", // 36 + "CONVENTION COLLECTIVE INTERREGIONALE", // 217 + "Convention collective interrégionale", // 7 + "Convention collective nationale de travail", // 1 + "CONVENTION COLLECTIVE NATIONALE", // 6 + "Convention collective nationale", // 6077 + "Convention collective régionale", // 148 + "convention collective", // 106 + "CONVENTION COLLECTIVE", // 148 + "Convention collective", // 666 + "Convention de référencement", // 1 + "Convention", // 1 + "CONVENTION", // 329 + "DECISION_CC", // 116 + "DECISION_EURO", // 243 + "Décision", // 1 + "DECISION", // 109937 + "DECLARATION", // 8 + "DECRET_LOI", // 2061 + "DECRET", // 747993 + "Délibération", // 1 + "DELIBERATION", // 10824 + "DELIBERATIONEURO", // 26 + "Dénonciation par lettre", // 3 + "Dénonciation", // 2 + "DIRECTIVE_EURO", // 22593 + "DIRECTIVE", // 43 + "ELECTIONDUPRESIDENTDELAREPUBLIQU", // 6 + "INFORMATION", // 26 + "INFORMATIONS_DIVERSES", // 16 + "INFORMATIONS_PARLEMENTAIRES", // 2576 + "INSTRUCTION", // 218 + "INSTRUCTIONEURO", // 700 + "Lettre de dénonciation", // 1 + "LETTREEURO", // 5 + "LISTE", // 262 + "LOI_CONSTIT", // 30 + "LOI_ORGANIQUE", // 2899 + "LOI_PROGRAMME", // 55 + "LOI", // 216342 + "MEMOIRE", // 21 + "MODIFICATION", // 125 + "NOTE", // 3 + "OBSERVATION", // 256 + "ORDONNANCE", // 35340 + "Procès-verbal de désaccord", // 4 + "PROJET", // 93 + "PROTOCOLE D'ACCORD COLLECTIF", // 7 + "Protocole d'accord de méthode", // 1 + "PROTOCOLE D'ACCORD INTERBRANCHE", // 3 + "Protocole D'accord", // 1 + "PROTOCOLE D'ACCORD", // 33 + "Protocole d'accord", // 62 + "Protocole", // 55 + "PROTOCOLE", // 7 + "PUBLICATION", // 1 + "RAPPORT", // 1756 + "Recommandation patronale", // 2 + "RECOMMANDATION_EURO", // 1 + "RECOMMANDATION", // 243 + "Rectificatif au Bulletin officiel n°", // 4 + "REGLEMENT", // 800 + "REGLEMENTEUROPEEN", // 1897 + "RESULTATS", // 3901 + "SAISINE", // 352 + "SALAIRES", // 4 + "SENATUS", // 4 + "SUSPENSION", // 1 + "TABLEAU", // 12 +] as const +export const allJorfTexteVersionLienNaturesMutable = [ + ...allJorfTexteVersionLienNatures, +] + +export const allJorfTexteVersionLienTypes = [ + "ABROGATION", // 34942 + "ABROGE", // 72512 + "ANNULATION", // 381 + "ANNULE", // 32 + "APPLICATION", // 294702 + "CITATION", // 1220159 + "CODIFICATION", // 249655 + "CONCORDANCE", // 27893 + "CONCORDE", // 328 + "CREATION", // 44426 + "CREE", // 1 + "DENONCE", // 1 + "DISJOINT", // 2 + "DISJONCTION", // 1 + "ELARGISSEMENT", // 10 + "ETEND", // 40707 + "EXTENSION", // 1002 + "HISTO", // 2 + "MODIFICATION", // 39581 + "MODIFIE", // 277772 + "PEREMPTION", // 1559 + "PERIME", // 2 + "RATIFICATION", // 3 + "RATIFIE", // 342 + "RATTACHEMENT", // 1 + "RECTIFICATION", // 762 + "RENVOI", // 1 + "RENVOIT", // 811 + "SPEC_APPLI", // 29805 + "TEXTE_SUITE", // 74 + "TRANSFERT", // 981 + "TRANSPOSITION", // 6513 + "TXT_ASSOCIE", // 11821 + "TXT_SOURCE", // 81350 +] as const +export const allJorfTexteVersionLienTypesMutable = [ + ...allJorfTexteVersionLienTypes, +] + +export const allJorfTexteVersionNatures = [ + "ABROGATION", // 8 + "Accord multilatéral", // 1 + "ACCORD_FONCTION_PUBLIQUE", // 4 + "ACCORD", // 46 + "ACTE", // 3 + "ADDITIF", // 131 + "ANNEXE", // 1 + "ANNONCES", // 756 + "ARRANGEMENT", // 1 + "ARRET", // 65 + "ARRETE", // 615239 + "ARRETEAVIS", // 1 + "ARRETEEURO", // 14 + "ARRETEURO", // 556 + "ATTESTATION", // 1 + "AVENANT", // 186 + "AVIS", // 97999 + "AVISEURO", // 4618 + "CANDIDAT", // 2 + "CHARTE", // 1 + "CIRCULAIRE", // 3532 + "CITATION", // 494 + "CODE", // 58 + "COMMUNIQUE", // 17 + "COMPLEMENT", // 2 + "COMPOSITION", // 9 + "CONSTITUTION", // 4 + "CONTRAT", // 2 + "CONVENTION", // 151 + "DATE", // 1 + "DECISION_CC", // 96 + "DECISION_EURO", // 550 + "DECISION", // 67164 + "DECLARATION", // 20 + "DECLARATIONEURO", // 18 + "DECRET_LOI", // 660 + "DECRET", // 209363 + "DELEGATION", // 1 + "DELIBERATION", // 3993 + "DELIBERATIONEURO", // 36 + "DEUXIEME", // 5 + "DIRECTIVE_EURO", // 4249 + "DIRECTIVE", // 13 + "DISPOSITIONS", // 1 + "ELECTION", // 1 + "ELECTIONDUPRESIDENTDELAREPUBLIQU", // 2 + "EXEQUATUR", // 174 + "INFORMATION", // 106 + "INFORMATIONEURO", // 1 + "INFORMATIONS_CESE", // 285 + "INFORMATIONS_DIVERSES", // 524 + "INFORMATIONS_PARLEMENTAIRES", // 6042 + "INSTRUCTION", // 158 + "INSTRUCTIONEURO", // 524 + "LETTRE", // 13 + "LETTREEURO", // 15 + "LISTE", // 5552 + "LOI_CONSTIT", // 12 + "LOI_ORGANIQUE", // 105 + "LOI_PROGRAMME", // 2 + "LOI", // 12859 + "MEMOIRE", // 63 + "MESSAGE", // 2 + "MODIFICATION", // 497 + "NOTE", // 3 + "OBSERVATION", // 288 + "ORDONNANCE", // 3282 + "PREMIER", // 1 + "PROCLAMATION", // 3 + "PROJET", // 3 + "PROPOSITION", // 6 + "PROTOCOLE", // 16 + "PUBLICATION", // 2 + "RAPPORT", // 1968 + "RECOMMANDATION", // 126 + "RECTIFICATIF", // 3 + "REGLEMENT", // 902 + "REGLEMENTEUROPEEN", // 571 + "RELEVE", // 3 + "REMISE", // 121 + "RESULTATS", // 14479 + "SAISINE", // 392 + "SENATUS", // 2 + "SUSPENSION", // 1 + "TABLEAU", // 1092 + "TRAITE", // 5 + "TROISIEME", // 2 + "VOCABULAIRE", // 169 +] as const +export const allJorfTexteVersionNaturesMutable = [...allJorfTexteVersionNatures] + +export const allJorfTexteVersionOrigines = ["JORF"] as const +export const allJorfTexteVersionOriginesMutable = [ + ...allJorfTexteVersionOrigines, +] diff --git a/src/lib/legal/legi.ts b/src/lib/legal/legi.ts index 64c42a4..8eef5dc 100644 --- a/src/lib/legal/legi.ts +++ b/src/lib/legal/legi.ts @@ -1,3 +1,5 @@ +import type { Sens } from "./shared" + export interface LegiArticle { BLOC_TEXTUEL?: { CONTENU: string // HTML @@ -32,7 +34,7 @@ export interface LegiArticle { "@naturetexte"?: LegiArticleLienNature "@nortexte"?: string "@num"?: string - "@sens": LegiArticleLienSens + "@sens": Sens "@typelien": LegiArticleLienType }> } @@ -79,8 +81,6 @@ export type LegiArticleLienArticleOrigine = export type LegiArticleLienNature = (typeof allLegiArticleLienNatures)[number] -export type LegiArticleLienSens = (typeof allLegiArticleLienSens)[number] - export type LegiArticleLienType = (typeof allLegiArticleLienTypes)[number] export type LegiArticleNature = (typeof allLegiArticleNatures)[number] @@ -154,9 +154,6 @@ export const allLegiArticleLienNatures = [ ] as const export const allLegiArticleLienNaturesMutable = [...allLegiArticleLienNatures] -export const allLegiArticleLienSens = ["cible", "source"] as const -export const allLegiArticleLienSensMutable = [...allLegiArticleLienSens] - export const allLegiArticleLienTypes = [ "ABROGATION", // 237556 "ABROGE", // 480524 diff --git a/src/lib/legal/shared.ts b/src/lib/legal/shared.ts new file mode 100644 index 0000000..8867da4 --- /dev/null +++ b/src/lib/legal/shared.ts @@ -0,0 +1,4 @@ +export type Sens = (typeof allSens)[number] + +export const allSens = ["cible", "source"] as const +export const allSensMutable = [...allSens] diff --git a/src/scripts/import_jorf.ts b/src/scripts/import_jorf.ts index ff1542e..8db6723 100644 --- a/src/scripts/import_jorf.ts +++ b/src/scripts/import_jorf.ts @@ -17,16 +17,20 @@ import { auditJo, auditJorfArticle, auditJorfSectionTa, + auditJorfTextelr, + auditJorfTexteVersion, // jorfArticleStats, - jorfSectionTaStats, + // jorfSectionTaStats, // joStats, + jorfTextelrStats, + // jorfTexteVersionStats, } from "$lib/auditors/jorf" import type { Jo, JorfArticle, JorfSectionTa, - Textelr, - TexteVersion, + JorfTextelr, + JorfTexteVersion, Versions, XmlHeader, } from "$lib/legal" @@ -196,8 +200,8 @@ async function importJorf( | Jo | JorfArticle | JorfSectionTa - | Textelr - | TexteVersion + | JorfTextelr + | JorfTexteVersion | Versions | XmlHeader ), @@ -334,7 +338,19 @@ async function importJorf( break case "TEXTE_VERSION": if (categoryTag === undefined || categoryTag === tag) { - const texteVersion = element as TexteVersion + const [texteVersion, error] = auditChain( + auditJorfTexteVersion, + auditRequire, + )(strictAudit, element) as [JorfTexteVersion, unknown] + assert.strictEqual( + error, + null, + `Unexpected format for TEXTE_VERSION:\n${JSON.stringify( + texteVersion, + null, + 2, + )}\nError:\n${JSON.stringify(error, null, 2)}`, + ) const textAFragments = [ texteVersion.META.META_SPEC.META_TEXTE_VERSION.TITRE, texteVersion.META.META_SPEC.META_TEXTE_VERSION.TITREFULL, @@ -348,7 +364,7 @@ async function importJorf( ) VALUES ( ${texteVersion.META.META_COMMUN.ID}, ${db.json(texteVersion as unknown as JSONValue)}, - ${texteVersion.META.META_COMMUN.NATURE}, + ${texteVersion.META.META_COMMUN.NATURE ?? null}, setweight(to_tsvector('french', ${textAFragments.join( " ", )}), 'A') @@ -356,7 +372,7 @@ async function importJorf( ON CONFLICT (id) DO UPDATE SET data = ${db.json(texteVersion as unknown as JSONValue)}, - nature = ${texteVersion.META.META_COMMUN.NATURE}, + nature = ${texteVersion.META.META_COMMUN.NATURE ?? null}, text_search = setweight(to_tsvector('french', ${textAFragments.join( " ", )}), 'A') @@ -366,7 +382,19 @@ async function importJorf( break case "TEXTELR": if (categoryTag === undefined || categoryTag === tag) { - const textelr = element as Textelr + const [textelr, error] = auditChain( + auditJorfTextelr, + auditRequire, + )(strictAudit, element) as [JorfTextelr, unknown] + assert.strictEqual( + error, + null, + `Unexpected format for TEXTELR:\n${JSON.stringify( + textelr, + null, + 2, + )}\nError:\n${JSON.stringify(error, null, 2)}`, + ) await db` INSERT INTO textelr ( id, @@ -490,10 +518,15 @@ async function importJorf( // JSON.stringify(jorfArticleStats, null, 2), // ) // console.log("JO stats =", JSON.stringify(joStats, null, 2)) - console.log( - "JORF SECTION_TA stats =", - JSON.stringify(jorfSectionTaStats, null, 2), - ) + // console.log( + // "JORF SECTION_TA stats =", + // JSON.stringify(jorfSectionTaStats, null, 2), + // ) + console.log("JORF TEXTELR stats =", JSON.stringify(jorfTextelrStats, null, 2)) + // console.log( + // "JORF TEXTE_VERSION stats =", + // JSON.stringify(jorfTexteVersionStats, null, 2), + // ) } sade("import_jorf ", true)