Compare commits
No commits in common. "b2e8b33dae259f839f66cd89a514128fae8f5724" and "bfb471b1660bb953880bafa367a6cc9cb5311155" have entirely different histories.
b2e8b33dae
...
bfb471b166
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1 +1,4 @@
|
|||||||
|
/.yarn/** linguist-vendored
|
||||||
|
/.yarn/releases/* binary
|
||||||
|
/.yarn/plugins/**/* binary
|
||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
|
|||||||
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,3 +1,11 @@
|
|||||||
|
.yarn/*
|
||||||
|
!.yarn/patches
|
||||||
|
!.yarn/plugins
|
||||||
|
!.yarn/releases
|
||||||
|
!.yarn/sdks
|
||||||
|
!.yarn/versions
|
||||||
|
|
||||||
|
node_modules
|
||||||
.env
|
.env
|
||||||
dist
|
dist
|
||||||
coverage
|
coverage
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
. "$(dirname -- "$0")/_/hook.sh"
|
|
||||||
|
|
||||||
deno run -A npm:lint-staged
|
|
||||||
9
.husky/pre-commit
Normal file
9
.husky/pre-commit
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# .husky/pre-commit
|
||||||
|
yarn lint-staged
|
||||||
|
|
||||||
|
branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
|
|
||||||
|
if [ "$branch" = "main" ]; then
|
||||||
|
echo "You can't commit directly to main branch"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"*": ["deno fmt --check"],
|
"*": ["yarn prettier -u --write"],
|
||||||
"*.ts": ["deno lint --fix"]
|
"*.ts": ["yarn eslint --fix"]
|
||||||
}
|
}
|
||||||
|
|||||||
4
.prettierignore
Normal file
4
.prettierignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
dist
|
||||||
|
coverage
|
||||||
|
.yarn/**/*
|
||||||
|
yarn.lock
|
||||||
3
.prettierrc
Normal file
3
.prettierrc
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"tabWidth": 2
|
||||||
|
}
|
||||||
4
.vscode/extensions.json
vendored
4
.vscode/extensions.json
vendored
@ -2,11 +2,13 @@
|
|||||||
"recommendations": [
|
"recommendations": [
|
||||||
"bierner.github-markdown-preview",
|
"bierner.github-markdown-preview",
|
||||||
"bradlc.vscode-tailwindcss",
|
"bradlc.vscode-tailwindcss",
|
||||||
|
"dbaeumer.vscode-eslint",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
"streetsidesoftware.code-spell-checker",
|
"streetsidesoftware.code-spell-checker",
|
||||||
"streetsidesoftware.code-spell-checker-spanish",
|
"streetsidesoftware.code-spell-checker-spanish",
|
||||||
"usernamehw.errorlens",
|
"usernamehw.errorlens",
|
||||||
"bourhaouta.tailwindshades",
|
"bourhaouta.tailwindshades",
|
||||||
"austenc.tailwind-docs",
|
"austenc.tailwind-docs",
|
||||||
"denoland.vscode-deno",
|
"vitest.explorer"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -17,8 +17,5 @@
|
|||||||
},
|
},
|
||||||
"typescript.preferences.importModuleSpecifierEnding": "js",
|
"typescript.preferences.importModuleSpecifierEnding": "js",
|
||||||
"cSpell.words": ["autodocs", "Syntropy"],
|
"cSpell.words": ["autodocs", "Syntropy"],
|
||||||
"typescript.preferences.autoImportFileExcludePatterns": ["**/chai/**"],
|
"typescript.preferences.autoImportFileExcludePatterns": ["**/chai/**"]
|
||||||
"[typescript]": {
|
|
||||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
925
.yarn/releases/yarn-4.5.0.cjs
vendored
Normal file
925
.yarn/releases/yarn-4.5.0.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
3
.yarnrc.yml
Normal file
3
.yarnrc.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
nodeLinker: node-modules
|
||||||
|
|
||||||
|
yarnPath: .yarn/releases/yarn-4.5.0.cjs
|
||||||
36
deno.jsonc
36
deno.jsonc
@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"tasks": {
|
|
||||||
"test": "deno test --allow-all --unstable-ffi",
|
|
||||||
"test:dev": "deno test --allow-all --unstable-ffi --watch",
|
|
||||||
"hook": "deno run --allow-read --allow-run --allow-write https://deno.land/x/deno_hooks@0.1.1/mod.ts"
|
|
||||||
},
|
|
||||||
"workspace": [
|
|
||||||
"packages/fabric/core",
|
|
||||||
"packages/fabric/domain",
|
|
||||||
"packages/fabric/sqlite-store",
|
|
||||||
"packages/fabric/testing",
|
|
||||||
"packages/templates/domain",
|
|
||||||
"packages/templates/lib"
|
|
||||||
],
|
|
||||||
"imports": {
|
|
||||||
"@db/sqlite": "jsr:@db/sqlite@^0.12.0",
|
|
||||||
"@quentinadam/decimal": "jsr:@quentinadam/decimal@^0.1.6",
|
|
||||||
"@std/expect": "jsr:@std/expect@^1.0.5",
|
|
||||||
"@std/testing": "jsr:@std/testing@^1.0.3",
|
|
||||||
"expect-type": "npm:expect-type@^1.1.0"
|
|
||||||
},
|
|
||||||
"compilerOptions": {
|
|
||||||
"strict": true,
|
|
||||||
"exactOptionalPropertyTypes": true,
|
|
||||||
"useUnknownInCatchVariables": true,
|
|
||||||
"noImplicitOverride": true,
|
|
||||||
"noUncheckedIndexedAccess": true
|
|
||||||
},
|
|
||||||
"lint": {
|
|
||||||
"include": ["src/"],
|
|
||||||
"rules": {
|
|
||||||
"tags": ["recommended"],
|
|
||||||
"exclude": ["no-namespace"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
138
deno.lock
138
deno.lock
@ -1,138 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "4",
|
|
||||||
"specifiers": {
|
|
||||||
"jsr:@db/sqlite@*": "0.12.0",
|
|
||||||
"jsr:@db/sqlite@0.12": "0.12.0",
|
|
||||||
"jsr:@denosaurs/plug@1": "1.0.6",
|
|
||||||
"jsr:@quentinadam/assert@~0.1.7": "0.1.7",
|
|
||||||
"jsr:@quentinadam/decimal@*": "0.1.6",
|
|
||||||
"jsr:@quentinadam/decimal@~0.1.6": "0.1.6",
|
|
||||||
"jsr:@std/assert@0.217": "0.217.0",
|
|
||||||
"jsr:@std/assert@0.221": "0.221.0",
|
|
||||||
"jsr:@std/assert@^1.0.6": "1.0.6",
|
|
||||||
"jsr:@std/data-structures@^1.0.4": "1.0.4",
|
|
||||||
"jsr:@std/encoding@0.221": "0.221.0",
|
|
||||||
"jsr:@std/expect@*": "1.0.5",
|
|
||||||
"jsr:@std/expect@^1.0.5": "1.0.5",
|
|
||||||
"jsr:@std/fmt@0.221": "0.221.0",
|
|
||||||
"jsr:@std/fs@0.221": "0.221.0",
|
|
||||||
"jsr:@std/fs@^1.0.4": "1.0.4",
|
|
||||||
"jsr:@std/internal@^1.0.4": "1.0.4",
|
|
||||||
"jsr:@std/path@0.217": "0.217.0",
|
|
||||||
"jsr:@std/path@0.221": "0.221.0",
|
|
||||||
"jsr:@std/path@^1.0.6": "1.0.6",
|
|
||||||
"jsr:@std/testing@^1.0.3": "1.0.3",
|
|
||||||
"npm:expect-type@*": "1.1.0",
|
|
||||||
"npm:expect-type@^1.1.0": "1.1.0"
|
|
||||||
},
|
|
||||||
"jsr": {
|
|
||||||
"@db/sqlite@0.12.0": {
|
|
||||||
"integrity": "dd1ef7f621ad50fc1e073a1c3609c4470bd51edc0994139c5bf9851de7a6d85f",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@denosaurs/plug",
|
|
||||||
"jsr:@std/path@0.217"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@denosaurs/plug@1.0.6": {
|
|
||||||
"integrity": "6cf5b9daba7799837b9ffbe89f3450510f588fafef8115ddab1ff0be9cb7c1a7",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/encoding",
|
|
||||||
"jsr:@std/fmt",
|
|
||||||
"jsr:@std/fs@0.221",
|
|
||||||
"jsr:@std/path@0.221"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@quentinadam/assert@0.1.7": {
|
|
||||||
"integrity": "0246fb7fd3aa7b286535db40feefdafc588272d3f287b4eb995c96263ab6dfca"
|
|
||||||
},
|
|
||||||
"@quentinadam/decimal@0.1.6": {
|
|
||||||
"integrity": "fd3e2684614355db8a6ef94a839cbe115f040e8dcc843a17a0c5afa23e3db408",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@quentinadam/assert"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/assert@0.217.0": {
|
|
||||||
"integrity": "c98e279362ca6982d5285c3b89517b757c1e3477ee9f14eb2fdf80a45aaa9642"
|
|
||||||
},
|
|
||||||
"@std/assert@0.221.0": {
|
|
||||||
"integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a"
|
|
||||||
},
|
|
||||||
"@std/assert@1.0.6": {
|
|
||||||
"integrity": "1904c05806a25d94fe791d6d883b685c9e2dcd60e4f9fc30f4fc5cf010c72207",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/internal"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/data-structures@1.0.4": {
|
|
||||||
"integrity": "fa0e20c11eb9ba673417450915c750a0001405a784e2a4e0c3725031681684a0"
|
|
||||||
},
|
|
||||||
"@std/encoding@0.221.0": {
|
|
||||||
"integrity": "d1dd76ef0dc5d14088411e6dc1dede53bf8308c95d1537df1214c97137208e45"
|
|
||||||
},
|
|
||||||
"@std/expect@1.0.5": {
|
|
||||||
"integrity": "8c7ac797e2ffe57becc6399c0f2fd06230cb9ef124d45229c6e592c563824af1",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/assert@^1.0.6",
|
|
||||||
"jsr:@std/internal"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/fmt@0.221.0": {
|
|
||||||
"integrity": "379fed69bdd9731110f26b9085aeb740606b20428ce6af31ef6bd45ef8efa62a"
|
|
||||||
},
|
|
||||||
"@std/fs@0.221.0": {
|
|
||||||
"integrity": "028044450299de8ed5a716ade4e6d524399f035513b85913794f4e81f07da286",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/assert@0.221",
|
|
||||||
"jsr:@std/path@0.221"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/fs@1.0.4": {
|
|
||||||
"integrity": "2907d32d8d1d9e540588fd5fe0ec21ee638134bd51df327ad4e443aaef07123c",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/path@^1.0.6"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/internal@1.0.4": {
|
|
||||||
"integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422"
|
|
||||||
},
|
|
||||||
"@std/path@0.217.0": {
|
|
||||||
"integrity": "1217cc25534bca9a2f672d7fe7c6f356e4027df400c0e85c0ef3e4343bc67d11",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/assert@0.217"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/path@0.221.0": {
|
|
||||||
"integrity": "0a36f6b17314ef653a3a1649740cc8db51b25a133ecfe838f20b79a56ebe0095",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/assert@0.221"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"@std/path@1.0.6": {
|
|
||||||
"integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed"
|
|
||||||
},
|
|
||||||
"@std/testing@1.0.3": {
|
|
||||||
"integrity": "f98c2bee53860a5916727d7e7d3abe920dd6f9edace022e2d059f00d05c2cf42",
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@std/assert@^1.0.6",
|
|
||||||
"jsr:@std/data-structures",
|
|
||||||
"jsr:@std/fs@^1.0.4",
|
|
||||||
"jsr:@std/internal",
|
|
||||||
"jsr:@std/path@^1.0.6"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"npm": {
|
|
||||||
"expect-type@1.1.0": {
|
|
||||||
"integrity": "sha512-bFi65yM+xZgk+u/KRIpekdSYkTB5W1pEf0Lt8Q8Msh7b+eQ7LXVtIB1Bkm4fvclDEL1b2CZkMhv2mOeF8tMdkA=="
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"workspace": {
|
|
||||||
"dependencies": [
|
|
||||||
"jsr:@db/sqlite@0.12",
|
|
||||||
"jsr:@quentinadam/decimal@~0.1.6",
|
|
||||||
"jsr:@std/expect@^1.0.5",
|
|
||||||
"jsr:@std/testing@^1.0.3",
|
|
||||||
"npm:expect-type@^1.1.0"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
15
eslint.config.js
Normal file
15
eslint.config.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
import eslint from "@eslint/js";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
eslint.configs.recommended,
|
||||||
|
...tseslint.configs.strict,
|
||||||
|
...tseslint.configs.stylistic,
|
||||||
|
{
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-namespace": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
33
package.json
Normal file
33
package.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "ulthar-framework",
|
||||||
|
"packageManager": "yarn@4.5.0",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"workspaces": [
|
||||||
|
"packages/**/*",
|
||||||
|
"apps/**/*"
|
||||||
|
],
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.12.0",
|
||||||
|
"@types/eslint": "^9.6.1",
|
||||||
|
"@types/eslint__js": "^8.42.3",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"eslint": "^9.12.0",
|
||||||
|
"husky": "^9.1.6",
|
||||||
|
"lint-staged": "^15.2.10",
|
||||||
|
"prettier": "^3.3.3",
|
||||||
|
"tsx": "^4.19.1",
|
||||||
|
"typescript": "^5.6.3",
|
||||||
|
"typescript-eslint": "^8.8.1",
|
||||||
|
"zx": "^8.1.9"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"lint": "eslint . --fix --report-unused-disable-directives",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"test": "yarn workspaces foreach -vvpA run test --run --clearScreen false",
|
||||||
|
"build": "yarn workspaces foreach -vvpA --topological run build",
|
||||||
|
"add-package": "tsx ./scripts/add-package.ts",
|
||||||
|
"postinstall": "husky"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@fabric/core",
|
|
||||||
"exports": {
|
|
||||||
".": "./src/index.ts"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
packages/fabric/core/package.json
Normal file
25
packages/fabric/core/package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "@fabric/core",
|
||||||
|
"private": true,
|
||||||
|
"sideEffects": false,
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"packageManager": "yarn@4.1.1",
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitest/coverage-v8": "^2.1.2",
|
||||||
|
"typescript": "^5.6.3",
|
||||||
|
"vitest": "^2.1.2"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "vitest",
|
||||||
|
"coverage": "vitest run --coverage",
|
||||||
|
"build": "tsc -p tsconfig.build.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
import { describe, expectTypeOf, test } from "@fabric/testing";
|
import { describe, expectTypeOf, test } from "vitest";
|
||||||
import type { ArrayElement } from "./array-element.ts";
|
|
||||||
|
|
||||||
describe("ArrayElement", () => {
|
describe("ArrayElement utils", () => {
|
||||||
test("Given an array, it should return the element type of the array", () => {
|
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"]>;
|
type result = ArrayElement<["a", "b", "c"]>;
|
||||||
|
|
||||||
expectTypeOf<result>().toEqualTypeOf<"a" | "b" | "c">();
|
expectTypeOf<result>().toEqualTypeOf<"a" | "b" | "c">();
|
||||||
@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Get the element type of an array.
|
* Get the element type of an array.
|
||||||
*/
|
*/
|
||||||
export type ArrayElement<T extends readonly unknown[]> = T extends
|
export type ArrayElement<T extends readonly unknown[]> =
|
||||||
readonly (infer U)[] ? U : never;
|
T extends readonly (infer U)[] ? U : never;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the first element type of a tuple.
|
* Get the first element type of a tuple.
|
||||||
*/
|
*/
|
||||||
export type TupleFirstElement<T extends readonly unknown[]> = T extends
|
export type TupleFirstElement<T extends readonly unknown[]> =
|
||||||
readonly [infer U, ...unknown[]] ? U : never;
|
T extends readonly [infer U, ...unknown[]] ? U : never;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the LAST element type of a tuple.
|
* Get the LAST element type of a tuple.
|
||||||
*/
|
*/
|
||||||
export type TupleLastElement<T extends readonly unknown[]> = T extends
|
export type TupleLastElement<T extends readonly unknown[]> =
|
||||||
readonly [...unknown[], infer U] ? U : never;
|
T extends readonly [...unknown[], infer U] ? U : never;
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./array-element.ts";
|
export * from "./array-element.js";
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export * from "./is-error.ts";
|
export * from "./is-error.js";
|
||||||
export * from "./tagged-error.ts";
|
export * from "./tagged-error.js";
|
||||||
export * from "./unexpected-error.ts";
|
export * from "./unexpected-error.js";
|
||||||
|
|||||||
23
packages/fabric/core/src/error/is-error.spec.ts
Normal file
23
packages/fabric/core/src/error/is-error.spec.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||||
|
import { Result } from "../result/result.js";
|
||||||
|
import { isError } from "./is-error.js";
|
||||||
|
import { TaggedError } from "./tagged-error.js";
|
||||||
|
|
||||||
|
describe("is-error", () => {
|
||||||
|
it("should determine if a value is an error", () => {
|
||||||
|
type DemoResult = Result<number, TaggedError<"DemoError">>;
|
||||||
|
|
||||||
|
//Ok should not be an error
|
||||||
|
const ok: DemoResult = 42;
|
||||||
|
expect(isError(ok)).toBe(false);
|
||||||
|
|
||||||
|
//Error should be an error
|
||||||
|
const error: DemoResult = new TaggedError("DemoError");
|
||||||
|
expect(isError(error)).toBe(true);
|
||||||
|
|
||||||
|
//After a check, typescript should be able to infer the type
|
||||||
|
if (isError(error)) {
|
||||||
|
expectTypeOf(error).toEqualTypeOf<TaggedError<"DemoError">>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,16 +0,0 @@
|
|||||||
import { describe, expect, expectTypeOf, test } from "@fabric/testing";
|
|
||||||
import { isError } from "./is-error.ts";
|
|
||||||
import { UnexpectedError } from "./unexpected-error.ts";
|
|
||||||
|
|
||||||
describe("is-error", () => {
|
|
||||||
test("Given a value that is an error, it should return true", () => {
|
|
||||||
const error = new UnexpectedError();
|
|
||||||
|
|
||||||
expect(isError(error)).toBe(true);
|
|
||||||
|
|
||||||
//After a check, typescript should be able to infer the type
|
|
||||||
if (isError(error)) {
|
|
||||||
expectTypeOf(error).toEqualTypeOf<UnexpectedError>();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedError } from "./tagged-error.ts";
|
import { TaggedError } from "./tagged-error.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if a value is an error.
|
* Indicates if a value is an error.
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "../variant/index.ts";
|
import { TaggedVariant, VariantTag } from "../variant/index.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TaggedError is a tagged variant with an error message.
|
* A TaggedError is a tagged variant with an error message.
|
||||||
*/
|
*/
|
||||||
export abstract class TaggedError<Tag extends string = string> extends Error
|
export abstract class TaggedError<Tag extends string = string>
|
||||||
implements TaggedVariant<Tag> {
|
extends Error
|
||||||
|
implements TaggedVariant<Tag>
|
||||||
|
{
|
||||||
readonly [VariantTag]: Tag;
|
readonly [VariantTag]: Tag;
|
||||||
|
|
||||||
constructor(tag: Tag, message?: string) {
|
constructor(tag: Tag, message?: string) {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { TaggedError } from "./tagged-error.ts";
|
import { TaggedError } from "./tagged-error.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `UnexpectedError` represents any type of unexpected error.
|
* `UnexpectedError` represents any type of unexpected error.
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
export * from "./array/index.ts";
|
export * from "./array/index.js";
|
||||||
export * from "./error/index.ts";
|
export * from "./error/index.js";
|
||||||
export * from "./record/index.ts";
|
export * from "./record/index.js";
|
||||||
export * from "./result/index.ts";
|
export * from "./result/index.js";
|
||||||
export * from "./run/index.ts";
|
export * from "./run/index.js";
|
||||||
export * from "./time/index.ts";
|
export * from "./time/index.js";
|
||||||
export * from "./types/index.ts";
|
export * from "./types/index.js";
|
||||||
export * from "./utils/index.ts";
|
export * from "./utils/index.js";
|
||||||
export * from "./variant/index.ts";
|
export * from "./variant/index.js";
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
export * from "./is-record-empty.ts";
|
export * from "./is-record-empty.js";
|
||||||
export * from "./is-record.ts";
|
export * from "./is-record.js";
|
||||||
|
|||||||
19
packages/fabric/core/src/record/is-record-empty.spec.ts
Normal file
19
packages/fabric/core/src/record/is-record-empty.spec.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { isRecordEmpty } from "./is-record-empty.js";
|
||||||
|
|
||||||
|
describe("Record - Is Record Empty", () => {
|
||||||
|
it("should return true for an empty record", () => {
|
||||||
|
const result = isRecordEmpty({});
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false for a non-empty record", () => {
|
||||||
|
const result = isRecordEmpty({ key: "value" });
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false for a record with multiple keys", () => {
|
||||||
|
const result = isRecordEmpty({ key1: "value1", key2: "value2" });
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,19 +0,0 @@
|
|||||||
import { describe, expect, test } from "@fabric/testing";
|
|
||||||
import { isRecordEmpty } from "./is-record-empty.ts";
|
|
||||||
|
|
||||||
describe("Record - Is Record Empty", () => {
|
|
||||||
test("Given an empty record, it should return true", () => {
|
|
||||||
const result = isRecordEmpty({});
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Given a record with a single key, it should return false", () => {
|
|
||||||
const result = isRecordEmpty({ key: "value" });
|
|
||||||
expect(result).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Given a record with multiple keys, it should return false", () => {
|
|
||||||
const result = isRecordEmpty({ key1: "value1", key2: "value2" });
|
|
||||||
expect(result).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,23 +1,23 @@
|
|||||||
import { describe, expect, test } from "@fabric/testing";
|
import { describe, expect, it } from "vitest";
|
||||||
import { isRecord } from "./is-record.ts";
|
import { isRecord } from "./is-record.js";
|
||||||
|
|
||||||
describe("isRecord", () => {
|
describe("isRecord", () => {
|
||||||
test("Given an empty object, it should return true", () => {
|
it("should return true for an object", () => {
|
||||||
const obj = { name: "John", age: 30 };
|
const obj = { name: "John", age: 30 };
|
||||||
expect(isRecord(obj)).toBe(true);
|
expect(isRecord(obj)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Given an array, it should return false", () => {
|
it("should return false for an array", () => {
|
||||||
const arr = [1, 2, 3];
|
const arr = [1, 2, 3];
|
||||||
expect(isRecord(arr)).toBe(false);
|
expect(isRecord(arr)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Given a number, it should return false", () => {
|
it("should return false for null", () => {
|
||||||
const value = null;
|
const value = null;
|
||||||
expect(isRecord(value)).toBe(false);
|
expect(isRecord(value)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Given a string, it should return false", () => {
|
it("should return false for a string", () => {
|
||||||
const value = "Hello";
|
const value = "Hello";
|
||||||
expect(isRecord(value)).toBe(false);
|
expect(isRecord(value)).toBe(false);
|
||||||
});
|
});
|
||||||
@ -1,8 +1,8 @@
|
|||||||
// deno-lint-ignore-file no-namespace no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type { TaggedError } from "../error/tagged-error.ts";
|
import { TaggedError } from "../error/tagged-error.js";
|
||||||
import { UnexpectedError } from "../error/unexpected-error.ts";
|
import { UnexpectedError } from "../error/unexpected-error.js";
|
||||||
import type { MaybePromise } from "../types/maybe-promise.ts";
|
import { MaybePromise } from "../types/maybe-promise.js";
|
||||||
import { Result } from "./result.ts";
|
import { Result } from "./result.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An AsyncResult represents the result of an asynchronous operation that can
|
* An AsyncResult represents the result of an asynchronous operation that can
|
||||||
@ -25,7 +25,9 @@ export namespace AsyncResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function from<T>(fn: () => MaybePromise<T>): AsyncResult<T, never> {
|
export async function from<T>(
|
||||||
|
fn: () => MaybePromise<T>,
|
||||||
|
): AsyncResult<T, never> {
|
||||||
return tryFrom(fn, (error) => new UnexpectedError(error) as never);
|
return tryFrom(fn, (error) => new UnexpectedError(error) as never);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
export * from "./async-result.ts";
|
export * from "./async-result.js";
|
||||||
export * from "./result.ts";
|
export * from "./result.js";
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { describe, expect, expectTypeOf, fn, test } from "@fabric/testing";
|
import { describe, expect, expectTypeOf, it, vitest } from "vitest";
|
||||||
import { UnexpectedError } from "../error/unexpected-error.ts";
|
import { UnexpectedError } from "../error/unexpected-error.js";
|
||||||
import { Result } from "./result.ts";
|
import { Result } from "./result.js";
|
||||||
|
|
||||||
describe("Result", () => {
|
describe("Result", () => {
|
||||||
describe("isOk", () => {
|
describe("isOk", () => {
|
||||||
test("should return true if the result is ok", () => {
|
it("should return true if the result is ok", () => {
|
||||||
const result = Result.succeedWith(1) as Result<number, UnexpectedError>;
|
const result = Result.succeedWith(1) as Result<number, UnexpectedError>;
|
||||||
|
|
||||||
expect(result.isOk()).toBe(true);
|
expect(result.isOk()).toBe(true);
|
||||||
@ -18,7 +18,7 @@ describe("Result", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("isError", () => {
|
describe("isError", () => {
|
||||||
test("should return true if the result is an error", () => {
|
it("should return true if the result is an error", () => {
|
||||||
const result = Result.failWith(new UnexpectedError()) as Result<
|
const result = Result.failWith(new UnexpectedError()) as Result<
|
||||||
number,
|
number,
|
||||||
UnexpectedError
|
UnexpectedError
|
||||||
@ -35,7 +35,7 @@ describe("Result", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Map", () => {
|
describe("Map", () => {
|
||||||
test("should return the result of the last function", () => {
|
it("should return the result of the last function", () => {
|
||||||
const x = 0;
|
const x = 0;
|
||||||
|
|
||||||
const result = Result.succeedWith(x + 1).map((x) => x * 2);
|
const result = Result.succeedWith(x + 1).map((x) => x * 2);
|
||||||
@ -45,13 +45,13 @@ describe("Result", () => {
|
|||||||
expectTypeOf(result).toEqualTypeOf<Result<number, never>>();
|
expectTypeOf(result).toEqualTypeOf<Result<number, never>>();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not execute the function if the result is an error", () => {
|
it("should not execute the function if the result is an error", () => {
|
||||||
const mock = fn() as () => number;
|
const fn = vitest.fn();
|
||||||
const result = Result.failWith(new UnexpectedError()).map(mock);
|
const result = Result.failWith(new UnexpectedError()).map(fn);
|
||||||
|
|
||||||
expect(result.isError()).toBe(true);
|
expect(result.isError()).toBe(true);
|
||||||
|
|
||||||
expect(mock).not.toHaveBeenCalled();
|
expect(fn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1,7 +1,7 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import { isError } from "../error/is-error.ts";
|
import { isError } from "../error/is-error.js";
|
||||||
import type { TaggedError } from "../error/tagged-error.ts";
|
import { TaggedError } from "../error/tagged-error.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Result represents the outcome of an operation
|
* A Result represents the outcome of an operation
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./run.ts";
|
export * from "./run.js";
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
// deno-lint-ignore-file require-await
|
import { describe, expect, it } from "vitest";
|
||||||
import { describe, expect, test } from "@fabric/testing";
|
import { UnexpectedError } from "../error/unexpected-error.js";
|
||||||
import { UnexpectedError } from "../error/unexpected-error.ts";
|
import { Result } from "../result/result.js";
|
||||||
import { Result } from "../result/result.ts";
|
import { Run } from "./run.js";
|
||||||
import { Run } from "./run.ts";
|
|
||||||
|
|
||||||
describe("Run", () => {
|
describe("Run", () => {
|
||||||
describe("In Sequence", () => {
|
describe("In Sequence", () => {
|
||||||
test("should pipe the results of multiple async functions", async () => {
|
it("should pipe the results of multiple async functions", async () => {
|
||||||
const result = await Run.seq(
|
const result = await Run.seq(
|
||||||
async () => Result.succeedWith(1),
|
async () => Result.succeedWith(1),
|
||||||
async (x) => Result.succeedWith(x + 1),
|
async (x) => Result.succeedWith(x + 1),
|
||||||
@ -16,7 +15,7 @@ describe("Run", () => {
|
|||||||
expect(result.unwrapOrThrow()).toEqual(4);
|
expect(result.unwrapOrThrow()).toEqual(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return the first error if one of the functions fails", async () => {
|
it("should return the first error if one of the functions fails", async () => {
|
||||||
const result = await Run.seq(
|
const result = await Run.seq(
|
||||||
async () => Result.succeedWith(1),
|
async () => Result.succeedWith(1),
|
||||||
async () => Result.failWith(new UnexpectedError()),
|
async () => Result.failWith(new UnexpectedError()),
|
||||||
@ -1,26 +1,21 @@
|
|||||||
// deno-lint-ignore-file no-namespace no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type { TaggedError } from "../error/tagged-error.ts";
|
import { TaggedError } from "../error/tagged-error.js";
|
||||||
import type { AsyncResult } from "../result/async-result.ts";
|
import { AsyncResult } from "../result/async-result.js";
|
||||||
|
|
||||||
export namespace Run {
|
export namespace Run {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export async function seq<
|
export async function seq<
|
||||||
T1,
|
T1, TE1 extends TaggedError,
|
||||||
TE1 extends TaggedError,
|
T2, TE2 extends TaggedError,
|
||||||
T2,
|
|
||||||
TE2 extends TaggedError,
|
|
||||||
>(
|
>(
|
||||||
fn1: () => AsyncResult<T1, TE1>,
|
fn1: () => AsyncResult<T1, TE1>,
|
||||||
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
||||||
): AsyncResult<T2, TE1 | TE2>;
|
): AsyncResult<T2, TE1 | TE2>;
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export async function seq<
|
export async function seq<
|
||||||
T1,
|
T1, TE1 extends TaggedError,
|
||||||
TE1 extends TaggedError,
|
T2, TE2 extends TaggedError,
|
||||||
T2,
|
T3, TE3 extends TaggedError,
|
||||||
TE2 extends TaggedError,
|
|
||||||
T3,
|
|
||||||
TE3 extends TaggedError,
|
|
||||||
>(
|
>(
|
||||||
fn1: () => AsyncResult<T1, TE1>,
|
fn1: () => AsyncResult<T1, TE1>,
|
||||||
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
||||||
@ -28,14 +23,10 @@ export namespace Run {
|
|||||||
): AsyncResult<T3, TE1 | TE2 | TE3>;
|
): AsyncResult<T3, TE1 | TE2 | TE3>;
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export async function seq<
|
export async function seq<
|
||||||
T1,
|
T1, TE1 extends TaggedError,
|
||||||
TE1 extends TaggedError,
|
T2, TE2 extends TaggedError,
|
||||||
T2,
|
T3, TE3 extends TaggedError,
|
||||||
TE2 extends TaggedError,
|
T4, TE4 extends TaggedError,
|
||||||
T3,
|
|
||||||
TE3 extends TaggedError,
|
|
||||||
T4,
|
|
||||||
TE4 extends TaggedError,
|
|
||||||
>(
|
>(
|
||||||
fn1: () => AsyncResult<T1, TE1>,
|
fn1: () => AsyncResult<T1, TE1>,
|
||||||
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
||||||
@ -45,14 +36,14 @@ export namespace Run {
|
|||||||
export async function seq(
|
export async function seq(
|
||||||
...fns: ((...args: any[]) => AsyncResult<any, any>)[]
|
...fns: ((...args: any[]) => AsyncResult<any, any>)[]
|
||||||
): AsyncResult<any, any> {
|
): AsyncResult<any, any> {
|
||||||
let result = await fns[0]!();
|
let result = await fns[0]();
|
||||||
|
|
||||||
for (let i = 1; i < fns.length; i++) {
|
for (let i = 1; i < fns.length; i++) {
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = await fns[i]!(result.unwrapOrThrow());
|
result = await fns[i](result.unwrapOrThrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -60,22 +51,17 @@ export namespace Run {
|
|||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export async function seqUNSAFE<
|
export async function seqUNSAFE<
|
||||||
T1,
|
T1, TE1 extends TaggedError,
|
||||||
TE1 extends TaggedError,
|
T2, TE2 extends TaggedError,
|
||||||
T2,
|
|
||||||
TE2 extends TaggedError,
|
|
||||||
>(
|
>(
|
||||||
fn1: () => AsyncResult<T1, TE1>,
|
fn1: () => AsyncResult<T1, TE1>,
|
||||||
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
||||||
): Promise<T2>;
|
): Promise<T2>;
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export async function seqUNSAFE<
|
export async function seqUNSAFE<
|
||||||
T1,
|
T1,TE1 extends TaggedError,
|
||||||
TE1 extends TaggedError,
|
T2,TE2 extends TaggedError,
|
||||||
T2,
|
T3,TE3 extends TaggedError,
|
||||||
TE2 extends TaggedError,
|
|
||||||
T3,
|
|
||||||
TE3 extends TaggedError,
|
|
||||||
>(
|
>(
|
||||||
fn1: () => AsyncResult<T1, TE1>,
|
fn1: () => AsyncResult<T1, TE1>,
|
||||||
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
fn2: (value: T1) => AsyncResult<T2, TE2>,
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
export * from "./posix-date.ts";
|
export * from "./posix-date.js";
|
||||||
export * from "./time-constants.ts";
|
export * from "./time-constants.js";
|
||||||
|
export * from "./timeout.js";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { isRecord } from "../record/is-record.ts";
|
import { isRecord } from "../record/is-record.js";
|
||||||
import type { TaggedVariant } from "../variant/variant.ts";
|
import { TaggedVariant } from "../variant/variant.js";
|
||||||
|
|
||||||
export class PosixDate {
|
export class PosixDate {
|
||||||
constructor(public readonly timestamp: number = Date.now()) {}
|
constructor(public readonly timestamp: number = Date.now()) {}
|
||||||
@ -22,9 +22,8 @@ export class PosixDate {
|
|||||||
"timestamp" in value &&
|
"timestamp" in value &&
|
||||||
value["type"] === "posix-date" &&
|
value["type"] === "posix-date" &&
|
||||||
typeof value["timestamp"] === "number"
|
typeof value["timestamp"] === "number"
|
||||||
) {
|
)
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
44
packages/fabric/core/src/time/timeout.spec.ts
Normal file
44
packages/fabric/core/src/time/timeout.spec.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
import { timeout } from "./timeout.js";
|
||||||
|
|
||||||
|
const HEAVY_TESTS =
|
||||||
|
process.env.HEAVY_TESTS === "true" || process.env.RUN_ALL_TESTS === "true";
|
||||||
|
|
||||||
|
describe("timeout", () => {
|
||||||
|
test.runIf(HEAVY_TESTS)(
|
||||||
|
"timeout never triggers *before* the input time",
|
||||||
|
async () => {
|
||||||
|
const count = 10000;
|
||||||
|
const maxTimeInMs = 1000;
|
||||||
|
|
||||||
|
const result = await Promise.all(
|
||||||
|
new Array(count).fill(0).map(async (e, i) => {
|
||||||
|
const start = Date.now();
|
||||||
|
const ms = i % maxTimeInMs;
|
||||||
|
await timeout(ms);
|
||||||
|
const end = Date.now();
|
||||||
|
return end - start;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
result
|
||||||
|
.map((t, i) => {
|
||||||
|
return [t, i % maxTimeInMs]; //Actual time and expected time
|
||||||
|
})
|
||||||
|
.filter((e) => {
|
||||||
|
return e[0] < e[1]; //Actual time is less than the expected time
|
||||||
|
}),
|
||||||
|
).toEqual([]);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test("using timeout we can define a timeout in milliseconds", async () => {
|
||||||
|
const start = Date.now();
|
||||||
|
await timeout(100);
|
||||||
|
const end = Date.now();
|
||||||
|
|
||||||
|
const time = end - start;
|
||||||
|
|
||||||
|
expect(time).toBeGreaterThanOrEqual(100);
|
||||||
|
});
|
||||||
|
});
|
||||||
14
packages/fabric/core/src/time/timeout.ts
Normal file
14
packages/fabric/core/src/time/timeout.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export function timeout(ms: number) {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
const start = Date.now();
|
||||||
|
setTimeout(() => {
|
||||||
|
const end = Date.now();
|
||||||
|
const remaining = ms - (end - start);
|
||||||
|
if (remaining > 0) {
|
||||||
|
timeout(remaining).then(resolve);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
|
||||||
/**
|
/**
|
||||||
* A function that takes an argument of type `T` and returns a value of type `R`.
|
* A function that takes an argument of type `T` and returns a value of type `R`.
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export type Fn<T = any, R = any> = (arg: T) => R;
|
export type Fn<T = any, R = any> = (arg: T) => R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export * from "./enum.ts";
|
export * from "./enum.js";
|
||||||
export * from "./fn.ts";
|
export * from "./fn.js";
|
||||||
export * from "./keyof.ts";
|
export * from "./keyof.js";
|
||||||
export * from "./maybe-promise.ts";
|
export * from "./maybe-promise.js";
|
||||||
export * from "./optional.ts";
|
export * from "./optional.js";
|
||||||
export * from "./record.ts";
|
export * from "./record.js";
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { UnexpectedError } from "../error/unexpected-error.ts";
|
import { UnexpectedError } from "../error/unexpected-error.js";
|
||||||
|
|
||||||
export function ensureValue<T>(value?: T): T {
|
export function ensureValue<T>(value?: T): T {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
throw new UnexpectedError("Value is nullish.");
|
throw new UnexpectedError("Value is undefined");
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./ensure-value.ts";
|
export * from "./ensure-value.js";
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
export * from "./match.ts";
|
export * from "./match.js";
|
||||||
export * from "./variant.ts";
|
export * from "./variant.js";
|
||||||
|
|||||||
36
packages/fabric/core/src/variant/match.spec.ts
Normal file
36
packages/fabric/core/src/variant/match.spec.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { match } from "./match.js";
|
||||||
|
import { TaggedVariant, VariantTag } from "./variant.js";
|
||||||
|
|
||||||
|
interface V1 extends TaggedVariant<"V1"> {
|
||||||
|
a: number;
|
||||||
|
}
|
||||||
|
interface V2 extends TaggedVariant<"V2"> {
|
||||||
|
b: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Variant = V1 | V2;
|
||||||
|
|
||||||
|
describe("Pattern matching", () => {
|
||||||
|
it("Should match a pattern", () => {
|
||||||
|
const v = { [VariantTag]: "V1", a: 42 } as Variant;
|
||||||
|
|
||||||
|
const result = match(v).case({
|
||||||
|
V1: (v) => v.a,
|
||||||
|
V2: (v) => v.b,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBe(42);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should alert that a pattern is not exhaustive", () => {
|
||||||
|
const v = { [VariantTag]: "V1", a: 42 } as Variant;
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
// @ts-expect-error Testing non-exhaustive pattern matching
|
||||||
|
match(v).case({
|
||||||
|
V2: (v) => v.b,
|
||||||
|
}),
|
||||||
|
).toThrowError("Non-exhaustive pattern match");
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,35 +0,0 @@
|
|||||||
import { expect } from "jsr:@std/expect";
|
|
||||||
import { match } from "./match.ts";
|
|
||||||
import { type TaggedVariant, VariantTag } from "./variant.ts";
|
|
||||||
|
|
||||||
interface V1 extends TaggedVariant<"V1"> {
|
|
||||||
a: number;
|
|
||||||
}
|
|
||||||
interface V2 extends TaggedVariant<"V2"> {
|
|
||||||
b: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type Variant = V1 | V2;
|
|
||||||
|
|
||||||
const v = { [VariantTag]: "V1", a: 42 } as Variant;
|
|
||||||
|
|
||||||
Deno.test("match().case() calls the correct function", () => {
|
|
||||||
const result = match(v).case({
|
|
||||||
V1: (v) => v.a,
|
|
||||||
V2: (v) => v.b,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBe(42);
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test(
|
|
||||||
"match().case() throws an error for non-exhaustive pattern matching",
|
|
||||||
() => {
|
|
||||||
expect(() =>
|
|
||||||
// @ts-expect-error Testing non-exhaustive pattern matching
|
|
||||||
match(v).case({
|
|
||||||
V2: (v) => v.b,
|
|
||||||
})
|
|
||||||
).toThrow("Non-exhaustive pattern match");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@ -1,9 +1,5 @@
|
|||||||
import type { Fn } from "../types/fn.ts";
|
import { Fn } from "../types/fn.js";
|
||||||
import {
|
import { TaggedVariant, VariantFromTag, VariantTag } from "./variant.js";
|
||||||
type TaggedVariant,
|
|
||||||
type VariantFromTag,
|
|
||||||
VariantTag,
|
|
||||||
} from "./variant.ts";
|
|
||||||
|
|
||||||
export type VariantMatcher<TVariant extends TaggedVariant<string>, T> = {
|
export type VariantMatcher<TVariant extends TaggedVariant<string>, T> = {
|
||||||
[K in TVariant[VariantTag]]: Fn<VariantFromTag<TVariant, K>, T>;
|
[K in TVariant[VariantTag]]: Fn<VariantFromTag<TVariant, K>, T>;
|
||||||
|
|||||||
41
packages/fabric/core/src/variant/variant.spec.ts
Normal file
41
packages/fabric/core/src/variant/variant.spec.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||||
|
import { TaggedVariant, Variant, VariantTag } from "./variant.js";
|
||||||
|
|
||||||
|
interface SuccessVariant extends TaggedVariant<"success"> {
|
||||||
|
[VariantTag]: "success";
|
||||||
|
data: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ErrorVariant extends TaggedVariant<"error"> {
|
||||||
|
[VariantTag]: "error";
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Variant", () => {
|
||||||
|
describe("isVariant", () => {
|
||||||
|
const successVariant = {
|
||||||
|
[VariantTag]: "success",
|
||||||
|
data: "Operation successful",
|
||||||
|
} as SuccessVariant | ErrorVariant;
|
||||||
|
|
||||||
|
const errorVariant = {
|
||||||
|
[VariantTag]: "error",
|
||||||
|
message: "Operation failed",
|
||||||
|
} as SuccessVariant | ErrorVariant;
|
||||||
|
|
||||||
|
it("should return true for a matching tag and correctly infer it", () => {
|
||||||
|
if (Variant.is(successVariant, "success")) {
|
||||||
|
expectTypeOf(successVariant).toEqualTypeOf<SuccessVariant>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Variant.is(errorVariant, "error")) {
|
||||||
|
expectTypeOf(errorVariant).toEqualTypeOf<ErrorVariant>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false for a non-matching tag", () => {
|
||||||
|
expect(Variant.is(successVariant, "error")).toBe(false);
|
||||||
|
expect(Variant.is(errorVariant, "success")).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,32 +0,0 @@
|
|||||||
import { expect } from "jsr:@std/expect";
|
|
||||||
import { type TaggedVariant, Variant, VariantTag } from "./variant.ts";
|
|
||||||
|
|
||||||
interface SuccessVariant extends TaggedVariant<"success"> {
|
|
||||||
[VariantTag]: "success";
|
|
||||||
data: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ErrorVariant extends TaggedVariant<"error"> {
|
|
||||||
[VariantTag]: "error";
|
|
||||||
message: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const successVariant = {
|
|
||||||
[VariantTag]: "success",
|
|
||||||
data: "Operation successful",
|
|
||||||
} as SuccessVariant | ErrorVariant;
|
|
||||||
|
|
||||||
const errorVariant = {
|
|
||||||
[VariantTag]: "error",
|
|
||||||
message: "Operation failed",
|
|
||||||
} as SuccessVariant | ErrorVariant;
|
|
||||||
|
|
||||||
Deno.test("is() should return true for a matching tag", () => {
|
|
||||||
expect(Variant.is(successVariant, "success")).toBe(true);
|
|
||||||
expect(Variant.is(errorVariant, "error")).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test("is() should return false for a non-matching tag", () => {
|
|
||||||
expect(Variant.is(successVariant, "error")).toBe(false);
|
|
||||||
expect(Variant.is(errorVariant, "success")).toBe(false);
|
|
||||||
});
|
|
||||||
15
packages/fabric/core/tsconfig.build.json
Normal file
15
packages/fabric/core/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/core/tsconfig.json
Normal file
4
packages/fabric/core/tsconfig.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../../tsconfig.json",
|
||||||
|
"exclude": ["dist", "node_modules"]
|
||||||
|
}
|
||||||
10
packages/fabric/core/vitest.config.ts
Normal file
10
packages/fabric/core/vitest.config.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
coverage: {
|
||||||
|
exclude: ["dist/**", "vitest.config.ts", "**/index.ts", "**/*.spec.ts"],
|
||||||
|
},
|
||||||
|
passWithNoTests: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@fabric/domain",
|
|
||||||
"exports": {
|
|
||||||
".": "./src/index.ts",
|
|
||||||
"./mocks": "./src/mocks.ts"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
30
packages/fabric/domain/package.json
Normal file
30
packages/fabric/domain/package.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"name": "@fabric/domain",
|
||||||
|
"private": true,
|
||||||
|
"sideEffects": false,
|
||||||
|
"type": "module",
|
||||||
|
"main": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": "./dist/index.js",
|
||||||
|
"./mocks": "./dist/mocks.js"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"packageManager": "yarn@4.1.1",
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitest/coverage-v8": "^2.1.2",
|
||||||
|
"typescript": "^5.6.3",
|
||||||
|
"vitest": "^2.1.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fabric/core": "workspace:^",
|
||||||
|
"decimal.js": "^10.4.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "vitest",
|
||||||
|
"coverage": "vitest run --coverage",
|
||||||
|
"build": "tsc -p tsconfig.build.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import { TaggedError } from "@fabric/core";
|
import { TaggedError } from "@fabric/core";
|
||||||
|
|
||||||
export class CircularDependencyError
|
export class CircularDependencyError extends TaggedError<"CircularDependencyError"> {
|
||||||
extends TaggedError<"CircularDependencyError"> {
|
|
||||||
context: { key: string; dep: string };
|
context: { key: string; dep: string };
|
||||||
constructor(key: string, dep: string) {
|
constructor(key: string, dep: string) {
|
||||||
super("CircularDependencyError");
|
super("CircularDependencyError");
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
export * from "./circular-dependency-error.ts";
|
export * from "./circular-dependency-error.js";
|
||||||
export * from "./query-error.ts";
|
export * from "./query-error.js";
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { TaggedError } from "@fabric/core";
|
import { TaggedError } from "@fabric/core";
|
||||||
|
|
||||||
export class StoreQueryError extends TaggedError<"StoreQueryError"> {
|
export class StoreQueryError extends TaggedError<"StoreQueryError"> {
|
||||||
constructor(message: string) {
|
constructor(public message: string) {
|
||||||
super("StoreQueryError", message);
|
super("StoreQueryError", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
import type {
|
import {
|
||||||
AsyncResult,
|
AsyncResult,
|
||||||
MaybePromise,
|
MaybePromise,
|
||||||
PosixDate,
|
PosixDate,
|
||||||
VariantFromTag,
|
VariantFromTag,
|
||||||
VariantTag,
|
VariantTag,
|
||||||
} from "@fabric/core";
|
} from "@fabric/core";
|
||||||
import type { StoreQueryError } from "../errors/query-error.ts";
|
import { StoreQueryError } from "../errors/query-error.js";
|
||||||
import type { UUID } from "../types/uuid.ts";
|
import { UUID } from "../types/uuid.js";
|
||||||
import type { Event } from "./event.ts";
|
import { Event } from "./event.js";
|
||||||
import type { StoredEvent } from "./stored-event.ts";
|
import { StoredEvent } from "./stored-event.js";
|
||||||
|
|
||||||
export interface EventStore<TEvents extends Event> {
|
export interface EventStore<TEvents extends Event> {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type { VariantTag } from "@fabric/core";
|
import { VariantTag } from "@fabric/core";
|
||||||
import type { UUID } from "../types/uuid.ts";
|
import { UUID } from "../types/uuid.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An event is a tagged variant with a payload and a timestamp.
|
* An event is a tagged variant with a payload and a timestamp.
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export * from "./event-store.ts";
|
export * from "./event-store.js";
|
||||||
export * from "./event.ts";
|
export * from "./event.js";
|
||||||
export * from "./stored-event.ts";
|
export * from "./stored-event.js";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { PosixDate } from "@fabric/core";
|
import { PosixDate } from "@fabric/core";
|
||||||
import type { Event } from "./event.ts";
|
import { Event } from "./event.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { MimeType } from "./mime-type.ts";
|
import { MimeType } from "./mime-type.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file. Its the base type for all files.
|
* Represents a file. Its the base type for all files.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { ImageMimeType } from "./mime-type.ts";
|
import { ImageMimeType } from "./mime-type.js";
|
||||||
import type { StoredFile } from "./stored-file.ts";
|
import { StoredFile } from "./stored-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an image file.
|
* Represents an image file.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { Base64String } from "../types/base-64.ts";
|
import { Base64String } from "../types/base-64.js";
|
||||||
import type { BaseFile } from "./base-file.ts";
|
import { BaseFile } from "./base-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file with its contents in memory.
|
* Represents a file with its contents in memory.
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
export * from "./base-file.ts";
|
export * from "./base-file.js";
|
||||||
export * from "./bytes.ts";
|
export * from "./bytes.js";
|
||||||
export * from "./image-file.ts";
|
export * from "./image-file.js";
|
||||||
export * from "./in-memory-file.ts";
|
export * from "./in-memory-file.js";
|
||||||
export * from "./invalid-file-type-error.ts";
|
export * from "./invalid-file-type-error.js";
|
||||||
export * from "./is-in-memory-file.ts";
|
export * from "./is-in-memory-file.js";
|
||||||
export * from "./is-mime-type.ts";
|
export * from "./is-mime-type.js";
|
||||||
export * from "./media-file.ts";
|
export * from "./media-file.js";
|
||||||
export * from "./mime-type.ts";
|
export * from "./mime-type.js";
|
||||||
export * from "./stored-file.ts";
|
export * from "./stored-file.js";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { isRecord } from "@fabric/core";
|
import { isRecord } from "@fabric/core";
|
||||||
import type { InMemoryFile } from "./in-memory-file.ts";
|
import { InMemoryFile } from "./in-memory-file.js";
|
||||||
|
|
||||||
export function isInMemoryFile(value: unknown): value is InMemoryFile {
|
export function isInMemoryFile(value: unknown): value is InMemoryFile {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { describe, expect, expectTypeOf, test } from "@fabric/testing";
|
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||||
import { isMimeType } from "./is-mime-type.ts";
|
import { isMimeType } from "./is-mime-type.js";
|
||||||
|
|
||||||
describe("isMimeType", () => {
|
describe("isMimeType", () => {
|
||||||
test("should return true if the file type is the same as the mime type", () => {
|
it("should return true if the file type is the same as the mime type", () => {
|
||||||
const fileType = "image/png" as string;
|
const fileType = "image/png" as string;
|
||||||
const result = isMimeType("image/.*", fileType);
|
const result = isMimeType("image/.*", fileType);
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
@ -11,7 +11,7 @@ describe("isMimeType", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return false if the file type is not the same as the mime type", () => {
|
it("should return false if the file type is not the same as the mime type", () => {
|
||||||
const fileType = "image/png" as string;
|
const fileType = "image/png" as string;
|
||||||
expect(isMimeType("image/jpeg", fileType)).toBe(false);
|
expect(isMimeType("image/jpeg", fileType)).toBe(false);
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import type { MimeType } from "./mime-type.ts";
|
import { MimeType } from "./mime-type.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the actual file type is the same as the expected mime type.
|
* Checks if the actual file type is the same as the expected mime type.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { StoredFile } from "./stored-file.ts";
|
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 type { Entity } from "../types/entity.ts";
|
import { Entity } from "../types/entity.js";
|
||||||
import type { BaseFile } from "./base-file.ts";
|
import { BaseFile } from "./base-file.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file as managed by the domain.
|
* Represents a file as managed by the domain.
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
export * from "./errors/index.ts";
|
export * from "./errors/index.js";
|
||||||
export * from "./events/index.ts";
|
export * from "./events/index.js";
|
||||||
export * from "./files/index.ts";
|
export * from "./files/index.js";
|
||||||
export * from "./models/index.ts";
|
export * from "./models/index.js";
|
||||||
export * from "./security/index.ts";
|
export * from "./security/index.js";
|
||||||
export * from "./services/index.ts";
|
export * from "./services/index.js";
|
||||||
export * from "./types/index.ts";
|
export * from "./types/index.js";
|
||||||
export * from "./use-case/index.ts";
|
export * from "./use-case/index.js";
|
||||||
export * from "./utils/index.ts";
|
export * from "./utils/index.js";
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./services/mocks.ts";
|
export * from "./services/mocks.js";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface DecimalFieldOptions extends BaseField {
|
export interface DecimalFieldOptions extends BaseField {
|
||||||
isUnsigned?: boolean;
|
isUnsigned?: boolean;
|
||||||
@ -8,7 +8,8 @@ export interface DecimalFieldOptions extends BaseField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DecimalField
|
export interface DecimalField
|
||||||
extends TaggedVariant<"DecimalField">, DecimalFieldOptions {}
|
extends TaggedVariant<"DecimalField">,
|
||||||
|
DecimalFieldOptions {}
|
||||||
|
|
||||||
export function createDecimalField<T extends DecimalFieldOptions>(
|
export function createDecimalField<T extends DecimalFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars
|
||||||
export interface EmbeddedFieldOptions<T = any> extends BaseField {}
|
export interface EmbeddedFieldOptions<T = any> extends BaseField {}
|
||||||
|
|
||||||
export interface EmbeddedField<T = any>
|
export interface EmbeddedField<T = any>
|
||||||
extends TaggedVariant<"EmbeddedField">, EmbeddedFieldOptions<T> {}
|
extends TaggedVariant<"EmbeddedField">,
|
||||||
|
EmbeddedFieldOptions<T> {}
|
||||||
|
|
||||||
export function createEmbeddedField<
|
export function createEmbeddedField<
|
||||||
K = any,
|
K = any,
|
||||||
|
|||||||
@ -1,37 +1,36 @@
|
|||||||
import type { PosixDate } from "@fabric/core";
|
import { PosixDate } from "@fabric/core";
|
||||||
import type Decimal from "jsr:@quentinadam/decimal";
|
import { Decimal } from "decimal.js";
|
||||||
import type { UUID } from "../../types/uuid.ts";
|
import { UUID } from "../../types/uuid.js";
|
||||||
import type { DecimalField } from "./decimal.ts";
|
import { DecimalField } from "./decimal.js";
|
||||||
import type { EmbeddedField } from "./embedded.ts";
|
import { EmbeddedField } from "./embedded.js";
|
||||||
import type { FloatField } from "./float.ts";
|
import { FloatField } from "./float.js";
|
||||||
import type { IntegerField } from "./integer.ts";
|
import { IntegerField } from "./integer.js";
|
||||||
import type { ReferenceField } from "./reference-field.ts";
|
import { ReferenceField } from "./reference-field.js";
|
||||||
import type { StringField } from "./string-field.ts";
|
import { StringField } from "./string-field.js";
|
||||||
import type { TimestampField } from "./timestamp.ts";
|
import { TimestampField } from "./timestamp.js";
|
||||||
import type { UUIDField } from "./uuid-field.ts";
|
import { UUIDField } from "./uuid-field.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a field definition to its corresponding TypeScript type.
|
* Converts a field definition to its corresponding TypeScript type.
|
||||||
*/
|
*/
|
||||||
//prettier-ignore
|
//prettier-ignore
|
||||||
export type FieldToType<TField> = TField extends StringField
|
export type FieldToType<TField> =
|
||||||
? MaybeOptional<TField, string>
|
TField extends StringField ? MaybeOptional<TField, string>
|
||||||
: TField extends UUIDField ? MaybeOptional<TField, UUID>
|
: TField extends UUIDField ? MaybeOptional<TField, UUID>
|
||||||
: TField extends IntegerField ? IntegerFieldToType<TField>
|
: TField extends IntegerField ? IntegerFieldToType<TField>
|
||||||
: TField extends ReferenceField ? MaybeOptional<TField, UUID>
|
: TField extends ReferenceField ? MaybeOptional<TField, UUID>
|
||||||
: TField extends DecimalField ? MaybeOptional<TField, Decimal>
|
: TField extends DecimalField ? MaybeOptional<TField, Decimal>
|
||||||
: TField extends FloatField ? MaybeOptional<TField, number>
|
: TField extends FloatField ? MaybeOptional<TField, number>
|
||||||
: TField extends TimestampField ? MaybeOptional<TField, PosixDate>
|
: TField extends TimestampField ? MaybeOptional<TField, PosixDate>
|
||||||
: TField extends EmbeddedField<infer TSubModel>
|
: TField extends EmbeddedField<infer TSubModel> ? MaybeOptional<TField, TSubModel>
|
||||||
? MaybeOptional<TField, TSubModel>
|
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
//prettier-ignore
|
//prettier-ignore
|
||||||
type IntegerFieldToType<TField extends IntegerField> =
|
type IntegerFieldToType<TField extends IntegerField> = TField["hasArbitraryPrecision"] extends true
|
||||||
TField["hasArbitraryPrecision"] extends true ? MaybeOptional<TField, bigint>
|
? MaybeOptional<TField, bigint>
|
||||||
: TField["hasArbitraryPrecision"] extends false
|
: TField["hasArbitraryPrecision"] extends false
|
||||||
? MaybeOptional<TField, number>
|
? MaybeOptional<TField, number>
|
||||||
: MaybeOptional<TField, number | bigint>;
|
: MaybeOptional<TField, number | bigint>;
|
||||||
|
|
||||||
type MaybeOptional<TField, TType> = TField extends { isOptional: true }
|
type MaybeOptional<TField, TType> = TField extends { isOptional: true }
|
||||||
? TType | null
|
? TType | null
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||||
export interface FloatFieldOptions extends BaseField {}
|
export interface FloatFieldOptions extends BaseField {}
|
||||||
|
|
||||||
export interface FloatField
|
export interface FloatField
|
||||||
extends TaggedVariant<"FloatField">, FloatFieldOptions {}
|
extends TaggedVariant<"FloatField">,
|
||||||
|
FloatFieldOptions {}
|
||||||
|
|
||||||
export function createFloatField<T extends FloatFieldOptions>(
|
export function createFloatField<T extends FloatFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
import { createDecimalField, type DecimalField } from "./decimal.ts";
|
import { createDecimalField, DecimalField } from "./decimal.js";
|
||||||
import { createEmbeddedField, type EmbeddedField } from "./embedded.ts";
|
import { createEmbeddedField, EmbeddedField } from "./embedded.js";
|
||||||
import { createFloatField, type FloatField } from "./float.ts";
|
import { createFloatField, FloatField } from "./float.js";
|
||||||
import { createIntegerField, type IntegerField } from "./integer.ts";
|
import { createIntegerField, IntegerField } from "./integer.js";
|
||||||
import {
|
import { createReferenceField, ReferenceField } from "./reference-field.js";
|
||||||
createReferenceField,
|
import { createStringField, StringField } from "./string-field.js";
|
||||||
type ReferenceField,
|
import { createTimestampField, TimestampField } from "./timestamp.js";
|
||||||
} from "./reference-field.ts";
|
import { createUUIDField, UUIDField } from "./uuid-field.js";
|
||||||
import { createStringField, type StringField } from "./string-field.ts";
|
export * from "./base-field.js";
|
||||||
import { createTimestampField, type TimestampField } from "./timestamp.ts";
|
export * from "./field-to-type.js";
|
||||||
import { createUUIDField, type UUIDField } from "./uuid-field.ts";
|
export * from "./reference-field.js";
|
||||||
export * from "./base-field.ts";
|
|
||||||
export * from "./field-to-type.ts";
|
|
||||||
export * from "./reference-field.ts";
|
|
||||||
|
|
||||||
export type FieldDefinition =
|
export type FieldDefinition =
|
||||||
| StringField
|
| StringField
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface IntegerFieldOptions extends BaseField {
|
export interface IntegerFieldOptions extends BaseField {
|
||||||
isUnsigned?: boolean;
|
isUnsigned?: boolean;
|
||||||
@ -7,7 +7,8 @@ export interface IntegerFieldOptions extends BaseField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IntegerField
|
export interface IntegerField
|
||||||
extends TaggedVariant<"IntegerField">, IntegerFieldOptions {}
|
extends TaggedVariant<"IntegerField">,
|
||||||
|
IntegerFieldOptions {}
|
||||||
|
|
||||||
export function createIntegerField<T extends IntegerFieldOptions>(
|
export function createIntegerField<T extends IntegerFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { isError } from "@fabric/core";
|
import { isError } from "@fabric/core";
|
||||||
import { describe, expect, test } from "@fabric/testing";
|
import { describe, expect, it } from "vitest";
|
||||||
import { defineModel } from "../model.ts";
|
import { defineModel } from "../model.js";
|
||||||
import { Field } from "./index.ts";
|
import { Field } from "./index.js";
|
||||||
import {
|
import {
|
||||||
InvalidReferenceFieldError,
|
InvalidReferenceFieldError,
|
||||||
validateReferenceField,
|
validateReferenceField,
|
||||||
} from "./reference-field.ts";
|
} from "./reference-field.js";
|
||||||
|
|
||||||
describe("Validate Reference Field", () => {
|
describe("Validate Reference Field", () => {
|
||||||
const schema = {
|
const schema = {
|
||||||
@ -20,7 +20,7 @@ describe("Validate Reference Field", () => {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
test("should return an error when the target model is not in the schema", () => {
|
it("should return an error when the target model is not in the schema", () => {
|
||||||
const result = validateReferenceField(
|
const result = validateReferenceField(
|
||||||
schema,
|
schema,
|
||||||
Field.reference({
|
Field.reference({
|
||||||
@ -31,7 +31,7 @@ describe("Validate Reference Field", () => {
|
|||||||
expect(result).toBeInstanceOf(InvalidReferenceFieldError);
|
expect(result).toBeInstanceOf(InvalidReferenceFieldError);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not return an error if the target model is in the schema", () => {
|
it("should not return an error if the target model is in the schema", () => {
|
||||||
validateReferenceField(
|
validateReferenceField(
|
||||||
schema,
|
schema,
|
||||||
Field.reference({
|
Field.reference({
|
||||||
@ -40,7 +40,7 @@ describe("Validate Reference Field", () => {
|
|||||||
).unwrapOrThrow();
|
).unwrapOrThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return an error if the target key is not in the target model", () => {
|
it("should return an error if the target key is not in the target model", () => {
|
||||||
const result = validateReferenceField(
|
const result = validateReferenceField(
|
||||||
schema,
|
schema,
|
||||||
Field.reference({
|
Field.reference({
|
||||||
@ -52,7 +52,7 @@ describe("Validate Reference Field", () => {
|
|||||||
expect(result).toBeInstanceOf(InvalidReferenceFieldError);
|
expect(result).toBeInstanceOf(InvalidReferenceFieldError);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should return error if the target key is not unique", () => {
|
it("should return error if the target key is not unique", () => {
|
||||||
const result = validateReferenceField(
|
const result = validateReferenceField(
|
||||||
schema,
|
schema,
|
||||||
Field.reference({
|
Field.reference({
|
||||||
@ -64,7 +64,7 @@ describe("Validate Reference Field", () => {
|
|||||||
expect(result).toBeInstanceOf(InvalidReferenceFieldError);
|
expect(result).toBeInstanceOf(InvalidReferenceFieldError);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not return an error if the target key is in the target model and is unique", () => {
|
it("should not return an error if the target key is in the target model and is unique", () => {
|
||||||
const result = validateReferenceField(
|
const result = validateReferenceField(
|
||||||
schema,
|
schema,
|
||||||
Field.reference({
|
Field.reference({
|
||||||
@ -1,11 +1,6 @@
|
|||||||
import {
|
import { Result, TaggedError, TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
Result,
|
import { ModelSchema } from "../model-schema.js";
|
||||||
TaggedError,
|
import { BaseField } from "./base-field.js";
|
||||||
type TaggedVariant,
|
|
||||||
VariantTag,
|
|
||||||
} from "@fabric/core";
|
|
||||||
import type { ModelSchema } from "../model-schema.ts";
|
|
||||||
import type { BaseField } from "./base-field.ts";
|
|
||||||
|
|
||||||
export interface ReferenceFieldOptions extends BaseField {
|
export interface ReferenceFieldOptions extends BaseField {
|
||||||
targetModel: string;
|
targetModel: string;
|
||||||
@ -13,7 +8,8 @@ export interface ReferenceFieldOptions extends BaseField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ReferenceField
|
export interface ReferenceField
|
||||||
extends TaggedVariant<"ReferenceField">, ReferenceFieldOptions {}
|
extends TaggedVariant<"ReferenceField">,
|
||||||
|
ReferenceFieldOptions {}
|
||||||
|
|
||||||
export function createReferenceField<T extends ReferenceFieldOptions>(
|
export function createReferenceField<T extends ReferenceFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
@ -40,7 +36,7 @@ export function validateReferenceField(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.targetKey && !schema[field.targetModel]!.fields[field.targetKey]) {
|
if (field.targetKey && !schema[field.targetModel].fields[field.targetKey]) {
|
||||||
return Result.failWith(
|
return Result.failWith(
|
||||||
new InvalidReferenceFieldError(
|
new InvalidReferenceFieldError(
|
||||||
`The target key '${field.targetKey}' is not in the target model '${field.targetModel}'.`,
|
`The target key '${field.targetKey}' is not in the target model '${field.targetModel}'.`,
|
||||||
@ -50,7 +46,7 @@ export function validateReferenceField(
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
field.targetKey &&
|
field.targetKey &&
|
||||||
!schema[field.targetModel]!.fields[field.targetKey]!.isUnique
|
!schema[field.targetModel].fields[field.targetKey].isUnique
|
||||||
) {
|
) {
|
||||||
return Result.failWith(
|
return Result.failWith(
|
||||||
new InvalidReferenceFieldError(
|
new InvalidReferenceFieldError(
|
||||||
@ -62,8 +58,7 @@ export function validateReferenceField(
|
|||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InvalidReferenceFieldError
|
export class InvalidReferenceFieldError extends TaggedError<"InvalidReferenceField"> {
|
||||||
extends TaggedError<"InvalidReferenceField"> {
|
|
||||||
constructor(readonly reason: string) {
|
constructor(readonly reason: string) {
|
||||||
super("InvalidReferenceField");
|
super("InvalidReferenceField");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface StringFieldOptions extends BaseField {
|
export interface StringFieldOptions extends BaseField {
|
||||||
maxLength?: number;
|
maxLength?: number;
|
||||||
@ -7,7 +7,8 @@ export interface StringFieldOptions extends BaseField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface StringField
|
export interface StringField
|
||||||
extends TaggedVariant<"StringField">, StringFieldOptions {}
|
extends TaggedVariant<"StringField">,
|
||||||
|
StringFieldOptions {}
|
||||||
|
|
||||||
export function createStringField<T extends StringFieldOptions>(
|
export function createStringField<T extends StringFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||||
export interface TimestampFieldOptions extends BaseField {}
|
export interface TimestampFieldOptions extends BaseField {}
|
||||||
|
|
||||||
export interface TimestampField
|
export interface TimestampField
|
||||||
extends TaggedVariant<"TimestampField">, TimestampFieldOptions {}
|
extends TaggedVariant<"TimestampField">,
|
||||||
|
TimestampFieldOptions {}
|
||||||
|
|
||||||
export function createTimestampField<T extends TimestampFieldOptions>(
|
export function createTimestampField<T extends TimestampFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
import { type TaggedVariant, VariantTag } from "@fabric/core";
|
import { TaggedVariant, VariantTag } from "@fabric/core";
|
||||||
import type { BaseField } from "./base-field.ts";
|
import { BaseField } from "./base-field.js";
|
||||||
|
|
||||||
export interface UUIDFieldOptions extends BaseField {
|
export interface UUIDFieldOptions extends BaseField {
|
||||||
isPrimaryKey?: boolean;
|
isPrimaryKey?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UUIDField
|
export interface UUIDField
|
||||||
extends TaggedVariant<"UUIDField">, UUIDFieldOptions {}
|
extends TaggedVariant<"UUIDField">,
|
||||||
|
UUIDFieldOptions {}
|
||||||
|
|
||||||
export function createUUIDField<T extends UUIDFieldOptions>(
|
export function createUUIDField<T extends UUIDFieldOptions>(
|
||||||
opts: T = {} as T,
|
opts: T = {} as T,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
export * from "./fields/index.ts";
|
export * from "./fields/index.js";
|
||||||
export * from "./model-schema.ts";
|
export * from "./model-schema.js";
|
||||||
export * from "./model.ts";
|
export * from "./model.js";
|
||||||
export * from "./query/index.ts";
|
export * from "./query/index.js";
|
||||||
export * from "./state-store.ts";
|
export * from "./state-store.js";
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { Model } from "./model.ts";
|
import { Model } from "./model.js";
|
||||||
|
|
||||||
export type ModelSchema = Record<string, Model>;
|
export type ModelSchema = Record<string, Model>;
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
import type { PosixDate } from "@fabric/core";
|
import { describe, expectTypeOf, it } from "vitest";
|
||||||
import { describe, expectTypeOf, test } from "@fabric/testing";
|
import { UUID } from "../types/uuid.js";
|
||||||
import type { UUID } from "../types/uuid.ts";
|
import { Field } from "./fields/index.js";
|
||||||
import { Field } from "./fields/index.ts";
|
import { defineModel, ModelToType } from "./model.js";
|
||||||
import { defineModel, type ModelToType } from "./model.ts";
|
|
||||||
|
|
||||||
describe("CreateModel", () => {
|
describe("CreateModel", () => {
|
||||||
test("should create a model and it's interface type", () => {
|
it("should create a model and it's interface type", () => {
|
||||||
const User = defineModel("User", {
|
const User = defineModel("User", {
|
||||||
name: Field.string(),
|
name: Field.string(),
|
||||||
password: Field.string(),
|
password: Field.string(),
|
||||||
@ -20,7 +19,6 @@ describe("CreateModel", () => {
|
|||||||
name: string;
|
name: string;
|
||||||
password: string;
|
password: string;
|
||||||
phone: string | null;
|
phone: string | null;
|
||||||
deletedAt: PosixDate | null;
|
|
||||||
}>();
|
}>();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import type { Keyof } from "@fabric/core";
|
import { Keyof } from "@fabric/core";
|
||||||
import type { FieldToType } from "./fields/field-to-type.ts";
|
import { FieldToType } from "./fields/field-to-type.js";
|
||||||
import { Field, type FieldDefinition } from "./fields/index.ts";
|
import { Field, FieldDefinition } from "./fields/index.js";
|
||||||
|
|
||||||
export type CustomModelFields = Record<string, FieldDefinition>;
|
export type CustomModelFields = Record<string, FieldDefinition>;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type { Keyof, TaggedVariant } from "@fabric/core";
|
|
||||||
|
import { Keyof, TaggedVariant } from "@fabric/core";
|
||||||
|
|
||||||
export type AggregateOptions<T = any> = Record<string, AggregateFn<T>>;
|
export type AggregateOptions<T = any> = Record<string, AggregateFn<T>>;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
export type FilterOptions<T = any> =
|
export type FilterOptions<T = any> =
|
||||||
| SingleFilterOption<T>
|
| SingleFilterOption<T>
|
||||||
@ -20,10 +20,11 @@ export const FILTER_OPTION_TYPE_SYMBOL = "_filter_type";
|
|||||||
export const FILTER_OPTION_VALUE_SYMBOL = "_filter_value";
|
export const FILTER_OPTION_VALUE_SYMBOL = "_filter_value";
|
||||||
export const FILTER_OPTION_OPERATOR_SYMBOL = "_filter_operator";
|
export const FILTER_OPTION_OPERATOR_SYMBOL = "_filter_operator";
|
||||||
|
|
||||||
export type LikeFilterOption<T> = T extends string ? {
|
export type LikeFilterOption<T> = T extends string
|
||||||
[FILTER_OPTION_TYPE_SYMBOL]: "like";
|
? {
|
||||||
[FILTER_OPTION_VALUE_SYMBOL]: string;
|
[FILTER_OPTION_TYPE_SYMBOL]: "like";
|
||||||
}
|
[FILTER_OPTION_VALUE_SYMBOL]: string;
|
||||||
|
}
|
||||||
: never;
|
: never;
|
||||||
|
|
||||||
export interface InFilterOption<T> {
|
export interface InFilterOption<T> {
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export * from "./filter-options.ts";
|
export * from "./filter-options.js";
|
||||||
export * from "./order-by-options.ts";
|
export * from "./order-by-options.js";
|
||||||
export * from "./query.ts";
|
export * from "./query.js";
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
// deno-lint-ignore-file no-explicit-any
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type { AsyncResult, Keyof, Optional } from "@fabric/core";
|
import { AsyncResult, Keyof, Optional } from "@fabric/core";
|
||||||
import type { StoreQueryError } from "../../errors/query-error.ts";
|
import { StoreQueryError } from "../../errors/query-error.js";
|
||||||
import type { FilterOptions } from "./filter-options.ts";
|
import { FilterOptions } from "./filter-options.js";
|
||||||
import type { OrderByOptions } from "./order-by-options.ts";
|
import { OrderByOptions } from "./order-by-options.js";
|
||||||
|
|
||||||
export interface StoreQuery<T> {
|
export interface StoreQuery<T> {
|
||||||
where(where: FilterOptions<T>): StoreSortableQuery<T>;
|
where(where: FilterOptions<T>): StoreSortableQuery<T>;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import type { AsyncResult } from "@fabric/core";
|
import { AsyncResult } from "@fabric/core";
|
||||||
import type { StoreQueryError } from "../errors/query-error.ts";
|
import { StoreQueryError } from "../errors/query-error.js";
|
||||||
import type { ModelSchemaFromModels } from "./model-schema.ts";
|
import { ModelSchemaFromModels } from "./model-schema.js";
|
||||||
import type { Model, ModelToType } from "./model.ts";
|
import { Model, ModelToType } from "./model.js";
|
||||||
import type { StoreQuery } from "./query/query.ts";
|
import { StoreQuery } from "./query/query.js";
|
||||||
|
|
||||||
export interface ReadonlyStateStore<TModel extends Model> {
|
export interface ReadonlyStateStore<TModel extends Model> {
|
||||||
from<T extends keyof ModelSchemaFromModels<TModel>>(
|
from<T extends keyof ModelSchemaFromModels<TModel>>(
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import type { VariantTag } from "@fabric/core";
|
import { VariantTag } from "@fabric/core";
|
||||||
import type { Event } from "../events/event.ts";
|
import { Event } from "../events/event.js";
|
||||||
import type { StoredEvent } from "../events/stored-event.ts";
|
import { StoredEvent } from "../events/stored-event.js";
|
||||||
import type { Model, ModelToType } from "../models/model.ts";
|
import { Model, ModelToType } from "../models/model.js";
|
||||||
|
|
||||||
export interface Projection<TModel extends Model, TEvents extends Event> {
|
export interface Projection<TModel extends Model, TEvents extends Event> {
|
||||||
model: TModel;
|
model: TModel;
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./policy.ts";
|
export * from "./policy.js";
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./uuid-generator.ts";
|
export * from "./uuid-generator.js";
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
export * from "./uuid-generator.mock.ts";
|
export * from "./uuid-generator.mock.js";
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user