@mathrunet/masamune
Version:
Manages packages for the server portion (NodeJS) of the Masamune framework.
94 lines • 3.49 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SqlApiBase = exports.SqlApiModelBase = void 0;
/**
* Base class for the API's model.
*
* Inherit this to create a model for the API.
*
* APIのモデルの基底クラス。
*
* これを継承してAPIのモデルを作成します。
*/
class SqlApiModelBase {
}
exports.SqlApiModelBase = SqlApiModelBase;
/**
* Base class for the API.
*
* Inherit this to create an API.
*
* APIの基底クラス。
*
* これを継承してAPIを作成します。
*/
class SqlApiBase {
/**
*
* @param {string} table
* Table Name.
*
* テーブル名。
*
* @param {"GET" | "POST" | "DELETE" | "PUT" | "COUNT"} method
* Specify the method to be used.
*
* 使用するメソッドを指定します。
*
* @param {{ [key: string]: any }[]} where
* Specify the conditions for retrieving data from Sql.
*
* Sqlからデータを取得するための条件を指定します。
*
* @param {{ [key: string]: any } | undefined} value
* Data to be added to the table.
*
* テーブルに追加するデータ。
*
* @returns {Promise<{ [key: string]: any }[] | number | null>}
* When [null] is returned, the condition is not met.
*
* Otherwise, it returns the retrieved data.
*
* [null]が返却されたときは条件に一致しないとき。
*
* その他の場合は取得されたデータを返します。
*/
process(_a) {
return __awaiter(this, arguments, void 0, function* ({ table, method, where, value, }) {
if (table !== this.table) {
return null;
}
switch (method) {
case "GET": {
return (yield this.get(where !== null && where !== void 0 ? where : [])).map((e) => { return e.toJson(); });
}
case "COUNT": {
yield this.count(where !== null && where !== void 0 ? where : []);
return [];
}
case "POST": {
return [(yield this.post(value !== null && value !== void 0 ? value : {}, where !== null && where !== void 0 ? where : [])).toJson()];
}
case "PUT": {
return [(yield this.put(value !== null && value !== void 0 ? value : {}, where !== null && where !== void 0 ? where : [])).toJson()];
}
case "DELETE": {
yield this.delete(where !== null && where !== void 0 ? where : []);
return [];
}
}
});
}
}
exports.SqlApiBase = SqlApiBase;
//# sourceMappingURL=sql_api_base.js.map