@growi/core 1.3.0 → 1.3.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.
Files changed (31) hide show
  1. package/LICENSE +21 -0
  2. package/dist/interfaces/attachment.d.ts +3 -3
  3. package/dist/interfaces/external-account.d.ts +2 -2
  4. package/dist/interfaces/page.d.ts +5 -5
  5. package/dist/interfaces/revision.d.ts +3 -3
  6. package/dist/interfaces/subscription.d.ts +2 -2
  7. package/dist/interfaces/user.d.ts +4 -4
  8. package/dist/models/devided-page-path.cjs +1 -1
  9. package/dist/models/devided-page-path.cjs.map +1 -1
  10. package/dist/models/devided-page-path.js +4 -4
  11. package/dist/models/serializers/attachment-serializer.cjs.map +1 -1
  12. package/dist/models/serializers/attachment-serializer.d.ts +2 -2
  13. package/dist/models/serializers/user-serializer.cjs.map +1 -1
  14. package/dist/models/serializers/user-serializer.d.ts +1 -1
  15. package/dist/models/vo/error-apiv3.cjs +1 -1
  16. package/dist/models/vo/error-apiv3.cjs.map +1 -1
  17. package/dist/models/vo/error-apiv3.js +4 -4
  18. package/dist/swr/use-global-socket.d.ts +1 -1
  19. package/dist/utils/growi-theme-metadata.d.ts +1 -1
  20. package/dist/utils/page-path-utils/generate-children-regexp.cjs +2 -0
  21. package/dist/utils/page-path-utils/generate-children-regexp.cjs.map +1 -0
  22. package/dist/utils/page-path-utils/generate-children-regexp.d.ts +4 -0
  23. package/dist/utils/page-path-utils/generate-children-regexp.js +7 -0
  24. package/dist/utils/page-path-utils/generate-children-regexp.js.map +1 -0
  25. package/dist/utils/page-path-utils/generate-children-regexp.spec.d.ts +1 -0
  26. package/dist/utils/page-path-utils/index.cjs +1 -1
  27. package/dist/utils/page-path-utils/index.cjs.map +1 -1
  28. package/dist/utils/page-path-utils/index.d.ts +1 -4
  29. package/dist/utils/page-path-utils/index.js +21 -18
  30. package/dist/utils/page-path-utils/index.js.map +1 -1
  31. package/package.json +13 -12
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 WESEEK, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,7 +1,7 @@
1
- import { IUser } from './user';
2
- import { IPage } from './page';
3
- import { HasObjectId } from './has-object-id';
4
1
  import { Ref } from './common';
2
+ import { HasObjectId } from './has-object-id';
3
+ import { IPage } from './page';
4
+ import { IUser } from './user';
5
5
 
