Compare commits
2 Commits
b164c7d97f
...
c4483f073e
| Author | SHA1 | Date | |
|---|---|---|---|
| c4483f073e | |||
| 0ffe2838c1 |
12
packages/fabric/core/src/array/array-element.spec.ts
Normal file
12
packages/fabric/core/src/array/array-element.spec.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { describe, expectTypeOf, test } from "vitest";
|
||||
|
||||
describe("ArrayElement utils", () => {
|
||||
test("Given an array, it should return the element type of the array", () => {
|
||||
type ArrayElement<T extends readonly unknown[]> =
|
||||
T extends readonly (infer U)[] ? U : never;
|
||||
|
||||
type result = ArrayElement<["a", "b", "c"]>;
|
||||
|
||||
expectTypeOf<result>().toEqualTypeOf<"a" | "b" | "c">();
|
||||
});
|
||||
});
|
||||
17
packages/fabric/core/src/array/array-element.ts
Normal file
17
packages/fabric/core/src/array/array-element.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Get the element type of an array.
|
||||
*/
|
||||
export type ArrayElement<T extends readonly unknown[]> =
|
||||
T extends readonly (infer U)[] ? U : never;
|
||||
|
||||
/**
|
||||
* Get the first element type of a tuple.
|
||||
*/
|
||||
export type TupleFirstElement<T extends readonly unknown[]> =
|
||||
T extends readonly [infer U, ...unknown[]] ? U : never;
|
||||
|
||||
/**
|
||||
* Get the LAST element type of a tuple.
|
||||
*/
|
||||
export type TupleLastElement<T extends readonly unknown[]> =
|
||||
T extends readonly [...unknown[], infer U] ? U : never;
|
||||
1
packages/fabric/core/src/array/index.ts
Normal file
1
packages/fabric/core/src/array/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./array-element.js";
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseFile } from "../../../files/base-file.js";
|
||||
import { Entity } from "../entity.js";
|
||||
import { BaseFile } from "./base-file.js";
|
||||
|
||||
/**
|
||||
* 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 { ImageMimeType } from "./mime-type.js";
|
||||
|
||||
/**
|
||||
* Represents an image file.
|
||||
|
||||
@ -1,10 +1,2 @@
|
||||
export * from "./base-file.js";
|
||||
export * from "./bytes.js";
|
||||
export * from "./domain-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 "./files/index.js";
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
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>
|
||||
extends TaggedVariant<TTag> {
|
||||
payload: TPayload;
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* A PolicyMap maps user types to their security policies.
|
||||
*/
|
||||
export type PolicyMap<
|
||||
UserType extends string,
|
||||
PolicyType extends string,
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
export * from "./email.js";
|
||||
export * from "./sem-ver.js";
|
||||
export * from "./semver.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.
|
||||
*
|
||||
* 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<
|
||||
TDependencies,
|
||||
|
||||
@ -1,15 +1,8 @@
|
||||
import { VariantTag } from "../variant/variant.js";
|
||||
import { TaggedError } from "./tagged-error.js";
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
return (
|
||||
err instanceof Error &&
|
||||
VariantTag in err &&
|
||||
typeof err[VariantTag] === "string"
|
||||
);
|
||||
return err instanceof TaggedError;
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
import { TaggedVariant, VariantTag } from "../variant/index.js";
|
||||
|
||||
/**
|
||||
* Un TaggedError es un error que tiene un tag que lo identifica, lo cual
|
||||
* permite a los consumidores de la instancia de error identificar el tipo de
|
||||
* error que ocurrió.
|
||||
* A TaggedError is a tagged variant with an error message.
|
||||
*/
|
||||
export class TaggedError<Tag extends string>
|
||||
extends Error
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
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
|
||||
* la lógica de la aplicación, pero que siempre podrían suceder y
|
||||
* debemos estar preparados para manejarlos.
|
||||
* This error is used to represent errors that should not occur in
|
||||
* the application logic, but that could always happen and
|
||||
* we must be prepared to handle.
|
||||
*/
|
||||
export class UnexpectedError extends TaggedError<"UnexpectedError"> {
|
||||
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"> {
|
||||
constructor() {
|
||||
@ -5,7 +5,7 @@ import { MimeType } from "./mime-type.js";
|
||||
*/
|
||||
export function isMimeType<T extends MimeType>(
|
||||
expectedMimeType: T,
|
||||
actualFileType: string,
|
||||
): actualFileType is T {
|
||||
return actualFileType.match("^" + expectedMimeType + "$") !== null;
|
||||
actualMimeType: string,
|
||||
): actualMimeType is T {
|
||||
return actualMimeType.match("^" + expectedMimeType + "$") !== null;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import validator from "validator";
|
||||
import { isRecord } from "../../../record/is-record.js";
|
||||
import { isRecord } from "../record/is-record.js";
|
||||
import { InMemoryFile } from "./uploaded-file.js";
|
||||
|
||||
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.
|
||||
@ -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";
|
||||
|
||||
/**
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./array/index.js";
|
||||
export * from "./domain/index.js";
|
||||
export * from "./error/index.js";
|
||||
export * from "./record/index.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();
|
||||
await timeout(100);
|
||||
const end = Date.now();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user