@xleddyl/nuxt-cms 0.1.34 → 0.1.35

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
3
  "configKey": "cms",
4
- "version": "0.1.34",
4
+ "version": "0.1.35",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -10,7 +10,7 @@ import { introspectionFromSchema, buildSchema } from 'graphql';
10
10
  import { minifyIntrospection, outputIntrospectionFile } from 'gql.tada/internal';
11
11
  import { createJiti } from 'jiti';
12
12
  import { typeName, blockTypeName, blockUnionName, renderGraphqlSdl } from '../dist/runtime/shared/graphql-sdl.js';
13
- import { isMultiSelect, fieldConditions, isTranslatableField, isTranslatableMediaField, isPrivateField, DEFAULT_MEDIA_MAX_FILE_SIZE } from '../dist/runtime/shared/index.js';
13
+ import { isMultiSelect, fieldConditions, isTranslatableField, isTranslatableMediaField, isRequiredField, isPrivateField, DEFAULT_MEDIA_MAX_FILE_SIZE } from '../dist/runtime/shared/index.js';
14
14
  import { scanMediaDirectory, readMediaFileMeta } from '../dist/runtime/server/utils/media-sync.js';
15
15
 
16
16
  async function collectMediaManifest(root) {
@@ -294,7 +294,7 @@ function columnExpr(key, field, dialect) {
294
294
  let expr;
295
295
  if (isTranslatableField(field)) {
296
296
  expr = isTranslatableMediaField(field) ? `text('${col}')` : jsonExpr(col, dialect);
297
- if (field.required) expr += ".notNull()";
297
+ if (isRequiredField(field)) expr += ".notNull()";
298
298
  return ` ${key}: ${expr},`;
299
299
  }
300
300
  switch (field.type) {
@@ -326,7 +326,7 @@ function columnExpr(key, field, dialect) {
326
326
  default:
327
327
  expr = `text('${col}')`;
328
328
  }
329
- if (field.required) expr += ".notNull()";
329
+ if (isRequiredField(field)) expr += ".notNull()";
330
330
  return ` ${key}: ${expr},`;
331
331
  }
332
332
  function isManyToMany(field) {
@@ -431,7 +431,7 @@ function fieldTsType(config, entryName, key, field) {
431
431
  if (field.type === "relation") {
432
432
  const target = typeName(field.to);
433
433
  if (field.cardinality === "many-to-many") return `${target}[]`;
434
- return field.required && !config[field.to]?.drafts ? target : `${target} | null`;
434
+ return isRequiredField(field) && !config[field.to]?.drafts ? target : `${target} | null`;
435
435
  }
436
436
  if (field.type === "media") return "CmsMedia | null";
437
437
  if (field.type === "select" && field.multiple) {
@@ -440,11 +440,11 @@ function fieldTsType(config, entryName, key, field) {
440
440
  }
441
441
  if (field.type === "blocks") {
442
442
  const union = blockUnionName(entryName, key);
443
- return field.required ? `${union}[]` : `${union}[] | null`;
443
+ return isRequiredField(field) ? `${union}[]` : `${union}[] | null`;
444
444
  }
445
- if (isTranslatableField(field)) return field.required ? "string" : "string | null";
445
+ if (isTranslatableField(field)) return isRequiredField(field) ? "string" : "string | null";
446
446
  const base = scalarTsType(field);
447
- return field.required ? base : `${base} | null`;
447
+ return isRequiredField(field) ? base : `${base} | null`;
448
448
  }
449
449
  function blockTypesTs(entryName, key, field) {
450
450
  const defs = [];
@@ -1,4 +1,4 @@
1
- import { isPrivateField, isTranslatableField } from "./index.js";
1
+ import { isPrivateField, isRequiredField, isTranslatableField } from "./index.js";
2
2
  export function typeName(name) {
3
3
  return name.replace(/(?:^|_)([a-z0-9])/gi, (_, c) => c.toUpperCase());
4
4
  }
@@ -52,14 +52,14 @@ function fieldSdl(config, entryName, key, field) {
52
52
  if (field.type === "relation") {
53
53
  const target = typeName(field.to);
54
54
  if (field.cardinality === "many-to-many") return ` ${key}: [${target}!]!`;
55
- const nonNull = field.required && !config[field.to]?.drafts;
55
+ const nonNull = isRequiredField(field) && !config[field.to]?.drafts;
56
56
  return ` ${key}: ${target}${nonNull ? "!" : ""}`;
57
57
  }
58
58
  if (field.type === "media") return ` ${key}: CmsMedia`;
59
59
  if (field.type === "select" && field.multiple) return ` ${key}: [String!]!`;
60
60
  if (field.type === "blocks")
61
- return ` ${key}: [${blockUnionName(entryName, key)}!]${field.required ? "!" : ""}`;
62
- return ` ${key}: ${scalarFor(field)}${field.required ? "!" : ""}`;
61
+ return ` ${key}: [${blockUnionName(entryName, key)}!]${isRequiredField(field) ? "!" : ""}`;
62
+ return ` ${key}: ${scalarFor(field)}${isRequiredField(field) ? "!" : ""}`;
63
63
  }
64
64
  function entrySdl(config, name, entry) {
65
65
  const lines = [" id: ID!"];
@@ -68,6 +68,7 @@ export interface FieldConfig {
68
68
  showIf?: FieldCondition | FieldCondition[];
69
69
  }
70
70
  export declare function isPrivateField(field: FieldConfig): boolean;
71
+ export declare function isRequiredField(field: FieldConfig): boolean;
71
72
  export declare function fieldConditions(field: FieldConfig): FieldCondition[];
72
73
  export declare function isFieldVisible(field: FieldConfig, values: Record<string, unknown> | null | undefined): boolean;
73
74
  export declare function isTranslatableField(field: FieldConfig): boolean;
@@ -64,6 +64,9 @@ export function normalizeMediaFolder(value) {
64
64
  export function isPrivateField(field) {
65
65
  return !!field.private;
66
66
  }
67
+ export function isRequiredField(field) {
68
+ return !!field.required && !field.showIf;
69
+ }
67
70
  export function fieldConditions(field) {
68
71
  if (!field.showIf) return [];
69
72
  return Array.isArray(field.showIf) ? field.showIf : [field.showIf];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "description": "Lightweight CMS that ships with your Nuxt app: runs on the Nitro server, content types defined in code, /cms admin panel, GraphQL API, SQLite or Postgres. No external CMS needed!",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",