6
6
  export type IAttachment = {
7
7
  page?: Ref<IPage>;
@@ -1,6 +1,6 @@
1
- import { IUser } from './user';
2
- import { HasObjectId } from './has-object-id';
3
1
  import { Ref } from './common';
2
+ import { HasObjectId } from './has-object-id';
3
+ import { IUser } from './user';
4
4
 
5
5
  export declare const IExternalAuthProviderType: {
6
6
  readonly ldap: "ldap";
@@ -1,9 +1,9 @@
1
- import { IUser, IUserGroup, IUserGroupHasId, IUserHasId } from './user';
2
- import { ITag } from './tag';
3
- import { SubscriptionStatusType } from './subscription';
4
- import { IRevision, HasRevisionShortbody, IRevisionHasId } from './revision';
5
- import { HasObjectId } from './has-object-id';
6
1
  import { Ref } from './common';
2
+ import { HasObjectId } from './has-object-id';
3
+ import { IRevision, HasRevisionShortbody, IRevisionHasId } from './revision';
4
+ import { SubscriptionStatusType } from './subscription';
5
+ import { ITag } from './tag';
6
+ import { IUser, IUserGroup, IUserGroupHasId, IUserHasId } from './user';
7
7
 
8
8
  export declare const GroupType: {
9
9
  readonly userGroup: "UserGroup";
@@ -1,7 +1,7 @@
1
- import { IUser } from './user';
2
- import { IPage } from './page';
3
- import { HasObjectId } from './has-object-id';
4
1
  import { Ref } from './common';
2
+ import { HasObjectId } from './has-object-id';
3
+ import { IPage } from './page';
4
+ import { IUser } from './user';
5
5
 
6
6
  export declare const Origin: {
7
7
  readonly View: "view";
@@ -1,6 +1,6 @@
1
- import { IUser } from './user';
2
- import { IPage } from './page';
3
1
  import { Ref } from './common';
2
+ import { IPage } from './page';
3
+ import { IUser } from './user';
4
4
 
5
5
  export declare const SubscriptionStatusType: {
6
6
  readonly SUBSCRIBE: "SUBSCRIBE";
@@ -1,8 +1,8 @@
1
- import { Lang } from './lang';
2
- import { HasObjectId } from './has-object-id';
3
- import { IExternalAuthProviderType } from './external-account';
4
- import { Ref } from './common';
5
1
  import { IAttachment } from './attachment';
2
+ import { Ref } from './common';
3
+ import { IExternalAuthProviderType } from './external-account';
4
+ import { HasObjectId } from './has-object-id';
5
+ import { Lang } from './lang';
6
6
 
7
7
  export type IUser = {
8
8
  name: string;
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var n=(r,t,e)=>t in r?c(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var s=(r,t,e)=>(n(r,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../utils/path-utils.cjs"),m=/^(.+\/[^/]+)\/(\d{4}|\d{4}\/\d{2}|\d{4}\/\d{2}\/\d{2})$/;class d{constructor(t,e=!1,h=!1){s(this,"isRoot");s(this,"isFormerRoot");s(this,"former");s(this,"latter");if(this.isRoot=!1,this.isFormerRoot=!1,this.former="",t==null||t===""||t==="/"){this.isRoot=!0,this.latter="/";return}const a=e?t:f.normalizePath(t);if(this.latter=a,h){const i=a.match(m);if(i!=null){this.former=i[1],this.latter=i[2];return}}let l=/^((.*)\/(?!em>))?(.+)$/;try{l=new RegExp("^((.*)(?<!<)\\/)?(.+)$")}catch{}const o=a.match(l);o!=null&&(this.isFormerRoot=o[1]==="/",this.former=o[2],this.latter=o[3])}}exports.DevidedPagePath=d;
1
+ "use strict";var c=Object.defineProperty;var n=(e,t,r)=>t in e?c(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var s=(e,t,r)=>n(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../utils/path-utils.cjs"),m=/^(.+\/[^/]+)\/(\d{4}|\d{4}\/\d{2}|\d{4}\/\d{2}\/\d{2})$/;class d{constructor(t,r=!1,h=!1){s(this,"isRoot");s(this,"isFormerRoot");s(this,"former");s(this,"latter");if(this.isRoot=!1,this.isFormerRoot=!1,this.former="",t==null||t===""||t==="/"){this.isRoot=!0,this.latter="/";return}const a=r?t:f.normalizePath(t);if(this.latter=a,h){const i=a.match(m);if(i!=null){this.former=i[1],this.latter=i[2];return}}let l=/^((.*)\/(?!em>))?(.+)$/;try{l=new RegExp("^((.*)(?<!<)\\/)?(.+)$")}catch{}const o=a.match(l);o!=null&&(this.isFormerRoot=o[1]==="/",this.former=o[2],this.latter=o[3])}}exports.DevidedPagePath=d;
2
2
  //# sourceMappingURL=devided-page-path.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"devided-page-path.cjs","sources":["../../src/models/devided-page-path.ts"],"sourcesContent":["import * as pathUtils from '../utils/path-utils';\n\n// https://regex101.com/r/BahpKX/2\nconst PATTERN_INCLUDE_DATE = /^(.+\\/[^/]+)\\/(\\d{4}|\\d{4}\\/\\d{2}|\\d{4}\\/\\d{2}\\/\\d{2})$/;\n\nexport class DevidedPagePath {\n\n isRoot: boolean;\n\n isFormerRoot: boolean;\n\n former: string;\n\n latter: string;\n\n constructor(path: string, skipNormalize = false, evalDatePath = false) {\n\n this.isRoot = false;\n this.isFormerRoot = false;\n this.former = '';\n\n // root\n if (path == null || path === '' || path === '/') {\n this.isRoot = true;\n this.latter = '/';\n return;\n }\n\n const pagePath = skipNormalize ? path : pathUtils.normalizePath(path);\n this.latter = pagePath;\n\n // evaluate date path\n if (evalDatePath) {\n const matchDate = pagePath.match(PATTERN_INCLUDE_DATE);\n if (matchDate != null) {\n this.former = matchDate[1];\n this.latter = matchDate[2];\n return;\n }\n }\n\n let PATTERN_DEFAULT = /^((.*)\\/(?!em>))?(.+)$/; // this will ignore em's end tags\n try { // for non-chrome browsers\n // eslint-disable-next-line regex/invalid\n PATTERN_DEFAULT = new RegExp('^((.*)(?<!<)\\\\/)?(.+)$'); // https://regex101.com/r/HJNvMW/1\n }\n catch (err) {\n // lookbehind regex is not supported on non-chrome browsers\n }\n\n const matchDefault = pagePath.match(PATTERN_DEFAULT);\n if (matchDefault != null) {\n this.isFormerRoot = matchDefault[1] === '/';\n this.former = matchDefault[2];\n this.latter = matchDefault[3];\n }\n }\n\n}\n"],"names":["PATTERN_INCLUDE_DATE","DevidedPagePath","path","skipNormalize","evalDatePath","__publicField","pagePath","pathUtils.normalizePath","matchDate","PATTERN_DEFAULT","matchDefault"],"mappings":"mSAGMA,EAAuB,0DAEtB,MAAMC,CAAgB,CAU3B,YAAYC,EAAcC,EAAgB,GAAOC,EAAe,GAAO,CARvEC,EAAA,eAEAA,EAAA,qBAEAA,EAAA,eAEAA,EAAA,eASE,GALA,KAAK,OAAS,GACd,KAAK,aAAe,GACpB,KAAK,OAAS,GAGVH,GAAQ,MAAQA,IAAS,IAAMA,IAAS,IAAK,CAC/C,KAAK,OAAS,GACd,KAAK,OAAS,IACd,MACF,CAEA,MAAMI,EAAWH,EAAgBD,EAAOK,gBAAwBL,CAAI,EAIpE,GAHA,KAAK,OAASI,EAGVF,EAAc,CACV,MAAAI,EAAYF,EAAS,MAAMN,CAAoB,EACrD,GAAIQ,GAAa,KAAM,CAChB,KAAA,OAASA,EAAU,CAAC,EACpB,KAAA,OAASA,EAAU,CAAC,EACzB,MACF,CACF,CAEA,IAAIC,EAAkB,yBAClB,GAAA,CAEgBA,EAAA,IAAI,OAAO,wBAAwB,OAE3C,CAEZ,CAEM,MAAAC,EAAeJ,EAAS,MAAMG,CAAe,EAC/CC,GAAgB,OACb,KAAA,aAAeA,EAAa,CAAC,IAAM,IACnC,KAAA,OAASA,EAAa,CAAC,EACvB,KAAA,OAASA,EAAa,CAAC,EAEhC,CAEF"}
1
+ {"version":3,"file":"devided-page-path.cjs","sources":["../../src/models/devided-page-path.ts"],"sourcesContent":["import * as pathUtils from '../utils/path-utils';\n\n// https://regex101.com/r/BahpKX/2\nconst PATTERN_INCLUDE_DATE = /^(.+\\/[^/]+)\\/(\\d{4}|\\d{4}\\/\\d{2}|\\d{4}\\/\\d{2}\\/\\d{2})$/;\n\nexport class DevidedPagePath {\n\n isRoot: boolean;\n\n isFormerRoot: boolean;\n\n former: string;\n\n latter: string;\n\n constructor(path: string, skipNormalize = false, evalDatePath = false) {\n\n this.isRoot = false;\n this.isFormerRoot = false;\n this.former = '';\n\n // root\n if (path == null || path === '' || path === '/') {\n this.isRoot = true;\n this.latter = '/';\n return;\n }\n\n const pagePath = skipNormalize ? path : pathUtils.normalizePath(path);\n this.latter = pagePath;\n\n // evaluate date path\n if (evalDatePath) {\n const matchDate = pagePath.match(PATTERN_INCLUDE_DATE);\n if (matchDate != null) {\n this.former = matchDate[1];\n this.latter = matchDate[2];\n return;\n }\n }\n\n let PATTERN_DEFAULT = /^((.*)\\/(?!em>))?(.+)$/; // this will ignore em's end tags\n try { // for non-chrome browsers\n // eslint-disable-next-line regex/invalid\n PATTERN_DEFAULT = new RegExp('^((.*)(?<!<)\\\\/)?(.+)$'); // https://regex101.com/r/HJNvMW/1\n }\n catch (err) {\n // lookbehind regex is not supported on non-chrome browsers\n }\n\n const matchDefault = pagePath.match(PATTERN_DEFAULT);\n if (matchDefault != null) {\n this.isFormerRoot = matchDefault[1] === '/';\n this.former = matchDefault[2];\n this.latter = matchDefault[3];\n }\n }\n\n}\n"],"names":["PATTERN_INCLUDE_DATE","DevidedPagePath","path","skipNormalize","evalDatePath","__publicField","pagePath","pathUtils.normalizePath","matchDate","PATTERN_DEFAULT","matchDefault"],"mappings":"+RAGMA,EAAuB,0DAEtB,MAAMC,CAAgB,CAU3B,YAAYC,EAAcC,EAAgB,GAAOC,EAAe,GAAO,CARvEC,EAAA,eAEAA,EAAA,qBAEAA,EAAA,eAEAA,EAAA,eASE,GALA,KAAK,OAAS,GACd,KAAK,aAAe,GACpB,KAAK,OAAS,GAGVH,GAAQ,MAAQA,IAAS,IAAMA,IAAS,IAAK,CAC/C,KAAK,OAAS,GACd,KAAK,OAAS,IACd,MACF,CAEA,MAAMI,EAAWH,EAAgBD,EAAOK,gBAAwBL,CAAI,EAIpE,GAHA,KAAK,OAASI,EAGVF,EAAc,CACV,MAAAI,EAAYF,EAAS,MAAMN,CAAoB,EACrD,GAAIQ,GAAa,KAAM,CAChB,KAAA,OAASA,EAAU,CAAC,EACpB,KAAA,OAASA,EAAU,CAAC,EACzB,MACF,CACF,CAEA,IAAIC,EAAkB,yBAClB,GAAA,CAEgBA,EAAA,IAAI,OAAO,wBAAwB,OAE3C,CAEZ,CAEM,MAAAC,EAAeJ,EAAS,MAAMG,CAAe,EAC/CC,GAAgB,OACb,KAAA,aAAeA,EAAa,CAAC,IAAM,IACnC,KAAA,OAASA,EAAa,CAAC,EACvB,KAAA,OAASA,EAAa,CAAC,EAEhC,CAEF"}
@@ -1,10 +1,10 @@
1
1
  var m = Object.defineProperty;
2
- var f = (e, t, r) => t in e ? m(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var o = (e, t, r) => (f(e, typeof t != "symbol" ? t + "" : t, r), r);
2
+ var f = (r, t, e) => t in r ? m(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var o = (r, t, e) => f(r, typeof t != "symbol" ? t + "" : t, e);
4
4
  import { normalizePath as c } from "../utils/path-utils.js";
5
5
  const n = /^(.+\/[^/]+)\/(\d{4}|\d{4}\/\d{2}|\d{4}\/\d{2}\/\d{2})$/;
6
6
  class u {
7
- constructor(t, r = !1, h = !1) {
7
+ constructor(t, e = !1, h = !1) {
8
8
  o(this, "isRoot");
9
9
  o(this, "isFormerRoot");
10
10
  o(this, "former");
@@ -13,7 +13,7 @@ class u {
13
13
  this.isRoot = !0, this.latter = "/";
14
14
  return;
15
15
  }
16
- const a = r ? t : c(t);
16
+ const a = e ? t : c(t);
17
17
  if (this.latter = a, h) {
18
18
  const i = a.match(n);
19
19
  if (i != null) {
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-serializer.cjs","sources":["../../../src/models/serializers/attachment-serializer.ts"],"sourcesContent":["import { Document } from 'mongoose';\n\nimport type { IAttachment, IUser } from '~/interfaces';\n\nimport { isPopulated, isRef, type Ref } from '../../interfaces/common';\n\nimport { serializeUserSecurely, type IUserSerializedSecurely } from './user-serializer';\n\nexport type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<A, 'creator'> & { creator?: Ref<IUserSerializedSecurely<IUser>> };\n\nconst omitInsecureAttributes = <A extends IAttachment>(attachment: A): IAttachmentSerializedSecurely<A> => {\n\n const leanDoc = (attachment instanceof Document)\n ? attachment.toObject<A>()\n : attachment;\n\n const { creator, ...rest } = leanDoc;\n\n const secureCreator = creator == null\n ? undefined\n : serializeUserSecurely(creator);\n\n return {\n creator: secureCreator,\n ...rest,\n };\n};\n\n\nexport function serializeAttachmentSecurely<A extends IAttachment>(attachment?: A): IAttachmentSerializedSecurely<A>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(attachment?: Ref<A>): Ref<IAttachmentSerializedSecurely<A>>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(attachment?: A | Ref<A>)\n : undefined | IAttachmentSerializedSecurely<A> | Ref<IAttachmentSerializedSecurely<A>> {\n\n if (attachment == null) return attachment;\n\n if (isRef(attachment) && !isPopulated(attachment)) return attachment;\n\n return omitInsecureAttributes(attachment);\n}\n"],"names":["omitInsecureAttributes","attachment","leanDoc","Document","creator","rest","serializeUserSecurely","serializeAttachmentSecurely","isRef","isPopulated"],"mappings":"wLAUMA,EAAiDC,GAAoD,CAEzG,MAAMC,EAAWD,aAAsBE,EAAAA,SACnCF,EAAW,SACX,EAAAA,EAEE,CAAE,QAAAG,EAAS,GAAGC,CAAA,EAASH,EAMtB,MAAA,CACL,QALoBE,GAAW,KAC7B,OACAE,EAAAA,sBAAsBF,CAAO,EAI/B,GAAGC,CAAA,CAEP,EAKO,SAASE,EAAmDN,EACwB,CAIzF,OAFIA,GAAc,MAEdO,EAAM,MAAAP,CAAU,GAAK,CAACQ,EAAAA,YAAYR,CAAU,EAAUA,EAEnDD,EAAuBC,CAAU,CAC1C"}
1
+ {"version":3,"file":"attachment-serializer.cjs","sources":["../../../src/models/serializers/attachment-serializer.ts"],"sourcesContent":["import { Document } from 'mongoose';\n\nimport type { IAttachment, IUser } from '~/interfaces';\n\nimport { isPopulated, isRef, type Ref } from '../../interfaces/common';\n\nimport { serializeUserSecurely, type IUserSerializedSecurely } from './user-serializer';\n\nexport type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<A, 'creator'> & { creator?: Ref<IUserSerializedSecurely<IUser>> };\n\nconst omitInsecureAttributes = <A extends IAttachment>(attachment: A): IAttachmentSerializedSecurely<A> => {\n\n const leanDoc = (attachment instanceof Document)\n ? attachment.toObject<A>()\n : attachment;\n\n const { creator, ...rest } = leanDoc;\n\n const secureCreator = creator == null\n ? undefined\n : serializeUserSecurely(creator);\n\n return {\n creator: secureCreator,\n ...rest,\n };\n};\n\n\nexport function serializeAttachmentSecurely<A extends IAttachment>(attachment?: A): IAttachmentSerializedSecurely<A>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(attachment?: Ref<A>): Ref<IAttachmentSerializedSecurely<A>>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(attachment?: A | Ref<A>)\n : undefined | IAttachmentSerializedSecurely<A> | Ref<IAttachmentSerializedSecurely<A>> {\n\n if (attachment == null) return attachment;\n\n if (isRef(attachment) && !isPopulated(attachment)) return attachment;\n\n return omitInsecureAttributes(attachment);\n}\n"],"names":["omitInsecureAttributes","attachment","leanDoc","Document","creator","rest","serializeUserSecurely","serializeAttachmentSecurely","isRef","isPopulated"],"mappings":"wLAUMA,EAAiDC,GAAoD,CAEzG,MAAMC,EAAWD,aAAsBE,EAAAA,SACnCF,EAAW,SACX,EAAAA,EAEE,CAAE,QAAAG,EAAS,GAAGC,CAAA,EAASH,EAMtB,MAAA,CACL,QALoBE,GAAW,KAC7B,OACAE,EAAAA,sBAAsBF,CAAO,EAI/B,GAAGC,CAAA,CAEP,EAKO,SAASE,EAAmDN,EACwB,CAIzF,OAFIA,GAAc,MAEdO,EAAAA,MAAMP,CAAU,GAAK,CAACQ,EAAY,YAAAR,CAAU,EAAUA,EAEnDD,EAAuBC,CAAU,CAC1C"}
@@ -1,6 +1,6 @@
1
- import { IUserSerializedSecurely } from './user-serializer';
2
- import { Ref } from '../../interfaces/common';
3
1
  import { IAttachment, IUser } from '../../interfaces';
2
+ import { Ref } from '../../interfaces/common';
3
+ import { IUserSerializedSecurely } from './user-serializer';
4
4
 
5
5
  export type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<A, 'creator'> & {
6
6
  creator?: Ref<IUserSerializedSecurely<IUser>>;
@@ -1 +1 @@
1
- {"version":3,"file":"user-serializer.cjs","sources":["../../../src/models/serializers/user-serializer.ts"],"sourcesContent":["import { Document } from 'mongoose';\n\nimport { isPopulated, isRef, type Ref } from '../../interfaces/common';\nimport type { IUser } from '../../interfaces/user';\n\nexport type IUserSerializedSecurely<U extends IUser> = Omit<U, 'password' | 'apiToken' | 'email'> & { email?: string };\n\nexport const omitInsecureAttributes = <U extends IUser>(user: U): IUserSerializedSecurely<U> => {\n\n const leanDoc = (user instanceof Document)\n ? user.toObject<U>()\n : user;\n\n const {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n password, apiToken, email, ...rest\n } = leanDoc;\n\n const secureUser: IUserSerializedSecurely<U> = rest;\n\n // omit email\n if (secureUser.isEmailPublished) {\n secureUser.email = email;\n }\n\n return secureUser;\n};\n\nexport function serializeUserSecurely<U extends IUser>(user?: U): IUserSerializedSecurely<U>;\nexport function serializeUserSecurely<U extends IUser>(user?: Ref<U>): Ref<IUserSerializedSecurely<U>>;\nexport function serializeUserSecurely<U extends IUser>(user?: U | Ref<U>): undefined | IUserSerializedSecurely<U> | Ref<IUserSerializedSecurely<U>> {\n if (user == null) return user;\n\n if (isRef(user) && !isPopulated(user)) return user;\n\n return omitInsecureAttributes(user);\n}\n"],"names":["omitInsecureAttributes","user","leanDoc","Document","password","apiToken","email","rest","secureUser","serializeUserSecurely","isRef","isPopulated"],"mappings":"qJAOaA,EAA2CC,GAAwC,CAE9F,MAAMC,EAAWD,aAAgBE,EAAAA,SAC7BF,EAAK,SACL,EAAAA,EAEE,CAEJ,SAAAG,EAAU,SAAAC,EAAU,MAAAC,EAAO,GAAGC,CAC5B,EAAAL,EAEEM,EAAyCD,EAG/C,OAAIC,EAAW,mBACbA,EAAW,MAAQF,GAGdE,CACT,EAIO,SAASC,EAAuCR,EAA6F,CAGlJ,OAFIA,GAAQ,MAERS,EAAM,MAAAT,CAAI,GAAK,CAACU,EAAAA,YAAYV,CAAI,EAAUA,EAEvCD,EAAuBC,CAAI,CACpC"}
1
+ {"version":3,"file":"user-serializer.cjs","sources":["../../../src/models/serializers/user-serializer.ts"],"sourcesContent":["import { Document } from 'mongoose';\n\nimport { isPopulated, isRef, type Ref } from '../../interfaces/common';\nimport type { IUser } from '../../interfaces/user';\n\nexport type IUserSerializedSecurely<U extends IUser> = Omit<U, 'password' | 'apiToken' | 'email'> & { email?: string };\n\nexport const omitInsecureAttributes = <U extends IUser>(user: U): IUserSerializedSecurely<U> => {\n\n const leanDoc = (user instanceof Document)\n ? user.toObject<U>()\n : user;\n\n const {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n password, apiToken, email, ...rest\n } = leanDoc;\n\n const secureUser: IUserSerializedSecurely<U> = rest;\n\n // omit email\n if (secureUser.isEmailPublished) {\n secureUser.email = email;\n }\n\n return secureUser;\n};\n\nexport function serializeUserSecurely<U extends IUser>(user?: U): IUserSerializedSecurely<U>;\nexport function serializeUserSecurely<U extends IUser>(user?: Ref<U>): Ref<IUserSerializedSecurely<U>>;\nexport function serializeUserSecurely<U extends IUser>(user?: U | Ref<U>): undefined | IUserSerializedSecurely<U> | Ref<IUserSerializedSecurely<U>> {\n if (user == null) return user;\n\n if (isRef(user) && !isPopulated(user)) return user;\n\n return omitInsecureAttributes(user);\n}\n"],"names":["omitInsecureAttributes","user","leanDoc","Document","password","apiToken","email","rest","secureUser","serializeUserSecurely","isRef","isPopulated"],"mappings":"qJAOaA,EAA2CC,GAAwC,CAE9F,MAAMC,EAAWD,aAAgBE,EAAAA,SAC7BF,EAAK,SACL,EAAAA,EAEE,CAEJ,SAAAG,EAAU,SAAAC,EAAU,MAAAC,EAAO,GAAGC,CAC5B,EAAAL,EAEEM,EAAyCD,EAG/C,OAAIC,EAAW,mBACbA,EAAW,MAAQF,GAGdE,CACT,EAIO,SAASC,EAAuCR,EAA6F,CAGlJ,OAFIA,GAAQ,MAERS,EAAAA,MAAMT,CAAI,GAAK,CAACU,EAAY,YAAAV,CAAI,EAAUA,EAEvCD,EAAuBC,CAAI,CACpC"}
@@ -1,5 +1,5 @@
1
- import { IUser } from '../../interfaces/user';
2
1
  import { Ref } from '../../interfaces/common';
2
+ import { IUser } from '../../interfaces/user';
3
3
 
4
4
  export type IUserSerializedSecurely<U extends IUser> = Omit<U, 'password' | 'apiToken' | 'email'> & {
5
5
  email?: string;
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var d=(e,r,s)=>r in e?a(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var t=(e,r,s)=>(d(e,typeof r!="symbol"?r+"":r,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g extends Error{constructor(s="",o="",i=void 0,c=void 0){super();t(this,"code");t(this,"args");this.message=s,this.code=o,this.stack=i,this.args=c}}exports.ErrorV3=g;
1
+ "use strict";var a=Object.defineProperty;var d=(s,r,e)=>r in s?a(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var t=(s,r,e)=>d(s,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class g extends Error{constructor(e="",o="",i=void 0,c=void 0){super();t(this,"code");t(this,"args");this.message=e,this.code=o,this.stack=i,this.args=c}}exports.ErrorV3=g;
2
2
  //# sourceMappingURL=error-apiv3.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-apiv3.cjs","sources":["../../../src/models/vo/error-apiv3.ts"],"sourcesContent":["export class ErrorV3 extends Error {\n\n code: string;\n\n args?: any;\n\n constructor(message = '', code = '', stack = undefined, args: any = undefined) {\n super(); // do not provide message to the super constructor\n this.message = message;\n this.code = code;\n this.stack = stack;\n this.args = args;\n }\n\n}\n"],"names":["ErrorV3","message","code","stack","args","__publicField"],"mappings":"wPAAO,MAAMA,UAAgB,KAAM,CAMjC,YAAYC,EAAU,GAAIC,EAAO,GAAIC,EAAQ,OAAWC,EAAY,OAAW,CACvE,QALRC,EAAA,aAEAA,EAAA,aAIE,KAAK,QAAUJ,EACf,KAAK,KAAOC,EACZ,KAAK,MAAQC,EACb,KAAK,KAAOC,CACd,CAEF"}
1
+ {"version":3,"file":"error-apiv3.cjs","sources":["../../../src/models/vo/error-apiv3.ts"],"sourcesContent":["export class ErrorV3 extends Error {\n\n code: string;\n\n args?: any;\n\n constructor(message = '', code = '', stack = undefined, args: any = undefined) {\n super(); // do not provide message to the super constructor\n this.message = message;\n this.code = code;\n this.stack = stack;\n this.args = args;\n }\n\n}\n"],"names":["ErrorV3","message","code","stack","args","__publicField"],"mappings":"oPAAO,MAAMA,UAAgB,KAAM,CAMjC,YAAYC,EAAU,GAAIC,EAAO,GAAIC,EAAQ,OAAWC,EAAY,OAAW,CACvE,QALRC,EAAA,aAEAA,EAAA,aAIE,KAAK,QAAUJ,EACf,KAAK,KAAOC,EACZ,KAAK,MAAQC,EACb,KAAK,KAAOC,CACd,CAEF"}
@@ -1,12 +1,12 @@
1
1
  var a = Object.defineProperty;
2
- var d = (o, s, r) => s in o ? a(o, s, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[s] = r;
3
- var t = (o, s, r) => (d(o, typeof s != "symbol" ? s + "" : s, r), r);
2
+ var d = (r, s, o) => s in r ? a(r, s, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[s] = o;
3
+ var t = (r, s, o) => d(r, typeof s != "symbol" ? s + "" : s, o);
4
4
  class g extends Error {
5
- constructor(r = "", e = "", c = void 0, i = void 0) {
5
+ constructor(o = "", e = "", c = void 0, i = void 0) {
6
6
  super();
7
7
  t(this, "code");
8
8
  t(this, "args");
9
- this.message = r, this.code = e, this.stack = c, this.args = i;
9
+ this.message = o, this.code = e, this.stack = c, this.args = i;
10
10
  }
11
11
  }
12
12
  export {
@@ -1,5 +1,5 @@
1
- import { SWRResponse } from 'swr';
2
1
  import { Socket } from 'socket.io-client';
2
+ import { SWRResponse } from 'swr';
3
3
 
4
4
  export declare const GLOBAL_SOCKET_NS = "/";
5
5
  export declare const GLOBAL_SOCKET_KEY = "globalSocket";
@@ -1,4 +1,4 @@
1
- import { GrowiThemeSchemeType } from '../interfaces/growi-theme-metadata';
2
1
  import { ColorScheme } from '../interfaces/color-scheme';
2
+ import { GrowiThemeSchemeType } from '../interfaces/growi-theme-metadata';
3
3
 
4
4
  export declare const getForcedColorScheme: (growiThemeSchemeType?: GrowiThemeSchemeType) => ColorScheme | undefined;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("escape-string-regexp"),n=require("./is-top-page.cjs"),t=e=>n.isTopPage(e)?new RegExp(/^\/[^/]+$/):new RegExp(`^${r(e)}(\\/[^/]+)\\/?$`);exports.generateChildrenRegExp=t;
2
+ //# sourceMappingURL=generate-children-regexp.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-children-regexp.cjs","sources":["../../../src/utils/page-path-utils/generate-children-regexp.ts"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nimport { isTopPage } from './is-top-page';\n\n/**\n * Generate RegExp instance for one level lower path\n */\nexport const generateChildrenRegExp = (path: string): RegExp => {\n // https://regex101.com/r/laJGzj/1\n // ex. /any_level1\n if (isTopPage(path)) return new RegExp(/^\\/[^/]+$/);\n\n // https://regex101.com/r/mrDJrx/1\n // ex. /parent/any_child OR /any_level1\n return new RegExp(`^${escapeStringRegexp(path)}(\\\\/[^/]+)\\\\/?$`);\n};\n"],"names":["generateChildrenRegExp","path","isTopPage","escapeStringRegexp"],"mappings":"uJAOaA,EAA0BC,GAGjCC,EAAAA,UAAUD,CAAI,EAAU,IAAI,OAAO,WAAW,EAI3C,IAAI,OAAO,IAAIE,EAAmBF,CAAI,CAAC,iBAAiB"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Generate RegExp instance for one level lower path
3
+ */
4
+ export declare const generateChildrenRegExp: (path: string) => RegExp;
@@ -0,0 +1,7 @@
1
+ import r from "escape-string-regexp";
2
+ import { isTopPage as n } from "./is-top-page.js";
3
+ const o = (e) => n(e) ? new RegExp(/^\/[^/]+$/) : new RegExp(`^${r(e)}(\\/[^/]+)\\/?$`);
4
+ export {
5
+ o as generateChildrenRegExp
6
+ };
7
+ //# sourceMappingURL=generate-children-regexp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-children-regexp.js","sources":["../../../src/utils/page-path-utils/generate-children-regexp.ts"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nimport { isTopPage } from './is-top-page';\n\n/**\n * Generate RegExp instance for one level lower path\n */\nexport const generateChildrenRegExp = (path: string): RegExp => {\n // https://regex101.com/r/laJGzj/1\n // ex. /any_level1\n if (isTopPage(path)) return new RegExp(/^\\/[^/]+$/);\n\n // https://regex101.com/r/mrDJrx/1\n // ex. /parent/any_child OR /any_level1\n return new RegExp(`^${escapeStringRegexp(path)}(\\\\/[^/]+)\\\\/?$`);\n};\n"],"names":["generateChildrenRegExp","path","isTopPage","escapeStringRegexp"],"mappings":";;AAOa,MAAAA,IAAyB,CAACC,MAGjCC,EAAUD,CAAI,IAAU,IAAI,OAAO,WAAW,IAI3C,IAAI,OAAO,IAAIE,EAAmBF,CAAI,CAAC,iBAAiB;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("escape-string-regexp"),P=require("../objectid-utils.cjs"),i=require("../path-utils.cjs"),m=require("./is-top-page.cjs"),o=m.isTopPage,c=e=>e==="/user",f=e=>{const t=e.substring(1);return P.isValidObjectId(t)},u=e=>!!e.match(/^\/user\/[^/]+$/),l=e=>c(e)||u(e),d=e=>!o(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)(\/.*|$)/,/^\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\/.*|$)/,/^\/user(?:\/[^/]+)?$/],h=e=>!S.some(t=>e.match(t)),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(`^${s(e)}`,"i");return r.replace(a,t)},x=e=>{if(e!=null)return e.replace(/ /g,"%20").replace(/\u3000/g,"%E3%80%80")},R=(...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(n=>new RegExp(`^${n}\\/.+`,"i").test(r)).length>0))},y=e=>e.filter(t=>!e.some(a=>new RegExp(`^${a.path}\\/.+`,"i").test(t.path))),b=(e,t)=>{if(e===t)return!0;const r=i.addTrailingSlash(e),a=i.addTrailingSlash(t),n=new RegExp(`^${s(r)}`,"i"),p=new RegExp(`^${s(a)}`,"i");return!!(n.test(t)||p.test(e))},g=(e,t)=>{if(e===t)return!0;const r=i.addTrailingSlash(e);return!!new RegExp(`^${s(r)}`,"i").test(t)},D=(e,t)=>!g(e,t),O=e=>e.includes("/"),j=e=>o(e)?new RegExp(/^\/[^/]+$/):new RegExp(`^${e}(\\/[^/]+)\\/?$`),q=e=>{let t=null;const r=e.match(/^\/user\/([^/]+)\/?/);return r&&(t=r[1]),t};exports.canMoveByPath=D;exports.convertToNewAffiliationPath=A;exports.encodeSpaces=x;exports.generateChildrenRegExp=j;exports.generateEditorPath=R;exports.getUsernameByPath=q;exports.hasSlash=O;exports.isCreatablePage=h;exports.isEitherOfPathAreaOverlap=b;exports.isMovablePage=d;exports.isPathAreaOverlap=g;exports.isPermalink=f;exports.isSharedPage=w;exports.isTopPage=o;exports.isTrashPage=T;exports.isTrashTopPage=E;exports.isUserPage=$;exports.isUsersHomepage=u;exports.isUsersProtectedPages=l;exports.isUsersTopPage=c;exports.omitDuplicateAreaPageFromPages=y;exports.omitDuplicateAreaPathFromPaths=U;exports.userHomepagePath=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("escape-string-regexp"),P=require("../objectid-utils.cjs"),i=require("../path-utils.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)},u=e=>!!e.match(/^\/user\/[^/]+$/),l=e=>c(e)||u(e),$=e=>!o(e)&&!l(e),T=e=>!!e.match(/^\/user\/.*?$/),E=e=>e==="/trash",S=e=>!!e.match(/^\/trash(\/.*)?$/),w=e=>!!e.match(/^\/share(\/.*)?$/),v=[/\^|\$|\*|\+|#|<|>|%|\?/,/^\/-\/.*/,/^\/_r\/.*/,/^\/_apix?(\/.*)?/,/^\/?https?:\/\/.+$/,/\/{2,}/,/\s+\/\s+/,/.+\/edit$/,/.+\.md$/,/^(\.\.)$/,/(\/\.\.)\/?/,/\\/,/^\/(_search|_private-legacy-pages)(\/.*|$)/,/^\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\/.*|$)/,/^\/user(?:\/[^/]+)?$/,/^(\/.+){130,}$/],h=e=>!v.some(t=>e.match(t)),A=e=>(e==null?void 0:e.username)==null?"":`/user/${e.username}`,U=(e,t,r)=>{if(t==null)throw new Error("Please input the new page path");const a=new RegExp(`^${s(e)}`,"i");return r.replace(a,t)},x=e=>{if(e!=null)return e.replace(/ /g,"%20").replace(/\u3000/g,"%E3%80%80")},R=(...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")}},y=e=>{const t=Array.from(new Set(e));return t.filter(r=>!(t.filter(n=>new RegExp(`^${n}\\/.+`,"i").test(r)).length>0))},b=e=>e.filter(t=>!e.some(a=>new RegExp(`^${a.path}\\/.+`,"i").test(t.path))),D=(e,t)=>{if(e===t)return!0;const r=i.addTrailingSlash(e),a=i.addTrailingSlash(t),n=new RegExp(`^${s(r)}`,"i"),p=new RegExp(`^${s(a)}`,"i");return!!(n.test(t)||p.test(e))},g=(e,t)=>{if(e===t)return!0;const r=i.addTrailingSlash(e);return!!new RegExp(`^${s(r)}`,"i").test(t)},O=(e,t)=>!g(e,t),q=e=>e.includes("/"),C=e=>{let t=null;const r=e.match(/^\/user\/([^/]+)\/?/);return r&&(t=r[1]),t};exports.generateChildrenRegExp=d.generateChildrenRegExp;exports.canMoveByPath=O;exports.convertToNewAffiliationPath=U;exports.encodeSpaces=x;exports.generateEditorPath=R;exports.getUsernameByPath=C;exports.hasSlash=q;exports.isCreatablePage=h;exports.isEitherOfPathAreaOverlap=D;exports.isMovablePage=$;exports.isPathAreaOverlap=g;exports.isPermalink=f;exports.isSharedPage=w;exports.isTopPage=o;exports.isTrashPage=S;exports.isTrashTopPage=E;exports.isUserPage=T;exports.isUsersHomepage=u;exports.isUsersProtectedPages=l;exports.isUsersTopPage=c;exports.omitDuplicateAreaPageFromPages=b;exports.omitDuplicateAreaPathFromPaths=y;exports.userHomepagePath=A;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nimport { IUser } from '~/interfaces';\n\nimport { isValidObjectId } from '../objectid-utils';\nimport { addTrailingSlash } from '../path-utils';\n\nimport { isTopPage as _isTopPage } from './is-top-page';\n\nexport const isTopPage = _isTopPage;\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/weseek/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/weseek/growi/issues/3582\n /\\\\/, // see: https://github.com/weseek/growi/issues/7241\n /^\\/(_search|_private-legacy-pages)(\\/.*|$)/,\n /^\\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\\/.*|$)/,\n /^\\/user(?:\\/[^/]+)?$/, // https://regex101.com/r/9Eh2S1/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 = (user: IUser | null | undefined): 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 = (oldPath: string, newPath: string, childPath: string): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${escapeStringRegexp(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 }\n catch (err) {\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 = uniquePaths.filter(p => (new RegExp(`^${p}\\\\/.+`, 'i')).test(path)).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 */\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some(p => (new RegExp(`^${p.path}\\\\/.+`, 'i')).test(page.path));\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 = (path1: string, path2: string): 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(`^${escapeStringRegexp(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${escapeStringRegexp(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 = (pathToTest: string, pathToBeTested: string): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${escapeStringRegexp(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 * Generate RegExp instance for one level lower path\n */\nexport const generateChildrenRegExp = (path: string): RegExp => {\n // https://regex101.com/r/laJGzj/1\n // ex. /any_level1\n if (isTopPage(path)) return new RegExp(/^\\/[^/]+$/);\n\n // https://regex101.com/r/mrDJrx/1\n // ex. /parent/any_child OR /any_level1\n return new RegExp(`^${path}(\\\\/[^/]+)\\\\/?$`);\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\n\nexport * from './is-top-page';\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","escapeStringRegexp","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","generateChildrenRegExp","getUsernameByPath","username","match"],"mappings":"yNASaA,EAAYC,EAAA,UAMZC,EAAkBC,GACtBA,IAAS,QAOLC,EAAeD,GAA0B,CAC9C,MAAAE,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,CAAI,GAAK,CAACK,EAAsBL,CAAI,EAO3CO,EAAcP,GAErB,EAAAA,EAAK,MAAM,eAAe,EAWnBQ,EAAkBR,GACtBA,IAAS,SAOLS,EAAeT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AAKF,GAAM,IAAI,OAAO,IAAIA,EAAE,IAAI,QAAS,GAAG,EAAG,KAAKG,EAAK,IAAI,CAAC,CAGzF,EAUUC,EAA4B,CAACC,EAAeC,IAA2B,CAClF,GAAID,IAAUC,EACL,MAAA,GAGH,MAAAC,EAAiBC,mBAAiBH,CAAK,EACvCI,EAAiBD,mBAAiBF,CAAK,EAEvCI,EAAY,IAAI,OAAO,IAAIjB,EAAmBc,CAAc,CAAC,GAAI,GAAG,EACpEI,EAAY,IAAI,OAAO,IAAIlB,EAAmBgB,CAAc,CAAC,GAAI,GAAG,EAE1E,MAAI,GAAAC,EAAU,KAAKJ,CAAK,GAAKK,EAAU,KAAKN,CAAK,EAKnD,EASaO,EAAoB,CAACC,EAAoBC,IAAoC,CACxF,GAAID,IAAeC,EACV,MAAA,GAGH,MAAAC,EAAgBP,mBAAiBK,CAAU,EAG7C,MAAA,EADmB,IAAI,OAAO,IAAIpB,EAAmBsB,CAAa,CAAC,GAAI,GAAG,EAC3D,KAAKD,CAAc,CAKxC,EAQaE,EAAgB,CAACC,EAAkBC,IACvC,CAACN,EAAkBK,EAAUC,CAAM,EAM/BC,EAAYC,GAChBA,EAAI,SAAS,GAAG,EAMZC,EAA0BjD,GAGjCH,EAAUG,CAAI,EAAU,IAAI,OAAO,WAAW,EAI3C,IAAI,OAAO,IAAIA,CAAI,iBAAiB,EAQhCkD,EAAqBlD,GAAgC,CAChE,IAAImD,EAA0B,KAExB,MAAAC,EAAQpD,EAAK,MAAM,qBAAqB,EAC9C,OAAIoD,IACFD,EAAWC,EAAM,CAAC,GAGbD,CACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nimport type { IUser } from '~/interfaces';\n\nimport { isValidObjectId } from '../objectid-utils';\nimport { addTrailingSlash } from '../path-utils';\n\nimport { isTopPage as _isTopPage } from './is-top-page';\n\nexport const isTopPage = _isTopPage;\nexport * from './generate-children-regexp';\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/weseek/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/weseek/growi/issues/3582\n /\\\\/, // see: https://github.com/weseek/growi/issues/7241\n /^\\/(_search|_private-legacy-pages)(\\/.*|$)/,\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 = (user: IUser | null | undefined): 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 = (oldPath: string, newPath: string, childPath: string): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${escapeStringRegexp(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 }\n catch (err) {\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 = uniquePaths.filter(p => (new RegExp(`^${p}\\\\/.+`, 'i')).test(path)).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 */\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some(p => (new RegExp(`^${p.path}\\\\/.+`, 'i')).test(page.path));\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 = (path1: string, path2: string): 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(`^${escapeStringRegexp(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${escapeStringRegexp(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 = (pathToTest: string, pathToBeTested: string): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${escapeStringRegexp(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\n\nexport * from './is-top-page';\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","escapeStringRegexp","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"],"mappings":"qQASaA,EAAYC,EAAA,UAOZC,EAAkBC,GACtBA,IAAS,QAOLC,EAAeD,GAA0B,CAC9C,MAAAE,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,EAO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Y,OAAOC,GAAM,IAAI,OAAO,IAAIA,CAAC,QAAS,GAAG,EAAG,KAAK5B,CAAI,CAAC,EAAE,OAAS,EAGlG,CACH,EAQa6B,EAAkCC,GACtCA,EAAM,OAAQC,GAGZ,CAFaD,EAAM,KAAKF,GAAM,IAAI,OAAO,IAAIA,EAAE,IAAI,QAAS,GAAG,EAAG,KAAKG,EAAK,IAAI,CAAC,CAGzF,EAUUC,EAA4B,CAACC,EAAeC,IAA2B,CAClF,GAAID,IAAUC,EACL,MAAA,GAGH,MAAAC,EAAiBC,mBAAiBH,CAAK,EACvCI,EAAiBD,mBAAiBF,CAAK,EAEvCI,EAAY,IAAI,OAAO,IAAIjB,EAAmBc,CAAc,CAAC,GAAI,GAAG,EACpEI,EAAY,IAAI,OAAO,IAAIlB,EAAmBgB,CAAc,CAAC,GAAI,GAAG,EAE1E,MAAI,GAAAC,EAAU,KAAKJ,CAAK,GAAKK,EAAU,KAAKN,CAAK,EAKnD,EASaO,EAAoB,CAACC,EAAoBC,IAAoC,CACxF,GAAID,IAAeC,EACV,MAAA,GAGH,MAAAC,EAAgBP,mBAAiBK,CAAU,EAG7C,MAAA,EADmB,IAAI,OAAO,IAAIpB,EAAmBsB,CAAa,CAAC,GAAI,GAAG,EAC3D,KAAKD,CAAc,CAKxC,EAQaE,EAAgB,CAACC,EAAkBC,IACvC,CAACN,EAAkBK,EAAUC,CAAM,EAM/BC,EAAYC,GAChBA,EAAI,SAAS,GAAG,EAQZC,EAAqBjD,GAAgC,CAChE,IAAIkD,EAA0B,KAExB,MAAAC,EAAQnD,EAAK,MAAM,qBAAqB,EAC9C,OAAImD,IACFD,EAAWC,EAAM,CAAC,GAGbD,CACT"}
@@ -1,6 +1,7 @@
1
1
  import { IUser } from '../../interfaces';
2
2
 
3
3
  export declare const isTopPage: (path: string) => boolean;
4
+ export * from './generate-children-regexp';
4
5
  /**
5
6
  * Whether path is the top page of users
6
7
  * @param path
@@ -112,10 +113,6 @@ export declare const canMoveByPath: (fromPath: string, toPath: string) => boolea
112
113
  * check if string has '/' in it
113
114
  */
114
115
  export declare const hasSlash: (str: string) => boolean;
115
- /**
116
- * Generate RegExp instance for one level lower path
117
- */
118
- export declare const generateChildrenRegExp: (path: string) => RegExp;
119
116
  /**
120
117
  * Get username from user page path
121
118
  * @param path string
@@ -1,11 +1,12 @@
1
- import n from "escape-string-regexp";
2
- import { isValidObjectId as u } from "../objectid-utils.js";
1
+ import a from "escape-string-regexp";
2
+ import { isValidObjectId as c } from "../objectid-utils.js";
3
3
  import { addTrailingSlash as i } from "../path-utils.js";
4
- import { isTopPage as l } from "./is-top-page.js";
5
- const o = l, h = (e) => e === "/user", x = (e) => {
4
+ import { isTopPage as u } from "./is-top-page.js";
5
+ import { generateChildrenRegExp as M } from "./generate-children-regexp.js";
6
+ const l = u, h = (e) => e === "/user", x = (e) => {
6
7
  const t = e.substring(1);
7
- return u(t);
8
- }, p = (e) => !!e.match(/^\/user\/[^/]+$/), g = (e) => h(e) || p(e), R = (e) => !o(e) && !g(e), A = (e) => !!e.match(/^\/user\/.*?$/), S = (e) => e === "/trash", T = (e) => !!e.match(/^\/trash(\/.*)?$/), v = (e) => !!e.match(/^\/share(\/.*)?$/), m = [
8
+ return c(t);
9
+ }, p = (e) => !!e.match(/^\/user\/[^/]+$/), g = (e) => h(e) || p(e), A = (e) => !l(e) && !g(e), R = (e) => !!e.match(/^\/user\/.*?$/), S = (e) => e === "/trash", T = (e) => !!e.match(/^\/trash(\/.*)?$/), v = (e) => !!e.match(/^\/share(\/.*)?$/), m = [
9
10
  /\^|\$|\*|\+|#|<|>|%|\?/,
10
11
  /^\/-\/.*/,
11
12
  /^\/_r\/.*/,
@@ -26,12 +27,14 @@ const o = l, h = (e) => e === "/user", x = (e) => {
26
27
  // see: https://github.com/weseek/growi/issues/7241
27
28
  /^\/(_search|_private-legacy-pages)(\/.*|$)/,
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
32
+ /^(\/.+){130,}$/
33
+ // avoid deep layer path. see: https://regex101.com/r/L0kzOD/1
31
34
  ], f = (e) => !m.some((t) => e.match(t)), y = (e) => (e == null ? void 0 : e.username) == null ? "" : `/user/${e.username}`, D = (e, t, r) => {
32
35
  if (t == null)
33
36
  throw new Error("Please input the new page path");
34
- const s = new RegExp(`^${n(e)}`, "i");
37
+ const s = new RegExp(`^${a(e)}`, "i");
35
38
  return r.replace(s, t);
36
39
  }, U = (e) => {
37
40
  if (e != null)
@@ -47,18 +50,18 @@ const o = l, h = (e) => e === "/user", x = (e) => {
47
50
  }
48
51
  }, I = (e) => {
49
52
  const t = Array.from(new Set(e));
50
- return t.filter((r) => !(t.filter((a) => new RegExp(`^${a}\\/.+`, "i").test(r)).length > 0));
53
+ return t.filter((r) => !(t.filter((n) => new RegExp(`^${n}\\/.+`, "i").test(r)).length > 0));
51
54
  }, O = (e) => e.filter((t) => !e.some((s) => new RegExp(`^${s.path}\\/.+`, "i").test(t.path))), _ = (e, t) => {
52
55
  if (e === t)
53
56
  return !0;
54
- const r = i(e), s = i(t), a = new RegExp(`^${n(r)}`, "i"), c = new RegExp(`^${n(s)}`, "i");
55
- return !!(a.test(t) || c.test(e));
57
+ const r = i(e), s = i(t), n = new RegExp(`^${a(r)}`, "i"), o = new RegExp(`^${a(s)}`, "i");
58
+ return !!(n.test(t) || o.test(e));
56
59
  }, P = (e, t) => {
57
60
  if (e === t)
58
61
  return !0;
59
62
  const r = i(e);
60
- return !!new RegExp(`^${n(r)}`, "i").test(t);
61
- }, j = (e, t) => !P(e, t), C = (e) => e.includes("/"), W = (e) => o(e) ? new RegExp(/^\/[^/]+$/) : new RegExp(`^${e}(\\/[^/]+)\\/?$`), F = (e) => {
63
+ return !!new RegExp(`^${a(r)}`, "i").test(t);
64
+ }, j = (e, t) => !P(e, t), C = (e) => e.includes("/"), W = (e) => {
62
65
  let t = null;
63
66
  const r = e.match(/^\/user\/([^/]+)\/?/);
64
67
  return r && (t = r[1]), t;
@@ -67,20 +70,20 @@ export {
67
70
  j as canMoveByPath,
68
71
  D as convertToNewAffiliationPath,
69
72
  U as encodeSpaces,
70
- W as generateChildrenRegExp,
73
+ M as generateChildrenRegExp,
71
74
  b as generateEditorPath,
72
- F as getUsernameByPath,
75
+ W as getUsernameByPath,
73
76
  C as hasSlash,
74
77
  f as isCreatablePage,
75
78
  _ as isEitherOfPathAreaOverlap,
76
- R as isMovablePage,
79
+ A as isMovablePage,
77
80
  P as isPathAreaOverlap,
78
81
  x as isPermalink,
79
82
  v as isSharedPage,
80
- o as isTopPage,
83
+ l as isTopPage,
81
84
  T as isTrashPage,
82
85
  S as isTrashTopPage,
83
- A as isUserPage,
86
+ R as isUserPage,
84
87
  p as isUsersHomepage,
85
88
  g as isUsersProtectedPages,
86
89
  h as isUsersTopPage,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/utils/page-path-utils/index.ts"],"sourcesContent":["import escapeStringRegexp from 'escape-string-regexp';\n\nimport { IUser } from '~/interfaces';\n\nimport { isValidObjectId } from '../objectid-utils';\nimport { addTrailingSlash } from '../path-utils';\n\nimport { isTopPage as _isTopPage } from './is-top-page';\n\nexport const isTopPage = _isTopPage;\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/weseek/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/weseek/growi/issues/3582\n /\\\\/, // see: https://github.com/weseek/growi/issues/7241\n /^\\/(_search|_private-legacy-pages)(\\/.*|$)/,\n /^\\/(installer|register|login|logout|admin|me|files|trash|paste|comments|tags|share|attachment)(\\/.*|$)/,\n /^\\/user(?:\\/[^/]+)?$/, // https://regex101.com/r/9Eh2S1/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 = (user: IUser | null | undefined): 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 = (oldPath: string, newPath: string, childPath: string): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${escapeStringRegexp(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 }\n catch (err) {\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 = uniquePaths.filter(p => (new RegExp(`^${p}\\\\/.+`, 'i')).test(path)).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 */\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some(p => (new RegExp(`^${p.path}\\\\/.+`, 'i')).test(page.path));\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 = (path1: string, path2: string): 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(`^${escapeStringRegexp(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${escapeStringRegexp(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 = (pathToTest: string, pathToBeTested: string): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${escapeStringRegexp(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 * Generate RegExp instance for one level lower path\n */\nexport const generateChildrenRegExp = (path: string): RegExp => {\n // https://regex101.com/r/laJGzj/1\n // ex. /any_level1\n if (isTopPage(path)) return new RegExp(/^\\/[^/]+$/);\n\n // https://regex101.com/r/mrDJrx/1\n // ex. /parent/any_child OR /any_level1\n return new RegExp(`^${path}(\\\\/[^/]+)\\\\/?$`);\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\n\nexport * from './is-top-page';\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","escapeStringRegexp","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","generateChildrenRegExp","getUsernameByPath","username","match"],"mappings":";;;;AASO,MAAMA,IAAYC,GAMZC,IAAiB,CAACC,MACtBA,MAAS,SAOLC,IAAc,CAACD,MAA0B;AAC9C,QAAAE,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,MAA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import escapeStringRegexp from 'escape-string-regexp';\n\nimport type { IUser } from '~/interfaces';\n\nimport { isValidObjectId } from '../objectid-utils';\nimport { addTrailingSlash } from '../path-utils';\n\nimport { isTopPage as _isTopPage } from './is-top-page';\n\nexport const isTopPage = _isTopPage;\nexport * from './generate-children-regexp';\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/weseek/growi/issues/3582\n /(\\/\\.\\.)\\/?/, // see: https://github.com/weseek/growi/issues/3582\n /\\\\/, // see: https://github.com/weseek/growi/issues/7241\n /^\\/(_search|_private-legacy-pages)(\\/.*|$)/,\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 = (user: IUser | null | undefined): 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 = (oldPath: string, newPath: string, childPath: string): string => {\n if (newPath == null) {\n throw new Error('Please input the new page path');\n }\n const pathRegExp = new RegExp(`^${escapeStringRegexp(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 }\n catch (err) {\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 = uniquePaths.filter(p => (new RegExp(`^${p}\\\\/.+`, 'i')).test(path)).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 */\nexport const omitDuplicateAreaPageFromPages = (pages: any[]): any[] => {\n return pages.filter((page) => {\n const isDuplicate = pages.some(p => (new RegExp(`^${p.path}\\\\/.+`, 'i')).test(page.path));\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 = (path1: string, path2: string): 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(`^${escapeStringRegexp(path1WithSlash)}`, 'i');\n const path2Area = new RegExp(`^${escapeStringRegexp(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 = (pathToTest: string, pathToBeTested: string): boolean => {\n if (pathToTest === pathToBeTested) {\n return true;\n }\n\n const pathWithSlash = addTrailingSlash(pathToTest);\n\n const pathAreaToTest = new RegExp(`^${escapeStringRegexp(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\n\nexport * from './is-top-page';\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","escapeStringRegexp","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"],"mappings":";;;;;AASO,MAAMA,IAAYC,GAOZC,IAAiB,CAACC,MACtBA,MAAS,SAOLC,IAAc,CAACD,MAA0B;AAC9C,QA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AAkBC,MACvC,CAACN,EAAkBK,GAAUC,CAAM,GAM/BC,IAAW,CAACC,MAChBA,EAAI,SAAS,GAAG,GAQZC,IAAoB,CAACjD,MAAgC;AAChE,MAAIkD,IAA0B;AAExB,QAAAC,IAAQnD,EAAK,MAAM,qBAAqB;AAC9C,SAAImD,MACFD,IAAWC,EAAM,CAAC,IAGbD;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growi/core",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "GROWI Core Libraries",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -55,16 +55,6 @@
55
55
  "require": "./dist/utils/*.cjs"
56
56
  }
57
57
  },
58
- "scripts": {
59
- "build": "vite build",
60
- "clean": "shx rm -rf dist",
61
- "dev": "vite build --mode dev",
62
- "watch": "yarn dev -w --emptyOutDir=false",
63
- "lint:js": "yarn eslint **/*.{js,ts}",
64
- "lint:typecheck": "tsc",
65
- "lint": "npm-run-all -p lint:*",
66
- "test": "vitest run --coverage"
67
- },
68
58
  "// comments for dependencies": {
69
59
  "escape-string-regexp": "5.0.0 or above exports only ESM"
70
60
  },
@@ -75,6 +65,17 @@
75
65
  "devDependencies": {
76
66
  "eslint-plugin-regex": "^1.8.0",
77
67
  "mongoose": "^6.11.3",
68
+ "socket.io-client": "^4.7.5",
78
69
  "swr": "^2.2.2"
70
+ },
71
+ "scripts": {
72
+ "build": "vite build",
73
+ "clean": "shx rm -rf dist",
74
+ "dev": "vite build --mode dev",
75
+ "watch": "pnpm run dev -w --emptyOutDir=false",
76
+ "lint:js": "eslint **/*.{js,ts}",
77
+ "lint:typecheck": "vue-tsc --noEmit",
78
+ "lint": "npm-run-all -p lint:*",
79
+ "test": "vitest run --coverage"
79
80
  }
80
- }
81
+ }