Add validation of JORF SECTION_TA and improve other validations

This commit is contained in:
Emmanuel 2023-02-12 13:39:07 +01:00
parent bf3cda1a09
commit 920d52bcc0
10 changed files with 904 additions and 292 deletions

View file

@ -1,18 +1,18 @@
import { import {
type Audit,
auditRequire,
auditDateIso8601String,
auditTrimString,
auditInteger,
auditFunction,
auditEmptyToNull,
auditNullish,
auditSwitch,
auditString,
auditTest,
auditNumber,
auditCleanArray, auditCleanArray,
auditDateIso8601String,
auditEmptyToNull,
auditFunction,
auditInteger,
auditNullish,
auditNumber,
auditOptions, auditOptions,
auditRequire,
auditString,
auditSwitch,
auditTest,
auditTrimString,
type Audit,
} from "@auditors/core" } from "@auditors/core"
function auditArborescence( function auditArborescence(

View file

@ -1,17 +1,17 @@
import { import {
type Audit,
auditRequire,
auditDateIso8601String,
auditTrimString,
auditInteger,
auditFunction,
auditEmptyToNull,
auditNullish,
auditSwitch,
auditNumber,
auditCleanArray, auditCleanArray,
auditOptions, auditDateIso8601String,
auditEmptyToNull,
auditFunction,
auditHttpUrl, auditHttpUrl,
auditInteger,
auditNullish,
auditNumber,
auditOptions,
auditRequire,
auditSwitch,
auditTrimString,
type Audit,
} from "@auditors/core" } from "@auditors/core"
import { import {
@ -590,7 +590,7 @@ function auditTexte(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
auditFunction((titreTxt) => auditFunction((titreTxt) =>
Array.isArray(titreTxt) ? titreTxt : [titreTxt], Array.isArray(titreTxt) ? titreTxt : [titreTxt],
), ),
auditCleanArray(auditTitreTxt), auditCleanArray(auditTitreTxt, auditRequire),
auditRequire, auditRequire,
) )
audit.attribute(data, "TM", true, errors, remainingKeys, auditTm) audit.attribute(data, "TM", true, errors, remainingKeys, auditTm)
@ -781,7 +781,7 @@ function auditVersions(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors, errors,
remainingKeys, remainingKeys,
auditFunction((version) => (Array.isArray(version) ? version : [version])), auditFunction((version) => (Array.isArray(version) ? version : [version])),
auditCleanArray(auditVersion), auditCleanArray(auditVersion, auditRequire),
auditRequire, auditRequire,
) )

View file

@ -1,2 +1,3 @@
export { auditJo, joStats } from "./jo" export { auditJo, joStats } from "./jo"
export { auditJorfArticle, jorfArticleStats } from "./articles" export { auditJorfArticle, jorfArticleStats } from "./articles"
export { auditJorfSectionTa, jorfSectionTaStats } from "./section_ta"

View file

@ -1,18 +1,18 @@
import { import {
type Audit,
auditRequire,
auditDateIso8601String,
auditTrimString,
auditInteger,
auditFunction,
auditEmptyToNull,
auditNullish,
auditSwitch,
auditNumber,
auditCleanArray, auditCleanArray,
auditOptions, auditDateIso8601String,
auditEmptyToNull,
auditFunction,
auditHttpUrl, auditHttpUrl,
auditInteger,
auditNullish,
auditNumber,
auditOptions,
auditRequire,
auditStringToNumber, auditStringToNumber,
auditSwitch,
auditTrimString,
type Audit,
} from "@auditors/core" } from "@auditors/core"
import { allJoNaturesMutable, allJoOriginesMutable } from "$lib/legal" import { allJoNaturesMutable, allJoOriginesMutable } from "$lib/legal"
@ -340,7 +340,7 @@ function auditTm(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors, errors,
remainingKeys, remainingKeys,
auditStringToNumber, auditStringToNumber,
auditNumber, auditInteger,
auditRequire, auditRequire,
) )
audit.attribute( audit.attribute(

View file

@ -0,0 +1,516 @@
import {
auditCleanArray,
auditDateIso8601String,
auditEmptyToNull,
auditFunction,
auditInteger,
auditNullish,
auditOptions,
auditRequire,
auditStringToNumber,
auditSwitch,
auditTrimString,
type Audit,
} from "@auditors/core"
import {
allJorfSectionTaLienArtEtatsMutable,
allJorfSectionTaLienArtOriginesMutable,
// allJorfSectionTaLienSectionTaEtatsMutable,
allJorfSectionTaTexteNaturesMutable,
} from "$lib/legal"
export const jorfSectionTaStats: {
countByLienArtEtat: { [etat: string]: number }
countByLienArtOrigine: { [origine: string]: number }
countByLienSectionTaEtat: { [etat: string]: number }
countByTexteNature: { [nature: string]: number }
} = {
countByLienArtEtat: {},
countByLienArtOrigine: {},
countByLienSectionTaEtat: {},
countByTexteNature: {},
}
function auditContexte(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",
true,
errors,
remainingKeys,
auditTexte,
auditRequire,
)
return audit.reduceRemaining(data, errors, remainingKeys)
}
export function auditJorfSectionTa(
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 ["COMMENTAIRE", "TITRE_TA"]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
}
audit.attribute(
data,
"CONTEXTE",
true,
errors,
remainingKeys,
auditContexte,
auditRequire,
)
audit.attribute(
data,
"ID",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
audit.attribute(
data,
"STRUCTURE_TA",
true,
errors,
remainingKeys,
auditSwitch(
[auditTrimString, auditEmptyToNull, auditNullish],
auditStructureTa,
),
)
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) => {
// jorfSectionTaStats.countByLienArtEtat[etat] =
// (jorfSectionTaStats.countByLienArtEtat[etat] ?? 0) + 1
// return etat
// }),
auditOptions(allJorfSectionTaLienArtEtatsMutable),
)
audit.attribute(
data,
"@id",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
audit.attribute(
data,
"@num",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
audit.attribute(
data,
"@origine",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
// auditFunction((origine) => {
// jorfSectionTaStats.countByLienArtOrigine[origine] =
// (jorfSectionTaStats.countByLienArtOrigine[origine] ?? 0) + 1
// return origine
// }),
auditOptions(allJorfSectionTaLienArtOriginesMutable),
auditRequire,
)
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),
auditNullish,
)
audit.attribute(
data,
"@niv",
true,
errors,
remainingKeys,
auditStringToNumber,
auditInteger,
auditRequire,
)
return audit.reduceRemaining(data, errors, remainingKeys)
}
function auditStructureTa(
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 auditTexte(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",
"@nor",
"@num",
"@num_parution_jo",
]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
}
audit.attribute(
data,
"@cid",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
for (const key of ["@date_publi", "@date_signature"]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
// auditFunction((date) => date.replace(/^11992-12-27$/, "1992-12-27")),
auditDateIso8601String,
auditRequire,
)
}
audit.attribute(
data,
"@nature",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
// auditFunction((nature) => {
// jorfSectionTaStats.countByTexteNature[nature] =
// (jorfSectionTaStats.countByTexteNature[nature] ?? 0) + 1
// return nature
// }),
auditOptions(allJorfSectionTaTexteNaturesMutable),
)
audit.attribute(
data,
"TITRE_TXT",
true,
errors,
remainingKeys,
auditFunction((titreTxt) =>
Array.isArray(titreTxt) ? titreTxt : [titreTxt],
),
auditCleanArray(auditTitreTxt, auditRequire),
auditRequire,
)
audit.attribute(data, "TM", true, errors, remainingKeys, auditTm)
return audit.reduceRemaining(data, errors, remainingKeys)
}
function auditTitreTm(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,
auditTrimString,
auditEmptyToNull,
)
for (const key of ["@debut", "@fin"]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditDateIso8601String,
auditRequire,
)
}
audit.attribute(
data,
"@id",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
return audit.reduceRemaining(data, errors, remainingKeys)
}
function auditTitreTxt(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", "@id_txt"]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
}
audit.attribute(
data,
"@c_titre_court",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
for (const key of ["@debut", "@fin"]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditDateIso8601String,
auditRequire,
)
}
return audit.reduceRemaining(data, errors, remainingKeys)
}
/// Table des matières
function auditTm(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,
"TITRE_TM",
true,
errors,
remainingKeys,
auditTitreTm,
auditRequire,
)
audit.attribute(data, "TM", true, errors, remainingKeys, auditTm)
return audit.reduceRemaining(data, errors, remainingKeys)
}

View file

@ -1,21 +1,20 @@
import { import {
type Audit,
auditRequire,
auditDateIso8601String,
auditTrimString,
auditInteger,
auditFunction,
auditEmptyToNull,
auditSwitch,
auditNumber,
auditCleanArray, auditCleanArray,
auditOptions, auditDateIso8601String,
auditEmptyToNull,
auditFunction,
auditHttpUrl, auditHttpUrl,
auditInteger,
auditNumber,
auditOptions,
auditRequire,
auditSwitch,
auditTrimString,
type Audit,
} from "@auditors/core" } from "@auditors/core"
import { import {
allLegiArticleEtatsMutable, allLegiArticleEtatsMutable,
allLegiArticleLienArticleOriginesMutable,
allLegiArticleLienNaturesMutable, allLegiArticleLienNaturesMutable,
allLegiArticleLienSensMutable, allLegiArticleLienSensMutable,
allLegiArticleLienTypesMutable, allLegiArticleLienTypesMutable,
@ -94,33 +93,6 @@ function auditContexte(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
return audit.reduceRemaining(data, errors, remainingKeys) 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)
}
export function auditLegiArticle( export function auditLegiArticle(
audit: Audit, audit: Audit,
dataUnknown: unknown, dataUnknown: unknown,
@ -217,7 +189,7 @@ function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
[auditTrimString, auditEmptyToNull], [auditTrimString, auditEmptyToNull],
), ),
) )
for (const key of ["@cidtexte", "@id", "@nortexte"]) { for (const key of ["@cidtexte", "@id", "@nortexte", "@num"]) {
audit.attribute( audit.attribute(
data, data,
key, key,
@ -228,18 +200,16 @@ function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
auditEmptyToNull, auditEmptyToNull,
) )
} }
for (const key of ["@datesignatexte"]) { audit.attribute(
audit.attribute( data,
data, "@datesignatexte",
key, true,
true, errors,
errors, remainingKeys,
remainingKeys, auditTrimString,
auditTrimString, auditEmptyToNull,
auditEmptyToNull, auditDateIso8601String,
auditDateIso8601String, )
)
}
audit.attribute( audit.attribute(
data, data,
"@naturetexte", "@naturetexte",
@ -255,15 +225,6 @@ function auditLien(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
// }), // }),
auditOptions(allLegiArticleLienNaturesMutable), auditOptions(allLegiArticleLienNaturesMutable),
) )
audit.attribute(
data,
"@num",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
audit.attribute( audit.attribute(
data, data,
"@numtexte", "@numtexte",
@ -369,7 +330,7 @@ function auditLienArt(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
remainingKeys, remainingKeys,
auditTrimString, auditTrimString,
auditEmptyToNull, auditEmptyToNull,
auditOptions(allLegiArticleLienArticleOriginesMutable), auditOptions(allLegiArticleOriginesMutable),
auditRequire, auditRequire,
) )
@ -395,7 +356,7 @@ function auditLiens(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors, errors,
remainingKeys, remainingKeys,
auditFunction((lien) => (Array.isArray(lien) ? lien : [lien])), auditFunction((lien) => (Array.isArray(lien) ? lien : [lien])),
auditCleanArray(auditLien), auditCleanArray(auditLien, auditRequire),
auditRequire, auditRequire,
) )
@ -627,16 +588,23 @@ function auditTexte(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
const data = { ...dataUnknown } const data = { ...dataUnknown }
const errors: { [key: string]: unknown } = {} const errors: { [key: string]: unknown } = {}
const remainingKeys = new Set(Object.keys(data)) const remainingKeys = new Set(Object.keys(data))
for (const key of [
audit.attribute(
data,
"@autorite", "@autorite",
true, "@ministere",
errors, "@nor",
remainingKeys, "@num",
auditTrimString, "@num_parution_jo",
auditEmptyToNull, ]) {
) audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
}
audit.attribute( audit.attribute(
data, data,
"@cid", "@cid",
@ -659,15 +627,6 @@ function auditTexte(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
auditRequire, auditRequire,
) )
} }
audit.attribute(
data,
"@ministere",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
audit.attribute( audit.attribute(
data, data,
"@nature", "@nature",
@ -683,17 +642,6 @@ function auditTexte(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
// }), // }),
auditOptions(allLegiArticleTexteNaturesMutable), auditOptions(allLegiArticleTexteNaturesMutable),
) )
for (const key of ["@nor", "@num", "@num_parution_jo"]) {
audit.attribute(
data,
key,
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
)
}
audit.attribute( audit.attribute(
data, data,
"TITRE_TXT", "TITRE_TXT",
@ -703,7 +651,7 @@ function auditTexte(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
auditFunction((titreTxt) => auditFunction((titreTxt) =>
Array.isArray(titreTxt) ? titreTxt : [titreTxt], Array.isArray(titreTxt) ? titreTxt : [titreTxt],
), ),
auditCleanArray(auditTitreTxt), auditCleanArray(auditTitreTxt, auditRequire),
auditRequire, auditRequire,
) )
audit.attribute(data, "TM", true, errors, remainingKeys, auditTm) audit.attribute(data, "TM", true, errors, remainingKeys, auditTm)
@ -723,18 +671,20 @@ function auditTitreTm(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
const errors: { [key: string]: unknown } = {} const errors: { [key: string]: unknown } = {}
const remainingKeys = new Set(Object.keys(data)) const remainingKeys = new Set(Object.keys(data))
audit.attribute( for (const key of ["#text", "@id"]) {
data, audit.attribute(
"#text", data,
true, key,
errors, true,
remainingKeys, errors,
auditSwitch( remainingKeys,
[auditNumber, auditInteger, auditFunction((num) => num.toString())], auditSwitch(
[auditTrimString, auditEmptyToNull], [auditNumber, auditInteger, auditFunction((num) => num.toString())],
), [auditTrimString, auditEmptyToNull],
auditRequire, ),
) auditRequire,
)
}
for (const key of ["@debut", "@fin"]) { for (const key of ["@debut", "@fin"]) {
audit.attribute( audit.attribute(
data, data,
@ -746,16 +696,6 @@ function auditTitreTm(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
auditRequire, auditRequire,
) )
} }
audit.attribute(
data,
"@id",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
return audit.reduceRemaining(data, errors, remainingKeys) return audit.reduceRemaining(data, errors, remainingKeys)
} }
@ -772,26 +712,18 @@ function auditTitreTxt(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
const errors: { [key: string]: unknown } = {} const errors: { [key: string]: unknown } = {}
const remainingKeys = new Set(Object.keys(data)) const remainingKeys = new Set(Object.keys(data))
audit.attribute( for (const key of ["#text", "@c_titre_court", "@id_txt"]) {
data, audit.attribute(
"#text", data,
true, key,
errors, true,
remainingKeys, errors,
auditTrimString, remainingKeys,
auditEmptyToNull, auditTrimString,
auditRequire, auditEmptyToNull,
) auditRequire,
audit.attribute( )
data, }
"@c_titre_court",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
for (const key of ["@debut", "@fin"]) { for (const key of ["@debut", "@fin"]) {
audit.attribute( audit.attribute(
data, data,
@ -803,16 +735,6 @@ function auditTitreTxt(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
auditRequire, auditRequire,
) )
} }
audit.attribute(
data,
"@id_txt",
true,
errors,
remainingKeys,
auditTrimString,
auditEmptyToNull,
auditRequire,
)
return audit.reduceRemaining(data, errors, remainingKeys) return audit.reduceRemaining(data, errors, remainingKeys)
} }
@ -837,7 +759,7 @@ function auditTm(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors, errors,
remainingKeys, remainingKeys,
auditFunction((titreTm) => (Array.isArray(titreTm) ? titreTm : [titreTm])), auditFunction((titreTm) => (Array.isArray(titreTm) ? titreTm : [titreTm])),
auditCleanArray(auditTitreTm), auditCleanArray(auditTitreTm, auditRequire),
auditRequire, auditRequire,
) )
audit.attribute(data, "TM", true, errors, remainingKeys, auditTm) audit.attribute(data, "TM", true, errors, remainingKeys, auditTm)
@ -904,7 +826,7 @@ function auditVersions(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors, errors,
remainingKeys, remainingKeys,
auditFunction((version) => (Array.isArray(version) ? version : [version])), auditFunction((version) => (Array.isArray(version) ? version : [version])),
auditCleanArray(auditVersion), auditCleanArray(auditVersion, auditRequire),
auditRequire, auditRequire,
) )

View file

@ -2,6 +2,8 @@ import type { MenuItem } from "@tricoteuses/explorer-tools"
import type { DossierLegislatif } from "./dole" import type { DossierLegislatif } from "./dole"
import type { Jo } from "./jorf"
export type { DossierLegislatif } from "./dole" export type { DossierLegislatif } from "./dole"
export { export {
allJoNatures, allJoNatures,
@ -20,6 +22,15 @@ export {
allJorfArticleTexteNaturesMutable, allJorfArticleTexteNaturesMutable,
allJorfArticleTypes, allJorfArticleTypes,
allJorfArticleTypesMutable, allJorfArticleTypesMutable,
allJorfSectionTaLienArtEtats,
allJorfSectionTaLienArtEtatsMutable,
allJorfSectionTaLienArtOrigines,
allJorfSectionTaLienArtOriginesMutable,
allJorfSectionTaLienSectionTaEtats,
allJorfSectionTaLienSectionTaEtatsMutable,
allJorfSectionTaTexteNatures,
allJorfSectionTaTexteNaturesMutable,
type Jo,
type JoNature, type JoNature,
type JoOrigine, type JoOrigine,
type JorfArticle, type JorfArticle,
@ -29,6 +40,9 @@ export {
type JorfArticleOrigine, type JorfArticleOrigine,
type JorfArticleTexteNature, type JorfArticleTexteNature,
type JorfArticleType, type JorfArticleType,
type JorfSectionTa,
type JorfSectionTaLienArtEtat,
type JorfSectionTaTexteNature,
} from "./jorf" } from "./jorf"
export { export {
allLegiArticleEtats, allLegiArticleEtats,
@ -145,22 +159,6 @@ export interface IdWrapper {
id: string id: string
} }
export interface Jo {
META: {
META_SPEC: {
META_CONTENEUR: {
NUM: string
TITRE: string
DATE_PUBLI: string
}
}
META_COMMUN: MetaCommun
}
STRUCTURE_TXT: {
TM: Tm
}
}
export type LegalObject = export type LegalObject =
| Article | Article
| DossierLegislatif | DossierLegislatif

View file

@ -1,3 +1,35 @@
export interface Jo {
META: {
META_COMMUN: {
ID: string
ID_ELI?: string
NATURE: JoNature
ORIGINE: JoOrigine
URL: string
}
META_SPEC: {
META_CONTENEUR: {
DATE_PUBLI: string
NUM?: string
TITRE: string
}
}
}
STRUCTURE_TXT?: {
LIEN_TXT?: JoLienTxt[]
TM?: JoTm[]
}
}
export interface JoLienTxt {
"@idtxt": string
"@titretxt": string
}
export type JoNature = (typeof allJoNatures)[number]
export type JoOrigine = (typeof allJoOrigines)[number]
export interface JorfArticle { export interface JorfArticle {
BLOC_TEXTUEL?: { BLOC_TEXTUEL?: {
CONTENU: string // HTML CONTENU: string // HTML
@ -30,13 +62,13 @@ export interface JorfArticle {
ID: string ID: string
ID_ELI?: string ID_ELI?: string
NATURE?: JorfArticleNature NATURE?: JorfArticleNature
URL: string
ORIGINE: JorfArticleOrigine ORIGINE: JorfArticleOrigine
URL: string
} }
META_SPEC: { META_SPEC: {
META_ARTICLE: { META_ARTICLE: {
DATE_FIN: string
DATE_DEBUT: string DATE_DEBUT: string
DATE_FIN: string
/// Mots-clés /// Mots-clés
MCS_ART?: { MC: string[] } MCS_ART?: { MC: string[] }
NUM?: string NUM?: string
@ -59,10 +91,6 @@ export interface JorfArticle {
} }
} }
export type JoNature = (typeof allJoNatures)[number]
export type JoOrigine = (typeof allJoOrigines)[number]
export type JorfArticleEtat = (typeof allJorfArticleEtats)[number] export type JorfArticleEtat = (typeof allJorfArticleEtats)[number]
export type JorfArticleLienArticleOrigine = export type JorfArticleLienArticleOrigine =
@ -74,9 +102,7 @@ export type JorfArticleOrigine = (typeof allJorfArticleOrigines)[number]
export type JorfArticleTexteNature = (typeof allJorfArticleTexteNatures)[number] export type JorfArticleTexteNature = (typeof allJorfArticleTexteNatures)[number]
export type JorfArticleType = (typeof allJorfArticleTypes)[number] /// Table des matières (TM) d'un article de Journal officiel
/// Table des matières (TM)
export interface JorfArticleTm { export interface JorfArticleTm {
TITRE_TM: { TITRE_TM: {
"#text"?: string "#text"?: string
@ -87,6 +113,85 @@ export interface JorfArticleTm {
TM?: JorfArticleTm TM?: JorfArticleTm
} }
export type JorfArticleType = (typeof allJorfArticleTypes)[number]
export interface JorfSectionTa {
COMMENTAIRE?: string
CONTEXTE: {
ID: string
TEXTE: {
"@autorite"?: string
"@cid": string
"@date_publi": string
"@date_signature": string
"@ministere"?: string
"@nature"?: JorfSectionTaTexteNature
"@nor"?: string
"@num"?: string
"@num_parution_jo"?: string
TITRE_TXT: Array<{
"#text": string
"@c_titre_court"?: string
"@debut": string
"@fin": string
"@id_txt": string
}>
TM?: JorfSectionTaTm[]
}
}
TITRE_TA?: string
STRUCTURE_TA?: Array<{
LIEN_ART?: Array<{
"@debut": string
"@etat"?: JorfSectionTaLienArtEtat
"@fin": string
"@id": string
"@num"?: string
"@origine"?: JorfSectionTaLienArtOrigine
}>
LIEN_SECTION_TA?: Array<{
"#text"?: string
"@cid": string
"@debut": string
// "@etat"?: JorfSectionTaLienSectionTaEtat
"@fin": string
"@id": string
"@niv": number
"@url": string
}>
}>
}
export type JorfSectionTaLienArtEtat =
(typeof allJorfSectionTaLienArtEtats)[number]
export type JorfSectionTaLienArtOrigine =
(typeof allJorfSectionTaLienArtOrigines)[number]
export type JorfSectionTaLienSectionTaEtat =
(typeof allJorfSectionTaLienSectionTaEtats)[number]
export type JorfSectionTaTexteNature =
(typeof allJorfSectionTaTexteNatures)[number]
interface JorfSectionTaTm {
TITRE_TM: {
"#text"?: string
"@debut": string
"@fin": string
"@id": string
}
TM?: JorfSectionTaTm
}
/// Table des matières (TM) d'un Journal officiel
export interface JoTm {
"@niv": number
LIEN_TXT?: JoLienTxt[]
TITRE_TM: string
TM?: JoTm[]
}
export const allJoNatures = ["JO"] as const export const allJoNatures = ["JO"] as const
export const allJoNaturesMutable = [...allJoNatures] export const allJoNaturesMutable = [...allJoNatures]
@ -118,77 +223,77 @@ export const allJorfArticleOrigines = ["JORF"] as const
export const allJorfArticleOriginesMutable = [...allJorfArticleOrigines] export const allJorfArticleOriginesMutable = [...allJorfArticleOrigines]
export const allJorfArticleTexteNatures = [ export const allJorfArticleTexteNatures = [
"DECRET", // 555543
"LOI", // 64957
"ARRETE", // 1228598
"DECISION", // 244100
"LISTE", // 24279
"AVIS", // 101688
"CODE", // 14737
"RESULTATS", // 14954
"MODIFICATION", // 724
"RAPPORT", // 2491
"REGLEMENT", // 1930
"LOI_ORGANIQUE", // 1144
"CIRCULAIRE", // 3933
"LOI_PROGRAMME", // 10
"CITATION", // 423
"ORDONNANCE", // 33582
"DELIBERATION", // 11012
"INSTRUCTION", // 1207
"AVENANT", // 533
"DECLARATION", // 77
"OBSERVATION", // 623
"INFORMATION", // 143
"RECOMMANDATION", // 204
"SAISINE", // 1075
"EXEQUATUR", // 173
"TABLEAU", // 1063
"REMISE", // 119
"ACCORD", // 153
"MEMOIRE", // 72
"DECISION_CC", // 51
"LOI_CONSTIT", // 76
"LETTRE", // 10
"ELECTIONDUPRESIDENTDELAREPUBLIQU", // 16
"CONVENTION", // 972
"ARRET", // 23
"CONTRAT", // 32
"COMPOSITION", // 19
"ADDITIF", // 139
"VOCABULAIRE", // 170
"DATE", // 1
"PROTOCOLE", // 25
"PROPOSITION", // 11
"DECRET_LOI", // 85
"COMMUNIQUE", // 3
"PROCLAMATION", // 17
"CONSTITUTION", // 41
"DIRECTIVE", // 11
"DECISION_EURO", // 15
"ABROGATION", // 10 "ABROGATION", // 10
"PREMIER", // 1
"PUBLICATION", // 2
"RECTIFICATIF", // 3
"DEUXIEME", // 5
"DELEGATION", // 1
"ANNEXE", // 2
"RELEVE", // 2
"COMPLEMENT", // 2
"ARRANGEMENT", // 1
"TROISIEME", // 2
"ELECTION", // 1
"SUSPENSION", // 2
"ATTESTATION", // 1
"CANDIDAT", // 2
"CHARTE", // 1
"PROJET", // 6
"INFORMATIONS_DIVERSES", // 524
"INFORMATIONS_PARLEMENTAIRES", // 6335
"INFORMATIONS_CESE", // 285
"ANNONCES", // 755
"Accord multilatéral", // 3 "Accord multilatéral", // 3
"ACCORD_FONCTION_PUBLIQUE", // "ACCORD_FONCTION_PUBLIQUE", //
"ACCORD", // 153
"ADDITIF", // 139
"ANNEXE", // 2
"ANNONCES", // 755
"ARRANGEMENT", // 1
"ARRET", // 23
"ARRETE", // 1228598
"ATTESTATION", // 1
"AVENANT", // 533
"AVIS", // 101688
"CANDIDAT", // 2
"CHARTE", // 1
"CIRCULAIRE", // 3933
"CITATION", // 423
"CODE", // 14737
"COMMUNIQUE", // 3
"COMPLEMENT", // 2
"COMPOSITION", // 19
"CONSTITUTION", // 41
"CONTRAT", // 32
"CONVENTION", // 972
"DATE", // 1
"DECISION_CC", // 51
"DECISION_EURO", // 15
"DECISION", // 244100
"DECLARATION", // 77
"DECRET_LOI", // 85
"DECRET", // 555543
"DELEGATION", // 1
"DELIBERATION", // 11012
"DEUXIEME", // 5
"DIRECTIVE", // 11
"ELECTION", // 1
"ELECTIONDUPRESIDENTDELAREPUBLIQU", // 16
"EXEQUATUR", // 173
"INFORMATION", // 143
"INFORMATIONS_CESE", // 285
"INFORMATIONS_DIVERSES", // 524
"INFORMATIONS_PARLEMENTAIRES", // 6335
"INSTRUCTION", // 1207
"LETTRE", // 10
"LISTE", // 24279
"LOI_CONSTIT", // 76
"LOI_ORGANIQUE", // 1144
"LOI_PROGRAMME", // 10
"LOI", // 64957
"MEMOIRE", // 72
"MODIFICATION", // 724
"OBSERVATION", // 623
"ORDONNANCE", // 33582
"PREMIER", // 1
"PROCLAMATION", // 17
"PROJET", // 6
"PROPOSITION", // 11
"PROTOCOLE", // 25
"PUBLICATION", // 2
"RAPPORT", // 2491
"RECOMMANDATION", // 204
"RECTIFICATIF", // 3
"REGLEMENT", // 1930
"RELEVE", // 2
"REMISE", // 119
"RESULTATS", // 14954
"SAISINE", // 1075
"SUSPENSION", // 2
"TABLEAU", // 1063
"TROISIEME", // 2
"VOCABULAIRE", // 170
] as const ] as const
export const allJorfArticleTexteNaturesMutable = [...allJorfArticleTexteNatures] export const allJorfArticleTexteNaturesMutable = [...allJorfArticleTexteNatures]
@ -198,3 +303,53 @@ export const allJorfArticleTypes = [
"PARTIELLEMENT_MODIF", "PARTIELLEMENT_MODIF",
] as const ] as const
export const allJorfArticleTypesMutable = [...allJorfArticleTypes] export const allJorfArticleTypesMutable = [...allJorfArticleTypes]
export const allJorfSectionTaLienArtEtats = ["VIGUEUR"] as const
export const allJorfSectionTaLienArtEtatsMutable = [
...allJorfSectionTaLienArtEtats,
]
export const allJorfSectionTaLienArtOrigines = ["JORF"] as const
export const allJorfSectionTaLienArtOriginesMutable = [
...allJorfSectionTaLienArtOrigines,
]
export const allJorfSectionTaLienSectionTaEtats = [] as const
export const allJorfSectionTaLienSectionTaEtatsMutable = [
...allJorfSectionTaLienSectionTaEtats,
]
export const allJorfSectionTaTexteNatures = [
"Accord multilatéral", // 2
"ACCORD_FONCTION_PUBLIQUE", // 2
"ACCORD", // 3
"ADDITIF", // 3
"ARRETE", // 53716
"AVENANT", // 89
"AVIS", // 3212
"CIRCULAIRE", // 168
"CONVENTION", // 38
"DECISION", // 16923
"DECLARATION", // 4
"DECRET", // 44405
"DELIBERATION", // 2476
"DIRECTIVE", // 2
"INFORMATIONS_PARLEMENTAIRES", // 28
"INSTRUCTION", // 39
"LISTE", // 394
"LOI_ORGANIQUE", // 71
"LOI", // 5161
"MODIFICATION", // 6
"ORDONNANCE", // 9566
"PROPOSITION", // 3
"PROTOCOLE", // 1
"RAPPORT", // 390
"RECOMMANDATION", // 5
"REGLEMENT", // 40
"RESULTATS", // 324
"SAISINE", // 3
"TABLEAU", // 100
] as const
export const allJorfSectionTaTexteNaturesMutable = [
...allJorfSectionTaTexteNatures,
]

View file

@ -4,16 +4,18 @@ export interface LegiArticle {
} }
CONTEXTE: { CONTEXTE: {
TEXTE: { TEXTE: {
"@autorite"?: string
"@cid": string "@cid": string
"@date_publi": string "@date_publi": string
"@date_signature": string "@date_signature": string
"@ministere"?: string
"@nature"?: LegiArticleTexteNature "@nature"?: LegiArticleTexteNature
"@nor"?: string "@nor"?: string
"@num"?: string "@num"?: string
"@num_parution_jo"?: string "@num_parution_jo"?: string
TITRE_TXT: Array<{ TITRE_TXT: Array<{
"#text": string "#text": string
"@c_titre_court"?: string "@c_titre_court": string
"@debut": string "@debut": string
"@fin": string "@fin": string
"@id_txt": string "@id_txt": string
@ -21,29 +23,40 @@ export interface LegiArticle {
TM?: LegiArticleTm TM?: LegiArticleTm
} }
} }
LIENS?: {
LIEN: Array<{
"#text"?: string
"@cidtexte"?: string
"@datesignatexte"?: string
"@id"?: string
"@naturetexte"?: LegiArticleLienNature
"@nortexte"?: string
"@num"?: string
"@sens": LegiArticleLienSens
"@typelien": LegiArticleLienType
}>
}
META: { META: {
META_COMMUN: { META_COMMUN: {
ANCIEN_ID?: string ANCIEN_ID?: string
ELI_ALIAS?: {
ID_ELI_ALIAS: string
}
ID: string ID: string
ID_ELI?: string NATURE: LegiArticleNature
NATURE?: LegiArticleNature
URL: string
ORIGINE: LegiArticleOrigine ORIGINE: LegiArticleOrigine
URL: string
} }
META_SPEC: { META_SPEC: {
META_ARTICLE: { META_ARTICLE: {
DATE_FIN: string
DATE_DEBUT: string DATE_DEBUT: string
/// Mots-clés DATE_FIN: string
MCS_ART?: { MC: string[] } ETAT?: LegiArticleEtat
NUM?: string NUM?: string
TYPE?: LegiArticleType TYPE?: LegiArticleType
} }
} }
} }
NOTA?: {
CONTENU: string // HTML
}
VERSIONS: { VERSIONS: {
VERSION: Array<{ VERSION: Array<{
"@etat"?: LegiArticleEtat "@etat"?: LegiArticleEtat
@ -53,7 +66,7 @@ export interface LegiArticle {
"@fin": string "@fin": string
"@id": string "@id": string
"@num"?: string "@num"?: string
"@origine": LegiArticleLienArticleOrigine "@origine": LegiArticleOrigine
} }
}> }>
} }
@ -81,7 +94,7 @@ export type LegiArticleType = (typeof allLegiArticleTypes)[number]
/// Table des matières (TM) /// Table des matières (TM)
export interface LegiArticleTm { export interface LegiArticleTm {
TITRE_TM: { TITRE_TM: {
"#text"?: string "#text": string
"@debut": string "@debut": string
"@fin": string "@fin": string
"@id": string "@id": string

View file

@ -16,12 +16,15 @@ import { auditId, auditVersions } from "$lib/auditors/legal"
import { import {
auditJo, auditJo,
auditJorfArticle, auditJorfArticle,
joStats, auditJorfSectionTa,
// jorfArticleStats,
jorfSectionTaStats,
// joStats,
} from "$lib/auditors/jorf" } from "$lib/auditors/jorf"
import type { import type {
Jo, Jo,
JorfArticle, JorfArticle,
SectionTa, JorfSectionTa,
Textelr, Textelr,
TexteVersion, TexteVersion,
Versions, Versions,
@ -483,10 +486,14 @@ async function importJorf(
} }
// console.log( // console.log(
// "JORF articles stats =", // "JORF ARTICLE stats =",
// JSON.stringify(jorfArticleStats, null, 2), // JSON.stringify(jorfArticleStats, null, 2),
// ) // )
console.log("JO stats =", JSON.stringify(joStats, null, 2)) // console.log("JO stats =", JSON.stringify(joStats, null, 2))
console.log(
"JORF SECTION_TA stats =",
JSON.stringify(jorfSectionTaStats, null, 2),
)
} }
sade("import_jorf <dilaDir>", true) sade("import_jorf <dilaDir>", true)