mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
Release 0.12 (#143)
* changed tb imports * cleanup: replace console.log/warn with $console, remove commented-out code Removed various commented-out code and replaced direct `console.log` and `console.warn` usage across the codebase with `$console` from "core" for standardized logging. Also adjusted linting rules in biome.json to enable warnings for `console.log` usage. * ts: enable incremental * fix imports in test files reorganize imports to use "@sinclair/typebox" directly, replacing local utility references, and add missing "override" keywords in test classes. * added media permissions (#142) * added permissions support for media module introduced `MediaPermissions` for fine-grained access control in the media module, updated routes to enforce these permissions, and adjusted permission registration logic. * fix: handle token absence in getUploadHeaders and add tests for transport modes ensure getUploadHeaders does not set Authorization header when token is missing. Add unit tests to validate behavior for different token_transport options. * remove console.log on DropzoneContainer.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * add bcrypt and refactored auth resolve (#147) * reworked auth architecture with improved password handling and claims Refactored password strategy to prepare supporting bcrypt, improving hashing/encryption flexibility. Updated authentication flow with enhanced user resolution mechanisms, safe JWT generation, and consistent profile handling. Adjusted dependencies to include bcryptjs and updated lock files accordingly. * fix strategy forms handling, add register route and hidden fields Refactored strategy forms to include hidden fields for type and name. Added a registration route with necessary adjustments to the admin controller and routes. Corrected field handling within relevant forms and components. * refactored auth handling to support bcrypt, extracted user pool * update email regex to allow '+' and '_' characters * update test stub password for AppAuth spec * update data exceptions to use HttpStatus constants, adjust logging level in AppUserPool * rework strategies to extend a base class instead of interface * added simple bcrypt test * add validation logs and improve data validation handling (#157) Added warning logs for invalid data during mutator validation, refined field validation logic to handle undefined values, and adjusted event validation comments for clarity. Minor improvements include exporting events from core and handling optional chaining in entity field validation. * modify MediaApi to support custom fetch implementation, defaults to native fetch (#158) * modify MediaApi to support custom fetch implementation, defaults to native fetch added an optional `fetcher` parameter to allow usage of a custom fetch function in both `upload` and `fetcher` methods. Defaults to the standard `fetch` if none is provided. * fix tests and improve api fetcher types * update admin basepath handling and window context integration (#155) Refactored `useBkndWindowContext` to include `admin_basepath` and updated its usage in routing. Improved type consistency with `AdminBkndWindowContext` and ensured default values are applied for window context. * trigger `repository-find-[one|many]-[before|after]` based on `limit` (#160) * refactor error handling in authenticator and password strategy (#161) made `respondWithError` method public, updated login and register routes in `PasswordStrategy` to handle errors using `respondWithError` for consistency. * add disableSubmitOnError prop to NativeForm and export getFlashMessage (#162) Introduced a `disableSubmitOnError` prop to NativeForm to control submit button behavior when errors are present. Also exported `getFlashMessage` from the core for external usage. * update dependencies in package.json (#156) moved several dependencies between devDependencies and dependencies for better categorization and removed redundant entries. * update imports to adjust nodeTestRunner path and remove unused export (#163) updated imports in test files to reflect the correct path for nodeTestRunner. removed redundant export of nodeTestRunner from index file to clean up module structure. In some environments this could cause issues requiring to exclude `node:test`, just removing it for now. * fix sync events not awaited (#164) * refactor(dropzone): extract DropzoneInner and unify state management with zustand (#165) Simplified Dropzone implementation by extracting inner logic to a new component, `DropzoneInner`. Replaced local dropzone state logic with centralized state management using zustand. Adjusted API exports and props accordingly for consistency and maintainability. * replace LiquidJs rendering with simplified renderer (#167) * replace LiquidJs rendering with simplified renderer Removed dependency on LiquidJS and replaced it with a custom templating solution using lodash `get`. Updated corresponding components, editors, and tests to align with the new rendering approach. Removed unused filters and tags. * remove liquid js from package json * feat/cli-generate-types (#166) * init types generation * update type generation for entities and fields Refactored `EntityTypescript` to support improved field types and relations. Added `toType` method overrides for various fields to define accurate TypeScript types. Enhanced CLI `types` command with new options for output style and file handling. Removed redundant test files. * update type generation code and CLI option description removed unused imports definition, adjusted formatting in EntityTypescript, and clarified the CLI style option description. * fix json schema field type generation * reworked system entities to prevent recursive types * reworked system entities to prevent recursive types * remove unused object function * types: use number instead of Generated * update data hooks and api types * update data hooks and api types * update data hooks and api types * update data hooks and api types --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -9,13 +9,11 @@ export class DebugLogger {
|
||||
}
|
||||
|
||||
context(context: string) {
|
||||
//console.log("[ settings context ]", context, this._context);
|
||||
this._context.push(context);
|
||||
return this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
//console.log("[ clear context ]", this._context.pop(), this._context);
|
||||
this._context.pop();
|
||||
return this;
|
||||
}
|
||||
@@ -33,6 +31,8 @@ export class DebugLogger {
|
||||
const indents = " ".repeat(Math.max(this._context.length - 1, 0));
|
||||
const context =
|
||||
this._context.length > 0 ? `[${this._context[this._context.length - 1]}]` : "";
|
||||
|
||||
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
||||
console.log(indents, context, time, ...args);
|
||||
|
||||
this.last = now;
|
||||
|
||||
@@ -4,7 +4,6 @@ import weekOfYear from "dayjs/plugin/weekOfYear.js";
|
||||
declare module "dayjs" {
|
||||
interface Dayjs {
|
||||
week(): number;
|
||||
|
||||
week(value: number): dayjs.Dayjs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { extension, guess, isMimeType } from "media/storage/mime-types-tiny";
|
||||
import { randomString } from "core/utils/strings";
|
||||
import type { Context } from "hono";
|
||||
import { invariant } from "core/utils/runtime";
|
||||
import { $console } from "../console";
|
||||
|
||||
export function getContentName(request: Request): string | undefined;
|
||||
export function getContentName(contentDisposition: string): string | undefined;
|
||||
@@ -130,7 +131,7 @@ export async function getFileFromContext(c: Context<any>): Promise<File> {
|
||||
return await blobToFile(v);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error parsing form data", e);
|
||||
$console.warn("Error parsing form data", e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@@ -141,7 +142,7 @@ export async function getFileFromContext(c: Context<any>): Promise<File> {
|
||||
return await blobToFile(blob, { name: getContentName(c.req.raw), type: contentType });
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Error parsing blob", e);
|
||||
$console.warn("Error parsing blob", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -359,3 +359,50 @@ export function getPath(
|
||||
throw new Error(`Invalid path: ${path.join(".")}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function objectToJsLiteral(value: object, indent: number = 0, _level: number = 0): string {
|
||||
const nl = indent ? "\n" : "";
|
||||
const pad = (lvl: number) => (indent ? " ".repeat(indent * lvl) : "");
|
||||
const openPad = pad(_level + 1);
|
||||
const closePad = pad(_level);
|
||||
|
||||
// primitives
|
||||
if (value === null) return "null";
|
||||
if (value === undefined) return "undefined";
|
||||
const t = typeof value;
|
||||
if (t === "string") return JSON.stringify(value); // handles escapes
|
||||
if (t === "number" || t === "boolean") return String(value);
|
||||
|
||||
// arrays
|
||||
if (Array.isArray(value)) {
|
||||
const out = value
|
||||
.map((v) => objectToJsLiteral(v, indent, _level + 1))
|
||||
.join(", " + (indent ? nl + openPad : ""));
|
||||
return (
|
||||
"[" +
|
||||
(indent && value.length ? nl + openPad : "") +
|
||||
out +
|
||||
(indent && value.length ? nl + closePad : "") +
|
||||
"]"
|
||||
);
|
||||
}
|
||||
|
||||
// objects
|
||||
if (t === "object") {
|
||||
const entries = Object.entries(value).map(([k, v]) => {
|
||||
const idOk = /^[A-Za-z_$][\w$]*$/.test(k); // valid identifier?
|
||||
const key = idOk ? k : JSON.stringify(k); // quote if needed
|
||||
return key + ": " + objectToJsLiteral(v, indent, _level + 1);
|
||||
});
|
||||
const out = entries.join(", " + (indent ? nl + openPad : ""));
|
||||
return (
|
||||
"{" +
|
||||
(indent && entries.length ? nl + openPad : "") +
|
||||
out +
|
||||
(indent && entries.length ? nl + closePad : "") +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
throw new TypeError(`Unsupported data type: ${t}`);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import { randomString } from "core/utils/strings";
|
||||
import type { Context } from "hono";
|
||||
import { extension, guess, isMimeType } from "media/storage/mime-types-tiny";
|
||||
|
||||
export function headersToObject(headers: Headers): Record<string, string> {
|
||||
if (!headers) return {};
|
||||
return { ...Object.fromEntries(headers.entries()) };
|
||||
@@ -102,7 +98,7 @@ export function decodeSearch(str) {
|
||||
export const enum HttpStatus {
|
||||
// Informational responses (100–199)
|
||||
CONTINUE = 100,
|
||||
SWITCHING_PROTOCOLS = 101,
|
||||
//SWITCHING_PROTOCOLS = 101,
|
||||
PROCESSING = 102,
|
||||
EARLY_HINTS = 103,
|
||||
|
||||
@@ -111,8 +107,8 @@ export const enum HttpStatus {
|
||||
CREATED = 201,
|
||||
ACCEPTED = 202,
|
||||
NON_AUTHORITATIVE_INFORMATION = 203,
|
||||
NO_CONTENT = 204,
|
||||
RESET_CONTENT = 205,
|
||||
//NO_CONTENT = 204,
|
||||
//RESET_CONTENT = 205,
|
||||
PARTIAL_CONTENT = 206,
|
||||
MULTI_STATUS = 207,
|
||||
ALREADY_REPORTED = 208,
|
||||
@@ -123,7 +119,7 @@ export const enum HttpStatus {
|
||||
MOVED_PERMANENTLY = 301,
|
||||
FOUND = 302,
|
||||
SEE_OTHER = 303,
|
||||
NOT_MODIFIED = 304,
|
||||
//NOT_MODIFIED = 304,
|
||||
USE_PROXY = 305,
|
||||
TEMPORARY_REDIRECT = 307,
|
||||
PERMANENT_REDIRECT = 308,
|
||||
@@ -172,3 +168,13 @@ export const enum HttpStatus {
|
||||
NOT_EXTENDED = 510,
|
||||
NETWORK_AUTHENTICATION_REQUIRED = 511,
|
||||
}
|
||||
// biome-ignore lint/suspicious/noConstEnum: <explanation>
|
||||
export const enum HttpStatusEmpty {
|
||||
// Informational responses (100–199)
|
||||
SWITCHING_PROTOCOLS = 101,
|
||||
// Successful responses (200–299)
|
||||
NO_CONTENT = 204,
|
||||
RESET_CONTENT = 205,
|
||||
// Redirection messages (300–399)
|
||||
NOT_MODIFIED = 304,
|
||||
}
|
||||
|
||||
@@ -132,3 +132,8 @@ export function slugify(str: string): string {
|
||||
.replace(/-+/g, "-") // remove consecutive hyphens
|
||||
);
|
||||
}
|
||||
|
||||
export function truncate(str: string, length = 50, end = "..."): string {
|
||||
if (str.length <= length) return str;
|
||||
return str.substring(0, length) + end;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
import {
|
||||
Kind,
|
||||
type ObjectOptions,
|
||||
type SchemaOptions,
|
||||
type Static,
|
||||
type StaticDecode,
|
||||
type StringOptions,
|
||||
type TLiteral,
|
||||
type TLiteralValue,
|
||||
type TObject,
|
||||
type TRecord,
|
||||
type TSchema,
|
||||
type TString,
|
||||
Type,
|
||||
import * as tb from "@sinclair/typebox";
|
||||
import type {
|
||||
TypeRegistry,
|
||||
Static,
|
||||
StaticDecode,
|
||||
TSchema,
|
||||
SchemaOptions,
|
||||
TObject,
|
||||
} from "@sinclair/typebox";
|
||||
import {
|
||||
DefaultErrorFunction,
|
||||
@@ -43,7 +36,7 @@ const validationSymbol = Symbol("tb-parse-validation");
|
||||
export class TypeInvalidError extends Error {
|
||||
errors: ValueError[];
|
||||
constructor(
|
||||
public schema: TSchema,
|
||||
public schema: tb.TSchema,
|
||||
public data: unknown,
|
||||
message?: string,
|
||||
) {
|
||||
@@ -92,29 +85,28 @@ 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,
|
||||
data: RecursivePartial<Static<Schema>>,
|
||||
data: RecursivePartial<tb.Static<Schema>>,
|
||||
options?: ParseOptions,
|
||||
): Static<Schema> {
|
||||
): tb.Static<Schema> {
|
||||
if (!options?.forceParse && typeof data === "object" && validationSymbol in data) {
|
||||
if (options?.useDefaults === false) {
|
||||
return data as Static<typeof schema>;
|
||||
return data as tb.Static<typeof schema>;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if (Check(schema, parsed)) {
|
||||
options?.skipMark !== true && mark(parsed, true);
|
||||
return parsed as Static<typeof schema>;
|
||||
return parsed as tb.Static<typeof schema>;
|
||||
} else if (options?.onError) {
|
||||
options.onError(Errors(schema, data));
|
||||
} else {
|
||||
//console.warn("errors", JSON.stringify([...Errors(schema, data)], null, 2));
|
||||
throw new TypeInvalidError(schema, data);
|
||||
}
|
||||
|
||||
@@ -122,26 +114,24 @@ export function parse<Schema extends TSchema = TSchema>(
|
||||
return undefined as any;
|
||||
}
|
||||
|
||||
export function parseDecode<Schema extends TSchema = TSchema>(
|
||||
export function parseDecode<Schema extends tb.TSchema = tb.TSchema>(
|
||||
schema: Schema,
|
||||
data: RecursivePartial<StaticDecode<Schema>>,
|
||||
): StaticDecode<Schema> {
|
||||
//console.log("parseDecode", schema, data);
|
||||
data: RecursivePartial<tb.StaticDecode<Schema>>,
|
||||
): tb.StaticDecode<Schema> {
|
||||
const parsed = Default(schema, data);
|
||||
|
||||
if (Check(schema, parsed)) {
|
||||
return parsed as StaticDecode<typeof schema>;
|
||||
return parsed as tb.StaticDecode<typeof schema>;
|
||||
}
|
||||
//console.log("errors", ...Errors(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,
|
||||
data: Static<Schema>,
|
||||
data: tb.Static<Schema>,
|
||||
options?: ParseOptions,
|
||||
): Static<Schema> {
|
||||
): tb.Static<Schema> {
|
||||
return parse(schema, data as any, options);
|
||||
}
|
||||
|
||||
@@ -150,11 +140,14 @@ export function registerCustomTypeboxKinds(registry: typeof TypeRegistry) {
|
||||
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) =>
|
||||
Type.Unsafe<T[number]>({
|
||||
[Kind]: "StringEnum",
|
||||
export const StringEnum = <const T extends readonly string[]>(
|
||||
values: T,
|
||||
options?: tb.StringOptions,
|
||||
) =>
|
||||
tb.Type.Unsafe<T[number]>({
|
||||
[tb.Kind]: "StringEnum",
|
||||
type: "string",
|
||||
enum: values,
|
||||
...options,
|
||||
@@ -162,45 +155,47 @@ export const StringEnum = <const T extends readonly string[]>(values: T, options
|
||||
|
||||
// key value record compatible with RJSF and typebox inference
|
||||
// acting like a Record, but using an Object with additionalProperties
|
||||
export const StringRecord = <T extends TSchema>(properties: T, options?: ObjectOptions) =>
|
||||
Type.Object({}, { ...options, additionalProperties: properties }) as unknown as TRecord<
|
||||
TString,
|
||||
export const StringRecord = <T extends tb.TSchema>(properties: T, options?: tb.ObjectOptions) =>
|
||||
tb.Type.Object({}, { ...options, additionalProperties: properties }) as unknown as tb.TRecord<
|
||||
tb.TString,
|
||||
typeof properties
|
||||
>;
|
||||
|
||||
// fixed value that only be what is given + prefilled
|
||||
export const Const = <T extends TLiteralValue = TLiteralValue>(value: T, options?: SchemaOptions) =>
|
||||
Type.Literal(value, { ...options, default: value, const: value, readOnly: true }) as TLiteral<T>;
|
||||
export const Const = <T extends tb.TLiteralValue = tb.TLiteralValue>(
|
||||
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_]*$",
|
||||
minLength: 2,
|
||||
maxLength: 150,
|
||||
});
|
||||
|
||||
export const StrictObject = <T extends tb.TProperties>(
|
||||
properties: T,
|
||||
options?: tb.ObjectOptions,
|
||||
): tb.TObject<T> => tb.Type.Object(properties, { ...options, additionalProperties: false });
|
||||
|
||||
SetErrorFunction((error) => {
|
||||
if (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 DefaultErrorFunction(error);
|
||||
});
|
||||
|
||||
export {
|
||||
Type,
|
||||
type Static,
|
||||
type StaticDecode,
|
||||
type TSchema,
|
||||
Kind,
|
||||
type TObject,
|
||||
type ValueError,
|
||||
type SchemaOptions,
|
||||
Value,
|
||||
Default,
|
||||
Errors,
|
||||
Check,
|
||||
};
|
||||
export type { Static, StaticDecode, TSchema, TObject, ValueError, SchemaOptions };
|
||||
|
||||
export { Value, Default, Errors, Check };
|
||||
|
||||
Reference in New Issue
Block a user