@shapio/schema 0.5.10 → 0.5.12

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 CHANGED
@@ -746,6 +746,11 @@ export declare const effectiveLayout: (model: ModelDefinition) => DocumentLayout
746
746
  export declare const stripFieldsOf: (layout: DocumentLayout, hasValue: (field: FieldDefinition) => boolean, limit?: number) => FieldDefinition[];
747
747
  /** How the model's entries open (`display.layout`): `document` unless set to `form`. */
748
748
  export declare const entryLayoutOf: (model: ModelDefinition) => EntryLayout;
749
+ /**
750
+ * How `layout` is stored on a model (`display.layout`). Document is the default, so a model that extends
751
+ * nothing leaves it unset. A model that extends another spells it out: unset would inherit the parent's.
752
+ */
753
+ export declare const storedEntryLayout: (model: Pick<ModelDefinition, "extends">, layout: EntryLayout | undefined) => EntryLayout | undefined;
749
754
  /**
750
755
  * One section of a form-layout entry: a `display.groups` group (its `id` and `label`), or a run of
751
756
  * consecutive ungrouped fields (`label` undefined). A run's `id` is `ungrouped-<ID of its first field>`:
@@ -898,8 +903,9 @@ export type DefinitionInputWithIds = (WithIds<ModelDefinitionInput> & {
898
903
  * Applies defaults so that two definitions meaning the same thing are byte-identical once serialized
899
904
  * canonically: a hand-written file that omits `public` hashes the same as one that says `public: true`.
900
905
  * Empty optional strings and arrays are dropped, and so are the defaults of keys added after definitions
901
- * were first hashed (`width: 'full'`, `display.layout: 'document'`). A collection without a plural API ID
902
- * gets the suggested one (`suggestPlural`), so files and definitions from before plural API IDs keep working.
906
+ * were first hashed (`width: 'full'`, and `display.layout: 'document'` on a model that extends nothing). A
907
+ * collection without a plural API ID gets the suggested one (`suggestPlural`), so files and definitions from
908
+ * before plural API IDs keep working.
903
909
  */
904
910
  export declare const normalizeDefinition: (input: DefinitionInputWithIds) => SchemaDefinition;
905
911
  /** Normalizes a definition that is already normalized-shaped (e.g. read back from the database). */
