@strapi2front/generators 0.4.1 → 0.5.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/dist/index.d.ts +116 -2
- package/dist/index.js +1803 -288
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedSchema, StrapiLocale } from '@strapi2front/core';
|
|
1
|
+
import { ParsedSchema, StrapiLocale, Attribute } from '@strapi2front/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Shared types for generators
|
|
@@ -127,6 +127,27 @@ interface ByFeatureGeneratorOptions {
|
|
|
127
127
|
types: boolean;
|
|
128
128
|
services: boolean;
|
|
129
129
|
actions: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Generate Zod schemas for validation
|
|
132
|
+
* Useful for React Hook Form, TanStack Form, Formik, etc.
|
|
133
|
+
* @default true for TypeScript, false for JSDoc
|
|
134
|
+
*/
|
|
135
|
+
schemas?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Generate upload helpers (upload-client + upload-action)
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
upload?: boolean;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Schema generation options
|
|
144
|
+
*/
|
|
145
|
+
schemaOptions?: {
|
|
146
|
+
/**
|
|
147
|
+
* Use advanced relation format with connect/disconnect/set operations
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
advancedRelations?: boolean;
|
|
130
151
|
};
|
|
131
152
|
blocksRendererInstalled?: boolean;
|
|
132
153
|
strapiVersion?: "v4" | "v5";
|
|
@@ -150,17 +171,21 @@ interface ByFeatureGeneratorOptions {
|
|
|
150
171
|
* collections/
|
|
151
172
|
* article/
|
|
152
173
|
* types.ts
|
|
174
|
+
* schemas.ts
|
|
153
175
|
* service.ts
|
|
154
176
|
* actions.ts
|
|
155
177
|
* singles/
|
|
156
178
|
* homepage/
|
|
157
179
|
* types.ts
|
|
180
|
+
* schemas.ts
|
|
158
181
|
* service.ts
|
|
159
182
|
* components/
|
|
160
183
|
* seo.ts
|
|
161
184
|
* shared/
|
|
162
185
|
* utils.ts
|
|
163
186
|
* client.ts
|
|
187
|
+
* upload-client.ts (when features.upload)
|
|
188
|
+
* upload-action.ts (when features.upload + actions + TypeScript)
|
|
164
189
|
* locales.ts
|
|
165
190
|
*/
|
|
166
191
|
declare function generateByFeature(schema: ParsedSchema, locales: StrapiLocale[], options: ByFeatureGeneratorOptions): Promise<string[]>;
|
|
@@ -178,6 +203,8 @@ interface AstroActionsOptions {
|
|
|
178
203
|
outputDir: string;
|
|
179
204
|
servicesImportPath: string;
|
|
180
205
|
strapiVersion?: StrapiVersion;
|
|
206
|
+
/** Use typed Zod schemas instead of generic z.record(z.unknown()) */
|
|
207
|
+
useTypedSchemas?: boolean;
|
|
181
208
|
}
|
|
182
209
|
/**
|
|
183
210
|
* Check if Astro Actions are supported
|
|
@@ -311,6 +338,93 @@ interface JSDocServicesOptions {
|
|
|
311
338
|
*/
|
|
312
339
|
declare function generateJSDocServices(schema: ParsedSchema, options: JSDocServicesOptions): Promise<string[]>;
|
|
313
340
|
|
|
341
|
+
/**
|
|
342
|
+
* Zod Schemas generator
|
|
343
|
+
* Generates Zod validation schemas for Strapi content types
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
interface ZodSchemasOptions {
|
|
347
|
+
outputDir: string;
|
|
348
|
+
/** Generate schemas alongside types in by-feature structure */
|
|
349
|
+
byFeature?: boolean;
|
|
350
|
+
/** Strapi version - affects ID types for relations (v4: number, v5: string) */
|
|
351
|
+
strapiVersion?: 'v4' | 'v5';
|
|
352
|
+
}
|
|
353
|
+
interface GeneratedSchemaInfo {
|
|
354
|
+
/** File path where schema was written */
|
|
355
|
+
filePath: string;
|
|
356
|
+
/** Schema names generated */
|
|
357
|
+
schemas: string[];
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Generate Zod schemas from parsed schema
|
|
361
|
+
*/
|
|
362
|
+
declare function generateZodSchemas(schema: ParsedSchema, options: ZodSchemasOptions): Promise<GeneratedSchemaInfo[]>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Zod Schema mapping utilities
|
|
366
|
+
* Converts Strapi attributes to Zod schema strings
|
|
367
|
+
*
|
|
368
|
+
* Note: This mapper generates Zod schema code as strings
|
|
369
|
+
* that will be written to generated files.
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Options for schema generation
|
|
374
|
+
*/
|
|
375
|
+
interface ZodMapperOptions {
|
|
376
|
+
/** Whether this is for an update schema (all fields optional) */
|
|
377
|
+
isUpdate?: boolean;
|
|
378
|
+
/** Whether to include relation fields */
|
|
379
|
+
includeRelations?: boolean;
|
|
380
|
+
/** Whether to include media fields */
|
|
381
|
+
includeMedia?: boolean;
|
|
382
|
+
/** Whether to include component fields */
|
|
383
|
+
includeComponents?: boolean;
|
|
384
|
+
/** Strapi version - affects ID types (v4: number, v5: string documentId) */
|
|
385
|
+
strapiVersion?: 'v4' | 'v5';
|
|
386
|
+
/**
|
|
387
|
+
* Use advanced relation format with connect/disconnect/set
|
|
388
|
+
* @default false - uses simple ID arrays
|
|
389
|
+
*/
|
|
390
|
+
useAdvancedRelations?: boolean;
|
|
391
|
+
/**
|
|
392
|
+
* Map of component UIDs to their schema variable names
|
|
393
|
+
* e.g. { 'curse.resource': 'resourceSchema' }
|
|
394
|
+
* When provided, component fields reference imported schemas instead of z.record(z.unknown())
|
|
395
|
+
*/
|
|
396
|
+
componentSchemaNames?: Map<string, string>;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Result of mapping an attribute to Zod
|
|
400
|
+
*/
|
|
401
|
+
interface ZodMappedAttribute {
|
|
402
|
+
/** The Zod schema string (e.g., "z.string().min(1)") */
|
|
403
|
+
schema: string;
|
|
404
|
+
/** Whether this field should be skipped in generation */
|
|
405
|
+
skip: boolean;
|
|
406
|
+
/** Reason for skipping (if skip is true) */
|
|
407
|
+
skipReason?: string;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Check if a field is a system field
|
|
411
|
+
*/
|
|
412
|
+
declare function isSystemField(fieldName: string): boolean;
|
|
413
|
+
/**
|
|
414
|
+
* Map a Strapi attribute to a Zod schema string
|
|
415
|
+
*/
|
|
416
|
+
declare function mapAttributeToZodSchema(attr: Attribute, options?: ZodMapperOptions): ZodMappedAttribute;
|
|
417
|
+
/**
|
|
418
|
+
* Generate a complete Zod object schema from attributes
|
|
419
|
+
*/
|
|
420
|
+
declare function generateZodObjectSchema(attributes: Record<string, Attribute>, options?: ZodMapperOptions): {
|
|
421
|
+
schema: string;
|
|
422
|
+
skippedFields: Array<{
|
|
423
|
+
name: string;
|
|
424
|
+
reason: string;
|
|
425
|
+
}>;
|
|
426
|
+
};
|
|
427
|
+
|
|
314
428
|
/**
|
|
315
429
|
* Format TypeScript code using Prettier
|
|
316
430
|
*/
|
|
@@ -362,4 +476,4 @@ declare function toKebabCase(str: string): string;
|
|
|
362
476
|
*/
|
|
363
477
|
declare function pluralize(word: string): string;
|
|
364
478
|
|
|
365
|
-
export { type ActionsGeneratorOptions, type AstroActionsOptions, type BaseGeneratorOptions, type ByFeatureGeneratorOptions, type ClientGeneratorOptions, type Framework, type GeneratorContext, type GeneratorResult, type JSDocServicesOptions, type JSDocTypesOptions, type LocalesGeneratorOptions, type NextJsActionsOptions, type NuxtServerRoutesOptions, type OutputFormat, type ServiceGeneratorOptions, type StrapiVersion, type SupportedFramework, type TypeGeneratorOptions, type TypeScriptTypesOptions, deleteFile, ensureDir, fileExists, formatCode, formatJson, frameworkSupport, generateActions, generateAstroActions, generateByFeature, generateClient, generateJSDocServices, generateJSDocTypes, generateLocales, generateNextJsActions, generateNuxtServerRoutes, generateServices, generateTypeScriptTypes, generateTypes, isAstroActionsSupported, isNextJsActionsSupported, isNuxtServerRoutesSupported, listFiles, pluralize, readFile, toCamelCase, toKebabCase, toPascalCase, writeFile };
|
|
479
|
+
export { type ActionsGeneratorOptions, type AstroActionsOptions, type BaseGeneratorOptions, type ByFeatureGeneratorOptions, type ClientGeneratorOptions, type Framework, type GeneratedSchemaInfo, type GeneratorContext, type GeneratorResult, type JSDocServicesOptions, type JSDocTypesOptions, type LocalesGeneratorOptions, type NextJsActionsOptions, type NuxtServerRoutesOptions, type OutputFormat, type ServiceGeneratorOptions, type StrapiVersion, type SupportedFramework, type TypeGeneratorOptions, type TypeScriptTypesOptions, type ZodMappedAttribute, type ZodMapperOptions, type ZodSchemasOptions, deleteFile, ensureDir, fileExists, formatCode, formatJson, frameworkSupport, generateActions, generateAstroActions, generateByFeature, generateClient, generateJSDocServices, generateJSDocTypes, generateLocales, generateNextJsActions, generateNuxtServerRoutes, generateServices, generateTypeScriptTypes, generateTypes, generateZodObjectSchema, generateZodSchemas, isAstroActionsSupported, isNextJsActionsSupported, isNuxtServerRoutesSupported, isSystemField, listFiles, mapAttributeToZodSchema, pluralize, readFile, toCamelCase, toKebabCase, toPascalCase, writeFile };
|