diff --git a/packages/@sanity/base/test/mocks/schema.js b/packages/@sanity/base/test/mocks/schema.js index 0e85db28953..0ab8137dfc5 100644 --- a/packages/@sanity/base/test/mocks/schema.js +++ b/packages/@sanity/base/test/mocks/schema.js @@ -8,7 +8,7 @@ const schema = { type: 'document', icon: Icon, fields: [], - initialValue: () => ({ + initialValues: () => ({ role: 'Developer' }) }, diff --git a/packages/@sanity/desk-tool/test/mocks/schema.js b/packages/@sanity/desk-tool/test/mocks/schema.js index 5cf9a35935e..5f30842a478 100644 --- a/packages/@sanity/desk-tool/test/mocks/schema.js +++ b/packages/@sanity/desk-tool/test/mocks/schema.js @@ -122,7 +122,7 @@ function post() { media: 'mainImage' } }, - initialValue: { + initialValues: { slug: {_type: 'slug', current: 'default-slug'} }, orderings: [ diff --git a/packages/@sanity/initial-value-templates/src/builder.ts b/packages/@sanity/initial-value-templates/src/builder.ts index 25f356f8e9e..7a9cb995d73 100644 --- a/packages/@sanity/initial-value-templates/src/builder.ts +++ b/packages/@sanity/initial-value-templates/src/builder.ts @@ -18,7 +18,7 @@ function defaultTemplateForType( schemaType: type.name, title: type.title || type.name, icon: type.icon, - value: type.initialValue || {_type: type.name} + value: type.initialValues || {_type: type.name} }) } diff --git a/packages/@sanity/initial-value-templates/src/parts/Schema.ts b/packages/@sanity/initial-value-templates/src/parts/Schema.ts index f7c327bd2ad..707555f5c16 100644 --- a/packages/@sanity/initial-value-templates/src/parts/Schema.ts +++ b/packages/@sanity/initial-value-templates/src/parts/Schema.ts @@ -40,7 +40,7 @@ export interface SchemaType { to?: SchemaField[] fields?: SchemaField[] orderings?: Ordering[] - initialValue?: Function | {[key: string]: any} + initialValues?: Function | {[key: string]: any} preview?: { select?: PreviewFields prepare?: PreviewPreparer diff --git a/packages/@sanity/initial-value-templates/test/mocks/schema.js b/packages/@sanity/initial-value-templates/test/mocks/schema.js index 7c971b596f1..d96bb1389be 100644 --- a/packages/@sanity/initial-value-templates/test/mocks/schema.js +++ b/packages/@sanity/initial-value-templates/test/mocks/schema.js @@ -8,7 +8,7 @@ const schema = { type: 'document', icon: Icon, fields: [], - initialValue: () => ({ + initialValues: () => ({ role: 'Developer' }) }, diff --git a/packages/@sanity/schema/src/sanity/validation/types/document.js b/packages/@sanity/schema/src/sanity/validation/types/document.js index 8eb3458d38f..ae0a6157317 100644 --- a/packages/@sanity/schema/src/sanity/validation/types/document.js +++ b/packages/@sanity/schema/src/sanity/validation/types/document.js @@ -4,14 +4,18 @@ import object from './object' export default (typeDefinition, visitorContext) => { const typeDef = object(typeDefinition, visitorContext) - const {initialValue} = typeDef + const {initialValue, initialValues} = typeDef - const hasInitialValue = typeof initialValue !== 'undefined' - if (hasInitialValue && !isPlainObject(initialValue) && typeof initialValue !== 'function') { + const hasInitialValues = typeof initialValues !== 'undefined' + if (hasInitialValues && !isPlainObject(initialValues) && typeof initialValues !== 'function') { typeDef._problems.push( - error(`The "initialValue" property must be either a plain object or a function`) + error(`The "initialValues" property must be either a plain object or a function`) ) } + if (typeof initialValue !== 'undefined') { + typeDef._problems.push(error(`Found property "initialValue" - did you mean "initialValues"?`)) + } + return typeDef } diff --git a/packages/@sanity/structure/test/__snapshots__/DocumentListItem.test.ts.snap b/packages/@sanity/structure/test/__snapshots__/DocumentListItem.test.ts.snap index 49c28732b86..b986dd70f53 100644 --- a/packages/@sanity/structure/test/__snapshots__/DocumentListItem.test.ts.snap +++ b/packages/@sanity/structure/test/__snapshots__/DocumentListItem.test.ts.snap @@ -131,7 +131,7 @@ Object { }, ], "icon": [Function], - "initialValue": Object { + "initialValues": Object { "slug": Object { "_type": "slug", "current": "default-slug", @@ -306,7 +306,7 @@ Object { }, ], "icon": [Function], - "initialValue": Object { + "initialValues": Object { "slug": Object { "_type": "slug", "current": "default-slug", @@ -429,7 +429,7 @@ Object { }, ], "icon": [Function], - "initialValue": Object { + "initialValues": Object { "slug": Object { "_type": "slug", "current": "default-slug", diff --git a/packages/@sanity/structure/test/__snapshots__/documentTypeListItems.test.ts.snap b/packages/@sanity/structure/test/__snapshots__/documentTypeListItems.test.ts.snap index 9dc5d7f3caa..5002677729f 100644 --- a/packages/@sanity/structure/test/__snapshots__/documentTypeListItems.test.ts.snap +++ b/packages/@sanity/structure/test/__snapshots__/documentTypeListItems.test.ts.snap @@ -630,7 +630,7 @@ Array [ }, ], "icon": [Function], - "initialValue": Object { + "initialValues": Object { "slug": Object { "_type": "slug", "current": "default-slug", @@ -1031,7 +1031,7 @@ Array [ }, ], "icon": [Function], - "initialValue": Object { + "initialValues": Object { "slug": Object { "_type": "slug", "current": "default-slug", diff --git a/packages/@sanity/structure/test/mocks/schema.js b/packages/@sanity/structure/test/mocks/schema.js index 5cf9a35935e..5f30842a478 100644 --- a/packages/@sanity/structure/test/mocks/schema.js +++ b/packages/@sanity/structure/test/mocks/schema.js @@ -122,7 +122,7 @@ function post() { media: 'mainImage' } }, - initialValue: { + initialValues: { slug: {_type: 'slug', current: 'default-slug'} }, orderings: [ diff --git a/packages/test-studio/schemas/author.js b/packages/test-studio/schemas/author.js index 025f2ccd682..c51244aa60c 100644 --- a/packages/test-studio/schemas/author.js +++ b/packages/test-studio/schemas/author.js @@ -100,7 +100,7 @@ export default { } ], - initialValue: () => + initialValues: () => new Promise(resolve => setTimeout(resolve, 2500, { name: 'Foo', diff --git a/packages/test-studio/schemas/book.js b/packages/test-studio/schemas/book.js index 7f989c51550..9eba58fa31d 100644 --- a/packages/test-studio/schemas/book.js +++ b/packages/test-studio/schemas/book.js @@ -106,7 +106,7 @@ export default { }) } }, - initialValue: { + initialValues: { title: 'Foo' } }