@focus4/entities
Advanced tools
+1
-1
| { | ||
| "name": "@focus4/entities", | ||
| "version": "12.10.0", | ||
| "version": "12.10.1", | ||
| "description": "Focus v4, entities module", | ||
@@ -5,0 +5,0 @@ "main": "lib/focus4.entities.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 }; |
| 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 |
| {"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,CA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,KAAqB,gBAAA,GAChC,SAAA,CAAU,CAAA;;;;;iBAOpD,aAAA,CAAc,OAAA,IAAU,CAAA,EAAG,yBAAA,KAA8B,yBAAA,GAAkC,kBAAA;;;;;;AHjD3G;iBIcgB,oBAAA,WAA+B,OAAA,CAAA,CAAS,KAAA,sBAA2B,MAAA,EAAQ,CAAA,GAAC,MAAA,CAAA,CAAA;;;;;iBAoB5E,aAAA,CAAc,MAAA,EAAQ,OAAA,GAAU,MAAA,IAAU,QAAA,CAAS,OAAA;;;;;iBAQnD,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"} |
| 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. | ||
| */ | ||
| function entity(entries) { | ||
| for (const key in entries) if (entries[key].type === "field" && !entries[key].name) entries[key].name = key; | ||
| return entries; | ||
| } | ||
| //#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; | ||
| } | ||
| /** | ||
| * 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 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; | ||
| } | ||
| //#endregion | ||
| //#region src/utils.ts | ||
| /** | ||
| * 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 : void 0; | ||
| } | ||
| /** | ||
| * Teste si le schéma est un schéma array. | ||
| * @param schema Le schéma. | ||
| */ | ||
| function isArraySchema(schema) { | ||
| return schema.type === "array"; | ||
| } | ||
| /** | ||
| * Teste si le schéma est un schéma boolean. | ||
| * @param schema Le schéma. | ||
| */ | ||
| function isBooleanSchema(schema) { | ||
| return schema.type === "boolean"; | ||
| } | ||
| /** | ||
| * Teste si le schéma est un schéma date. | ||
| * @param schema Le schéma. | ||
| */ | ||
| function isDateSchema(schema) { | ||
| return schema.format === "date"; | ||
| } | ||
| /** | ||
| * Teste si le schéma est un schéma datetime. | ||
| * @param schema Le schéma. | ||
| */ | ||
| function isDateTimeSchema(schema) { | ||
| return schema.format === "datetime"; | ||
| } | ||
| /** | ||
| * 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"; | ||
| } | ||
| /** | ||
| * Teste si le schéma est un schéma number. | ||
| * @param schema Le schéma. | ||
| */ | ||
| function isNumberSchema(schema) { | ||
| return schema.type === "number"; | ||
| } | ||
| /** | ||
| * Teste si le schéma est un schéma string. | ||
| * @param schema Le schéma. | ||
| */ | ||
| function isStringSchema(schema) { | ||
| return schema.type === "string"; | ||
| } | ||
| //#endregion | ||
| export { entries_exports as e, entity, isArraySchema, isBooleanSchema, isDateSchema, isDateTimeSchema, isIntSchema, isNumberSchema, isStringSchema, stringToSchemaOutput }; | ||
| //# sourceMappingURL=focus4.entities.js.map |
| {"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;AACnB,QAAM,OAAO;AACb,OAAK,MAAM,SAAS,OAAO,EAAE;;;AAIrC,IAAa,4BAAb,cAA+C,aAAa;CAExD,cAAc;AACV,QAAM,iBAAiB;;;;;;;;;;;ACpE/B,SAAgB,MAAM,QAAgB,WAAuD,MAAK,GAAG;AACjG,QAAO,QAAQ,IAAI,kBAAkB,OAAO,CAAC,CAAC;;;;;;;AAOlD,SAAgB,OACZ,QACA,WAAyD,MAAK,GAChE;AACE,QAAO,QAAQ,IAAI,mBAAmB,OAAO,CAAC,CAAC;;;;;;;AAQnD,SAAgB,KAA6B,QAAW,WAAqD,MAAK,GAAG;AACjH,QAAO,QAAQ,IAAI,iBAAiB,OAAO,CAAC,CAAC;;;;;;AAOjD,SAAgB,cAAc,WAAuE,MAAK,GAAG;AACzG,QAAO,QAAQ,IAAI,2BAA2B,CAAC,CAAC;;;;;;;;ACpCpD,SAAgB,qBAAwC,OAA2B,QAAW;AAC1F,KAAI,OAAO,SAAS,YAAY,MAC5B,QAAO;AAGX,KAAI,OAAO,SAAS,YAAY,MAC5B,QAAO,OAAO,WAAW,MAAM;AAGnC,KAAI,OAAO,SAAS,UAChB,QAAQ,UAAU,SAAS,OAAO,UAAU,UAAU,QAAQ,KAAA;;;;;;AAUtE,SAAgB,cAAc,QAA8C;AACxE,QAAO,OAAO,SAAS;;;;;;AAO3B,SAAgB,gBAAgB,QAAuC;AACnE,QAAO,OAAO,SAAS;;;;;;AAO3B,SAAgB,aAAa,QAAuC;AAChE,QAAQ,OAAqB,WAAW;;;;;;AAO5C,SAAgB,iBAAiB,QAA2C;AACxE,QAAQ,OAAqB,WAAW;;;;;;AAO5C,SAAgB,YAAY,QAA8C;CACtE,MAAM,EAAC,WAAU;AACjB,QAAO,WAAW,WAAW,WAAW;;;;;;AAO5C,SAAgB,eAAe,QAAsC;AACjE,QAAO,OAAO,SAAS;;;;;;AAO3B,SAAgB,eAAe,QAAsC;AACjE,QAAO,OAAO,SAAS"} |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
801
-97.1%2
-71.43%0
-100%2
100%