🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@focus4/entities

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@focus4/entities - npm Package Compare versions

Comparing version
12.9.0
to
12.10.0
+13
lib/chunk-pbuEa-1d.js
//#region \0rolldown/runtime.js
var __defProp = Object.defineProperty;
var __exportAll = (all, no_symbols) => {
let target = {};
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
return target;
};
//#endregion
export { __exportAll as t };
{"version":3,"file":"focus4.entities.d.ts","names":[],"sources":["../src/types.ts","../src/builders/entity.ts","../src/builders/entry-builders.ts","../src/builders/entries.ts","../src/utils.ts"],"mappings":";;;;KAGY,aAAA,GAAgB,OAAA,YAAmB,OAAA,WAAkB,OAAA;;KAGrD,eAAA,GAAkB,QAAA,CAAS,OAAA,aAAoB,QAAA,CAAS,OAAA,YAAmB,QAAA,CAAS,OAAA;;KAGpF,aAAA,MAAmB,CAAA,SAAU,QAAA,aAAqB,EAAA,GAAK,CAAA;;QAG3D,MAAA;EAAA,UACM,MAAA,WAAiB,OAAA;IAVyC;IAYhE,MAAA,EAAQ,CAAA;EAAA;AAAA;;UAKC,UAAA,WAAqB,MAAA,kBAAwB,MAAA,CAAO,CAAA,cAAe,MAAA,CAAO,CAAA;EAAA,SAC9E,IAAA;EAfD;EAAA,SAkBC,SAAA,GAAY,CAAA;;WAGZ,MAAA,EAAQ,CAAA;EArBS;EAAA,SAwBjB,UAAA;EAxB8C;EAAA,SA2B9C,IAAA;EA3B0E;EAAA,SA8B1E,KAAA;EA9BkF;EAAA,SAiClF,OAAA;EAjC0B;EAAA,SAoC1B,YAAA,GAAe,CAAA;AAAA;;UAIX,WAAA,WAAsB,MAAA;EAAA,SAC1B,IAAA;EAzC0F;EAAA,SA4C1F,MAAA,EAAQ,CAAA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eAAA,CAAgB,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,UAAA;;AJvC5D;;;iBI+CgB,YAAA,CAAa,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,UAAA;;;;;iBAQzC,gBAAA,CAAiB,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,cAAA;;;;;iBAQ7C,WAAA,CAAY,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,QAAA,GAAW,MAAA;;;;;iBASnD,cAAA,CAAe,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,SAAA;AJrE3D;;;;AAAA,iBI6EgB,cAAA,CAAe,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,SAAA"}
+202
-3

@@ -1,3 +0,202 @@

