@easy-cms/plugin-nested-docs 0.44.0 → 0.46.0

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -2
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -25,6 +25,11 @@ function normalizePath(path) {
25
25
  });
26
26
  return `/${(parts ?? []).join("/")}`;
27
27
  }
28
+ function pathScopeFields(cms, nested) {
29
+ const slug = cms.config.collections.find((c) => c.slug === nested.slug)?.fields.find((f) => f.name === nested.slugField);
30
+ const within = slug?.uniqueWithin === void 0 ? [] : [slug.uniqueWithin].flat();
31
+ return within.filter((name) => name !== nested.parentField);
32
+ }
28
33
 
29
34
  // src/tree.ts
30
35
  import { randomUUID } from "crypto";
@@ -151,16 +156,29 @@ async function findByPath(instance, collection, path, options = {}) {
151
156
  const { nested } = nestedOf(cms, collection);
152
157
  const found = await cms.find(collection, {
153
158
  ...options,
154
- where: { [nested.pathField]: { equals: normalizePath(path) } },
159
+ where: {
160
+ and: [
161
+ { [nested.pathField]: { equals: normalizePath(path) } },
162
+ ...await scopeWhere(cms, nested, options)
163
+ ]
164
+ },
155
165
  limit: 1
156
166
  });
157
167
  return found.docs[0] ?? null;
158
168
  }
169
+ async function scopeWhere(cms, nested, options) {
170
+ const names = pathScopeFields(cms, nested);
171
+ if (names.length === 0 || !options.context) return [];
172
+ const scope = await cms.uniqueScope(nested.slug, nested.slugField, options);
173
+ return names.map((name) => ({ [name]: { equals: scope[name] ?? null } }));
174
+ }
159
175
  async function getTree(instance, collection, options = {}) {
160
176
  const cms = localApi(instance);
161
177
  const { nested } = nestedOf(cms, collection);
178
+ const scope = await scopeWhere(cms, nested, options);
162
179
  const { docs } = await cms.find(collection, {
163
180
  ...options,
181
+ ...scope.length ? { where: { and: scope } } : {},
164
182
  limit: 0,
165
183
  depth: 0,
166
184
  sort: nested.sort
@@ -248,7 +266,7 @@ import {
248
266
  // src/info.ts
249
267
  var INFO = {
250
268
  name: "@easy-cms/plugin-nested-docs",
251
- ...true ? { version: "0.44.0" } : {}
269
+ ...true ? { version: "0.46.0" } : {}
252
270
  };
253
271
 
254
272
  // src/plugin.ts
@@ -377,12 +395,16 @@ function nestedDocsPlugin(options) {
377
395
  { field: names.parent, message: `is too deep: pages go at most ${maxDepth} levels` }
378
396
  ]);
379
397
  }
398
+ const scope = pathScopeFields(cms, nested).map((name) => ({
399
+ [name]: { equals: data[name] ?? null }
400
+ }));
380
401
  for (const [locale, path] of trail.path) {
381
402
  if (!path) continue;
382
403
  const taken = await cms.find(collection.slug, {
383
404
  where: {
384
405
  and: [
385
406
  { [names.path]: { equals: path } },
407
+ ...scope,
386
408
  ...selfId === null ? [] : [{ id: { not_equals: selfId } }]
387
409
  ]
388
410
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-nested-docs",
3
- "version": "0.44.0",
3
+ "version": "0.46.0",
4
4
  "description": "Nested pages for Easy CMS: a parent for each page, breadcrumbs and full paths kept up to date, and a tree in the admin",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,12 +17,12 @@
17
17
  "dist"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@easy-cms/core": "^0.44.0"
20
+ "@easy-cms/core": "^0.46.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@easy-cms/core": "^0.44.0",
24
- "@easy-cms/plugin-redirects": "^0.44.0",
25
- "@easy-cms/db-sqlite": "^0.44.0"
23
+ "@easy-cms/core": "^0.46.0",
24
+ "@easy-cms/db-sqlite": "^0.46.0",
25
+ "@easy-cms/plugin-redirects": "^0.46.0"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=22.12"