Add validation of LEGI objects
This commit is contained in:
parent
191a5ef637
commit
ad857f45f3
12 changed files with 2750 additions and 72 deletions
|
@ -251,7 +251,6 @@ function auditLienSectionTa(
|
|||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditNullish,
|
||||
// auditFunction((etat) => {
|
||||
// jorfSectionTaStats.countByLienSectionTaEtat[etat] =
|
||||
// (jorfSectionTaStats.countByLienSectionTaEtat[etat] ?? 0) + 1
|
||||
|
|
|
@ -674,17 +674,15 @@ function auditMetaTexteChronicle(
|
|||
),
|
||||
)
|
||||
}
|
||||
for (const key of ["ORIGINE_PUBLI"]) {
|
||||
audit.attribute(
|
||||
data,
|
||||
key,
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"ORIGINE_PUBLI",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
||||
|
|
|
@ -223,17 +223,15 @@ function auditLienSectionTa(
|
|||
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,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"#text",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
for (const key of ["@cid", "@id", "@url"]) {
|
||||
audit.attribute(
|
||||
data,
|
||||
|
@ -265,13 +263,13 @@ function auditLienSectionTa(
|
|||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditNullish,
|
||||
// auditFunction((etat) => {
|
||||
// jorfSectionTaStats.countByLienSectionTaEtat[etat] =
|
||||
// (jorfSectionTaStats.countByLienSectionTaEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
// auditOptions(allJorfSectionTaLienSectionTaEtatsMutable),
|
||||
auditNullish,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
|
@ -310,29 +308,25 @@ function auditLienTxt(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
|
|||
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,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"@id",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditRequire,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"@num",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
||||
|
@ -550,17 +544,15 @@ function auditMetaTexteChronicle(
|
|||
),
|
||||
)
|
||||
}
|
||||
for (const key of ["ORIGINE_PUBLI"]) {
|
||||
audit.attribute(
|
||||
data,
|
||||
key,
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"ORIGINE_PUBLI",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
export { auditLegiArticle, legiArticleStats } from "./articles"
|
||||
export { auditLegiSectionTa, legiSectionTaStats } from "./section_ta"
|
||||
export { auditLegiTextelr, legiTextelrStats } from "./textelr"
|
||||
export { auditLegiTexteVersion, legiTexteVersionStats } from "./texte_version"
|
||||
|
|
529
src/lib/auditors/legi/section_ta.ts
Normal file
529
src/lib/auditors/legi/section_ta.ts
Normal file
|
@ -0,0 +1,529 @@
|
|||
import {
|
||||
auditCleanArray,
|
||||
auditDateIso8601String,
|
||||
auditEmptyToNull,
|
||||
auditFunction,
|
||||
auditInteger,
|
||||
auditNullish,
|
||||
auditNumber,
|
||||
auditOptions,
|
||||
auditRequire,
|
||||
auditStringToNumber,
|
||||
auditSwitch,
|
||||
auditTrimString,
|
||||
type Audit,
|
||||
} from "@auditors/core"
|
||||
|
||||
import {
|
||||
allLegiSectionTaLienArtEtatsMutable,
|
||||
allLegiSectionTaLienArtOriginesMutable,
|
||||
allLegiSectionTaLienSectionTaEtatsMutable,
|
||||
allLegiSectionTaTexteNaturesMutable,
|
||||
} from "$lib/legal"
|
||||
|
||||
export const legiSectionTaStats: {
|
||||
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 auditLegiSectionTa(
|
||||
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,
|
||||
"COMMENTAIRE",
|
||||
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,
|
||||
),
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"TITRE_TA",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditSwitch(
|
||||
[auditNumber, auditFunction((num) => num.toString())],
|
||||
[auditTrimString, auditEmptyToNull],
|
||||
),
|
||||
)
|
||||
|
||||
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) => {
|
||||
// legiSectionTaStats.countByLienArtEtat[etat] =
|
||||
// (legiSectionTaStats.countByLienArtEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
auditOptions(allLegiSectionTaLienArtEtatsMutable),
|
||||
)
|
||||
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) => {
|
||||
// legiSectionTaStats.countByLienArtOrigine[origine] =
|
||||
// (legiSectionTaStats.countByLienArtOrigine[origine] ?? 0) + 1
|
||||
// return origine
|
||||
// }),
|
||||
auditOptions(allLegiSectionTaLienArtOriginesMutable),
|
||||
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,
|
||||
auditSwitch(
|
||||
[auditNumber, auditFunction((num) => num.toString())],
|
||||
[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,
|
||||
// auditFunction((etat) => {
|
||||
// legiSectionTaStats.countByLienSectionTaEtat[etat] =
|
||||
// (legiSectionTaStats.countByLienSectionTaEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
auditOptions(allLegiSectionTaLienSectionTaEtatsMutable),
|
||||
)
|
||||
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) => {
|
||||
// legiSectionTaStats.countByTexteNature[nature] =
|
||||
// (legiSectionTaStats.countByTexteNature[nature] ?? 0) + 1
|
||||
// return nature
|
||||
// }),
|
||||
auditOptions(allLegiSectionTaTexteNaturesMutable),
|
||||
)
|
||||
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,
|
||||
auditSwitch(
|
||||
[auditNumber, auditFunction((num) => num.toString())],
|
||||
[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,
|
||||
auditFunction((titreTm) => (Array.isArray(titreTm) ? titreTm : [titreTm])),
|
||||
auditCleanArray(auditTitreTm, auditRequire),
|
||||
auditRequire,
|
||||
)
|
||||
audit.attribute(data, "TM", true, errors, remainingKeys, auditTm)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
859
src/lib/auditors/legi/texte_version.ts
Normal file
859
src/lib/auditors/legi/texte_version.ts
Normal file
|
@ -0,0 +1,859 @@
|
|||
import {
|
||||
auditCleanArray,
|
||||
auditDateIso8601String,
|
||||
auditEmptyToNull,
|
||||
auditFunction,
|
||||
auditHttpUrl,
|
||||
auditInteger,
|
||||
auditNullish,
|
||||
auditNumber,
|
||||
auditOptions,
|
||||
auditRequire,
|
||||
auditSwitch,
|
||||
auditTrimString,
|
||||
type Audit,
|
||||
} from "@auditors/core"
|
||||
|
||||
import {
|
||||
allLegiTexteVersionEtatsMutable,
|
||||
allLegiTexteVersionLienNaturesMutable,
|
||||
allLegiTexteVersionLienTypesMutable,
|
||||
allLegiTexteVersionNaturesMutable,
|
||||
allLegiTexteVersionOriginesMutable,
|
||||
allSensMutable,
|
||||
} from "$lib/legal"
|
||||
|
||||
export const legiTexteVersionStats: {
|
||||
countByEtat: { [etat: string]: number }
|
||||
countByLienNature: { [nature: string]: number }
|
||||
countByLienType: { [type: string]: number }
|
||||
countByNature: { [nature: string]: number }
|
||||
countByOrigine: { [origine: string]: number }
|
||||
} = {
|
||||
countByEtat: {},
|
||||
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 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 auditLegiTexteVersion(
|
||||
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,
|
||||
"META",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditMeta,
|
||||
auditRequire,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"NOTA",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditNota,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"RECT",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditRect,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"SIGNATAIRES",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditSignataires,
|
||||
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", "@nortexte", "@num", "@numtexte"]) {
|
||||
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) => {
|
||||
// legiTexteVersionStats.countByLienNature[nature] =
|
||||
// (legiTexteVersionStats.countByLienNature[nature] ?? 0) + 1
|
||||
// return nature
|
||||
// }),
|
||||
auditOptions(allLegiTexteVersionLienNaturesMutable),
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"@sens",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditOptions(allSensMutable),
|
||||
auditRequire,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"@typelien",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
// auditFunction((type) => {
|
||||
// legiTexteVersionStats.countByLienType[type] =
|
||||
// (legiTexteVersionStats.countByLienType[type] ?? 0) + 1
|
||||
// return type
|
||||
// }),
|
||||
auditOptions(allLegiTexteVersionLienTypesMutable),
|
||||
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) => {
|
||||
// legiTexteVersionStats.countByNature[nature] =
|
||||
// (legiTexteVersionStats.countByNature[nature] ?? 0) + 1
|
||||
// return nature
|
||||
// }),
|
||||
auditOptions(allLegiTexteVersionNaturesMutable),
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"ORIGINE",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
// auditFunction((origine) => {
|
||||
// legiTexteVersionStats.countByOrigine[origine] =
|
||||
// (legiTexteVersionStats.countByOrigine[origine] ?? 0) + 1
|
||||
// return origine
|
||||
// }),
|
||||
auditOptions(allLegiTexteVersionOriginesMutable),
|
||||
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", "DERNIERE_MODIFICATION"]) {
|
||||
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],
|
||||
),
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"ORIGINE_PUBLI",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"VERSIONS_A_VENIR",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditSwitch(
|
||||
[auditTrimString, auditEmptyToNull, auditNullish],
|
||||
auditVersionsAVenir,
|
||||
),
|
||||
)
|
||||
|
||||
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,
|
||||
"ETAT",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
// auditFunction((etat) => {
|
||||
// legiTexteVersionStats.countByEtat[etat] =
|
||||
// (legiTexteVersionStats.countByEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
auditOptions(allLegiTexteVersionEtatsMutable),
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"LIENS",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditSwitch(auditTrimString, auditLiens),
|
||||
auditEmptyToNull,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"MCS_TXT",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditSwitch([auditTrimString, auditEmptyToNull, auditNullish], auditMcsTxt),
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"TITREFULL",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditRequire,
|
||||
)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
||||
|
||||
function auditNota(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 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)
|
||||
}
|
||||
|
||||
function auditVersionsAVenir(
|
||||
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_A_VENIR",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditFunction((date) => (Array.isArray(date) ? date : [date])),
|
||||
auditCleanArray(auditDateIso8601String, auditRequire),
|
||||
auditRequire,
|
||||
)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
662
src/lib/auditors/legi/textelr.ts
Normal file
662
src/lib/auditors/legi/textelr.ts
Normal file
|
@ -0,0 +1,662 @@
|
|||
import {
|
||||
auditCleanArray,
|
||||
auditDateIso8601String,
|
||||
auditEmptyToNull,
|
||||
auditFunction,
|
||||
auditHttpUrl,
|
||||
auditInteger,
|
||||
auditNullish,
|
||||
auditNumber,
|
||||
auditOptions,
|
||||
auditRequire,
|
||||
auditStringToNumber,
|
||||
auditSwitch,
|
||||
auditTrimString,
|
||||
type Audit,
|
||||
} from "@auditors/core"
|
||||
|
||||
import {
|
||||
allLegiTextelrEtatsMutable,
|
||||
allLegiTextelrLienArtEtatsMutable,
|
||||
allLegiTextelrLienArtOriginesMutable,
|
||||
allLegiTextelrLienSectionTaEtatsMutable,
|
||||
allLegiTextelrNaturesMutable,
|
||||
allLegiTextelrOriginesMutable,
|
||||
} from "$lib/legal"
|
||||
|
||||
export const legiTextelrStats: {
|
||||
countByEtat: { [etat: string]: number }
|
||||
countByLienArtEtat: { [etat: string]: number }
|
||||
countByLienArtNature: { [nature: string]: number }
|
||||
countByLienArtOrigine: { [origine: string]: number }
|
||||
countByLienSectionTaEtat: { [etat: string]: number }
|
||||
countByNature: { [nature: string]: number }
|
||||
countByOrigine: { [origine: string]: number }
|
||||
} = {
|
||||
countByEtat: {},
|
||||
countByLienArtEtat: {},
|
||||
countByLienArtNature: {},
|
||||
countByLienArtOrigine: {},
|
||||
countByLienSectionTaEtat: {},
|
||||
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))
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
||||
|
||||
export function auditLegiTextelr(
|
||||
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) => {
|
||||
// legiTextelrStats.countByLienArtEtat[etat] =
|
||||
// (legiTextelrStats.countByLienArtEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
auditOptions(allLegiTextelrLienArtEtatsMutable),
|
||||
)
|
||||
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,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"@origine",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
// auditFunction((origine) => {
|
||||
// legiTextelrStats.countByLienArtOrigine[origine] =
|
||||
// (legiTextelrStats.countByLienArtOrigine[origine] ?? 0) + 1
|
||||
// return origine
|
||||
// }),
|
||||
auditOptions(allLegiTextelrLienArtOriginesMutable),
|
||||
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", "@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,
|
||||
// auditFunction((etat) => {
|
||||
// legiTextelrStats.countByLienSectionTaEtat[etat] =
|
||||
// (legiTextelrStats.countByLienSectionTaEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
auditOptions(allLegiTextelrLienSectionTaEtatsMutable),
|
||||
)
|
||||
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,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"@id",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditRequire,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"@num",
|
||||
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,
|
||||
auditEmptyToNull,
|
||||
auditNullish,
|
||||
)
|
||||
for (const key of ["ID", "URL"]) {
|
||||
audit.attribute(
|
||||
data,
|
||||
key,
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
auditRequire,
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"NATURE",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
// auditFunction((nature) => {
|
||||
// legiTextelrStats.countByNature[nature] =
|
||||
// (legiTextelrStats.countByNature[nature] ?? 0) + 1
|
||||
// return nature
|
||||
// }),
|
||||
auditOptions(allLegiTextelrNaturesMutable),
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"ORIGINE",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
// auditFunction((origine) => {
|
||||
// legiTextelrStats.countByOrigine[origine] =
|
||||
// (legiTextelrStats.countByOrigine[origine] ?? 0) + 1
|
||||
// return origine
|
||||
// }),
|
||||
auditOptions(allLegiTextelrOriginesMutable),
|
||||
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", "DERNIERE_MODIFICATION"]) {
|
||||
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],
|
||||
),
|
||||
)
|
||||
}
|
||||
audit.attribute(
|
||||
data,
|
||||
"ORIGINE_PUBLI",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditTrimString,
|
||||
auditEmptyToNull,
|
||||
)
|
||||
audit.attribute(
|
||||
data,
|
||||
"VERSIONS_A_VENIR",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditSwitch(
|
||||
[auditTrimString, auditEmptyToNull, auditNullish],
|
||||
auditVersionsAVenir,
|
||||
),
|
||||
)
|
||||
|
||||
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) => {
|
||||
// legiTextelrStats.countByEtat[etat] =
|
||||
// (legiTextelrStats.countByEtat[etat] ?? 0) + 1
|
||||
// return etat
|
||||
// }),
|
||||
auditOptions(allLegiTextelrEtatsMutable),
|
||||
)
|
||||
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)
|
||||
}
|
||||
|
||||
function auditVersionsAVenir(
|
||||
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_A_VENIR",
|
||||
true,
|
||||
errors,
|
||||
remainingKeys,
|
||||
auditFunction((date) => (Array.isArray(date) ? date : [date])),
|
||||
auditCleanArray(auditDateIso8601String, auditRequire),
|
||||
auditRequire,
|
||||
)
|
||||
|
||||
return audit.reduceRemaining(data, errors, remainingKeys)
|
||||
}
|
|
@ -78,6 +78,36 @@ export {
|
|||
allLegiArticleTexteNaturesMutable,
|
||||
allLegiArticleTypes,
|
||||
allLegiArticleTypesMutable,
|
||||
allLegiSectionTaLienArtEtats,
|
||||
allLegiSectionTaLienArtEtatsMutable,
|
||||
allLegiSectionTaLienArtOrigines,
|
||||
allLegiSectionTaLienArtOriginesMutable,
|
||||
allLegiSectionTaLienSectionTaEtats,
|
||||
allLegiSectionTaLienSectionTaEtatsMutable,
|
||||
allLegiSectionTaTexteNatures,
|
||||
allLegiSectionTaTexteNaturesMutable,
|
||||
allLegiTextelrEtats,
|
||||
allLegiTextelrEtatsMutable,
|
||||
allLegiTextelrLienArtEtats,
|
||||
allLegiTextelrLienArtEtatsMutable,
|
||||
allLegiTextelrLienArtOrigines,
|
||||
allLegiTextelrLienArtOriginesMutable,
|
||||
allLegiTextelrLienSectionTaEtats,
|
||||
allLegiTextelrLienSectionTaEtatsMutable,
|
||||
allLegiTextelrNatures,
|
||||
allLegiTextelrNaturesMutable,
|
||||
allLegiTextelrOrigines,
|
||||
allLegiTextelrOriginesMutable,
|
||||
allLegiTexteVersionEtats,
|
||||
allLegiTexteVersionEtatsMutable,
|
||||
allLegiTexteVersionLienNatures,
|
||||
allLegiTexteVersionLienNaturesMutable,
|
||||
allLegiTexteVersionLienTypes,
|
||||
allLegiTexteVersionLienTypesMutable,
|
||||
allLegiTexteVersionNatures,
|
||||
allLegiTexteVersionNaturesMutable,
|
||||
allLegiTexteVersionOrigines,
|
||||
allLegiTexteVersionOriginesMutable,
|
||||
allSens,
|
||||
allSensMutable,
|
||||
type DossierLegislatif,
|
||||
|
@ -114,6 +144,22 @@ export {
|
|||
type LegiArticleOrigine,
|
||||
type LegiArticleTexteNature,
|
||||
type LegiArticleType,
|
||||
type LegiSectionTa,
|
||||
type LegiSectionTaLienArtEtat,
|
||||
type LegiSectionTaTexteNature,
|
||||
type LegiTextelr,
|
||||
type LegiTextelrEtat,
|
||||
type LegiTextelrLienArtEtat,
|
||||
type LegiTextelrLienArtOrigine,
|
||||
type LegiTextelrLienSectionTaEtat,
|
||||
type LegiTextelrNature,
|
||||
type LegiTextelrOrigine,
|
||||
type LegiTexteVersion,
|
||||
type LegiTexteVersionEtat,
|
||||
type LegiTexteVersionLienNature,
|
||||
type LegiTexteVersionLienType,
|
||||
type LegiTexteVersionNature,
|
||||
type LegiTexteVersionOrigine,
|
||||
type Sens,
|
||||
} from "./legal"
|
||||
|
||||
|
|
|
@ -93,6 +93,36 @@ export {
|
|||
allLegiArticleTexteNaturesMutable,
|
||||
allLegiArticleTypes,
|
||||
allLegiArticleTypesMutable,
|
||||
allLegiSectionTaLienArtEtats,
|
||||
allLegiSectionTaLienArtEtatsMutable,
|
||||
allLegiSectionTaLienArtOrigines,
|
||||
allLegiSectionTaLienArtOriginesMutable,
|
||||
allLegiSectionTaLienSectionTaEtats,
|
||||
allLegiSectionTaLienSectionTaEtatsMutable,
|
||||
allLegiSectionTaTexteNatures,
|
||||
allLegiSectionTaTexteNaturesMutable,
|
||||
allLegiTextelrEtats,
|
||||
allLegiTextelrEtatsMutable,
|
||||
allLegiTextelrLienArtEtats,
|
||||
allLegiTextelrLienArtEtatsMutable,
|
||||
allLegiTextelrLienArtOrigines,
|
||||
allLegiTextelrLienArtOriginesMutable,
|
||||
allLegiTextelrLienSectionTaEtats,
|
||||
allLegiTextelrLienSectionTaEtatsMutable,
|
||||
allLegiTextelrNatures,
|
||||
allLegiTextelrNaturesMutable,
|
||||
allLegiTextelrOrigines,
|
||||
allLegiTextelrOriginesMutable,
|
||||
allLegiTexteVersionEtats,
|
||||
allLegiTexteVersionEtatsMutable,
|
||||
allLegiTexteVersionLienNatures,
|
||||
allLegiTexteVersionLienNaturesMutable,
|
||||
allLegiTexteVersionLienTypes,
|
||||
allLegiTexteVersionLienTypesMutable,
|
||||
allLegiTexteVersionNatures,
|
||||
allLegiTexteVersionNaturesMutable,
|
||||
allLegiTexteVersionOrigines,
|
||||
allLegiTexteVersionOriginesMutable,
|
||||
type LegiArticle,
|
||||
type LegiArticleEtat,
|
||||
type LegiArticleLienArticleOrigine,
|
||||
|
@ -102,6 +132,22 @@ export {
|
|||
type LegiArticleOrigine,
|
||||
type LegiArticleTexteNature,
|
||||
type LegiArticleType,
|
||||
type LegiSectionTa,
|
||||
type LegiSectionTaLienArtEtat,
|
||||
type LegiSectionTaTexteNature,
|
||||
type LegiTextelr,
|
||||
type LegiTextelrEtat,
|
||||
type LegiTextelrLienArtEtat,
|
||||
type LegiTextelrLienArtOrigine,
|
||||
type LegiTextelrLienSectionTaEtat,
|
||||
type LegiTextelrNature,
|
||||
type LegiTextelrOrigine,
|
||||
type LegiTexteVersion,
|
||||
type LegiTexteVersionEtat,
|
||||
type LegiTexteVersionLienNature,
|
||||
type LegiTexteVersionLienType,
|
||||
type LegiTexteVersionNature,
|
||||
type LegiTexteVersionOrigine,
|
||||
} from "./legi"
|
||||
export { allSens, allSensMutable, type Sens } from "./shared"
|
||||
|
||||
|
|
|
@ -187,7 +187,65 @@ interface JorfSectionTaTm {
|
|||
}
|
||||
|
||||
export interface JorfTextelr {
|
||||
// TODO
|
||||
META: {
|
||||
META_COMMUN: {
|
||||
ANCIEN_ID?: string
|
||||
ELI_ALIAS?: {
|
||||
ID_ELI_ALIAS: string
|
||||
}
|
||||
ID: string
|
||||
ID_ELI?: string
|
||||
NATURE?: JorfTextelrNature
|
||||
ORIGINE: JorfTextelrOrigine
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
STRUCT?: {
|
||||
LIEN_ART?: Array<{
|
||||
"@debut": string
|
||||
"@etat"?: JorfTextelrLienArtEtat
|
||||
"@fin": string
|
||||
"@id": string
|
||||
// "@nature"?: undefined
|
||||
"@num"?: string
|
||||
"@origine"?: JorfTextelrLienArtOrigine
|
||||
}>
|
||||
LIEN_SECTION_TA?: Array<{
|
||||
"#text"?: string
|
||||
"@cid": string
|
||||
"@debut": string
|
||||
// "@etat"?: undefined
|
||||
"@fin": string
|
||||
"@id": string
|
||||
"@niv": number
|
||||
"@url": string
|
||||
}>
|
||||
}
|
||||
VERSIONS: {
|
||||
VERSION: Array<{
|
||||
"@etat"?: JorfTextelrEtat
|
||||
LIEN_TXT: {
|
||||
"@debut": string
|
||||
"@fin": string
|
||||
"@id": string
|
||||
"@num"?: string
|
||||
}
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
export type JorfTextelrEtat = (typeof allJorfTextelrEtats)[number]
|
||||
|
|
|
@ -89,8 +89,6 @@ export type LegiArticleOrigine = (typeof allLegiArticleOrigines)[number]
|
|||
|
||||
export type LegiArticleTexteNature = (typeof allLegiArticleTexteNatures)[number]
|
||||
|
||||
export type LegiArticleType = (typeof allLegiArticleTypes)[number]
|
||||
|
||||
/// Table des matières (TM)
|
||||
export interface LegiArticleTm {
|
||||
TITRE_TM: {
|
||||
|
@ -102,6 +100,244 @@ export interface LegiArticleTm {
|
|||
TM?: LegiArticleTm
|
||||
}
|
||||
|
||||
export type LegiArticleType = (typeof allLegiArticleTypes)[number]
|
||||
|
||||
export interface LegiSectionTa {
|
||||
COMMENTAIRE?: string
|
||||
CONTEXTE: {
|
||||
TEXTE: {
|
||||
"@autorite"?: string
|
||||
"@cid": string
|
||||
"@date_publi": string
|
||||
"@date_signature": string
|
||||
"@ministere"?: string
|
||||
"@nature"?: LegiSectionTaTexteNature
|
||||
"@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?: LegiSectionTaTm[]
|
||||
}
|
||||
}
|
||||
ID: string
|
||||
STRUCTURE_TA?: Array<{
|
||||
LIEN_ART?: Array<{
|
||||
"@debut": string
|
||||
"@etat"?: LegiSectionTaLienArtEtat
|
||||
"@fin": string
|
||||
"@id": string
|
||||
"@num"?: string
|
||||
"@origine": LegiSectionTaLienArtOrigine
|
||||
}>
|
||||
LIEN_SECTION_TA?: Array<{
|
||||
"#text"?: string
|
||||
"@cid": string
|
||||
"@debut": string
|
||||
"@etat"?: LegiSectionTaLienSectionTaEtat
|
||||
"@fin": string
|
||||
"@id": string
|
||||
"@niv": number
|
||||
"@url": string
|
||||
}>
|
||||
}>
|
||||
TITRE_TA?: string
|
||||
}
|
||||
|
||||
export type LegiSectionTaLienArtEtat =
|
||||
(typeof allLegiSectionTaLienArtEtats)[number]
|
||||
|
||||
export type LegiSectionTaLienArtOrigine =
|
||||
(typeof allLegiSectionTaLienArtOrigines)[number]
|
||||
|
||||
export type LegiSectionTaLienSectionTaEtat =
|
||||
(typeof allLegiSectionTaLienSectionTaEtats)[number]
|
||||
|
||||
export type LegiSectionTaTexteNature =
|
||||
(typeof allLegiSectionTaTexteNatures)[number]
|
||||
|
||||
interface LegiSectionTaTm {
|
||||
TITRE_TM: {
|
||||
"#text"?: string
|
||||
"@debut": string
|
||||
"@fin": string
|
||||
"@id": string
|
||||
}
|
||||
TM?: LegiSectionTaTm
|
||||
}
|
||||
|
||||
export interface LegiTextelr {
|
||||
META: {
|
||||
META_COMMUN: {
|
||||
ANCIEN_ID?: string
|
||||
ID: string
|
||||
NATURE?: LegiTextelrNature
|
||||
ORIGINE: LegiTextelrOrigine
|
||||
URL: string
|
||||
}
|
||||
META_SPEC: {
|
||||
META_TEXTE_CHRONICLE: {
|
||||
CID: string
|
||||
DATE_PUBLI: string
|
||||
DATE_TEXTE: string
|
||||
DERNIERE_MODIFICATION: string
|
||||
NOR?: string
|
||||
NUM?: string
|
||||
NUM_PARUTION?: number
|
||||
NUM_SEQUENCE?: number
|
||||
ORIGINE_PUBLI?: string
|
||||
PAGE_DEB_PUBLI?: number
|
||||
PAGE_FIN_PUBLI?: number
|
||||
VERSIONS_A_VENIR?: {
|
||||
VERSION_A_VENIR: string[]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
STRUCT?: {
|
||||
LIEN_ART?: Array<{
|
||||
"@debut": string
|
||||
"@etat"?: LegiTextelrLienArtEtat
|
||||
"@fin": string
|
||||
"@id": string
|
||||
// "@nature"?: undefined
|
||||
"@num"?: string
|
||||
"@origine": LegiTextelrLienArtOrigine
|
||||
}>
|
||||
LIEN_SECTION_TA?: Array<{
|
||||
"#text": string
|
||||
"@cid": string
|
||||
"@debut": string
|
||||
"@etat"?: LegiTextelrLienSectionTaEtat
|
||||
"@fin": string
|
||||
"@id": string
|
||||
"@niv": number
|
||||
"@url": string
|
||||
}>
|
||||
}
|
||||
VERSIONS: {
|
||||
VERSION: Array<{
|
||||
"@etat"?: LegiTextelrEtat
|
||||
LIEN_TXT: {
|
||||
"@debut": string
|
||||
"@fin": string
|
||||
"@id": string
|
||||
"@num"?: string
|
||||
}
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
export type LegiTextelrEtat = (typeof allLegiTextelrEtats)[number]
|
||||
|
||||
export type LegiTextelrLienArtEtat = (typeof allLegiTextelrLienArtEtats)[number]
|
||||
|
||||
export type LegiTextelrLienArtOrigine =
|
||||
(typeof allLegiTextelrLienArtOrigines)[number]
|
||||
|
||||
export type LegiTextelrLienSectionTaEtat =
|
||||
(typeof allLegiTextelrLienSectionTaEtats)[number]
|
||||
|
||||
export type LegiTextelrNature = (typeof allLegiTextelrNatures)[number]
|
||||
|
||||
export type LegiTextelrOrigine = (typeof allLegiTextelrOrigines)[number]
|
||||
|
||||
export interface LegiTexteVersion {
|
||||
ABRO?: {
|
||||
CONTENU: string // HTML
|
||||
}
|
||||
META: {
|
||||
META_COMMUN: {
|
||||
ANCIEN_ID?: string
|
||||
ELI_ALIAS?: {
|
||||
ID_ELI_ALIAS: string
|
||||
}
|
||||
ID: string
|
||||
ID_ELI?: string
|
||||
NATURE?: LegiTexteVersionNature
|
||||
ORIGINE: LegiTexteVersionOrigine
|
||||
URL: string
|
||||
}
|
||||
META_SPEC: {
|
||||
META_TEXTE_CHRONICLE: {
|
||||
CID: string
|
||||
DATE_PUBLI: string
|
||||
DATE_TEXTE: string
|
||||
DERNIERE_MODIFICATION: string
|
||||
NOR?: string
|
||||
NUM?: string
|
||||
NUM_PARUTION?: number
|
||||
NUM_SEQUENCE?: number
|
||||
ORIGINE_PUBLI?: string
|
||||
PAGE_DEB_PUBLI?: number
|
||||
PAGE_FIN_PUBLI?: number
|
||||
VERSIONS_A_VENIR?: {
|
||||
VERSION_A_VENIR: string[]
|
||||
}
|
||||
}
|
||||
META_TEXTE_VERSION: {
|
||||
AUTORITE?: string
|
||||
DATE_DEBUT?: string
|
||||
DATE_FIN?: string
|
||||
ETAT?: LegiTexteVersionEtat
|
||||
LIENS?: {
|
||||
LIEN: Array<{
|
||||
"#text"?: string
|
||||
"@cidtexte"?: string
|
||||
"@datesignatexte"?: string
|
||||
"@id"?: string
|
||||
"@naturetexte"?: LegiTexteVersionLienNature
|
||||
"@num"?: string
|
||||
"@nortexte"?: string
|
||||
"@numtexte"?: string
|
||||
"@sens": Sens
|
||||
"@typelien": LegiTexteVersionLienType
|
||||
}>
|
||||
}
|
||||
MCS_TXT?: {
|
||||
MC: string[]
|
||||
}
|
||||
MINISTERE?: string
|
||||
TITRE?: string
|
||||
TITREFULL: string
|
||||
}
|
||||
}
|
||||
}
|
||||
NOTA?: {
|
||||
CONTENU: string // HTML
|
||||
}
|
||||
RECT?: {
|
||||
CONTENU: string // HTML
|
||||
}
|
||||
SIGNATAIRES?: {
|
||||
CONTENU: string // HTML
|
||||
}
|
||||
TP?: {
|
||||
CONTENU: string // HTML
|
||||
}
|
||||
VISAS?: {
|
||||
CONTENU: string // HTML
|
||||
}
|
||||
}
|
||||
|
||||
export type LegiTexteVersionEtat = (typeof allLegiTexteVersionEtats)[number]
|
||||
|
||||
export type LegiTexteVersionLienNature =
|
||||
(typeof allLegiTexteVersionLienNatures)[number]
|
||||
|
||||
export type LegiTexteVersionLienType =
|
||||
(typeof allLegiTexteVersionLienTypes)[number]
|
||||
|
||||
export type LegiTexteVersionNature = (typeof allLegiTexteVersionNatures)[number]
|
||||
|
||||
export type LegiTexteVersionOrigine =
|
||||
(typeof allLegiTexteVersionOrigines)[number]
|
||||
|
||||
export const allLegiArticleEtats = [
|
||||
"ABROGE_DIFF", // 16233
|
||||
"ABROGE", // 341353
|
||||
|
@ -192,7 +428,7 @@ export const allLegiArticleLienTypesMutable = [...allLegiArticleLienTypes]
|
|||
export const allLegiArticleNatures = ["Article"] as const
|
||||
export const allLegiArticleNaturesMutable = [...allLegiArticleNatures]
|
||||
|
||||
export const allLegiArticleOrigines = ["LEGI"] as const
|
||||
export const allLegiArticleOrigines = ["JORF", "LEGI"] as const
|
||||
export const allLegiArticleOriginesMutable = [...allLegiArticleOrigines]
|
||||
|
||||
export const allLegiArticleTexteNatures = [
|
||||
|
@ -223,3 +459,195 @@ export const allLegiArticleTypes = [
|
|||
"PARTIELLEMENT_MODIF",
|
||||
] as const
|
||||
export const allLegiArticleTypesMutable = [...allLegiArticleTypes]
|
||||
|
||||
export const allLegiSectionTaLienArtEtats = [
|
||||
"ABROGE_DIFF", // 7802
|
||||
"ABROGE", // 226461
|
||||
"ANNULE", // 1163
|
||||
"DISJOINT", // 92
|
||||
"MODIFIE_MORT_NE", // 7125
|
||||
"MODIFIE", // 399735
|
||||
"PERIME", // 4899
|
||||
"TRANSFERE", // 17504
|
||||
"VIGUEUR_DIFF", // 8862
|
||||
"VIGUEUR", // 346656
|
||||
] as const
|
||||
export const allLegiSectionTaLienArtEtatsMutable = [
|
||||
...allLegiSectionTaLienArtEtats,
|
||||
]
|
||||
|
||||
export const allLegiSectionTaLienArtOrigines = ["LEGI"] as const
|
||||
export const allLegiSectionTaLienArtOriginesMutable = [
|
||||
...allLegiSectionTaLienArtOrigines,
|
||||
]
|
||||
|
||||
export const allLegiSectionTaLienSectionTaEtats = [
|
||||
"ABROGE_DIFF", // 1193
|
||||
"ABROGE", // 58938
|
||||
"ANNULE", // 165
|
||||
"MODIFIE_MORT_NE", // 276
|
||||
"MODIFIE", // 14034
|
||||
"PERIME", // 1051
|
||||
"TRANSFERE", // 169
|
||||
"VIGUEUR_DIFF", // 1840
|
||||
"VIGUEUR", // 95108
|
||||
] as const
|
||||
export const allLegiSectionTaLienSectionTaEtatsMutable = [
|
||||
...allLegiSectionTaLienSectionTaEtats,
|
||||
]
|
||||
|
||||
export const allLegiSectionTaTexteNatures = [
|
||||
"ACCORD_FONCTION_PUBLIQUE", // 2
|
||||
"ARRETE", // 56659
|
||||
"CODE", // 102450
|
||||
"CONSTITUTION", // 34
|
||||
"DECISION", // 5
|
||||
"DECRET_LOI", // 74
|
||||
"DECRET", // 51211
|
||||
"DELIBERATION", // 587
|
||||
"DIRECTIVE", // 18
|
||||
"LOI_CONSTIT", // 4
|
||||
"LOI_ORGANIQUE", // 154
|
||||
"LOI_PROGRAMME", // 9
|
||||
"LOI", // 12005
|
||||
"ORDONNANCE", // 4639
|
||||
] as const
|
||||
export const allLegiSectionTaTexteNaturesMutable = [
|
||||
...allLegiSectionTaTexteNatures,
|
||||
]
|
||||
|
||||
export const allLegiTextelrEtats = [
|
||||
"ABROGE_DIFF", // 1897
|
||||
"ABROGE", // 24375
|
||||
"ANNULE", // 210
|
||||
"MODIFIE_MORT_NE", // 65
|
||||
"MODIFIE", // 9270
|
||||
"PERIME", // 3629
|
||||
"VIGUEUR_DIFF", // 2086
|
||||
"VIGUEUR", // 103917
|
||||
] as const
|
||||
export const allLegiTextelrEtatsMutable = [...allLegiTextelrEtats]
|
||||
|
||||
export const allLegiTextelrLienArtEtats = [
|
||||
"ABROGE_DIFF", // 9742
|
||||
"ABROGE", // 134670
|
||||
"ANNULE", // 878
|
||||
"MODIFIE_MORT_NE", // 795
|
||||
"MODIFIE", // 90079
|
||||
"PERIME", // 15026
|
||||
"TRANSFERE", // 943
|
||||
"VIGUEUR_DIFF", // 6195
|
||||
"VIGUEUR", // 311266
|
||||
] as const
|
||||
export const allLegiTextelrLienArtEtatsMutable = [...allLegiTextelrLienArtEtats]
|
||||
|
||||
export const allLegiTextelrLienArtOrigines = ["LEGI"] as const
|
||||
export const allLegiTextelrLienArtOriginesMutable = [
|
||||
...allLegiTextelrLienArtOrigines,
|
||||
]
|
||||
|
||||
export const allLegiTextelrLienSectionTaEtats = [
|
||||
"ABROGE_DIFF", // 1395
|
||||
"ABROGE", // 24538
|
||||
"ANNULE", // 148
|
||||
"MODIFIE_MORT_NE", // 38
|
||||
"MODIFIE", // 1388
|
||||
"PERIME", // 572
|
||||
"TRANSFERE", // 6
|
||||
"VIGUEUR_DIFF", // 1816
|
||||
"VIGUEUR", // 48481
|
||||
] as const
|
||||
export const allLegiTextelrLienSectionTaEtatsMutable = [
|
||||
...allLegiTextelrLienSectionTaEtats,
|
||||
]
|
||||
|
||||
export const allLegiTextelrNatures = [
|
||||
"ACCORD_FONCTION_PUBLIQUE", // 4
|
||||
"ARRETE", // 77686
|
||||
"AVIS", // 12
|
||||
"CODE", // 114
|
||||
"CONSTITUTION", // 3
|
||||
"CONVENTION", // 1
|
||||
"DECISION", // 12
|
||||
"DECLARATION", // 1
|
||||
"DECRET_LOI", // 35
|
||||
"DECRET", // 53031
|
||||
"DELIBERATION", // 11
|
||||
"LOI_CONSTIT", // 19
|
||||
"LOI_ORGANIQUE", // 111
|
||||
"LOI", // 3457
|
||||
"ORDONNANCE", // 1520
|
||||
] as const
|
||||
export const allLegiTextelrNaturesMutable = [...allLegiTextelrNatures]
|
||||
|
||||
export const allLegiTextelrOrigines = ["LEGI"] as const
|
||||
export const allLegiTextelrOriginesMutable = [...allLegiTextelrOrigines]
|
||||
|
||||
export const allLegiTexteVersionEtats = [
|
||||
"ABROGE_DIFF", // 1712
|
||||
"ABROGE", // 23360
|
||||
"ANNULE", // 205
|
||||
"MODIFIE_MORT_NE", // 36
|
||||
"MODIFIE", // 3833
|
||||
"PERIME", // 3601
|
||||
"VIGUEUR_DIFF", // 2073
|
||||
"VIGUEUR", // 101189
|
||||
] as const
|
||||
export const allLegiTexteVersionEtatsMutable = [...allLegiTexteVersionEtats]
|
||||
|
||||
export const allLegiTexteVersionLienNatures = [] as const
|
||||
export const allLegiTexteVersionLienNaturesMutable = [
|
||||
...allLegiTexteVersionLienNatures,
|
||||
]
|
||||
|
||||
export const allLegiTexteVersionLienTypes = [
|
||||
"ABROGATION", // 8409
|
||||
"ABROGE", // 19027
|
||||
"ANNULATION", // 246
|
||||
"ANNULE", // 2
|
||||
"APPLICATION", // 9114
|
||||
"CITATION", // 271999
|
||||
"CODIFICATION", // 10433
|
||||
"CONCORDANCE", // 79
|
||||
"CONCORDE", // 9
|
||||
"CREATION", // 1711
|
||||
"HISTO", // 22
|
||||
"MODIFICATION", // 2116
|
||||
"MODIFIE", // 3557
|
||||
"PEREMPTION", // 5628
|
||||
"PERIME", // 4
|
||||
"RATIFICATION", // 261
|
||||
"RATIFIE", // 53
|
||||
"RECTIFICATION", // 90
|
||||
"SPEC_APPLI", // 1766
|
||||
"TRANSPOSITION", // 74
|
||||
"TXT_ASSOCIE", // 4469
|
||||
"TXT_SOURCE", // 19858
|
||||
] as const
|
||||
export const allLegiTexteVersionLienTypesMutable = [
|
||||
...allLegiTexteVersionLienTypes,
|
||||
]
|
||||
|
||||
export const allLegiTexteVersionNatures = [
|
||||
"ACCORD_FONCTION_PUBLIQUE", // 4
|
||||
"ARRETE", // 77680
|
||||
"AVIS", // 12
|
||||
"CODE", // 114
|
||||
"CONSTITUTION", // 3
|
||||
"CONVENTION", // 1
|
||||
"DECISION", // 12
|
||||
"DECLARATION", // 1
|
||||
"DECRET_LOI", // 35
|
||||
"DECRET", // 53030
|
||||
"DELIBERATION", // 11
|
||||
"LOI_CONSTIT", // 19
|
||||
"LOI_ORGANIQUE", // 111
|
||||
"LOI", // 3457
|
||||
"ORDONNANCE", // 1520
|
||||
] as const
|
||||
export const allLegiTexteVersionNaturesMutable = [...allLegiTexteVersionNatures]
|
||||
|
||||
export const allLegiTexteVersionOrigines = ["LEGI"] as const
|
||||
export const allLegiTexteVersionOriginesMutable = [
|
||||
...allLegiTexteVersionOrigines,
|
||||
]
|
||||
|
|
|
@ -15,13 +15,19 @@ import sade from "sade"
|
|||
import { auditId, auditVersions } from "$lib/auditors/legal"
|
||||
import {
|
||||
auditLegiArticle,
|
||||
auditLegiSectionTa,
|
||||
auditLegiTextelr,
|
||||
auditLegiTexteVersion,
|
||||
// legiArticleStats
|
||||
// legiSectionTaStats,
|
||||
// legiTextelrStats,
|
||||
// legiTexteVersionStats,
|
||||
} from "$lib/auditors/legi"
|
||||
import type {
|
||||
LegiArticle,
|
||||
SectionTa,
|
||||
Textelr,
|
||||
TexteVersion,
|
||||
LegiSectionTa,
|
||||
LegiTextelr,
|
||||
LegiTexteVersion,
|
||||
Versions,
|
||||
XmlHeader,
|
||||
} from "$lib/legal"
|
||||
|
@ -175,7 +181,14 @@ async function importLegi(
|
|||
const xmlData = xmlParser.parse(xmlString)
|
||||
for (const [tag, element] of Object.entries(xmlData) as [
|
||||
CategoryTag | "?xml",
|
||||
LegiArticle | SectionTa | Textelr | TexteVersion | Versions | XmlHeader,
|
||||
(
|
||||
| LegiArticle
|
||||
| LegiSectionTa
|
||||
| LegiTextelr
|
||||
| LegiTexteVersion
|
||||
| Versions
|
||||
| XmlHeader
|
||||
),
|
||||
][]) {
|
||||
switch (tag) {
|
||||
case "?xml": {
|
||||
|
@ -250,7 +263,19 @@ async function importLegi(
|
|||
break
|
||||
case "SECTION_TA":
|
||||
if (categoryTag === undefined || categoryTag === tag) {
|
||||
const section = element as SectionTa
|
||||
const [section, error] = auditChain(
|
||||
auditLegiSectionTa,
|
||||
auditRequire,
|
||||
)(strictAudit, element) as [LegiSectionTa, unknown]
|
||||
assert.strictEqual(
|
||||
error,
|
||||
null,
|
||||
`Unexpected format for SECTION_TA:\n${JSON.stringify(
|
||||
section,
|
||||
null,
|
||||
2,
|
||||
)}\nError:\n${JSON.stringify(error, null, 2)}`,
|
||||
)
|
||||
await db`
|
||||
INSERT INTO section_ta (
|
||||
id,
|
||||
|
@ -268,7 +293,19 @@ async function importLegi(
|
|||
break
|
||||
case "TEXTE_VERSION":
|
||||
if (categoryTag === undefined || categoryTag === tag) {
|
||||
const texteVersion = element as TexteVersion
|
||||
const [texteVersion, error] = auditChain(
|
||||
auditLegiTexteVersion,
|
||||
auditRequire,
|
||||
)(strictAudit, element) as [LegiTexteVersion, 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,
|
||||
|
@ -282,7 +319,7 @@ async function importLegi(
|
|||
) VALUES (
|
||||
${texteVersion.META.META_COMMUN.ID},
|
||||
${db.json(texteVersion as unknown as JSONValue)},
|
||||
${texteVersion.META.META_COMMUN.NATURE},
|
||||
${texteVersion.META.META_COMMUN.NATURE ?? ""},
|
||||
setweight(to_tsvector('french', ${textAFragments.join(
|
||||
" ",
|
||||
)}), 'A')
|
||||
|
@ -290,7 +327,7 @@ async function importLegi(
|
|||
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 ?? ""},
|
||||
text_search = setweight(to_tsvector('french', ${textAFragments.join(
|
||||
" ",
|
||||
)}), 'A')
|
||||
|
@ -300,7 +337,19 @@ async function importLegi(
|
|||
break
|
||||
case "TEXTELR":
|
||||
if (categoryTag === undefined || categoryTag === tag) {
|
||||
const textelr = element as Textelr
|
||||
const [textelr, error] = auditChain(
|
||||
auditLegiTextelr,
|
||||
auditRequire,
|
||||
)(strictAudit, element) as [LegiTextelr, 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,
|
||||
|
@ -412,9 +461,18 @@ async function importLegi(
|
|||
}
|
||||
}
|
||||
// console.log(
|
||||
// "LEGI articles stats =",
|
||||
// "LEGI ARTICLE stats =",
|
||||
// JSON.stringify(legiArticleStats, null, 2),
|
||||
// )
|
||||
// console.log(
|
||||
// "LEGI SECTION_TA stats =",
|
||||
// JSON.stringify(legiSectionTaStats, null, 2),
|
||||
// )
|
||||
// console.log("LEGI TEXTELR stats =", JSON.stringify(legiTextelrStats, null, 2))
|
||||
// console.log(
|
||||
// "LEGI TEXTE_VERSION stats =",
|
||||
// JSON.stringify(legiTexteVersionStats, null, 2),
|
||||
// )
|
||||
}
|
||||
|
||||
sade("import_legi <dilaDir>", true)
|
||||
|
|
Loading…
Reference in a new issue