Viniciustda/OiTenta / .agents/skills/config-package-shared
config-package-shared
VerifiedReconstrói o pacote compartilhado base da aplicação, concentrando contratos reutilizáveis, classes base, erros de domínio, casos de uso e validações consumidas pelo backend, frontend e módulos de negócio.
assets/shared-template/src/model/entity.ts
View on GitHubimport { v4 as uuidv4 } from "uuid";
import { DateRule, RequiredRule, UuidRule, Validator } from "../validation";
export interface EntityState {
id?: string;
createdAt?: Date;
updatedAt?: Date;
deletedAt?: Date | null;
}
export abstract class Entity<TState extends EntityState> {
protected readonly props: Readonly<TState>;
protected constructor(props: TState) {
const createdAt = props.createdAt ?? new Date();
const updatedAt = props.updatedAt ?? cloneDate(createdAt);
const deletedAt = props.deletedAt ?? null;
this.props = Object.freeze({
...props,
id: props.id ?? uuidv4(),
createdAt: cloneDate(createdAt),
updatedAt: cloneDate(updatedAt),
deletedAt: deletedAt === null ? null : cloneDate(deletedAt),
}) as Readonly<TState>;
this.validateId();
this.validateTimestamps();
}
get id(): string {
return this.props.id!;
}
get createdAt(): Date {
return this.props.createdAt!;
}
get updatedAt(): Date {
return this.props.updatedAt!;
}
get deletedAt(): Date | null | undefined {
return this.props.deletedAt;
}
equals(entity?: Entity<TState> | null): boolean {
return entity !== null && entity !== undefined && this.id === entity.id;
}
clone(data: Partial<TState>): this {
const EntityClass = this.constructor as new (props: TState) => this;
return new EntityClass({
...(this.props as TState),
...data,
updatedAt: data.updatedAt ?? new Date(),
});
}
public abstract validate(): void;
private validateId(): void {
Validator.validate([
{
code: "id",
value: this.id,
rules: [new RequiredRule(), new UuidRule()],
},
]);
}
private validateTimestamps(): void {
Validator.validate([
{
code: "createdAt",
value: this.createdAt,
rules: [new RequiredRule(), new DateRule()],
},
{
code: "updatedAt",
value: this.updatedAt,
rules: [new RequiredRule(), new DateRule()],
},
{
code: "deletedAt",
value: this.deletedAt,
rules: [new DateRule()],
},
]);
}
}
function cloneDate(value: Date): Date {
return new Date(value.getTime());
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |