From 709b3356c7c8e92c9e7522086747ad04dba3c5af Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Mon, 15 Aug 2022 20:34:20 +0200 Subject: [PATCH] Rename auditors module. --- src/lib/auditors/data.ts | 99 ---------------------------------- src/lib/scripts/import_jorf.ts | 2 +- src/lib/scripts/import_legi.ts | 2 +- 3 files changed, 2 insertions(+), 101 deletions(-) delete mode 100644 src/lib/auditors/data.ts diff --git a/src/lib/auditors/data.ts b/src/lib/auditors/data.ts deleted file mode 100644 index 34de0d0..0000000 --- a/src/lib/auditors/data.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { - type Audit, - auditChain, - auditRequire, - auditString, - auditTest, - auditOptions, -} from "@auditors/core" - -export const auditId = auditChain( - auditString, - auditTest((id) => id.length === 20, "Invalid length for ID"), -) - -export 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, - auditVersionsVersion, - auditRequire, - ) - - return audit.reduceRemaining(data, errors, remainingKeys) -} - -export function auditVersionsVersion( - 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", - true, - errors, - remainingKeys, - auditId, - auditRequire, - ) - audit.attribute( - data, - "@fin", - true, - errors, - remainingKeys, - auditString, - auditOptions(["2999-01-01"]), - auditRequire, - ) - audit.attribute( - data, - "@etat", - true, - errors, - remainingKeys, - auditString, - auditOptions([""]), - auditRequire, - ) - audit.attribute( - data, - "@debut", - true, - errors, - remainingKeys, - auditString, - auditOptions(["2999-01-01"]), - auditRequire, - ) - - return audit.reduceRemaining(data, errors, remainingKeys) -} diff --git a/src/lib/scripts/import_jorf.ts b/src/lib/scripts/import_jorf.ts index 59f0979..fcd69ea 100644 --- a/src/lib/scripts/import_jorf.ts +++ b/src/lib/scripts/import_jorf.ts @@ -7,7 +7,7 @@ import path from "path" import type { JSONValue } from "postgres" import sade from "sade" -import { auditId, auditVersions } from "$lib/auditors/data" +import { auditId, auditVersions } from "$lib/auditors/legal" import type { Article, Jo, diff --git a/src/lib/scripts/import_legi.ts b/src/lib/scripts/import_legi.ts index 4b57f8d..8007023 100644 --- a/src/lib/scripts/import_legi.ts +++ b/src/lib/scripts/import_legi.ts @@ -7,7 +7,7 @@ import path from "path" import type { JSONValue } from "postgres" import sade from "sade" -import { auditId, auditVersions } from "$lib/auditors/data" +import { auditId, auditVersions } from "$lib/auditors/legal" import type { Article, SectionTa,