@lobb-js/core 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/api/meta/service.ts
CHANGED
|
@@ -63,6 +63,7 @@ export class MetaService {
|
|
|
63
63
|
field.type = fieldConfig.type;
|
|
64
64
|
field.label = fieldName;
|
|
65
65
|
field.key = fieldName;
|
|
66
|
+
field.enum = "enum" in fieldConfig ? fieldConfig.enum : undefined;
|
|
66
67
|
field.validators = fieldConfig.validators;
|
|
67
68
|
field.pre_processors = fieldConfig.pre_processors;
|
|
68
69
|
field.ui = fieldConfig.ui;
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,8 @@ export type { CollectionFieldsWithoutId } from "./types/config/collectionsConfig
|
|
|
28
28
|
export type {
|
|
29
29
|
CollectionField,
|
|
30
30
|
CollectionFieldBase,
|
|
31
|
+
EnumOption,
|
|
32
|
+
EnumLevel,
|
|
31
33
|
} from "./types/config/collectionFields.ts";
|
|
32
34
|
export type { Dashboard, Extension } from "./types/Extension.ts";
|
|
33
35
|
export { Field } from "./types/Field.ts";
|
|
@@ -2,6 +2,17 @@ import { RelationCollectionFieldSchema } from "./relations.ts";
|
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
+
export type EnumLevel = "success" | "warning" | "danger" | "info" | "neutral" | "muted";
|
|
6
|
+
|
|
7
|
+
export const EnumOptionSchema = z.object({
|
|
8
|
+
value: z.string(),
|
|
9
|
+
level: z.enum(["success", "warning", "danger", "info", "neutral", "muted"]),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type EnumOption = z.infer<typeof EnumOptionSchema>;
|
|
13
|
+
|
|
14
|
+
const StringEnumSchema = z.union([z.array(z.string()), z.array(EnumOptionSchema)]);
|
|
15
|
+
|
|
5
16
|
// Define the UiInput schema
|
|
6
17
|
const UiInputSchema = z.object({
|
|
7
18
|
type: z.string(),
|
|
@@ -93,19 +104,19 @@ export const CollectionStringFieldSchema = CollectionFieldBaseSchema.extend({
|
|
|
93
104
|
type: z.literal("string"),
|
|
94
105
|
length: z.number(),
|
|
95
106
|
default: z.string().optional(),
|
|
96
|
-
enum:
|
|
107
|
+
enum: StringEnumSchema.optional(),
|
|
97
108
|
});
|
|
98
109
|
|
|
99
110
|
export const CollectionTextFieldSchema = CollectionFieldBaseSchema.extend({
|
|
100
111
|
type: z.literal("text"),
|
|
101
112
|
default: z.string().optional(),
|
|
102
|
-
enum:
|
|
113
|
+
enum: StringEnumSchema.optional(),
|
|
103
114
|
});
|
|
104
115
|
|
|
105
116
|
export const CollectionTimeFieldSchema = CollectionFieldBaseSchema.extend({
|
|
106
117
|
type: z.literal("time"),
|
|
107
118
|
default: z.string().optional(),
|
|
108
|
-
enum:
|
|
119
|
+
enum: StringEnumSchema.optional(),
|
|
109
120
|
});
|
|
110
121
|
|
|
111
122
|
// Union type if you want a single schema for all
|
|
@@ -16,8 +16,11 @@ async function runEnumCheck(input: any, processAllFields: boolean) {
|
|
|
16
16
|
const value = data[fieldName];
|
|
17
17
|
if (value === undefined || value === null) continue;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const allowedValues = fieldConfig.enum.map((item: any) =>
|
|
20
|
+
typeof item === "object" ? item.value : item
|
|
21
|
+
);
|
|
22
|
+
if (!allowedValues.includes(value)) {
|
|
23
|
+
errors[fieldName] = [`${fieldName} must be one of: ${allowedValues.join(", ")}`];
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
|