@mathrunet/masamune 1.6.5 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # [1.7.0](https://github.com/mathrunet/node_masamune/compare/v1.6.4...v1.7.0) (2023-11-03)
2
+
3
+
4
+ ### feat
5
+
6
+ * Add SqlApiBase. ([ff6c5b2](https://github.com/mathrunet/node_masamune/commit/ff6c5b28905402f326904eb4052e86db82be4778))
7
+
8
+ ### fix
9
+
10
+ * ver.1.6.5. ([33bb2ec](https://github.com/mathrunet/node_masamune/commit/33bb2ec9f27c208926b093699d65d1c74ad854e7))
11
+
12
+
13
+
1
14
  ## [1.6.4](https://github.com/mathrunet/node_masamune/compare/v1.6.3...v1.6.4) (2023-11-02)
2
15
 
3
16
 
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as base from "./lib/functions_base";
2
2
  import * as regions from "./lib/regions";
3
3
  export * from "./functions";
4
4
  export * from "./lib/api";
5
+ export * from "./lib/sql_api_base";
5
6
  export * from "./lib/schedule_process_function_base";
6
7
  export * from "./lib/request_process_function_base";
7
8
  export * from "./lib/call_process_function_base";
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ exports.deploy = exports.notification = exports.sendGrid = exports.gmail = void
30
30
  const admin = __importStar(require("firebase-admin"));
31
31
  __exportStar(require("./functions"), exports);
32
32
  __exportStar(require("./lib/api"), exports);
33
+ __exportStar(require("./lib/sql_api_base"), exports);
33
34
  __exportStar(require("./lib/schedule_process_function_base"), exports);
34
35
  __exportStar(require("./lib/request_process_function_base"), exports);
35
36
  __exportStar(require("./lib/call_process_function_base"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAAwC;AAExC,8CAA4B;AAC5B,4CAA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,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;SACpD;KACJ;AACL,CAAC;AAPD,wBAOC"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Base class for the API's model.
3
+ *
4
+ * Inherit this to create a model for the API.
5
+ *
6
+ * APIのモデルの基底クラス。
7
+ *
8
+ * これを継承してAPIのモデルを作成します。
9
+ */
10
+ export declare abstract class SqlApiModelBase {
11
+ /**
12
+ * Convert [SqlApiModelBase] to a format that can be handled by Json.
13
+ *
14
+ * [SqlApiModelBase]をJsonで扱える形式に変換します。
15
+ *
16
+ * @returns {{ [key: string]: any }}
17
+ * Json format.
18
+ *
19
+ * Json形式。
20
+ */
21
+ abstract toJson(): {
22
+ [key: string]: any;
23
+ };
24
+ }
25
+ /**
26
+ * Base class for the API.
27
+ *
28
+ * Inherit this to create an API.
29
+ *
30
+ * APIの基底クラス。
31
+ *
32
+ * これを継承してAPIを作成します。
33
+ */
34
+ export declare abstract class SqlApiBase<T extends SqlApiModelBase> {
35
+ /**
36
+ * Name of table to be used.
37
+ *
38
+ * 使用するテーブル名。
39
+ */
40
+ abstract table: string;
41
+ /**
42
+ * Get the data from the table.
43
+ *
44
+ * テーブルからデータを取得します。
45
+ *
46
+ * @param {{ [key: string]: any }[]} where
47
+ * Specify the conditions for retrieving data from Sql.
48
+ *
49
+ * Sqlからデータを取得するための条件を指定します。
50
+ *
51
+ * @returns {Promise<T[]>}
52
+ * Data from the table.
53
+ *
54
+ * テーブルからのデータ。
55
+ */
56
+ abstract get(where: {
57
+ [key: string]: any;
58
+ }[]): Promise<T[]>;
59
+ /**
60
+ * Get the number of records matching [where].
61
+ *
62
+ * [where]に一致するレコードの数を取得します。
63
+ *
64
+ * @param {{ [key: string]: any }[]} where
65
+ * Specify the conditions for retrieving data from Sql.
66
+ *
67
+ * Sqlからデータを取得するための条件を指定します。
68
+ *
69
+ * @returns {Promise<number>}
70
+ * Number of records matching [where].
71
+ *
72
+ * [where]に一致するレコードの数。
73
+ */
74
+ abstract count(where: {
75
+ [key: string]: any;
76
+ }[]): Promise<number>;
77
+ /**
78
+ * Add data to the table.
79
+ *
80
+ * テーブルにデータを追加します。
81
+ *
82
+ * @param {{ [key: string]: any }} value
83
+ * Data to be added to the table.
84
+ *
85
+ * テーブルに追加するデータ。
86
+ *
87
+ * @param {{ [key: string]: any }[]} where
88
+ * Specify the conditions for adding data from Sql.
89
+ *
90
+ * Sqlからデータを追加するための条件を指定します。
91
+ *
92
+ * @returns {Promise<T>}
93
+ * Data added to the table.
94
+ *
95
+ * テーブルに追加されたデータ。
96
+ */
97
+ abstract post(value: {
98
+ [key: string]: any;
99
+ }, where: {
100
+ [key: string]: any;
101
+ }[]): Promise<T>;
102
+ /**
103
+ * Update the data in the table.
104
+ *
105
+ * テーブルのデータを更新します。
106
+ *
107
+ * @param {{ [key: string]: any }} value
108
+ * Data to be updated in the table.
109
+ *
110
+ * テーブルの更新するデータ。
111
+ *
112
+ * @param {{ [key: string]: any }[]} where
113
+ * Specify the conditions for updating data from Sql.
114
+ *
115
+ * Sqlからデータを更新するための条件を指定します。
116
+ *
117
+ * @returns {Promise<T>}
118
+ * Updated data for the table.
119
+ *
120
+ * テーブルの更新されたデータ。
121
+ */
122
+ abstract put(value: {
123
+ [key: string]: any;
124
+ }, where: {
125
+ [key: string]: any;
126
+ }[]): Promise<T>;
127
+ /**
128
+ * Deletes data from the table.
129
+ *
130
+ * テーブルからデータを削除します。
131
+ *
132
+ * @param { [key: string]: any }[] where
133
+ * Specify the conditions for deleting data from Sql.
134
+ *
135
+ * Sqlからデータを削除するための条件を指定します。
136
+ *
137
+ * @returns {Promise<void>}
138
+ */
139
+ abstract delete(where: {
140
+ [key: string]: any;
141
+ }[]): Promise<void>;
142
+ /**
143
+ *
144
+ * @param {string} table
145
+ * Table Name.
146
+ *
147
+ * テーブル名。
148
+ *
149
+ * @param {"GET" | "POST" | "DELETE" | "PUT" | "COUNT"} method
150
+ * Specify the method to be used.
151
+ *
152
+ * 使用するメソッドを指定します。
153
+ *
154
+ * @param {{ [key: string]: any }[]} where
155
+ * Specify the conditions for retrieving data from Sql.
156
+ *
157
+ * Sqlからデータを取得するための条件を指定します。
158
+ *
159
+ * @param {{ [key: string]: any } | undefined} value
160
+ * Data to be added to the table.
161
+ *
162
+ * テーブルに追加するデータ。
163
+ *
164
+ * @returns {Promise<{ [key: string]: any }[] | number | null>}
165
+ * When [null] is returned, the condition is not met.
166
+ *
167
+ * Otherwise, it returns the retrieved data.
168
+ *
169
+ * [null]が返却されたときは条件に一致しないとき。
170
+ *
171
+ * その他の場合は取得されたデータを返します。
172
+ */
173
+ process({ table, method, where, value, }: {
174
+ table: string;
175
+ method: "GET" | "POST" | "DELETE" | "PUT" | "COUNT";
176
+ where?: {
177
+ [key: string]: any;
178
+ }[] | undefined;
179
+ value?: {
180
+ [key: string]: any;
181
+ } | undefined;
182
+ }): Promise<{
183
+ [key: string]: any;
184
+ }[] | number | null>;
185
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SqlApiBase = exports.SqlApiModelBase = void 0;
13
+ /**
14
+ * Base class for the API's model.
15
+ *
16
+ * Inherit this to create a model for the API.
17
+ *
18
+ * APIのモデルの基底クラス。
19
+ *
20
+ * これを継承してAPIのモデルを作成します。
21
+ */
22
+ class SqlApiModelBase {
23
+ }
24
+ exports.SqlApiModelBase = SqlApiModelBase;
25
+ /**
26
+ * Base class for the API.
27
+ *
28
+ * Inherit this to create an API.
29
+ *
30
+ * APIの基底クラス。
31
+ *
32
+ * これを継承してAPIを作成します。
33
+ */
34
+ class SqlApiBase {
35
+ /**
36
+ *
37
+ * @param {string} table
38
+ * Table Name.
39
+ *
40
+ * テーブル名。
41
+ *
42
+ * @param {"GET" | "POST" | "DELETE" | "PUT" | "COUNT"} method
43
+ * Specify the method to be used.
44
+ *
45
+ * 使用するメソッドを指定します。
46
+ *
47
+ * @param {{ [key: string]: any }[]} where
48
+ * Specify the conditions for retrieving data from Sql.
49
+ *
50
+ * Sqlからデータを取得するための条件を指定します。
51
+ *
52
+ * @param {{ [key: string]: any } | undefined} value
53
+ * Data to be added to the table.
54
+ *
55
+ * テーブルに追加するデータ。
56
+ *
57
+ * @returns {Promise<{ [key: string]: any }[] | number | null>}
58
+ * When [null] is returned, the condition is not met.
59
+ *
60
+ * Otherwise, it returns the retrieved data.
61
+ *
62
+ * [null]が返却されたときは条件に一致しないとき。
63
+ *
64
+ * その他の場合は取得されたデータを返します。
65
+ */
66
+ process({ table, method, where, value, }) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (table !== this.table) {
69
+ return null;
70
+ }
71
+ switch (method) {
72
+ case "GET": {
73
+ return (yield this.get(where !== null && where !== void 0 ? where : [])).map((e) => { return e.toJson(); });
74
+ }
75
+ case "COUNT": {
76
+ yield this.count(where !== null && where !== void 0 ? where : []);
77
+ return [];
78
+ }
79
+ case "POST": {
80
+ return [(yield this.post(value !== null && value !== void 0 ? value : {}, where !== null && where !== void 0 ? where : [])).toJson()];
81
+ }
82
+ case "PUT": {
83
+ return [(yield this.put(value !== null && value !== void 0 ? value : {}, where !== null && where !== void 0 ? where : [])).toJson()];
84
+ }
85
+ case "DELETE": {
86
+ yield this.delete(where !== null && where !== void 0 ? where : []);
87
+ return [];
88
+ }
89
+ }
90
+ });
91
+ }
92
+ }
93
+ exports.SqlApiBase = SqlApiBase;
94
+ //# sourceMappingURL=sql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AE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;iBAChE;gBACD,KAAK,QAAQ,CAAC,CAAC;oBACX,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC;oBAC/B,OAAO,EAAE,CAAC;iBACb;aACJ;QACL,CAAC;KAAA;CACJ;AArKD,gCAqKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mathrunet/masamune",
3
- "version": "1.6.5",
3
+ "version": "1.7.0",
4
4
  "description": "Manages packages for the server portion (NodeJS) of the Masamune framework.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",