@xleddyl/nuxt-cms 0.8.1 → 0.8.2

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.8.1",
4
+ "version": "0.8.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -9,7 +9,7 @@ import { minifyIntrospection, outputIntrospectionFile } from 'gql.tada/internal'
9
9
  import { createJiti } from 'jiti';
10
10
  import { typeName, blockTypeName as blockTypeName$1, blocksFieldTypeName, renderGraphqlSdl } from '../dist/runtime/shared/graphql-sdl.js';
11
11
  import { migrationsDirFor } from '../dist/runtime/shared/migrations-dir.js';
12
- import { entryFieldsFor, isPrivateField, blockTypeName, pageColumnFields, isTranslatableField, isTranslatableMediaField, isStringListField, pageAllFields, normalizeContentEntries, PAGE_PATH_FIELD, pageRoutes, isCollectionKind, isMultiSelect, layoutErrors, listErrors, mobileMediaKey, fieldConditions, selectOptionValues, CONTENT_SLUG_FIELD, pageFieldsTableName, pageMediaTableName, CONTENT_SYSTEM_FIELDS, isRequiredField, pageFields, mediaTypeFilter, DEFAULT_MEDIA_MAX_FILE_SIZE, normalizeCmsConfig } from '../dist/runtime/shared/index.js';
12
+ import { entryFieldsFor, isPrivateField, blockTypeName, pageColumnFields, isTranslatableField, isTranslatableMediaField, isStringListField, pageAllFields, normalizeContentEntries, PAGE_PATH_FIELD, pageRoutes, isCollectionKind, isMultiSelect, layoutErrors, listErrors, mobileMediaKey, fieldConditions, selectOptionValues, pageFieldsTableName, pageMediaTableName, CONTENT_SYSTEM_FIELDS, isRequiredField, pageFields, mediaTypeFilter, DEFAULT_MEDIA_MAX_FILE_SIZE, normalizeCmsConfig } from '../dist/runtime/shared/index.js';
13
13
  import { previewPathErrors, DEFAULT_CMS_PREVIEW_PATH } from '../dist/runtime/shared/preview.js';
14
14
  import { scanMediaDirectory, readMediaFileMeta } from '../dist/runtime/server/utils/media-sync.js';
15
15
  import { createHash } from 'node:crypto';
@@ -482,8 +482,6 @@ function validateConfig(config, i18n) {
482
482
  if (!source) errors.push(`${fat}: slug source '${field.from}' is not a declared field`);
483
483
  else if (source.type !== "text")
484
484
  errors.push(`${fat}: slug source '${field.from}' must be a text field`);
485
- else if (isTranslatableField(source) && !(entry.kind === "content" && key === CONTENT_SLUG_FIELD))
486
- errors.push(`${fat}: slug source '${field.from}' cannot be translatable`);
487
485
  }
488
486
  if (field.type === "tags") {
489
487
  errors.push(...tagsOptionErrors(fat, field));
@@ -761,9 +759,8 @@ function columnExpr(key, field, dialect, table) {
761
759
  expr = `text('${col}').unique()`;
762
760
  break;
763
761
  case "relation": {
764
- const onDelete = field.onDelete ?? (field.required ? "restrict" : "set null");
765
- const target = field.to === table ? `(): ${anyColumnType(dialect)}` : "()";
766
- expr = `text('${col}').references(${target} => ${field.to}.id, { onDelete: '${onDelete}' })`;
762
+ const onDelete = relationOnDelete(field);
763
+ expr = field.to === table ? `text('${col}')` : `text('${col}').references(() => ${field.to}.id, { onDelete: '${onDelete}' })`;
767
764
  if (field.cardinality === "one-to-one") expr += ".unique()";
768
765
  break;
769
766
  }
@@ -773,8 +770,8 @@ function columnExpr(key, field, dialect, table) {
773
770
  if (isRequiredField(field)) expr += ".notNull()";
774
771
  return ` ${key}: ${expr},`;
775
772
  }
776
- function anyColumnType(dialect) {
777
- return dialect === "postgres" ? "AnyPgColumn" : "AnySQLiteColumn";
773
+ function relationOnDelete(field) {
774
+ return field.onDelete ?? (field.required ? "restrict" : "set null");
778
775
  }
779
776
  function isSelfRelation(table, field) {
780
777
  return field.type === "relation" && !isManyToMany(field) && field.to === table;
@@ -792,6 +789,7 @@ function tableExpr(name, entry, dialect) {
792
789
  const pg = dialect === "postgres";
793
790
  const tableFn = pg ? "pgTable" : "sqliteTable";
794
791
  const lines = [];
792
+ const selfReferences = [];
795
793
  lines.push(` id: text('id').primaryKey(),`);
796
794
  if (entry.kind === "page") lines.push(` path: text('path').notNull().unique(),`);
797
795
  for (const [key, field] of Object.entries(
@@ -799,13 +797,22 @@ function tableExpr(name, entry, dialect) {
799
797
  )) {
800
798
  if (isManyToMany(field)) continue;
801
799
  lines.push(columnExpr(key, field, dialect, name));
800
+ if (isSelfRelation(name, field))
801
+ selfReferences.push(
802
+ `foreignKey({ columns: [table.${key}], foreignColumns: [table.id] }).onDelete('${relationOnDelete(
803
+ field
804
+ )}')`
805
+ );
802
806
  }
803
807
  if (entry.drafts) lines.push(` status: text('status').notNull().default('draft'),`);
804
808
  if (isCollectionKind(entry)) lines.push(` createdAt: ${nowExpr(pg, "created_at")},`);
805
809
  lines.push(` updatedAt: ${nowExpr(pg, "updated_at")},`);
810
+ const extra = selfReferences.length ? `, table => [
811
+ ${selfReferences.join(",\n ")},
812
+ ]` : "";
806
813
  return `export const ${name} = ${tableFn}('${name}', {
807
814
  ${lines.join("\n")}
808
- })`;
815
+ }${extra})`;
809
816
  }
810
817
  function joinTableExpr(name, key, field, dialect) {
811
818
  const pg = dialect === "postgres";
@@ -888,18 +895,14 @@ function renderSchemaFile(config, dialect, resolveImport = (s) => s) {
888
895
  core.add("jsonb");
889
896
  if (pg) core.add("timestamp");
890
897
  if (fields.some(isManyToMany) || rowsEntries.length) core.add("primaryKey");
891
- const hasSelfRelation = derived.some(
898
+ if (derived.some(
892
899
  ([name, entry]) => Object.values(entry.kind === "page" ? pageColumnFields(entry) : entry.fields).some(
893
900
  (field) => isSelfRelation(name, field)
894
901
  )
895
- );
902
+ ))
903
+ core.add("foreignKey");
896
904
  const imports = [
897
905
  ...pg ? [] : [`import { sql } from '${resolveImport("drizzle-orm")}'`],
898
- ...hasSelfRelation ? [
899
- `import type { ${anyColumnType(dialect)} } from '${resolveImport(
900
- `drizzle-orm/${pg ? "pg-core" : "sqlite-core"}`
901
- )}'`
902
- ] : [],
903
906
  `import { ${[...core].sort().join(", ")} } from '${resolveImport(
904
907
  `drizzle-orm/${pg ? "pg-core" : "sqlite-core"}`
905
908
  )}'`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/nuxt-cms",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
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)",