core: user: private and public projection (#507)

This commit is contained in:
undefined authored and GitHub committed 2023-02-24 14:58:22 +08:00
1 parent 4fe734a6f3
commit bd13c57d82
6 files changed
+44 -26

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
interface SerializeOptions {
showDisplayName: boolean;
currentSerializer?: (k: string, v: any) => any;
}
export default function serializer(options: SerializeOptions, ignoreSerializeFunction = false) {
options.currentSerializer = (k: string, v: any) => {
if (typeof k.startsWith !== 'function') console.log(k, v);
if (k.startsWith('_') && k !== '_id') return undefined;
if (typeof v === 'bigint') return `BigInt::${v.toString()}`;
if (!ignoreSerializeFunction && v && typeof v === 'object'
&& 'serialize' in v && typeof v.serialize === 'function') return v.serialize(options);
return v;
};
return options.currentSerializer;
}