export { e, entity } from "./builders";
export { isArraySchema, isBooleanSchema, isDateSchema, isDateTimeSchema, isIntSchema, isNumberSchema, isStringSchema, stringToSchemaOutput } from "./utils";
export type { Entity, EntityToType, FieldEntry, ListEntry, ObjectEntry, RecursiveListEntry, SingleZodType, ZodTypeMultiple, ZodTypeSingle } from "./types";
import { ZodArray, ZodBoolean, ZodISODate, ZodISODateTime, ZodInt, ZodInt32, ZodNumber, ZodString, ZodType, output } from "zod";
//#region src/types.d.ts
/** Correspond à un type de schéma pour un type primitif. */
type ZodTypeSingle = ZodType<boolean> | ZodType<number> | ZodType<string>;
/** Correspond à un type de schéma pour un type d'array de primitives. */
type ZodTypeMultiple = ZodArray<ZodType<boolean>> | ZodArray<ZodType<number>> | ZodArray<ZodType<string>>;
/** Récupère le type de domaine simple d'un type de domaine multiple. */
type SingleZodType<S> = S extends ZodArray<infer ES> ? ES : S;
/** Définition d'un domaine. */
declare global {
interface Domain<S extends ZodType = any> {
/** Schéma Zod d'un champ du domaine. */
schema: S;
}
}
/** Métadonnées d'une entrée de type "field" pour une entité. */
interface FieldEntry<D extends Domain = any, T extends output<D["schema"]> = output<D["schema"]>> {
readonly type: "field";
/** Type du champ, s'il est plus précis que celui du domaine. */
readonly fieldType?: T;
/** Domaine du champ. */
readonly domain: D;
/** Champ obligatoire. */
readonly isRequired: boolean;
/** Nom de l'entrée. */
readonly name: string;
/** Libellé de l'entrée. */
readonly label: string;
/** Commentaire de l'entrée */
readonly comment?: string;
/** Valeur par défaut du champ dans un formulaire. */
readonly defaultValue?: T;
}
/** Métadonnées d'une entrée de type "object" pour une entité. */
interface ObjectEntry<E extends Entity = any> {
readonly type: "object";
/** Entité de l'entrée */
readonly entity: E;
/** Objet obligatoire. Sera `true` si non renseigné. */
readonly isRequired?: boolean;
/** Libellé de l'entrée (non utilisé). */
readonly label?: string;
/** Commentaire de l'entrée (non utilisé). */
readonly comment?: string;
}
/** Métadonnées d'une entrée de type "list" pour une entité. */
interface ListEntry<E extends Entity = any> {
readonly type: "list";
/** Entité de l'entrée */
readonly entity: E;
/** Liste obligatoire. Sera `true` si non renseigné. */
readonly isRequired?: boolean;
/** Libellé de l'entrée (non utilisé). */
readonly label?: string;
/** Commentaire de l'entrée (non utilisé). */
readonly comment?: string;
}
/** Métadonnées d'une entrée de type "recursive-list" pour une entité. */
interface RecursiveListEntry {
readonly type: "recursive-list";
/** Liste obligatoire. Sera `true` si non renseigné. */
readonly isRequired?: boolean;
/** Libellé de l'entrée (non utilisé). */
readonly label?: string;
/** Commentaire de l'entrée (non utilisé). */
readonly comment?: string;
}
/** Génère le type associé à une entité, avec toutes ses propriétés en optionnel. */
type EntityToType<E extends Entity> = { -readonly [P in keyof E]?: E[P] extends FieldEntry ? E[P]["fieldType"] : E[P] extends ObjectEntry<infer OE> ? EntityToType<OE> : E[P] extends ListEntry<infer LE> ? EntityToType<LE>[] : E[P] extends RecursiveListEntry ? EntityToType<E>[] : E[P] extends [Entity] ? EntityToType<E[P][0]>[] : E[P] extends Entity ? EntityToType<E[P]> : never };
/** Définition d'une entité. */
interface Entity extends Record<string, FieldEntry | ObjectEntry | ListEntry | RecursiveListEntry | Entity | [Entity]> {}
//#endregion
//#region src/builders/entity.d.ts
/**
* Crée une entité à partir d'une définition d'entrées.
*
* La seule valeur ajoutée de cette fonction (pour l'instant) est de renseigner automatiquement le nom des champs créés.
*/
declare function entity<const E extends Entity>(entries: E): E;
//#endregion
//#region src/builders/entry-builders.d.ts
declare class EntryBuilder {
constructor(type: "field" | "object" | "list" | "recursive-list");
/** Rend l'entrée d'entité non-obligatoire. */
optional(): this;
/**
* Renseigne le libellé de l'entrée d'entité
* @param label Le libellé.
*/
label(label: string): this;
/**
* Renseigne le commentaire de l'entrée d'entité
* @param comment Le commentaire.
*/
comment(comment: string): this;
}
declare class FieldEntryBuilder<T = any> extends EntryBuilder {
constructor(domain: Domain);
/**
* Renseigne la valeur par défaut du champ.
* @param defaultValue La valeur par défaut.
*/
defaultValue(defaultValue: T): this;
/**
* Renseigne le nom du champ. Si non renseigné, il sera renseigné par la fonction `entity` avec le nom de la propriété dans l'objet.
* @param name Le nom du champ.
*/
name(name: string): this;
/** Précise le type du champ, au delà du type déduit de son schéma. Le nouveau type doit y être assignable à l'ancien. */
type<NT extends T>(): FieldEntryBuilder<NT>;
}
declare class ObjectEntryBuilder extends EntryBuilder {
constructor(e: Entity);
}
declare class ListEntryBuilder extends EntryBuilder {
constructor(e: Entity);
}
declare class RecursiveListEntryBuilder extends EntryBuilder {
entry: RecursiveListEntry;
constructor();
}
declare namespace entries_d_exports {
export { field, list, object, recursiveList };
}
/**
* Crée un champ pour une entité.
*
* (Le champ sera obligatoire par défaut)
* @param domain Le domaine du champ.
*/
declare function field<D extends Domain>(domain: D): FieldEntry<D>;
/**
* Crée un champ pour une entité.
*
* (Le champ sera obligatoire par défaut)
* @param domain Le domaine du champ.
* @param builder Le configurateur du champ.
*/
declare function field<D extends Domain, T extends output<D["schema"]> = output<D["schema"]>>(domain: D, builder: (f: FieldEntryBuilder<output<D["schema"]>>) => FieldEntryBuilder<T>): FieldEntry<D, T>;
/**
* Crée un composition simple pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
declare function object<const E extends Entity>(entity: E, builder?: (f: ObjectEntryBuilder) => ObjectEntryBuilder): ObjectEntry<E>;
/**
* Crée un composition liste pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
declare function list<const E extends Entity>(entity: E, builder?: (f: ListEntryBuilder) => ListEntryBuilder): ListEntry<E>;
/**
* Crée un composition de liste récursive (une liste de l'entité qui la contient).
* @param builder Le configurateur.
*/
declare function recursiveList(builder?: (f: RecursiveListEntryBuilder) => RecursiveListEntryBuilder): RecursiveListEntry;
//#endregion
//#region src/utils.d.ts
/**
* Convertit une valeur string dans le type du schéma demandé.
* @param value Valeur à convertir.
*/
declare function stringToSchemaOutput<S extends ZodType>(value: string | undefined, schema: S): output<S> | undefined;
/**
* Teste si le schéma est un schéma array.
* @param schema Le schéma.
*/
declare function isArraySchema(schema: ZodType): schema is ZodArray<ZodType>;
/**
* Teste si le schéma est un schéma boolean.
* @param schema Le schéma.
*/
declare function isBooleanSchema(schema: ZodType): schema is ZodBoolean;
/**
* Teste si le schéma est un schéma date.
* @param schema Le schéma.
*/
declare function isDateSchema(schema: ZodType): schema is ZodISODate;
/**
* Teste si le schéma est un schéma datetime.
* @param schema Le schéma.
*/
declare function isDateTimeSchema(schema: ZodType): schema is ZodISODateTime;
/**
* Teste si le schéma est un schéma int.
* @param schema Le schéma.
*/
declare function isIntSchema(schema: ZodType): schema is ZodInt32 | ZodInt;
/**
* Teste si le schéma est un schéma number.
* @param schema Le schéma.
*/
declare function isNumberSchema(schema: ZodType): schema is ZodNumber;
/**
* Teste si le schéma est un schéma string.
* @param schema Le schéma.
*/
declare function isStringSchema(schema: ZodType): schema is ZodString;
//#endregion
export { type Entity, type EntityToType, type FieldEntry, type ListEntry, type ObjectEntry, type RecursiveListEntry, type SingleZodType, type ZodTypeMultiple, type ZodTypeSingle, entries_d_exports as e, entity, isArraySchema, isBooleanSchema, isDateSchema, isDateTimeSchema, isIntSchema, isNumberSchema, isStringSchema, stringToSchemaOutput };
//# sourceMappingURL=focus4.entities.d.ts.map
+153
-156

@@ -0,191 +1,188 @@

