@fabric/domain: extract domain utils from fabric/core and create a new package
This commit is contained in:
parent
59810a2118
commit
80c34e4649
@ -1 +1 @@
|
|||||||
# @ulthar/fabric-core
|
# @fabric/core
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@ulthar/fabric-core",
|
"name": "@fabric/core",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
export * from "./image-file.js";
|
|
||||||
export * from "./stored-file.js";
|
|
||||||
@ -1 +0,0 @@
|
|||||||
export * from "./entity.js";
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
export * from "./entity/index.js";
|
|
||||||
export * from "./models/index.js";
|
|
||||||
export * from "./security/index.js";
|
|
||||||
export * from "./types/index.js";
|
|
||||||
export * from "./use-case/index.js";
|
|
||||||
@ -1,9 +1,7 @@
|
|||||||
export * from "./array/index.js";
|
export * from "./array/index.js";
|
||||||
export * from "./domain/index.js";
|
|
||||||
export * from "./error/index.js";
|
export * from "./error/index.js";
|
||||||
export * from "./record/index.js";
|
export * from "./record/index.js";
|
||||||
export * from "./result/index.js";
|
export * from "./result/index.js";
|
||||||
export * from "./storage/index.js";
|
|
||||||
export * from "./time/index.js";
|
export * from "./time/index.js";
|
||||||
export * from "./types/index.js";
|
export * from "./types/index.js";
|
||||||
export * from "./variant/index.js";
|
export * from "./variant/index.js";
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
import { ModelSchema } from "../domain/index.js";
|
|
||||||
import { ModelToType } from "../domain/models/types/model-to-type.js";
|
|
||||||
import { Keyof } from "../types/keyof.js";
|
|
||||||
import { StoreQuery } from "./query/query.js";
|
|
||||||
|
|
||||||
export interface StateStore<TModels extends ModelSchema> {
|
|
||||||
from<TEntityName extends Keyof<TModels>>(
|
|
||||||
entityName: TEntityName,
|
|
||||||
): StoreQuery<ModelToType<TModels[TEntityName]>>;
|
|
||||||
}
|
|
||||||
@ -1 +1 @@
|
|||||||
export type EnumToValues<T extends Record<string, string>> = T[keyof T];
|
export type EnumToType<T extends Record<string, string>> = T[keyof T];
|
||||||
|
|||||||
1
packages/fabric/domain/README.md
Normal file
1
packages/fabric/domain/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# model
|
||||||
22
packages/fabric/domain/package.json
Normal file
22
packages/fabric/domain/package.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "@fabric/domain",
|
||||||
|
"type": "module",
|
||||||
|
"module": "dist/index.js",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"private": true,
|
||||||
|
"packageManager": "yarn@4.1.1",
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^5.6.2",
|
||||||
|
"vitest": "^2.1.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fabric/core": "workspace:^"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "vitest",
|
||||||
|
"build": "tsc -p tsconfig.build.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedError } from "../../error/tagged-error.js";
|
import { TaggedError } from "@fabric/core";
|
||||||
|
|
||||||
export class CircularDependencyError extends TaggedError<"CircularDependencyError"> {
|
export class CircularDependencyError extends TaggedError<"CircularDependencyError"> {
|
||||||
context: { key: string; dep: string };
|
context: { key: string; dep: string };
|
||||||
@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { TaggedError } from "../../error/tagged-error.js";
|
|
||||||
|
import { TaggedError } from "@fabric/core";
|
||||||
|
|
||||||
export class StoreQueryError extends TaggedError<"StoreQueryError"> {
|
export class StoreQueryError extends TaggedError<"StoreQueryError"> {
|
||||||
constructor(
|
constructor(
|
||||||
@ -1,6 +1,5 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { PosixDate } from "../../time/posix-date.js";
|
import { PosixDate, TaggedVariant } from "@fabric/core";
|
||||||
import { TaggedVariant } from "../../variant/variant.js";
|
|
||||||
import { UUID } from "../types/uuid.js";
|
import { UUID } from "../types/uuid.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,8 +14,7 @@ export interface Event<TTag extends string = string, TPayload = any>
|
|||||||
/**
|
/**
|
||||||
* A stored event is an inmutable event, already stored, with it's version in the stream and timestamp.
|
* A stored event is an inmutable event, already stored, with it's version in the stream and timestamp.
|
||||||
*/
|
*/
|
||||||
export interface StoredEvent<TTag extends string = string, TPayload = any>
|
export type StoredEvent<TEvent extends Event> = Readonly<TEvent> & {
|
||||||
extends Readonly<Event<TTag, TPayload>> {
|
|
||||||
readonly version: number;
|
readonly version: number;
|
||||||
readonly timestamp: PosixDate;
|
readonly timestamp: PosixDate;
|
||||||
}
|
};
|
||||||
1
packages/fabric/domain/src/events/index.ts
Normal file
1
packages/fabric/domain/src/events/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from "./event.js";
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { ImageMimeType } from "../../../files/mime-type.js";
|
import { ImageMimeType } from "./mime-type.js";
|
||||||
import { StoredFile } from "./stored-file.js";
|
import { StoredFile } from "./stored-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { Base64String } from "../domain/types/base-64.js";
|
import { Base64String } from "../types/base-64.js";
|
||||||
import { BaseFile } from "./base-file.js";
|
import { BaseFile } from "./base-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1,8 +1,10 @@
|
|||||||
export * from "./base-file.js";
|
export * from "./base-file.js";
|
||||||
export * from "./bytes.js";
|
export * from "./bytes.js";
|
||||||
|
export * from "./image-file.js";
|
||||||
export * from "./in-memory-file.js";
|
export * from "./in-memory-file.js";
|
||||||
export * from "./invalid-file-type-error.js";
|
export * from "./invalid-file-type-error.js";
|
||||||
export * from "./is-in-memory-file.js";
|
export * from "./is-in-memory-file.js";
|
||||||
export * from "./is-mime-type.js";
|
export * from "./is-mime-type.js";
|
||||||
export * from "./media-file.js";
|
export * from "./media-file.js";
|
||||||
export * from "./mime-type.js";
|
export * from "./mime-type.js";
|
||||||
|
export * from "./stored-file.js";
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedError } from "../error/tagged-error.js";
|
import { TaggedError } from "@fabric/core";
|
||||||
|
|
||||||
export class InvalidFileTypeError extends TaggedError<"InvalidFileTypeError"> {
|
export class InvalidFileTypeError extends TaggedError<"InvalidFileTypeError"> {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -1,5 +1,5 @@
|
|||||||
|
import { isRecord } from "@fabric/core";
|
||||||
import validator from "validator";
|
import validator from "validator";
|
||||||
import { isRecord } from "../record/is-record.js";
|
|
||||||
import { InMemoryFile } from "./in-memory-file.js";
|
import { InMemoryFile } from "./in-memory-file.js";
|
||||||
|
|
||||||
const { isBase64, isMimeType } = validator;
|
const { isBase64, isMimeType } = validator;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { StoredFile } from "../domain/entity/files/stored-file.js";
|
import { StoredFile } from "./stored-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,5 +1,5 @@
|
|||||||
import { BaseFile } from "../../../files/base-file.js";
|
import { Entity } from "../types/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.
|
||||||
9
packages/fabric/domain/src/index.ts
Normal file
9
packages/fabric/domain/src/index.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export * from "./errors/index.js";
|
||||||
|
export * from "./events/index.js";
|
||||||
|
export * from "./files/index.js";
|
||||||
|
export * from "./models/index.js";
|
||||||
|
export * from "./query/index.js";
|
||||||
|
export * from "./security/index.js";
|
||||||
|
export * from "./storage/index.js";
|
||||||
|
export * from "./types/index.js";
|
||||||
|
export * from "./use-case/index.js";
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedVariant, VariantTag } from "../../../variant/variant.js";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import { BaseField } from "./base-field.js";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface IntegerFieldOptions extends BaseField {
|
export interface IntegerFieldOptions extends BaseField {
|
||||||
@ -1,5 +1,5 @@
|
|||||||
|
import { isError } from "@fabric/core";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { isError } from "../../../error/is-error.js";
|
|
||||||
import { defineModel } from "../model.js";
|
import { defineModel } from "../model.js";
|
||||||
import { Field } from "./index.js";
|
import { Field } from "./index.js";
|
||||||
import {
|
import {
|
||||||
@ -1,6 +1,4 @@
|
|||||||
import { TaggedError } from "../../../error/tagged-error.js";
|
import { Result, TaggedError, TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import { Result } from "../../../result/result.js";
|
|
||||||
import { TaggedVariant, VariantTag } from "../../../variant/variant.js";
|
|
||||||
import { ModelSchema } from "../model-schema.js";
|
import { ModelSchema } from "../model-schema.js";
|
||||||
import { BaseField } from "./base-field.js";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedVariant, VariantTag } from "../../../variant/variant.js";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import { BaseField } from "./base-field.js";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface StringFieldOptions extends BaseField {
|
export interface StringFieldOptions extends BaseField {
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedVariant, VariantTag } from "../../../variant/variant.js";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import { BaseField } from "./base-field.js";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface UUIDFieldOptions extends BaseField {
|
export interface UUIDFieldOptions extends BaseField {
|
||||||
24
packages/fabric/domain/src/query/aggregate-options.ts
Normal file
24
packages/fabric/domain/src/query/aggregate-options.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
|
import { Keyof, TaggedVariant } from "@fabric/core";
|
||||||
|
|
||||||
|
export type AggregateOptions<T = any> = Record<string, AggregateFn<T>>;
|
||||||
|
|
||||||
|
export type AggregateFn<T> = CountAggregate<T>;
|
||||||
|
|
||||||
|
export interface CountAggregate<T> extends TaggedVariant<"AggregateCount"> {
|
||||||
|
field: Keyof<T>;
|
||||||
|
}
|
||||||
|
export interface SumAggregate<T> extends TaggedVariant<"AggregateSum"> {
|
||||||
|
field: Keyof<T>;
|
||||||
|
}
|
||||||
|
export interface AvgAggregate<T> extends TaggedVariant<"AggregateAvg"> {
|
||||||
|
field: Keyof<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MinAggregate<T> extends TaggedVariant<"AggregateMin"> {
|
||||||
|
field: Keyof<T>;
|
||||||
|
}
|
||||||
|
export interface MaxAggregate<T> extends TaggedVariant<"AggregateMax"> {
|
||||||
|
field: Keyof<T>;
|
||||||
|
}
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import { ModelSchema } from "../../domain/index.js";
|
import { AsyncResult, Keyof } from "@fabric/core";
|
||||||
import { ModelToType } from "../../domain/models/types/model-to-type.js";
|
|
||||||
import { AsyncResult } from "../../result/async-result.js";
|
|
||||||
import { Keyof } from "../../types/index.js";
|
|
||||||
import { StoreQueryError } from "../errors/query-error.js";
|
import { StoreQueryError } from "../errors/query-error.js";
|
||||||
import { StorageDriver } from "../storage-driver.js";
|
import { ModelToType } from "../models/index.js";
|
||||||
|
import { ModelSchema } from "../models/model-schema.js";
|
||||||
|
import { StorageDriver } from "../storage/storage-driver.js";
|
||||||
|
import { AggregateOptions } from "./aggregate-options.js";
|
||||||
import { FilterOptions } from "./filter-options.js";
|
import { FilterOptions } from "./filter-options.js";
|
||||||
import { OrderByOptions } from "./order-by-options.js";
|
import { OrderByOptions } from "./order-by-options.js";
|
||||||
import {
|
import {
|
||||||
@ -24,6 +24,9 @@ export class QueryBuilder<
|
|||||||
private driver: StorageDriver,
|
private driver: StorageDriver,
|
||||||
private query: QueryDefinition<TEntityName>,
|
private query: QueryDefinition<TEntityName>,
|
||||||
) {}
|
) {}
|
||||||
|
aggregate<K extends AggregateOptions<T>>(): SelectableQuery<K> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
where(where: FilterOptions<T>): StoreSortableQuery<T> {
|
where(where: FilterOptions<T>): StoreSortableQuery<T> {
|
||||||
this.query = {
|
this.query = {
|
||||||
@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { AsyncResult } from "../../result/async-result.js";
|
import { AsyncResult, Keyof } from "@fabric/core";
|
||||||
import { Keyof } from "../../types/keyof.js";
|
|
||||||
import { StoreQueryError } from "../errors/query-error.js";
|
import { StoreQueryError } from "../errors/query-error.js";
|
||||||
|
import { AggregateOptions } from "./aggregate-options.js";
|
||||||
import { FilterOptions } from "./filter-options.js";
|
import { FilterOptions } from "./filter-options.js";
|
||||||
import { OrderByOptions } from "./order-by-options.js";
|
import { OrderByOptions } from "./order-by-options.js";
|
||||||
|
|
||||||
@ -10,6 +10,8 @@ export interface StoreQuery<T> {
|
|||||||
orderBy(opts: OrderByOptions<T>): StoreLimitableQuery<T>;
|
orderBy(opts: OrderByOptions<T>): StoreLimitableQuery<T>;
|
||||||
limit(limit: number, offset?: number): SelectableQuery<T>;
|
limit(limit: number, offset?: number): SelectableQuery<T>;
|
||||||
|
|
||||||
|
aggregate<K extends AggregateOptions<T>>(opts: K): SelectableQuery<K>;
|
||||||
|
|
||||||
select(): AsyncResult<T[], StoreQueryError>;
|
select(): AsyncResult<T[], StoreQueryError>;
|
||||||
select<K extends Keyof<T>>(
|
select<K extends Keyof<T>>(
|
||||||
keys: K[],
|
keys: K[],
|
||||||
@ -1,9 +1,7 @@
|
|||||||
import { Event } from "../domain/events/event.js";
|
import { AsyncResult, MaybePromise, PosixDate } from "@fabric/core";
|
||||||
import { UUID } from "../domain/index.js";
|
import { StoreQueryError } from "../errors/query-error.js";
|
||||||
import { AsyncResult } from "../result/async-result.js";
|
import { Event, StoredEvent } from "../events/event.js";
|
||||||
import { PosixDate } from "../time/posix-date.js";
|
import { UUID } from "../types/uuid.js";
|
||||||
import { MaybePromise } from "../types/maybe-promise.js";
|
|
||||||
import { StoreQueryError } from "./errors/query-error.js";
|
|
||||||
|
|
||||||
export interface EventStore<TEvent extends Event = Event> {
|
export interface EventStore<TEvent extends Event = Event> {
|
||||||
getStream<TEventStreamEvent extends TEvent>(
|
getStream<TEventStreamEvent extends TEvent>(
|
||||||
@ -36,8 +34,3 @@ export interface EventFilterOptions {
|
|||||||
limit?: number;
|
limit?: number;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StoredEvent<TEvent extends Event = Event> = TEvent & {
|
|
||||||
version: bigint;
|
|
||||||
timestamp: number;
|
|
||||||
};
|
|
||||||
@ -1,5 +1,3 @@
|
|||||||
export * from "./errors/index.js";
|
|
||||||
export * from "./event-store.js";
|
export * from "./event-store.js";
|
||||||
export * from "./query/index.js";
|
|
||||||
export * from "./state-store.js";
|
export * from "./state-store.js";
|
||||||
export * from "./storage-driver.js";
|
export * from "./storage-driver.js";
|
||||||
18
packages/fabric/domain/src/storage/state-store.ts
Normal file
18
packages/fabric/domain/src/storage/state-store.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Keyof } from "@fabric/core";
|
||||||
|
import { ModelToType } from "../models/index.js";
|
||||||
|
import { ModelSchema } from "../models/model-schema.js";
|
||||||
|
import { QueryBuilder } from "../query/query-builder.js";
|
||||||
|
import { StoreQuery } from "../query/query.js";
|
||||||
|
import { StorageDriver } from "./storage-driver.js";
|
||||||
|
|
||||||
|
export class StateStore<TModels extends ModelSchema> {
|
||||||
|
constructor(private driver: StorageDriver) {}
|
||||||
|
|
||||||
|
from<TEntityName extends Keyof<TModels>>(
|
||||||
|
entityName: TEntityName,
|
||||||
|
): StoreQuery<ModelToType<TModels[TEntityName]>> {
|
||||||
|
return new QueryBuilder(this.driver, {
|
||||||
|
from: entityName,
|
||||||
|
}) as StoreQuery<ModelToType<TModels[TEntityName]>>;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,11 +1,10 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import { ModelSchema } from "../domain/index.js";
|
import { AsyncResult, UnexpectedError } from "@fabric/core";
|
||||||
import { UnexpectedError } from "../error/unexpected-error.js";
|
import { CircularDependencyError } from "../errors/circular-dependency-error.js";
|
||||||
import { AsyncResult } from "../result/async-result.js";
|
import { StoreQueryError } from "../errors/query-error.js";
|
||||||
import { CircularDependencyError } from "./errors/circular-dependency-error.js";
|
import { ModelSchema } from "../models/model-schema.js";
|
||||||
import { StoreQueryError } from "./errors/query-error.js";
|
import { QueryDefinition } from "../query/query.js";
|
||||||
import { QueryDefinition } from "./query/query.js";
|
|
||||||
|
|
||||||
export interface StorageDriver {
|
export interface StorageDriver {
|
||||||
/**
|
/**
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { UUID } from "../types/uuid.js";
|
import { UUID } from "./uuid.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An entity is a domain object that is defined by its identity.
|
* An entity is a domain object that is defined by its identity.
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
export * from "./base-64.js";
|
||||||
export * from "./email.js";
|
export * from "./email.js";
|
||||||
|
export * from "./entity.js";
|
||||||
export * from "./semver.js";
|
export * from "./semver.js";
|
||||||
export * from "./uuid.js";
|
export * from "./uuid.js";
|
||||||
@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { TaggedError } from "../../error/tagged-error.js";
|
import { TaggedError } from "@fabric/core";
|
||||||
import { UseCase } from "./use-case.js";
|
import { UseCase } from "./use-case.js";
|
||||||
|
|
||||||
export type UseCaseDefinition<
|
export type UseCaseDefinition<
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import { TaggedError } from "../../error/tagged-error.js";
|
import { AsyncResult, TaggedError } from "@fabric/core";
|
||||||
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.
|
||||||
1
packages/fabric/domain/src/utils/index.ts
Normal file
1
packages/fabric/domain/src/utils/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from "./sort-by-dependencies.js";
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { Result } from "../../result/result.js";
|
import { Result } from "@fabric/core";
|
||||||
import { CircularDependencyError } from "../errors/circular-dependency-error.js";
|
import { CircularDependencyError } from "../errors/circular-dependency-error.js";
|
||||||
|
|
||||||
export function sortByDependencies<T>(
|
export function sortByDependencies<T>(
|
||||||
15
packages/fabric/domain/tsconfig.build.json
Normal file
15
packages/fabric/domain/tsconfig.build.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": false,
|
||||||
|
"allowImportingTsExtensions": false,
|
||||||
|
"outDir": "dist"
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"dist",
|
||||||
|
"node_modules",
|
||||||
|
"coverage",
|
||||||
|
"vitest.config.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
4
packages/fabric/domain/tsconfig.json
Normal file
4
packages/fabric/domain/tsconfig.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../tsconfig.json",
|
||||||
|
"exclude": ["dist", "node_modules"]
|
||||||
|
}
|
||||||
10
packages/fabric/domain/vitest.config.ts
Normal file
10
packages/fabric/domain/vitest.config.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
coverage: {
|
||||||
|
exclude: ["**/index.ts"],
|
||||||
|
},
|
||||||
|
passWithNoTests: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
@ -13,7 +13,8 @@
|
|||||||
"vitest": "^2.1.1"
|
"vitest": "^2.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ulthar/fabric-core": "workspace:^",
|
"@fabric/core": "workspace:^",
|
||||||
|
"@fabric/domain": "workspace:^",
|
||||||
"sqlite3": "^5.1.7"
|
"sqlite3": "^5.1.7"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import {
|
import { VariantTag } from "@fabric/core";
|
||||||
BaseField,
|
import { BaseField, FieldDefinition, Model } from "@fabric/domain";
|
||||||
FieldDefinition,
|
|
||||||
ModelDefinition,
|
|
||||||
VariantTag,
|
|
||||||
} from "@ulthar/fabric-core";
|
|
||||||
|
|
||||||
type FieldMap = {
|
type FieldMap = {
|
||||||
[K in FieldDefinition[VariantTag]]: (
|
[K in FieldDefinition[VariantTag]]: (
|
||||||
@ -23,6 +19,12 @@ const FieldMap: FieldMap = {
|
|||||||
modifiersFromOpts(f),
|
modifiersFromOpts(f),
|
||||||
].join(" ");
|
].join(" ");
|
||||||
},
|
},
|
||||||
|
IntegerField: function (): string {
|
||||||
|
throw new Error("Function not implemented.");
|
||||||
|
},
|
||||||
|
ReferenceField: function (): string {
|
||||||
|
throw new Error("Function not implemented.");
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function modifiersFromOpts(options: BaseField) {
|
function modifiersFromOpts(options: BaseField) {
|
||||||
@ -37,7 +39,7 @@ function fieldDefinitionToSQL(field: FieldDefinition) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function modelToSql(
|
export function modelToSql(
|
||||||
model: ModelDefinition<string, Record<string, FieldDefinition>>,
|
model: Model<string, Record<string, FieldDefinition>>,
|
||||||
) {
|
) {
|
||||||
return Object.entries(model.fields)
|
return Object.entries(model.fields)
|
||||||
.map(([name, type]) => `${name} ${fieldDefinitionToSQL(type)}`)
|
.map(([name, type]) => `${name} ${fieldDefinitionToSQL(type)}`)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { createModel, Field, isError } from "@ulthar/fabric-core";
|
import { createModel, Field, isError } from "@fabric/core";
|
||||||
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
||||||
import { SQLiteStorageDriver } from "./sqlite-driver.js";
|
import { SQLiteStorageDriver } from "./sqlite-driver.js";
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import { AsyncResult, UnexpectedError } from "@fabric/core";
|
||||||
|
import { unlink } from "fs/promises";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AsyncResult,
|
|
||||||
CircularDependencyError,
|
CircularDependencyError,
|
||||||
ModelDefinition,
|
|
||||||
QueryDefinition,
|
QueryDefinition,
|
||||||
StorageDriver,
|
StorageDriver,
|
||||||
StoreQueryError,
|
StoreQueryError,
|
||||||
UnexpectedError,
|
} from "@fabric/domain";
|
||||||
} from "@ulthar/fabric-core";
|
|
||||||
import { unlink } from "fs/promises";
|
|
||||||
|
|
||||||
import { Database, Statement } from "sqlite3";
|
import { Database, Statement } from "sqlite3";
|
||||||
import { modelToSql } from "./model-to-sql.js";
|
import { modelToSql } from "./model-to-sql.js";
|
||||||
import {
|
import {
|
||||||
|
|||||||
@ -13,7 +13,8 @@
|
|||||||
"vitest": "^2.1.1"
|
"vitest": "^2.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ulthar/fabric-core": "workspace:^"
|
"@fabric/core": "workspace:^",
|
||||||
|
"@fabric/domain": "workspace:^"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { EnumToValues } from "@ulthar/fabric-core";
|
import { EnumToType } from "@fabric/core";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A permission is a string that represents a something that a user is allowed to do in the system. It should be in the form of: `ACTION_ENTITY`.
|
* A permission is a string that represents a something that a user is allowed to do in the system. It should be in the form of: `ACTION_ENTITY`.
|
||||||
@ -7,4 +7,4 @@ import { EnumToValues } from "@ulthar/fabric-core";
|
|||||||
*/
|
*/
|
||||||
export const Permission = {} as const;
|
export const Permission = {} as const;
|
||||||
|
|
||||||
export type Permission = EnumToValues<typeof Permission>;
|
export type Permission = EnumToType<typeof Permission>;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Policy } from "@ulthar/fabric-core";
|
import { Policy } from "@fabric/domain";
|
||||||
import { Permission } from "./permission.js";
|
import { Permission } from "./permission.js";
|
||||||
import { UserType } from "./users.js";
|
import { UserType } from "./users.js";
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { EnumToValues } from "@ulthar/fabric-core";
|
import { EnumToType } from "@fabric/core";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A User Type is a string that represents a user type.
|
* A User Type is a string that represents a user type.
|
||||||
@ -8,4 +8,4 @@ export const UserType = {
|
|||||||
// ADMIN: "ADMIN",
|
// ADMIN: "ADMIN",
|
||||||
// SPECIAL_USER: "SPECIAL_USER",
|
// SPECIAL_USER: "SPECIAL_USER",
|
||||||
};
|
};
|
||||||
export type UserType = EnumToValues<typeof UserType>;
|
export type UserType = EnumToType<typeof UserType>;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { UseCaseDefinition } from "@ulthar/fabric-core";
|
import { UseCaseDefinition } from "@fabric/domain";
|
||||||
|
|
||||||
export const UseCases = [] as const satisfies UseCaseDefinition[];
|
export const UseCases = [] as const satisfies UseCaseDefinition[];
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
"vitest": "^2.1.1"
|
"vitest": "^2.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ulthar/fabric-core": "workspace:^"
|
"@fabric/core": "workspace:^"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
|
|||||||
39
yarn.lock
39
yarn.lock
@ -403,6 +403,27 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@fabric/core@workspace:^, @fabric/core@workspace:packages/fabric/core":
|
||||||
|
version: 0.0.0-use.local
|
||||||
|
resolution: "@fabric/core@workspace:packages/fabric/core"
|
||||||
|
dependencies:
|
||||||
|
"@types/validator": "npm:^13.12.2"
|
||||||
|
typescript: "npm:^5.6.2"
|
||||||
|
validator: "npm:^13.12.0"
|
||||||
|
vitest: "npm:^2.1.1"
|
||||||
|
languageName: unknown
|
||||||
|
linkType: soft
|
||||||
|
|
||||||
|
"@fabric/domain@workspace:^, @fabric/domain@workspace:packages/fabric/domain":
|
||||||
|
version: 0.0.0-use.local
|
||||||
|
resolution: "@fabric/domain@workspace:packages/fabric/domain"
|
||||||
|
dependencies:
|
||||||
|
"@fabric/core": "workspace:^"
|
||||||
|
typescript: "npm:^5.6.2"
|
||||||
|
vitest: "npm:^2.1.1"
|
||||||
|
languageName: unknown
|
||||||
|
linkType: soft
|
||||||
|
|
||||||
"@gar/promisify@npm:^1.0.1":
|
"@gar/promisify@npm:^1.0.1":
|
||||||
version: 1.1.3
|
version: 1.1.3
|
||||||
resolution: "@gar/promisify@npm:1.1.3"
|
resolution: "@gar/promisify@npm:1.1.3"
|
||||||
@ -824,22 +845,11 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@ulthar/fabric-core@workspace:^, @ulthar/fabric-core@workspace:packages/fabric/core":
|
|
||||||
version: 0.0.0-use.local
|
|
||||||
resolution: "@ulthar/fabric-core@workspace:packages/fabric/core"
|
|
||||||
dependencies:
|
|
||||||
"@types/validator": "npm:^13.12.2"
|
|
||||||
typescript: "npm:^5.6.2"
|
|
||||||
validator: "npm:^13.12.0"
|
|
||||||
vitest: "npm:^2.1.1"
|
|
||||||
languageName: unknown
|
|
||||||
linkType: soft
|
|
||||||
|
|
||||||
"@ulthar/lib-template@workspace:packages/templates/lib":
|
"@ulthar/lib-template@workspace:packages/templates/lib":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@ulthar/lib-template@workspace:packages/templates/lib"
|
resolution: "@ulthar/lib-template@workspace:packages/templates/lib"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@ulthar/fabric-core": "workspace:^"
|
"@fabric/core": "workspace:^"
|
||||||
typescript: "npm:^5.6.2"
|
typescript: "npm:^5.6.2"
|
||||||
vitest: "npm:^2.1.1"
|
vitest: "npm:^2.1.1"
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
@ -849,7 +859,8 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@ulthar/store-sqlite@workspace:packages/fabric/store-sqlite"
|
resolution: "@ulthar/store-sqlite@workspace:packages/fabric/store-sqlite"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@ulthar/fabric-core": "workspace:^"
|
"@fabric/core": "workspace:^"
|
||||||
|
"@fabric/domain": "workspace:^"
|
||||||
sqlite3: "npm:^5.1.7"
|
sqlite3: "npm:^5.1.7"
|
||||||
typescript: "npm:^5.6.2"
|
typescript: "npm:^5.6.2"
|
||||||
vitest: "npm:^2.1.1"
|
vitest: "npm:^2.1.1"
|
||||||
@ -860,7 +871,7 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@ulthar/template-domain@workspace:packages/templates/domain"
|
resolution: "@ulthar/template-domain@workspace:packages/templates/domain"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@ulthar/fabric-core": "workspace:^"
|
"@fabric/core": "workspace:^"
|
||||||
typescript: "npm:^5.6.2"
|
typescript: "npm:^5.6.2"
|
||||||
vitest: "npm:^2.1.1"
|
vitest: "npm:^2.1.1"
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user