@growi/core 3.1.1 → 3.1.2-next.70cb0d78d48a4262bc6fc975ee83c7c47f0df155

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.
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=129,r=e=>e.startsWith("/")&&e.split("/").filter(t=>t!=="").length>s;exports.exceedsMaxPageDepth=r;
2
+ //# sourceMappingURL=exceeds-max-page-depth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceeds-max-page-depth.cjs","sources":["../../../src/utils/page-path-utils/exceeds-max-page-depth.ts"],"sourcesContent":["const MAX_PAGE_DEPTH = 129;\n\n/**\n * Whether path is nested deeper than a page is allowed to be.\n * Counted rather than matched: a pattern like /^(\\/.+){130,}$/ backtracks\n * exponentially in the number of slashes.\n * @param path\n */\nexport const exceedsMaxPageDepth = (path: string): boolean => {\n return (\n path.startsWith('/') &&\n path.split('/').filter((segment) => segment !== '').length > MAX_PAGE_DEPTH\n );\n};\n"],"names":["MAX_PAGE_DEPTH","exceedsMaxPageDepth","path","segment"],"mappings":"gFAAA,MAAMA,EAAiB,IAQVC,EAAuBC,GAEhCA,EAAK,WAAW,GAAG,GACnBA,EAAK,MAAM,GAAG,EAAE,OAAQC,GAAYA,IAAY,EAAE,EAAE,OAASH"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Whether path is nested deeper than a page is allowed to be.
3
+ * Counted rather than matched: a pattern like /^(\/.+){130,}$/ backtracks
4
+ * exponentially in the number of slashes.
5
+ * @param path
6
+ */
7
+ export declare const exceedsMaxPageDepth: (path: string) => boolean;
@@ -0,0 +1,5 @@
1
+ const s = (t) => t.startsWith("/") && t.split("/").filter((e) => e !== "").length > 129;
2
+ export {
3
+ s as exceedsMaxPageDepth
4
+ };
5
+ //# sourceMappingURL=exceeds-max-page-depth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exceeds-max-page-depth.js","sources":["../../../src/utils/page-path-utils/exceeds-max-page-depth.ts"],"sourcesContent":["const MAX_PAGE_DEPTH = 129;\n\n/**\n * Whether path is nested deeper than a page is allowed to be.\n * Counted rather than matched: a pattern like /^(\\/.+){130,}$/ backtracks\n * exponentially in the number of slashes.\n * @param path\n */\nexport const exceedsMaxPageDepth = (path: string): boolean => {\n return (\n path.startsWith('/') &&\n path.split('/').filter((segment) => segment !== '').length > MAX_PAGE_DEPTH\n );\n};\n"],"names":["exceedsMaxPageDepth","path","segment"],"mappings":"AAQO,MAAMA,IAAsB,CAACC,MAEhCA,EAAK,WAAW,GAAG,KACnBA,EAAK,MAAM,GAAG,EAAE,OAAO,CAACC,MAAYA,MAAY,EAAE,EAAE,SAAS;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../objectid-utils.cjs"),n=require("../path-utils.cjs"),P=require("./is-top-page.cjs"),m=require("./generate-children-regexp.cjs"),i=P.isTopPage,o=e=>e==="/user",d=e=>{const t=e.substring(1);return p.isValidObjectId(t)},c=e=>!!e.match(/^\/user\/[^/]+$/),l=e=>o(e)||c(e),f=e=>!i(e)&&!l(e),$=e=>!!e.match(/^\/user\/.*?$/),E=e=>e==="/trash",T=e=>!!e.match(/^\/trash(\/.*)?$/),w=e=>!!e.match(/^\/share(\/.*)?$/),S=[/\^|\$|\*|\+|#|<|>|%|\?/,/^\/-\/.*/,/^\/_r\/.*/,/^\/_apix?(\/.*)?/,/^\/?https?:\/\/.+$/,/\/{2,}/,/\s+\/\s+/,/.+\/edit$/,/.+\.md$/,/^(\.\.)$/,/(\/\.\.)\/?/,/\\/,/^\/(_search|_private-legacy-pages|_news)(\/.*|$)/,/^\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\/.*|$)/,/^\/user(?:\/[^/]+)?$/,/^(\/.+){130,}$/],u=e=>!S.some(t=>e.match(t)),v=e=>(e==null?void 0:e.username)==null?"":`/user/${e.username}`,x=(e,t,r)=>{if(t==null)throw new Error("Please input the new page path");const a=new RegExp(`^${RegExp.escape(e)}`,"i");return r.replace(a,t)},A=e=>{if(e!=null)return e.replace(/ /g,"%20").replace(/\u3000/g,"%E3%80%80")},R=(...e)=>{const t=[...e].join("/");if(!u(t))throw new Error("Invalid characters on path");try{return`${new URL(t,"https://dummy").pathname}#edit`}catch{throw new Error("Invalid path format")}},b=e=>{const t=Array.from(new Set(e));return t.filter(r=>!(t.filter(s=>new RegExp(`^${s}\\/.+`,"i").test(r)).length>0))},U=e=>e.filter(t=>!e.some(a=>new RegExp(`^${a.path}\\/.+`,"i").test(t.path))),y=(e,t)=>{if(e===t)return!0;const r=n.addTrailingSlash(e),a=n.addTrailingSlash(t),s=new RegExp(`^${RegExp.escape(r)}`,"i"),g=new RegExp(`^${RegExp.escape(a)}`,"i");return!!(s.test(t)||g.test(e))},h=(e,t)=>{if(e===t)return!0;const r=n.addTrailingSlash(e);return!!new RegExp(`^${RegExp.escape(r)}`,"i").test(t)},D=(e,t)=>!h(e,t),O=e=>e.includes("/"),C=e=>{let t=null;const r=e.match(/^\/user\/([^/]+)\/?/);return r&&(t=r[1]),t},j=e=>/^(?:\/[^/*?[\]{}]+)*\/\*$/.test(e);exports.generateChildrenRegExp=m.generateChildrenRegExp;exports.canMoveByPath=D;exports.convertToNewAffiliationPath=x;exports.encodeSpaces=A;exports.generateEditorPath=R;exports.getUsernameByPath=C;exports.hasSlash=O;exports.isCreatablePage=u;exports.isEitherOfPathAreaOverlap=y;exports.isGlobPatternPath=j;exports.isMovablePage=f;exports.isPathAreaOverlap=h;exports.isPermalink=d;exports.isSharedPage=w;exports.isTopPage=i;exports.isTrashPage=T;exports.isTrashTopPage=E;exports.isUserPage=$;exports.isUsersHomepage=c;exports.isUsersProtectedPages=l;exports.isUsersTopPage=o;exports.omitDuplicateAreaPageFromPages=U;exports.omitDuplicateAreaPathFromPaths=b;exports.userHomepagePath=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../objectid-utils.cjs"),n=require("../path-utils.cjs"),i=require("./exceeds-max-page-depth.cjs"),m=require("./is-top-page.cjs"),d=require("./generate-children-regexp.cjs"),o=m.isTopPage,c=e=>e==="/user",f=e=>{const t=e.substring(1);return P.isValidObjectId(t)},l=e=>!!e.match(/^\/user\/[^/]+$/),u=e=>c(e)||l(e),x=e=>!o(e)&&!u(e),$=e=>!!e.match(/^\/user\/.*?$/),E=e=>e==="/trash",T=e=>!!e.match(/^\/trash(\/.*)?$/),w=e=>!!e.match(/^\/share(\/.*)?$/),S=[/\^|\$|\*|\+|#|<|>|%|\?/,/^\/-\/.*/,/^\/_r\/.*/,/^\/_apix?(\/.*)?/,/^\/?https?:\/\/.+$/,/\/{2,}/,/\s\/\s/,/.\/edit$/,/.\.md$/,/^(\.\.)$/,/(\/\.\.)\/?/,/\\/,/^\/(_search|_private-legacy-pages|_news)(\/.*|$)/,/^\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\/.*|$)/,/^\/user(?:\/[^/]+)?$/],h=e=>!S.some(t=>e.match(t))&&!i.exceedsMaxPageDepth(e),v=e=>(e==null?void 0:e.username)==null?"":`/user/${e.username}`,A=(e,t,r)=>{if(t==null)throw new Error("Please input the new page path");const a=new RegExp(`^${RegExp.escape(e)}`,"i");return r.replace(a,t)},R=e=>{if(e!=null)return e.replace(/ /g,"%20").replace(/\u3000/g,"%E3%80%80")},b=(...e)=>{const t=[...e].join("/");if(!h(t))throw new Error("Invalid characters on path");try{return`${new URL(t,"https://dummy").pathname}#edit`}catch{throw new Error("Invalid path format")}},U=e=>{const t=Array.from(new Set(e));return t.filter(r=>!(t.filter(s=>new RegExp(`^${s}\\/.+`,"i").test(r)).length>0))},D=e=>e.filter(t=>!e.some(a=>new RegExp(`^${a.path}\\/.+`,"i").test(t.path))),y=(e,t)=>{if(e===t)return!0;const r=n.addTrailingSlash(e),a=n.addTrailingSlash(t),s=new RegExp(`^${RegExp.escape(r)}`,"i"),p=new RegExp(`^${RegExp.escape(a)}`,"i");return!!(s.test(t)||p.test(e))},g=(e,t)=>{if(e===t)return!0;const r=n.addTrailingSlash(e);return!!new RegExp(`^${RegExp.escape(r)}`,"i").test(t)},M=(e,t)=>!g(e,t),O=e=>e.includes("/"),q=e=>{let t=null;const r=e.match(/^\/user\/([^/]+)\/?/);return r&&(t=r[1]),t},C=e=>/^(?:\/[^/*?[\]{}]+)*\/\*$/.test(e);exports.exceedsMaxPageDepth=i.exceedsMaxPageDepth;exports.generateChildrenRegExp=d.generateChildrenRegExp;exports.canMoveByPath=M;exports.convertToNewAffiliationPath=A;exports.encodeSpaces=R;exports.generateEditorPath=b;exports.getUsernameByPath=q;exports.hasSlash=O;exports.isCreatablePage=h;exports.isEitherOfPathAreaOverlap=y;exports.isGlobPatternPath=C;exports.isMovablePage=x;exports.isPathAreaOverlap=g;exports.isPermalink=f;exports.isSharedPage=w;exports.isTopPage=o;exports.isTrashPage=T;exports.isTrashTopPage=E;exports.isUserPage=$;exports.isUsersHomepage=l;exports.isUsersProtectedPages=u;exports.isUsersTopPage=c;exports.omitDuplicateAreaPageFromPages=D;exports.omitDuplicateAreaPathFromPaths=U;exports.userHomepagePath=v;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import { isValidObjectId } from '../objectid-utils.js';\nimport { addTrailingSlash } from '../path-utils.js';\nimport { isTopPage as _isTopPage } from './is-top-page.js';\n\nexport const isTopPage = _isTopPage;\n\nexport * from './generate-children-regexp.js';\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isUsersTopPage = (path: string): boolean => {\n return path === '/user';\n};\n\n/**\n * Whether the path is permalink\n * @param path\n */\nexport const isPermalink = (path: string): boolean => {\n const pageIdStr = path.substring(1);\n return isValidObjectId(pageIdStr);\n};\n\n/**\n * Whether path is user's homepage\n * @param path\n */\nexport const isUsersHomepage = (path: string): boolean => {\n // https://regex101.com/r/utVQct/1\n if (path.match(/^\\/user\\/[^/]+$/)) {\n return true;\n }\n return false;\n};\n\n/**\n * Whether path is the protected pages for systems\n * @param path\n */\nexport const isUsersProtectedPages = (path: string): boolean => {\n return isUsersTopPage(path) || isUsersHomepage(path);\n};\n\n/**\n * Whether path is movable\n * @param path\n */\nexport const isMovablePage = (path: string): boolean => {\n return !isTopPage(path) && !isUsersProtectedPages(path);\n};\n\n/**\n * Whether path belongs to the user page\n * @param path\n */\nexport const isUserPage = (path: string): boolean => {\n // https://regex101.com/r/MwifLR/1\n if (path.match(/^\\/user\\/.*?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isTrashTopPage = (path: string): boolean => {\n return path === '/trash';\n};\n\n/**\n * Whether path belongs to the trash page\n * @param path\n */\nexport const isTrashPage = (path: string): boolean => {\n // https://regex101.com/r/BSDdRr/1\n if (path.match(/^\\/trash(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path belongs to the shared page\n * @param path\n */\nexport const isSharedPage = (path: string): boolean => {\n // https://regex101.com/r/ZjdOiB/1\n if (path.match(/^\\/share(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\nconst restrictedPatternsToCreate: Array<RegExp> = [\n /\\^|\\$|\\*|\\+|#|<|>|%|\\?/,\n /^\\/-\\/.*/,\n /^\\/_r\\/.*/,\n /^\\/_apix?(\\/.*)?/,\n /^\\/?https?:\\/\\/.+$/, // avoid miss in renaming\n /\\/{2,}/, // avoid miss in renaming\n /\\s+\\/\\s+/, // avoid miss in renaming\n /.+\\/edit$/,\n /.+\\.md$/,\n /^(\\.\\.)$/, // see: https://github.com/growilabs/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/growilabs/growi/issues/3582\n /\\\\/, // see: https://github.com/growilabs/growi/issues/7241\n /^\\/(_search|_private-legacy-pages|_news)(\\/.*|$)/,\n /^\\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\\/.*|$)/,\n /^\\/user(?:\\/[^/]+)?$/, // https://regex101.com/r/9Eh2S1/1\n /^(\\/.+){130,}$/, // avoid deep layer path. see: https://regex101.com/r/L0kzOD/1\n];\nexport const isCreatablePage = (path: string): boolean => {\n return !restrictedPatternsToCreate.some((pattern) => path.match(pattern));\n};\n\n/**\n * return user's homepage path\n * @param user\n */\nexport const userHomepagePath = (\n user: { username: string } | null | undefined,\n): string => {\n if (user?.username == null) {\n return '';\n }\n return `/user/${user.username}`;\n};\n\n/**\n * return user path\n * @param parentPath\n * @param childPath\n * @param newPath\n */\nexport const convertToNewAffiliationPath = (\n oldPath: string,\n newPath: string,\n childPath: string,\n): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${RegExp.escape(oldPath)}`, 'i');\n return childPath.replace(pathRegExp, newPath);\n};\n\n/**\n * Encode SPACE and IDEOGRAPHIC SPACE\n * @param {string} path\n * @returns {string}\n */\nexport const encodeSpaces = (path?: string): string | undefined => {\n if (path == null) {\n return undefined;\n }\n\n // Encode SPACE and IDEOGRAPHIC SPACE\n return path.replace(/ /g, '%20').replace(/\\u3000/g, '%E3%80%80');\n};\n\n/**\n * Generate editor path\n * @param {string} paths\n * @returns {string}\n */\nexport const generateEditorPath = (...paths: string[]): string => {\n const joinedPath = [...paths].join('/');\n\n if (!isCreatablePage(joinedPath)) {\n throw new Error('Invalid characters on path');\n }\n\n try {\n const url = new URL(joinedPath, 'https://dummy');\n return `${url.pathname}#edit`;\n } catch {\n throw new Error('Invalid path format');\n }\n};\n\n/**\n * return paths without duplicate area of regexp /^${path}\\/.+/i\n * ex. expect(omitDuplicateAreaPathFromPaths(['/A', '/A/B', '/A/B/C'])).toStrictEqual(['/A'])\n * @param paths paths to be tested\n * @returns omitted paths\n */\nexport const omitDuplicateAreaPathFromPaths = (paths: string[]): string[] => {\n const uniquePaths = Array.from(new Set(paths));\n return uniquePaths.filter((path) => {\n const isDuplicate =\n uniquePaths.filter((p) => new RegExp(`^${p}\\\\/.+`, 'i').test(path))\n .length > 0;\n\n return !isDuplicate;\n });\n};\n\n/**\n * return pages with path without duplicate area of regexp /^${path}\\/.+/i\n * if the pages' path are the same, it will NOT omit any of them since the other attributes will not be the same\n * @param paths paths to be tested\n * @returns omitted paths\n */\n// biome-ignore lint/suspicious/noExplicitAny: ignore\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some((p) =>\n new RegExp(`^${p.path}\\\\/.+`, 'i').test(page.path),\n );\n\n return !isDuplicate;\n });\n};\n\n/**\n * Check if the area of either path1 or path2 includes the area of the other path\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isEitherOfPathAreaOverlap = (\n path1: string,\n path2: string,\n): boolean => {\n if (path1 === path2) {\n return true;\n }\n\n const path1WithSlash = addTrailingSlash(path1);\n const path2WithSlash = addTrailingSlash(path2);\n\n const path1Area = new RegExp(`^${RegExp.escape(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${RegExp.escape(path2WithSlash)}`, 'i');\n\n if (path1Area.test(path2) || path2Area.test(path1)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Check if the area of pathToTest includes the area of pathToBeTested\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isPathAreaOverlap = (\n pathToTest: string,\n pathToBeTested: string,\n): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${RegExp.escape(pathWithSlash)}`, 'i');\n if (pathAreaToTest.test(pathToBeTested)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Determine whether can move by fromPath and toPath\n * @param fromPath string\n * @param toPath string\n * @returns boolean\n */\nexport const canMoveByPath = (fromPath: string, toPath: string): boolean => {\n return !isPathAreaOverlap(fromPath, toPath);\n};\n\n/**\n * check if string has '/' in it\n */\nexport const hasSlash = (str: string): boolean => {\n return str.includes('/');\n};\n\n/**\n * Get username from user page path\n * @param path string\n * @returns string | null\n */\nexport const getUsernameByPath = (path: string): string | null => {\n let username: string | null = null;\n // https://regex101.com/r/qj4SfD/1\n const match = path.match(/^\\/user\\/([^/]+)\\/?/);\n if (match) {\n username = match[1];\n }\n\n return username;\n};\n\nexport const isGlobPatternPath = (path: string): boolean => {\n // https://regex101.com/r/IBy7HS/1\n const globPattern = /^(?:\\/[^/*?[\\]{}]+)*\\/\\*$/;\n return globPattern.test(path);\n};\n\nexport * from './is-top-page.js';\n"],"names":["isTopPage","_isTopPage","isUsersTopPage","path","isPermalink","pageIdStr","isValidObjectId","isUsersHomepage","isUsersProtectedPages","isMovablePage","isUserPage","isTrashTopPage","isTrashPage","isSharedPage","restrictedPatternsToCreate","isCreatablePage","pattern","userHomepagePath","user","convertToNewAffiliationPath","oldPath","newPath","childPath","pathRegExp","encodeSpaces","generateEditorPath","paths","joinedPath","omitDuplicateAreaPathFromPaths","uniquePaths","p","omitDuplicateAreaPageFromPages","pages","page","isEitherOfPathAreaOverlap","path1","path2","path1WithSlash","addTrailingSlash","path2WithSlash","path1Area","path2Area","isPathAreaOverlap","pathToTest","pathToBeTested","pathWithSlash","canMoveByPath","fromPath","toPath","hasSlash","str","getUsernameByPath","username","match","isGlobPatternPath"],"mappings":"mOAIaA,EAAYC,EAAAA,UAQZC,EAAkBC,GACtBA,IAAS,QAOLC,EAAeD,GAA0B,CACpD,MAAME,EAAYF,EAAK,UAAU,CAAC,EAClC,OAAOG,EAAAA,gBAAgBD,CAAS,CAClC,EAMaE,EAAmBJ,GAE1B,EAAAA,EAAK,MAAM,iBAAiB,EAUrBK,EAAyBL,GAC7BD,EAAeC,CAAI,GAAKI,EAAgBJ,CAAI,EAOxCM,EAAiBN,GACrB,CAACH,EAAUG,CA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CAAC,QAAS,GAAG,EAAE,KAAK3B,CAAI,CAAC,EAC/D,OAAS,EAGf,CACH,EASa4B,EAAkCC,GACtCA,EAAM,OAAQC,GAKZ,CAJaD,EAAM,KAAMF,GAC9B,IAAI,OAAO,IAAIA,EAAE,IAAI,QAAS,GAAG,EAAE,KAAKG,EAAK,IAAI,CAAA,CAIpD,EAUUC,EAA4B,CACvCC,EACAC,IACY,CACZ,GAAID,IAAUC,EACZ,MAAO,GAGT,MAAMC,EAAiBC,EAAAA,iBAAiBH,CAAK,EACvCI,EAAiBD,EAAAA,iBAAiBF,CAAK,EAEvCI,EAAY,IAAI,OAAO,IAAI,OAAO,OAAOH,CAAc,CAAC,GAAI,GAAG,EAC/DI,EAAY,IAAI,OAAO,IAAI,OAAO,OAAOF,CAAc,CAAC,GAAI,GAAG,EAErE,MAAI,GAAAC,EAAU,KAAKJ,CAAK,GAAKK,EAAU,KAAKN,CAAK,EAKnD,EASaO,EAAoB,CAC/BC,EACAC,IACY,CACZ,GAAID,IAAeC,EACjB,MAAO,GAGT,MAAMC,EAAgBP,EAAAA,iBAAiBK,CAAU,EAGjD,MAAI,EADmB,IAAI,OAAO,IAAI,OAAO,OAAOE,CAAa,CAAC,GAAI,GAAG,EACtD,KAAKD,CAAc,CAKxC,EAQaE,EAAgB,CAACC,EAAkBC,IACvC,CAACN,EAAkBK,EAAUC,CAAM,EAM/BC,EAAYC,GAChBA,EAAI,SAAS,GAAG,EAQZC,EAAqBhD,GAAgC,CAChE,IAAIiD,EAA0B,KAE9B,MAAMC,EAAQlD,EAAK,MAAM,qBAAqB,EAC9C,OAAIkD,IACFD,EAAWC,EAAM,CAAC,GAGbD,CACT,EAEaE,EAAqBnD,GAEZ,4BACD,KAAKA,CAAI"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import { isValidObjectId } from '../objectid-utils.js';\nimport { addTrailingSlash } from '../path-utils.js';\nimport { exceedsMaxPageDepth } from './exceeds-max-page-depth.js';\nimport { isTopPage as _isTopPage } from './is-top-page.js';\n\nexport const isTopPage = _isTopPage;\n\nexport * from './generate-children-regexp.js';\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isUsersTopPage = (path: string): boolean => {\n return path === '/user';\n};\n\n/**\n * Whether the path is permalink\n * @param path\n */\nexport const isPermalink = (path: string): boolean => {\n const pageIdStr = path.substring(1);\n return isValidObjectId(pageIdStr);\n};\n\n/**\n * Whether path is user's homepage\n * @param path\n */\nexport const isUsersHomepage = (path: string): boolean => {\n // https://regex101.com/r/utVQct/1\n if (path.match(/^\\/user\\/[^/]+$/)) {\n return true;\n }\n return false;\n};\n\n/**\n * Whether path is the protected pages for systems\n * @param path\n */\nexport const isUsersProtectedPages = (path: string): boolean => {\n return isUsersTopPage(path) || isUsersHomepage(path);\n};\n\n/**\n * Whether path is movable\n * @param path\n */\nexport const isMovablePage = (path: string): boolean => {\n return !isTopPage(path) && !isUsersProtectedPages(path);\n};\n\n/**\n * Whether path belongs to the user page\n * @param path\n */\nexport const isUserPage = (path: string): boolean => {\n // https://regex101.com/r/MwifLR/1\n if (path.match(/^\\/user\\/.*?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isTrashTopPage = (path: string): boolean => {\n return path === '/trash';\n};\n\n/**\n * Whether path belongs to the trash page\n * @param path\n */\nexport const isTrashPage = (path: string): boolean => {\n // https://regex101.com/r/BSDdRr/1\n if (path.match(/^\\/trash(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path belongs to the shared page\n * @param path\n */\nexport const isSharedPage = (path: string): boolean => {\n // https://regex101.com/r/ZjdOiB/1\n if (path.match(/^\\/share(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\nconst restrictedPatternsToCreate: Array<RegExp> = [\n /\\^|\\$|\\*|\\+|#|<|>|%|\\?/,\n /^\\/-\\/.*/,\n /^\\/_r\\/.*/,\n /^\\/_apix?(\\/.*)?/,\n /^\\/?https?:\\/\\/.+$/, // avoid miss in renaming\n /\\/{2,}/, // avoid miss in renaming\n /\\s\\/\\s/, // avoid miss in renaming\n /.\\/edit$/,\n /.\\.md$/,\n /^(\\.\\.)$/, // see: https://github.com/growilabs/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/growilabs/growi/issues/3582\n /\\\\/, // see: https://github.com/growilabs/growi/issues/7241\n /^\\/(_search|_private-legacy-pages|_news)(\\/.*|$)/,\n /^\\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\\/.*|$)/,\n /^\\/user(?:\\/[^/]+)?$/, // https://regex101.com/r/9Eh2S1/1\n];\n\nexport const isCreatablePage = (path: string): boolean => {\n return (\n !restrictedPatternsToCreate.some((pattern) => path.match(pattern)) &&\n !exceedsMaxPageDepth(path)\n );\n};\n\n/**\n * return user's homepage path\n * @param user\n */\nexport const userHomepagePath = (\n user: { username: string } | null | undefined,\n): string => {\n if (user?.username == null) {\n return '';\n }\n return `/user/${user.username}`;\n};\n\n/**\n * return user path\n * @param parentPath\n * @param childPath\n * @param newPath\n */\nexport const convertToNewAffiliationPath = (\n oldPath: string,\n newPath: string,\n childPath: string,\n): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${RegExp.escape(oldPath)}`, 'i');\n return childPath.replace(pathRegExp, newPath);\n};\n\n/**\n * Encode SPACE and IDEOGRAPHIC SPACE\n * @param {string} path\n * @returns {string}\n */\nexport const encodeSpaces = (path?: string): string | undefined => {\n if (path == null) {\n return undefined;\n }\n\n // Encode SPACE and IDEOGRAPHIC SPACE\n return path.replace(/ /g, '%20').replace(/\\u3000/g, '%E3%80%80');\n};\n\n/**\n * Generate editor path\n * @param {string} paths\n * @returns {string}\n */\nexport const generateEditorPath = (...paths: string[]): string => {\n const joinedPath = [...paths].join('/');\n\n if (!isCreatablePage(joinedPath)) {\n throw new Error('Invalid characters on path');\n }\n\n try {\n const url = new URL(joinedPath, 'https://dummy');\n return `${url.pathname}#edit`;\n } catch {\n throw new Error('Invalid path format');\n }\n};\n\n/**\n * return paths without duplicate area of regexp /^${path}\\/.+/i\n * ex. expect(omitDuplicateAreaPathFromPaths(['/A', '/A/B', '/A/B/C'])).toStrictEqual(['/A'])\n * @param paths paths to be tested\n * @returns omitted paths\n */\nexport const omitDuplicateAreaPathFromPaths = (paths: string[]): string[] => {\n const uniquePaths = Array.from(new Set(paths));\n return uniquePaths.filter((path) => {\n const isDuplicate =\n uniquePaths.filter((p) => new RegExp(`^${p}\\\\/.+`, 'i').test(path))\n .length > 0;\n\n return !isDuplicate;\n });\n};\n\n/**\n * return pages with path without duplicate area of regexp /^${path}\\/.+/i\n * if the pages' path are the same, it will NOT omit any of them since the other attributes will not be the same\n * @param paths paths to be tested\n * @returns omitted paths\n */\n// biome-ignore lint/suspicious/noExplicitAny: ignore\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some((p) =>\n new RegExp(`^${p.path}\\\\/.+`, 'i').test(page.path),\n );\n\n return !isDuplicate;\n });\n};\n\n/**\n * Check if the area of either path1 or path2 includes the area of the other path\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isEitherOfPathAreaOverlap = (\n path1: string,\n path2: string,\n): boolean => {\n if (path1 === path2) {\n return true;\n }\n\n const path1WithSlash = addTrailingSlash(path1);\n const path2WithSlash = addTrailingSlash(path2);\n\n const path1Area = new RegExp(`^${RegExp.escape(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${RegExp.escape(path2WithSlash)}`, 'i');\n\n if (path1Area.test(path2) || path2Area.test(path1)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Check if the area of pathToTest includes the area of pathToBeTested\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isPathAreaOverlap = (\n pathToTest: string,\n pathToBeTested: string,\n): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${RegExp.escape(pathWithSlash)}`, 'i');\n if (pathAreaToTest.test(pathToBeTested)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Determine whether can move by fromPath and toPath\n * @param fromPath string\n * @param toPath string\n * @returns boolean\n */\nexport const canMoveByPath = (fromPath: string, toPath: string): boolean => {\n return !isPathAreaOverlap(fromPath, toPath);\n};\n\n/**\n * check if string has '/' in it\n */\nexport const hasSlash = (str: string): boolean => {\n return str.includes('/');\n};\n\n/**\n * Get username from user page path\n * @param path string\n * @returns string | null\n */\nexport const getUsernameByPath = (path: string): string | null => {\n let username: string | null = null;\n // https://regex101.com/r/qj4SfD/1\n const match = path.match(/^\\/user\\/([^/]+)\\/?/);\n if (match) {\n username = match[1];\n }\n\n return username;\n};\n\nexport const isGlobPatternPath = (path: string): boolean => {\n // https://regex101.com/r/IBy7HS/1\n const globPattern = /^(?:\\/[^/*?[\\]{}]+)*\\/\\*$/;\n return globPattern.test(path);\n};\n\nexport * from './exceeds-max-page-depth.js';\nexport * from './is-top-page.js';\n"],"names":["isTopPage","_isTopPage","isUsersTopPage","path","isPermalink","pageIdStr","isValidObjectId","isUsersHomepage","isUsersProtectedPages","isMovablePage","isUserPage","isTrashTopPage","isTrashPage","isSharedPage","restrictedPatternsToCreate","isCreatablePage","pattern","exceedsMaxPageDepth","userHomepagePath","user","convertToNewAffiliationPath","oldPath","newPath","childPath","pathRegExp","encodeSpaces","generateEditorPath","paths","joinedPath","omitDuplicateAreaPathFromPaths","uniquePaths","p","omitDuplicateAreaPageFromPages","pages","page","isEitherOfPathAreaOverlap","path1","path2","path1WithSlash","addTrailingSlash","path2WithSlash","path1Area","path2Area","isPathAreaOverlap","pathToTest","pathToBeTested","pathWithSlash","canMoveByPath","fromPath","toPath","hasSlash","str","getUsernameByPath","username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ChBA,EAAI,SAAS,GAAG,EAQZC,EAAqBjD,GAAgC,CAChE,IAAIkD,EAA0B,KAE9B,MAAMC,EAAQnD,EAAK,MAAM,qBAAqB,EAC9C,OAAImD,IACFD,EAAWC,EAAM,CAAC,GAGbD,CACT,EAEaE,EAAqBpD,GAEZ,4BACD,KAAKA,CAAI"}
@@ -120,4 +120,5 @@ export declare const hasSlash: (str: string) => boolean;
120
120
  */