import { t as __exportAll } from "./chunk-pbuEa-1d.js";
//#region src/builders/entity.ts
/**
* Crée une entité à partir d'une définition d'entrées.
*
* La seule valeur ajoutée de cette fonction (pour l'instant) est de renseigner automatiquement le nom des champs créés.
*/
* Crée une entité à partir d'une définition d'entrées.
*
* La seule valeur ajoutée de cette fonction (pour l'instant) est de renseigner automatiquement le nom des champs créés.
*/
function entity(entries) {
for (const key in entries) {
if (entries[key].type === "field" && !entries[key].name) {
entries[key].name = key;
}
}
return entries;
for (const key in entries) if (entries[key].type === "field" && !entries[key].name) entries[key].name = key;
return entries;
}
class EntryBuilder {
/** @internal */
entry;
constructor(type) {
this.entry = { type, label: "", isRequired: true };
}
/** Rend l'entrée d'entité non-obligatoire. */
optional() {
this.entry.isRequired = false;
return this;
}
/**
* Renseigne le libellé de l'entrée d'entité
* @param label Le libellé.
*/
label(label) {
this.entry.label = label;
return this;
}
/**
* Renseigne le commentaire de l'entrée d'entité
* @param comment Le commentaire.
*/
comment(comment) {
this.entry.comment = comment;
return this;
}
//#endregion
//#region src/builders/entry-builders.ts
var EntryBuilder = class {
/** @internal */
entry;
constructor(type) {
this.entry = {
type,
label: "",
isRequired: true
};
}
/** Rend l'entrée d'entité non-obligatoire. */
optional() {
this.entry.isRequired = false;
return this;
}
/**
* Renseigne le libellé de l'entrée d'entité
* @param label Le libellé.
*/
label(label) {
this.entry.label = label;
return this;
}
/**
* Renseigne le commentaire de l'entrée d'entité
* @param comment Le commentaire.
*/
comment(comment) {
this.entry.comment = comment;
return this;
}
};
var FieldEntryBuilder = class extends EntryBuilder {
constructor(domain) {
super("field");
this.entry.name = "";
this.entry.domain = domain;
}
/**
* Renseigne la valeur par défaut du champ.
* @param defaultValue La valeur par défaut.
*/
defaultValue(defaultValue) {
this.entry.defaultValue = defaultValue;
return this;
}
/**
* Renseigne le nom du champ. Si non renseigné, il sera renseigné par la fonction `entity` avec le nom de la propriété dans l'objet.
* @param name Le nom du champ.
*/
name(name) {
this.entry.name = name;
return this;
}
/** Précise le type du champ, au delà du type déduit de son schéma. Le nouveau type doit y être assignable à l'ancien. */
type() {
return this;
}
};
var ObjectEntryBuilder = class extends EntryBuilder {
constructor(e) {
super("object");
this.entry.entity = entity(e);
}
};
var ListEntryBuilder = class extends EntryBuilder {
constructor(e) {
super("list");
this.entry.entity = entity(e);
}
};
var RecursiveListEntryBuilder = class extends EntryBuilder {
constructor() {
super("recursive-list");
}
};
//#endregion
//#region src/builders/entries.ts
var entries_exports = /* @__PURE__ */ __exportAll({
field: () => field,
list: () => list,
object: () => object,
recursiveList: () => recursiveList
});
function field(domain, builder = (f) => f) {
return builder(new FieldEntryBuilder(domain)).entry;
}
class FieldEntryBuilder extends EntryBuilder {
constructor(domain) {
super("field");
this.entry.name = "";
this.entry.domain = domain;
}
/**
* Renseigne la valeur par défaut du champ.
* @param defaultValue La valeur par défaut.
*/
defaultValue(defaultValue) {
this.entry.defaultValue = defaultValue;
return this;
}
/**
* Renseigne le nom du champ. Si non renseigné, il sera renseigné par la fonction `entity` avec le nom de la propriété dans l'objet.
* @param name Le nom du champ.
*/
name(name) {
this.entry.name = name;
return this;
}
/** Précise le type du champ, au delà du type déduit de son schéma. Le nouveau type doit y être assignable à l'ancien. */
type() {
return this;
}
}
class ObjectEntryBuilder extends EntryBuilder {
constructor(e) {
super("object");
this.entry.entity = entity(e);
}
}
class ListEntryBuilder extends EntryBuilder {
constructor(e) {
super("list");
this.entry.entity = entity(e);
}
}
class RecursiveListEntryBuilder extends EntryBuilder {
constructor() {
super("recursive-list");
}
}
function field(domain, builder = f => f) {
return builder(new FieldEntryBuilder(domain)).entry;
}
/**
* Crée un composition simple pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
function object(entity, builder = f => f) {
return builder(new ObjectEntryBuilder(entity)).entry;
* Crée un composition simple pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
function object(entity, builder = (f) => f) {
return builder(new ObjectEntryBuilder(entity)).entry;
}
/**
* Crée un composition liste pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
function list(entity, builder = f => f) {
return builder(new ListEntryBuilder(entity)).entry;
* Crée un composition liste pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
function list(entity, builder = (f) => f) {
return builder(new ListEntryBuilder(entity)).entry;
}
/**
* Crée un composition de liste récursive (une liste de l'entité qui la contient).
* @param builder Le configurateur.
*/
function recursiveList(builder = f => f) {
return builder(new RecursiveListEntryBuilder()).entry;
* Crée un composition de liste récursive (une liste de l'entité qui la contient).
* @param builder Le configurateur.
*/
function recursiveList(builder = (f) => f) {
return builder(new RecursiveListEntryBuilder()).entry;
}
var entries = /*#__PURE__*/Object.freeze({
__proto__: null,
field: field,
list: list,
object: object,
recursiveList: recursiveList
});
//#endregion
//#region src/utils.ts
/**
* Convertit une valeur string dans le type du schéma demandé.
* @param value Valeur à convertir.
*/
* Convertit une valeur string dans le type du schéma demandé.
* @param value Valeur à convertir.
*/
function stringToSchemaOutput(value, schema) {
if (schema.type === "string" && value) {
return value;
}
if (schema.type === "number" && value) {
return Number.parseFloat(value);
}
if (schema.type === "boolean") {
return (value === "true" ? true : value === "false" ? false : undefined);
}
return undefined;
if (schema.type === "string" && value) return value;
if (schema.type === "number" && value) return Number.parseFloat(value);
if (schema.type === "boolean") return value === "true" ? true : value === "false" ? false : void 0;
}
/**
* Teste si le schéma est un schéma array.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma array.
* @param schema Le schéma.
*/
function isArraySchema(schema) {
return schema.type === "array";
return schema.type === "array";
}
/**
* Teste si le schéma est un schéma boolean.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma boolean.
* @param schema Le schéma.
*/
function isBooleanSchema(schema) {
return schema.type === "boolean";
return schema.type === "boolean";
}
/**
* Teste si le schéma est un schéma date.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma date.
* @param schema Le schéma.
*/
function isDateSchema(schema) {
return schema.format === "date";
return schema.format === "date";
}
/**
* Teste si le schéma est un schéma datetime.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma datetime.
* @param schema Le schéma.
*/
function isDateTimeSchema(schema) {
return schema.format === "datetime";
return schema.format === "datetime";
}
/**
* Teste si le schéma est un schéma int.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma int.
* @param schema Le schéma.
*/
function isIntSchema(schema) {
const { format } = schema;
return format === "int32" || format === "safeint";
const { format } = schema;
return format === "int32" || format === "safeint";
}
/**
* Teste si le schéma est un schéma number.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma number.
* @param schema Le schéma.
*/
function isNumberSchema(schema) {
return schema.type === "number";
return schema.type === "number";
}
/**
* Teste si le schéma est un schéma string.
* @param schema Le schéma.
*/
* Teste si le schéma est un schéma string.
* @param schema Le schéma.
*/
function isStringSchema(schema) {
return schema.type === "string";
return schema.type === "string";
}
//#endregion
export { entries_exports as e, entity, isArraySchema, isBooleanSchema, isDateSchema, isDateTimeSchema, isIntSchema, isNumberSchema, isStringSchema, stringToSchemaOutput };
export { entries as e, entity, isArraySchema, isBooleanSchema, isDateSchema, isDateTimeSchema, isIntSchema, isNumberSchema, isStringSchema, stringToSchemaOutput };
//# sourceMappingURL=focus4.entities.js.map
//# sourceMappingURL=focus4.entities.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"focus4.entities.js","sources":["../src/builders/entity.ts","../src/builders/entry-builders.ts","../src/builders/entries.ts","../src/utils.ts"],"sourcesContent":["import {Entity, FieldEntry} from \"../types\";\r\n\r\n/**\r\n * Crée une entité à partir d'une définition d'entrées.\r\n *\r\n * La seule valeur ajoutée de cette fonction (pour l'instant) est de renseigner automatiquement le nom des champs créés.\r\n */\r\nexport function entity<const E extends Entity>(entries: E): E {\r\n for (const key in entries) {\r\n if ((entries[key] as FieldEntry).type === \"field\" && !(entries[key] as FieldEntry).name) {\r\n (entries[key] as any).name = key;\r\n }\r\n }\r\n\r\n return entries;\r\n}\r\n","import {Entity, FieldEntry, ListEntry, ObjectEntry, RecursiveListEntry} from \"../types\";\r\n\r\nimport {entity} from \"./entity\";\r\n\r\ntype PartialNonReadonly<T> = {-readonly [P in keyof T]?: T[P]};\r\n\r\nclass EntryBuilder {\r\n /** @internal */\r\n entry: PartialNonReadonly<ObjectEntry | FieldEntry | ListEntry | RecursiveListEntry>;\r\n\r\n constructor(type: \"field\" | \"object\" | \"list\" | \"recursive-list\") {\r\n this.entry = {type, label: \"\", isRequired: true};\r\n }\r\n\r\n /** Rend l'entrée d'entité non-obligatoire. */\r\n optional() {\r\n this.entry.isRequired = false;\r\n return this;\r\n }\r\n\r\n /**\r\n * Renseigne le libellé de l'entrée d'entité\r\n * @param label Le libellé.\r\n */\r\n label(label: string) {\r\n this.entry.label = label;\r\n return this;\r\n }\r\n /**\r\n * Renseigne le commentaire de l'entrée d'entité\r\n * @param comment Le commentaire.\r\n */\r\n comment(comment: string) {\r\n this.entry.comment = comment;\r\n return this;\r\n }\r\n}\r\n\r\nexport class FieldEntryBuilder<T = any> extends EntryBuilder {\r\n /** @internal */\r\n declare entry: PartialNonReadonly<FieldEntry>;\r\n\r\n constructor(domain: Domain) {\r\n super(\"field\");\r\n this.entry.name = \"\";\r\n this.entry.domain = domain;\r\n }\r\n /**\r\n * Renseigne la valeur par défaut du champ.\r\n * @param defaultValue La valeur par défaut.\r\n */\r\n defaultValue(defaultValue: T) {\r\n this.entry.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n /**\r\n * Renseigne le nom du champ. Si non renseigné, il sera renseigné par la fonction `entity` avec le nom de la propriété dans l'objet.\r\n * @param name Le nom du champ.\r\n */\r\n name(name: string) {\r\n this.entry.name = name;\r\n return this;\r\n }\r\n\r\n /** Précise le type du champ, au delà du type déduit de son schéma. Le nouveau type doit y être assignable à l'ancien. */\r\n type<NT extends T>(): FieldEntryBuilder<NT> {\r\n return this;\r\n }\r\n}\r\n\r\nexport class ObjectEntryBuilder extends EntryBuilder {\r\n /** @internal */\r\n declare entry: PartialNonReadonly<ObjectEntry>;\r\n constructor(e: Entity) {\r\n super(\"object\");\r\n this.entry.entity = entity(e);\r\n }\r\n}\r\n\r\nexport class ListEntryBuilder extends EntryBuilder {\r\n /** @internal */\r\n declare entry: PartialNonReadonly<ListEntry>;\r\n constructor(e: Entity) {\r\n super(\"list\");\r\n this.entry.entity = entity(e);\r\n }\r\n}\r\n\r\nexport class RecursiveListEntryBuilder extends EntryBuilder {\r\n declare entry: RecursiveListEntry;\r\n constructor() {\r\n super(\"recursive-list\");\r\n }\r\n}\r\n","import {output} from \"zod\";\r\n\r\nimport {Entity, FieldEntry, ListEntry, ObjectEntry} from \"../types\";\r\n\r\nimport {FieldEntryBuilder, ListEntryBuilder, ObjectEntryBuilder, RecursiveListEntryBuilder} from \"./entry-builders\";\r\n\r\n/**\r\n * Crée un champ pour une entité.\r\n *\r\n * (Le champ sera obligatoire par défaut)\r\n * @param domain Le domaine du champ.\r\n */\r\nexport function field<D extends Domain>(domain: D): FieldEntry<D>;\r\n/**\r\n * Crée un champ pour une entité.\r\n *\r\n * (Le champ sera obligatoire par défaut)\r\n * @param domain Le domaine du champ.\r\n * @param builder Le configurateur du champ.\r\n */\r\nexport function field<D extends Domain, T extends output<D[\"schema\"]> = output<D[\"schema\"]>>(\r\n domain: D,\r\n builder: (f: FieldEntryBuilder<output<D[\"schema\"]>>) => FieldEntryBuilder<T>\r\n): FieldEntry<D, T>;\r\nexport function field(domain: Domain, builder: (f: FieldEntryBuilder) => FieldEntryBuilder = f => f) {\r\n return builder(new FieldEntryBuilder(domain)).entry;\r\n}\r\n/**\r\n * Crée un composition simple pour une entité.\r\n * @param entity L'entité pour la composition.\r\n * @param builder Le configurateur.\r\n */\r\nexport function object<const E extends Entity>(\r\n entity: E,\r\n builder: (f: ObjectEntryBuilder) => ObjectEntryBuilder = f => f\r\n) {\r\n return builder(new ObjectEntryBuilder(entity)).entry as ObjectEntry<E>;\r\n}\r\n\r\n/**\r\n * Crée un composition liste pour une entité.\r\n * @param entity L'entité pour la composition.\r\n * @param builder Le configurateur.\r\n */\r\nexport function list<const E extends Entity>(entity: E, builder: (f: ListEntryBuilder) => ListEntryBuilder = f => f) {\r\n return builder(new ListEntryBuilder(entity)).entry as ListEntry<E>;\r\n}\r\n\r\n/**\r\n * Crée un composition de liste récursive (une liste de l'entité qui la contient).\r\n * @param builder Le configurateur.\r\n */\r\nexport function recursiveList(builder: (f: RecursiveListEntryBuilder) => RecursiveListEntryBuilder = f => f) {\r\n return builder(new RecursiveListEntryBuilder()).entry;\r\n}\r\n","import {\r\n output,\r\n ZodArray,\r\n ZodBoolean,\r\n ZodInt,\r\n ZodInt32,\r\n ZodISODate,\r\n ZodISODateTime,\r\n ZodNumber,\r\n ZodString,\r\n ZodType\r\n} from \"zod\";\r\n\r\n/**\r\n * Convertit une valeur string dans le type du schéma demandé.\r\n * @param value Valeur à convertir.\r\n */\r\nexport function stringToSchemaOutput<S extends ZodType>(value: string | undefined, schema: S) {\r\n if (schema.type === \"string\" && value) {\r\n return value as output<S>;\r\n }\r\n\r\n if (schema.type === \"number\" && value) {\r\n return Number.parseFloat(value) as output<S>;\r\n }\r\n\r\n if (schema.type === \"boolean\") {\r\n return (value === \"true\" ? true : value === \"false\" ? false : undefined) as output<S>;\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma array.\r\n * @param schema Le schéma.\r\n */\r\nexport function isArraySchema(schema: ZodType): schema is ZodArray<ZodType> {\r\n return schema.type === \"array\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma boolean.\r\n * @param schema Le schéma.\r\n */\r\nexport function isBooleanSchema(schema: ZodType): schema is ZodBoolean {\r\n return schema.type === \"boolean\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma date.\r\n * @param schema Le schéma.\r\n */\r\nexport function isDateSchema(schema: ZodType): schema is ZodISODate {\r\n return (schema as ZodString).format === \"date\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma datetime.\r\n * @param schema Le schéma.\r\n */\r\nexport function isDateTimeSchema(schema: ZodType): schema is ZodISODateTime {\r\n return (schema as ZodString).format === \"datetime\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma int.\r\n * @param schema Le schéma.\r\n */\r\nexport function isIntSchema(schema: ZodType): schema is ZodInt32 | ZodInt {\r\n const {format} = schema as ZodNumber;\r\n return format === \"int32\" || format === \"safeint\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma number.\r\n * @param schema Le schéma.\r\n */\r\nexport function isNumberSchema(schema: ZodType): schema is ZodNumber {\r\n return schema.type === \"number\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma string.\r\n * @param schema Le schéma.\r\n */\r\nexport function isStringSchema(schema: ZodType): schema is ZodString {\r\n return schema.type === \"string\";\r\n}\r\n"],"names":[],"mappings":"AAEA;;;;AAIG;AACG,SAAU,MAAM,CAAyB,OAAU,EAAA;AACrD,IAAA,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;AACvB,QAAA,IAAK,OAAO,CAAC,GAAG,CAAgB,CAAC,IAAI,KAAK,OAAO,IAAI,CAAE,OAAO,CAAC,GAAG,CAAgB,CAAC,IAAI,EAAE;AACpF,YAAA,OAAO,CAAC,GAAG,CAAS,CAAC,IAAI,GAAG,GAAG;QACpC;IACJ;AAEA,IAAA,OAAO,OAAO;AAClB;;ACTA,MAAM,YAAY,CAAA;;AAEd,IAAA,KAAK;AAEL,IAAA,WAAA,CAAY,IAAoD,EAAA;AAC5D,QAAA,IAAI,CAAC,KAAK,GAAG,EAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAC;IACpD;;IAGA,QAAQ,GAAA;AACJ,QAAA,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK;AAC7B,QAAA,OAAO,IAAI;IACf;AAEA;;;AAGG;AACH,IAAA,KAAK,CAAC,KAAa,EAAA;AACf,QAAA,IAAI,CAAC,KAAK,CA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A,OAAO,MAAM,CAAC,IAAI,KAAK,SAAS;AACpC;AAEA;;;AAGG;AACG,SAAU,YAAY,CAAC,MAAe,EAAA;AACxC,IAAA,OAAQ,MAAoB,CAAC,MAAM,KAAK,MAAM;AAClD;AAEA;;;AAGG;AACG,SAAU,gBAAgB,CAAC,MAAe,EAAA;AAC5C,IAAA,OAAQ,MAAoB,CAAC,MAAM,KAAK,UAAU;AACtD;AAEA;;;AAGG;AACG,SAAU,WAAW,CAAC,MAAe,EAAA;AACvC,IAAA,MAAM,EAAC,MAAM,EAAC,GAAG,MAAmB;AACpC,IAAA,OAAO,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,SAAS;AACrD;AAEA;;;AAGG;AACG,SAAU,cAAc,CAAC,MAAe,EAAA;AAC1C,IAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;AACnC;AAEA;;;AAGG;AACG,SAAU,cAAc,CAAC,MAAe,EAAA;AAC1C,IAAA,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;AACnC;;;;"}
{"version":3,"file":"focus4.entities.js","names":[],"sources":["../src/builders/entity.ts","../src/builders/entry-builders.ts","../src/builders/entries.ts","../src/utils.ts"],"sourcesContent":["import {Entity, FieldEntry} from \"../types\";\r\n\r\n/**\r\n * Crée une entité à partir d'une définition d'entrées.\r\n *\r\n * La seule valeur ajoutée de cette fonction (pour l'instant) est de renseigner automatiquement le nom des champs créés.\r\n */\r\nexport function entity<const E extends Entity>(entries: E): E {\r\n for (const key in entries) {\r\n if ((entries[key] as FieldEntry).type === \"field\" && !(entries[key] as FieldEntry).name) {\r\n (entries[key] as any).name = key;\r\n }\r\n }\r\n\r\n return entries;\r\n}\r\n","import {Entity, FieldEntry, ListEntry, ObjectEntry, RecursiveListEntry} from \"../types\";\r\n\r\nimport {entity} from \"./entity\";\r\n\r\ntype PartialNonReadonly<T> = {-readonly [P in keyof T]?: T[P]};\r\n\r\nclass EntryBuilder {\r\n /** @internal */\r\n entry: PartialNonReadonly<ObjectEntry | FieldEntry | ListEntry | RecursiveListEntry>;\r\n\r\n constructor(type: \"field\" | \"object\" | \"list\" | \"recursive-list\") {\r\n this.entry = {type, label: \"\", isRequired: true};\r\n }\r\n\r\n /** Rend l'entrée d'entité non-obligatoire. */\r\n optional() {\r\n this.entry.isRequired = false;\r\n return this;\r\n }\r\n\r\n /**\r\n * Renseigne le libellé de l'entrée d'entité\r\n * @param label Le libellé.\r\n */\r\n label(label: string) {\r\n this.entry.label = label;\r\n return this;\r\n }\r\n /**\r\n * Renseigne le commentaire de l'entrée d'entité\r\n * @param comment Le commentaire.\r\n */\r\n comment(comment: string) {\r\n this.entry.comment = comment;\r\n return this;\r\n }\r\n}\r\n\r\nexport class FieldEntryBuilder<T = any> extends EntryBuilder {\r\n /** @internal */\r\n declare entry: PartialNonReadonly<FieldEntry>;\r\n\r\n constructor(domain: Domain) {\r\n super(\"field\");\r\n this.entry.name = \"\";\r\n this.entry.domain = domain;\r\n }\r\n /**\r\n * Renseigne la valeur par défaut du champ.\r\n * @param defaultValue La valeur par défaut.\r\n */\r\n defaultValue(defaultValue: T) {\r\n this.entry.defaultValue = defaultValue;\r\n return this;\r\n }\r\n\r\n /**\r\n * Renseigne le nom du champ. Si non renseigné, il sera renseigné par la fonction `entity` avec le nom de la propriété dans l'objet.\r\n * @param name Le nom du champ.\r\n */\r\n name(name: string) {\r\n this.entry.name = name;\r\n return this;\r\n }\r\n\r\n /** Précise le type du champ, au delà du type déduit de son schéma. Le nouveau type doit y être assignable à l'ancien. */\r\n type<NT extends T>(): FieldEntryBuilder<NT> {\r\n return this;\r\n }\r\n}\r\n\r\nexport class ObjectEntryBuilder extends EntryBuilder {\r\n /** @internal */\r\n declare entry: PartialNonReadonly<ObjectEntry>;\r\n constructor(e: Entity) {\r\n super(\"object\");\r\n this.entry.entity = entity(e);\r\n }\r\n}\r\n\r\nexport class ListEntryBuilder extends EntryBuilder {\r\n /** @internal */\r\n declare entry: PartialNonReadonly<ListEntry>;\r\n constructor(e: Entity) {\r\n super(\"list\");\r\n this.entry.entity = entity(e);\r\n }\r\n}\r\n\r\nexport class RecursiveListEntryBuilder extends EntryBuilder {\r\n declare entry: RecursiveListEntry;\r\n constructor() {\r\n super(\"recursive-list\");\r\n }\r\n}\r\n","import {output} from \"zod\";\r\n\r\nimport {Entity, FieldEntry, ListEntry, ObjectEntry} from \"../types\";\r\n\r\nimport {FieldEntryBuilder, ListEntryBuilder, ObjectEntryBuilder, RecursiveListEntryBuilder} from \"./entry-builders\";\r\n\r\n/**\r\n * Crée un champ pour une entité.\r\n *\r\n * (Le champ sera obligatoire par défaut)\r\n * @param domain Le domaine du champ.\r\n */\r\nexport function field<D extends Domain>(domain: D): FieldEntry<D>;\r\n/**\r\n * Crée un champ pour une entité.\r\n *\r\n * (Le champ sera obligatoire par défaut)\r\n * @param domain Le domaine du champ.\r\n * @param builder Le configurateur du champ.\r\n */\r\nexport function field<D extends Domain, T extends output<D[\"schema\"]> = output<D[\"schema\"]>>(\r\n domain: D,\r\n builder: (f: FieldEntryBuilder<output<D[\"schema\"]>>) => FieldEntryBuilder<T>\r\n): FieldEntry<D, T>;\r\nexport function field(domain: Domain, builder: (f: FieldEntryBuilder) => FieldEntryBuilder = f => f) {\r\n return builder(new FieldEntryBuilder(domain)).entry;\r\n}\r\n/**\r\n * Crée un composition simple pour une entité.\r\n * @param entity L'entité pour la composition.\r\n * @param builder Le configurateur.\r\n */\r\nexport function object<const E extends Entity>(\r\n entity: E,\r\n builder: (f: ObjectEntryBuilder) => ObjectEntryBuilder = f => f\r\n) {\r\n return builder(new ObjectEntryBuilder(entity)).entry as ObjectEntry<E>;\r\n}\r\n\r\n/**\r\n * Crée un composition liste pour une entité.\r\n * @param entity L'entité pour la composition.\r\n * @param builder Le configurateur.\r\n */\r\nexport function list<const E extends Entity>(entity: E, builder: (f: ListEntryBuilder) => ListEntryBuilder = f => f) {\r\n return builder(new ListEntryBuilder(entity)).entry as ListEntry<E>;\r\n}\r\n\r\n/**\r\n * Crée un composition de liste récursive (une liste de l'entité qui la contient).\r\n * @param builder Le configurateur.\r\n */\r\nexport function recursiveList(builder: (f: RecursiveListEntryBuilder) => RecursiveListEntryBuilder = f => f) {\r\n return builder(new RecursiveListEntryBuilder()).entry;\r\n}\r\n","import {\r\n output,\r\n ZodArray,\r\n ZodBoolean,\r\n ZodInt,\r\n ZodInt32,\r\n ZodISODate,\r\n ZodISODateTime,\r\n ZodNumber,\r\n ZodString,\r\n ZodType\r\n} from \"zod\";\r\n\r\n/**\r\n * Convertit une valeur string dans le type du schéma demandé.\r\n * @param value Valeur à convertir.\r\n */\r\nexport function stringToSchemaOutput<S extends ZodType>(value: string | undefined, schema: S) {\r\n if (schema.type === \"string\" && value) {\r\n return value as output<S>;\r\n }\r\n\r\n if (schema.type === \"number\" && value) {\r\n return Number.parseFloat(value) as output<S>;\r\n }\r\n\r\n if (schema.type === \"boolean\") {\r\n return (value === \"true\" ? true : value === \"false\" ? false : undefined) as output<S>;\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma array.\r\n * @param schema Le schéma.\r\n */\r\nexport function isArraySchema(schema: ZodType): schema is ZodArray<ZodType> {\r\n return schema.type === \"array\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma boolean.\r\n * @param schema Le schéma.\r\n */\r\nexport function isBooleanSchema(schema: ZodType): schema is ZodBoolean {\r\n return schema.type === \"boolean\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma date.\r\n * @param schema Le schéma.\r\n */\r\nexport function isDateSchema(schema: ZodType): schema is ZodISODate {\r\n return (schema as ZodString).format === \"date\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma datetime.\r\n * @param schema Le schéma.\r\n */\r\nexport function isDateTimeSchema(schema: ZodType): schema is ZodISODateTime {\r\n return (schema as ZodString).format === \"datetime\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma int.\r\n * @param schema Le schéma.\r\n */\r\nexport function isIntSchema(schema: ZodType): schema is ZodInt32 | ZodInt {\r\n const {format} = schema as ZodNumber;\r\n return format === \"int32\" || format === \"safeint\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma number.\r\n * @param schema Le schéma.\r\n */\r\nexport function isNumberSchema(schema: ZodType): schema is ZodNumber {\r\n return schema.type === \"number\";\r\n}\r\n\r\n/**\r\n * Teste si le schéma est un schéma string.\r\n * @param schema Le schéma.\r\n */\r\nexport function isStringSchema(schema: ZodType): schema is ZodString {\r\n return schema.type === \"string\";\r\n}\r\n"],"mappings":";;;;;;;AAOA,SAAgB,OAA+B,SAAe;AAC1D,MAAK,MAAM,OAAO,QACd,KAAK,QAAQ,KAAoB,SAAS,WAAW,CAAE,QAAQ,KAAoB,KAC9E,SAAQ,KAAa,OAAO;AAIrC,QAAO;;;;ACRX,IAAM,eAAN,MAAmB;;CAEf;CAEA,YAAY,MAAsD;AAC9D,OAAK,QAAQ;GAAC;GAAM,OAAO;GAAI,YAAY;GAAK;;;CAIpD,WAAW;AACP,OAAK,MAAM,aAAa;AACxB,SAAO;;;;;;CAOX,MAAM,OAAe;AACjB,OAAK,MAAM,QAAQ;AACnB,SAAO;;;;;;CAMX,QAAQ,SAAiB;AACrB,OAAK,MAAM,UAAU;AACrB,SAAO;;;AAIf,IAAa,oBAAb,cAAgD,aAAa;CAIzD,YAAY,QAAgB;AACxB,QAAM,QAAQ;AACd,OAAK,MAAM,OAAO;AAClB,OAAK,MAAM,SAAS;;;;;;CAMxB,aAAa,cAAiB;AAC1B,OAAK,MAAM,eAAe;AAC1B,SAAO;;;;;;CAOX,KAAK,MAAc;AACf,OAAK,MAAM,OAAO;AAClB,SAAO;;;CAIX,OAA4C;AACxC,SAAO;;;AAIf,IAAa,qBAAb,cAAwC,aAAa;CAGjD,YAAY,GAAW;AACnB,QAAM,SAAS;AACf,OAAK,MAAM,SAAS,OAAO,EAAE;;;AAIrC,IAAa,mBAAb,cAAsC,aAAa;CAG/C,YAAY,GAAW;AAC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12.9.0",
"version": "12.10.0",
"description": "Focus v4, entities module",

@@ -15,8 +15,7 @@ "main": "lib/focus4.entities.js",

"scripts": {
"build": "rollup -cm --bundleConfigAsCjs"
"build": "tsdown"
},
"peerDependencies": {
"zod": ">= 4 < 5"
},
"gitHead": "fa2a850433c95d8f541379723dbaf54284e5eed7"
}
}
import { Entity } from "../types";
/**
* Crée une entité à partir d'une définition d'entrées.
*
* La seule valeur ajoutée de cette fonction (pour l'instant) est de renseigner automatiquement le nom des champs créés.
*/
export declare function entity<const E extends Entity>(entries: E): E;
import { output } from "zod";
import { Entity, FieldEntry, ListEntry, ObjectEntry } from "../types";
import { FieldEntryBuilder, ListEntryBuilder, ObjectEntryBuilder, RecursiveListEntryBuilder } from "./entry-builders";
/**
* Crée un champ pour une entité.
*
* (Le champ sera obligatoire par défaut)
* @param domain Le domaine du champ.
*/
export declare function field<D extends Domain>(domain: D): FieldEntry<D>;
/**
* Crée un champ pour une entité.
*
* (Le champ sera obligatoire par défaut)
* @param domain Le domaine du champ.
* @param builder Le configurateur du champ.
*/
export declare function field<D extends Domain, T extends output<D["schema"]> = output<D["schema"]>>(domain: D, builder: (f: FieldEntryBuilder<output<D["schema"]>>) => FieldEntryBuilder<T>): FieldEntry<D, T>;
/**
* Crée un composition simple pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
export declare function object<const E extends Entity>(entity: E, builder?: (f: ObjectEntryBuilder) => ObjectEntryBuilder): ObjectEntry<E>;
/**
* Crée un composition liste pour une entité.
* @param entity L'entité pour la composition.
* @param builder Le configurateur.
*/
export declare function list<const E extends Entity>(entity: E, builder?: (f: ListEntryBuilder) => ListEntryBuilder): ListEntry<E>;
/**
* Crée un composition de liste récursive (une liste de l'entité qui la contient).
* @param builder Le configurateur.
*/
export declare function recursiveList(builder?: (f: RecursiveListEntryBuilder) => RecursiveListEntryBuilder): import("../types").RecursiveListEntry;
import { Entity, RecursiveListEntry } from "../types";
declare class EntryBuilder {
constructor(type: "field" | "object" | "list" | "recursive-list");
/** Rend l'entrée d'entité non-obligatoire. */
optional(): this;
/**
* Renseigne le libellé de l'entrée d'entité
* @param label Le libellé.
*/
label(label: string): this;
/**
* Renseigne le commentaire de l'entrée d'entité
* @param comment Le commentaire.
*/
comment(comment: string): this;
}
export declare class FieldEntryBuilder<T = any> extends EntryBuilder {
constructor(domain: Domain);
/**
* Renseigne la valeur par défaut du champ.
* @param defaultValue La valeur par défaut.
*/
defaultValue(defaultValue: T): this;
/**
* Renseigne le nom du champ. Si non renseigné, il sera renseigné par la fonction `entity` avec le nom de la propriété dans l'objet.
* @param name Le nom du champ.
*/
name(name: string): this;
/** Précise le type du champ, au delà du type déduit de son schéma. Le nouveau type doit y être assignable à l'ancien. */
type<NT extends T>(): FieldEntryBuilder<NT>;
}
export declare class ObjectEntryBuilder extends EntryBuilder {
constructor(e: Entity);
}
export declare class ListEntryBuilder extends EntryBuilder {
constructor(e: Entity);
}
export declare class RecursiveListEntryBuilder extends EntryBuilder {
entry: RecursiveListEntry;
constructor();
}
export {};
export { entity } from "./entity";
export * as e from "./entries";
import { output, ZodArray, ZodType } from "zod";
/** Correspond à un type de schéma pour un type primitif. */
export type ZodTypeSingle = ZodType<boolean> | ZodType<number> | ZodType<string>;
/** Correspond à un type de schéma pour un type d'array de primitives. */
export type ZodTypeMultiple = ZodArray<ZodType<boolean>> | ZodArray<ZodType<number>> | ZodArray<ZodType<string>>;
/** Récupère le type de domaine simple d'un type de domaine multiple. */
export type SingleZodType<S> = S extends ZodArray<infer ES> ? ES : S;
/** Définition d'un domaine. */
declare global {
interface Domain<S extends ZodType = any> {
/** Schéma Zod d'un champ du domaine. */
schema: S;
}
}
/** Métadonnées d'une entrée de type "field" pour une entité. */
export interface FieldEntry<D extends Domain = any, T extends output<D["schema"]> = output<D["schema"]>> {
readonly type: "field";
/** Type du champ, s'il est plus précis que celui du domaine. */
readonly fieldType?: T;
/** Domaine du champ. */
readonly domain: D;
/** Champ obligatoire. */
readonly isRequired: boolean;
/** Nom de l'entrée. */
readonly name: string;
/** Libellé de l'entrée. */
readonly label: string;
/** Commentaire de l'entrée */
readonly comment?: string;
/** Valeur par défaut du champ dans un formulaire. */
readonly defaultValue?: T;
}
/** Métadonnées d'une entrée de type "object" pour une entité. */
export interface ObjectEntry<E extends Entity = any> {
readonly type: "object";
/** Entité de l'entrée */
readonly entity: E;
/** Objet obligatoire. Sera `true` si non renseigné. */
readonly isRequired?: boolean;
/** Libellé de l'entrée (non utilisé). */
readonly label?: string;
/** Commentaire de l'entrée (non utilisé). */
readonly comment?: string;
}
/** Métadonnées d'une entrée de type "list" pour une entité. */
export interface ListEntry<E extends Entity = any> {
readonly type: "list";
/** Entité de l'entrée */
readonly entity: E;
/** Liste obligatoire. Sera `true` si non renseigné. */
readonly isRequired?: boolean;
/** Libellé de l'entrée (non utilisé). */
readonly label?: string;
/** Commentaire de l'entrée (non utilisé). */
readonly comment?: string;
}
/** Métadonnées d'une entrée de type "recursive-list" pour une entité. */
export interface RecursiveListEntry {
readonly type: "recursive-list";
/** Liste obligatoire. Sera `true` si non renseigné. */
readonly isRequired?: boolean;
/** Libellé de l'entrée (non utilisé). */
readonly label?: string;
/** Commentaire de l'entrée (non utilisé). */
readonly comment?: string;
}
/** Génère le type associé à une entité, avec toutes ses propriétés en optionnel. */
export type EntityToType<E extends Entity> = {
-readonly [P in keyof E]?: E[P] extends FieldEntry ? E[P]["fieldType"] : E[P] extends ObjectEntry<infer OE> ? EntityToType<OE> : E[P] extends ListEntry<infer LE> ? EntityToType<LE>[] : E[P] extends RecursiveListEntry ? EntityToType<E>[] : E[P] extends [Entity] ? EntityToType<E[P][0]>[] : E[P] extends Entity ? EntityToType<E[P]> : never;
};
/** Définition d'une entité. */
export interface Entity extends Record<string, FieldEntry | ObjectEntry | ListEntry | RecursiveListEntry | Entity | [Entity]> {
}
import { output, ZodArray, ZodBoolean, ZodInt, ZodInt32, ZodISODate, ZodISODateTime, ZodNumber, ZodString, ZodType } from "zod";
/**
* Convertit une valeur string dans le type du schéma demandé.
* @param value Valeur à convertir.
*/
export declare function stringToSchemaOutput<S extends ZodType>(value: string | undefined, schema: S): output<S> | undefined;
/**
* Teste si le schéma est un schéma array.
* @param schema Le schéma.
*/
export declare function isArraySchema(schema: ZodType): schema is ZodArray<ZodType>;
/**
* Teste si le schéma est un schéma boolean.
* @param schema Le schéma.
*/
export declare function isBooleanSchema(schema: ZodType): schema is ZodBoolean;
/**
* Teste si le schéma est un schéma date.
* @param schema Le schéma.
*/
export declare function isDateSchema(schema: ZodType): schema is ZodISODate;
/**
* Teste si le schéma est un schéma datetime.
* @param schema Le schéma.
*/
export declare function isDateTimeSchema(schema: ZodType): schema is ZodISODateTime;
/**
* Teste si le schéma est un schéma int.
* @param schema Le schéma.
*/
export declare function isIntSchema(schema: ZodType): schema is ZodInt32 | ZodInt;
/**
* Teste si le schéma est un schéma number.
* @param schema Le schéma.
*/
export declare function isNumberSchema(schema: ZodType): schema is ZodNumber;
/**
* Teste si le schéma est un schéma string.
* @param schema Le schéma.
*/
export declare function isStringSchema(schema: ZodType): schema is ZodString;
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS