[fabric-core] Improve some JSDocs, improve some names, and re-organice some files
This commit is contained in:
parent
b164c7d97f
commit
0ffe2838c1
@ -1,5 +1,5 @@
|
|||||||
|
import { BaseFile } from "../../../files/base-file.js";
|
||||||
import { Entity } from "../entity.js";
|
import { Entity } from "../entity.js";
|
||||||
import { BaseFile } from "./base-file.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file as managed by the domain.
|
* Represents a file as managed by the domain.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
import { ImageMimeType } from "../../../files/mime-type.js";
|
||||||
import { DomainFile } from "./domain-file.js";
|
import { DomainFile } from "./domain-file.js";
|
||||||
import { ImageMimeType } from "./mime-type.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an image file.
|
* Represents an image file.
|
||||||
|
|||||||
@ -1,10 +1,2 @@
|
|||||||
export * from "./base-file.js";
|
|
||||||
export * from "./bytes.js";
|
|
||||||
export * from "./domain-file.js";
|
export * from "./domain-file.js";
|
||||||
export * from "./image-file.js";
|
export * from "./image-file.js";
|
||||||
export * from "./invalid-file-type-error.js";
|
|
||||||
export * from "./is-mime-type.js";
|
|
||||||
export * from "./is-uploaded-file.js";
|
|
||||||
export * from "./media-file.js";
|
|
||||||
export * from "./mime-type.js";
|
|
||||||
export * from "./uploaded-file.js";
|
|
||||||
|
|||||||
@ -1,2 +1 @@
|
|||||||
export * from "./entity.js";
|
export * from "./entity.js";
|
||||||
export * from "./files/index.js";
|
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import { TaggedVariant } from "../../variant/variant.js";
|
import { TaggedVariant } from "../../variant/variant.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event is a tagged variant with a payload and a timestamp.
|
||||||
|
*/
|
||||||
export interface Event<TTag extends string, TPayload>
|
export interface Event<TTag extends string, TPayload>
|
||||||
extends TaggedVariant<TTag> {
|
extends TaggedVariant<TTag> {
|
||||||
payload: TPayload;
|
payload: TPayload;
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* A PolicyMap maps user types to their security policies.
|
||||||
|
*/
|
||||||
export type PolicyMap<
|
export type PolicyMap<
|
||||||
UserType extends string,
|
UserType extends string,
|
||||||
PolicyType extends string,
|
PolicyType extends string,
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export * from "./email.js";
|
export * from "./email.js";
|
||||||
export * from "./sem-ver.js";
|
export * from "./semver.js";
|
||||||
export * from "./uuid.js";
|
export * from "./uuid.js";
|
||||||
|
|||||||
@ -3,11 +3,6 @@ import { AsyncResult } from "../../result/async-result.js";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A use case is a piece of domain logic that can be executed.
|
* A use case is a piece of domain logic that can be executed.
|
||||||
*
|
|
||||||
* It can be one of two types:
|
|
||||||
*
|
|
||||||
* - `Query`: A use case that only reads data.
|
|
||||||
* - `Command`: A use case that modifies data.
|
|
||||||
*/
|
*/
|
||||||
export type UseCase<
|
export type UseCase<
|
||||||
TDependencies,
|
TDependencies,
|
||||||
|
|||||||
@ -1,15 +1,8 @@
|
|||||||
import { VariantTag } from "../variant/variant.js";
|
|
||||||
import { TaggedError } from "./tagged-error.js";
|
import { TaggedError } from "./tagged-error.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if a value is an error.
|
* Indicates if a value is an error.
|
||||||
*
|
|
||||||
* In case it is an error, the type of the error is able to be inferred.
|
|
||||||
*/
|
*/
|
||||||
export function isError(err: unknown): err is TaggedError<string> {
|
export function isError(err: unknown): err is TaggedError<string> {
|
||||||
return (
|
return err instanceof TaggedError;
|
||||||
err instanceof Error &&
|
|
||||||
VariantTag in err &&
|
|
||||||
typeof err[VariantTag] === "string"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { TaggedVariant, VariantTag } from "../variant/index.js";
|
import { TaggedVariant, VariantTag } from "../variant/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Un TaggedError es un error que tiene un tag que lo identifica, lo cual
|
* A TaggedError is a tagged variant with an error message.
|
||||||
* permite a los consumidores de la instancia de error identificar el tipo de
|
|
||||||
* error que ocurrió.
|
|
||||||
*/
|
*/
|
||||||
export class TaggedError<Tag extends string>
|
export class TaggedError<Tag extends string>
|
||||||
extends Error
|
extends Error
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { TaggedError } from "./tagged-error.js";
|
import { TaggedError } from "./tagged-error.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `UnexpectedError` representa cualquier tipo de error inesperado.
|
* `UnexpectedError` represents any type of unexpected error.
|
||||||
*
|
*
|
||||||
* Este error se utiliza para representar errores que no deberían ocurrir en
|
* This error is used to represent errors that should not occur in
|
||||||
* la lógica de la aplicación, pero que siempre podrían suceder y
|
* the application logic, but that could always happen and
|
||||||
* debemos estar preparados para manejarlos.
|
* we must be prepared to handle.
|
||||||
*/
|
*/
|
||||||
export class UnexpectedError extends TaggedError<"UnexpectedError"> {
|
export class UnexpectedError extends TaggedError<"UnexpectedError"> {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
8
packages/fabric/core/src/files/index.ts
Normal file
8
packages/fabric/core/src/files/index.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export * from "./base-file.js";
|
||||||
|
export * from "./bytes.js";
|
||||||
|
export * from "./invalid-file-type-error.js";
|
||||||
|
export * from "./is-mime-type.js";
|
||||||
|
export * from "./is-uploaded-file.js";
|
||||||
|
export * from "./media-file.js";
|
||||||
|
export * from "./mime-type.js";
|
||||||
|
export * from "./uploaded-file.js";
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedError } from "../../../error/tagged-error.js";
|
import { TaggedError } from "../error/tagged-error.js";
|
||||||
|
|
||||||
export class InvalidFileTypeError extends TaggedError<"InvalidFileTypeError"> {
|
export class InvalidFileTypeError extends TaggedError<"InvalidFileTypeError"> {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -5,7 +5,7 @@ import { MimeType } from "./mime-type.js";
|
|||||||
*/
|
*/
|
||||||
export function isMimeType<T extends MimeType>(
|
export function isMimeType<T extends MimeType>(
|
||||||
expectedMimeType: T,
|
expectedMimeType: T,
|
||||||
actualFileType: string,
|
actualMimeType: string,
|
||||||
): actualFileType is T {
|
): actualMimeType is T {
|
||||||
return actualFileType.match("^" + expectedMimeType + "$") !== null;
|
return actualMimeType.match("^" + expectedMimeType + "$") !== null;
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import validator from "validator";
|
import validator from "validator";
|
||||||
import { isRecord } from "../../../record/is-record.js";
|
import { isRecord } from "../record/is-record.js";
|
||||||
import { InMemoryFile } from "./uploaded-file.js";
|
import { InMemoryFile } from "./uploaded-file.js";
|
||||||
|
|
||||||
const { isBase64, isMimeType } = validator;
|
const { isBase64, isMimeType } = validator;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { DomainFile } from "./domain-file.js";
|
import { DomainFile } from "../domain/entity/files/domain-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a media file, either an image, a video or an audio file.
|
* Represents a media file, either an image, a video or an audio file.
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { Base64String } from "../../types/base-64.js";
|
import { Base64String } from "../domain/types/base-64.js";
|
||||||
import { BaseFile } from "./base-file.js";
|
import { BaseFile } from "./base-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +32,7 @@ describe("timeout", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
test("using ms we can define a timeout in milliseconds", async () => {
|
test("using timeout we can define a timeout in milliseconds", async () => {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
await timeout(100);
|
await timeout(100);
|
||||||
const end = Date.now();
|
const end = Date.now();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user