121
121
  export declare const getUsernameByPath: (path: string) => string | null;
122
122
  export declare const isGlobPatternPath: (path: string) => boolean;
123
+ export * from './exceeds-max-page-depth.js';
123
124
  export * from './is-top-page.js';
@@ -1,11 +1,12 @@
1
1
  import { isValidObjectId as i } from "../objectid-utils.js";
2
2
  import { addTrailingSlash as n } from "../path-utils.js";
3
- import { isTopPage as c } from "./is-top-page.js";
4
- import { generateChildrenRegExp as H } from "./generate-children-regexp.js";
5
- const u = c, l = (e) => e === "/user", E = (e) => {
3
+ import { exceedsMaxPageDepth as c } from "./exceeds-max-page-depth.js";
4
+ import { isTopPage as u } from "./is-top-page.js";
5
+ import { generateChildrenRegExp as k } from "./generate-children-regexp.js";
6
+ const l = u, p = (e) => e === "/user", w = (e) => {
6
7
  const t = e.substring(1);
7
8
  return i(t);
8
- }, h = (e) => !!e.match(/^\/user\/[^/]+$/), p = (e) => l(e) || h(e), w = (e) => !u(e) && !p(e), x = (e) => !!e.match(/^\/user\/.*?$/), R = (e) => e === "/trash", A = (e) => !!e.match(/^\/trash(\/.*)?$/), T = (e) => !!e.match(/^\/share(\/.*)?$/), g = [
9
+ }, h = (e) => !!e.match(/^\/user\/[^/]+$/), g = (e) => p(e) || h(e), R = (e) => !l(e) && !g(e), A = (e) => !!e.match(/^\/user\/.*?$/), T = (e) => e === "/trash", v = (e) => !!e.match(/^\/trash(\/.*)?$/), S = (e) => !!e.match(/^\/share(\/.*)?$/), m = [
9
10
  /\^|\$|\*|\+|#|<|>|%|\?/,
10
11
  /^\/-\/.*/,
11
12
  /^\/_r\/.*/,
@@ -14,10 +15,10 @@ const u = c, l = (e) => e === "/user", E = (e) => {
14
15
  // avoid miss in renaming
15
16
  /\/{2,}/,
16
17
  // avoid miss in renaming
17
- /\s+\/\s+/,
18
+ /\s\/\s/,
18
19
  // avoid miss in renaming
19
- /.+\/edit$/,
20
- /.+\.md$/,
20
+ /.\/edit$/,
21
+ /.\.md$/,
21
22
  /^(\.\.)$/,
22
23
  // see: https://github.com/growilabs/growi/issues/3582
23
24
  /(\/\.\.)\/?/,
@@ -26,71 +27,70 @@ const u = c, l = (e) => e === "/user", E = (e) => {
26
27
  // see: https://github.com/growilabs/growi/issues/7241
27
28
  /^\/(_search|_private-legacy-pages|_news)(\/.*|$)/,
28
29
  /^\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\/.*|$)/,
29
- /^\/user(?:\/[^/]+)?$/,
30
+ /^\/user(?:\/[^/]+)?$/
30
31
  // https://regex101.com/r/9Eh2S1/1
31
- /^(\/.+){130,}$/
32
- // avoid deep layer path. see: https://regex101.com/r/L0kzOD/1
33
- ], m = (e) => !g.some((t) => e.match(t)), v = (e) => (e == null ? void 0 : e.username) == null ? "" : `/user/${e.username}`, S = (e, t, r) => {
32
+ ], f = (e) => !m.some((t) => e.match(t)) && !c(e), b = (e) => (e == null ? void 0 : e.username) == null ? "" : `/user/${e.username}`, D = (e, t, r) => {
34
33
  if (t == null)
35
34
  throw new Error("Please input the new page path");
36
35
  const s = new RegExp(`^${RegExp.escape(e)}`, "i");
37
36
  return r.replace(s, t);
38
- }, b = (e) => {
37
+ }, y = (e) => {
39
38
  if (e != null)
40
39
  return e.replace(/ /g, "%20").replace(/\u3000/g, "%E3%80%80");
41
- }, y = (...e) => {
40
+ }, U = (...e) => {
42
41
  const t = [...e].join("/");
43
- if (!m(t))
42
+ if (!f(t))
44
43
  throw new Error("Invalid characters on path");
45
44
  try {
46
45
  return `${new URL(t, "https://dummy").pathname}#edit`;
47
46
  } catch {
48
47
  throw new Error("Invalid path format");
49
48
  }
50
- }, D = (e) => {
49
+ }, _ = (e) => {
51
50
  const t = Array.from(new Set(e));
52
51
  return t.filter((r) => !(t.filter((a) => new RegExp(`^${a}\\/.+`, "i").test(r)).length > 0));
53
- }, U = (e) => e.filter((t) => !e.some(
52
+ }, I = (e) => e.filter((t) => !e.some(
54
53
  (s) => new RegExp(`^${s.path}\\/.+`, "i").test(t.path)
55
- )), _ = (e, t) => {
54
+ )), O = (e, t) => {
56
55
  if (e === t)
57
56
  return !0;
58
57
  const r = n(e), s = n(t), a = new RegExp(`^${RegExp.escape(r)}`, "i"), o = new RegExp(`^${RegExp.escape(s)}`, "i");
59
58
  return !!(a.test(t) || o.test(e));
60
- }, f = (e, t) => {
59
+ }, P = (e, t) => {
61
60
  if (e === t)
62
61
  return !0;
63
62
  const r = n(e);
64
63
  return !!new RegExp(`^${RegExp.escape(r)}`, "i").test(t);
65
- }, I = (e, t) => !f(e, t), O = (e) => e.includes("/"), j = (e) => {
64
+ }, j = (e, t) => !P(e, t), C = (e) => e.includes("/"), M = (e) => {
66
65
  let t = null;
67
66
  const r = e.match(/^\/user\/([^/]+)\/?/);
68
67
  return r && (t = r[1]), t;
69
- }, C = (e) => /^(?:\/[^/*?[\]{}]+)*\/\*$/.test(e);
68
+ }, W = (e) => /^(?:\/[^/*?[\]{}]+)*\/\*$/.test(e);
70
69
  export {
71
- I as canMoveByPath,
72
- S as convertToNewAffiliationPath,
73
- b as encodeSpaces,
74
- H as generateChildrenRegExp,
75
- y as generateEditorPath,
76
- j as getUsernameByPath,
77
- O as hasSlash,
78
- m as isCreatablePage,
79
- _ as isEitherOfPathAreaOverlap,
80
- C as isGlobPatternPath,
81
- w as isMovablePage,
82
- f as isPathAreaOverlap,
83
- E as isPermalink,
84
- T as isSharedPage,
85
- u as isTopPage,
86
- A as isTrashPage,
87
- R as isTrashTopPage,
88
- x as isUserPage,
70
+ j as canMoveByPath,
71
+ D as convertToNewAffiliationPath,
72
+ y as encodeSpaces,
73
+ c as exceedsMaxPageDepth,
74
+ k as generateChildrenRegExp,
75
+ U as generateEditorPath,
76
+ M as getUsernameByPath,
77
+ C as hasSlash,
78
+ f as isCreatablePage,
79
+ O as isEitherOfPathAreaOverlap,
80
+ W as isGlobPatternPath,
81
+ R as isMovablePage,
82
+ P as isPathAreaOverlap,
83
+ w as isPermalink,
84
+ S as isSharedPage,
85
+ l as isTopPage,
86
+ v as isTrashPage,
87
+ T as isTrashTopPage,
88
+ A as isUserPage,
89
89
  h as isUsersHomepage,
90
- p as isUsersProtectedPages,
91
- l as isUsersTopPage,
92
- U as omitDuplicateAreaPageFromPages,
93
- D as omitDuplicateAreaPathFromPaths,
94
- v as userHomepagePath
90
+ g as isUsersProtectedPages,
91
+ p as isUsersTopPage,
92
+ I as omitDuplicateAreaPageFromPages,
93
+ _ as omitDuplicateAreaPathFromPaths,
94
+ b as userHomepagePath
95
95
  };
96
96
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import { isValidObjectId } from '../objectid-utils.js';\nimport { addTrailingSlash } from '../path-utils.js';\nimport { isTopPage as _isTopPage } from './is-top-page.js';\n\nexport const isTopPage = _isTopPage;\n\nexport * from './generate-children-regexp.js';\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isUsersTopPage = (path: string): boolean => {\n return path === '/user';\n};\n\n/**\n * Whether the path is permalink\n * @param path\n */\nexport const isPermalink = (path: string): boolean => {\n const pageIdStr = path.substring(1);\n return isValidObjectId(pageIdStr);\n};\n\n/**\n * Whether path is user's homepage\n * @param path\n */\nexport const isUsersHomepage = (path: string): boolean => {\n // https://regex101.com/r/utVQct/1\n if (path.match(/^\\/user\\/[^/]+$/)) {\n return true;\n }\n return false;\n};\n\n/**\n * Whether path is the protected pages for systems\n * @param path\n */\nexport const isUsersProtectedPages = (path: string): boolean => {\n return isUsersTopPage(path) || isUsersHomepage(path);\n};\n\n/**\n * Whether path is movable\n * @param path\n */\nexport const isMovablePage = (path: string): boolean => {\n return !isTopPage(path) && !isUsersProtectedPages(path);\n};\n\n/**\n * Whether path belongs to the user page\n * @param path\n */\nexport const isUserPage = (path: string): boolean => {\n // https://regex101.com/r/MwifLR/1\n if (path.match(/^\\/user\\/.*?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isTrashTopPage = (path: string): boolean => {\n return path === '/trash';\n};\n\n/**\n * Whether path belongs to the trash page\n * @param path\n */\nexport const isTrashPage = (path: string): boolean => {\n // https://regex101.com/r/BSDdRr/1\n if (path.match(/^\\/trash(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path belongs to the shared page\n * @param path\n */\nexport const isSharedPage = (path: string): boolean => {\n // https://regex101.com/r/ZjdOiB/1\n if (path.match(/^\\/share(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\nconst restrictedPatternsToCreate: Array<RegExp> = [\n /\\^|\\$|\\*|\\+|#|<|>|%|\\?/,\n /^\\/-\\/.*/,\n /^\\/_r\\/.*/,\n /^\\/_apix?(\\/.*)?/,\n /^\\/?https?:\\/\\/.+$/, // avoid miss in renaming\n /\\/{2,}/, // avoid miss in renaming\n /\\s+\\/\\s+/, // avoid miss in renaming\n /.+\\/edit$/,\n /.+\\.md$/,\n /^(\\.\\.)$/, // see: https://github.com/growilabs/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/growilabs/growi/issues/3582\n /\\\\/, // see: https://github.com/growilabs/growi/issues/7241\n /^\\/(_search|_private-legacy-pages|_news)(\\/.*|$)/,\n /^\\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\\/.*|$)/,\n /^\\/user(?:\\/[^/]+)?$/, // https://regex101.com/r/9Eh2S1/1\n /^(\\/.+){130,}$/, // avoid deep layer path. see: https://regex101.com/r/L0kzOD/1\n];\nexport const isCreatablePage = (path: string): boolean => {\n return !restrictedPatternsToCreate.some((pattern) => path.match(pattern));\n};\n\n/**\n * return user's homepage path\n * @param user\n */\nexport const userHomepagePath = (\n user: { username: string } | null | undefined,\n): string => {\n if (user?.username == null) {\n return '';\n }\n return `/user/${user.username}`;\n};\n\n/**\n * return user path\n * @param parentPath\n * @param childPath\n * @param newPath\n */\nexport const convertToNewAffiliationPath = (\n oldPath: string,\n newPath: string,\n childPath: string,\n): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${RegExp.escape(oldPath)}`, 'i');\n return childPath.replace(pathRegExp, newPath);\n};\n\n/**\n * Encode SPACE and IDEOGRAPHIC SPACE\n * @param {string} path\n * @returns {string}\n */\nexport const encodeSpaces = (path?: string): string | undefined => {\n if (path == null) {\n return undefined;\n }\n\n // Encode SPACE and IDEOGRAPHIC SPACE\n return path.replace(/ /g, '%20').replace(/\\u3000/g, '%E3%80%80');\n};\n\n/**\n * Generate editor path\n * @param {string} paths\n * @returns {string}\n */\nexport const generateEditorPath = (...paths: string[]): string => {\n const joinedPath = [...paths].join('/');\n\n if (!isCreatablePage(joinedPath)) {\n throw new Error('Invalid characters on path');\n }\n\n try {\n const url = new URL(joinedPath, 'https://dummy');\n return `${url.pathname}#edit`;\n } catch {\n throw new Error('Invalid path format');\n }\n};\n\n/**\n * return paths without duplicate area of regexp /^${path}\\/.+/i\n * ex. expect(omitDuplicateAreaPathFromPaths(['/A', '/A/B', '/A/B/C'])).toStrictEqual(['/A'])\n * @param paths paths to be tested\n * @returns omitted paths\n */\nexport const omitDuplicateAreaPathFromPaths = (paths: string[]): string[] => {\n const uniquePaths = Array.from(new Set(paths));\n return uniquePaths.filter((path) => {\n const isDuplicate =\n uniquePaths.filter((p) => new RegExp(`^${p}\\\\/.+`, 'i').test(path))\n .length > 0;\n\n return !isDuplicate;\n });\n};\n\n/**\n * return pages with path without duplicate area of regexp /^${path}\\/.+/i\n * if the pages' path are the same, it will NOT omit any of them since the other attributes will not be the same\n * @param paths paths to be tested\n * @returns omitted paths\n */\n// biome-ignore lint/suspicious/noExplicitAny: ignore\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some((p) =>\n new RegExp(`^${p.path}\\\\/.+`, 'i').test(page.path),\n );\n\n return !isDuplicate;\n });\n};\n\n/**\n * Check if the area of either path1 or path2 includes the area of the other path\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isEitherOfPathAreaOverlap = (\n path1: string,\n path2: string,\n): boolean => {\n if (path1 === path2) {\n return true;\n }\n\n const path1WithSlash = addTrailingSlash(path1);\n const path2WithSlash = addTrailingSlash(path2);\n\n const path1Area = new RegExp(`^${RegExp.escape(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${RegExp.escape(path2WithSlash)}`, 'i');\n\n if (path1Area.test(path2) || path2Area.test(path1)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Check if the area of pathToTest includes the area of pathToBeTested\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isPathAreaOverlap = (\n pathToTest: string,\n pathToBeTested: string,\n): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${RegExp.escape(pathWithSlash)}`, 'i');\n if (pathAreaToTest.test(pathToBeTested)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Determine whether can move by fromPath and toPath\n * @param fromPath string\n * @param toPath string\n * @returns boolean\n */\nexport const canMoveByPath = (fromPath: string, toPath: string): boolean => {\n return !isPathAreaOverlap(fromPath, toPath);\n};\n\n/**\n * check if string has '/' in it\n */\nexport const hasSlash = (str: string): boolean => {\n return str.includes('/');\n};\n\n/**\n * Get username from user page path\n * @param path string\n * @returns string | null\n */\nexport const getUsernameByPath = (path: string): string | null => {\n let username: string | null = null;\n // https://regex101.com/r/qj4SfD/1\n const match = path.match(/^\\/user\\/([^/]+)\\/?/);\n if (match) {\n username = match[1];\n }\n\n return username;\n};\n\nexport const isGlobPatternPath = (path: string): boolean => {\n // https://regex101.com/r/IBy7HS/1\n const globPattern = /^(?:\\/[^/*?[\\]{}]+)*\\/\\*$/;\n return globPattern.test(path);\n};\n\nexport * from './is-top-page.js';\n"],"names":["isTopPage","_isTopPage","isUsersTopPage","path","isPermalink","pageIdStr","isValidObjectId","isUsersHomepage","isUsersProtectedPages","isMovablePage","isUserPage","isTrashTopPage","isTrashPage","isSharedPage","restrictedPatternsToCreate","isCreatablePage","pattern","userHomepagePath","user","convertToNewAffiliationPath","oldPath","newPath","childPath","pathRegExp","encodeSpaces","generateEditorPath","paths","joinedPath","omitDuplicateAreaPathFromPaths","uniquePaths","p","omitDuplicateAreaPageFromPages","pages","page","isEitherOfPathAreaOverlap","path1","path2","path1WithSlash","addTrailingSlash","path2WithSlash","path1Area","path2Area","isPathAreaOverlap","pathToTest","pathToBeTested","pathWithSlash","canMoveByPath","fromPath","toPath","hasSlash","str","getUsernameByPath","username","match","isGlobPatternPath"],"mappings":";;;;AAIO,MAAMA,IAAYC,GAQZC,IAAiB,CAACC,MACtBA,MAAS,SAOLC,IAAc,CAACD,MAA0B;AACpD,QAAME,IAAYF,EAAK,UAAU,CAAC;AAClC,SAAOG,EAAgBD,CAAS;AAClC,GAMaE,IAAkB,CAACJ,MAE1B,EAAAA,EAAK,MAAM,iBAAiB,GAUrBK,IAAwB,CAACL,MAC7BD,EAAeC,CAAI,KAAKI,EAAgBJ,CAAI,GAOxCM,IAAgB,CAACN,MACrB,CAACH,EAAUG,CAAI,KAAK,CAACK,EAAsBL,CAAI,GAO3CO,IAAa,CAACP,MAErB,EAAAA,EAAK,MAAM,eAAe,GAWnBQ,IAAiB,CAACR,MACtBA,MAAS,UAOLS,IAAc,CAACT,MAEtB,EAAAA,EAAK,MAAM,kBAAkB,GAWtBU,IAAe,CAACV,MAEvB,EAAAA,EAAK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SAAS,GAAG,EAAE,KAAK3B,CAAI,CAAC,EAC/D,SAAS,EAGf;AACH,GASa4B,IAAiC,CAACC,MACtCA,EAAM,OAAO,CAACC,MAKZ,CAJaD,EAAM;AAAA,EAAK,CAACF,MAC9B,IAAI,OAAO,IAAIA,EAAE,IAAI,SAAS,GAAG,EAAE,KAAKG,EAAK,IAAI;AAAA,CAIpD,GAUUC,IAA4B,CACvCC,GACAC,MACY;AACZ,MAAID,MAAUC;AACZ,WAAO;AAGT,QAAMC,IAAiBC,EAAiBH,CAAK,GACvCI,IAAiBD,EAAiBF,CAAK,GAEvCI,IAAY,IAAI,OAAO,IAAI,OAAO,OAAOH,CAAc,CAAC,IAAI,GAAG,GAC/DI,IAAY,IAAI,OAAO,IAAI,OAAO,OAAOF,CAAc,CAAC,IAAI,GAAG;AAErE,SAAI,GAAAC,EAAU,KAAKJ,CAAK,KAAKK,EAAU,KAAKN,CAAK;AAKnD,GASaO,IAAoB,CAC/BC,GACAC,MACY;AACZ,MAAID,MAAeC;AACjB,WAAO;AAGT,QAAMC,IAAgBP,EAAiBK,CAAU;AAGjD,SAAI,EADmB,IAAI,OAAO,IAAI,OAAO,OAAOE,CAAa,CAAC,IAAI,GAAG,EACtD,KAAKD,CAAc;AAKxC,GAQaE,IAAgB,CAACC,GAAkBC,MACvC,CAACN,EAAkBK,GAAUC,CAAM,GAM/BC,IAAW,CAACC,MAChBA,EAAI,SAAS,GAAG,GAQZC,IAAoB,CAAChD,MAAgC;AAChE,MAAIiD,IAA0B;AAE9B,QAAMC,IAAQlD,EAAK,MAAM,qBAAqB;AAC9C,SAAIkD,MACFD,IAAWC,EAAM,CAAC,IAGbD;AACT,GAEaE,IAAoB,CAACnD,MAEZ,4BACD,KAAKA,CAAI;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import { isValidObjectId } from '../objectid-utils.js';\nimport { addTrailingSlash } from '../path-utils.js';\nimport { exceedsMaxPageDepth } from './exceeds-max-page-depth.js';\nimport { isTopPage as _isTopPage } from './is-top-page.js';\n\nexport const isTopPage = _isTopPage;\n\nexport * from './generate-children-regexp.js';\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isUsersTopPage = (path: string): boolean => {\n return path === '/user';\n};\n\n/**\n * Whether the path is permalink\n * @param path\n */\nexport const isPermalink = (path: string): boolean => {\n const pageIdStr = path.substring(1);\n return isValidObjectId(pageIdStr);\n};\n\n/**\n * Whether path is user's homepage\n * @param path\n */\nexport const isUsersHomepage = (path: string): boolean => {\n // https://regex101.com/r/utVQct/1\n if (path.match(/^\\/user\\/[^/]+$/)) {\n return true;\n }\n return false;\n};\n\n/**\n * Whether path is the protected pages for systems\n * @param path\n */\nexport const isUsersProtectedPages = (path: string): boolean => {\n return isUsersTopPage(path) || isUsersHomepage(path);\n};\n\n/**\n * Whether path is movable\n * @param path\n */\nexport const isMovablePage = (path: string): boolean => {\n return !isTopPage(path) && !isUsersProtectedPages(path);\n};\n\n/**\n * Whether path belongs to the user page\n * @param path\n */\nexport const isUserPage = (path: string): boolean => {\n // https://regex101.com/r/MwifLR/1\n if (path.match(/^\\/user\\/.*?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path is the top page of users\n * @param path\n */\nexport const isTrashTopPage = (path: string): boolean => {\n return path === '/trash';\n};\n\n/**\n * Whether path belongs to the trash page\n * @param path\n */\nexport const isTrashPage = (path: string): boolean => {\n // https://regex101.com/r/BSDdRr/1\n if (path.match(/^\\/trash(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Whether path belongs to the shared page\n * @param path\n */\nexport const isSharedPage = (path: string): boolean => {\n // https://regex101.com/r/ZjdOiB/1\n if (path.match(/^\\/share(\\/.*)?$/)) {\n return true;\n }\n\n return false;\n};\n\nconst restrictedPatternsToCreate: Array<RegExp> = [\n /\\^|\\$|\\*|\\+|#|<|>|%|\\?/,\n /^\\/-\\/.*/,\n /^\\/_r\\/.*/,\n /^\\/_apix?(\\/.*)?/,\n /^\\/?https?:\\/\\/.+$/, // avoid miss in renaming\n /\\/{2,}/, // avoid miss in renaming\n /\\s\\/\\s/, // avoid miss in renaming\n /.\\/edit$/,\n /.\\.md$/,\n /^(\\.\\.)$/, // see: https://github.com/growilabs/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/growilabs/growi/issues/3582\n /\\\\/, // see: https://github.com/growilabs/growi/issues/7241\n /^\\/(_search|_private-legacy-pages|_news)(\\/.*|$)/,\n /^\\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\\/.*|$)/,\n /^\\/user(?:\\/[^/]+)?$/, // https://regex101.com/r/9Eh2S1/1\n];\n\nexport const isCreatablePage = (path: string): boolean => {\n return (\n !restrictedPatternsToCreate.some((pattern) => path.match(pattern)) &&\n !exceedsMaxPageDepth(path)\n );\n};\n\n/**\n * return user's homepage path\n * @param user\n */\nexport const userHomepagePath = (\n user: { username: string } | null | undefined,\n): string => {\n if (user?.username == null) {\n return '';\n }\n return `/user/${user.username}`;\n};\n\n/**\n * return user path\n * @param parentPath\n * @param childPath\n * @param newPath\n */\nexport const convertToNewAffiliationPath = (\n oldPath: string,\n newPath: string,\n childPath: string,\n): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${RegExp.escape(oldPath)}`, 'i');\n return childPath.replace(pathRegExp, newPath);\n};\n\n/**\n * Encode SPACE and IDEOGRAPHIC SPACE\n * @param {string} path\n * @returns {string}\n */\nexport const encodeSpaces = (path?: string): string | undefined => {\n if (path == null) {\n return undefined;\n }\n\n // Encode SPACE and IDEOGRAPHIC SPACE\n return path.replace(/ /g, '%20').replace(/\\u3000/g, '%E3%80%80');\n};\n\n/**\n * Generate editor path\n * @param {string} paths\n * @returns {string}\n */\nexport const generateEditorPath = (...paths: string[]): string => {\n const joinedPath = [...paths].join('/');\n\n if (!isCreatablePage(joinedPath)) {\n throw new Error('Invalid characters on path');\n }\n\n try {\n const url = new URL(joinedPath, 'https://dummy');\n return `${url.pathname}#edit`;\n } catch {\n throw new Error('Invalid path format');\n }\n};\n\n/**\n * return paths without duplicate area of regexp /^${path}\\/.+/i\n * ex. expect(omitDuplicateAreaPathFromPaths(['/A', '/A/B', '/A/B/C'])).toStrictEqual(['/A'])\n * @param paths paths to be tested\n * @returns omitted paths\n */\nexport const omitDuplicateAreaPathFromPaths = (paths: string[]): string[] => {\n const uniquePaths = Array.from(new Set(paths));\n return uniquePaths.filter((path) => {\n const isDuplicate =\n uniquePaths.filter((p) => new RegExp(`^${p}\\\\/.+`, 'i').test(path))\n .length > 0;\n\n return !isDuplicate;\n });\n};\n\n/**\n * return pages with path without duplicate area of regexp /^${path}\\/.+/i\n * if the pages' path are the same, it will NOT omit any of them since the other attributes will not be the same\n * @param paths paths to be tested\n * @returns omitted paths\n */\n// biome-ignore lint/suspicious/noExplicitAny: ignore\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some((p) =>\n new RegExp(`^${p.path}\\\\/.+`, 'i').test(page.path),\n );\n\n return !isDuplicate;\n });\n};\n\n/**\n * Check if the area of either path1 or path2 includes the area of the other path\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isEitherOfPathAreaOverlap = (\n path1: string,\n path2: string,\n): boolean => {\n if (path1 === path2) {\n return true;\n }\n\n const path1WithSlash = addTrailingSlash(path1);\n const path2WithSlash = addTrailingSlash(path2);\n\n const path1Area = new RegExp(`^${RegExp.escape(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${RegExp.escape(path2WithSlash)}`, 'i');\n\n if (path1Area.test(path2) || path2Area.test(path1)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Check if the area of pathToTest includes the area of pathToBeTested\n * The area of path is the same as /^\\/hoge\\//i\n * @param pathToTest string\n * @param pathToBeTested string\n * @returns boolean\n */\nexport const isPathAreaOverlap = (\n pathToTest: string,\n pathToBeTested: string,\n): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${RegExp.escape(pathWithSlash)}`, 'i');\n if (pathAreaToTest.test(pathToBeTested)) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Determine whether can move by fromPath and toPath\n * @param fromPath string\n * @param toPath string\n * @returns boolean\n */\nexport const canMoveByPath = (fromPath: string, toPath: string): boolean => {\n return !isPathAreaOverlap(fromPath, toPath);\n};\n\n/**\n * check if string has '/' in it\n */\nexport const hasSlash = (str: string): boolean => {\n return str.includes('/');\n};\n\n/**\n * Get username from user page path\n * @param path string\n * @returns string | null\n */\nexport const getUsernameByPath = (path: string): string | null => {\n let username: string | null = null;\n // https://regex101.com/r/qj4SfD/1\n const match = path.match(/^\\/user\\/([^/]+)\\/?/);\n if (match) {\n username = match[1];\n }\n\n return username;\n};\n\nexport const isGlobPatternPath = (path: string): boolean => {\n // https://regex101.com/r/IBy7HS/1\n const globPattern = /^(?:\\/[^/*?[\\]{}]+)*\\/\\*$/;\n return globPattern.test(path);\n};\n\nexport * from './exceeds-max-page-depth.js';\nexport * from './is-top-page.js';\n"],"names":["isTopPage","_isTopPage","isUsersTopPage","path","isPermalink","pageIdStr","isValidObjectId","isUsersHomepage","isUsersProtectedPages","isMovablePage","isUserPage","isTrashTopPage","isTrashPage","isSharedPage","restrictedPatternsToCreate","isCreatablePage","pattern","exceedsMaxPageDepth","userHomepagePath","user","convertToNewAffiliationPath","oldPath","newPath","childPath","pathRegExp","encodeSpaces","generateEditorPath","paths","joinedPath","omitDuplicateAreaPathFromPaths","uniquePaths","p","omitDuplicateAreaPageFromPages","pages","page","isEitherOfPathAreaOverlap","path1","path2","path1WithSlash","addTrailingSlash","path2WithSlash","path1Area","path2Area","isPathAreaOverlap","pathToTest","pathToBeTested","pathWithSlash","canMoveByPath","fromPath","toPath","hasSlash","str","getUsernameByPath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AgBP,EAAiBK,CAAU;AAGjD,SAAI,EADmB,IAAI,OAAO,IAAI,OAAO,OAAOE,CAAa,CAAC,IAAI,GAAG,EACtD,KAAKD,CAAc;AAKxC,GAQaE,IAAgB,CAACC,GAAkBC,MACvC,CAACN,EAAkBK,GAAUC,CAAM,GAM/BC,IAAW,CAACC,MAChBA,EAAI,SAAS,GAAG,GAQZC,IAAoB,CAACjD,MAAgC;AAChE,MAAIkD,IAA0B;AAE9B,QAAMC,IAAQnD,EAAK,MAAM,qBAAqB;AAC9C,SAAImD,MACFD,IAAWC,EAAM,CAAC,IAGbD;AACT,GAEaE,IAAoB,CAACpD,MAEZ,4BACD,KAAKA,CAAI;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growi/core",
3
- "version": "3.1.1",
3
+ "version": "3.1.2-next.70cb0d78d48a4262bc6fc975ee83c7c47f0df155",
4
4
  "description": "GROWI Core Libraries",
5
5
  "license": "MIT",
6
6
  "repository": {