@opengis/fastify-table 1.0.91 → 1.0.93
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 +281 -273
- package/crud/funcs/dataUpdate.js +30 -29
- package/package.json +26 -26
- package/table/controllers/suggest.js +3 -3
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate.js +28 -28
- package/table/funcs/getFilterSQL/index.js +5 -1
package/Changelog.md
CHANGED
|
@@ -1,273 +1,281 @@
|
|
|
1
|
-
# fastify-table
|
|
2
|
-
|
|
3
|
-
## 1.0.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
## 1.0.
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
## 1.0.
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
## 1.0.
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
## 1.0.
|
|
20
|
-
|
|
21
|
-
- data API meta
|
|
22
|
-
|
|
23
|
-
## 1.0.
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
## 1.0.
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
## 1.0.
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
## 1.0.
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
## 1.0.
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
## 1.0.
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
## 1.0.
|
|
48
|
-
|
|
49
|
-
- add
|
|
50
|
-
|
|
51
|
-
## 1.0.
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
## 1.0.
|
|
56
|
-
|
|
57
|
-
- add
|
|
58
|
-
|
|
59
|
-
## 1.0.
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
## 1.0.
|
|
64
|
-
|
|
65
|
-
- add
|
|
66
|
-
|
|
67
|
-
## 1.0.
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
## 1.0.
|
|
72
|
-
|
|
73
|
-
- add
|
|
74
|
-
|
|
75
|
-
## 1.0.
|
|
76
|
-
|
|
77
|
-
- add
|
|
78
|
-
|
|
79
|
-
## 1.0.
|
|
80
|
-
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
## 1.0.
|
|
84
|
-
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
## 1.0.
|
|
88
|
-
|
|
89
|
-
- code optimization
|
|
90
|
-
|
|
91
|
-
## 1.0.
|
|
92
|
-
|
|
93
|
-
-
|
|
94
|
-
|
|
95
|
-
## 1.0.
|
|
96
|
-
|
|
97
|
-
- code optimization
|
|
98
|
-
|
|
99
|
-
## 1.0.
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
|
|
103
|
-
## 1.0.
|
|
104
|
-
|
|
105
|
-
- code optimization
|
|
106
|
-
|
|
107
|
-
## 1.0.
|
|
108
|
-
|
|
109
|
-
-
|
|
110
|
-
|
|
111
|
-
## 1.0.
|
|
112
|
-
|
|
113
|
-
-
|
|
114
|
-
|
|
115
|
-
## 1.0.
|
|
116
|
-
|
|
117
|
-
- add
|
|
118
|
-
|
|
119
|
-
## 1.0.
|
|
120
|
-
|
|
121
|
-
-
|
|
122
|
-
|
|
123
|
-
## 1.0.
|
|
124
|
-
|
|
125
|
-
-
|
|
126
|
-
|
|
127
|
-
## 1.0.
|
|
128
|
-
|
|
129
|
-
- search api
|
|
130
|
-
|
|
131
|
-
## 1.0.
|
|
132
|
-
|
|
133
|
-
-
|
|
134
|
-
|
|
135
|
-
## 1.0.
|
|
136
|
-
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
## 1.0.
|
|
140
|
-
|
|
141
|
-
-
|
|
142
|
-
|
|
143
|
-
## 1.0.
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
## 1.0.
|
|
148
|
-
|
|
149
|
-
-
|
|
150
|
-
|
|
151
|
-
## 1.0.
|
|
152
|
-
|
|
153
|
-
-
|
|
154
|
-
|
|
155
|
-
## 1.0.
|
|
156
|
-
|
|
157
|
-
-
|
|
158
|
-
|
|
159
|
-
## 1.0.
|
|
160
|
-
|
|
161
|
-
-
|
|
162
|
-
|
|
163
|
-
## 1.0.
|
|
164
|
-
|
|
165
|
-
-
|
|
166
|
-
|
|
167
|
-
## 1.0.
|
|
168
|
-
|
|
169
|
-
-
|
|
170
|
-
|
|
171
|
-
## 1.0.
|
|
172
|
-
|
|
173
|
-
-
|
|
174
|
-
|
|
175
|
-
## 1.0.
|
|
176
|
-
|
|
177
|
-
-
|
|
178
|
-
|
|
179
|
-
## 1.0.
|
|
180
|
-
|
|
181
|
-
-
|
|
182
|
-
|
|
183
|
-
## 1.0.
|
|
184
|
-
|
|
185
|
-
- widget
|
|
186
|
-
|
|
187
|
-
## 1.0.
|
|
188
|
-
|
|
189
|
-
-
|
|
190
|
-
|
|
191
|
-
## 1.0.
|
|
192
|
-
|
|
193
|
-
-
|
|
194
|
-
|
|
195
|
-
## 1.0.
|
|
196
|
-
|
|
197
|
-
-
|
|
198
|
-
|
|
199
|
-
## 1.0.
|
|
200
|
-
|
|
201
|
-
-
|
|
202
|
-
|
|
203
|
-
## 1.0.
|
|
204
|
-
|
|
205
|
-
-
|
|
206
|
-
|
|
207
|
-
## 1.0.
|
|
208
|
-
|
|
209
|
-
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
-
|
|
219
|
-
|
|
220
|
-
## 1.0.
|
|
221
|
-
|
|
222
|
-
-
|
|
223
|
-
|
|
224
|
-
## 1.0.
|
|
225
|
-
|
|
226
|
-
- widget
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
-
|
|
241
|
-
|
|
242
|
-
## 1.0.
|
|
243
|
-
|
|
244
|
-
-
|
|
245
|
-
|
|
246
|
-
## 1.0.
|
|
247
|
-
|
|
248
|
-
- code optimization
|
|
249
|
-
|
|
250
|
-
## 1.0.
|
|
251
|
-
|
|
252
|
-
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
- fix
|
|
263
|
-
|
|
264
|
-
## 1.0.
|
|
265
|
-
|
|
266
|
-
- fix
|
|
267
|
-
|
|
268
|
-
## 1.0.
|
|
269
|
-
|
|
270
|
-
-
|
|
271
|
-
|
|
272
|
-
-
|
|
273
|
-
|
|
1
|
+
# fastify-table
|
|
2
|
+
|
|
3
|
+
## 1.0.93 - 05.09.2024
|
|
4
|
+
|
|
5
|
+
- fix data API with sql columns filter
|
|
6
|
+
|
|
7
|
+
## 1.0.92 - 03.09.2024
|
|
8
|
+
|
|
9
|
+
- fix getTemplate
|
|
10
|
+
|
|
11
|
+
## 1.0.91 - 30.08.2024
|
|
12
|
+
|
|
13
|
+
- add CRUD and Auth logs
|
|
14
|
+
|
|
15
|
+
## 1.0.90 - 27.08.2024
|
|
16
|
+
|
|
17
|
+
- logger file API to core
|
|
18
|
+
|
|
19
|
+
## 1.0.89 - 26.08.2024
|
|
20
|
+
|
|
21
|
+
- data API meta bbox polyline support
|
|
22
|
+
|
|
23
|
+
## 1.0.87 - 26.08.2024
|
|
24
|
+
|
|
25
|
+
- change of null handling method of update crud API
|
|
26
|
+
|
|
27
|
+
## 1.0.86 - 23.08.2024
|
|
28
|
+
|
|
29
|
+
- data API meta cls support
|
|
30
|
+
|
|
31
|
+
## 1.0.84 - 22.08.2024
|
|
32
|
+
|
|
33
|
+
- suggest table:column support
|
|
34
|
+
|
|
35
|
+
## 1.0.83 - 20.08.2024
|
|
36
|
+
|
|
37
|
+
- code optimization
|
|
38
|
+
|
|
39
|
+
## 1.0.81 - 15.08.2024
|
|
40
|
+
|
|
41
|
+
- refactor /table API
|
|
42
|
+
|
|
43
|
+
## 1.0.78 - 14.08.2024
|
|
44
|
+
|
|
45
|
+
- add sqlColumns to /api/data/:table/?:id
|
|
46
|
+
|
|
47
|
+
## 1.0.77 - 13.08.2024
|
|
48
|
+
|
|
49
|
+
- add statusMonitor API
|
|
50
|
+
|
|
51
|
+
## 1.0.75 - 12.08.2024
|
|
52
|
+
|
|
53
|
+
- something do
|
|
54
|
+
|
|
55
|
+
## 1.0.71 - 01.08.2024
|
|
56
|
+
|
|
57
|
+
- add compile settings to form
|
|
58
|
+
|
|
59
|
+
## 1.0.70 - 29.07.2024
|
|
60
|
+
|
|
61
|
+
- add cron funcs and API
|
|
62
|
+
|
|
63
|
+
## 1.0.69 - 26.07.2024
|
|
64
|
+
|
|
65
|
+
- add column classifier mode for data API
|
|
66
|
+
|
|
67
|
+
## 1.0.68 - 26.07.2024
|
|
68
|
+
|
|
69
|
+
- code optimization
|
|
70
|
+
|
|
71
|
+
## 1.0.66 - 25.07.2024
|
|
72
|
+
|
|
73
|
+
- add notification compile template from data params support
|
|
74
|
+
|
|
75
|
+
## 1.0.65 - 23.07.2024
|
|
76
|
+
|
|
77
|
+
- add rest API token support
|
|
78
|
+
|
|
79
|
+
## 1.0.62 - 22.07.2024
|
|
80
|
+
|
|
81
|
+
- add email notification func and test api
|
|
82
|
+
|
|
83
|
+
## 1.0.61 - 18.07.2024
|
|
84
|
+
|
|
85
|
+
- add custom actions for table
|
|
86
|
+
|
|
87
|
+
## 1.0.60 - 12.07.2024
|
|
88
|
+
|
|
89
|
+
- code optimization
|
|
90
|
+
|
|
91
|
+
## 1.0.59 - 12.07.2024
|
|
92
|
+
|
|
93
|
+
- code optimization
|
|
94
|
+
|
|
95
|
+
## 1.0.58 - 08.07.2024
|
|
96
|
+
|
|
97
|
+
- code optimization
|
|
98
|
+
|
|
99
|
+
## 1.0.57 - 04.07.2024
|
|
100
|
+
|
|
101
|
+
- fix crud update boolean column
|
|
102
|
+
|
|
103
|
+
## 1.0.56 - 04.07.2024
|
|
104
|
+
|
|
105
|
+
- code optimization
|
|
106
|
+
|
|
107
|
+
## 1.0.55 - 02.07.2024
|
|
108
|
+
|
|
109
|
+
- callback support
|
|
110
|
+
|
|
111
|
+
## 1.0.54 - 01.07.2024
|
|
112
|
+
|
|
113
|
+
- code optimization
|
|
114
|
+
|
|
115
|
+
## 1.0.53 - 28.06.2024
|
|
116
|
+
|
|
117
|
+
- add migrations support
|
|
118
|
+
|
|
119
|
+
## 1.0.52 - 28.06.2024
|
|
120
|
+
|
|
121
|
+
- add table get api
|
|
122
|
+
|
|
123
|
+
## 1.0.51 - 27.06.2024
|
|
124
|
+
|
|
125
|
+
- add next-id api
|
|
126
|
+
|
|
127
|
+
## 1.0.50 - 27.06.2024
|
|
128
|
+
|
|
129
|
+
- refactor search api
|
|
130
|
+
|
|
131
|
+
## 1.0.49 - 26.06.2024
|
|
132
|
+
|
|
133
|
+
- refactor - npm settings
|
|
134
|
+
|
|
135
|
+
## 1.0.48 - 26.06.2024
|
|
136
|
+
|
|
137
|
+
- search api no specified table mode support
|
|
138
|
+
|
|
139
|
+
## 1.0.47 - 25.06.2024
|
|
140
|
+
|
|
141
|
+
- add extra properties support
|
|
142
|
+
|
|
143
|
+
## 1.0.46 - 24.06.2024
|
|
144
|
+
|
|
145
|
+
- fix data api edit geometry
|
|
146
|
+
|
|
147
|
+
## 1.0.45 - 19.06.2024
|
|
148
|
+
|
|
149
|
+
- fix data api table template order
|
|
150
|
+
|
|
151
|
+
## 1.0.44 - 18.06.2024
|
|
152
|
+
|
|
153
|
+
- add extra data support (form DataTable)
|
|
154
|
+
|
|
155
|
+
## 1.0.43 - 14.06.2024
|
|
156
|
+
|
|
157
|
+
- add settings api, funcs, migration
|
|
158
|
+
|
|
159
|
+
## 1.0.42 - 12.06.2024
|
|
160
|
+
|
|
161
|
+
- table cardSql support
|
|
162
|
+
|
|
163
|
+
## 1.0.41 - 12.06.2024
|
|
164
|
+
|
|
165
|
+
- cls to db (crm.cls)
|
|
166
|
+
|
|
167
|
+
## 1.0.40 - 12.06.2024
|
|
168
|
+
|
|
169
|
+
- fix widget GET API
|
|
170
|
+
|
|
171
|
+
## 1.0.39 - 29.05.2024
|
|
172
|
+
|
|
173
|
+
- add getFolder func
|
|
174
|
+
|
|
175
|
+
## 1.0.37 - 23.05.2024
|
|
176
|
+
|
|
177
|
+
- add gallery widget
|
|
178
|
+
|
|
179
|
+
## 1.0.36 - 22.05.2024
|
|
180
|
+
|
|
181
|
+
- fix filter api array processing
|
|
182
|
+
|
|
183
|
+
## 1.0.31 - 20.05.2024
|
|
184
|
+
|
|
185
|
+
- widget db structure refactor
|
|
186
|
+
|
|
187
|
+
## 1.0.30 - 17.05.2024
|
|
188
|
+
|
|
189
|
+
- code optimization
|
|
190
|
+
|
|
191
|
+
## 1.0.29 - 17.05.2024
|
|
192
|
+
|
|
193
|
+
- widget api post (file)
|
|
194
|
+
|
|
195
|
+
## 1.0.28 - 14.05.2024
|
|
196
|
+
|
|
197
|
+
- dblist api set
|
|
198
|
+
|
|
199
|
+
## 1.0.27 - 12.05.2024
|
|
200
|
+
|
|
201
|
+
- code optimization
|
|
202
|
+
|
|
203
|
+
## 1.0.26 - 09.05.2024
|
|
204
|
+
|
|
205
|
+
- fix getTableSql
|
|
206
|
+
|
|
207
|
+
## 1.0.25 - 08.05.2024
|
|
208
|
+
|
|
209
|
+
- decorator to hook
|
|
210
|
+
|
|
211
|
+
## 1.0.24 - 07.05.2024
|
|
212
|
+
|
|
213
|
+
- getTemplate page
|
|
214
|
+
|
|
215
|
+
## 1.0.23 - 07.05.2024
|
|
216
|
+
|
|
217
|
+
- getTemplate funcs
|
|
218
|
+
- dblist api
|
|
219
|
+
|
|
220
|
+
## 1.0.22 - 03.05.2024
|
|
221
|
+
|
|
222
|
+
- getFilterSQL funcs
|
|
223
|
+
|
|
224
|
+
## 1.0.21 - 03.05.2024
|
|
225
|
+
|
|
226
|
+
- fix widget db structure
|
|
227
|
+
|
|
228
|
+
## 1.0.20 - 03.05.2024
|
|
229
|
+
|
|
230
|
+
- fix filter separator
|
|
231
|
+
|
|
232
|
+
## 1.0.19 - 02.05.2024
|
|
233
|
+
|
|
234
|
+
- widget plugin
|
|
235
|
+
- notification plugin
|
|
236
|
+
|
|
237
|
+
## 1.0.9 - 29.04.2024
|
|
238
|
+
|
|
239
|
+
- crud token support
|
|
240
|
+
- security - xss restriction
|
|
241
|
+
|
|
242
|
+
## 1.0.8 - 29.04.2024
|
|
243
|
+
|
|
244
|
+
- filter fix
|
|
245
|
+
|
|
246
|
+
## 1.0.7 - 26.04.2024
|
|
247
|
+
|
|
248
|
+
- code optimization
|
|
249
|
+
|
|
250
|
+
## 1.0.6 - 25.04.2024
|
|
251
|
+
|
|
252
|
+
- code optimization
|
|
253
|
+
|
|
254
|
+
## 1.0.5 - 24.04.2024
|
|
255
|
+
|
|
256
|
+
- code optimization
|
|
257
|
+
|
|
258
|
+
## 1.0.4 - 20.04.2024
|
|
259
|
+
|
|
260
|
+
- data api - order
|
|
261
|
+
- suggest api - db support
|
|
262
|
+
- del api fix
|
|
263
|
+
|
|
264
|
+
## 1.0.3 - 17.04.2024
|
|
265
|
+
|
|
266
|
+
- fix unit test
|
|
267
|
+
|
|
268
|
+
## 1.0.2 - 14.04.2024
|
|
269
|
+
|
|
270
|
+
- fix redis
|
|
271
|
+
|
|
272
|
+
## 1.0.1 - 14.04.2024
|
|
273
|
+
|
|
274
|
+
- fix redis
|
|
275
|
+
|
|
276
|
+
## 1.0.0 - 14.04.2024
|
|
277
|
+
|
|
278
|
+
- crud
|
|
279
|
+
- pg
|
|
280
|
+
- redis
|
|
281
|
+
- table
|
package/crud/funcs/dataUpdate.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import logChanges from './utils/logChanges.js';
|
|
5
|
-
|
|
6
|
-
export default async function dataUpdate({
|
|
7
|
-
table, id, data, pg: pg1, uid,
|
|
8
|
-
}) {
|
|
9
|
-
if (!data || !table || !id) return null;
|
|
10
|
-
|
|
11
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
12
|
-
const { columns, pk } = await getMeta(table);
|
|
13
|
-
|
|
14
|
-
const names = columns?.map((el) => el.name);
|
|
15
|
-
const filterData = Object.keys(data)
|
|
16
|
-
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el)));
|
|
17
|
-
|
|
18
|
-
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import logChanges from './utils/logChanges.js';
|
|
5
|
+
|
|
6
|
+
export default async function dataUpdate({
|
|
7
|
+
table, id, data, pg: pg1, uid,
|
|
8
|
+
}) {
|
|
9
|
+
if (!data || !table || !id) return null;
|
|
10
|
+
|
|
11
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
12
|
+
const { columns, pk } = await getMeta(table);
|
|
13
|
+
|
|
14
|
+
const names = columns?.map((el) => el.name);
|
|
15
|
+
const filterData = Object.keys(data)
|
|
16
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el)));
|
|
17
|
+
|
|
18
|
+
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
19
|
+
|
|
20
|
+
const updateQuery = `UPDATE ${table} SET ${filterData?.map((key, i) => (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`)).join(',')}
|
|
21
|
+
WHERE ${pk} = $1 returning *`;
|
|
22
|
+
// console.log(updateQuery, filterValue);
|
|
23
|
+
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
24
|
+
|
|
25
|
+
await logChanges({
|
|
26
|
+
pg, table, data, id, uid, type: 'UPDATE',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return res;
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "core-plugins",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
9
|
-
"test": "node --test"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@opengis/fastify-hb": "^1.1.0",
|
|
13
|
-
"@fastify/sensible": "^5.0.0",
|
|
14
|
-
"@fastify/url-data": "^5.4.0",
|
|
15
|
-
"fastify": "^4.26.1",
|
|
16
|
-
"fastify-plugin": "^4.0.0",
|
|
17
|
-
"ioredis": "^5.3.2",
|
|
18
|
-
"pg": "^8.11.3",
|
|
19
|
-
"nodemailer": "^6.5.0"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"eslint": "^8.49.0",
|
|
23
|
-
"eslint-config-airbnb": "^19.0.4"
|
|
24
|
-
},
|
|
25
|
-
"author": "Softpro",
|
|
26
|
-
"license": "ISC"
|
|
1
|
+
{
|
|
2
|
+
"name": "@opengis/fastify-table",
|
|
3
|
+
"version": "1.0.93",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "core-plugins",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
9
|
+
"test": "node --test"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@opengis/fastify-hb": "^1.1.0",
|
|
13
|
+
"@fastify/sensible": "^5.0.0",
|
|
14
|
+
"@fastify/url-data": "^5.4.0",
|
|
15
|
+
"fastify": "^4.26.1",
|
|
16
|
+
"fastify-plugin": "^4.0.0",
|
|
17
|
+
"ioredis": "^5.3.2",
|
|
18
|
+
"pg": "^8.11.3",
|
|
19
|
+
"nodemailer": "^6.5.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"eslint": "^8.49.0",
|
|
23
|
+
"eslint-config-airbnb": "^19.0.4"
|
|
24
|
+
},
|
|
25
|
+
"author": "Softpro",
|
|
26
|
+
"license": "ISC"
|
|
27
27
|
}
|
|
@@ -2,7 +2,7 @@ import getSelectMeta from './utils/getSelectMeta.js';
|
|
|
2
2
|
import getPG from '../../pg/funcs/getPG.js';
|
|
3
3
|
import config from '../../config.js';
|
|
4
4
|
import getTemplate from './utils/getTemplate.js';
|
|
5
|
-
import getTableSql from '../funcs/getFilterSQL/util/getTableSql.js';
|
|
5
|
+
// import getTableSql from '../funcs/getFilterSQL/util/getTableSql.js';
|
|
6
6
|
|
|
7
7
|
const limit = 50;
|
|
8
8
|
const headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Cache-Control': 'no-cache' };
|
|
@@ -22,7 +22,7 @@ export default async function suggest(req) {
|
|
|
22
22
|
if (table && !pg1.pk[body?.table || table]) {
|
|
23
23
|
return { headers, status: 400, message: 'param name is invalid: 1' };
|
|
24
24
|
}
|
|
25
|
-
const columnExists =
|
|
25
|
+
const columnExists = body?.columns?.find((col) => col?.name === column);
|
|
26
26
|
if (table && (!column || !columnExists)) {
|
|
27
27
|
return { headers, status: 400, message: 'param name is invalid: 2' };
|
|
28
28
|
}
|
|
@@ -32,7 +32,7 @@ export default async function suggest(req) {
|
|
|
32
32
|
original: `with c(id,text) as (select row_number() over(), ${column} from ${body?.table || table} group by ${column} ) select * from c`,
|
|
33
33
|
searchQuery: '("text" ilike $1 )',
|
|
34
34
|
}
|
|
35
|
-
: await getSelectMeta({ name: selectName });
|
|
35
|
+
: await getSelectMeta({ name: selectName, nocache: query?.nocache });
|
|
36
36
|
const pg = meta?.db ? getPG(meta.db) : pg1;
|
|
37
37
|
if (!meta) return { headers, status: 404, message: 'Not found query select ' };
|
|
38
38
|
if (query.meta) return meta;
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
// import pgClients from '../../../pg/pgClients.js';
|
|
2
|
-
import getPG from '../../../pg/funcs/getPG.js';
|
|
3
|
-
|
|
4
|
-
import getSelect from './getSelect.js';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
function getTable(table) {
|
|
8
|
-
// eslint-disable-next-line class-methods-use-this
|
|
9
|
-
const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
10
|
-
.map((el) => el.split(/[ )]/)[0]);
|
|
11
|
-
return result?.pop();
|
|
12
|
-
} */
|
|
13
|
-
|
|
14
|
-
const selectMeta = {};
|
|
15
|
-
|
|
16
|
-
export default async function getSelectMeta({ name, pg: pg1 }) {
|
|
17
|
-
if (selectMeta[name]) return selectMeta[name];
|
|
18
|
-
|
|
19
|
-
const cls = await getSelect(name);
|
|
20
|
-
|
|
21
|
-
if (!cls) return null;
|
|
22
|
-
if (cls.arr) return cls;
|
|
23
|
-
if (!cls.sql) return null;
|
|
24
|
-
|
|
25
|
-
const pg = pg1 || getPG({ db: cls.db || 'client' });
|
|
26
|
-
const { sql: original } = cls;
|
|
27
|
-
const sql = `with c(id,text) as (${original} ) select * from c `;
|
|
28
|
-
|
|
29
|
-
/*= == meta table === */
|
|
30
|
-
const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
31
|
-
.map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
|
|
32
|
-
|
|
33
|
-
const dataOrigin = await pg.query(`${sql} limit 0`);
|
|
34
|
-
|
|
35
|
-
const dataOrigin1 = await pg.query(`${original} limit 0`);
|
|
36
|
-
|
|
37
|
-
// const table = getTable(original);
|
|
38
|
-
const count = cls?.count ?? await pg.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
|
|
39
|
-
|
|
40
|
-
// column name
|
|
41
|
-
const cols = dataOrigin.fields.map((el) => el.name);
|
|
42
|
-
const type = dataOrigin.fields.map((el) => pg.pgType?.[el.dataTypeID] || 'text');
|
|
43
|
-
|
|
44
|
-
const searchColumn = cls?.searchColumn || (
|
|
45
|
-
dataOrigin.fields.find((el) => el.name === 'search') ? 'search' : dataOrigin.fields[1].name);
|
|
46
|
-
|
|
47
|
-
const searchQuery = `(${searchColumn.split(',').map((el) => `"${el}" ilike $1 `).join(' or ')})`;
|
|
48
|
-
|
|
49
|
-
const data = {
|
|
50
|
-
|
|
51
|
-
type: type.join(','),
|
|
52
|
-
cols: cols.join(','),
|
|
53
|
-
originalCols: dataOrigin1.fields.map((el) => el.name).join(','),
|
|
54
|
-
db: cls.db,
|
|
55
|
-
original: original?.includes('where') ? `select * from (${sql})q` : sql,
|
|
56
|
-
sql,
|
|
57
|
-
count,
|
|
58
|
-
searchQuery,
|
|
59
|
-
table: tableNew.join(','),
|
|
60
|
-
time: new Date().toISOString(),
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
selectMeta[name] = data;
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
1
|
+
// import pgClients from '../../../pg/pgClients.js';
|
|
2
|
+
import getPG from '../../../pg/funcs/getPG.js';
|
|
3
|
+
|
|
4
|
+
import getSelect from './getSelect.js';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
function getTable(table) {
|
|
8
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9
|
+
const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
10
|
+
.map((el) => el.split(/[ )]/)[0]);
|
|
11
|
+
return result?.pop();
|
|
12
|
+
} */
|
|
13
|
+
|
|
14
|
+
const selectMeta = {};
|
|
15
|
+
|
|
16
|
+
export default async function getSelectMeta({ name, pg: pg1, nocache }) {
|
|
17
|
+
if (selectMeta[name] && !nocache) return selectMeta[name];
|
|
18
|
+
|
|
19
|
+
const cls = await getSelect(name);
|
|
20
|
+
|
|
21
|
+
if (!cls) return null;
|
|
22
|
+
if (cls.arr) return cls;
|
|
23
|
+
if (!cls.sql) return null;
|
|
24
|
+
|
|
25
|
+
const pg = pg1 || getPG({ db: cls.db || 'client' });
|
|
26
|
+
const { sql: original } = cls;
|
|
27
|
+
const sql = `with c(id,text) as (${original} ) select * from c `;
|
|
28
|
+
|
|
29
|
+
/*= == meta table === */
|
|
30
|
+
const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
31
|
+
.map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
|
|
32
|
+
|
|
33
|
+
const dataOrigin = await pg.query(`${sql} limit 0`);
|
|
34
|
+
|
|
35
|
+
const dataOrigin1 = await pg.query(`${original} limit 0`);
|
|
36
|
+
|
|
37
|
+
// const table = getTable(original);
|
|
38
|
+
const count = cls?.count ?? await pg.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
|
|
39
|
+
|
|
40
|
+
// column name
|
|
41
|
+
const cols = dataOrigin.fields.map((el) => el.name);
|
|
42
|
+
const type = dataOrigin.fields.map((el) => pg.pgType?.[el.dataTypeID] || 'text');
|
|
43
|
+
|
|
44
|
+
const searchColumn = cls?.searchColumn || (
|
|
45
|
+
dataOrigin.fields.find((el) => el.name === 'search') ? 'search' : dataOrigin.fields[1].name);
|
|
46
|
+
|
|
47
|
+
const searchQuery = `(${searchColumn.split(',').map((el) => `"${el}" ilike $1 `).join(' or ')})`;
|
|
48
|
+
|
|
49
|
+
const data = {
|
|
50
|
+
|
|
51
|
+
type: type.join(','),
|
|
52
|
+
cols: cols.join(','),
|
|
53
|
+
originalCols: dataOrigin1.fields.map((el) => el.name).join(','),
|
|
54
|
+
db: cls.db,
|
|
55
|
+
original: original?.includes('where') ? `select * from (${sql})q` : sql,
|
|
56
|
+
sql,
|
|
57
|
+
count,
|
|
58
|
+
searchQuery,
|
|
59
|
+
table: tableNew.join(','),
|
|
60
|
+
time: new Date().toISOString(),
|
|
61
|
+
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
selectMeta[name] = data;
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import config from '../../../config.js';
|
|
5
|
-
|
|
6
|
-
const loadTemplate = {};
|
|
7
|
-
|
|
8
|
-
export default async function getTemplateDir(type, name) {
|
|
9
|
-
if (!type) return null;
|
|
10
|
-
if (!name) return null;
|
|
11
|
-
|
|
12
|
-
const cwd = process.cwd();
|
|
13
|
-
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
14
|
-
|
|
15
|
-
if (!loadTemplate[type]) {
|
|
16
|
-
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
17
|
-
loadTemplate[type] = typeList;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
|
|
21
|
-
const ext = fullname ? path.extname(fullname)?.slice(1) : null;
|
|
22
|
-
if (!ext) return null;
|
|
23
|
-
|
|
24
|
-
const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
|
|
25
|
-
const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
|
|
26
|
-
if (sql) return {
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import config from '../../../config.js';
|
|
5
|
+
|
|
6
|
+
const loadTemplate = {};
|
|
7
|
+
|
|
8
|
+
export default async function getTemplateDir(type, name) {
|
|
9
|
+
if (!type) return null;
|
|
10
|
+
if (!name) return null;
|
|
11
|
+
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
14
|
+
|
|
15
|
+
if (!loadTemplate[type]) {
|
|
16
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
17
|
+
loadTemplate[type] = typeList;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
|
|
21
|
+
const ext = fullname ? path.extname(fullname)?.slice(1) : null;
|
|
22
|
+
if (!ext) return null;
|
|
23
|
+
|
|
24
|
+
const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
|
|
25
|
+
const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
|
|
26
|
+
if (sql) return { sql };
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
@@ -18,8 +18,12 @@ async function getFilterSQL({
|
|
|
18
18
|
|
|
19
19
|
const body = await getTemplate('table', table);
|
|
20
20
|
|
|
21
|
+
const sqlList = body?.sql?.length
|
|
22
|
+
? body?.sql?.filter((el) => !el.disabled && el?.sql?.replace)
|
|
23
|
+
.map((el) => ` left join lateral (${el.filter ? el.sql.replace(/limit 1/ig, '') : el.sql}) as ${el.name} on 1=1 `).join(' ')
|
|
24
|
+
: '';
|
|
21
25
|
const fieldQuery = config.allTemplates?.table?.[table] ? `${config.allTemplates?.table?.[table]} limit 0`
|
|
22
|
-
: `select * from ${body?.table || table} limit 0`;
|
|
26
|
+
: `select * from ${body?.table || table} ${sqlList ? ` t ${sqlList}` : ''} where 1=1 limit 0`;
|
|
23
27
|
const { fields = [] } = await pg.query(fieldQuery);
|
|
24
28
|
|
|
25
29
|
const { fields: fieldsModel } = pg.pk[body?.table] ? await pg.query(`select * from ${body.table} limit 0`) : {};
|