dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
36 lines (35 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityAction = exports.Entity = void 0;
const index_js_1 = require("../errors/index.js");
const constants_js_1 = require("./constants.js");
const index_js_2 = require("./utils/index.js");
class Entity {
constructor({ name, table, schema, computeKey, entityAttribute = true, timestamps = true, meta = {} }) {
this.type = 'entity';
this.entityName = name;
this.table = table;
this.entityAttribute = entityAttribute;
this.timestamps = timestamps;
if (computeKey === undefined && !(0, index_js_2.doesSchemaValidateTableSchema)(schema, table)) {
throw new index_js_1.DynamoDBToolboxError('entity.invalidSchema', {
message: `Entity ${name} schema does not follow its table primary key schema`
});
}
this.attributes = schema.attributes;
this.schema = (0, index_js_2.buildEntitySchema)({ ...this, schema });
this.schema.check();
this.computeKey = computeKey;
this.meta = meta;
}
build(Action) {
return new Action(this);
}
}
exports.Entity = Entity;
class EntityAction {
constructor(entity) {
this.entity = entity;
}
}
exports.EntityAction = EntityAction;