Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async insertAndGet>(
command: SingleInsertCommand>
): Promise {
const { entityName, value } = command;
// @ts-ignore newValue must contain id
const newValue: M[N] = value.id
? value
: update(value, {
id: timeStampWithRandomString()
});
const operation = PhenylStateUpdater.register(
this.entityState,
entityName,
newValue
);
// @ts-ignore operation is nonbreaking
this.entityState = update(this.entityState, operation);
return newValue;
}
/**
>(command: T): T {
const normalizedOperation = normalizeUpdateOperation(command.operation);
const version = {
id: timeStampWithRandomString(),
op: JSON.stringify(command.operation)
};
const $push = Object.assign({}, normalizedOperation.$push, {
"_PhenylMeta.versions": { $each: [version], $slice: -100 }
});
const newOperation = Object.assign({}, normalizedOperation, { $push });
return Object.assign({}, command, { operation: newOperation });
}
const newValues: M[N][] = values.map(value =>
value.id
? value
: update(value, {
id: timeStampWithRandomString()
})
);
async create(
preSession: PreSession>
): Promise> {
let value = preSession;
if (value.id == null) {
value = Object.assign({}, value, { id: timeStampWithRandomString() });
}
return this.set(value);
}
public static attachMetaInfoToNewEntity(
entity: E
): EntityWithMetaInfo {
const versionId = timeStampWithRandomString();
const _PhenylMeta = {
versions: [{ id: versionId, op: "" }]
};
return Object.assign({}, entity, { _PhenylMeta });
}