UNPKG

@aws-amplify/graphql-schema-generator

Version:
71 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Model = exports.Index = exports.Field = void 0; class Field { constructor(name, type) { this.name = name; this.type = type; this.default = undefined; } } exports.Field = Field; class Index { constructor(name) { this.name = name; this.fields = []; } getFields() { return this.fields; } setFields(fields) { this.fields = [...fields]; } } exports.Index = Index; class Model { constructor(name) { this.name = name; this.fields = []; this.primaryKey = undefined; this.indexes = []; } getName() { return this.name; } addField(field) { if (this.hasField(field.name)) { throw new Error(`Field "${field.name}" already exists.`); } this.fields.push(field); } hasField(name) { return this.fields.some((f) => f.name === name); } setPrimaryKey(fields) { const primaryKey = new Index('PRIMARY_KEY'); primaryKey.setFields(fields); this.primaryKey = primaryKey; } getPrimaryKey() { return this.primaryKey; } getIndexes() { return this.indexes; } addIndex(name, fields) { if (this.hasIndex(name)) { throw new Error(`Index "${name}" already exists.`); } const index = new Index(name); index.setFields(fields); this.indexes.push(index); } hasIndex(name) { return this.indexes.some((i) => i.name === name); } getFields() { return this.fields; } } exports.Model = Model; //# sourceMappingURL=types.js.map