box-node-sdk
Version:
Official SDK for Box Platform APIs
86 lines (85 loc) • 3.13 kB
text/typescript
import { serializeWebhookMini } from './webhookMini';
import { deserializeWebhookMini } from './webhookMini';
import { WebhookMini } from './webhookMini';
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 interface Webhooks {
/**
* The limit that was used for these entries. This will be the same as the
* `limit` query parameter unless that value exceeded the maximum value
* allowed. The maximum value varies by API. */
readonly limit?: number;
/**
* The marker for the start of the next page of results. */
readonly nextMarker?: string | null;
/**
* The marker for the start of the previous page of results. */
readonly prevMarker?: string | null;
/**
* A list of webhooks. */
readonly entries?: readonly WebhookMini[];
readonly rawData?: SerializedData;
}
export function serializeWebhooks(val: Webhooks): SerializedData {
return {
['limit']: val.limit,
['next_marker']: val.nextMarker,
['prev_marker']: val.prevMarker,
['entries']:
val.entries == void 0
? val.entries
: (val.entries.map(function (item: WebhookMini): SerializedData {
return serializeWebhookMini(item);
}) as readonly any[]),
};
}
export function deserializeWebhooks(val: SerializedData): Webhooks {
if (!sdIsMap(val)) {
throw new BoxSdkError({ message: 'Expecting a map for "Webhooks"' });
}
if (!(val.limit == void 0) && !sdIsNumber(val.limit)) {
throw new BoxSdkError({
message: 'Expecting number for "limit" of type "Webhooks"',
});
}
const limit: undefined | number = val.limit == void 0 ? void 0 : val.limit;
if (!(val.next_marker == void 0) && !sdIsString(val.next_marker)) {
throw new BoxSdkError({
message: 'Expecting string for "next_marker" of type "Webhooks"',
});
}
const nextMarker: undefined | string =
val.next_marker == void 0 ? void 0 : val.next_marker;
if (!(val.prev_marker == void 0) && !sdIsString(val.prev_marker)) {
throw new BoxSdkError({
message: 'Expecting string for "prev_marker" of type "Webhooks"',
});
}
const prevMarker: undefined | string =
val.prev_marker == void 0 ? void 0 : val.prev_marker;
if (!(val.entries == void 0) && !sdIsList(val.entries)) {
throw new BoxSdkError({
message: 'Expecting array for "entries" of type "Webhooks"',
});
}
const entries: undefined | readonly WebhookMini[] =
val.entries == void 0
? void 0
: sdIsList(val.entries)
? (val.entries.map(function (itm: SerializedData): WebhookMini {
return deserializeWebhookMini(itm);
}) as readonly any[])
: [];
return {
limit: limit,
nextMarker: nextMarker,
prevMarker: prevMarker,
entries: entries,
} satisfies Webhooks;
}