Merge pull request #146 from bknd-io/chore/optimize-tb

adjust typebox imports and enable TS incremental
This commit is contained in:
dswbx
2025-04-11 13:11:35 +02:00
committed by GitHub
69 changed files with 256 additions and 189 deletions
+2 -3
View File
@@ -1,7 +1,6 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import type { TObject, TString } from "@sinclair/typebox"; import { type TObject, type TString, Type } from "@sinclair/typebox";
import { Registry } from "../../src/core/registry/Registry"; import { Registry } from "core";
import { type TSchema, Type } from "../../src/core/utils";
type Constructor<T> = new (...args: any[]) => T; type Constructor<T> = new (...args: any[]) => T;
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { SchemaObject } from "../../../src/core"; import { SchemaObject } from "../../../src/core";
import { Type } from "../../../src/core/utils"; import { Type } from "@sinclair/typebox";
describe("SchemaObject", async () => { describe("SchemaObject", async () => {
test("basic", async () => { test("basic", async () => {
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { Type } from "../../../../src/core/utils"; import { Type } from "@sinclair/typebox";
import { Entity, EntityIndex, Field } from "../../../../src/data"; import { Entity, EntityIndex, Field } from "../../../../src/data";
class TestField extends Field { class TestField extends Field {
+1 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { Type } from "../../src/core/utils"; import { Type } from "@sinclair/typebox";
import { Task } from "../../src/flows"; import { Task } from "../../src/flows";
import { dynamic } from "../../src/flows/tasks/Task"; import { dynamic } from "../../src/flows/tasks/Task";
+2 -1
View File
@@ -1,7 +1,8 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { Hono } from "hono"; import { Hono } from "hono";
import { Event, EventManager } from "../../src/core/events"; import { Event, EventManager } from "../../src/core/events";
import { type Static, type StaticDecode, Type, parse } from "../../src/core/utils"; import { parse } from "../../src/core/utils";
import { type Static, type StaticDecode, Type } from "@sinclair/typebox";
import { EventTrigger, Flow, HttpTrigger, type InputsMap, Task } from "../../src/flows"; import { EventTrigger, Flow, HttpTrigger, type InputsMap, Task } from "../../src/flows";
import { dynamic } from "../../src/flows/tasks/Task"; import { dynamic } from "../../src/flows/tasks/Task";
+2 -1
View File
@@ -1,7 +1,8 @@
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { isEqual } from "lodash-es"; import { isEqual } from "lodash-es";
import { type Static, Type, _jsonp, withDisabledConsole } from "../../src/core/utils"; import { _jsonp, withDisabledConsole } from "../../src/core/utils";
import { type Static, Type } from "@sinclair/typebox";
import { Condition, ExecutionEvent, FetchTask, Flow, LogTask, Task } from "../../src/flows"; import { Condition, ExecutionEvent, FetchTask, Flow, LogTask, Task } from "../../src/flows";
/*beforeAll(disableConsoleLog); /*beforeAll(disableConsoleLog);
+4 -3
View File
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { type TSchema, Type, stripMark } from "../../src/core/utils"; import { stripMark } from "../../src/core/utils";
import { type TSchema, Type } from "@sinclair/typebox";
import { EntityManager, em, entity, index, text } from "../../src/data"; import { EntityManager, em, entity, index, text } from "../../src/data";
import { DummyConnection } from "../../src/data/connection/DummyConnection"; import { DummyConnection } from "../../src/data/connection/DummyConnection";
import { Module } from "../../src/modules/Module"; import { Module } from "../../src/modules/Module";
@@ -9,10 +10,10 @@ function createModule<Schema extends TSchema>(schema: Schema) {
getSchema() { getSchema() {
return schema; return schema;
} }
toJSON() { override toJSON() {
return this.config; return this.config;
} }
useForceParse() { override useForceParse() {
return true; return true;
} }
} }
+2 -1
View File
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"; import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
import { Type, disableConsoleLog, enableConsoleLog, stripMark } from "../../src/core/utils"; import { disableConsoleLog, enableConsoleLog, stripMark } from "../../src/core/utils";
import { Type } from "@sinclair/typebox";
import { entity, text } from "../../src/data"; import { entity, text } from "../../src/data";
import { Module } from "../../src/modules/Module"; import { Module } from "../../src/modules/Module";
import { ModuleManager, getDefaultConfig } from "../../src/modules/ModuleManager"; import { ModuleManager, getDefaultConfig } from "../../src/modules/ModuleManager";
@@ -1,8 +1,10 @@
import { registries } from "bknd"; import { registries } from "bknd";
import { isDebug } from "bknd/core"; import { isDebug } from "bknd/core";
import { StringEnum, Type } from "bknd/utils"; import { StringEnum } from "bknd/utils";
import { guessMimeType as guess, StorageAdapter, type FileBody } from "bknd/media"; import { guessMimeType as guess, StorageAdapter, type FileBody } from "bknd/media";
import { getBindings } from "../bindings"; import { getBindings } from "../bindings";
import * as tb from "@sinclair/typebox";
const { Type } = tb;
export function makeSchema(bindings: string[] = []) { export function makeSchema(bindings: string[] = []) {
return Type.Object( return Type.Object(
@@ -1,7 +1,9 @@
import { readFile, readdir, stat, unlink, writeFile } from "node:fs/promises"; import { readFile, readdir, stat, unlink, writeFile } from "node:fs/promises";
import { type Static, Type, isFile, parse } from "bknd/utils"; import { type Static, isFile, parse } from "bknd/utils";
import type { FileBody, FileListObject, FileMeta, FileUploadPayload } from "bknd/media"; import type { FileBody, FileListObject, FileMeta, FileUploadPayload } from "bknd/media";
import { StorageAdapter, guessMimeType as guess } from "bknd/media"; import { StorageAdapter, guessMimeType as guess } from "bknd/media";
import * as tb from "@sinclair/typebox";
const { Type } = tb;
export const localAdapterConfig = Type.Object( export const localAdapterConfig = Type.Object(
{ {
+3 -1
View File
@@ -1,9 +1,11 @@
import { type AppAuth, AuthPermissions, type SafeUser, type Strategy } from "auth"; import { type AppAuth, AuthPermissions, type SafeUser, type Strategy } from "auth";
import { tbValidator as tb } from "core"; import { tbValidator as tb } from "core";
import { Type, TypeInvalidError, parse, transformObject } from "core/utils"; import { TypeInvalidError, parse, transformObject } from "core/utils";
import { DataPermissions } from "data"; import { DataPermissions } from "data";
import type { Hono } from "hono"; import type { Hono } from "hono";
import { Controller, type ServerEnv } from "modules/Controller"; import { Controller, type ServerEnv } from "modules/Controller";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type AuthActionResponse = { export type AuthActionResponse = {
success: boolean; success: boolean;
+3 -1
View File
@@ -1,6 +1,8 @@
import { cookieConfig, jwtConfig } from "auth/authenticate/Authenticator"; import { cookieConfig, jwtConfig } from "auth/authenticate/Authenticator";
import { CustomOAuthStrategy, OAuthStrategy, PasswordStrategy } from "auth/authenticate/strategies"; import { CustomOAuthStrategy, OAuthStrategy, PasswordStrategy } from "auth/authenticate/strategies";
import { type Static, StringRecord, Type, objectTransform } from "core/utils"; import { type Static, StringRecord, objectTransform } from "core/utils";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const Strategies = { export const Strategies = {
password: { password: {
+9 -1
View File
@@ -1,12 +1,20 @@
import { $console, type DB, Exception, type PrimaryFieldType } from "core"; import { $console, type DB, Exception, type PrimaryFieldType } from "core";
import { addFlashMessage } from "core/server/flash"; import { addFlashMessage } from "core/server/flash";
import { parse, runtimeSupports, type Static, StringEnum, type TObject, Type } from "core/utils"; import {
type Static,
StringEnum,
type TObject,
parse,
runtimeSupports,
} from "core/utils";
import type { Context, Hono } from "hono"; import type { Context, Hono } from "hono";
import { deleteCookie, getSignedCookie, setSignedCookie } from "hono/cookie"; import { deleteCookie, getSignedCookie, setSignedCookie } from "hono/cookie";
import { sign, verify } from "hono/jwt"; import { sign, verify } from "hono/jwt";
import type { CookieOptions } from "hono/utils/cookie"; import type { CookieOptions } from "hono/utils/cookie";
import type { ServerEnv } from "modules/Controller"; import type { ServerEnv } from "modules/Controller";
import { pick } from "lodash-es"; import { pick } from "lodash-es";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
type Input = any; // workaround type Input = any; // workaround
export type JWTPayload = Parameters<typeof sign>[0]; export type JWTPayload = Parameters<typeof sign>[0];
@@ -1,8 +1,11 @@
import type { Authenticator, Strategy } from "auth"; import type { Authenticator, Strategy } from "auth";
import { tbValidator as tb } from "core"; import { tbValidator as tb } from "core";
import { hash, parse, type Static, StringEnum, Type } from "core/utils"; import { type Static, StringEnum, parse } from "core/utils";
import { hash } from "core/utils";
import { Hono } from "hono"; import { Hono } from "hono";
import { createStrategyAction, type StrategyActions } from "../Authenticator"; import { type StrategyActions, createStrategyAction } from "../Authenticator";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
type LoginSchema = { username: string; password: string } | { email: string; password: string }; type LoginSchema = { username: string; password: string } | { email: string; password: string };
type RegisterSchema = { email: string; password: string; [key: string]: any }; type RegisterSchema = { email: string; password: string; [key: string]: any };
@@ -1,6 +1,8 @@
import { type Static, StringEnum, Type } from "core/utils"; import { type Static, StringEnum } from "core/utils";
import * as tbbox from "@sinclair/typebox";
import type * as oauth from "oauth4webapi"; import type * as oauth from "oauth4webapi";
import { OAuthStrategy } from "./OAuthStrategy"; import { OAuthStrategy } from "./OAuthStrategy";
const { Type } = tbbox;
type SupportedTypes = "oauth2" | "oidc"; type SupportedTypes = "oauth2" | "oidc";
@@ -1,10 +1,12 @@
import type { AuthAction, Authenticator, Strategy } from "auth"; import type { AuthAction, Authenticator, Strategy } from "auth";
import { Exception, isDebug } from "core"; import { Exception, isDebug } from "core";
import { type Static, StringEnum, Type, filterKeys } from "core/utils"; import { type Static, StringEnum, filterKeys } from "core/utils";
import { type Context, Hono } from "hono"; import { type Context, Hono } from "hono";
import { getSignedCookie, setSignedCookie } from "hono/cookie"; import { getSignedCookie, setSignedCookie } from "hono/cookie";
import * as oauth from "oauth4webapi"; import * as oauth from "oauth4webapi";
import * as issuers from "./issuers"; import * as issuers from "./issuers";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
type ConfiguredIssuers = keyof typeof issuers; type ConfiguredIssuers = keyof typeof issuers;
type SupportedTypes = "oauth2" | "oidc"; type SupportedTypes = "oauth2" | "oidc";
+46 -53
View File
@@ -1,18 +1,11 @@
import { import * as tb from "@sinclair/typebox";
Kind, import type {
type ObjectOptions,
type SchemaOptions,
type Static,
type StaticDecode,
type StringOptions,
type TLiteral,
type TLiteralValue,
type TObject,
type TRecord,
type TSchema,
type TString,
Type,
TypeRegistry, TypeRegistry,
Static,
StaticDecode,
TSchema,
SchemaOptions,
TObject,
} from "@sinclair/typebox"; } from "@sinclair/typebox";
import { import {
DefaultErrorFunction, DefaultErrorFunction,
@@ -43,7 +36,7 @@ const validationSymbol = Symbol("tb-parse-validation");
export class TypeInvalidError extends Error { export class TypeInvalidError extends Error {
errors: ValueError[]; errors: ValueError[];
constructor( constructor(
public schema: TSchema, public schema: tb.TSchema,
public data: unknown, public data: unknown,
message?: string, message?: string,
) { ) {
@@ -92,25 +85,25 @@ export function mark(obj: any, validated = true) {
} }
} }
export function parse<Schema extends TSchema = TSchema>( export function parse<Schema extends tb.TSchema = tb.TSchema>(
schema: Schema, schema: Schema,
data: RecursivePartial<Static<Schema>>, data: RecursivePartial<tb.Static<Schema>>,
options?: ParseOptions, options?: ParseOptions,
): Static<Schema> { ): tb.Static<Schema> {
if (!options?.forceParse && typeof data === "object" && validationSymbol in data) { if (!options?.forceParse && typeof data === "object" && validationSymbol in data) {
if (options?.useDefaults === false) { if (options?.useDefaults === false) {
return data as Static<typeof schema>; return data as tb.Static<typeof schema>;
} }
// this is important as defaults are expected // this is important as defaults are expected
return Default(schema, data as any) as Static<Schema>; return Default(schema, data as any) as tb.Static<Schema>;
} }
const parsed = options?.useDefaults === false ? data : Default(schema, data); const parsed = options?.useDefaults === false ? data : Default(schema, data);
if (Check(schema, parsed)) { if (Check(schema, parsed)) {
options?.skipMark !== true && mark(parsed, true); options?.skipMark !== true && mark(parsed, true);
return parsed as Static<typeof schema>; return parsed as tb.Static<typeof schema>;
} else if (options?.onError) { } else if (options?.onError) {
options.onError(Errors(schema, data)); options.onError(Errors(schema, data));
} else { } else {
@@ -121,24 +114,24 @@ export function parse<Schema extends TSchema = TSchema>(
return undefined as any; return undefined as any;
} }
export function parseDecode<Schema extends TSchema = TSchema>( export function parseDecode<Schema extends tb.TSchema = tb.TSchema>(
schema: Schema, schema: Schema,
data: RecursivePartial<StaticDecode<Schema>>, data: RecursivePartial<tb.StaticDecode<Schema>>,
): StaticDecode<Schema> { ): tb.StaticDecode<Schema> {
const parsed = Default(schema, data); const parsed = Default(schema, data);
if (Check(schema, parsed)) { if (Check(schema, parsed)) {
return parsed as StaticDecode<typeof schema>; return parsed as tb.StaticDecode<typeof schema>;
} }
throw new TypeInvalidError(schema, data); throw new TypeInvalidError(schema, data);
} }
export function strictParse<Schema extends TSchema = TSchema>( export function strictParse<Schema extends tb.TSchema = tb.TSchema>(
schema: Schema, schema: Schema,
data: Static<Schema>, data: tb.Static<Schema>,
options?: ParseOptions, options?: ParseOptions,
): Static<Schema> { ): tb.Static<Schema> {
return parse(schema, data as any, options); return parse(schema, data as any, options);
} }
@@ -147,11 +140,14 @@ export function registerCustomTypeboxKinds(registry: typeof TypeRegistry) {
return typeof value === "string" && schema.enum.includes(value); return typeof value === "string" && schema.enum.includes(value);
}); });
} }
registerCustomTypeboxKinds(TypeRegistry); registerCustomTypeboxKinds(tb.TypeRegistry);
export const StringEnum = <const T extends readonly string[]>(values: T, options?: StringOptions) => export const StringEnum = <const T extends readonly string[]>(
Type.Unsafe<T[number]>({ values: T,
[Kind]: "StringEnum", options?: tb.StringOptions,
) =>
tb.Type.Unsafe<T[number]>({
[tb.Kind]: "StringEnum",
type: "string", type: "string",
enum: values, enum: values,
...options, ...options,
@@ -159,17 +155,25 @@ export const StringEnum = <const T extends readonly string[]>(values: T, options
// key value record compatible with RJSF and typebox inference // key value record compatible with RJSF and typebox inference
// acting like a Record, but using an Object with additionalProperties // acting like a Record, but using an Object with additionalProperties
export const StringRecord = <T extends TSchema>(properties: T, options?: ObjectOptions) => export const StringRecord = <T extends tb.TSchema>(properties: T, options?: tb.ObjectOptions) =>
Type.Object({}, { ...options, additionalProperties: properties }) as unknown as TRecord< tb.Type.Object({}, { ...options, additionalProperties: properties }) as unknown as tb.TRecord<
TString, tb.TString,
typeof properties typeof properties
>; >;
// fixed value that only be what is given + prefilled // fixed value that only be what is given + prefilled
export const Const = <T extends TLiteralValue = TLiteralValue>(value: T, options?: SchemaOptions) => export const Const = <T extends tb.TLiteralValue = tb.TLiteralValue>(
Type.Literal(value, { ...options, default: value, const: value, readOnly: true }) as TLiteral<T>; value: T,
options?: tb.SchemaOptions,
) =>
tb.Type.Literal(value, {
...options,
default: value,
const: value,
readOnly: true,
}) as tb.TLiteral<T>;
export const StringIdentifier = Type.String({ export const StringIdentifier = tb.Type.String({
pattern: "^[a-zA-Z_][a-zA-Z0-9_]*$", pattern: "^[a-zA-Z_][a-zA-Z0-9_]*$",
minLength: 2, minLength: 2,
maxLength: 150, maxLength: 150,
@@ -180,24 +184,13 @@ SetErrorFunction((error) => {
return error.schema.errorMessage; return error.schema.errorMessage;
} }
if (error?.schema?.[Kind] === "StringEnum") { if (error?.schema?.[tb.Kind] === "StringEnum") {
return `Expected: ${error.schema.enum.map((e) => `"${e}"`).join(", ")}`; return `Expected: ${error.schema.enum.map((e) => `"${e}"`).join(", ")}`;
} }
return DefaultErrorFunction(error); return DefaultErrorFunction(error);
}); });
export { export type { Static, StaticDecode, TSchema, TObject, ValueError, SchemaOptions };
Type,
type Static, export { Value, Default, Errors, Check };
type StaticDecode,
type TSchema,
Kind,
type TObject,
type ValueError,
type SchemaOptions,
Value,
Default,
Errors,
Check,
};
+3 -1
View File
@@ -1,5 +1,6 @@
import { $console, isDebug, tbValidator as tb } from "core"; import { $console, isDebug, tbValidator as tb } from "core";
import { StringEnum, Type } from "core/utils"; import { StringEnum } from "core/utils";
import * as tbbox from "@sinclair/typebox";
import { import {
DataPermissions, DataPermissions,
type EntityData, type EntityData,
@@ -14,6 +15,7 @@ import type { ModuleBuildContext } from "modules";
import { Controller } from "modules/Controller"; import { Controller } from "modules/Controller";
import * as SystemPermissions from "modules/permissions"; import * as SystemPermissions from "modules/permissions";
import type { AppDataConfig } from "../data-schema"; import type { AppDataConfig } from "../data-schema";
const { Type } = tbbox;
export class DataController extends Controller { export class DataController extends Controller {
constructor( constructor(
+26 -23
View File
@@ -1,4 +1,5 @@
import { type Static, StringRecord, Type, objectTransform } from "core/utils"; import { type Static, StringRecord, objectTransform } from "core/utils";
import * as tb from "@sinclair/typebox";
import { import {
FieldClassMap, FieldClassMap,
RelationClassMap, RelationClassMap,
@@ -18,35 +19,37 @@ export type FieldType = keyof typeof FIELDS;
export const RELATIONS = RelationClassMap; export const RELATIONS = RelationClassMap;
export const fieldsSchemaObject = objectTransform(FIELDS, (field, name) => { export const fieldsSchemaObject = objectTransform(FIELDS, (field, name) => {
return Type.Object( return tb.Type.Object(
{ {
type: Type.Const(name, { default: name, readOnly: true }), type: tb.Type.Const(name, { default: name, readOnly: true }),
config: Type.Optional(field.schema), config: tb.Type.Optional(field.schema),
}, },
{ {
title: name, title: name,
}, },
); );
}); });
export const fieldsSchema = Type.Union(Object.values(fieldsSchemaObject)); export const fieldsSchema = tb.Type.Union(Object.values(fieldsSchemaObject));
export const entityFields = StringRecord(fieldsSchema); export const entityFields = StringRecord(fieldsSchema);
export type TAppDataField = Static<typeof fieldsSchema>; export type TAppDataField = Static<typeof fieldsSchema>;
export type TAppDataEntityFields = Static<typeof entityFields>; export type TAppDataEntityFields = Static<typeof entityFields>;
export const entitiesSchema = Type.Object({ export const entitiesSchema = tb.Type.Object({
type: Type.Optional(Type.String({ enum: entityTypes, default: "regular", readOnly: true })), type: tb.Type.Optional(
config: Type.Optional(entityConfigSchema), tb.Type.String({ enum: entityTypes, default: "regular", readOnly: true }),
fields: Type.Optional(entityFields), ),
config: tb.Type.Optional(entityConfigSchema),
fields: tb.Type.Optional(entityFields),
}); });
export type TAppDataEntity = Static<typeof entitiesSchema>; export type TAppDataEntity = Static<typeof entitiesSchema>;
export const relationsSchema = Object.entries(RelationClassMap).map(([name, relationClass]) => { export const relationsSchema = Object.entries(RelationClassMap).map(([name, relationClass]) => {
return Type.Object( return tb.Type.Object(
{ {
type: Type.Const(name, { default: name, readOnly: true }), type: tb.Type.Const(name, { default: name, readOnly: true }),
source: Type.String(), source: tb.Type.String(),
target: Type.String(), target: tb.Type.String(),
config: Type.Optional(relationClass.schema), config: tb.Type.Optional(relationClass.schema),
}, },
{ {
title: name, title: name,
@@ -55,23 +58,23 @@ export const relationsSchema = Object.entries(RelationClassMap).map(([name, rela
}); });
export type TAppDataRelation = Static<(typeof relationsSchema)[number]>; export type TAppDataRelation = Static<(typeof relationsSchema)[number]>;
export const indicesSchema = Type.Object( export const indicesSchema = tb.Type.Object(
{ {
entity: Type.String(), entity: tb.Type.String(),
fields: Type.Array(Type.String(), { minItems: 1 }), fields: tb.Type.Array(tb.Type.String(), { minItems: 1 }),
unique: Type.Optional(Type.Boolean({ default: false })), unique: tb.Type.Optional(tb.Type.Boolean({ default: false })),
}, },
{ {
additionalProperties: false, additionalProperties: false,
}, },
); );
export const dataConfigSchema = Type.Object( export const dataConfigSchema = tb.Type.Object(
{ {
basepath: Type.Optional(Type.String({ default: "/api/data" })), basepath: tb.Type.Optional(tb.Type.String({ default: "/api/data" })),
entities: Type.Optional(StringRecord(entitiesSchema, { default: {} })), entities: tb.Type.Optional(StringRecord(entitiesSchema, { default: {} })),
relations: Type.Optional(StringRecord(Type.Union(relationsSchema), { default: {} })), relations: tb.Type.Optional(StringRecord(tb.Type.Union(relationsSchema), { default: {} })),
indices: Type.Optional(StringRecord(indicesSchema, { default: {} })), indices: tb.Type.Optional(StringRecord(indicesSchema, { default: {} })),
}, },
{ {
additionalProperties: false, additionalProperties: false,
+2 -1
View File
@@ -2,12 +2,13 @@ import { $console, config } from "core";
import { import {
type Static, type Static,
StringEnum, StringEnum,
Type,
parse, parse,
snakeToPascalWithSpaces, snakeToPascalWithSpaces,
transformObject, transformObject,
} from "core/utils"; } from "core/utils";
import { type Field, PrimaryField, type TActionContext, type TRenderContext } from "../fields"; import { type Field, PrimaryField, type TActionContext, type TRenderContext } from "../fields";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
// @todo: entity must be migrated to typebox // @todo: entity must be migrated to typebox
export const entityConfigSchema = Type.Object( export const entityConfigSchema = Type.Object(
+3 -1
View File
@@ -1,7 +1,9 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import type { EntityManager } from "data"; import type { EntityManager } from "data";
import { TransformPersistFailedException } from "../errors"; import { TransformPersistFailedException } from "../errors";
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field"; import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
import * as tb from "@sinclair/typebox";
const { Type } = tb;
export const booleanFieldConfigSchema = Type.Composite([ export const booleanFieldConfigSchema = Type.Composite([
Type.Object({ Type.Object({
+3 -1
View File
@@ -1,7 +1,9 @@
import { type Static, StringEnum, Type, dayjs } from "core/utils"; import { type Static, StringEnum, dayjs } from "core/utils";
import type { EntityManager } from "../entities"; import type { EntityManager } from "../entities";
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field"; import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
import { $console } from "core"; import { $console } from "core";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const dateFieldConfigSchema = Type.Composite( export const dateFieldConfigSchema = Type.Composite(
[ [
+3 -1
View File
@@ -1,7 +1,9 @@
import { Const, type Static, StringEnum, Type } from "core/utils"; import { Const, type Static, StringEnum } from "core/utils";
import type { EntityManager } from "data"; import type { EntityManager } from "data";
import { TransformPersistFailedException } from "../errors"; import { TransformPersistFailedException } from "../errors";
import { baseFieldConfigSchema, Field, type TActionContext, type TRenderContext } from "./Field"; import { baseFieldConfigSchema, Field, type TActionContext, type TRenderContext } from "./Field";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const enumFieldConfigSchema = Type.Composite( export const enumFieldConfigSchema = Type.Composite(
[ [
+2 -1
View File
@@ -4,13 +4,14 @@ import {
type Static, type Static,
StringEnum, StringEnum,
type TSchema, type TSchema,
Type,
TypeInvalidError, TypeInvalidError,
} from "core/utils"; } from "core/utils";
import type { HTMLInputTypeAttribute, InputHTMLAttributes } from "react"; import type { HTMLInputTypeAttribute, InputHTMLAttributes } from "react";
import type { EntityManager } from "../entities"; import type { EntityManager } from "../entities";
import { InvalidFieldConfigException, TransformPersistFailedException } from "../errors"; import { InvalidFieldConfigException, TransformPersistFailedException } from "../errors";
import type { FieldSpec } from "data/connection/Connection"; import type { FieldSpec } from "data/connection/Connection";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
// @todo: contexts need to be reworked // @todo: contexts need to be reworked
// e.g. "table" is irrelevant, because if read is not given, it fails // e.g. "table" is irrelevant, because if read is not given, it fails
+3 -1
View File
@@ -1,7 +1,9 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import type { EntityManager } from "data"; import type { EntityManager } from "data";
import { TransformPersistFailedException } from "../errors"; import { TransformPersistFailedException } from "../errors";
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field"; import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const jsonFieldConfigSchema = Type.Composite([baseFieldConfigSchema, Type.Object({})]); export const jsonFieldConfigSchema = Type.Composite([baseFieldConfigSchema, Type.Object({})]);
+3 -1
View File
@@ -1,8 +1,10 @@
import { type Schema as JsonSchema, Validator } from "@cfworker/json-schema"; import { type Schema as JsonSchema, Validator } from "@cfworker/json-schema";
import { Default, FromSchema, type Static, Type } from "core/utils"; import { Default, FromSchema, type Static } from "core/utils";
import type { EntityManager } from "data"; import type { EntityManager } from "data";
import { TransformPersistFailedException } from "../errors"; import { TransformPersistFailedException } from "../errors";
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field"; import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const jsonSchemaFieldConfigSchema = Type.Composite( export const jsonSchemaFieldConfigSchema = Type.Composite(
[ [
+3 -1
View File
@@ -1,7 +1,9 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import type { EntityManager } from "data"; import type { EntityManager } from "data";
import { TransformPersistFailedException } from "../errors"; import { TransformPersistFailedException } from "../errors";
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field"; import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const numberFieldConfigSchema = Type.Composite( export const numberFieldConfigSchema = Type.Composite(
[ [
+3 -1
View File
@@ -1,6 +1,8 @@
import { config } from "core"; import { config } from "core";
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import { Field, baseFieldConfigSchema } from "./Field"; import { Field, baseFieldConfigSchema } from "./Field";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const primaryFieldConfigSchema = Type.Composite([ export const primaryFieldConfigSchema = Type.Composite([
Type.Omit(baseFieldConfigSchema, ["required"]), Type.Omit(baseFieldConfigSchema, ["required"]),
+3 -1
View File
@@ -1,7 +1,9 @@
import { type Static, Type } from "core/utils";
import type { EntityManager } from "data"; import type { EntityManager } from "data";
import type { Static } from "core/utils";
import { TransformPersistFailedException } from "../errors"; import { TransformPersistFailedException } from "../errors";
import { Field, type TActionContext, baseFieldConfigSchema } from "./Field"; import { Field, type TActionContext, baseFieldConfigSchema } from "./Field";
import * as tb from "@sinclair/typebox";
const { Type } = tb;
export const textFieldConfigSchema = Type.Composite( export const textFieldConfigSchema = Type.Composite(
[ [
+3 -1
View File
@@ -1,5 +1,7 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import { Field, baseFieldConfigSchema } from "./Field"; import { Field, baseFieldConfigSchema } from "./Field";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const virtualFieldConfigSchema = Type.Composite([baseFieldConfigSchema, Type.Object({})]); export const virtualFieldConfigSchema = Type.Composite([baseFieldConfigSchema, Type.Object({})]);
+3 -1
View File
@@ -1,4 +1,4 @@
import { type Static, Type, parse } from "core/utils"; import { type Static, parse } from "core/utils";
import type { ExpressionBuilder, SelectQueryBuilder } from "kysely"; import type { ExpressionBuilder, SelectQueryBuilder } from "kysely";
import type { Entity, EntityData, EntityManager } from "../entities"; import type { Entity, EntityData, EntityManager } from "../entities";
import { import {
@@ -8,6 +8,8 @@ import {
} from "../relations"; } from "../relations";
import type { RepoQuery } from "../server/data-query-impl"; import type { RepoQuery } from "../server/data-query-impl";
import type { RelationType } from "./relation-types"; import type { RelationType } from "./relation-types";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type KyselyJsonFrom = any; export type KyselyJsonFrom = any;
export type KyselyQueryBuilder = SelectQueryBuilder<any, any, any>; export type KyselyQueryBuilder = SelectQueryBuilder<any, any, any>;
+3 -1
View File
@@ -1,4 +1,4 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import type { ExpressionBuilder } from "kysely"; import type { ExpressionBuilder } from "kysely";
import { Entity, type EntityManager } from "../entities"; import { Entity, type EntityManager } from "../entities";
import { type Field, PrimaryField } from "../fields"; import { type Field, PrimaryField } from "../fields";
@@ -7,6 +7,8 @@ import { EntityRelation, type KyselyQueryBuilder } from "./EntityRelation";
import { EntityRelationAnchor } from "./EntityRelationAnchor"; import { EntityRelationAnchor } from "./EntityRelationAnchor";
import { RelationField } from "./RelationField"; import { RelationField } from "./RelationField";
import { type RelationType, RelationTypes } from "./relation-types"; import { type RelationType, RelationTypes } from "./relation-types";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type ManyToManyRelationConfig = Static<typeof ManyToManyRelation.schema>; export type ManyToManyRelationConfig = Static<typeof ManyToManyRelation.schema>;
+4 -1
View File
@@ -1,5 +1,6 @@
import type { PrimaryFieldType } from "core"; import type { PrimaryFieldType } from "core";
import { snakeToPascalWithSpaces, type Static, Type } from "core/utils"; import { snakeToPascalWithSpaces } from "core/utils";
import type { Static } from "core/utils";
import type { ExpressionBuilder } from "kysely"; import type { ExpressionBuilder } from "kysely";
import type { Entity, EntityManager } from "../entities"; import type { Entity, EntityManager } from "../entities";
import type { RepoQuery } from "../server/data-query-impl"; import type { RepoQuery } from "../server/data-query-impl";
@@ -8,6 +9,8 @@ import { EntityRelationAnchor } from "./EntityRelationAnchor";
import { RelationField, type RelationFieldBaseConfig } from "./RelationField"; import { RelationField, type RelationFieldBaseConfig } from "./RelationField";
import type { MutationInstructionResponse } from "./RelationMutator"; import type { MutationInstructionResponse } from "./RelationMutator";
import { type RelationType, RelationTypes } from "./relation-types"; import { type RelationType, RelationTypes } from "./relation-types";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
/** /**
* Source entity receives the mapping field * Source entity receives the mapping field
@@ -1,4 +1,4 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import type { ExpressionBuilder } from "kysely"; import type { ExpressionBuilder } from "kysely";
import type { Entity, EntityManager } from "../entities"; import type { Entity, EntityManager } from "../entities";
import { NumberField, TextField } from "../fields"; import { NumberField, TextField } from "../fields";
@@ -6,6 +6,8 @@ import type { RepoQuery } from "../server/data-query-impl";
import { EntityRelation, type KyselyJsonFrom, type KyselyQueryBuilder } from "./EntityRelation"; import { EntityRelation, type KyselyJsonFrom, type KyselyQueryBuilder } from "./EntityRelation";
import { EntityRelationAnchor } from "./EntityRelationAnchor"; import { EntityRelationAnchor } from "./EntityRelationAnchor";
import { type RelationType, RelationTypes } from "./relation-types"; import { type RelationType, RelationTypes } from "./relation-types";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type PolymorphicRelationConfig = Static<typeof PolymorphicRelation.schema>; export type PolymorphicRelationConfig = Static<typeof PolymorphicRelation.schema>;
+3 -1
View File
@@ -1,8 +1,10 @@
import { type Static, StringEnum, Type } from "core/utils"; import { type Static, StringEnum } from "core/utils";
import type { EntityManager } from "../entities"; import type { EntityManager } from "../entities";
import { Field, baseFieldConfigSchema } from "../fields"; import { Field, baseFieldConfigSchema } from "../fields";
import type { EntityRelation } from "./EntityRelation"; import type { EntityRelation } from "./EntityRelation";
import type { EntityRelationAnchor } from "./EntityRelationAnchor"; import type { EntityRelationAnchor } from "./EntityRelationAnchor";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const CASCADES = ["cascade", "set null", "set default", "restrict", "no action"] as const; const CASCADES = ["cascade", "set null", "set default", "restrict", "no action"] as const;
+3 -9
View File
@@ -1,14 +1,8 @@
import type { TThis } from "@sinclair/typebox"; import type { TThis } from "@sinclair/typebox";
import { import { type SchemaOptions, type StaticDecode, StringEnum, Value, isObject } from "core/utils";
type SchemaOptions,
type Static,
type StaticDecode,
StringEnum,
Type,
Value,
isObject,
} from "core/utils";
import { WhereBuilder, type WhereQuery } from "../entities"; import { WhereBuilder, type WhereQuery } from "../entities";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const NumberOrString = (options: SchemaOptions = {}) => const NumberOrString = (options: SchemaOptions = {}) =>
Type.Transform(Type.Union([Type.Number(), Type.String()], options)) Type.Transform(Type.Union([Type.Number(), Type.String()], options))
+3 -1
View File
@@ -1,5 +1,7 @@
import { Const, type Static, StringRecord, Type, transformObject } from "core/utils"; import { Const, type Static, StringRecord, transformObject } from "core/utils";
import { TaskMap, TriggerMap } from "flows"; import { TaskMap, TriggerMap } from "flows";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const TASKS = { export const TASKS = {
...TaskMap, ...TaskMap,
+2 -1
View File
@@ -1,8 +1,9 @@
import type { EventManager } from "core/events"; import type { EventManager } from "core/events";
import { Type } from "core/utils";
import type { Flow } from "../Flow"; import type { Flow } from "../Flow";
import { Trigger } from "./Trigger"; import { Trigger } from "./Trigger";
import { $console } from "core"; import { $console } from "core";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class EventTrigger extends Trigger<typeof EventTrigger.schema> { export class EventTrigger extends Trigger<typeof EventTrigger.schema> {
override type = "event"; override type = "event";
+3 -1
View File
@@ -1,7 +1,9 @@
import { StringEnum, Type } from "core/utils"; import { StringEnum } from "core/utils";
import type { Context, Hono } from "hono"; import type { Context, Hono } from "hono";
import type { Flow } from "../Flow"; import type { Flow } from "../Flow";
import { Trigger } from "./Trigger"; import { Trigger } from "./Trigger";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const httpMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"] as const; const httpMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"] as const;
+3 -1
View File
@@ -1,6 +1,8 @@
import { type Static, StringEnum, Type, parse } from "core/utils"; import { type Static, StringEnum, parse } from "core/utils";
import type { Execution } from "../Execution"; import type { Execution } from "../Execution";
import type { Flow } from "../Flow"; import type { Flow } from "../Flow";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class Trigger<Schema extends typeof Trigger.schema = typeof Trigger.schema> { export class Trigger<Schema extends typeof Trigger.schema = typeof Trigger.schema> {
// @todo: remove this // @todo: remove this
+4 -1
View File
@@ -1,7 +1,10 @@
import type { StaticDecode, TSchema } from "@sinclair/typebox"; import type { StaticDecode, TSchema } from "@sinclair/typebox";
import { BkndError, SimpleRenderer } from "core"; import { BkndError, SimpleRenderer } from "core";
import { parse, type Static, type TObject, Type, ucFirst, Value } from "core/utils"; import { type Static, type TObject, Value, parse, ucFirst } from "core/utils";
import type { InputsMap } from "../flows/Execution"; import type { InputsMap } from "../flows/Execution";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
//type InstanceOf<T> = T extends new (...args: any) => infer R ? R : never;
export type TaskResult<Output = any> = { export type TaskResult<Output = any> = {
start: Date; start: Date;
+3 -2
View File
@@ -1,6 +1,7 @@
import { StringEnum, Type } from "core/utils"; import { StringEnum } from "core/utils";
import type { InputsMap } from "../../flows/Execution";
import { Task, dynamic } from "../Task"; import { Task, dynamic } from "../Task";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const FetchMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"]; const FetchMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
+2 -1
View File
@@ -1,6 +1,7 @@
import { Type } from "core/utils";
import { Task } from "../Task"; import { Task } from "../Task";
import { $console } from "core"; import { $console } from "core";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class LogTask extends Task<typeof LogTask.schema> { export class LogTask extends Task<typeof LogTask.schema> {
type = "log"; type = "log";
+2 -1
View File
@@ -1,5 +1,6 @@
import { Type } from "core/utils";
import { Task } from "../Task"; import { Task } from "../Task";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class RenderTask<Output extends Record<string, any>> extends Task< export class RenderTask<Output extends Record<string, any>> extends Task<
typeof RenderTask.schema, typeof RenderTask.schema,
+2 -1
View File
@@ -1,6 +1,7 @@
import { Type } from "core/utils";
import { Flow } from "../../flows/Flow"; import { Flow } from "../../flows/Flow";
import { Task, dynamic } from "../Task"; import { Task, dynamic } from "../Task";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export class SubFlowTask<Output extends Record<string, any>> extends Task< export class SubFlowTask<Output extends Record<string, any>> extends Task<
typeof SubFlowTask.schema, typeof SubFlowTask.schema,
+3 -1
View File
@@ -1,5 +1,7 @@
import { type Static, Type } from "core/utils"; import type { Static } from "core/utils";
import { Field, baseFieldConfigSchema } from "data"; import { Field, baseFieldConfigSchema } from "data";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const mediaFieldConfigSchema = Type.Composite([ export const mediaFieldConfigSchema = Type.Composite([
Type.Object({ Type.Object({
+3 -1
View File
@@ -1,10 +1,12 @@
import { isDebug, tbValidator as tb } from "core"; import { isDebug, tbValidator as tb } from "core";
import { HttpStatus, Type, getFileFromContext, headersToObject } from "core/utils"; import { HttpStatus, getFileFromContext } from "core/utils";
import type { StorageAdapter } from "media"; import type { StorageAdapter } from "media";
import { StorageEvents, getRandomizedFilename } from "media"; import { StorageEvents, getRandomizedFilename } from "media";
import { Controller } from "modules/Controller"; import { Controller } from "modules/Controller";
import type { AppMedia } from "../AppMedia"; import type { AppMedia } from "../AppMedia";
import { MediaField } from "../MediaField"; import { MediaField } from "../MediaField";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const booleanLike = Type.Transform(Type.String()) const booleanLike = Type.Transform(Type.String())
.Decode((v) => v === "1") .Decode((v) => v === "1")
+3 -1
View File
@@ -1,6 +1,8 @@
import { Const, type Static, Type, objectTransform } from "core/utils"; import { Const, type Static, objectTransform } from "core/utils";
import { Adapters } from "media"; import { Adapters } from "media";
import { registries } from "modules/registries"; import { registries } from "modules/registries";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const ADAPTERS = { export const ADAPTERS = {
...Adapters, ...Adapters,
@@ -1,7 +1,9 @@
import { hash, pickHeaders } from "core/utils"; import { hash, pickHeaders } from "core/utils";
import { type Static, Type, parse } from "core/utils"; import { type Static, parse } from "core/utils";
import type { FileBody, FileListObject, FileMeta } from "../../Storage"; import type { FileBody, FileListObject, FileMeta } from "../../Storage";
import { StorageAdapter } from "../../StorageAdapter"; import { StorageAdapter } from "../../StorageAdapter";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const cloudinaryAdapterConfig = Type.Object( export const cloudinaryAdapterConfig = Type.Object(
{ {
@@ -7,10 +7,12 @@ import type {
PutObjectRequest, PutObjectRequest,
} from "@aws-sdk/client-s3"; } from "@aws-sdk/client-s3";
import { AwsClient, isDebug } from "core"; import { AwsClient, isDebug } from "core";
import { type Static, Type, isFile, parse, pickHeaders2 } from "core/utils"; import { type Static, isFile, parse, pickHeaders2 } from "core/utils";
import { transform } from "lodash-es"; import { transform } from "lodash-es";
import type { FileBody, FileListObject } from "../../Storage"; import type { FileBody, FileListObject } from "../../Storage";
import { StorageAdapter } from "../../StorageAdapter"; import { StorageAdapter } from "../../StorageAdapter";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export const s3AdapterConfig = Type.Object( export const s3AdapterConfig = Type.Object(
{ {
+2 -1
View File
@@ -6,7 +6,6 @@ import {
Default, Default,
type Static, type Static,
StringEnum, StringEnum,
Type,
mark, mark,
objectEach, objectEach,
stripMark, stripMark,
@@ -34,6 +33,8 @@ import { AppFlows } from "../flows/AppFlows";
import { AppMedia } from "../media/AppMedia"; import { AppMedia } from "../media/AppMedia";
import type { ServerEnv } from "./Controller"; import type { ServerEnv } from "./Controller";
import { Module, type ModuleBuildContext } from "./Module"; import { Module, type ModuleBuildContext } from "./Module";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type { ModuleBuildContext }; export type { ModuleBuildContext };
+4 -2
View File
@@ -1,7 +1,9 @@
import { $console, Exception, isDebug } from "core"; import { Exception, isDebug, $console } from "core";
import { type Static, StringEnum, Type } from "core/utils"; import { type Static, StringEnum } from "core/utils";
import { cors } from "hono/cors"; import { cors } from "hono/cors";
import { Module } from "modules/Module"; import { Module } from "modules/Module";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const serverMethods = ["GET", "POST", "PATCH", "PUT", "DELETE"]; const serverMethods = ["GET", "POST", "PATCH", "PUT", "DELETE"];
+2 -1
View File
@@ -4,7 +4,6 @@ import type { App } from "App";
import { $console, tbValidator as tb } from "core"; import { $console, tbValidator as tb } from "core";
import { import {
StringEnum, StringEnum,
Type,
TypeInvalidError, TypeInvalidError,
datetimeStringLocal, datetimeStringLocal,
datetimeStringUTC, datetimeStringUTC,
@@ -14,6 +13,8 @@ import {
import { getRuntimeKey } from "core/utils"; import { getRuntimeKey } from "core/utils";
import type { Context, Hono } from "hono"; import type { Context, Hono } from "hono";
import { Controller } from "modules/Controller"; import { Controller } from "modules/Controller";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
import { import {
MODULE_NAMES, MODULE_NAMES,
+2 -1
View File
@@ -1,6 +1,7 @@
import { Type } from "core/utils";
import type { ModuleConfigs } from "modules/ModuleManager"; import type { ModuleConfigs } from "modules/ModuleManager";
import type { OpenAPIV3 as OAS } from "openapi-types"; import type { OpenAPIV3 as OAS } from "openapi-types";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
function prefixPaths(paths: OAS.PathsObject, prefix: string): OAS.PathsObject { function prefixPaths(paths: OAS.PathsObject, prefix: string): OAS.PathsObject {
const result: OAS.PathsObject = {}; const result: OAS.PathsObject = {};
@@ -1,4 +1,4 @@
import { Type, TypeInvalidError, parse, transformObject } from "core/utils"; import { TypeInvalidError, parse, transformObject } from "core/utils";
import { constructEntity } from "data"; import { constructEntity } from "data";
import { import {
type TAppDataEntity, type TAppDataEntity,
@@ -13,6 +13,8 @@ import {
import { useBknd } from "ui/client/bknd"; import { useBknd } from "ui/client/bknd";
import type { TSchemaActions } from "ui/client/schema/actions"; import type { TSchemaActions } from "ui/client/schema/actions";
import { bkndModals } from "ui/modals"; import { bkndModals } from "ui/modals";
import * as tb from "@sinclair/typebox";
const { Type } = tb;
export function useBkndData() { export function useBkndData() {
const { config, app, schema, actions: bkndActions } = useBknd(); const { config, app, schema, actions: bkndActions } = useBknd();
+2 -1
View File
@@ -1,6 +1,5 @@
import type { AppAuthOAuthStrategy, AppAuthSchema } from "auth/auth-schema"; import type { AppAuthOAuthStrategy, AppAuthSchema } from "auth/auth-schema";
import clsx from "clsx"; import clsx from "clsx";
import { Type } from "core/utils";
import { Form } from "json-schema-form-react"; import { Form } from "json-schema-form-react";
import { transform } from "lodash-es"; import { transform } from "lodash-es";
import type { ComponentPropsWithoutRef } from "react"; import type { ComponentPropsWithoutRef } from "react";
@@ -11,6 +10,8 @@ import type { ValueError } from "@sinclair/typebox/value";
import { type TSchema, Value } from "core/utils"; import { type TSchema, Value } from "core/utils";
import type { Validator } from "json-schema-form-react"; import type { Validator } from "json-schema-form-react";
import { useTheme } from "ui/client/use-theme"; import { useTheme } from "ui/client/use-theme";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
class TypeboxValidator implements Validator<ValueError> { class TypeboxValidator implements Validator<ValueError> {
async validate(schema: TSchema, data: any) { async validate(schema: TSchema, data: any) {
-1
View File
@@ -2,7 +2,6 @@ import {
type Static, type Static,
type StaticDecode, type StaticDecode,
type TSchema, type TSchema,
Type,
decodeSearch, decodeSearch,
encodeSearch, encodeSearch,
parseDecode, parseDecode,
@@ -1,6 +1,6 @@
import type { ModalProps } from "@mantine/core"; import type { ModalProps } from "@mantine/core";
import type { ContextModalProps } from "@mantine/modals"; import type { ContextModalProps } from "@mantine/modals";
import { type Static, StringEnum, StringIdentifier, Type } from "core/utils"; import { type Static, StringEnum, StringIdentifier } from "core/utils";
import { entitiesSchema, fieldsSchema, relationsSchema } from "data/data-schema"; import { entitiesSchema, fieldsSchema, relationsSchema } from "data/data-schema";
import { useState } from "react"; import { useState } from "react";
import { type Modal2Ref, ModalBody, ModalFooter, ModalTitle } from "ui/components/modal/Modal2"; import { type Modal2Ref, ModalBody, ModalFooter, ModalTitle } from "ui/components/modal/Modal2";
@@ -11,6 +11,8 @@ import { StepEntityFields } from "./step.entity.fields";
import { StepRelation } from "./step.relation"; import { StepRelation } from "./step.relation";
import { StepSelect } from "./step.select"; import { StepSelect } from "./step.select";
import Templates from "./templates/register"; import Templates from "./templates/register";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type CreateModalRef = Modal2Ref; export type CreateModalRef = Modal2Ref;
@@ -2,15 +2,9 @@ import { typeboxResolver } from "@hookform/resolvers/typebox";
import { Switch, TextInput } from "@mantine/core"; import { Switch, TextInput } from "@mantine/core";
import { TypeRegistry } from "@sinclair/typebox"; import { TypeRegistry } from "@sinclair/typebox";
import { IconDatabase } from "@tabler/icons-react"; import { IconDatabase } from "@tabler/icons-react";
import { import { type Static, StringEnum, StringIdentifier, registerCustomTypeboxKinds } from "core/utils";
type Static,
StringEnum,
StringIdentifier,
Type,
registerCustomTypeboxKinds,
} from "core/utils";
import { ManyToOneRelation, type RelationType, RelationTypes } from "data"; import { ManyToOneRelation, type RelationType, RelationTypes } from "data";
import { type ReactNode, startTransition, useEffect } from "react"; import type { ReactNode } from "react";
import { type Control, type FieldValues, type UseFormRegister, useForm } from "react-hook-form"; import { type Control, type FieldValues, type UseFormRegister, useForm } from "react-hook-form";
import { TbRefresh } from "react-icons/tb"; import { TbRefresh } from "react-icons/tb";
import { useBknd } from "ui/client/bknd"; import { useBknd } from "ui/client/bknd";
@@ -20,6 +14,8 @@ import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelec
import { useStepContext } from "ui/components/steps/Steps"; import { useStepContext } from "ui/components/steps/Steps";
import { useEvent } from "ui/hooks/use-event"; import { useEvent } from "ui/hooks/use-event";
import { ModalBody, ModalFooter, type TCreateModalSchema } from "./CreateModal"; import { ModalBody, ModalFooter, type TCreateModalSchema } from "./CreateModal";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
// @todo: check if this could become an issue // @todo: check if this could become an issue
registerCustomTypeboxKinds(TypeRegistry); registerCustomTypeboxKinds(TypeRegistry);
@@ -1,13 +1,6 @@
import { typeboxResolver } from "@hookform/resolvers/typebox"; import { typeboxResolver } from "@hookform/resolvers/typebox";
import { Radio, TextInput } from "@mantine/core"; import { Radio, TextInput } from "@mantine/core";
import { import { Default, type Static, StringEnum, StringIdentifier, transformObject } from "core/utils";
Default,
type Static,
StringEnum,
StringIdentifier,
Type,
transformObject,
} from "core/utils";
import type { MediaFieldConfig } from "media/MediaField"; import type { MediaFieldConfig } from "media/MediaField";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
@@ -22,6 +15,8 @@ import {
type TFieldCreate, type TFieldCreate,
useStepContext, useStepContext,
} from "../../CreateModal"; } from "../../CreateModal";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const schema = Type.Object({ const schema = Type.Object({
entity: StringIdentifier, entity: StringIdentifier,
@@ -1,9 +1,11 @@
import { Handle, type Node, type NodeProps, Position } from "@xyflow/react"; import { Handle, type Node, type NodeProps, Position } from "@xyflow/react";
import { Const, Type, transformObject } from "core/utils"; import { Const, transformObject } from "core/utils";
import { type Trigger, TriggerMap } from "flows"; import { type Trigger, TriggerMap } from "flows";
import type { IconType } from "react-icons"; import type { IconType } from "react-icons";
import { TbCircleLetterT } from "react-icons/tb"; import { TbCircleLetterT } from "react-icons/tb";
import { JsonSchemaForm } from "ui/components/form/json-schema"; import { JsonSchemaForm } from "ui/components/form/json-schema";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export type TaskComponentProps = NodeProps<Node<{ trigger: Trigger }>> & { export type TaskComponentProps = NodeProps<Node<{ trigger: Trigger }>> & {
Icon?: IconType; Icon?: IconType;
@@ -4,7 +4,6 @@ import { useToggle } from "@mantine/hooks";
import { IconMinus, IconPlus, IconWorld } from "@tabler/icons-react"; import { IconMinus, IconPlus, IconWorld } from "@tabler/icons-react";
import type { Node, NodeProps } from "@xyflow/react"; import type { Node, NodeProps } from "@xyflow/react";
import type { Static } from "core/utils"; import type { Static } from "core/utils";
import { Type } from "core/utils";
import { FetchTask } from "flows"; import { FetchTask } from "flows";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
@@ -15,6 +14,8 @@ import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelec
import { type TFlowNodeData, useFlowSelector } from "../../../hooks/use-flow"; import { type TFlowNodeData, useFlowSelector } from "../../../hooks/use-flow";
import { KeyValueInput } from "../../form/KeyValueInput"; import { KeyValueInput } from "../../form/KeyValueInput";
import { BaseNode } from "../BaseNode"; import { BaseNode } from "../BaseNode";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const schema = Type.Composite([ const schema = Type.Composite([
FetchTask.schema, FetchTask.schema,
@@ -1,20 +1,9 @@
import { typeboxResolver } from "@hookform/resolvers/typebox"; import { typeboxResolver } from "@hookform/resolvers/typebox";
import { TextInput } from "@mantine/core"; import { TextInput } from "@mantine/core";
import { TypeRegistry } from "@sinclair/typebox"; import type { Node, NodeProps } from "@xyflow/react";
import { Clean } from "@sinclair/typebox/value"; import { Const, type Static, registerCustomTypeboxKinds, transformObject } from "core/utils";
import { type Node, type NodeProps, Position } from "@xyflow/react";
import {
Const,
type Static,
StringEnum,
Type,
registerCustomTypeboxKinds,
transformObject,
} from "core/utils";
import { TriggerMap } from "flows"; import { TriggerMap } from "flows";
import type { TAppFlowTriggerSchema } from "flows/AppFlows"; import type { TAppFlowTriggerSchema } from "flows/AppFlows";
import { isEqual } from "lodash-es";
import { useEffect } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { JsonViewer } from "ui/components/code/JsonViewer"; import { JsonViewer } from "ui/components/code/JsonViewer";
import { MantineSegmentedControl } from "ui/components/form/hook-form-mantine/MantineSegmentedControl"; import { MantineSegmentedControl } from "ui/components/form/hook-form-mantine/MantineSegmentedControl";
@@ -22,6 +11,8 @@ import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelec
import { useFlowCanvas, useFlowSelector } from "../../../hooks/use-flow"; import { useFlowCanvas, useFlowSelector } from "../../../hooks/use-flow";
import { BaseNode } from "../BaseNode"; import { BaseNode } from "../BaseNode";
import { Handle } from "../Handle"; import { Handle } from "../Handle";
import * as tb from "@sinclair/typebox";
const { Type, TypeRegistry } = tb;
// @todo: check if this could become an issue // @todo: check if this could become an issue
registerCustomTypeboxKinds(TypeRegistry); registerCustomTypeboxKinds(TypeRegistry);
+1 -1
View File
@@ -1,6 +1,6 @@
import clsx from "clsx"; import clsx from "clsx";
import { isDebug } from "core"; import { isDebug } from "core";
import { TbAlertCircle, TbChevronDown, TbChevronUp } from "react-icons/tb"; import { TbChevronDown, TbChevronUp } from "react-icons/tb";
import { useBknd } from "ui/client/BkndProvider"; import { useBknd } from "ui/client/BkndProvider";
import { useBkndAuth } from "ui/client/schema/auth/use-bknd-auth"; import { useBkndAuth } from "ui/client/schema/auth/use-bknd-auth";
import { Button } from "ui/components/buttons/Button"; import { Button } from "ui/components/buttons/Button";
@@ -1,4 +1,3 @@
import { Type } from "core/utils";
import type { EntityData } from "data"; import type { EntityData } from "data";
import { useState } from "react"; import { useState } from "react";
import { useEntityMutate } from "ui/client"; import { useEntityMutate } from "ui/client";
@@ -12,6 +11,8 @@ import { Breadcrumbs2 } from "ui/layouts/AppShell/Breadcrumbs2";
import { routes } from "ui/lib/routes"; import { routes } from "ui/lib/routes";
import { EntityForm } from "ui/modules/data/components/EntityForm"; import { EntityForm } from "ui/modules/data/components/EntityForm";
import { useEntityForm } from "ui/modules/data/hooks/useEntityForm"; import { useEntityForm } from "ui/modules/data/hooks/useEntityForm";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
export function DataEntityCreate({ params }) { export function DataEntityCreate({ params }) {
const { $data } = useBkndData(); const { $data } = useBkndData();
@@ -1,4 +1,3 @@
import { Type } from "core/utils";
import { type Entity, querySchema } from "data"; import { type Entity, querySchema } from "data";
import { Fragment } from "react"; import { Fragment } from "react";
import { TbDots } from "react-icons/tb"; import { TbDots } from "react-icons/tb";
@@ -15,6 +14,8 @@ import * as AppShell from "ui/layouts/AppShell/AppShell";
import { routes, useNavigate } from "ui/lib/routes"; import { routes, useNavigate } from "ui/lib/routes";
import { useCreateUserModal } from "ui/modules/auth/hooks/use-create-user-modal"; import { useCreateUserModal } from "ui/modules/auth/hooks/use-create-user-modal";
import { EntityTable2 } from "ui/modules/data/components/EntityTable2"; import { EntityTable2 } from "ui/modules/data/components/EntityTable2";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
// @todo: migrate to Typebox // @todo: migrate to Typebox
const searchSchema = Type.Composite( const searchSchema = Type.Composite(
@@ -5,7 +5,6 @@ import {
Default, Default,
type Static, type Static,
StringIdentifier, StringIdentifier,
Type,
objectCleanEmpty, objectCleanEmpty,
ucFirstAllSnakeToPascalWithSpaces, ucFirstAllSnakeToPascalWithSpaces,
} from "core/utils"; } from "core/utils";
@@ -27,6 +26,8 @@ import { type SortableItemProps, SortableList } from "ui/components/list/Sortabl
import { Popover } from "ui/components/overlay/Popover"; import { Popover } from "ui/components/overlay/Popover";
import { type TFieldSpec, fieldSpecs } from "ui/modules/data/components/fields-specs"; import { type TFieldSpec, fieldSpecs } from "ui/modules/data/components/fields-specs";
import { dataFieldsUiSchema } from "../../settings/routes/data.settings"; import { dataFieldsUiSchema } from "../../settings/routes/data.settings";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
const fieldsSchemaObject = originalFieldsSchemaObject; const fieldsSchemaObject = originalFieldsSchemaObject;
const fieldsSchema = Type.Union(Object.values(fieldsSchemaObject)); const fieldsSchema = Type.Union(Object.values(fieldsSchemaObject));
@@ -2,13 +2,7 @@ import { typeboxResolver } from "@hookform/resolvers/typebox";
import { TextInput } from "@mantine/core"; import { TextInput } from "@mantine/core";
import { useFocusTrap } from "@mantine/hooks"; import { useFocusTrap } from "@mantine/hooks";
import { TypeRegistry } from "@sinclair/typebox"; import { TypeRegistry } from "@sinclair/typebox";
import { import { type Static, StringEnum, StringIdentifier, registerCustomTypeboxKinds } from "core/utils";
type Static,
StringEnum,
StringIdentifier,
Type,
registerCustomTypeboxKinds,
} from "core/utils";
import { TRIGGERS } from "flows/flows-schema"; import { TRIGGERS } from "flows/flows-schema";
import { forwardRef, useState } from "react"; import { forwardRef, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
@@ -22,6 +16,8 @@ import {
ModalTitle, ModalTitle,
} from "../../../components/modal/Modal2"; } from "../../../components/modal/Modal2";
import { Step, Steps, useStepContext } from "../../../components/steps/Steps"; import { Step, Steps, useStepContext } from "../../../components/steps/Steps";
import * as tbbox from "@sinclair/typebox";
const { Type } = tbbox;
registerCustomTypeboxKinds(TypeRegistry); registerCustomTypeboxKinds(TypeRegistry);
+1
View File
@@ -2,6 +2,7 @@
"compilerOptions": { "compilerOptions": {
"types": ["bun-types", "@cloudflare/workers-types"], "types": ["bun-types", "@cloudflare/workers-types"],
"composite": false, "composite": false,
"incremental": true,
"module": "ESNext", "module": "ESNext",
"moduleResolution": "bundler", "moduleResolution": "bundler",
"jsx": "react-jsx", "jsx": "react-jsx",