nextjs-cms 0.9.37 → 0.9.39
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/LICENSE +21 -21
- package/README.md +279 -279
- package/dist/api/actions/files.d.ts.map +1 -1
- package/dist/api/actions/pages.d.ts +28 -7
- package/dist/api/actions/pages.d.ts.map +1 -1
- package/dist/api/actions/pages.js +112 -27
- package/dist/api/trpc/root.d.ts +65 -10
- package/dist/api/trpc/root.d.ts.map +1 -1
- package/dist/api/trpc/routers/config.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.d.ts +23 -2
- package/dist/api/trpc/routers/hasItemsSection.d.ts.map +1 -1
- package/dist/api/trpc/routers/hasItemsSection.js +2 -1
- package/dist/api/trpc/routers/logs.d.ts +37 -4
- package/dist/api/trpc/routers/logs.d.ts.map +1 -1
- package/dist/api/trpc/routers/logs.js +92 -43
- package/dist/api/trpc/routers/navigation.d.ts +4 -3
- package/dist/api/trpc/routers/navigation.d.ts.map +1 -1
- package/dist/api/trpc/routers/simpleSection.d.ts +1 -1
- package/dist/api/trpc/routers/simpleSection.d.ts.map +1 -1
- package/dist/api/trpc/server.d.ts +195 -30
- package/dist/api/trpc/server.d.ts.map +1 -1
- package/dist/cli/lib/db-config.js +10 -10
- package/dist/cli/lib/update-sections.js +24 -24
- package/dist/core/config/config-loader.d.ts +2 -2
- package/dist/core/db/table-checker/MysqlTable.js +10 -10
- package/dist/core/factories/FieldFactory.d.ts +1 -6
- package/dist/core/factories/FieldFactory.d.ts.map +1 -1
- package/dist/core/factories/FieldFactory.js +3 -68
- package/dist/core/factories/section-factory-with-esbuild.js +9 -9
- package/dist/core/factories/section-factory-with-jiti.js +9 -9
- package/dist/core/fields/checkbox.d.ts +3 -3
- package/dist/core/fields/color.d.ts +3 -3
- package/dist/core/fields/date-range.d.ts +2 -2
- package/dist/core/fields/date.d.ts +3 -3
- package/dist/core/fields/document.d.ts +3 -3
- package/dist/core/fields/field.d.ts +25 -12
- package/dist/core/fields/field.d.ts.map +1 -1
- package/dist/core/fields/field.js +51 -23
- package/dist/core/fields/index.d.ts +1 -0
- package/dist/core/fields/index.d.ts.map +1 -1
- package/dist/core/fields/index.js +2 -0
- package/dist/core/fields/map.d.ts +3 -3
- package/dist/core/fields/number.d.ts +4 -4
- package/dist/core/fields/password.d.ts +3 -3
- package/dist/core/fields/photo.d.ts +9 -9
- package/dist/core/fields/richText.d.ts +12 -12
- package/dist/core/fields/select.d.ts +7 -7
- package/dist/core/fields/selectMultiple.d.ts +4 -4
- package/dist/core/fields/slug.d.ts +9 -9
- package/dist/core/fields/tags.d.ts +3 -3
- package/dist/core/fields/text.d.ts +2 -2
- package/dist/core/fields/textArea.d.ts +2 -2
- package/dist/core/fields/video.d.ts +3 -3
- package/dist/core/helpers/conditional-rules.d.ts +63 -0
- package/dist/core/helpers/conditional-rules.d.ts.map +1 -0
- package/dist/core/helpers/conditional-rules.js +113 -0
- package/dist/core/helpers/index.d.ts +1 -0
- package/dist/core/helpers/index.d.ts.map +1 -1
- package/dist/core/helpers/index.js +4 -0
- package/dist/core/sections/category.d.ts +50 -50
- package/dist/core/sections/hasItems.d.ts +74 -74
- package/dist/core/sections/section.d.ts +23 -23
- package/dist/core/sections/simple.d.ts +6 -6
- package/dist/core/submit/submit.d.ts +4 -1
- package/dist/core/submit/submit.d.ts.map +1 -1
- package/dist/core/submit/submit.js +9 -19
- package/dist/core/types/index.d.ts +30 -8
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/logging/event-labels.d.ts +11 -0
- package/dist/logging/event-labels.d.ts.map +1 -0
- package/dist/logging/event-labels.js +14 -0
- package/dist/logging/log.d.ts +1 -1
- package/dist/logging/log.d.ts.map +1 -1
- package/dist/translations/base/en.d.ts +33 -0
- package/dist/translations/base/en.d.ts.map +1 -1
- package/dist/translations/base/en.js +33 -0
- package/dist/translations/client.d.ts +400 -4
- package/dist/translations/client.d.ts.map +1 -1
- package/dist/translations/server.d.ts +400 -4
- package/dist/translations/server.d.ts.map +1 -1
- package/package.json +7 -3
|
@@ -22,12 +22,12 @@ export class MysqlTableChecker extends DbTableChecker {
|
|
|
22
22
|
return _tables;
|
|
23
23
|
}
|
|
24
24
|
static async getColumns(tableName) {
|
|
25
|
-
const statement = sql `
|
|
26
|
-
SELECT COLUMN_NAME
|
|
27
|
-
FROM information_schema.COLUMNS c
|
|
28
|
-
inner join information_schema.TABLES t ON t.TABLE_NAME = c.TABLE_NAME
|
|
29
|
-
WHERE t.TABLE_SCHEMA = DATABASE()
|
|
30
|
-
AND c.TABLE_SCHEMA = DATABASE()
|
|
25
|
+
const statement = sql `
|
|
26
|
+
SELECT COLUMN_NAME
|
|
27
|
+
FROM information_schema.COLUMNS c
|
|
28
|
+
inner join information_schema.TABLES t ON t.TABLE_NAME = c.TABLE_NAME
|
|
29
|
+
WHERE t.TABLE_SCHEMA = DATABASE()
|
|
30
|
+
AND c.TABLE_SCHEMA = DATABASE()
|
|
31
31
|
AND t.TABLE_NAME = ${tableName}`;
|
|
32
32
|
const _cols = [];
|
|
33
33
|
const _res = await db.execute(statement);
|
|
@@ -84,10 +84,10 @@ export class MysqlTableChecker extends DbTableChecker {
|
|
|
84
84
|
fullTextKeys.push({ name: key, columns: _fullTextKeyMap[key] });
|
|
85
85
|
}
|
|
86
86
|
// Foreign keys should be retrieved from information_schema
|
|
87
|
-
const [foreignKeys] = await db.execute(sql `
|
|
88
|
-
SELECT COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
|
|
89
|
-
FROM information_schema.KEY_COLUMN_USAGE
|
|
90
|
-
WHERE TABLE_NAME = ${table} AND CONSTRAINT_NAME != 'PRIMARY' AND REFERENCED_TABLE_NAME IS NOT NULL;
|
|
87
|
+
const [foreignKeys] = await db.execute(sql `
|
|
88
|
+
SELECT COLUMN_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
|
|
89
|
+
FROM information_schema.KEY_COLUMN_USAGE
|
|
90
|
+
WHERE TABLE_NAME = ${table} AND CONSTRAINT_NAME != 'PRIMARY' AND REFERENCED_TABLE_NAME IS NOT NULL;
|
|
91
91
|
`);
|
|
92
92
|
return { primaryKeys, uniqueKeys, indexKeys, foreignKeys, fullTextKeys };
|
|
93
93
|
}
|
|
@@ -60,11 +60,6 @@ export declare class FieldFactory {
|
|
|
60
60
|
* Generate the fields
|
|
61
61
|
*/
|
|
62
62
|
generateFields(): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Sort the fields.
|
|
65
|
-
* This function sorts the conditional fields into their respective fields.
|
|
66
|
-
*/
|
|
67
|
-
private sortFields;
|
|
68
63
|
/**
|
|
69
64
|
* Sort fields by their order property, preserving original position for fields without order.
|
|
70
65
|
*
|
|
@@ -112,7 +107,7 @@ export declare class FieldFactory {
|
|
|
112
107
|
label: string;
|
|
113
108
|
required: boolean;
|
|
114
109
|
localized?: boolean;
|
|
115
|
-
|
|
110
|
+
conditionalGroup?: import("../types/index.js").ConditionalGroupClient;
|
|
116
111
|
readonly: boolean;
|
|
117
112
|
defaultValue: any;
|
|
118
113
|
value: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldFactory.d.ts","sourceRoot":"","sources":["../../../src/core/factories/FieldFactory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FieldFactory.d.ts","sourceRoot":"","sources":["../../../src/core/factories/FieldFactory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,KAAK,EAAgD,OAAO,EAAuB,MAAM,sBAAsB,CAAA;AAUtH,KAAK,eAAe,GACd;IACI,IAAI,EAAE,KAAK,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,KAAK,CAAA;CACjB,G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{ cloneDeep } from 'lodash-es';
|
|
4
3
|
import { db } from '../../db/client.js';
|
|
5
4
|
import getString from '../../translations/index.js';
|
|
6
5
|
import { resolveLanguage, resolveMultilingualString } from '../../translations/language-utils.js';
|
|
@@ -303,70 +302,6 @@ export class FieldFactory {
|
|
|
303
302
|
*/
|
|
304
303
|
await this.prepareField(input);
|
|
305
304
|
}
|
|
306
|
-
this.sortFields();
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Sort the fields.
|
|
310
|
-
* This function sorts the conditional fields into their respective fields.
|
|
311
|
-
*/
|
|
312
|
-
sortFields() {
|
|
313
|
-
if (this._error)
|
|
314
|
-
return;
|
|
315
|
-
if (!this._sectionInfo)
|
|
316
|
-
return;
|
|
317
|
-
/**
|
|
318
|
-
* Create a map of conditional fields
|
|
319
|
-
*/
|
|
320
|
-
const _conditionalFieldMap = new Map();
|
|
321
|
-
/**
|
|
322
|
-
* Loop through the fields and get the conditional fields
|
|
323
|
-
*/
|
|
324
|
-
for (const input of this._sectionInfo.fields) {
|
|
325
|
-
input.conditionalFields = [];
|
|
326
|
-
/**
|
|
327
|
-
* Check if the field is conditional.
|
|
328
|
-
*/
|
|
329
|
-
if (input.isConditional()) {
|
|
330
|
-
for (const rule of input.conditionalRules ?? []) {
|
|
331
|
-
/**
|
|
332
|
-
* Add the conditional input to the conditional fields lists
|
|
333
|
-
*/
|
|
334
|
-
if (!_conditionalFieldMap.has(rule.field.name)) {
|
|
335
|
-
_conditionalFieldMap.set(rule.field.name, []);
|
|
336
|
-
}
|
|
337
|
-
_conditionalFieldMap.get(rule.field.name).push(
|
|
338
|
-
/**
|
|
339
|
-
* Clone the conditional field to avoid reference issues
|
|
340
|
-
*/
|
|
341
|
-
cloneDeep({
|
|
342
|
-
field: input.exportForClient(),
|
|
343
|
-
rule: {
|
|
344
|
-
condition: rule.condition,
|
|
345
|
-
value: rule.value,
|
|
346
|
-
},
|
|
347
|
-
}));
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Assign conditionalFields to the appropriate fields
|
|
353
|
-
*/
|
|
354
|
-
for (const field of this._sectionInfo.fields) {
|
|
355
|
-
const matchingConditionalFields = _conditionalFieldMap.get(field.name);
|
|
356
|
-
if (matchingConditionalFields) {
|
|
357
|
-
field.conditionalFields.push(...matchingConditionalFields.map((clonedConditionalField) => ({
|
|
358
|
-
...clonedConditionalField,
|
|
359
|
-
rule: {
|
|
360
|
-
condition: clonedConditionalField.rule.condition,
|
|
361
|
-
value: clonedConditionalField.rule.value,
|
|
362
|
-
},
|
|
363
|
-
})));
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Destroy the map
|
|
368
|
-
*/
|
|
369
|
-
_conditionalFieldMap.clear();
|
|
370
305
|
}
|
|
371
306
|
/**
|
|
372
307
|
* Sort fields by their order property, preserving original position for fields without order.
|
|
@@ -439,9 +374,9 @@ export class FieldFactory {
|
|
|
439
374
|
const field = fields[j];
|
|
440
375
|
if (!field)
|
|
441
376
|
continue;
|
|
442
|
-
//
|
|
443
|
-
|
|
444
|
-
|
|
377
|
+
// Conditional fields are included here and self-gate on the client via their
|
|
378
|
+
// `conditionalGroup` (watching their controlling fields), so any field type can gate
|
|
379
|
+
// any other. Persistence is still decided server-side in `checkConditionalField`.
|
|
445
380
|
// For new item operations, exclude fields with adminGenerated not set to true
|
|
446
381
|
if (isNewOperation && field.adminGenerated !== true)
|
|
447
382
|
continue;
|
|
@@ -460,15 +460,15 @@ export class SectionFactory {
|
|
|
460
460
|
importErr.message.includes('Cannot find module') &&
|
|
461
461
|
importErr.message.includes('.section')) {
|
|
462
462
|
this.sectionProcessingErrors[file] ??= [];
|
|
463
|
-
this.sectionProcessingErrors[file].push(`❌ Invalid section import detected.
|
|
464
|
-
|
|
465
|
-
Sections MUST use extensionless relative imports:
|
|
466
|
-
|
|
467
|
-
✅ import exampleSection from './example.section'
|
|
468
|
-
❌ import exampleSection from './example.section.ts'
|
|
469
|
-
❌ import exampleSection from './example.section.js'
|
|
470
|
-
|
|
471
|
-
This file is bundled with esbuild, so Node never resolves the import directly.
|
|
463
|
+
this.sectionProcessingErrors[file].push(`❌ Invalid section import detected.
|
|
464
|
+
|
|
465
|
+
Sections MUST use extensionless relative imports:
|
|
466
|
+
|
|
467
|
+
✅ import exampleSection from './example.section'
|
|
468
|
+
❌ import exampleSection from './example.section.ts'
|
|
469
|
+
❌ import exampleSection from './example.section.js'
|
|
470
|
+
|
|
471
|
+
This file is bundled with esbuild, so Node never resolves the import directly.
|
|
472
472
|
If you added an extension manually, remove it.`);
|
|
473
473
|
this.errorCount++;
|
|
474
474
|
continue;
|
|
@@ -417,15 +417,15 @@ export class SectionFactory {
|
|
|
417
417
|
importErr.message.includes('Cannot find module') &&
|
|
418
418
|
importErr.message.includes('.section')) {
|
|
419
419
|
this.sectionProcessingErrors[file] ??= [];
|
|
420
|
-
this.sectionProcessingErrors[file].push(`❌ Invalid section import detected.
|
|
421
|
-
|
|
422
|
-
Sections MUST use extensionless relative imports:
|
|
423
|
-
|
|
424
|
-
✅ import exampleSection from './example.section'
|
|
425
|
-
❌ import exampleSection from './example.section.ts'
|
|
426
|
-
❌ import exampleSection from './example.section.js'
|
|
427
|
-
|
|
428
|
-
This file is bundled with jiti, so Node never resolves the import directly.
|
|
420
|
+
this.sectionProcessingErrors[file].push(`❌ Invalid section import detected.
|
|
421
|
+
|
|
422
|
+
Sections MUST use extensionless relative imports:
|
|
423
|
+
|
|
424
|
+
✅ import exampleSection from './example.section'
|
|
425
|
+
❌ import exampleSection from './example.section.ts'
|
|
426
|
+
❌ import exampleSection from './example.section.js'
|
|
427
|
+
|
|
428
|
+
This file is bundled with jiti, so Node never resolves the import directly.
|
|
429
429
|
If you added an extension manually, remove it.`);
|
|
430
430
|
this.errorCount++;
|
|
431
431
|
continue;
|
|
@@ -21,7 +21,7 @@ export declare class CheckboxField extends Field<'checkbox', Config> {
|
|
|
21
21
|
label: string;
|
|
22
22
|
required: boolean;
|
|
23
23
|
localized?: boolean;
|
|
24
|
-
|
|
24
|
+
conditionalGroup?: import("../types/index.js").ConditionalGroupClient;
|
|
25
25
|
readonly: boolean;
|
|
26
26
|
defaultValue: any;
|
|
27
27
|
value: any;
|
|
@@ -34,7 +34,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
34
34
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
35
35
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
36
36
|
order: z.ZodOptional<z.ZodNumber>;
|
|
37
|
-
conditionalRules: z.ZodOptional<z.
|
|
37
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
38
38
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
39
39
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
40
40
|
}, z.core.$strict>;
|
|
@@ -46,7 +46,7 @@ declare const checkboxFieldConfigSchema: z.ZodObject<{
|
|
|
46
46
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
47
47
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
48
48
|
order: z.ZodOptional<z.ZodNumber>;
|
|
49
|
-
conditionalRules: z.ZodOptional<z.
|
|
49
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
50
50
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
51
51
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
52
52
|
}, z.core.$strict>;
|
|
@@ -26,7 +26,7 @@ export declare class ColorField extends Field<'color', Config> {
|
|
|
26
26
|
label: string;
|
|
27
27
|
required: boolean;
|
|
28
28
|
localized?: boolean;
|
|
29
|
-
|
|
29
|
+
conditionalGroup?: import("../types/index.js").ConditionalGroupClient;
|
|
30
30
|
readonly: boolean;
|
|
31
31
|
defaultValue: any;
|
|
32
32
|
value: any;
|
|
@@ -50,7 +50,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
50
50
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
51
51
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
52
52
|
order: z.ZodOptional<z.ZodNumber>;
|
|
53
|
-
conditionalRules: z.ZodOptional<z.
|
|
53
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
54
54
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
55
55
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
56
56
|
}, z.core.$strict>;
|
|
@@ -67,7 +67,7 @@ declare const colorFieldConfigSchema: z.ZodObject<{
|
|
|
67
67
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
68
68
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
69
69
|
order: z.ZodOptional<z.ZodNumber>;
|
|
70
|
-
conditionalRules: z.ZodOptional<z.
|
|
70
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
71
71
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
72
72
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
73
73
|
}, z.core.$strict>;
|
|
@@ -74,7 +74,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
74
74
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
75
75
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
76
76
|
order: z.ZodOptional<z.ZodNumber>;
|
|
77
|
-
conditionalRules: z.ZodOptional<z.
|
|
77
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
78
78
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
79
79
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
80
80
|
}, z.core.$strict>;
|
|
@@ -101,7 +101,7 @@ declare const dateRangeFieldConfigSchema: z.ZodObject<{
|
|
|
101
101
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
102
102
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
103
103
|
order: z.ZodOptional<z.ZodNumber>;
|
|
104
|
-
conditionalRules: z.ZodOptional<z.
|
|
104
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
105
105
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
106
106
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
107
107
|
}, z.core.$strict>;
|
|
@@ -50,7 +50,7 @@ export declare class DateField extends Field<'date', Config> {
|
|
|
50
50
|
label: string;
|
|
51
51
|
required: boolean;
|
|
52
52
|
localized?: boolean;
|
|
53
|
-
|
|
53
|
+
conditionalGroup?: import("../types/index.js").ConditionalGroupClient;
|
|
54
54
|
readonly: boolean;
|
|
55
55
|
defaultValue: any;
|
|
56
56
|
value: any;
|
|
@@ -83,7 +83,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
83
83
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
84
84
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
85
85
|
order: z.ZodOptional<z.ZodNumber>;
|
|
86
|
-
conditionalRules: z.ZodOptional<z.
|
|
86
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
87
87
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
88
88
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
89
89
|
}, z.core.$strict>;
|
|
@@ -107,7 +107,7 @@ declare const dateFieldConfigSchema: z.ZodObject<{
|
|
|
107
107
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
108
108
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
109
109
|
order: z.ZodOptional<z.ZodNumber>;
|
|
110
|
-
conditionalRules: z.ZodOptional<z.
|
|
110
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
111
111
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
112
112
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
113
113
|
}, z.core.$strict>;
|
|
@@ -67,7 +67,7 @@ export declare class DocumentField extends FileField<'document', Config> {
|
|
|
67
67
|
label: string;
|
|
68
68
|
required: boolean;
|
|
69
69
|
localized?: boolean;
|
|
70
|
-
|
|
70
|
+
conditionalGroup?: import("../types/index.js").ConditionalGroupClient;
|
|
71
71
|
readonly: boolean;
|
|
72
72
|
defaultValue: any;
|
|
73
73
|
value: any;
|
|
@@ -136,7 +136,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
136
136
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
137
137
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
138
138
|
order: z.ZodOptional<z.ZodNumber>;
|
|
139
|
-
conditionalRules: z.ZodOptional<z.
|
|
139
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
140
140
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
141
141
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
142
142
|
}, z.core.$strict>;
|
|
@@ -180,7 +180,7 @@ declare const documentFieldConfigSchema: z.ZodObject<{
|
|
|
180
180
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
181
181
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
182
182
|
order: z.ZodOptional<z.ZodNumber>;
|
|
183
|
-
conditionalRules: z.ZodOptional<z.
|
|
183
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
184
184
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
185
185
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
186
186
|
}, z.core.$strict>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { entityKind } from '../helpers/index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ConditionalGroupClient, ConditionalRule, ConditionalRuleGroup, ConditionalRulesConfig, FieldType } from '../types/index.js';
|
|
3
3
|
import type { MultilingualString } from '../../translations/language-utils.js';
|
|
4
4
|
import * as z from 'zod';
|
|
5
5
|
/**
|
|
@@ -19,7 +19,7 @@ export declare abstract class Field<TType extends FieldType = FieldType, TExtraF
|
|
|
19
19
|
readonly localized: boolean;
|
|
20
20
|
readonly order: number | undefined;
|
|
21
21
|
readonly groupId: number | undefined;
|
|
22
|
-
readonly conditionalRules:
|
|
22
|
+
readonly conditionalRules: ConditionalRulesConfig | undefined;
|
|
23
23
|
protected language: string;
|
|
24
24
|
protected fallbackLanguage: string;
|
|
25
25
|
/**
|
|
@@ -44,10 +44,6 @@ export declare abstract class Field<TType extends FieldType = FieldType, TExtraF
|
|
|
44
44
|
itemIdentifier: string;
|
|
45
45
|
selectIdentifier: string;
|
|
46
46
|
};
|
|
47
|
-
/**
|
|
48
|
-
* Dynamically generated fields based on the value of `conditionalRules` from conditional fields.
|
|
49
|
-
*/
|
|
50
|
-
conditionalFields: ConditionalField[];
|
|
51
47
|
value: any;
|
|
52
48
|
constructor(config: BaseFieldConfig<TExtraFieldConfig>, fieldType: TType);
|
|
53
49
|
abstract checkRequired(): void;
|
|
@@ -91,19 +87,36 @@ export declare abstract class Field<TType extends FieldType = FieldType, TExtraF
|
|
|
91
87
|
label: string;
|
|
92
88
|
required: boolean;
|
|
93
89
|
localized?: boolean;
|
|
94
|
-
|
|
90
|
+
conditionalGroup?: ConditionalGroupClient;
|
|
95
91
|
readonly: boolean;
|
|
96
92
|
defaultValue: any;
|
|
97
93
|
value: any;
|
|
98
94
|
};
|
|
99
95
|
hasSqlNameAndValue(): boolean;
|
|
100
96
|
/**
|
|
101
|
-
*
|
|
97
|
+
* Normalize this field's `conditionalRules` config into a single group of rules, or `undefined`
|
|
98
|
+
* when the field has none. The one place either layer turns the authoring form (a single-rule
|
|
99
|
+
* array or an `and()` / `or()` group) into the group shape the evaluator consumes.
|
|
100
|
+
*/
|
|
101
|
+
getConditionalGroup(): ConditionalRuleGroup | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Project this field's rule group into its client-safe form: each rule references its controlling
|
|
104
|
+
* field by name rather than carrying the full field config. Returns `undefined` when not
|
|
105
|
+
* conditional, so it is omitted from the exported config.
|
|
106
|
+
*/
|
|
107
|
+
private exportConditionalGroup;
|
|
108
|
+
/**
|
|
109
|
+
* Check if field is conditional.
|
|
110
|
+
*
|
|
111
|
+
* A field is conditional once it has at least one rule that names a controlling field, a
|
|
112
|
+
* condition and a value. `value` is checked against `undefined` rather than for truthiness, so
|
|
113
|
+
* `false`, `0` and `''` stay valid values to compare against.
|
|
102
114
|
*/
|
|
103
115
|
isConditional(): boolean;
|
|
104
116
|
}
|
|
105
117
|
export type FieldClientConfig = ReturnType<Field['exportForClient']>;
|
|
106
118
|
export declare const conditionalRuleSchema: z.ZodCustom<ConditionalRule, ConditionalRule>;
|
|
119
|
+
export declare const conditionalRuleGroupSchema: z.ZodCustom<ConditionalRuleGroup, ConditionalRuleGroup>;
|
|
107
120
|
/**
|
|
108
121
|
* Base field configuration schema
|
|
109
122
|
* This schema defines the base properties that all fields share
|
|
@@ -116,11 +129,11 @@ export declare const baseFieldConfigSchema: z.ZodObject<{
|
|
|
116
129
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
117
130
|
order: z.ZodOptional<z.ZodNumber>;
|
|
118
131
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
132
|
+
* Make the field visible only when its rule(s) match the current value of the controlling
|
|
133
|
+
* field(s). A single rule is written as a one-element array; two or more rules must be combined
|
|
134
|
+
* explicitly with `and(...)` or `or(...)`.
|
|
122
135
|
*/
|
|
123
|
-
conditionalRules: z.ZodOptional<z.
|
|
136
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<ConditionalRule, ConditionalRule>], null>, z.ZodCustom<ConditionalRuleGroup, ConditionalRuleGroup>]>>;
|
|
124
137
|
/**
|
|
125
138
|
* adminGenerated is used to determine if the field is generated by the admin or not.
|
|
126
139
|
* If set to false, the field will not be included in the form.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/core/fields/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/core/fields/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6B,MAAM,qBAAqB,CAAA;AAC3E,OAAO,KAAK,EACR,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,EACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAE9E,OAAO,KAA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AM,qBAAqB;;;;;;IAW9B;;;;OAIG;;IAKH;;;;OAIG;;;kBAGL,CAAA;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,iBAAiB,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAC1G,iBAAiB,CAAA;AAErB;;GAEG;AACH,UAAU,QAAQ,CAAC,KAAK,SAAS,SAAS,CAAE,SAAQ,eAAe,CAAC,EAAE,CAAC;IACnE,IAAI,EAAE,KAAK,CAAA;CACd"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { entityKind } from '../helpers/index.js';
|
|
1
|
+
import { entityKind, normalizeConditionalRules } from '../helpers/index.js';
|
|
2
2
|
import { resolveMultilingualString } from '../../translations/language-utils.js';
|
|
3
3
|
import * as z from 'zod';
|
|
4
4
|
/**
|
|
@@ -39,10 +39,6 @@ export class Field {
|
|
|
39
39
|
* The primary key is automatically set as the combination of the reference item identifier and the option identifier.
|
|
40
40
|
*/
|
|
41
41
|
destinationDb;
|
|
42
|
-
/**
|
|
43
|
-
* Dynamically generated fields based on the value of `conditionalRules` from conditional fields.
|
|
44
|
-
*/
|
|
45
|
-
conditionalFields = [];
|
|
46
42
|
/*protected*/ value;
|
|
47
43
|
// No need to access the config
|
|
48
44
|
// protected config: BaseFieldConfig<TExtraFieldConfig>
|
|
@@ -121,7 +117,7 @@ export class Field {
|
|
|
121
117
|
label: this.getLocalizedLabel(),
|
|
122
118
|
required: this.required,
|
|
123
119
|
localized: this.localized,
|
|
124
|
-
|
|
120
|
+
conditionalGroup: this.exportConditionalGroup(),
|
|
125
121
|
readonly: this.adminGenerated === 'readonly',
|
|
126
122
|
defaultValue: this.defaultValue,
|
|
127
123
|
value: this.value,
|
|
@@ -131,25 +127,54 @@ export class Field {
|
|
|
131
127
|
return this.adminGenerated === true;
|
|
132
128
|
}
|
|
133
129
|
/**
|
|
134
|
-
*
|
|
130
|
+
* Normalize this field's `conditionalRules` config into a single group of rules, or `undefined`
|
|
131
|
+
* when the field has none. The one place either layer turns the authoring form (a single-rule
|
|
132
|
+
* array or an `and()` / `or()` group) into the group shape the evaluator consumes.
|
|
133
|
+
*/
|
|
134
|
+
getConditionalGroup() {
|
|
135
|
+
return normalizeConditionalRules(this.conditionalRules);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Project this field's rule group into its client-safe form: each rule references its controlling
|
|
139
|
+
* field by name rather than carrying the full field config. Returns `undefined` when not
|
|
140
|
+
* conditional, so it is omitted from the exported config.
|
|
141
|
+
*/
|
|
142
|
+
exportConditionalGroup() {
|
|
143
|
+
const group = this.getConditionalGroup();
|
|
144
|
+
if (!group)
|
|
145
|
+
return undefined;
|
|
146
|
+
return {
|
|
147
|
+
match: group.match,
|
|
148
|
+
rules: group.rules.map((rule) => ({
|
|
149
|
+
field: rule.field.name,
|
|
150
|
+
condition: rule.condition,
|
|
151
|
+
value: rule.value,
|
|
152
|
+
})),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Check if field is conditional.
|
|
157
|
+
*
|
|
158
|
+
* A field is conditional once it has at least one rule that names a controlling field, a
|
|
159
|
+
* condition and a value. `value` is checked against `undefined` rather than for truthiness, so
|
|
160
|
+
* `false`, `0` and `''` stay valid values to compare against.
|
|
135
161
|
*/
|
|
136
162
|
isConditional() {
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return (status = false);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
status = false;
|
|
147
|
-
}
|
|
148
|
-
return status;
|
|
163
|
+
const group = this.getConditionalGroup();
|
|
164
|
+
if (!group || group.rules.length === 0)
|
|
165
|
+
return false;
|
|
166
|
+
return group.rules.every((rule) => !!rule.field && !!rule.condition && rule.value !== undefined);
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
169
|
// Schema for ConditionalRule (circular dependency with FieldConfig, so use custom)
|
|
152
170
|
export const conditionalRuleSchema = z.custom();
|
|
171
|
+
// Schema for a rule group produced by and() / or(). Guarded so a bare multi-rule array (which the
|
|
172
|
+
// config type already forbids) also fails validation at runtime rather than being mistaken for one.
|
|
173
|
+
export const conditionalRuleGroupSchema = z.custom((value) => !!value &&
|
|
174
|
+
typeof value === 'object' &&
|
|
175
|
+
!Array.isArray(value) &&
|
|
176
|
+
(value.match === 'all' || value.match === 'any') &&
|
|
177
|
+
Array.isArray(value.rules));
|
|
153
178
|
/**
|
|
154
179
|
* Base field configuration schema
|
|
155
180
|
* This schema defines the base properties that all fields share
|
|
@@ -165,11 +190,14 @@ export const baseFieldConfigSchema = z.strictObject({
|
|
|
165
190
|
defaultValue: z.any().optional().describe('The default value of the field'),
|
|
166
191
|
order: z.number().optional().describe('The order of the field'),
|
|
167
192
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
193
|
+
* Make the field visible only when its rule(s) match the current value of the controlling
|
|
194
|
+
* field(s). A single rule is written as a one-element array; two or more rules must be combined
|
|
195
|
+
* explicitly with `and(...)` or `or(...)`.
|
|
171
196
|
*/
|
|
172
|
-
conditionalRules: z
|
|
197
|
+
conditionalRules: z
|
|
198
|
+
.union([z.tuple([conditionalRuleSchema]), conditionalRuleGroupSchema])
|
|
199
|
+
.optional()
|
|
200
|
+
.describe('Conditional visibility rules: a single-rule array, or an and()/or() group'),
|
|
173
201
|
/**
|
|
174
202
|
* adminGenerated is used to determine if the field is generated by the admin or not.
|
|
175
203
|
* If set to false, the field will not be included in the form.
|
|
@@ -37,6 +37,7 @@ export type { BaseFieldConfig, FieldClientConfig } from './field.js';
|
|
|
37
37
|
export { FileField } from './fileField.js';
|
|
38
38
|
export { fieldGroup } from './field-group.js';
|
|
39
39
|
export type { FieldGroup, FieldGroupOptions, FieldGroupConfig } from './field-group.js';
|
|
40
|
+
export { and, or } from '../helpers/conditional-rules.js';
|
|
40
41
|
import type { TextFieldConfig } from './text.js';
|
|
41
42
|
import type { NumberFieldConfig } from './number.js';
|
|
42
43
|
import type { TextAreaFieldConfig } from './textArea.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAChD,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAEvE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,YAAY,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,YAAY,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACtD,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEtG,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAChD,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAEvE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACnD,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAElG,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACnD,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE1E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,YAAY,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAA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,MAAM,WAAW,CAAA;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAEhD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,GACjB,eAAe,GACf,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,GACf,mBAAmB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,gBAAgB,GAChB,gBAAgB,GAChB,qBAAqB,GACrB,6BAA6B,GAC7B,mBAAmB,GACnB,cAAc,GACd,eAAe,GACf,oBAAoB,GACpB,gBAAgB,GAChB,eAAe,CAAA"}
|
|
@@ -18,3 +18,5 @@ export { SlugField, slugField } from './slug.js';
|
|
|
18
18
|
export { Field } from './field.js';
|
|
19
19
|
export { FileField } from './fileField.js';
|
|
20
20
|
export { fieldGroup } from './field-group.js';
|
|
21
|
+
// Conditional-rule grouping wrappers, imported by section configs alongside the field factories.
|
|
22
|
+
export { and, or } from '../helpers/conditional-rules.js';
|
|
@@ -75,7 +75,7 @@ export declare class MapField extends Field<'map', Config> {
|
|
|
75
75
|
label: string;
|
|
76
76
|
required: boolean;
|
|
77
77
|
localized?: boolean;
|
|
78
|
-
|
|
78
|
+
conditionalGroup?: import("../types/index.js").ConditionalGroupClient;
|
|
79
79
|
readonly: boolean;
|
|
80
80
|
defaultValue: any;
|
|
81
81
|
};
|
|
@@ -118,7 +118,7 @@ declare const optionsSchema: z.ZodObject<{
|
|
|
118
118
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
119
119
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
120
120
|
order: z.ZodOptional<z.ZodNumber>;
|
|
121
|
-
conditionalRules: z.ZodOptional<z.
|
|
121
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
122
122
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
123
123
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
124
124
|
}, z.core.$strict>;
|
|
@@ -150,7 +150,7 @@ declare const mapFieldConfigSchema: z.ZodObject<{
|
|
|
150
150
|
label: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
151
151
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
152
152
|
order: z.ZodOptional<z.ZodNumber>;
|
|
153
|
-
conditionalRules: z.ZodOptional<z.
|
|
153
|
+
conditionalRules: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodCustom<import("../types/index.js").ConditionalRule, import("../types/index.js").ConditionalRule>], null>, z.ZodCustom<import("../types/index.js").ConditionalRuleGroup, import("../types/index.js").ConditionalRuleGroup>]>>;
|
|
154
154
|
adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
|
|
155
155
|
localized: z.ZodOptional<z.ZodBoolean>;
|
|
156
156
|
}, z.core.$strict>;
|