@plank-cms/plank 0.27.0 → 0.27.1

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.
@@ -12,7 +12,7 @@
12
12
  href="https://fonts.googleapis.com/css2?family=Google+Sans:ital,opsz,wght@0,17..18,400..700;1,17..18,400..700&display=swap"
13
13
  rel="stylesheet"
14
14
  />
15
- <script type="module" crossorigin src="/admin/assets/index-C-XGjg93.js"></script>
15
+ <script type="module" crossorigin src="/admin/assets/index-DZUtOtML.js"></script>
16
16
  <link rel="stylesheet" crossorigin href="/admin/assets/index-BTElP7oS.css">
17
17
  </head>
18
18
  <body>
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { randomBytes } from "crypto";
7
7
  import { resolve, join } from "path";
8
8
  import fs from "fs-extra";
9
9
  import { execa } from "execa";
10
- var PACKAGE_VERSION = "0.27.0";
10
+ var PACKAGE_VERSION = "0.27.1";
11
11
  function generateSecret() {
12
12
  return randomBytes(32).toString("hex");
13
13
  }
@@ -106,7 +106,7 @@ import { dirname, join as join2, resolve as resolve2 } from "path";
106
106
  async function start() {
107
107
  config({ path: resolve2(process.cwd(), ".env") });
108
108
  process.env.PLANK_ADMIN_DIST = join2(dirname(fileURLToPath(import.meta.url)), "admin");
109
- const { start: startServer } = await import("./server-HPYV4HWB.js");
109
+ const { start: startServer } = await import("./server-5JMBMGIN.js");
110
110
  await startServer();
111
111
  }
112
112
 
@@ -3360,6 +3360,21 @@ function resolveLocalizedRow(row, ct, locale, fallbacks = []) {
3360
3360
  function junctionTableName2(sourceTable, fieldName) {
3361
3361
  return `_rel_${sourceTable}_${fieldName}`;
3362
3362
  }
3363
+ function resolveManyToManyBinding(tableName, field) {
3364
+ const isInverse = (field.relationType ?? "many-to-one") === "many-to-many" && typeof field.relatedTable === "string" && field.relatedTable.length > 0 && typeof field.relatedField === "string" && field.relatedField.length > 0;
3365
+ if (isInverse) {
3366
+ return {
3367
+ junctionTable: junctionTableName2(field.relatedTable, field.relatedField),
3368
+ currentIdColumn: "target_id",
3369
+ relatedIdColumn: "source_id"
3370
+ };
3371
+ }
3372
+ return {
3373
+ junctionTable: junctionTableName2(tableName, field.name),
3374
+ currentIdColumn: "source_id",
3375
+ relatedIdColumn: "target_id"
3376
+ };
3377
+ }
3363
3378
  function normalizeNavigationItems(value) {
3364
3379
  if (!Array.isArray(value))
3365
3380
  return value;
@@ -3397,12 +3412,12 @@ function normalizeNavigationFields(row, fields) {
3397
3412
  return out;
3398
3413
  }
3399
3414
  async function syncManyToMany(entryId, tableName, field, targetIds) {
3400
- const jt = junctionTableName2(tableName, field.name);
3401
- await pool_default.query(`DELETE FROM ${quoteIdentifier(jt)} WHERE source_id = $1`, [entryId]);
3415
+ const binding = resolveManyToManyBinding(tableName, field);
3416
+ await pool_default.query(`DELETE FROM ${quoteIdentifier(binding.junctionTable)} WHERE ${quoteIdentifier(binding.currentIdColumn)} = $1`, [entryId]);
3402
3417
  if (targetIds.length === 0)
3403
3418
  return;
3404
- const placeholders = targetIds.map((_3, i2) => `($1, $${i2 + 2})`).join(", ");
3405
- await pool_default.query(`INSERT INTO ${quoteIdentifier(jt)} (source_id, target_id) VALUES ${placeholders} ON CONFLICT DO NOTHING`, [entryId, ...targetIds]);
3419
+ const tuples = targetIds.map((_3, i2) => binding.currentIdColumn === "source_id" ? `($1, $${i2 + 2})` : `($${i2 + 2}, $1)`).join(", ");
3420
+ await pool_default.query(`INSERT INTO ${quoteIdentifier(binding.junctionTable)} (source_id, target_id) VALUES ${tuples} ON CONFLICT DO NOTHING`, [entryId, ...targetIds]);
3406
3421
  }
3407
3422
  async function isContributorRole(roleId) {
3408
3423
  if (!roleId)
@@ -3543,9 +3558,11 @@ async function loadManyToManyIds(entryId, tableName, fields) {
3543
3558
  return {};
3544
3559
  const result = {};
3545
3560
  await Promise.all(mmFields.map(async (f2) => {
3546
- const jt = junctionTableName2(tableName, f2.name);
3547
- const { rows } = await pool_default.query(`SELECT target_id FROM ${quoteIdentifier(jt)} WHERE source_id = $1`, [entryId]);
3548
- result[f2.name] = rows.map((r2) => r2.target_id);
3561
+ const binding = resolveManyToManyBinding(tableName, f2);
3562
+ const { rows } = await pool_default.query(`SELECT ${quoteIdentifier(binding.relatedIdColumn)} AS related_id
3563
+ FROM ${quoteIdentifier(binding.junctionTable)}
3564
+ WHERE ${quoteIdentifier(binding.currentIdColumn)} = $1`, [entryId]);
3565
+ result[f2.name] = rows.map((r2) => r2.related_id);
3549
3566
  }));
3550
3567
  return result;
3551
3568
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plank-cms/plank",
3
- "version": "0.27.0",
3
+ "version": "0.27.1",
4
4
  "description": "Self-hosted headless CMS. Deploy in minutes on your own infrastructure.",
5
5
  "type": "module",
6
6
  "files": [
@@ -55,9 +55,9 @@
55
55
  "devDependencies": {
56
56
  "@types/fs-extra": "^11.0.4",
57
57
  "tsup": "^8.5.0",
58
- "@plank-cms/core": "0.27.0",
59
- "@plank-cms/schema": "0.27.0",
60
- "@plank-cms/db": "0.27.0"
58
+ "@plank-cms/db": "0.27.1",
59
+ "@plank-cms/schema": "0.27.1",
60
+ "@plank-cms/core": "0.27.1"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsup",