@growi/core 3.0.1 → 3.1.0-next.243a041734bec9eeac9ffb17327f8fc09fcc145a
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.
- package/dist/models/serializers/attachment-serializer.cjs +1 -1
- package/dist/models/serializers/attachment-serializer.cjs.map +1 -1
- package/dist/models/serializers/attachment-serializer.d.ts +21 -1
- package/dist/models/serializers/attachment-serializer.js +19 -10
- package/dist/models/serializers/attachment-serializer.js.map +1 -1
- package/dist/models/serializers/attachment-serializer.spec.d.ts +1 -0
- package/dist/models/serializers/index.cjs +1 -1
- package/dist/models/serializers/index.js +6 -4
- package/dist/models/serializers/user-serializer.cjs +1 -1
- package/dist/models/serializers/user-serializer.cjs.map +1 -1
- package/dist/models/serializers/user-serializer.d.ts +13 -0
- package/dist/models/serializers/user-serializer.js +13 -8
- package/dist/models/serializers/user-serializer.js.map +1 -1
- package/dist/models/serializers/user-serializer.spec.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("mongoose"),s=require("../../interfaces/common.cjs"),i=require("./user-serializer.cjs"),u=e=>{const t=e instanceof n.Document?e.toObject():e,{creator:o,...r}=t;return{creator:o==null?void 0:i.serializeUserSecurely(o),...r}};function l(e){return e==null||s.isRef(e)&&!s.isPopulated(e)?e:u(e)}const a=e=>{const{pageId:t,creatorId:o,creator:r}=e,c=r===void 0?o:r&&i.toLegacyUserShape(r);return{...e,page:t,creator:c}};exports.serializeAttachmentSecurely=l;exports.toLegacyAttachmentShape=a;
|
|
2
2
|
//# sourceMappingURL=attachment-serializer.cjs.map
|
|
@@ -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.js';\nimport {\n type IUserSerializedSecurely,\n serializeUserSecurely,\n} from './user-serializer.js';\n\nexport type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<\n A,\n 'creator'\n> & { creator?: Ref<IUserSerializedSecurely<IUser>> };\n\nconst omitInsecureAttributes = <A extends IAttachment>(\n attachment: A,\n): IAttachmentSerializedSecurely<A> => {\n const leanDoc =\n attachment instanceof Document ? attachment.toObject<A>() : attachment;\n\n const { creator, ...rest } = leanDoc;\n\n const secureCreator =\n creator == null ? undefined : serializeUserSecurely(creator);\n\n return {\n creator: secureCreator,\n ...rest,\n };\n};\n\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A,\n): IAttachmentSerializedSecurely<A>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: Ref<A>,\n): Ref<IAttachmentSerializedSecurely<A>>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A | Ref<A>,\n):\n | undefined\n | IAttachmentSerializedSecurely<A>\n | Ref<IAttachmentSerializedSecurely<A>> {\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":"
|
|
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.js';\nimport {\n type IUserLegacyShape,\n type IUserSerializedSecurely,\n serializeUserSecurely,\n toLegacyUserShape,\n} from './user-serializer.js';\n\nexport type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<\n A,\n 'creator'\n> & { creator?: Ref<IUserSerializedSecurely<IUser>> };\n\nconst omitInsecureAttributes = <A extends IAttachment>(\n attachment: A,\n): IAttachmentSerializedSecurely<A> => {\n const leanDoc =\n attachment instanceof Document ? attachment.toObject<A>() : attachment;\n\n const { creator, ...rest } = leanDoc;\n\n const secureCreator =\n creator == null ? undefined : serializeUserSecurely(creator);\n\n return {\n creator: secureCreator,\n ...rest,\n };\n};\n\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A,\n): IAttachmentSerializedSecurely<A>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: Ref<A>,\n): Ref<IAttachmentSerializedSecurely<A>>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A | Ref<A>,\n):\n | undefined\n | IAttachmentSerializedSecurely<A>\n | Ref<IAttachmentSerializedSecurely<A>> {\n if (attachment == null) return attachment;\n\n if (isRef(attachment) && !isPopulated(attachment)) return attachment;\n\n return omitInsecureAttributes(attachment);\n}\n\ntype PrismaUserLike = Parameters<typeof toLegacyUserShape>[0];\n\ntype PrismaAttachmentLike = {\n pageId?: string | null;\n creatorId?: string | null;\n creator?: PrismaUserLike | null;\n};\n\ntype LegacyCreator<A extends PrismaAttachmentLike> = A extends {\n creator: infer U;\n}\n ? U extends PrismaUserLike\n ? IUserLegacyShape<U>\n : U\n : A['creatorId'];\n\nexport type IAttachmentLegacyShape<A extends PrismaAttachmentLike> = A & {\n page: A['pageId'];\n creator: LegacyCreator<A>;\n};\n\n/**\n * Restore the Mongoose-era field names on a Prisma attachment row.\n * `creator` is the populated user when the query\n * included it, and the bare `creatorId` otherwise.\n */\nexport const toLegacyAttachmentShape = <A extends PrismaAttachmentLike>(\n attachment: A,\n): IAttachmentLegacyShape<A> => {\n const { pageId, creatorId, creator } = attachment;\n\n // `undefined` means the relation was not included; `null` means it was and the user is gone\n const legacyCreator =\n creator === undefined ? creatorId : creator && toLegacyUserShape(creator);\n\n return {\n ...attachment,\n page: pageId,\n creator: legacyCreator,\n } as IAttachmentLegacyShape<A>;\n};\n"],"names":["omitInsecureAttributes","attachment","leanDoc","Document","creator","rest","serializeUserSecurely","serializeAttachmentSecurely","isRef","isPopulated","toLegacyAttachmentShape","pageId","creatorId","legacyCreator","toLegacyUserShape"],"mappings":"wLAiBMA,EACJC,GACqC,CACrC,MAAMC,EACJD,aAAsBE,EAAAA,SAAWF,EAAW,WAAgBA,EAExD,CAAE,QAAAG,EAAS,GAAGC,CAAA,EAASH,EAK7B,MAAO,CACL,QAHAE,GAAW,KAAO,OAAYE,EAAAA,sBAAsBF,CAAO,EAI3D,GAAGC,CAAA,CAEP,EAQO,SAASE,EACdN,EAIwC,CAGxC,OAFIA,GAAc,MAEdO,EAAAA,MAAMP,CAAU,GAAK,CAACQ,EAAAA,YAAYR,CAAU,EAAUA,EAEnDD,EAAuBC,CAAU,CAC1C,CA4BO,MAAMS,EACXT,GAC8B,CAC9B,KAAM,CAAE,OAAAU,EAAQ,UAAAC,EAAW,QAAAR,CAAA,EAAYH,EAGjCY,EACJT,IAAY,OAAYQ,EAAYR,GAAWU,EAAAA,kBAAkBV,CAAO,EAE1E,MAAO,CACL,GAAGH,EACH,KAAMU,EACN,QAASE,CAAA,CAEb"}
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { IAttachment, IUser } from '../../interfaces';
|
|
2
2
|
import { Ref } from '../../interfaces/common.js';
|
|
3
|
-
import { IUserSerializedSecurely } from './user-serializer.js';
|
|
3
|
+
import { IUserLegacyShape, IUserSerializedSecurely, toLegacyUserShape } from './user-serializer.js';
|
|
4
4
|
export type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<A, 'creator'> & {
|
|
5
5
|
creator?: Ref<IUserSerializedSecurely<IUser>>;
|
|
6
6
|
};
|
|
7
7
|
export declare function serializeAttachmentSecurely<A extends IAttachment>(attachment?: A): IAttachmentSerializedSecurely<A>;
|
|
8
8
|
export declare function serializeAttachmentSecurely<A extends IAttachment>(attachment?: Ref<A>): Ref<IAttachmentSerializedSecurely<A>>;
|
|
9
|
+
type PrismaUserLike = Parameters<typeof toLegacyUserShape>[0];
|
|
10
|
+
type PrismaAttachmentLike = {
|
|
11
|
+
pageId?: string | null;
|
|
12
|
+
creatorId?: string | null;
|
|
13
|
+
creator?: PrismaUserLike | null;
|
|
14
|
+
};
|
|
15
|
+
type LegacyCreator<A extends PrismaAttachmentLike> = A extends {
|
|
16
|
+
creator: infer U;
|
|
17
|
+
} ? U extends PrismaUserLike ? IUserLegacyShape<U> : U : A['creatorId'];
|
|
18
|
+
export type IAttachmentLegacyShape<A extends PrismaAttachmentLike> = A & {
|
|
19
|
+
page: A['pageId'];
|
|
20
|
+
creator: LegacyCreator<A>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Restore the Mongoose-era field names on a Prisma attachment row.
|
|
24
|
+
* `creator` is the populated user when the query
|
|
25
|
+
* included it, and the bare `creatorId` otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare const toLegacyAttachmentShape: <A extends PrismaAttachmentLike>(attachment: A) => IAttachmentLegacyShape<A>;
|
|
28
|
+
export {};
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
import { Document as
|
|
2
|
-
import { isRef as
|
|
3
|
-
import { serializeUserSecurely as
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
import { Document as t } from "mongoose";
|
|
2
|
+
import { isRef as i, isPopulated as u } from "../../interfaces/common.js";
|
|
3
|
+
import { toLegacyUserShape as n, serializeUserSecurely as l } from "./user-serializer.js";
|
|
4
|
+
const p = (r) => {
|
|
5
|
+
const c = r instanceof t ? r.toObject() : r, { creator: o, ...e } = c;
|
|
6
6
|
return {
|
|
7
|
-
creator:
|
|
8
|
-
...
|
|
7
|
+
creator: o == null ? void 0 : l(o),
|
|
8
|
+
...e
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
|
-
function
|
|
12
|
-
return r == null ||
|
|
11
|
+
function g(r) {
|
|
12
|
+
return r == null || i(r) && !u(r) ? r : p(r);
|
|
13
13
|
}
|
|
14
|
+
const y = (r) => {
|
|
15
|
+
const { pageId: c, creatorId: o, creator: e } = r, s = e === void 0 ? o : e && n(e);
|
|
16
|
+
return {
|
|
17
|
+
...r,
|
|
18
|
+
page: c,
|
|
19
|
+
creator: s
|
|
20
|
+
};
|
|
21
|
+
};
|
|
14
22
|
export {
|
|
15
|
-
|
|
23
|
+
g as serializeAttachmentSecurely,
|
|
24
|
+
y as toLegacyAttachmentShape
|
|
16
25
|
};
|
|
17
26
|
//# sourceMappingURL=attachment-serializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-serializer.js","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.js';\nimport {\n type IUserSerializedSecurely,\n serializeUserSecurely,\n} from './user-serializer.js';\n\nexport type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<\n A,\n 'creator'\n> & { creator?: Ref<IUserSerializedSecurely<IUser>> };\n\nconst omitInsecureAttributes = <A extends IAttachment>(\n attachment: A,\n): IAttachmentSerializedSecurely<A> => {\n const leanDoc =\n attachment instanceof Document ? attachment.toObject<A>() : attachment;\n\n const { creator, ...rest } = leanDoc;\n\n const secureCreator =\n creator == null ? undefined : serializeUserSecurely(creator);\n\n return {\n creator: secureCreator,\n ...rest,\n };\n};\n\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A,\n): IAttachmentSerializedSecurely<A>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: Ref<A>,\n): Ref<IAttachmentSerializedSecurely<A>>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A | Ref<A>,\n):\n | undefined\n | IAttachmentSerializedSecurely<A>\n | Ref<IAttachmentSerializedSecurely<A>> {\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":";;;
|
|
1
|
+
{"version":3,"file":"attachment-serializer.js","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.js';\nimport {\n type IUserLegacyShape,\n type IUserSerializedSecurely,\n serializeUserSecurely,\n toLegacyUserShape,\n} from './user-serializer.js';\n\nexport type IAttachmentSerializedSecurely<A extends IAttachment> = Omit<\n A,\n 'creator'\n> & { creator?: Ref<IUserSerializedSecurely<IUser>> };\n\nconst omitInsecureAttributes = <A extends IAttachment>(\n attachment: A,\n): IAttachmentSerializedSecurely<A> => {\n const leanDoc =\n attachment instanceof Document ? attachment.toObject<A>() : attachment;\n\n const { creator, ...rest } = leanDoc;\n\n const secureCreator =\n creator == null ? undefined : serializeUserSecurely(creator);\n\n return {\n creator: secureCreator,\n ...rest,\n };\n};\n\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A,\n): IAttachmentSerializedSecurely<A>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: Ref<A>,\n): Ref<IAttachmentSerializedSecurely<A>>;\nexport function serializeAttachmentSecurely<A extends IAttachment>(\n attachment?: A | Ref<A>,\n):\n | undefined\n | IAttachmentSerializedSecurely<A>\n | Ref<IAttachmentSerializedSecurely<A>> {\n if (attachment == null) return attachment;\n\n if (isRef(attachment) && !isPopulated(attachment)) return attachment;\n\n return omitInsecureAttributes(attachment);\n}\n\ntype PrismaUserLike = Parameters<typeof toLegacyUserShape>[0];\n\ntype PrismaAttachmentLike = {\n pageId?: string | null;\n creatorId?: string | null;\n creator?: PrismaUserLike | null;\n};\n\ntype LegacyCreator<A extends PrismaAttachmentLike> = A extends {\n creator: infer U;\n}\n ? U extends PrismaUserLike\n ? IUserLegacyShape<U>\n : U\n : A['creatorId'];\n\nexport type IAttachmentLegacyShape<A extends PrismaAttachmentLike> = A & {\n page: A['pageId'];\n creator: LegacyCreator<A>;\n};\n\n/**\n * Restore the Mongoose-era field names on a Prisma attachment row.\n * `creator` is the populated user when the query\n * included it, and the bare `creatorId` otherwise.\n */\nexport const toLegacyAttachmentShape = <A extends PrismaAttachmentLike>(\n attachment: A,\n): IAttachmentLegacyShape<A> => {\n const { pageId, creatorId, creator } = attachment;\n\n // `undefined` means the relation was not included; `null` means it was and the user is gone\n const legacyCreator =\n creator === undefined ? creatorId : creator && toLegacyUserShape(creator);\n\n return {\n ...attachment,\n page: pageId,\n creator: legacyCreator,\n } as IAttachmentLegacyShape<A>;\n};\n"],"names":["omitInsecureAttributes","attachment","leanDoc","Document","creator","rest","serializeUserSecurely","serializeAttachmentSecurely","isRef","isPopulated","toLegacyAttachmentShape","pageId","creatorId","legacyCreator","toLegacyUserShape"],"mappings":";;;AAiBA,MAAMA,IAAyB,CAC7BC,MACqC;AACrC,QAAMC,IACJD,aAAsBE,IAAWF,EAAW,aAAgBA,GAExD,EAAE,SAAAG,GAAS,GAAGC,EAAA,IAASH;AAK7B,SAAO;AAAA,IACL,SAHAE,KAAW,OAAO,SAAYE,EAAsBF,CAAO;AAAA,IAI3D,GAAGC;AAAA,EAAA;AAEP;AAQO,SAASE,EACdN,GAIwC;AAGxC,SAFIA,KAAc,QAEdO,EAAMP,CAAU,KAAK,CAACQ,EAAYR,CAAU,IAAUA,IAEnDD,EAAuBC,CAAU;AAC1C;AA4BO,MAAMS,IAA0B,CACrCT,MAC8B;AAC9B,QAAM,EAAE,QAAAU,GAAQ,WAAAC,GAAW,SAAAR,EAAA,IAAYH,GAGjCY,IACJT,MAAY,SAAYQ,IAAYR,KAAWU,EAAkBV,CAAO;AAE1E,SAAO;AAAA,IACL,GAAGH;AAAA,IACH,MAAMU;AAAA,IACN,SAASE;AAAA,EAAA;AAEb;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./attachment-serializer.cjs"),e=require("./user-serializer.cjs");exports.serializeAttachmentSecurely=t.serializeAttachmentSecurely;exports.toLegacyAttachmentShape=t.toLegacyAttachmentShape;exports.omitInsecureAttributes=e.omitInsecureAttributes;exports.serializeUserSecurely=e.serializeUserSecurely;exports.toLegacyUserShape=e.toLegacyUserShape;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { serializeAttachmentSecurely as
|
|
2
|
-
import { omitInsecureAttributes as o, serializeUserSecurely as s } from "./user-serializer.js";
|
|
1
|
+
import { serializeAttachmentSecurely as r, toLegacyAttachmentShape as a } from "./attachment-serializer.js";
|
|
2
|
+
import { omitInsecureAttributes as o, serializeUserSecurely as i, toLegacyUserShape as s } from "./user-serializer.js";
|
|
3
3
|
export {
|
|
4
4
|
o as omitInsecureAttributes,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
r as serializeAttachmentSecurely,
|
|
6
|
+
i as serializeUserSecurely,
|
|
7
|
+
a as toLegacyAttachmentShape,
|
|
8
|
+
s as toLegacyUserShape
|
|
7
9
|
};
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("mongoose"),i=require("../../interfaces/common.cjs"),o=e=>{const n=e instanceof s.Document?e.toObject():e,{password:m,apiToken:u,email:c,...r}=n,t=r;return t.isEmailPublished&&(t.email=c),t};function a(e){return e==null||i.isRef(e)&&!i.isPopulated(e)?e:o(e)}const l=e=>({...e,imageAttachment:e.imageAttachmentId});exports.omitInsecureAttributes=o;exports.serializeUserSecurely=a;exports.toLegacyUserShape=l;
|
|
2
2
|
//# sourceMappingURL=user-serializer.cjs.map
|
|
@@ -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.js';\nimport type { IUser } from '../../interfaces/user.js';\n\nexport type IUserSerializedSecurely<U extends IUser> = Omit<\n U,\n 'password' | 'apiToken' | 'email'\n> & { email?: string };\n\nexport const omitInsecureAttributes = <U extends IUser>(\n user: U,\n): IUserSerializedSecurely<U> => {\n const leanDoc = user instanceof Document ? user.toObject<U>() : user;\n\n const { password, apiToken, email, ...rest } = 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>(\n user?: U,\n): IUserSerializedSecurely<U>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: Ref<U>,\n): Ref<IUserSerializedSecurely<U>>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: U | Ref<U>,\n): 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":"qJAUaA,EACXC,GAC+B,CAC/B,MAAMC,EAAUD,aAAgBE,EAAAA,SAAWF,EAAK,WAAgBA,EAE1D,CAAE,SAAAG,EAAU,SAAAC,EAAU,MAAAC,EAAO,GAAGC,GAASL,EAEzCM,EAAyCD,EAG/C,OAAIC,EAAW,mBACbA,EAAW,MAAQF,GAGdE,CACT,EAQO,SAASC,EACdR,EAC0E,CAG1E,OAFIA,GAAQ,MAERS,EAAAA,MAAMT,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.js';\nimport type { IUser } from '../../interfaces/user.js';\n\nexport type IUserSerializedSecurely<U extends IUser> = Omit<\n U,\n 'password' | 'apiToken' | 'email'\n> & { email?: string };\n\nexport const omitInsecureAttributes = <U extends IUser>(\n user: U,\n): IUserSerializedSecurely<U> => {\n const leanDoc = user instanceof Document ? user.toObject<U>() : user;\n\n const { password, apiToken, email, ...rest } = 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>(\n user?: U,\n): IUserSerializedSecurely<U>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: Ref<U>,\n): Ref<IUserSerializedSecurely<U>>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: U | Ref<U>,\n): 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\ntype PrismaUserLike = { imageAttachmentId?: string | null };\n\nexport type IUserLegacyShape<U extends PrismaUserLike> = U & {\n imageAttachment: U['imageAttachmentId'];\n};\n\n/**\n * Restore the Mongoose-era field name (`imageAttachment`) on a Prisma user row.\n *\n * TODO: only `imageAttachment` is restored so far. Map the remaining Prisma/Mongoose as the callers that need them are migrated.\n */\nexport const toLegacyUserShape = <U extends PrismaUserLike>(\n user: U,\n): IUserLegacyShape<U> => ({\n ...user,\n imageAttachment: user.imageAttachmentId,\n});\n"],"names":["omitInsecureAttributes","user","leanDoc","Document","password","apiToken","email","rest","secureUser","serializeUserSecurely","isRef","isPopulated","toLegacyUserShape"],"mappings":"qJAUaA,EACXC,GAC+B,CAC/B,MAAMC,EAAUD,aAAgBE,EAAAA,SAAWF,EAAK,WAAgBA,EAE1D,CAAE,SAAAG,EAAU,SAAAC,EAAU,MAAAC,EAAO,GAAGC,GAASL,EAEzCM,EAAyCD,EAG/C,OAAIC,EAAW,mBACbA,EAAW,MAAQF,GAGdE,CACT,EAQO,SAASC,EACdR,EAC0E,CAG1E,OAFIA,GAAQ,MAERS,EAAAA,MAAMT,CAAI,GAAK,CAACU,EAAAA,YAAYV,CAAI,EAAUA,EAEvCD,EAAuBC,CAAI,CACpC,CAaO,MAAMW,EACXX,IACyB,CACzB,GAAGA,EACH,gBAAiBA,EAAK,iBACxB"}
|
|
@@ -6,3 +6,16 @@ export type IUserSerializedSecurely<U extends IUser> = Omit<U, 'password' | 'api
|
|
|
6
6
|
export declare const omitInsecureAttributes: <U extends IUser>(user: U) => IUserSerializedSecurely<U>;
|
|
7
7
|
export declare function serializeUserSecurely<U extends IUser>(user?: U): IUserSerializedSecurely<U>;
|
|
8
8
|
export declare function serializeUserSecurely<U extends IUser>(user?: Ref<U>): Ref<IUserSerializedSecurely<U>>;
|
|
9
|
+
type PrismaUserLike = {
|
|
10
|
+
imageAttachmentId?: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type IUserLegacyShape<U extends PrismaUserLike> = U & {
|
|
13
|
+
imageAttachment: U['imageAttachmentId'];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Restore the Mongoose-era field name (`imageAttachment`) on a Prisma user row.
|
|
17
|
+
*
|
|
18
|
+
* TODO: only `imageAttachment` is restored so far. Map the remaining Prisma/Mongoose as the callers that need them are migrated.
|
|
19
|
+
*/
|
|
20
|
+
export declare const toLegacyUserShape: <U extends PrismaUserLike>(user: U) => IUserLegacyShape<U>;
|
|
21
|
+
export {};
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import { Document as
|
|
2
|
-
import { isRef as
|
|
3
|
-
const
|
|
4
|
-
const i = t instanceof
|
|
5
|
-
return e.isEmailPublished && (e.email =
|
|
1
|
+
import { Document as c } from "mongoose";
|
|
2
|
+
import { isRef as a, isPopulated as r } from "../../interfaces/common.js";
|
|
3
|
+
const m = (t) => {
|
|
4
|
+
const i = t instanceof c ? t.toObject() : t, { password: s, apiToken: l, email: n, ...o } = i, e = o;
|
|
5
|
+
return e.isEmailPublished && (e.email = n), e;
|
|
6
6
|
};
|
|
7
7
|
function u(t) {
|
|
8
|
-
return t == null ||
|
|
8
|
+
return t == null || a(t) && !r(t) ? t : m(t);
|
|
9
9
|
}
|
|
10
|
+
const d = (t) => ({
|
|
11
|
+
...t,
|
|
12
|
+
imageAttachment: t.imageAttachmentId
|
|
13
|
+
});
|
|
10
14
|
export {
|
|
11
|
-
|
|
12
|
-
u as serializeUserSecurely
|
|
15
|
+
m as omitInsecureAttributes,
|
|
16
|
+
u as serializeUserSecurely,
|
|
17
|
+
d as toLegacyUserShape
|
|
13
18
|
};
|
|
14
19
|
//# sourceMappingURL=user-serializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-serializer.js","sources":["../../../src/models/serializers/user-serializer.ts"],"sourcesContent":["import { Document } from 'mongoose';\n\nimport { isPopulated, isRef, type Ref } from '../../interfaces/common.js';\nimport type { IUser } from '../../interfaces/user.js';\n\nexport type IUserSerializedSecurely<U extends IUser> = Omit<\n U,\n 'password' | 'apiToken' | 'email'\n> & { email?: string };\n\nexport const omitInsecureAttributes = <U extends IUser>(\n user: U,\n): IUserSerializedSecurely<U> => {\n const leanDoc = user instanceof Document ? user.toObject<U>() : user;\n\n const { password, apiToken, email, ...rest } = 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>(\n user?: U,\n): IUserSerializedSecurely<U>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: Ref<U>,\n): Ref<IUserSerializedSecurely<U>>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: U | Ref<U>,\n): 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":";;AAUO,MAAMA,IAAyB,CACpCC,MAC+B;AAC/B,QAAMC,IAAUD,aAAgBE,IAAWF,EAAK,aAAgBA,GAE1D,EAAE,UAAAG,GAAU,UAAAC,GAAU,OAAAC,GAAO,GAAGC,MAASL,GAEzCM,IAAyCD;AAG/C,SAAIC,EAAW,qBACbA,EAAW,QAAQF,IAGdE;AACT;AAQO,SAASC,EACdR,GAC0E;AAG1E,SAFIA,KAAQ,QAERS,EAAMT,CAAI,KAAK,CAACU,EAAYV,CAAI,IAAUA,IAEvCD,EAAuBC,CAAI;AACpC;"}
|
|
1
|
+
{"version":3,"file":"user-serializer.js","sources":["../../../src/models/serializers/user-serializer.ts"],"sourcesContent":["import { Document } from 'mongoose';\n\nimport { isPopulated, isRef, type Ref } from '../../interfaces/common.js';\nimport type { IUser } from '../../interfaces/user.js';\n\nexport type IUserSerializedSecurely<U extends IUser> = Omit<\n U,\n 'password' | 'apiToken' | 'email'\n> & { email?: string };\n\nexport const omitInsecureAttributes = <U extends IUser>(\n user: U,\n): IUserSerializedSecurely<U> => {\n const leanDoc = user instanceof Document ? user.toObject<U>() : user;\n\n const { password, apiToken, email, ...rest } = 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>(\n user?: U,\n): IUserSerializedSecurely<U>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: Ref<U>,\n): Ref<IUserSerializedSecurely<U>>;\nexport function serializeUserSecurely<U extends IUser>(\n user?: U | Ref<U>,\n): 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\ntype PrismaUserLike = { imageAttachmentId?: string | null };\n\nexport type IUserLegacyShape<U extends PrismaUserLike> = U & {\n imageAttachment: U['imageAttachmentId'];\n};\n\n/**\n * Restore the Mongoose-era field name (`imageAttachment`) on a Prisma user row.\n *\n * TODO: only `imageAttachment` is restored so far. Map the remaining Prisma/Mongoose as the callers that need them are migrated.\n */\nexport const toLegacyUserShape = <U extends PrismaUserLike>(\n user: U,\n): IUserLegacyShape<U> => ({\n ...user,\n imageAttachment: user.imageAttachmentId,\n});\n"],"names":["omitInsecureAttributes","user","leanDoc","Document","password","apiToken","email","rest","secureUser","serializeUserSecurely","isRef","isPopulated","toLegacyUserShape"],"mappings":";;AAUO,MAAMA,IAAyB,CACpCC,MAC+B;AAC/B,QAAMC,IAAUD,aAAgBE,IAAWF,EAAK,aAAgBA,GAE1D,EAAE,UAAAG,GAAU,UAAAC,GAAU,OAAAC,GAAO,GAAGC,MAASL,GAEzCM,IAAyCD;AAG/C,SAAIC,EAAW,qBACbA,EAAW,QAAQF,IAGdE;AACT;AAQO,SAASC,EACdR,GAC0E;AAG1E,SAFIA,KAAQ,QAERS,EAAMT,CAAI,KAAK,CAACU,EAAYV,CAAI,IAAUA,IAEvCD,EAAuBC,CAAI;AACpC;AAaO,MAAMW,IAAoB,CAC/BX,OACyB;AAAA,EACzB,GAAGA;AAAA,EACH,iBAAiBA,EAAK;AACxB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|