|
| 1 | +import { serializeUserMini } from './userMini.generated.js'; |
| 2 | +import { deserializeUserMini } from './userMini.generated.js'; |
| 3 | +import { serializeGroupMini } from './groupMini.generated.js'; |
| 4 | +import { deserializeGroupMini } from './groupMini.generated.js'; |
| 5 | +import { UserMini } from './userMini.generated.js'; |
| 6 | +import { GroupMini } from './groupMini.generated.js'; |
| 7 | +import { BoxSdkError } from '../box/errors.js'; |
| 8 | +import { SerializedData } from '../serialization/json.js'; |
| 9 | +import { sdIsEmpty } from '../serialization/json.js'; |
| 10 | +import { sdIsBoolean } from '../serialization/json.js'; |
| 11 | +import { sdIsNumber } from '../serialization/json.js'; |
| 12 | +import { sdIsString } from '../serialization/json.js'; |
| 13 | +import { sdIsList } from '../serialization/json.js'; |
| 14 | +import { sdIsMap } from '../serialization/json.js'; |
| 15 | +export type AppItemEventSourceTypeField = 'app_item'; |
| 16 | +export class AppItemEventSource { |
| 17 | + readonly id!: string; |
| 18 | + readonly type: AppItemEventSourceTypeField = |
| 19 | + 'app_item' as AppItemEventSourceTypeField; |
| 20 | + readonly appItemType!: string; |
| 21 | + readonly user?: UserMini; |
| 22 | + readonly group?: GroupMini; |
| 23 | + constructor( |
| 24 | + fields: Omit<AppItemEventSource, 'type'> & |
| 25 | + Partial<Pick<AppItemEventSource, 'type'>> |
| 26 | + ) { |
| 27 | + if (fields.id) { |
| 28 | + this.id = fields.id; |
| 29 | + } |
| 30 | + if (fields.type) { |
| 31 | + this.type = fields.type; |
| 32 | + } |
| 33 | + if (fields.appItemType) { |
| 34 | + this.appItemType = fields.appItemType; |
| 35 | + } |
| 36 | + if (fields.user) { |
| 37 | + this.user = fields.user; |
| 38 | + } |
| 39 | + if (fields.group) { |
| 40 | + this.group = fields.group; |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | +export interface AppItemEventSourceInput { |
| 45 | + readonly id: string; |
| 46 | + readonly type?: AppItemEventSourceTypeField; |
| 47 | + readonly appItemType: string; |
| 48 | + readonly user?: UserMini; |
| 49 | + readonly group?: GroupMini; |
| 50 | +} |
| 51 | +export function serializeAppItemEventSourceTypeField( |
| 52 | + val: AppItemEventSourceTypeField |
| 53 | +): SerializedData { |
| 54 | + return val; |
| 55 | +} |
| 56 | +export function deserializeAppItemEventSourceTypeField( |
| 57 | + val: SerializedData |
| 58 | +): AppItemEventSourceTypeField { |
| 59 | + if (val == 'app_item') { |
| 60 | + return val; |
| 61 | + } |
| 62 | + throw new BoxSdkError({ |
| 63 | + message: "Can't deserialize AppItemEventSourceTypeField", |
| 64 | + }); |
| 65 | +} |
| 66 | +export function serializeAppItemEventSource( |
| 67 | + val: AppItemEventSource |
| 68 | +): SerializedData { |
| 69 | + return { |
| 70 | + ['id']: val.id, |
| 71 | + ['type']: serializeAppItemEventSourceTypeField(val.type), |
| 72 | + ['app_item_type']: val.appItemType, |
| 73 | + ['user']: val.user == void 0 ? void 0 : serializeUserMini(val.user), |
| 74 | + ['group']: val.group == void 0 ? void 0 : serializeGroupMini(val.group), |
| 75 | + }; |
| 76 | +} |
| 77 | +export function deserializeAppItemEventSource( |
| 78 | + val: SerializedData |
| 79 | +): AppItemEventSource { |
| 80 | + if (!sdIsMap(val)) { |
| 81 | + throw new BoxSdkError({ |
| 82 | + message: 'Expecting a map for "AppItemEventSource"', |
| 83 | + }); |
| 84 | + } |
| 85 | + if (val.id == void 0) { |
| 86 | + throw new BoxSdkError({ |
| 87 | + message: 'Expecting "id" of type "AppItemEventSource" to be defined', |
| 88 | + }); |
| 89 | + } |
| 90 | + if (!sdIsString(val.id)) { |
| 91 | + throw new BoxSdkError({ |
| 92 | + message: 'Expecting string for "id" of type "AppItemEventSource"', |
| 93 | + }); |
| 94 | + } |
| 95 | + const id: string = val.id; |
| 96 | + if (val.type == void 0) { |
| 97 | + throw new BoxSdkError({ |
| 98 | + message: 'Expecting "type" of type "AppItemEventSource" to be defined', |
| 99 | + }); |
| 100 | + } |
| 101 | + const type: AppItemEventSourceTypeField = |
| 102 | + deserializeAppItemEventSourceTypeField(val.type); |
| 103 | + if (val.app_item_type == void 0) { |
| 104 | + throw new BoxSdkError({ |
| 105 | + message: |
| 106 | + 'Expecting "app_item_type" of type "AppItemEventSource" to be defined', |
| 107 | + }); |
| 108 | + } |
| 109 | + if (!sdIsString(val.app_item_type)) { |
| 110 | + throw new BoxSdkError({ |
| 111 | + message: |
| 112 | + 'Expecting string for "app_item_type" of type "AppItemEventSource"', |
| 113 | + }); |
| 114 | + } |
| 115 | + const appItemType: string = val.app_item_type; |
| 116 | + const user: undefined | UserMini = |
| 117 | + val.user == void 0 ? void 0 : deserializeUserMini(val.user); |
| 118 | + const group: undefined | GroupMini = |
| 119 | + val.group == void 0 ? void 0 : deserializeGroupMini(val.group); |
| 120 | + return { |
| 121 | + id: id, |
| 122 | + type: type, |
| 123 | + appItemType: appItemType, |
| 124 | + user: user, |
| 125 | + group: group, |
| 126 | + } satisfies AppItemEventSource; |
| 127 | +} |
| 128 | +export function serializeAppItemEventSourceInput( |
| 129 | + val: AppItemEventSourceInput |
| 130 | +): SerializedData { |
| 131 | + return { |
| 132 | + ['id']: val.id, |
| 133 | + ['type']: |
| 134 | + val.type == void 0 |
| 135 | + ? void 0 |
| 136 | + : serializeAppItemEventSourceTypeField(val.type), |
| 137 | + ['app_item_type']: val.appItemType, |
| 138 | + ['user']: val.user == void 0 ? void 0 : serializeUserMini(val.user), |
| 139 | + ['group']: val.group == void 0 ? void 0 : serializeGroupMini(val.group), |
| 140 | + }; |
| 141 | +} |
| 142 | +export function deserializeAppItemEventSourceInput( |
| 143 | + val: SerializedData |
| 144 | +): AppItemEventSourceInput { |
| 145 | + if (!sdIsMap(val)) { |
| 146 | + throw new BoxSdkError({ |
| 147 | + message: 'Expecting a map for "AppItemEventSourceInput"', |
| 148 | + }); |
| 149 | + } |
| 150 | + if (val.id == void 0) { |
| 151 | + throw new BoxSdkError({ |
| 152 | + message: 'Expecting "id" of type "AppItemEventSourceInput" to be defined', |
| 153 | + }); |
| 154 | + } |
| 155 | + if (!sdIsString(val.id)) { |
| 156 | + throw new BoxSdkError({ |
| 157 | + message: 'Expecting string for "id" of type "AppItemEventSourceInput"', |
| 158 | + }); |
| 159 | + } |
| 160 | + const id: string = val.id; |
| 161 | + const type: undefined | AppItemEventSourceTypeField = |
| 162 | + val.type == void 0 |
| 163 | + ? void 0 |
| 164 | + : deserializeAppItemEventSourceTypeField(val.type); |
| 165 | + if (val.app_item_type == void 0) { |
| 166 | + throw new BoxSdkError({ |
| 167 | + message: |
| 168 | + 'Expecting "app_item_type" of type "AppItemEventSourceInput" to be defined', |
| 169 | + }); |
| 170 | + } |
| 171 | + if (!sdIsString(val.app_item_type)) { |
| 172 | + throw new BoxSdkError({ |
| 173 | + message: |
| 174 | + 'Expecting string for "app_item_type" of type "AppItemEventSourceInput"', |
| 175 | + }); |
| 176 | + } |
| 177 | + const appItemType: string = val.app_item_type; |
| 178 | + const user: undefined | UserMini = |
| 179 | + val.user == void 0 ? void 0 : deserializeUserMini(val.user); |
| 180 | + const group: undefined | GroupMini = |
| 181 | + val.group == void 0 ? void 0 : deserializeGroupMini(val.group); |
| 182 | + return { |
| 183 | + id: id, |
| 184 | + type: type, |
| 185 | + appItemType: appItemType, |
| 186 | + user: user, |
| 187 | + group: group, |
| 188 | + } satisfies AppItemEventSourceInput; |
| 189 | +} |
0 commit comments