@webiny/api-core 0.0.0-unstable.61c048f412 → 0.0.0-unstable.ac6ebf63c6
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.
|
@@ -6,7 +6,7 @@ export declare abstract class FieldBuilder<TZod extends z.ZodTypeAny> {
|
|
|
6
6
|
protected zodSchema: TZod;
|
|
7
7
|
constructor(type: string, initialSchema: TZod);
|
|
8
8
|
label(text: string): this;
|
|
9
|
-
|
|
9
|
+
help(text: string): this;
|
|
10
10
|
placeholder(text: string): this;
|
|
11
11
|
toConfig(): FieldConfig;
|
|
12
12
|
getZodSchema(): TZod;
|
|
@@ -12,12 +12,12 @@ export class FieldBuilder {
|
|
|
12
12
|
this.config.label = text;
|
|
13
13
|
return this;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
this.config.
|
|
15
|
+
help(text) {
|
|
16
|
+
this.config.help = text;
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
19
|
placeholder(text) {
|
|
20
|
-
this.config.
|
|
20
|
+
this.config.placeholder = text;
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
23
|
toConfig() {
|
|
@@ -25,8 +25,8 @@ export class FieldBuilder {
|
|
|
25
25
|
fieldId: "",
|
|
26
26
|
type: this.config.type,
|
|
27
27
|
label: this.config.label,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
help: this.config.help,
|
|
29
|
+
placeholder: this.config.placeholder,
|
|
30
30
|
validation: this.config.validation || [],
|
|
31
31
|
settings: this.config.settings || {},
|
|
32
32
|
zodSchema: this.zodSchema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["z","FieldBuilder","config","validation","constructor","type","initialSchema","zodSchema","label","text","
|
|
1
|
+
{"version":3,"names":["z","FieldBuilder","config","validation","constructor","type","initialSchema","zodSchema","label","text","help","placeholder","toConfig","fieldId","settings","getZodSchema","TextFieldBuilder","schema","string","required","message","newSchema","min","push","name","minLength","length","maxLength","max","slug","regex","email","url","unique","ObjectFieldBuilder","nestedFields","fields","registry","fieldBuilders","shape","nestedConfigs","builder","Object","entries","object","optional","nullable"],"sources":["FieldBuilder.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { FieldConfig } from \"./types.js\";\nimport type { IFieldBuilderRegistry } from \"./abstractions.js\";\n\n// Make FieldBuilder return the Zod type it produces\nexport abstract class FieldBuilder<TZod extends z.ZodTypeAny> {\n protected config: Partial<FieldConfig> = {\n validation: []\n };\n protected zodSchema: TZod;\n\n constructor(type: string, initialSchema: TZod) {\n this.config.type = type;\n this.zodSchema = initialSchema;\n }\n\n label(text: string): this {\n this.config.label = text;\n return this;\n }\n\n help(text: string): this {\n this.config.help = text;\n return this;\n }\n\n placeholder(text: string): this {\n this.config.placeholder = text;\n return this;\n }\n\n toConfig(): FieldConfig {\n return {\n fieldId: \"\",\n type: this.config.type!,\n label: this.config.label,\n help: this.config.help,\n placeholder: this.config.placeholder,\n validation: this.config.validation || [],\n settings: this.config.settings || {},\n zodSchema: this.zodSchema\n };\n }\n\n getZodSchema(): TZod {\n return this.zodSchema;\n }\n}\n\n// Text Field Builder - properly track type transformations\nexport class TextFieldBuilder<TZod extends z.ZodString = z.ZodString> extends FieldBuilder<TZod> {\n constructor(schema?: TZod) {\n super(\"text\", (schema || z.string()) as TZod);\n }\n\n required(message?: string): TextFieldBuilder<z.ZodString> {\n const newSchema = (this.zodSchema as z.ZodString).min(1, message || \"Field is required\");\n this.zodSchema = newSchema as any;\n this.config.validation?.push({\n name: \"required\",\n message: message || \"Field is required\",\n settings: {}\n });\n return this as any;\n }\n\n minLength(length: number, message?: string): this {\n this.zodSchema = (this.zodSchema as z.ZodString).min(length, message) as TZod;\n return this;\n }\n\n maxLength(length: number, message?: string): this {\n this.zodSchema = (this.zodSchema as z.ZodString).max(length, message) as TZod;\n return this;\n }\n\n slug(): this {\n this.zodSchema = (this.zodSchema as z.ZodString).regex(\n /^[a-z0-9-]+$/,\n \"Must be a valid slug (lowercase letters, numbers, and hyphens only)\"\n ) as TZod;\n this.config.validation?.push({\n name: \"slug\",\n message: \"Must be a valid slug\",\n settings: {}\n });\n return this;\n }\n\n email(): this {\n this.zodSchema = (this.zodSchema as z.ZodString).email(\"Must be a valid email\") as TZod;\n this.config.validation?.push({\n name: \"email\",\n message: \"Must be a valid email\",\n settings: {}\n });\n return this;\n }\n\n url(): this {\n this.zodSchema = (this.zodSchema as z.ZodString).url(\"Must be a valid URL\") as TZod;\n this.config.validation?.push({\n name: \"url\",\n message: \"Must be a valid URL\",\n settings: {}\n });\n return this;\n }\n\n unique(): this {\n this.config.validation?.push({\n name: \"unique\",\n message: \"Value must be unique\",\n settings: {}\n });\n return this;\n }\n}\n\n// Object Field Builder - track the shape type\nexport class ObjectFieldBuilder<TShape extends z.ZodRawShape> extends FieldBuilder<\n z.ZodObject<TShape>\n> {\n private nestedFields: FieldConfig[] = [];\n\n constructor(\n fields: (registry: IFieldBuilderRegistry) => {\n [K in keyof TShape]: FieldBuilder<TShape[K]>;\n },\n registry: IFieldBuilderRegistry\n ) {\n const fieldBuilders = fields(registry);\n const shape = {} as TShape;\n const nestedConfigs: FieldConfig[] = [];\n\n for (const [fieldId, builder] of Object.entries(fieldBuilders) as Array<\n [keyof TShape, FieldBuilder<any>]\n >) {\n const config = builder.toConfig();\n config.fieldId = fieldId as string;\n nestedConfigs.push(config);\n shape[fieldId] = builder.getZodSchema() as TShape[keyof TShape];\n }\n\n super(\"object\", z.object(shape));\n this.nestedFields = nestedConfigs;\n this.config.fields = nestedConfigs;\n }\n\n optional(): ObjectFieldBuilder<TShape> & {\n getZodSchema(): z.ZodOptional<z.ZodObject<TShape>>;\n } {\n this.zodSchema = this.zodSchema.optional() as any;\n return this as any;\n }\n\n nullable(): ObjectFieldBuilder<TShape> & {\n getZodSchema(): z.ZodNullable<z.ZodObject<TShape>>;\n } {\n this.zodSchema = this.zodSchema.nullable() as any;\n return this as any;\n }\n\n override toConfig(): FieldConfig {\n const config = super.toConfig();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A,KAAK,CAAC,QAAQ,EAAEf,CAAC,CAAC4C,MAAM,CAACL,KAAK,CAAC,CAAC;IAChC,IAAI,CAACJ,YAAY,GAAGK,aAAa;IACjC,IAAI,CAACtC,MAAM,CAACkC,MAAM,GAAGI,aAAa;EACtC;EAEAK,QAAQA,CAAA,EAEN;IACE,IAAI,CAACtC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACsC,QAAQ,CAAC,CAAQ;IACjD,OAAO,IAAI;EACf;EAEAC,QAAQA,CAAA,EAEN;IACE,IAAI,CAACvC,SAAS,GAAG,IAAI,CAACA,SAAS,CAACuC,QAAQ,CAAC,CAAQ;IACjD,OAAO,IAAI;EACf;EAESlC,QAAQA,CAAA,EAAgB;IAC7B,MAAMV,MAAM,GAAG,KAAK,CAACU,QAAQ,CAAC,CAAC;IAC/BV,MAAM,CAACkC,MAAM,GAAG,IAAI,CAACD,YAAY;IACjC,OAAOjC,MAAM;EACjB;AACJ","ignoreList":[]}
|
|
@@ -41,7 +41,7 @@ export interface ITextFieldBuilder extends FieldBuilder<z.ZodString> {
|
|
|
41
41
|
email(): this;
|
|
42
42
|
url(): this;
|
|
43
43
|
unique(): this;
|
|
44
|
-
|
|
44
|
+
help(text: string): this;
|
|
45
45
|
placeholder(text: string): this;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -219,7 +219,7 @@ export interface IColorFieldBuilder extends FieldBuilder<z.ZodString> {
|
|
|
219
219
|
default(hex: string): this;
|
|
220
220
|
allowAlpha(): this;
|
|
221
221
|
palette(colors: string[]): this;
|
|
222
|
-
|
|
222
|
+
help(text: string): this;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
class ColorFieldBuilder extends FieldBuilder<z.ZodString> implements IColorFieldBuilder {
|
package/models/cms/types.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export interface FieldConfig {
|
|
|
6
6
|
fieldId: string;
|
|
7
7
|
type: string;
|
|
8
8
|
label?: string;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
help?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
11
|
validation?: ValidationRule[];
|
|
12
12
|
settings?: Record<string, any>;
|
|
13
13
|
zodSchema: z.ZodTypeAny;
|
package/models/cms/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { ModelClass } from \"~/models/base/ModelBuilder.js\";\nimport type { BaseModel } from \"~/models/base/BaseModel.js\";\nimport type { IModelData } from \"~/models/base/abstractions.js\";\n\nexport interface FieldConfig {\n fieldId: string;\n type: string;\n label?: string;\n
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { ModelClass } from \"~/models/base/ModelBuilder.js\";\nimport type { BaseModel } from \"~/models/base/BaseModel.js\";\nimport type { IModelData } from \"~/models/base/abstractions.js\";\n\nexport interface FieldConfig {\n fieldId: string;\n type: string;\n label?: string;\n help?: string;\n placeholder?: string;\n validation?: ValidationRule[];\n settings?: Record<string, any>;\n zodSchema: z.ZodTypeAny;\n fields?: FieldConfig[]; // For nested object fields\n}\n\nexport interface ValidationRule {\n name: string;\n message: string;\n settings: Record<string, any>;\n}\n\nexport interface CmsModelMetadata {\n icon?: string;\n description?: string;\n titleFieldId?: string;\n descriptionFieldId?: string;\n imageFieldId?: string;\n tags?: string[];\n}\n\n// Make PrivateCmsModel generic!\nexport interface PrivateCmsModel<TModel extends BaseModel<any>> {\n type: \"private\";\n modelType: \"private\";\n Model: ModelClass<TModel>;\n modelId: string;\n name: string;\n icon?: string;\n description?: string;\n fields: FieldConfig[];\n schema: TModel[\"__schema\"];\n create: (data: IModelData<TModel>) => TModel;\n}\n\nexport interface FieldBuilderConfig {\n fieldId: string;\n config: FieldConfig;\n zodSchema: z.ZodTypeAny;\n}\n"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.ac6ebf63c6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
},
|
|
58
58
|
"license": "MIT",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@webiny/api": "0.0.0-unstable.
|
|
60
|
+
"@webiny/api": "0.0.0-unstable.ac6ebf63c6",
|
|
61
61
|
"@webiny/di": "0.2.3",
|
|
62
|
-
"@webiny/error": "0.0.0-unstable.
|
|
63
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
64
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
65
|
-
"@webiny/handler-db": "0.0.0-unstable.
|
|
66
|
-
"@webiny/handler-graphql": "0.0.0-unstable.
|
|
67
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
68
|
-
"@webiny/project": "0.0.0-unstable.
|
|
69
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
70
|
-
"@webiny/wcp": "0.0.0-unstable.
|
|
62
|
+
"@webiny/error": "0.0.0-unstable.ac6ebf63c6",
|
|
63
|
+
"@webiny/feature": "0.0.0-unstable.ac6ebf63c6",
|
|
64
|
+
"@webiny/handler": "0.0.0-unstable.ac6ebf63c6",
|
|
65
|
+
"@webiny/handler-db": "0.0.0-unstable.ac6ebf63c6",
|
|
66
|
+
"@webiny/handler-graphql": "0.0.0-unstable.ac6ebf63c6",
|
|
67
|
+
"@webiny/plugins": "0.0.0-unstable.ac6ebf63c6",
|
|
68
|
+
"@webiny/project": "0.0.0-unstable.ac6ebf63c6",
|
|
69
|
+
"@webiny/utils": "0.0.0-unstable.ac6ebf63c6",
|
|
70
|
+
"@webiny/wcp": "0.0.0-unstable.ac6ebf63c6",
|
|
71
71
|
"dataloader": "2.2.3",
|
|
72
72
|
"jose": "5.10.0",
|
|
73
73
|
"jsonwebtoken": "9.0.3",
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/jsonwebtoken": "9.0.10",
|
|
83
83
|
"@types/md5": "2.3.6",
|
|
84
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
85
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
|
86
|
-
"@webiny/handler-aws": "0.0.0-unstable.
|
|
87
|
-
"@webiny/project-utils": "0.0.0-unstable.
|
|
84
|
+
"@webiny/build-tools": "0.0.0-unstable.ac6ebf63c6",
|
|
85
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.ac6ebf63c6",
|
|
86
|
+
"@webiny/handler-aws": "0.0.0-unstable.ac6ebf63c6",
|
|
87
|
+
"@webiny/project-utils": "0.0.0-unstable.ac6ebf63c6",
|
|
88
88
|
"jest-dynalite": "3.6.1",
|
|
89
|
-
"rimraf": "6.1.
|
|
89
|
+
"rimraf": "6.1.3",
|
|
90
90
|
"typescript": "5.9.3",
|
|
91
91
|
"vitest": "3.2.4"
|
|
92
92
|
},
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"access": "public",
|
|
95
95
|
"directory": "dist"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "ac6ebf63c6de308703d41f2c1b375e03cd96b813"
|
|
98
98
|
}
|