@vcp-dev/site-edit-engine 0.10.10 → 0.10.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.
@@ -8,5 +8,6 @@ export type SiteEditRouteSourceFile = {
8
8
  };
9
9
  export declare function scanNextAppRouterRoutesFromFiles(files: readonly SiteEditRouteSourceFile[]): SiteEditNextRouteConfig[];
10
10
  export declare function resolveNextAppRouteId(pathname: string | null | undefined, routes: SiteEditNextRouteConfig[], basePath?: string): string | undefined;
11
+ export declare function validateNextAppRouterRouteTable(routes: SiteEditNextRouteConfig[]): void;
11
12
  export declare function isNextAppRouterDynamicRoute(routeId: string): boolean;
12
13
  export declare function normalizeNextRoutePath(pathname: string | null | undefined, basePath?: string): string;
@@ -1 +1 @@
1
- import c from"node:fs";import u from"node:path";var P=/^page\.(?:tsx|ts|jsx|js|mjs|cjs)$/;function $(t){let r=W(t);return r?l(r).map(e=>({routeId:g(r,e),entryFile:d(u.relative(t,e))})).sort((e,n)=>e.routeId.localeCompare(n.routeId)):[]}function W(t){for(let r of["app","src/app"]){let e=u.join(t,r);if(c.existsSync(e)&&c.statSync(e).isDirectory()&&l(e).length>0)return e}return null}function l(t){let r=[];for(let e of c.readdirSync(t,{withFileTypes:!0})){let n=u.join(t,e.name);if(e.isDirectory()){if(e.name==="node_modules"||e.name.startsWith(".")||e.name.startsWith("_"))continue;r.push(...l(n));continue}e.isFile()&&P.test(e.name)&&r.push(n)}return r}function g(t,r){let e=d(u.relative(t,u.dirname(r))),n=e?e.split("/").map(S).filter(i=>!!i):[];return n.length===0?"/":`/${n.join("/")}`}function y(t){return t.startsWith("(")&&t.endsWith(")")}function S(t){return!t||t.startsWith("@")||t.startsWith("_")||y(t)?null:A(t)}function A(t){return t.replace(/^\((?:\.|\.\.|\.\.\.)\)/,"")}function d(t){return t.replace(/\\/g,"/")}var j=/^page\.(?:tsx|ts|jsx|js|mjs|cjs)$/,p=/^\[[^\]]+\]$/,h=/^\[\.\.\.[^\]]+\]$/,f=/^\[\[\.\.\.[^\]]+\]\]$/,m=new WeakMap;function k(t){let r=t.map(n=>T(n.path)),e=F(r);return e?r.filter(n=>B(e,n)).map(n=>({routeId:z(e,n),entryFile:n})).sort((n,i)=>n.routeId.localeCompare(i.routeId)):[]}function O(t,r,e=""){let n=x(t,e),i=v(r);return i.exactRouteIds.has(n)?n:i.dynamicMatchers.find(o=>o.matcher.test(n))?.routeId}function v(t){let r=t.map(o=>`${o.routeId}\0${o.entryFile}`).join("\0"),e=m.get(t);if(e?.signature===r)return e;let n=new Set(t.map(o=>o.routeId)),i=t.filter(o=>o.routeId!=="/"&&I(o.routeId)).sort((o,s)=>R(s.routeId)-R(o.routeId)||s.routeId.length-o.routeId.length||o.routeId.localeCompare(s.routeId)).map(o=>({routeId:o.routeId,matcher:N(o.routeId)})),a={signature:r,exactRouteIds:n,dynamicMatchers:i};return m.set(t,a),a}function I(t){return t.split("/").filter(Boolean).some(r=>p.test(r)||h.test(r)||f.test(r))}function Q(t){return I(x(t))}function x(t,r=""){let n=((t??"/").trim()||"/").split(/[?#]/,1)[0]||"/",i=n.startsWith("/")?n:`/${n}`,a=_(r),o=a&&(i===a||i.startsWith(`${a}/`))?i.slice(a.length)||"/":i,s=o.startsWith("/")?o:`/${o}`;return s==="/"?"/":s.replace(/\/+$/,"")}function F(t){return t.some(n=>n.startsWith("app/")&&!w(n))?"app":t.some(n=>n.startsWith("src/app/"))?"src/app":null}function w(t){return/^(?:src\/)?app\/(?:_vcp|\.vcp)/.test(t)}function B(t,r){if(!r.startsWith(`${t}/`))return!1;let e=r.slice(r.lastIndexOf("/")+1);return j.test(e)?r.slice(t.length+1,-e.length-1).split("/").filter(Boolean).every(n=>!n.startsWith("_")&&!n.startsWith(".")):!1}function z(t,r){let e=r.slice(t.length+1).split("/").slice(0,-1).map(C).filter(n=>!!n);return e.length===0?"/":`/${e.join("/")}`}function b(t){return t.startsWith("(")&&t.endsWith(")")}function C(t){return!t||t.startsWith("@")||t.startsWith("_")||b(t)?null:D(t)}function D(t){return t.replace(/^\((?:\.|\.\.|\.\.\.)\)/,"")}function N(t){if(t==="/")return/^\/$/;let r=t.split("/").filter(Boolean).map(e=>f.test(e)?"(?:/.*)?":h.test(e)?"/.+":p.test(e)?"/[^/]+":`/${M(e)}`).join("");return new RegExp(`^${r}$`)}function R(t){return t.split("/").filter(Boolean).reduce((r,e)=>f.test(e)?r+1:h.test(e)?r+2:p.test(e)?r+3:r+4,0)}function _(t){let r=t.trim();return!r||r==="/"?"":(r.startsWith("/")?r:`/${r}`).replace(/\/+$/,"")}function M(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function T(t){return t.replace(/\\/g,"/").replace(/^\.\//,"")}export{Q as isNextAppRouterDynamicRoute,x as normalizeNextRoutePath,O as resolveNextAppRouteId,$ as scanNextAppRouterRoutes,k as scanNextAppRouterRoutesFromFiles};
1
+ import d from"node:fs";import h from"node:path";var b=/^page\.(?:tsx|ts|jsx|js|mjs|cjs)$/;function C(t){let e=j(t);return e?g(e).map(r=>({routeId:F(e,r),entryFile:N(h.relative(t,r))})).sort((r,n)=>r.routeId.localeCompare(n.routeId)):[]}function j(t){for(let e of["app","src/app"]){let r=h.join(t,e);if(d.existsSync(r)&&d.statSync(r).isDirectory()&&g(r).length>0)return r}return null}function g(t){let e=[];for(let r of d.readdirSync(t,{withFileTypes:!0})){let n=h.join(t,r.name);if(r.isDirectory()){if(r.name==="node_modules"||r.name.startsWith(".")||r.name.startsWith("_"))continue;e.push(...g(n));continue}r.isFile()&&b.test(r.name)&&e.push(n)}return e}function F(t,e){let r=N(h.relative(t,h.dirname(e))),n=r?r.split("/").map(D).filter(s=>!!s):[];return n.length===0?"/":`/${n.join("/")}`}function B(t){return t.startsWith("(")&&t.endsWith(")")}function D(t){return!t||t.startsWith("@")||t.startsWith("_")||B(t)?null:T(t)}function T(t){return t.replace(/^\((?:\.|\.\.|\.\.\.)\)/,"")}function N(t){return t.replace(/\\/g,"/")}var k=/^page\.(?:tsx|ts|jsx|js|mjs|cjs)$/,W=/^\[[^\]]+\]$/,x=/^\[\.\.\.[^\]]+\]$/,P=/^\[\[\.\.\.[^\]]+\]\]$/,$="[]",R="[...]",y="[[...]]",w=new WeakMap;function Z(t){let e=t.map(n=>V(n.path)),r=M(e);return r?e.filter(n=>K(r,n)).map(n=>({routeId:L(r,n),entryFile:n})).sort((n,s)=>n.routeId.localeCompare(s.routeId)):[]}function tt(t,e,r=""){let n=A(t,r),s=I(e);return s.exactRouteIds.has(n)?n:s.dynamicMatchers.find(i=>i.matcher.test(n))?.routeId}function et(t){I(t)}function I(t){let e=t.map(o=>`${o.routeId}\0${o.entryFile}`).join("\0"),r=w.get(t);if(r?.signature===e)return r;let n=new Set;for(let o of t){if(n.has(o.routeId))throw u(`duplicate route id "${o.routeId}".`);n.add(o.routeId)}let s=S();for(let o of t)Y(s,o.routeId);let l=p(s,"/"),i=new Set(t.map(o=>o.routeId)),a=l.filter(o=>o!=="/"&&v(o)).map(o=>({routeId:o,matcher:O(o)})),f={signature:e,exactRouteIds:i,dynamicMatchers:a};return w.set(t,f),f}function u(t){return new Error(`Invalid Next App Router route table: ${t}`)}function S(){return{children:new Map,terminal:!1,slugName:null,restSlugName:null,optionalRestSlugName:null}}function z(t){if(!t.startsWith("[")||!t.endsWith("]"))return null;let e=t.slice(1,-1),r=!1;if(e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1),r=!0),e.includes("\u2026"))throw u(`Detected a three-dot character ('\u2026') at ('${e}'). Did you mean ('...')?`);let n=e.startsWith("...");if(n&&(e=e.slice(3)),e.startsWith("[")||e.endsWith("]"))throw u(`Segment names may not start or end with extra brackets ('${e}').`);if(e.startsWith("."))throw u(`Segment names may not start with erroneous periods ('${e}').`);if(!e)throw u(`Missing parameter name in segment ('${t}').`);if(n)return{kind:r?"optional-rest":"rest",name:e};if(r)throw u(`Optional route parameters are not yet supported ("${t}").`);return{kind:"slug",name:e}}function Y(t,e){let r=e.split("/").filter(Boolean),n=t,s=[];for(let l=0;l<r.length;l+=1){let i=r[l],a=z(i);if(!a){let c=n.children.get(i);c||(c=S(),n.children.set(i,c)),n=c;continue}if((a.kind==="rest"||a.kind==="optional-rest")&&l!==r.length-1)throw u("Catch-all must be the last part of the URL.");for(let c of s){if(c===a.name)throw u(`You cannot have the same slug name "${a.name}" repeat within a single dynamic path ("${e}").`);if(c.replace(/\W/g,"")===a.name.replace(/\W/g,""))throw u(`You cannot have the slug names "${c}" and "${a.name}" differ only by non-word symbols within a single dynamic path ("${e}").`)}s.push(a.name);let o;if(a.kind==="slug"){if(n.slugName!==null&&n.slugName!==a.name)throw u(`You cannot use different slug names for the same dynamic path ('${n.slugName}' !== '${a.name}').`);n.slugName=a.name,o=$}else if(a.kind==="rest"){if(n.optionalRestSlugName!==null)throw u(`You cannot use both an optional and required catch-all route at the same level ("[[...${n.optionalRestSlugName}]]" and "${i}").`);if(n.restSlugName!==null&&n.restSlugName!==a.name)throw u(`You cannot use different slug names for the same dynamic path ('${n.restSlugName}' !== '${a.name}').`);n.restSlugName=a.name,o=R}else{if(n.restSlugName!==null)throw u(`You cannot use both an required and optional catch-all route at the same level ("[...${n.restSlugName}]" and "${i}").`);if(n.optionalRestSlugName!==null&&n.optionalRestSlugName!==a.name)throw u(`You cannot use different slug names for the same dynamic path ('${n.optionalRestSlugName}' !== '${a.name}').`);n.optionalRestSlugName=a.name,o=y}let m=n.children.get(o);m||(m=S(),n.children.set(o,m)),n=m}n.terminal=!0}function p(t,e){let r=[...t.children.keys()].filter(a=>a!==$&&a!==R&&a!==y).sort(),n=[];for(let a of r)n.push(...p(t.children.get(a),`${e}${a}/`));let s=t.children.get($);if(s&&n.push(...p(s,`${e}[${t.slugName}]/`)),t.terminal){if(t.optionalRestSlugName!==null){let a=e==="/"?"/":e.slice(0,-1);throw u(`You cannot define a route with the same specificity as a optional catch-all route ("${a}" and "${a}[[...${t.optionalRestSlugName}]]").`)}n.unshift(e==="/"?"/":e.slice(0,-1))}let l=t.children.get(R);l&&n.push(...p(l,`${e}[...${t.restSlugName}]/`));let i=t.children.get(y);return i&&n.push(...p(i,`${e}[[...${t.optionalRestSlugName}]]/`)),n}function v(t){return t.split("/").filter(Boolean).some(e=>W.test(e)||x.test(e)||P.test(e))}function nt(t){return v(A(t))}function A(t,e=""){let n=((t??"/").trim()||"/").split(/[?#]/,1)[0]||"/",s=n.startsWith("/")?n:`/${n}`,l=Q(e),i=l&&(s===l||s.startsWith(`${l}/`))?s.slice(l.length)||"/":s,a=i.startsWith("/")?i:`/${i}`;return a==="/"?"/":a.replace(/\/+$/,"")}function M(t){return t.some(n=>n.startsWith("app/")&&!_(n))?"app":t.some(n=>n.startsWith("src/app/"))?"src/app":null}function _(t){return/^(?:src\/)?app\/(?:_vcp|\.vcp)/.test(t)}function K(t,e){if(!e.startsWith(`${t}/`))return!1;let r=e.slice(e.lastIndexOf("/")+1);return k.test(r)?e.slice(t.length+1,-r.length-1).split("/").filter(Boolean).every(n=>!n.startsWith("_")&&!n.startsWith(".")):!1}function L(t,e){let r=e.slice(t.length+1).split("/").slice(0,-1).map(q).filter(n=>!!n);return r.length===0?"/":`/${r.join("/")}`}function E(t){return t.startsWith("(")&&t.endsWith(")")}function q(t){return!t||t.startsWith("@")||t.startsWith("_")||E(t)?null:G(t)}function G(t){return t.replace(/^\((?:\.|\.\.|\.\.\.)\)/,"")}function O(t){if(t==="/")return/^\/$/;let e=t.split("/").filter(Boolean).map(r=>P.test(r)?"(?:/.*)?":x.test(r)?"/.+":W.test(r)?"/[^/]+":`/${U(r)}`).join("");return new RegExp(`^${e}$`)}function Q(t){let e=t.trim();return!e||e==="/"?"":(e.startsWith("/")?e:`/${e}`).replace(/\/+$/,"")}function U(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function V(t){return t.replace(/\\/g,"/").replace(/^\.\//,"")}export{nt as isNextAppRouterDynamicRoute,A as normalizeNextRoutePath,tt as resolveNextAppRouteId,C as scanNextAppRouterRoutes,Z as scanNextAppRouterRoutesFromFiles,et as validateNextAppRouterRouteTable};
@@ -480,6 +480,7 @@ export declare class PreviewFileSystemSiteEditEngineRuntime implements PreviewSi
480
480
  effectiveTemplateId?: string | undefined;
481
481
  };
482
482
  error: {
483
+ details?: Record<string, unknown> | undefined;
483
484
  code: "VERSION_STALE" | "RECOVERY_REQUIRED" | "NODE_NOT_FOUND" | "HOME_PAGE_LOCKED" | "ROUTE_NOT_FOUND" | "CAPABILITY_REJECTED" | "CONSTRAINT_VIOLATED" | "INVALID_PARAMS" | "PLAN_FAILED" | "TRANSACTION_PREFLIGHT_FAILED" | "ROUTE_REBUILD_FAILED" | "HISTORY_COMMIT_FAILED" | "MATERIALIZATION_CONFLICT" | "MATERIALIZATION_REJECTED" | "MUTATION_ASSERTION_REQUIRED" | "MUTATION_ASSERTION_INVALID" | "AST_PARSE_ERROR" | "UNSUPPORTED_OPERATION" | "LOCATOR_FAILED" | "INVALID_TARGET" | "WRITE_IO_ERROR" | "CONCURRENT_MODIFIED" | "ROLLBACK_FAILED" | "RECOVERY_PERSIST_FAILED" | "MUTATION_SESSION_REQUIRED" | "LEASE_ASSERTION_INVALID" | "LEASE_ASSERTION_EXPIRED" | "LEASE_ASSERTION_SCOPE_MISMATCH" | "CROSS_PAGE_MOVE_UNSUPPORTED" | "INTERNAL_ERROR";
484
485
  message: string;
485
486
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcp-dev/site-edit-engine",
3
- "version": "0.10.10",
3
+ "version": "0.10.12",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -60,7 +60,7 @@
60
60
  "@babel/parser": "^7.29.3",
61
61
  "@babel/traverse": "^7.29.0",
62
62
  "@babel/types": "^7.29.0",
63
- "@vcp-dev/contracts": "0.10.10",
63
+ "@vcp-dev/contracts": "0.10.12",
64
64
  "yaml": "^2.9.0"
65
65
  },
66
66
  "devDependencies": {