mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 08:36:01 +00:00
fixes
This commit is contained in:
@@ -6,7 +6,8 @@ import { s } from "core/object/schema";
|
||||
|
||||
export const booleanFieldConfigSchema = s
|
||||
.strictObject({
|
||||
default_value: s.boolean({ default: false }),
|
||||
//default_value: s.boolean({ default: false }),
|
||||
default_value: s.boolean(),
|
||||
...omitKeys(baseFieldConfigSchema.properties, ["default_value"]),
|
||||
})
|
||||
.partial();
|
||||
|
||||
@@ -7,11 +7,11 @@ import { s } from "core/object/schema";
|
||||
|
||||
export const dateFieldConfigSchema = s
|
||||
.strictObject({
|
||||
type: s.string({ enum: ["date", "datetime", "week"], default: "date" }),
|
||||
type: s.string({ enum: ["date", "datetime", "week"] }),
|
||||
timezone: s.string(),
|
||||
min_date: s.string(),
|
||||
max_date: s.string(),
|
||||
...omitKeys(baseFieldConfigSchema.properties, ["default_value"]),
|
||||
...baseFieldConfigSchema.properties,
|
||||
})
|
||||
.partial();
|
||||
|
||||
|
||||
@@ -27,26 +27,16 @@ export const baseFieldConfigSchema = s
|
||||
.strictObject({
|
||||
label: s.string(),
|
||||
description: s.string(),
|
||||
required: s.boolean({ default: DEFAULT_REQUIRED }),
|
||||
fillable: s.anyOf(
|
||||
[
|
||||
s.boolean({ title: "Boolean", default: DEFAULT_FILLABLE }),
|
||||
s.array(s.string({ enum: ActionContext }), { title: "Context", uniqueItems: true }),
|
||||
],
|
||||
{
|
||||
default: DEFAULT_FILLABLE,
|
||||
},
|
||||
),
|
||||
hidden: s.anyOf(
|
||||
[
|
||||
s.boolean({ title: "Boolean", default: DEFAULT_HIDDEN }),
|
||||
// @todo: tmp workaround
|
||||
s.array(s.string({ enum: TmpContext }), { title: "Context", uniqueItems: true }),
|
||||
],
|
||||
{
|
||||
default: DEFAULT_HIDDEN,
|
||||
},
|
||||
),
|
||||
required: s.boolean(),
|
||||
fillable: s.anyOf([
|
||||
s.boolean({ title: "Boolean" }),
|
||||
s.array(s.string({ enum: ActionContext }), { title: "Context", uniqueItems: true }),
|
||||
]),
|
||||
hidden: s.anyOf([
|
||||
s.boolean({ title: "Boolean" }),
|
||||
// @todo: tmp workaround
|
||||
s.array(s.string({ enum: TmpContext }), { title: "Context", uniqueItems: true }),
|
||||
]),
|
||||
// if field is virtual, it will not call transformPersist & transformRetrieve
|
||||
virtual: s.boolean(),
|
||||
default_value: s.any(),
|
||||
@@ -100,7 +90,9 @@ export abstract class Field<
|
||||
name: this.name,
|
||||
type: "text",
|
||||
nullable: true,
|
||||
dflt: this.getDefault(),
|
||||
// see field-test-suite.ts:41
|
||||
dflt: undefined,
|
||||
//dflt: this.getDefault(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -116,14 +108,14 @@ export abstract class Field<
|
||||
if (Array.isArray(this.config.fillable)) {
|
||||
return context ? this.config.fillable.includes(context) : DEFAULT_FILLABLE;
|
||||
}
|
||||
return !!this.config.fillable;
|
||||
return this.config.fillable ?? DEFAULT_FILLABLE;
|
||||
}
|
||||
|
||||
isHidden(context?: TmpActionAndRenderContext): boolean {
|
||||
if (Array.isArray(this.config.hidden)) {
|
||||
return context ? this.config.hidden.includes(context as any) : DEFAULT_HIDDEN;
|
||||
}
|
||||
return this.config.hidden ?? false;
|
||||
return this.config.hidden ?? DEFAULT_HIDDEN;
|
||||
}
|
||||
|
||||
isRequired(): boolean {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type Schema as JsonSchema, Validator } from "@cfworker/json-schema";
|
||||
import { FromSchema, objectToJsLiteral, omitKeys } from "core/utils";
|
||||
import { objectToJsLiteral } from "core/utils";
|
||||
import type { EntityManager } from "data";
|
||||
import { TransformPersistFailedException } from "../errors";
|
||||
import { Field, type TActionContext, type TRenderContext, baseFieldConfigSchema } from "./Field";
|
||||
@@ -8,10 +8,10 @@ import { s } from "core/object/schema";
|
||||
|
||||
export const jsonSchemaFieldConfigSchema = s
|
||||
.strictObject({
|
||||
schema: s.any({ type: "object", default: {} }),
|
||||
ui_schema: s.any({ type: "object", default: {} }),
|
||||
schema: s.any({ type: "object" }),
|
||||
ui_schema: s.any({ type: "object" }),
|
||||
default_from_schema: s.boolean(),
|
||||
...omitKeys(baseFieldConfigSchema.properties, ["default_value"]),
|
||||
...baseFieldConfigSchema.properties,
|
||||
})
|
||||
.partial();
|
||||
|
||||
@@ -26,7 +26,7 @@ export class JsonSchemaField<
|
||||
|
||||
constructor(name: string, config: Partial<JsonSchemaFieldConfig>) {
|
||||
super(name, config);
|
||||
this.validator = new Validator(this.getJsonSchema());
|
||||
this.validator = new Validator({ ...this.getJsonSchema() });
|
||||
}
|
||||
|
||||
protected getSchema() {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { omitKeys, uuidv7 } from "core/utils";
|
||||
import { Field, baseFieldConfigSchema } from "./Field";
|
||||
import type { TFieldTSType } from "data/entities/EntityTypescript";
|
||||
import { s } from "core/object/schema";
|
||||
import type { FieldSpec } from "data/connection/Connection";
|
||||
|
||||
export const primaryFieldTypes = ["integer", "uuid"] as const;
|
||||
export type TPrimaryFieldFormat = (typeof primaryFieldTypes)[number];
|
||||
@@ -26,7 +25,7 @@ export class PrimaryField<Required extends true | false = false> extends Field<
|
||||
override readonly type = "primary";
|
||||
|
||||
constructor(name: string = config.data.default_primary_field, cfg?: PrimaryFieldConfig) {
|
||||
super(name, { fillable: false, required: false, ...cfg });
|
||||
super(name, { ...cfg, fillable: false, required: false });
|
||||
}
|
||||
|
||||
override isRequired(): boolean {
|
||||
|
||||
@@ -10,8 +10,8 @@ export const textFieldConfigSchema = s
|
||||
minLength: s.number(),
|
||||
maxLength: s.number(),
|
||||
pattern: s.string(),
|
||||
html_config: s.object({
|
||||
element: s.string({ default: "input" }),
|
||||
html_config: s.partialObject({
|
||||
element: s.string(),
|
||||
props: s.record(s.anyOf([s.string({ title: "String" }), s.number({ title: "Number" })])),
|
||||
}),
|
||||
...omitKeys(baseFieldConfigSchema.properties, ["default_value"]),
|
||||
|
||||
@@ -50,7 +50,7 @@ export function fieldTestSuite(
|
||||
expect(noConfigField.hasDefault()).toBe(false);
|
||||
expect(noConfigField.getDefault()).toBeUndefined();
|
||||
expect(dflt.hasDefault()).toBe(true);
|
||||
expect(dflt.getDefault()).toBe(config.defaultValue);
|
||||
expect(dflt.getDefault()).toEqual(config.defaultValue);
|
||||
});
|
||||
|
||||
test("isFillable", async () => {
|
||||
@@ -98,9 +98,6 @@ export function fieldTestSuite(
|
||||
test("toJSON", async () => {
|
||||
const _config = {
|
||||
..._requiredConfig,
|
||||
fillable: true,
|
||||
required: false,
|
||||
hidden: false,
|
||||
};
|
||||
|
||||
function fieldJson(field: Field) {
|
||||
@@ -118,7 +115,10 @@ export function fieldTestSuite(
|
||||
|
||||
expect(fieldJson(fillable)).toEqual({
|
||||
type: noConfigField.type,
|
||||
config: _config,
|
||||
config: {
|
||||
..._config,
|
||||
fillable: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(fieldJson(required)).toEqual({
|
||||
|
||||
Reference in New Issue
Block a user