|
1 | 1 | import { v4 as uuidv4 } from 'uuid'; |
2 | | -import { WhereFilter } from '../../openapi/types.js'; |
| 2 | +import { TenantActivityStatus, WhereFilter } from '../../openapi/types.js'; |
3 | 3 | import { |
4 | 4 | BatchObject as BatchObjectGRPC, |
5 | 5 | BatchObject_MultiTargetRefProps, |
@@ -82,6 +82,7 @@ import { |
82 | 82 | import { ReferenceGuards } from '../references/classes.js'; |
83 | 83 | import { Beacon } from '../references/index.js'; |
84 | 84 | import { uuidToBeacon } from '../references/utils.js'; |
| 85 | +import { Tenant, TenantCreate, TenantUpdate } from '../tenants/types.js'; |
85 | 86 | import { |
86 | 87 | BatchObject, |
87 | 88 | BatchObjects, |
@@ -1135,4 +1136,73 @@ export class Serialize { |
1135 | 1136 | return { batch: batch, mapped: objs }; |
1136 | 1137 | }); |
1137 | 1138 | }; |
| 1139 | + |
| 1140 | + public static tenantsCreate(tenant: Tenant | TenantCreate): { |
| 1141 | + name: string; |
| 1142 | + activityStatus?: 'HOT' | 'COLD'; |
| 1143 | + } { |
| 1144 | + let activityStatus: TenantActivityStatus; |
| 1145 | + switch (tenant.activityStatus) { |
| 1146 | + case 'ACTIVE': |
| 1147 | + activityStatus = 'HOT'; |
| 1148 | + break; |
| 1149 | + case 'INACTIVE': |
| 1150 | + activityStatus = 'COLD'; |
| 1151 | + break; |
| 1152 | + case 'HOT': |
| 1153 | + case 'COLD': |
| 1154 | + case undefined: |
| 1155 | + activityStatus = tenant.activityStatus; |
| 1156 | + break; |
| 1157 | + case 'OFFLOADED': |
| 1158 | + throw new WeaviateInvalidInputError( |
| 1159 | + 'Cannot create a tenant with activity status OFFLOADED. Add objects to the tenant first and then you can update it to OFFLOADED.' |
| 1160 | + ); |
| 1161 | + case 'OFFLOADING': |
| 1162 | + throw new WeaviateInvalidInputError( |
| 1163 | + 'Cannot create a tenant with activity status OFFLOADING. This status is a read-only value that the server sets in the processing of making a tenant OFFLOADED.' |
| 1164 | + ); |
| 1165 | + case 'ONLOADING': |
| 1166 | + throw new WeaviateInvalidInputError( |
| 1167 | + 'Cannot create a tenant with activity status ONLOADING. This status is a read-only value that the server sets in the processing of making a tenant HOT.' |
| 1168 | + ); |
| 1169 | + } |
| 1170 | + return { |
| 1171 | + name: tenant.name, |
| 1172 | + activityStatus, |
| 1173 | + }; |
| 1174 | + } |
| 1175 | + |
| 1176 | + public static tenantUpdate = ( |
| 1177 | + tenant: Tenant | TenantUpdate |
| 1178 | + ): { name: string; activityStatus: 'HOT' | 'COLD' | 'FROZEN' } => { |
| 1179 | + let activityStatus: TenantActivityStatus; |
| 1180 | + switch (tenant.activityStatus) { |
| 1181 | + case 'ACTIVE': |
| 1182 | + activityStatus = 'HOT'; |
| 1183 | + break; |
| 1184 | + case 'INACTIVE': |
| 1185 | + activityStatus = 'COLD'; |
| 1186 | + break; |
| 1187 | + case 'OFFLOADED': |
| 1188 | + activityStatus = 'FROZEN'; |
| 1189 | + break; |
| 1190 | + case 'HOT': |
| 1191 | + case 'COLD': |
| 1192 | + activityStatus = tenant.activityStatus; |
| 1193 | + break; |
| 1194 | + case 'OFFLOADING': |
| 1195 | + throw new WeaviateInvalidInputError( |
| 1196 | + 'Cannot create a tenant with activity status OFFLOADING. This status is a read-only value that the server sets in the processing of making a tenant OFFLOADED.' |
| 1197 | + ); |
| 1198 | + case 'ONLOADING': |
| 1199 | + throw new WeaviateInvalidInputError( |
| 1200 | + 'Cannot create a tenant with activity status ONLOADING. This status is a read-only value that the server sets in the processing of making a tenant HOT.' |
| 1201 | + ); |
| 1202 | + } |
| 1203 | + return { |
| 1204 | + name: tenant.name, |
| 1205 | + activityStatus, |
| 1206 | + }; |
| 1207 | + }; |
1138 | 1208 | } |
0 commit comments