libmodulor
Version:
A TypeScript library to create platform-agnostic applications
34 lines (33 loc) • 946 B
JavaScript
import { UnavailableError } from '../error/index.js';
export const UCDataStoreMode = {
NONE: 'NONE',
READ: 'READ',
READ_WRITE: 'READ_WRITE',
WRITE: 'WRITE',
};
export function assertCan(op, mode) {
switch (mode) {
case 'NONE':
if (op === 'read') {
throw new UnavailableError('err_uc_data_store_not_readable');
}
if (op === 'write') {
throw new UnavailableError('err_uc_data_store_not_writable');
}
break;
case 'READ':
if (op === 'write') {
throw new UnavailableError('err_uc_data_store_not_writable');
}
break;
case 'READ_WRITE':
break;
case 'WRITE':
if (op === 'read') {
throw new UnavailableError('err_uc_data_store_not_readable');
}
break;
default:
mode;
}
}