package/dist/index.js CHANGED
@@ -728,6 +728,11 @@ const effectiveLayout = (model) => {
728
728
  const stripFieldsOf = (layout, hasValue, limit = 5) => layout.strip ?? layout.properties.filter(hasValue).slice(0, limit);
729
729
  /** How the model's entries open (`display.layout`): `document` unless set to `form`. */
730
730
  const entryLayoutOf = (model) => model.display.layout ?? "document";
731
+ /**
732
+ * How `layout` is stored on a model (`display.layout`). Document is the default, so a model that extends
733
+ * nothing leaves it unset. A model that extends another spells it out: unset would inherit the parent's.
734
+ */
735
+ const storedEntryLayout = (model, layout) => layout === "document" && !model.extends ? void 0 : layout;
731
736
  const ungroupedSectionId = (first, groupIds) => {
732
737
  let candidate = `ungrouped-${first.id}`;
733
738
  while (groupIds.has(candidate)) candidate = `~${candidate}`;
@@ -1278,17 +1283,18 @@ const normalizeField = (field) => {
1278
1283
  };
1279
1284
  return withoutEmpty(normalized);
1280
1285
  };
1281
- const normalizeModelDisplay = (display) => withoutEmpty({
1286
+ const normalizeModelDisplay = (display, extendsId) => withoutEmpty({
1282
1287
  ...display,
1283
- layout: display?.layout === "document" ? void 0 : display?.layout
1288
+ layout: storedEntryLayout({ extends: extendsId }, display?.layout)
1284
1289
  });
1285
1290
  const normalizeComponentDisplay = (display) => withoutEmpty({ ...display });
1286
1291
  /**
1287
1292
  * Applies defaults so that two definitions meaning the same thing are byte-identical once serialized
1288
1293
  * canonically: a hand-written file that omits `public` hashes the same as one that says `public: true`.
1289
1294
  * Empty optional strings and arrays are dropped, and so are the defaults of keys added after definitions
1290
- * were first hashed (`width: 'full'`, `display.layout: 'document'`). A collection without a plural API ID
1291
- * gets the suggested one (`suggestPlural`), so files and definitions from before plural API IDs keep working.
1295
+ * were first hashed (`width: 'full'`, and `display.layout: 'document'` on a model that extends nothing). A
1296
+ * collection without a plural API ID gets the suggested one (`suggestPlural`), so files and definitions from
1297
+ * before plural API IDs keep working.
1292
1298
  */
1293
1299
  const normalizeDefinition = (input) => {
1294
1300
  const fields = input.fields.map(normalizeField);
@@ -1314,7 +1320,7 @@ const normalizeDefinition = (input) => {
1314
1320
  draftAndPublish: input.draftAndPublish ?? true,
1315
1321
  extends: input.extends,
1316
1322
  fields,
1317
- display: normalizeModelDisplay(input.display)
1323
+ display: normalizeModelDisplay(input.display, input.extends)
1318
1324
  });
1319
1325
  };
1320
1326
  /** Normalizes a definition that is already normalized-shaped (e.g. read back from the database). */
@@ -3189,6 +3195,6 @@ const SeoDefaultsSchema = Type.Object({
3189
3195
  twitterHandle: Type.Union([Type.String({ pattern: SEO_TWITTER_HANDLE_PATTERN.source }), Type.Null()])
3190
3196
  }, closed);
3191
3197
  //#endregion
3192
- export { API_KEY_PATTERN, BIGINTEGER_PATTERN, BUILT_IN_THEME_KEYS, CANVAS_ELIGIBLE, CHANGE_KINDS, CODE_LANGUAGES, COMPONENT_TYPE_SUFFIXES, CUSTOM_EDITOR_ID_PATTERN, ComponentDefinitionInputSchema, ComponentDisplayInputSchema, DATA_TYPES, DATETIME_PATTERN, DATE_PATTERN, DECIMAL_PATTERN, DEFAULT_EDITORS, DEFAULT_SEO_KEYS, DEFINITION_KINDS, DefinitionInputSchema, EDITOR_CATALOG, EMPTY_SEO_DEFAULTS, ENTRY_LAYOUTS, EditorChoiceInputSchema, EnumValueSchema, FIELD_WIDTHS, FieldInputSchema, INLINE_TITLE_TYPES, INTERFACE_TYPE_SUFFIX, INVALID_TEXT_MESSAGE, LOCALE_CODE_PATTERN, LOCK_FILE_FORMAT_VERSION, LOCK_FILE_PATH, LocaleInputSchema, LockEntrySchema, LockFileError, LockFileSchema, MARK_RULES, MAX_API_KEY_LENGTH, MAX_COMPONENT_DEPTH, MAX_DESCRIPTION_LENGTH, MAX_FALLBACK_CHAIN, MAX_FIELDS_PER_DEFINITION, MAX_INHERITANCE_DEPTH, MAX_LABEL_LENGTH, MAX_RICHTEXT_DEPTH, MAX_ROUTE_KEY_LENGTH, MEDIA_KINDS, MODEL_KINDS, MODEL_TYPE_SUFFIXES, MUTATION_PREFIXES, ModelDefinitionInputSchema, ModelDisplayInputSchema, NODE_RULES, PLURAL_FALLBACK_SUFFIX, REFERENCE_DATA_TYPES, RELATION_CARDINALITIES, RESERVED_DEFINITION_API_KEYS, RESERVED_FIELD_API_KEYS, RESERVED_QUERY_NAMES, RESERVED_TYPE_NAMES, RICHTEXT_FORMAT, RICHTEXT_FORMAT_VERSION, ROUTE_KEY_PATTERN, SAFE_LINK_PATTERN, SCALAR_DATA_TYPES, SCHEMA_KIND_DIRECTORIES, SEO_COMPONENT_API_KEY, SEO_COMPONENT_ID, SEO_DESCRIPTION_SOFT_MAX, SEO_EDITOR_ID, SEO_FIELD_IDS, SEO_TITLE_PLACEHOLDER, SEO_TITLE_SOFT_MAX, SEO_TITLE_TEMPLATE_PATTERN, SEO_TWITTER_HANDLE_PATTERN, SETTINGS_SCHEMAS, SITES_DIRECTORY, SLUG_PATTERN, SORT_DIRECTIONS, STABLE_ID_PATTERN, STORAGE_FAMILY, STRIP_DEFAULT_COUNT, SchemaValidationError, SeoDefaultsSchema, SeoLocaleDefaultsSchema, TEXT_TITLE_FIELD_TYPES, THEME_BRAND_TOKENS, THEME_COLOR_PATTERN, THEME_DARK_UI_PAIRS, THEME_KEY_PATTERN, THEME_SEMANTIC_TOKENS, THEME_TEXT_PAIRS, THEME_TOKENS, THEME_UI_PAIRS, THEME_VARIANTS, TIME_PATTERN, TITLE_FIELD_TYPES, UID_PATTERN, UNIQUE_CAPABLE_DATA_TYPES, ancestorChain, applyTitleTemplate, assignIds, canonicalJson, changeDropsValues, checkApiKeySyntax, checkDefaultValue, checkDisplay, checkInheritance, checkThemeContrast, classifyChange, classifyChanges, classifyLocaleChange, collectionQueryName, contrastRatio, createDefinitionIndex, createStableId, decideSync, diffDefinitions, effectiveFormLayout, effectiveLayout, effectiveTitleField, embeddedComponentIds, entryLayoutOf, escapeHtml, findChildDefinitions, findDependentModels, findInvalidText, findReferencingDefinitions, foldApiKey, generatedNames, hashDefinition, isApiKeySyntaxValid, isCanvasEligible, isComponentDefinition, isCoverEligible, isCustomEditorId, isDataType, isDocumentPlaceable, isEmptyRichText, isModelDefinition, isSeoField, isStableId, isValidText, isValidTitleTemplate, issue, listCompatibleEditors, lockCoversSite, lockEntriesForSite, mergeDisplay, mergePulledLock, normalizeDefinition, ownFields, parseDefinition, parseLockFile, plainTextToRichText, renderRichTextHtml, renormalizeDefinition, resolveModelDefinition, resolveSeo, richTextBodyOf, richTextMediaIds, richTextPlainText, richTextToPlainText, routeKeyOf, routePathOf, schemaFilePath, scopeDirectory, scopeOfSchemaFilePath, seoComponentDefinition, seoDefaultsForLocale, serializeDefinition, serializeLockFile, sha256, splitRoutePath, storageFamilyOf, stripFieldsOf, suggestPlural, summarizeChanges, toTypeName, typeChangeDropsValues, uniqueFieldsChangingLocalization, upgradeLockFile, validateDefinition, validateRichText, validateSchema, withDerivedPlural, withSiteCovered };
3198
+ export { API_KEY_PATTERN, BIGINTEGER_PATTERN, BUILT_IN_THEME_KEYS, CANVAS_ELIGIBLE, CHANGE_KINDS, CODE_LANGUAGES, COMPONENT_TYPE_SUFFIXES, CUSTOM_EDITOR_ID_PATTERN, ComponentDefinitionInputSchema, ComponentDisplayInputSchema, DATA_TYPES, DATETIME_PATTERN, DATE_PATTERN, DECIMAL_PATTERN, DEFAULT_EDITORS, DEFAULT_SEO_KEYS, DEFINITION_KINDS, DefinitionInputSchema, EDITOR_CATALOG, EMPTY_SEO_DEFAULTS, ENTRY_LAYOUTS, EditorChoiceInputSchema, EnumValueSchema, FIELD_WIDTHS, FieldInputSchema, INLINE_TITLE_TYPES, INTERFACE_TYPE_SUFFIX, INVALID_TEXT_MESSAGE, LOCALE_CODE_PATTERN, LOCK_FILE_FORMAT_VERSION, LOCK_FILE_PATH, LocaleInputSchema, LockEntrySchema, LockFileError, LockFileSchema, MARK_RULES, MAX_API_KEY_LENGTH, MAX_COMPONENT_DEPTH, MAX_DESCRIPTION_LENGTH, MAX_FALLBACK_CHAIN, MAX_FIELDS_PER_DEFINITION, MAX_INHERITANCE_DEPTH, MAX_LABEL_LENGTH, MAX_RICHTEXT_DEPTH, MAX_ROUTE_KEY_LENGTH, MEDIA_KINDS, MODEL_KINDS, MODEL_TYPE_SUFFIXES, MUTATION_PREFIXES, ModelDefinitionInputSchema, ModelDisplayInputSchema, NODE_RULES, PLURAL_FALLBACK_SUFFIX, REFERENCE_DATA_TYPES, RELATION_CARDINALITIES, RESERVED_DEFINITION_API_KEYS, RESERVED_FIELD_API_KEYS, RESERVED_QUERY_NAMES, RESERVED_TYPE_NAMES, RICHTEXT_FORMAT, RICHTEXT_FORMAT_VERSION, ROUTE_KEY_PATTERN, SAFE_LINK_PATTERN, SCALAR_DATA_TYPES, SCHEMA_KIND_DIRECTORIES, SEO_COMPONENT_API_KEY, SEO_COMPONENT_ID, SEO_DESCRIPTION_SOFT_MAX, SEO_EDITOR_ID, SEO_FIELD_IDS, SEO_TITLE_PLACEHOLDER, SEO_TITLE_SOFT_MAX, SEO_TITLE_TEMPLATE_PATTERN, SEO_TWITTER_HANDLE_PATTERN, SETTINGS_SCHEMAS, SITES_DIRECTORY, SLUG_PATTERN, SORT_DIRECTIONS, STABLE_ID_PATTERN, STORAGE_FAMILY, STRIP_DEFAULT_COUNT, SchemaValidationError, SeoDefaultsSchema, SeoLocaleDefaultsSchema, TEXT_TITLE_FIELD_TYPES, THEME_BRAND_TOKENS, THEME_COLOR_PATTERN, THEME_DARK_UI_PAIRS, THEME_KEY_PATTERN, THEME_SEMANTIC_TOKENS, THEME_TEXT_PAIRS, THEME_TOKENS, THEME_UI_PAIRS, THEME_VARIANTS, TIME_PATTERN, TITLE_FIELD_TYPES, UID_PATTERN, UNIQUE_CAPABLE_DATA_TYPES, ancestorChain, applyTitleTemplate, assignIds, canonicalJson, changeDropsValues, checkApiKeySyntax, checkDefaultValue, checkDisplay, checkInheritance, checkThemeContrast, classifyChange, classifyChanges, classifyLocaleChange, collectionQueryName, contrastRatio, createDefinitionIndex, createStableId, decideSync, diffDefinitions, effectiveFormLayout, effectiveLayout, effectiveTitleField, embeddedComponentIds, entryLayoutOf, escapeHtml, findChildDefinitions, findDependentModels, findInvalidText, findReferencingDefinitions, foldApiKey, generatedNames, hashDefinition, isApiKeySyntaxValid, isCanvasEligible, isComponentDefinition, isCoverEligible, isCustomEditorId, isDataType, isDocumentPlaceable, isEmptyRichText, isModelDefinition, isSeoField, isStableId, isValidText, isValidTitleTemplate, issue, listCompatibleEditors, lockCoversSite, lockEntriesForSite, mergeDisplay, mergePulledLock, normalizeDefinition, ownFields, parseDefinition, parseLockFile, plainTextToRichText, renderRichTextHtml, renormalizeDefinition, resolveModelDefinition, resolveSeo, richTextBodyOf, richTextMediaIds, richTextPlainText, richTextToPlainText, routeKeyOf, routePathOf, schemaFilePath, scopeDirectory, scopeOfSchemaFilePath, seoComponentDefinition, seoDefaultsForLocale, serializeDefinition, serializeLockFile, sha256, splitRoutePath, storageFamilyOf, storedEntryLayout, stripFieldsOf, suggestPlural, summarizeChanges, toTypeName, typeChangeDropsValues, uniqueFieldsChangingLocalization, upgradeLockFile, validateDefinition, validateRichText, validateSchema, withDerivedPlural, withSiteCovered };
3193
3199
 
3194
3200
  //# sourceMappingURL=index.js.map