box-node-sdk
Version:
Official SDK for Box Platform APIs
70 lines (69 loc) • 2.53 kB
text/typescript
import { serializeUserBaseTypeField } from './userBase';
import { deserializeUserBaseTypeField } from './userBase';
import { serializeUserBase } from './userBase';
import { deserializeUserBase } from './userBase';
import { UserBaseTypeField } from './userBase';
import { UserBase } from './userBase';
import { BoxSdkError } from '../box/errors';
import { SerializedData } from '../serialization/json';
import { sdIsEmpty } from '../serialization/json';
import { sdIsBoolean } from '../serialization/json';
import { sdIsNumber } from '../serialization/json';
import { sdIsString } from '../serialization/json';
import { sdIsList } from '../serialization/json';
import { sdIsMap } from '../serialization/json';
export class UserMini extends UserBase {
readonly name?: string;
readonly login?: string;
constructor(fields: UserMini) {
super(fields);
if (fields.name !== undefined) {
this.name = fields.name;
}
if (fields.login !== undefined) {
this.login = fields.login;
}
}
}
export function serializeUserMini(val: UserMini): SerializedData {
const base: any = serializeUserBase(val);
if (!sdIsMap(base)) {
throw new BoxSdkError({ message: 'Expecting a map for "UserMini"' });
}
return { ...base, ...{ ['name']: val.name, ['login']: val.login } };
}
export function deserializeUserMini(val: SerializedData): UserMini {
if (!sdIsMap(val)) {
throw new BoxSdkError({ message: 'Expecting a map for "UserMini"' });
}
if (!(val.name == void 0) && !sdIsString(val.name)) {
throw new BoxSdkError({
message: 'Expecting string for "name" of type "UserMini"',
});
}
const name: undefined | string = val.name == void 0 ? void 0 : val.name;
if (!(val.login == void 0) && !sdIsString(val.login)) {
throw new BoxSdkError({
message: 'Expecting string for "login" of type "UserMini"',
});
}
const login: undefined | string = val.login == void 0 ? void 0 : val.login;
if (val.id == void 0) {
throw new BoxSdkError({
message: 'Expecting "id" of type "UserMini" to be defined',
});
}
if (!sdIsString(val.id)) {
throw new BoxSdkError({
message: 'Expecting string for "id" of type "UserMini"',
});
}
const id: string = val.id;
if (val.type == void 0) {
throw new BoxSdkError({
message: 'Expecting "type" of type "UserMini" to be defined',
});
}
const type: UserBaseTypeField = deserializeUserBaseTypeField(val.type);
return { name: name, login: login, id: id, type: type } satisfies UserMini;
}