payload 4.0.0-internal.2fddfc0 → 4.0.0-internal.3aa3d85
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.md +1 -1
- package/bin.js +11 -0
- package/dist/admin/RichText.d.ts +1 -21
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/admin/forms/Field.d.ts +2 -2
- package/dist/admin/forms/Field.d.ts.map +1 -1
- package/dist/admin/forms/Field.js.map +1 -1
- package/dist/admin/forms/Form.d.ts +0 -29
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/admin/functions/index.d.ts +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/types.d.ts +1 -0
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/auth/operations/auth.d.ts +2 -2
- package/dist/auth/operations/auth.d.ts.map +1 -1
- package/dist/auth/operations/auth.js.map +1 -1
- package/dist/auth/operations/login.d.ts +2 -1
- package/dist/auth/operations/login.d.ts.map +1 -1
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/me.js.map +1 -1
- package/dist/auth/operations/refresh.d.ts.map +1 -1
- package/dist/auth/operations/refresh.js +9 -3
- package/dist/auth/operations/refresh.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/auth/sendVerificationEmail.d.ts +2 -2
- package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
- package/dist/auth/sendVerificationEmail.js +1 -1
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/auth/sessions.d.ts +4 -5
- package/dist/auth/sessions.d.ts.map +1 -1
- package/dist/auth/sessions.js +5 -3
- package/dist/auth/sessions.js.map +1 -1
- package/dist/auth/strategies/apiKey.js.map +1 -1
- package/dist/auth/strategies/local/incrementLoginAttempts.d.ts +2 -2
- package/dist/auth/strategies/local/incrementLoginAttempts.d.ts.map +1 -1
- package/dist/auth/strategies/local/incrementLoginAttempts.js +1 -1
- package/dist/auth/strategies/local/incrementLoginAttempts.js.map +1 -1
- package/dist/auth/types.d.ts +28 -21
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
- package/dist/bin/generateImportMap/iterateCollections.js +10 -0
- package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -1
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +11 -3
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -1
- package/dist/collections/config/client.d.ts +1 -1
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js +1 -0
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/config/defaults.d.ts +0 -4
- package/dist/collections/config/defaults.d.ts.map +1 -1
- package/dist/collections/config/defaults.js +0 -15
- package/dist/collections/config/defaults.js.map +1 -1
- package/dist/collections/config/types.d.ts +6 -0
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/operations/findDistinct.d.ts.map +1 -1
- package/dist/collections/operations/findDistinct.js +1 -0
- package/dist/collections/operations/findDistinct.js.map +1 -1
- package/dist/collections/operations/local/count.d.ts +3 -3
- package/dist/collections/operations/local/count.d.ts.map +1 -1
- package/dist/collections/operations/local/count.js.map +1 -1
- package/dist/collections/operations/local/countVersions.d.ts +3 -3
- package/dist/collections/operations/local/countVersions.d.ts.map +1 -1
- package/dist/collections/operations/local/countVersions.js.map +1 -1
- package/dist/collections/operations/local/create.d.ts +3 -3
- package/dist/collections/operations/local/create.d.ts.map +1 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/delete.d.ts +3 -3
- package/dist/collections/operations/local/delete.d.ts.map +1 -1
- package/dist/collections/operations/local/delete.js.map +1 -1
- package/dist/collections/operations/local/duplicate.d.ts +3 -3
- package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/local/duplicate.js.map +1 -1
- package/dist/collections/operations/local/find.d.ts +3 -3
- package/dist/collections/operations/local/find.d.ts.map +1 -1
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +3 -3
- package/dist/collections/operations/local/findByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/collections/operations/local/findDistinct.d.ts +2 -2
- package/dist/collections/operations/local/findDistinct.d.ts.map +1 -1
- package/dist/collections/operations/local/findDistinct.js.map +1 -1
- package/dist/collections/operations/local/findVersionByID.d.ts +3 -3
- package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersionByID.js.map +1 -1
- package/dist/collections/operations/local/findVersions.d.ts +3 -3
- package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersions.js.map +1 -1
- package/dist/collections/operations/local/restoreVersion.d.ts +3 -3
- package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/local/restoreVersion.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +3 -3
- package/dist/collections/operations/local/update.d.ts.map +1 -1
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/utilities/types.d.ts +0 -9
- package/dist/collections/operations/utilities/types.d.ts.map +1 -1
- package/dist/collections/operations/utilities/types.js.map +1 -1
- package/dist/config/client.d.ts +2 -2
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js.map +1 -1
- package/dist/config/defaults.d.ts +0 -4
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +0 -78
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/definePlugin.d.ts +10 -10
- package/dist/config/definePlugin.d.ts.map +1 -1
- package/dist/config/definePlugin.js +7 -11
- package/dist/config/definePlugin.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +137 -13
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +35 -3
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/exports/internal.d.ts +1 -0
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +1 -0
- package/dist/exports/internal.js.map +1 -1
- package/dist/exports/shared.d.ts +3 -2
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +2 -1
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/baseFields/slug/countVersions.d.ts.map +1 -1
- package/dist/fields/baseFields/slug/countVersions.js +6 -8
- package/dist/fields/baseFields/slug/countVersions.js.map +1 -1
- package/dist/fields/baseFields/slug/generateSlug.d.ts +14 -7
- package/dist/fields/baseFields/slug/generateSlug.d.ts.map +1 -1
- package/dist/fields/baseFields/slug/generateSlug.js +53 -73
- package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
- package/dist/fields/baseFields/slug/types.d.ts +14 -0
- package/dist/fields/baseFields/slug/types.d.ts.map +1 -0
- package/dist/fields/baseFields/slug/types.js +6 -0
- package/dist/fields/baseFields/slug/types.js.map +1 -0
- package/dist/fields/config/client.d.ts +1 -1
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +2 -1
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +39 -0
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/types.d.ts +44 -8
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +11 -1
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +10 -1
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/setDefaultBeforeDuplicate.js +1 -0
- package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
- package/dist/fields/sortableFieldTypes.d.ts.map +1 -1
- package/dist/fields/sortableFieldTypes.js +1 -0
- package/dist/fields/sortableFieldTypes.js.map +1 -1
- package/dist/fields/validations.d.ts +4 -1
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +7 -0
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/operations/local/countVersions.d.ts +3 -3
- package/dist/globals/operations/local/countVersions.d.ts.map +1 -1
- package/dist/globals/operations/local/countVersions.js.map +1 -1
- package/dist/globals/operations/local/findOne.d.ts +3 -3
- package/dist/globals/operations/local/findOne.d.ts.map +1 -1
- package/dist/globals/operations/local/findOne.js.map +1 -1
- package/dist/globals/operations/local/findVersionByID.d.ts +3 -3
- package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/local/findVersionByID.js.map +1 -1
- package/dist/globals/operations/local/findVersions.d.ts +3 -3
- package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/local/findVersions.js.map +1 -1
- package/dist/globals/operations/local/restoreVersion.d.ts +3 -3
- package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/globals/operations/local/restoreVersion.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts +3 -3
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/index.bundled.d.ts +365 -300
- package/dist/index.d.ts +59 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/preferences/keys.d.ts +4 -0
- package/dist/preferences/keys.d.ts.map +1 -1
- package/dist/preferences/keys.js +4 -1
- package/dist/preferences/keys.js.map +1 -1
- package/dist/preferences/types.d.ts +15 -0
- package/dist/preferences/types.d.ts.map +1 -1
- package/dist/preferences/types.js +3 -1
- package/dist/preferences/types.js.map +1 -1
- package/dist/types/index.d.ts +8 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.js +1 -14
- package/dist/uploads/fetchAPI-multipart/processMultipart.js.map +1 -1
- package/dist/uploads/matchMimeType.d.ts +8 -0
- package/dist/uploads/matchMimeType.d.ts.map +1 -0
- package/dist/uploads/matchMimeType.js +19 -0
- package/dist/uploads/matchMimeType.js.map +1 -0
- package/dist/uploads/matchMimeType.spec.js +66 -0
- package/dist/uploads/matchMimeType.spec.js.map +1 -0
- package/dist/uploads/types.d.ts +21 -0
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js +6 -0
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts +13 -4
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +139 -61
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +319 -0
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/createLocalReq.d.ts +2 -2
- package/dist/utilities/createLocalReq.d.ts.map +1 -1
- package/dist/utilities/createLocalReq.js.map +1 -1
- package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
- package/dist/utilities/createPayloadRequest.js +1 -0
- package/dist/utilities/createPayloadRequest.js.map +1 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -1
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js +2 -0
- package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -1
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts +7 -1
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts.map +1 -1
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.js +19 -2
- package/dist/utilities/getEntityPermissions/populateFieldPermissions.js.map +1 -1
- package/dist/utilities/isURLAllowed.d.ts.map +1 -1
- package/dist/utilities/isURLAllowed.js +9 -3
- package/dist/utilities/isURLAllowed.js.map +1 -1
- package/dist/utilities/isURLAllowed.spec.js +78 -0
- package/dist/utilities/isURLAllowed.spec.js.map +1 -0
- package/dist/utilities/telemetry/conf/envPaths.d.ts.map +1 -1
- package/dist/utilities/telemetry/conf/envPaths.js +40 -31
- package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
- package/dist/utilities/telemetry/events/adminInit.d.ts.map +1 -1
- package/dist/utilities/telemetry/events/adminInit.js +2 -3
- package/dist/utilities/telemetry/events/adminInit.js.map +1 -1
- package/dist/utilities/telemetry/events/serverInit.d.ts.map +1 -1
- package/dist/utilities/telemetry/events/serverInit.js +2 -3
- package/dist/utilities/telemetry/events/serverInit.js.map +1 -1
- package/dist/utilities/telemetry/index.d.ts +14 -3
- package/dist/utilities/telemetry/index.d.ts.map +1 -1
- package/dist/utilities/telemetry/index.js +6 -1
- package/dist/utilities/telemetry/index.js.map +1 -1
- package/dist/utilities/telemetry/index.spec.js +43 -0
- package/dist/utilities/telemetry/index.spec.js.map +1 -0
- package/dist/versions/schedule/job.js.map +1 -1
- package/package.json +3 -3
- package/dist/fields/baseFields/slug/index.d.ts +0 -89
- package/dist/fields/baseFields/slug/index.d.ts.map +0 -1
- package/dist/fields/baseFields/slug/index.js +0 -81
- package/dist/fields/baseFields/slug/index.js.map +0 -1
- package/dist/utilities/isRSCEnabled.d.ts +0 -12
- package/dist/utilities/isRSCEnabled.d.ts.map +0 -1
- package/dist/utilities/isRSCEnabled.js +0 -14
- package/dist/utilities/isRSCEnabled.js.map +0 -1
|
@@ -4,6 +4,8 @@ import type { SanitizedCollectionConfig } from '../collections/config/types.js';
|
|
|
4
4
|
import type { SanitizedConfig } from '../config/types.js';
|
|
5
5
|
import type { FlattenedField } from '../fields/config/types.js';
|
|
6
6
|
import type { SanitizedGlobalConfig } from '../globals/config/types.js';
|
|
7
|
+
/** Read (`output`) vs write (`input`) shape: `input` is what `create`/`update` accept. */
|
|
8
|
+
export type SchemaVariant = 'input' | 'output';
|
|
7
9
|
/**
|
|
8
10
|
* Returns a JSON Schema Type with 'null' added if the field is not required.
|
|
9
11
|
*/
|
|
@@ -37,8 +39,9 @@ export type FieldsToJSONSchemaArgs = {
|
|
|
37
39
|
* ends up emitted once.
|
|
38
40
|
*/
|
|
39
41
|
typeStringDefinitions: Set<string>;
|
|
42
|
+
variant?: SchemaVariant;
|
|
40
43
|
};
|
|
41
|
-
export declare function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, forceInlineBlocks, i18n, interfaceNameDefinitions, typeStringDefinitions, }: FieldsToJSONSchemaArgs): {
|
|
44
|
+
export declare function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, forceInlineBlocks, i18n, interfaceNameDefinitions, typeStringDefinitions, variant, }: FieldsToJSONSchemaArgs): {
|
|
42
45
|
properties: {
|
|
43
46
|
[k: string]: JSONSchema4;
|
|
44
47
|
};
|
|
@@ -46,19 +49,21 @@ export declare function fieldsToJSONSchema({ collectionIDFieldTypes, config, fie
|
|
|
46
49
|
};
|
|
47
50
|
export declare function entityToJSONSchema(config: SanitizedConfig, entity: SanitizedCollectionConfig | SanitizedGlobalConfig, interfaceNameDefinitions: Map<string, JSONSchema4>, defaultIDType: 'number' | 'text', typeStringDefinitions: Set<string>, collectionIDFieldTypes?: {
|
|
48
51
|
[key: string]: 'number' | 'string';
|
|
49
|
-
}, i18n?: I18n, forceInlineBlocks?: boolean): JSONSchema4;
|
|
52
|
+
}, i18n?: I18n, forceInlineBlocks?: boolean, variant?: SchemaVariant): JSONSchema4;
|
|
50
53
|
/**
|
|
51
54
|
* Like {@link entityToJSONSchema}, but returns a standalone schema for one collection or global:
|
|
52
55
|
* the entity plus only the `$defs` it actually uses, so it resolves on its own rather than
|
|
53
56
|
* as part of the whole config schema.
|
|
54
57
|
*
|
|
55
58
|
* Relationship/upload `$ref`s to other collections are left in place - the caller handles those.
|
|
59
|
+
* (The `input` variant reduces relationships to IDs, so only rich-text node `$defs` still ref them.)
|
|
56
60
|
*/
|
|
57
|
-
export declare function entityToStandaloneJSONSchema({ config, defaultIDType, entity, i18n, }: {
|
|
61
|
+
export declare function entityToStandaloneJSONSchema({ config, defaultIDType, entity, i18n, variant, }: {
|
|
58
62
|
config: SanitizedConfig;
|
|
59
63
|
defaultIDType: 'number' | 'text';
|
|
60
64
|
entity: SanitizedCollectionConfig | SanitizedGlobalConfig;
|
|
61
65
|
i18n?: I18n;
|
|
66
|
+
variant?: SchemaVariant;
|
|
62
67
|
}): JSONSchema4;
|
|
63
68
|
export declare function fieldsToSelectJSONSchema({ config, fields, interfaceNameDefinitions, }: {
|
|
64
69
|
config: SanitizedConfig;
|
|
@@ -74,11 +79,15 @@ export declare function timezonesToJSONSchema(supportedTimezones: SanitizedConfi
|
|
|
74
79
|
* already uses that name - whether it was auto-generated or an explicit `interfaceName` - this one
|
|
75
80
|
* gets a content-hash suffix (`Hero_3F2A1B0C`) so the two don't overwrite each other. Registering
|
|
76
81
|
* the same block shape again reuses its name.
|
|
82
|
+
*
|
|
83
|
+
* The `input` variant adds an `Input` suffix (`HeroInput`) - unless the read-shaped def is already
|
|
84
|
+
* registered with byte-identical content (a block with nothing that differs between input and
|
|
85
|
+
* output), in which case it's shared as-is rather than emitting a redundant twin.
|
|
77
86
|
*/
|
|
78
87
|
export declare function registerBlockInterface(block: {
|
|
79
88
|
interfaceName?: string;
|
|
80
89
|
slug: string;
|
|
81
|
-
}, blockSchema: JSONSchema4, interfaceNameDefinitions: Map<string, JSONSchema4
|
|
90
|
+
}, blockSchema: JSONSchema4, interfaceNameDefinitions: Map<string, JSONSchema4>, variant?: SchemaVariant): string;
|
|
82
91
|
/**
|
|
83
92
|
* This is used for generating the TypeScript types (payload-types.ts) with the payload generate:types command.
|
|
84
93
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configToJSONSchema.d.ts","sourceRoot":"","sources":["../../src/utilities/configToJSONSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAKnE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAsB,cAAc,EAAU,MAAM,2BAA2B,CAAA;AAC3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"configToJSONSchema.d.ts","sourceRoot":"","sources":["../../src/utilities/configToJSONSchema.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { MissingEditorProp } from '../errors/MissingEditorProp.js';
|
|
3
|
-
import { fieldAffectsData } from '../fields/config/types.js';
|
|
3
|
+
import { fieldAffectsData, fieldIsVirtual } from '../fields/config/types.js';
|
|
4
4
|
import { generateJobsJSONSchemas } from '../queues/config/generateJobsJSONSchemas.js';
|
|
5
5
|
import { flattenAllFields } from './flattenAllFields.js';
|
|
6
6
|
import { formatNames, toWords } from './formatLabels.js';
|
|
7
7
|
import { getCollectionIDFieldTypes } from './getCollectionIDFieldTypes.js';
|
|
8
8
|
import { optionsAreEqual } from './optionsAreEqual.js';
|
|
9
|
+
// Virtual fields (computed) and join fields (derived from the inverse relationship) are read-only.
|
|
10
|
+
const fieldIsInputExcluded = (field)=>field.type === 'join' || fieldIsVirtual(field);
|
|
9
11
|
const fieldIsRequired = (field)=>{
|
|
10
12
|
const isConditional = Boolean(field?.admin && field?.admin?.condition);
|
|
11
13
|
if (isConditional) {
|
|
@@ -61,6 +63,22 @@ function generateEntitySelectSchemas(entities) {
|
|
|
61
63
|
required: Object.keys(properties)
|
|
62
64
|
};
|
|
63
65
|
}
|
|
66
|
+
function generateEntityInputSchemas(entities) {
|
|
67
|
+
const properties = [
|
|
68
|
+
...entities
|
|
69
|
+
].reduce((acc, { slug })=>{
|
|
70
|
+
acc[slug] = {
|
|
71
|
+
$ref: `#/$defs/${slug}_input`
|
|
72
|
+
};
|
|
73
|
+
return acc;
|
|
74
|
+
}, {});
|
|
75
|
+
return {
|
|
76
|
+
type: 'object',
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
properties,
|
|
79
|
+
required: Object.keys(properties)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
64
82
|
function generateCollectionJoinsSchemas(collections) {
|
|
65
83
|
const properties = [
|
|
66
84
|
...collections
|
|
@@ -308,11 +326,35 @@ function entityOrFieldToJsDocs({ entity, i18n }) {
|
|
|
308
326
|
}
|
|
309
327
|
return description;
|
|
310
328
|
}
|
|
311
|
-
export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, forceInlineBlocks, i18n, interfaceNameDefinitions, typeStringDefinitions }) {
|
|
329
|
+
export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, forceInlineBlocks, i18n, interfaceNameDefinitions, typeStringDefinitions, variant = 'output' }) {
|
|
312
330
|
const requiredFieldNames = new Set();
|
|
331
|
+
// Registers a named-interface (group/tab/array/select) def and returns its `$ref` name. For input,
|
|
332
|
+
// shares the read-shaped def when byte-identical; otherwise registers an `Input`-suffixed twin so
|
|
333
|
+
// the write shape doesn't collide with the read one.
|
|
334
|
+
const registerNamedInterface = (name, schema)=>{
|
|
335
|
+
if (variant === 'input') {
|
|
336
|
+
const outputDef = interfaceNameDefinitions.get(name);
|
|
337
|
+
if (outputDef && JSON.stringify(outputDef) === JSON.stringify(schema)) {
|
|
338
|
+
return name;
|
|
339
|
+
}
|
|
340
|
+
const inputName = `${name}Input`;
|
|
341
|
+
interfaceNameDefinitions.set(inputName, schema);
|
|
342
|
+
return inputName;
|
|
343
|
+
}
|
|
344
|
+
interfaceNameDefinitions.set(name, schema);
|
|
345
|
+
return name;
|
|
346
|
+
};
|
|
313
347
|
return {
|
|
314
348
|
properties: Object.fromEntries(fields.reduce((fieldSchemas, field, index)=>{
|
|
349
|
+
if (variant === 'input' && fieldIsInputExcluded(field)) {
|
|
350
|
+
return fieldSchemas;
|
|
351
|
+
}
|
|
352
|
+
const hasDefaultValue = 'defaultValue' in field && field.defaultValue !== undefined;
|
|
353
|
+
// `isRequired` only controls nullability (a non-required field gets `| null`). It does not
|
|
354
|
+
// change between variants, so e.g. a defaulted field stays non-null on input.
|
|
315
355
|
const isRequired = fieldAffectsData(field) && fieldIsRequired(field);
|
|
356
|
+
// `isOptionalOnInput` controls the `?`: on input, defaulted fields can be omitted.
|
|
357
|
+
const isOptionalOnInput = variant === 'input' && hasDefaultValue;
|
|
316
358
|
const fieldDescription = entityOrFieldToJsDocs({
|
|
317
359
|
entity: field,
|
|
318
360
|
i18n
|
|
@@ -338,14 +380,14 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
338
380
|
forceInlineBlocks,
|
|
339
381
|
i18n,
|
|
340
382
|
interfaceNameDefinitions,
|
|
341
|
-
typeStringDefinitions
|
|
383
|
+
typeStringDefinitions,
|
|
384
|
+
variant
|
|
342
385
|
})
|
|
343
386
|
}
|
|
344
387
|
};
|
|
345
388
|
if (field.interfaceName) {
|
|
346
|
-
interfaceNameDefinitions.set(field.interfaceName, fieldSchema);
|
|
347
389
|
fieldSchema = {
|
|
348
|
-
$ref: `#/$defs/${field.interfaceName}`
|
|
390
|
+
$ref: `#/$defs/${registerNamedInterface(field.interfaceName, fieldSchema)}`
|
|
349
391
|
};
|
|
350
392
|
}
|
|
351
393
|
break;
|
|
@@ -372,7 +414,8 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
372
414
|
forceInlineBlocks,
|
|
373
415
|
i18n,
|
|
374
416
|
interfaceNameDefinitions,
|
|
375
|
-
typeStringDefinitions
|
|
417
|
+
typeStringDefinitions,
|
|
418
|
+
variant
|
|
376
419
|
});
|
|
377
420
|
const blockSchema = {
|
|
378
421
|
type: 'object',
|
|
@@ -389,7 +432,7 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
389
432
|
]
|
|
390
433
|
};
|
|
391
434
|
return forceInlineBlocks ? blockSchema : {
|
|
392
|
-
$ref: `#/$defs/${registerBlockInterface(block, blockSchema, interfaceNameDefinitions)}`
|
|
435
|
+
$ref: `#/$defs/${registerBlockInterface(block, blockSchema, interfaceNameDefinitions, variant)}`
|
|
393
436
|
};
|
|
394
437
|
})
|
|
395
438
|
} : {}
|
|
@@ -407,6 +450,7 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
407
450
|
case 'code':
|
|
408
451
|
case 'date':
|
|
409
452
|
case 'email':
|
|
453
|
+
case 'slug':
|
|
410
454
|
case 'textarea':
|
|
411
455
|
{
|
|
412
456
|
fieldSchema = {
|
|
@@ -429,13 +473,13 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
429
473
|
forceInlineBlocks,
|
|
430
474
|
i18n,
|
|
431
475
|
interfaceNameDefinitions,
|
|
432
|
-
typeStringDefinitions
|
|
476
|
+
typeStringDefinitions,
|
|
477
|
+
variant
|
|
433
478
|
})
|
|
434
479
|
};
|
|
435
480
|
if (field.interfaceName) {
|
|
436
|
-
interfaceNameDefinitions.set(field.interfaceName, fieldSchema);
|
|
437
481
|
fieldSchema = {
|
|
438
|
-
$ref: `#/$defs/${field.interfaceName}`
|
|
482
|
+
$ref: `#/$defs/${registerNamedInterface(field.interfaceName, fieldSchema)}`
|
|
439
483
|
};
|
|
440
484
|
}
|
|
441
485
|
}
|
|
@@ -560,9 +604,8 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
560
604
|
enum: buildOptionEnums(field.options)
|
|
561
605
|
};
|
|
562
606
|
if (field.interfaceName) {
|
|
563
|
-
interfaceNameDefinitions.set(field.interfaceName, fieldSchema);
|
|
564
607
|
fieldSchema = {
|
|
565
|
-
$ref: `#/$defs/${field.interfaceName}`
|
|
608
|
+
$ref: `#/$defs/${registerNamedInterface(field.interfaceName, fieldSchema)}`
|
|
566
609
|
};
|
|
567
610
|
}
|
|
568
611
|
break;
|
|
@@ -570,6 +613,19 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
570
613
|
case 'relationship':
|
|
571
614
|
case 'upload':
|
|
572
615
|
{
|
|
616
|
+
// Read: an ID or the populated doc. Input: only the ID, so drop the `$ref`.
|
|
617
|
+
const relationValueSchema = (relation)=>variant === 'input' ? {
|
|
618
|
+
type: collectionIDFieldTypes[relation]
|
|
619
|
+
} : {
|
|
620
|
+
oneOf: [
|
|
621
|
+
{
|
|
622
|
+
type: collectionIDFieldTypes[relation]
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
$ref: `#/$defs/${relation}`
|
|
626
|
+
}
|
|
627
|
+
]
|
|
628
|
+
};
|
|
573
629
|
if (Array.isArray(field.relationTo)) {
|
|
574
630
|
if (field.hasMany) {
|
|
575
631
|
fieldSchema = {
|
|
@@ -584,16 +640,7 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
584
640
|
relationTo: {
|
|
585
641
|
const: relation
|
|
586
642
|
},
|
|
587
|
-
value:
|
|
588
|
-
oneOf: [
|
|
589
|
-
{
|
|
590
|
-
type: collectionIDFieldTypes[relation]
|
|
591
|
-
},
|
|
592
|
-
{
|
|
593
|
-
$ref: `#/$defs/${relation}`
|
|
594
|
-
}
|
|
595
|
-
]
|
|
596
|
-
}
|
|
643
|
+
value: relationValueSchema(relation)
|
|
597
644
|
},
|
|
598
645
|
required: [
|
|
599
646
|
'value',
|
|
@@ -614,16 +661,7 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
614
661
|
relationTo: {
|
|
615
662
|
const: relation
|
|
616
663
|
},
|
|
617
|
-
value:
|
|
618
|
-
oneOf: [
|
|
619
|
-
{
|
|
620
|
-
type: collectionIDFieldTypes[relation]
|
|
621
|
-
},
|
|
622
|
-
{
|
|
623
|
-
$ref: `#/$defs/${relation}`
|
|
624
|
-
}
|
|
625
|
-
]
|
|
626
|
-
}
|
|
664
|
+
value: relationValueSchema(relation)
|
|
627
665
|
},
|
|
628
666
|
required: [
|
|
629
667
|
'value',
|
|
@@ -637,7 +675,9 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
637
675
|
fieldSchema = {
|
|
638
676
|
...baseFieldSchema,
|
|
639
677
|
type: withNullableJSONSchemaType('array', isRequired),
|
|
640
|
-
items: {
|
|
678
|
+
items: variant === 'input' ? {
|
|
679
|
+
type: collectionIDFieldTypes[field.relationTo]
|
|
680
|
+
} : {
|
|
641
681
|
oneOf: [
|
|
642
682
|
{
|
|
643
683
|
type: collectionIDFieldTypes[field.relationTo]
|
|
@@ -648,6 +688,11 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
648
688
|
]
|
|
649
689
|
}
|
|
650
690
|
};
|
|
691
|
+
} else if (variant === 'input') {
|
|
692
|
+
fieldSchema = {
|
|
693
|
+
...baseFieldSchema,
|
|
694
|
+
type: withNullableJSONSchemaType(collectionIDFieldTypes[field.relationTo], isRequired)
|
|
695
|
+
};
|
|
651
696
|
} else {
|
|
652
697
|
fieldSchema = {
|
|
653
698
|
...baseFieldSchema,
|
|
@@ -682,7 +727,8 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
682
727
|
i18n,
|
|
683
728
|
interfaceNameDefinitions,
|
|
684
729
|
isRequired,
|
|
685
|
-
typeStringDefinitions
|
|
730
|
+
typeStringDefinitions,
|
|
731
|
+
variant
|
|
686
732
|
})
|
|
687
733
|
};
|
|
688
734
|
} else {
|
|
@@ -735,9 +781,8 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
735
781
|
}
|
|
736
782
|
}
|
|
737
783
|
if (field.interfaceName) {
|
|
738
|
-
interfaceNameDefinitions.set(field.interfaceName, fieldSchema);
|
|
739
784
|
fieldSchema = {
|
|
740
|
-
$ref: `#/$defs/${field.interfaceName}`
|
|
785
|
+
$ref: `#/$defs/${registerNamedInterface(field.interfaceName, fieldSchema)}`
|
|
741
786
|
};
|
|
742
787
|
}
|
|
743
788
|
break;
|
|
@@ -757,13 +802,13 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
757
802
|
forceInlineBlocks,
|
|
758
803
|
i18n,
|
|
759
804
|
interfaceNameDefinitions,
|
|
760
|
-
typeStringDefinitions
|
|
805
|
+
typeStringDefinitions,
|
|
806
|
+
variant
|
|
761
807
|
})
|
|
762
808
|
};
|
|
763
809
|
if (field.interfaceName) {
|
|
764
|
-
interfaceNameDefinitions.set(field.interfaceName, fieldSchema);
|
|
765
810
|
fieldSchema = {
|
|
766
|
-
$ref: `#/$defs/${field.interfaceName}`
|
|
811
|
+
$ref: `#/$defs/${registerNamedInterface(field.interfaceName, fieldSchema)}`
|
|
767
812
|
};
|
|
768
813
|
}
|
|
769
814
|
break;
|
|
@@ -792,12 +837,13 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
792
837
|
if ('jsonSchema' in field && field?.jsonSchema?.length) {
|
|
793
838
|
for (const schema of field.jsonSchema){
|
|
794
839
|
fieldSchema = schema({
|
|
795
|
-
jsonSchema: fieldSchema
|
|
840
|
+
jsonSchema: fieldSchema,
|
|
841
|
+
variant
|
|
796
842
|
});
|
|
797
843
|
}
|
|
798
844
|
}
|
|
799
845
|
if (fieldSchema && fieldAffectsData(field)) {
|
|
800
|
-
if (isRequired && fieldSchema.required !== false) {
|
|
846
|
+
if (isRequired && !isOptionalOnInput && fieldSchema.required !== false) {
|
|
801
847
|
requiredFieldNames.add(field.name);
|
|
802
848
|
}
|
|
803
849
|
fieldSchemas.set(field.name, fieldSchema);
|
|
@@ -808,17 +854,21 @@ export function fieldsToJSONSchema({ collectionIDFieldTypes, config, fields, for
|
|
|
808
854
|
};
|
|
809
855
|
}
|
|
810
856
|
// This function is part of the public API and is exported through payload/utilities
|
|
811
|
-
export function entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType, typeStringDefinitions, collectionIDFieldTypes, i18n, forceInlineBlocks) {
|
|
857
|
+
export function entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType, typeStringDefinitions, collectionIDFieldTypes, i18n, forceInlineBlocks, variant = 'output') {
|
|
812
858
|
if (!collectionIDFieldTypes) {
|
|
813
859
|
collectionIDFieldTypes = getCollectionIDFieldTypes({
|
|
814
860
|
config,
|
|
815
861
|
defaultIDType
|
|
816
862
|
});
|
|
817
863
|
}
|
|
818
|
-
const
|
|
864
|
+
const isInput = variant === 'input';
|
|
865
|
+
const baseTitle = entity.typescript?.interface ? entity.typescript.interface : formatNames(entity.slug).singular;
|
|
866
|
+
const title = isInput ? `${baseTitle}Input` : baseTitle;
|
|
819
867
|
let mutableFields = [
|
|
820
868
|
...entity.flattenedFields
|
|
821
869
|
];
|
|
870
|
+
// `required: true` keeps `id` non-null. On input it's made optional further below (it's dropped
|
|
871
|
+
// from `required`) so you can omit it or pass a custom ID, but it's still never `null`.
|
|
822
872
|
const idField = {
|
|
823
873
|
name: 'id',
|
|
824
874
|
type: defaultIDType,
|
|
@@ -826,20 +876,18 @@ export function entityToJSONSchema(config, entity, interfaceNameDefinitions, def
|
|
|
826
876
|
};
|
|
827
877
|
const customIdField = mutableFields.find((field)=>field.name === 'id');
|
|
828
878
|
if (customIdField && customIdField.type !== 'group' && customIdField.type !== 'tab') {
|
|
829
|
-
mutableFields = mutableFields.map((field)=>{
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
required: true
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
return field;
|
|
837
|
-
});
|
|
879
|
+
mutableFields = mutableFields.map((field)=>field === customIdField ? {
|
|
880
|
+
...field,
|
|
881
|
+
required: true
|
|
882
|
+
} : field);
|
|
838
883
|
} else {
|
|
839
884
|
mutableFields.unshift(idField);
|
|
840
885
|
}
|
|
841
|
-
|
|
842
|
-
|
|
886
|
+
if (isInput) {
|
|
887
|
+
// Managed by Payload, not set by a client.
|
|
888
|
+
mutableFields = mutableFields.filter((field)=>field.name !== 'createdAt' && field.name !== 'updatedAt' && field.name !== '_status');
|
|
889
|
+
} else if ('timestamps' in entity && entity.timestamps !== false) {
|
|
890
|
+
// mark timestamp fields required
|
|
843
891
|
mutableFields = mutableFields.map((field)=>{
|
|
844
892
|
if (field.name === 'createdAt' || field.name === 'updatedAt') {
|
|
845
893
|
return {
|
|
@@ -864,10 +912,16 @@ export function entityToJSONSchema(config, entity, interfaceNameDefinitions, def
|
|
|
864
912
|
forceInlineBlocks,
|
|
865
913
|
i18n,
|
|
866
914
|
interfaceNameDefinitions,
|
|
867
|
-
typeStringDefinitions
|
|
915
|
+
typeStringDefinitions,
|
|
916
|
+
variant
|
|
868
917
|
});
|
|
869
|
-
//
|
|
870
|
-
|
|
918
|
+
// On input, `id` is optional (omit it, or pass a custom ID). Removing it from `required` makes
|
|
919
|
+
// it optional without making it nullable.
|
|
920
|
+
if (isInput && Array.isArray(fieldsSchema.required)) {
|
|
921
|
+
fieldsSchema.required = fieldsSchema.required.filter((name)=>name !== 'id');
|
|
922
|
+
}
|
|
923
|
+
// The `User`-union discriminator (read-side, e.g. `req.user`); not part of create/update data.
|
|
924
|
+
if (isAuthCollection && !isInput) {
|
|
871
925
|
fieldsSchema.properties = {
|
|
872
926
|
...fieldsSchema.properties,
|
|
873
927
|
collection: {
|
|
@@ -903,10 +957,11 @@ export function entityToJSONSchema(config, entity, interfaceNameDefinitions, def
|
|
|
903
957
|
* as part of the whole config schema.
|
|
904
958
|
*
|
|
905
959
|
* Relationship/upload `$ref`s to other collections are left in place - the caller handles those.
|
|
906
|
-
|
|
960
|
+
* (The `input` variant reduces relationships to IDs, so only rich-text node `$defs` still ref them.)
|
|
961
|
+
*/ export function entityToStandaloneJSONSchema({ config, defaultIDType, entity, i18n, variant = 'output' }) {
|
|
907
962
|
const definitions = new Map();
|
|
908
963
|
// entityToJSONSchema fills `definitions` with everything the fields reference (node unions, blocks).
|
|
909
|
-
const schema = entityToJSONSchema(config, entity, definitions, defaultIDType, new Set(), undefined, i18n, true);
|
|
964
|
+
const schema = entityToJSONSchema(config, entity, definitions, defaultIDType, new Set(), undefined, i18n, true, variant);
|
|
910
965
|
// Timezone fields `$ref` supportedTimezones, which lives on the root config schema, so add it here.
|
|
911
966
|
const supportedTimezones = config.admin?.timezones?.supportedTimezones;
|
|
912
967
|
if (supportedTimezones?.length && schemaHasRef([
|
|
@@ -1213,8 +1268,19 @@ const hashBlockSchema = (schema)=>createHash('sha256').update(JSON.stringify(sch
|
|
|
1213
1268
|
* already uses that name - whether it was auto-generated or an explicit `interfaceName` - this one
|
|
1214
1269
|
* gets a content-hash suffix (`Hero_3F2A1B0C`) so the two don't overwrite each other. Registering
|
|
1215
1270
|
* the same block shape again reuses its name.
|
|
1216
|
-
|
|
1217
|
-
|
|
1271
|
+
*
|
|
1272
|
+
* The `input` variant adds an `Input` suffix (`HeroInput`) - unless the read-shaped def is already
|
|
1273
|
+
* registered with byte-identical content (a block with nothing that differs between input and
|
|
1274
|
+
* output), in which case it's shared as-is rather than emitting a redundant twin.
|
|
1275
|
+
*/ export function registerBlockInterface(block, blockSchema, interfaceNameDefinitions, variant = 'output') {
|
|
1276
|
+
const rawName = block.interfaceName ?? toWords(block.slug, true);
|
|
1277
|
+
if (variant === 'input') {
|
|
1278
|
+
const outputDef = interfaceNameDefinitions.get(rawName);
|
|
1279
|
+
if (outputDef && hashBlockSchema(outputDef) === hashBlockSchema(blockSchema)) {
|
|
1280
|
+
return rawName;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
const baseName = variant === 'input' ? `${rawName}Input` : rawName;
|
|
1218
1284
|
const existing = interfaceNameDefinitions.get(baseName);
|
|
1219
1285
|
// The name is free - claim it.
|
|
1220
1286
|
if (!existing) {
|
|
@@ -1261,8 +1327,12 @@ const hashBlockSchema = (schema)=>createHash('sha256').update(JSON.stringify(sch
|
|
|
1261
1327
|
entity: collection
|
|
1262
1328
|
}))
|
|
1263
1329
|
];
|
|
1330
|
+
const generateInputTypes = config.typescript?.generateInputTypes === true;
|
|
1264
1331
|
const entityDefinitions = entities.reduce((acc, { type, entity })=>{
|
|
1265
1332
|
acc[entity.slug] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType, typeStringDefinitions, collectionIDFieldTypes, i18n, forceInlineBlocks);
|
|
1333
|
+
if (generateInputTypes) {
|
|
1334
|
+
acc[`${entity.slug}_input`] = entityToJSONSchema(config, entity, interfaceNameDefinitions, defaultIDType, typeStringDefinitions, collectionIDFieldTypes, i18n, forceInlineBlocks, 'input');
|
|
1335
|
+
}
|
|
1266
1336
|
const select = fieldsToSelectJSONSchema({
|
|
1267
1337
|
config,
|
|
1268
1338
|
fields: entity.flattenedFields,
|
|
@@ -1359,6 +1429,10 @@ const hashBlockSchema = (schema)=>createHash('sha256').update(JSON.stringify(sch
|
|
|
1359
1429
|
globalsSelect: generateEntitySelectSchemas(config.globals || []),
|
|
1360
1430
|
locale: generateLocaleEntitySchemas(config.localization),
|
|
1361
1431
|
widgets: widgetSchemas.schema,
|
|
1432
|
+
...generateInputTypes ? {
|
|
1433
|
+
collectionsInput: generateEntityInputSchemas(config.collections || []),
|
|
1434
|
+
globalsInput: generateEntityInputSchemas(config.globals || [])
|
|
1435
|
+
} : {},
|
|
1362
1436
|
...config.typescript?.strictDraftTypes ? {
|
|
1363
1437
|
strictDraftTypes: {
|
|
1364
1438
|
type: 'boolean',
|
|
@@ -1375,6 +1449,10 @@ const hashBlockSchema = (schema)=>createHash('sha256').update(JSON.stringify(sch
|
|
|
1375
1449
|
'collectionsSelect',
|
|
1376
1450
|
'collectionsJoins',
|
|
1377
1451
|
'globalsSelect',
|
|
1452
|
+
...generateInputTypes ? [
|
|
1453
|
+
'collectionsInput',
|
|
1454
|
+
'globalsInput'
|
|
1455
|
+
] : [],
|
|
1378
1456
|
...config.typescript?.strictDraftTypes ? [
|
|
1379
1457
|
'strictDraftTypes'
|
|
1380
1458
|
] : [],
|