@dokebi/module 0.4.0 → 0.4.2
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/AI.md +292 -7
- package/README.md +19 -2
- package/dist/action-api.d.ts +73 -0
- package/dist/action-api.js +249 -0
- package/dist/action.d.ts +152 -0
- package/dist/action.js +498 -0
- package/dist/contract.d.ts +305 -0
- package/dist/contract.js +524 -0
- package/dist/data-api.d.ts +49 -0
- package/dist/data-api.js +147 -0
- package/dist/data-source.d.ts +238 -0
- package/dist/data-source.js +742 -0
- package/dist/dependency.d.ts +3 -0
- package/dist/dependency.js +10 -0
- package/dist/index.d.ts +43 -3
- package/dist/index.js +208 -16
- package/dist/parts.d.ts +75 -0
- package/dist/parts.js +231 -0
- package/dist/preset.d.ts +25 -0
- package/dist/preset.js +165 -0
- package/package.json +15 -5
- package/templates/module/controllers/items.ts +14 -3
- package/templates/module/models/summary.ts +4 -4
- package/templates/module/module.ts +4 -0
- package/templates/module/services/items.ts +7 -0
- package/templates/module-api/controllers/items.ts +14 -3
- package/templates/module-api/models/summary.ts +4 -4
- package/templates/module-api/module.ts +4 -0
- package/templates/module-api/services/items.ts +7 -0
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
// Data sources (D-0199, F-03): a module declares a window on its data — the fields with their kind
|
|
2
|
+
// and label, the sorts it can page by (each the columns of an index), its search, filters,
|
|
3
|
+
// permission, scopes and row actions — and a reader. One general read answers every caller (a data
|
|
4
|
+
// grid, a screen, another program, an AI): only declared fields, sorts and filters, a page-size
|
|
5
|
+
// limit and a keyset cursor. What a scope may combine is declared too, so a combination that would
|
|
6
|
+
// read more than one page of rows is refused before it reaches the database.
|
|
7
|
+
import { createHash } from 'node:crypto';
|
|
8
|
+
import { types } from 'node:util';
|
|
9
|
+
/**
|
|
10
|
+
* The one list of field kinds a data source, a data grid, a form and an MCP tool share (the
|
|
11
|
+
* product's shared kinds: text, number, money, date, datetime, status, boolean, person, image, file,
|
|
12
|
+
* rich text, category, choice; plus id). A list returns a rich text as text (an excerpt): the whole
|
|
13
|
+
* document is a record's.
|
|
14
|
+
*/
|
|
15
|
+
export const FIELD_TYPES = [
|
|
16
|
+
'id',
|
|
17
|
+
'text',
|
|
18
|
+
'number',
|
|
19
|
+
'money',
|
|
20
|
+
'date',
|
|
21
|
+
'datetime',
|
|
22
|
+
'status',
|
|
23
|
+
'boolean',
|
|
24
|
+
'person',
|
|
25
|
+
'image',
|
|
26
|
+
'file',
|
|
27
|
+
'richtext',
|
|
28
|
+
'category',
|
|
29
|
+
'choice',
|
|
30
|
+
];
|
|
31
|
+
/** The colours a choice may be drawn in (the ui kit's status colours). */
|
|
32
|
+
export const CHOICE_TONES = [
|
|
33
|
+
'primary',
|
|
34
|
+
'secondary',
|
|
35
|
+
'success',
|
|
36
|
+
'warning',
|
|
37
|
+
'info',
|
|
38
|
+
'destructive',
|
|
39
|
+
];
|
|
40
|
+
/** Limits of one data source (D-0199). */
|
|
41
|
+
export const DATA_LIMITS = Object.freeze({
|
|
42
|
+
fields: 64,
|
|
43
|
+
sorts: 16,
|
|
44
|
+
sortColumns: 4,
|
|
45
|
+
filters: 32,
|
|
46
|
+
actions: 16,
|
|
47
|
+
scopes: 8,
|
|
48
|
+
choices: 64,
|
|
49
|
+
/** Values one choice filter may ask for. */
|
|
50
|
+
choiceValues: 32,
|
|
51
|
+
pageMax: 500,
|
|
52
|
+
pageDefault: 20,
|
|
53
|
+
/** Characters of one value in a query (a filter value, a search text). */
|
|
54
|
+
valueChars: 200,
|
|
55
|
+
cursorChars: 1024,
|
|
56
|
+
});
|
|
57
|
+
const NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
58
|
+
/** Kinds no index orders usefully. */
|
|
59
|
+
const UNSORTABLE = new Set(['boolean', 'image', 'file', 'richtext']);
|
|
60
|
+
/** Kinds a filter cannot compare. */
|
|
61
|
+
const UNFILTERABLE = new Set(['image', 'file', 'richtext']);
|
|
62
|
+
/** Kinds whose value, when the field declares choices, must be one of them. */
|
|
63
|
+
const CHOSEN = new Set(['status', 'choice', 'category']);
|
|
64
|
+
const DISPLAY = /^[a-z][a-z0-9-]{0,39}$/;
|
|
65
|
+
const CHOICE = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$/;
|
|
66
|
+
const PERMISSION = /^[a-z0-9][a-z0-9_-]*(?:\.[a-z0-9][a-z0-9_-]*)+$/;
|
|
67
|
+
const HREF = /^\/[A-Za-z0-9/_.~{}-]{0,255}$/;
|
|
68
|
+
/** Thrown for a declaration that breaks a rule (contract.ts makes it INVALID_CONTRACT). */
|
|
69
|
+
export class DataSourceIssue extends Error {
|
|
70
|
+
}
|
|
71
|
+
const plain = (value) => value !== null &&
|
|
72
|
+
typeof value === 'object' &&
|
|
73
|
+
!Array.isArray(value) &&
|
|
74
|
+
!types.isProxy(value) &&
|
|
75
|
+
[Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
76
|
+
function only(input, keys, where) {
|
|
77
|
+
const extra = Object.keys(input).find((name) => !keys.includes(name));
|
|
78
|
+
if (extra)
|
|
79
|
+
throw new DataSourceIssue(`${where} has an unknown field: ${extra}`);
|
|
80
|
+
}
|
|
81
|
+
function names(value, where, limit, known) {
|
|
82
|
+
if (value === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
if (!Array.isArray(value) ||
|
|
85
|
+
types.isProxy(value) ||
|
|
86
|
+
value.length === 0 ||
|
|
87
|
+
value.length > limit ||
|
|
88
|
+
value.some((item) => typeof item !== 'string' || !NAME.test(item)) ||
|
|
89
|
+
new Set(value).size !== value.length)
|
|
90
|
+
throw new DataSourceIssue(`${where} must be 1 to ${limit} distinct names`);
|
|
91
|
+
for (const item of value)
|
|
92
|
+
if (known && !known.has(item))
|
|
93
|
+
throw new DataSourceIssue(`${where}: ${item} is not declared`);
|
|
94
|
+
return Object.freeze([...value]);
|
|
95
|
+
}
|
|
96
|
+
function entries(value, where, limit, required) {
|
|
97
|
+
if (value === undefined) {
|
|
98
|
+
if (required)
|
|
99
|
+
throw new DataSourceIssue(`${where} is required`);
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
if (!plain(value))
|
|
103
|
+
throw new DataSourceIssue(`${where} must be an object`);
|
|
104
|
+
const list = Object.entries(value);
|
|
105
|
+
if ((required && list.length === 0) || list.length > limit)
|
|
106
|
+
throw new DataSourceIssue(`${where} must have ${required ? 1 : 0} to ${limit} entries`);
|
|
107
|
+
return list.map(([name, item]) => {
|
|
108
|
+
if (!NAME.test(name))
|
|
109
|
+
throw new DataSourceIssue(`${where} has an invalid name: ${name}`);
|
|
110
|
+
if (!plain(item))
|
|
111
|
+
throw new DataSourceIssue(`${where}.${name} must be an object`);
|
|
112
|
+
return [name, item];
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks the D-0199 part of a data source declaration (`title` and `description` are checked by
|
|
117
|
+
* the caller). A declaration with only a title (D-0197) stays valid: it names a data source to
|
|
118
|
+
* come, and reading it answers DATA_SOURCE_FAILED until it has fields, sorts and a reader.
|
|
119
|
+
*/
|
|
120
|
+
export function readDataSource(input, where, label, permissionOf) {
|
|
121
|
+
only(input, [
|
|
122
|
+
'title',
|
|
123
|
+
'description',
|
|
124
|
+
'fields',
|
|
125
|
+
'sorts',
|
|
126
|
+
'search',
|
|
127
|
+
'filters',
|
|
128
|
+
'actions',
|
|
129
|
+
'permission',
|
|
130
|
+
'public',
|
|
131
|
+
'scopes',
|
|
132
|
+
'scope',
|
|
133
|
+
'limit',
|
|
134
|
+
'read',
|
|
135
|
+
], where);
|
|
136
|
+
const declared = input.fields !== undefined || input.sorts !== undefined || input.read !== undefined;
|
|
137
|
+
if (!declared) {
|
|
138
|
+
for (const key of [
|
|
139
|
+
'search',
|
|
140
|
+
'filters',
|
|
141
|
+
'actions',
|
|
142
|
+
'permission',
|
|
143
|
+
'public',
|
|
144
|
+
'scopes',
|
|
145
|
+
'scope',
|
|
146
|
+
'limit',
|
|
147
|
+
])
|
|
148
|
+
if (input[key] !== undefined)
|
|
149
|
+
throw new DataSourceIssue(`${where}.${key} needs fields, sorts and read`);
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
if (typeof input.read !== 'function')
|
|
153
|
+
throw new DataSourceIssue(`${where}.read must be a function`);
|
|
154
|
+
const fields = {};
|
|
155
|
+
for (const [name, item] of entries(input.fields, `${where}.fields`, DATA_LIMITS.fields, true)) {
|
|
156
|
+
const at = `${where}.fields.${name}`;
|
|
157
|
+
only(item, ['type', 'label', 'display', 'choices', 'hidden', 'unique'], at);
|
|
158
|
+
if (!FIELD_TYPES.includes(item.type))
|
|
159
|
+
throw new DataSourceIssue(`${at}.type must be one of ${FIELD_TYPES.join(', ')}`);
|
|
160
|
+
if (item.display !== undefined &&
|
|
161
|
+
(typeof item.display !== 'string' || !DISPLAY.test(item.display)))
|
|
162
|
+
throw new DataSourceIssue(`${at}.display must be a lower-case name`);
|
|
163
|
+
for (const flag of ['hidden', 'unique'])
|
|
164
|
+
if (item[flag] !== undefined && typeof item[flag] !== 'boolean')
|
|
165
|
+
throw new DataSourceIssue(`${at}.${flag} must be true or false`);
|
|
166
|
+
let choices;
|
|
167
|
+
if (item.choices !== undefined) {
|
|
168
|
+
if (!plain(item.choices))
|
|
169
|
+
throw new DataSourceIssue(`${at}.choices must be an object`);
|
|
170
|
+
const list = Object.entries(item.choices);
|
|
171
|
+
if (list.length === 0 || list.length > DATA_LIMITS.choices)
|
|
172
|
+
throw new DataSourceIssue(`${at}.choices must have 1 to ${DATA_LIMITS.choices} entries`);
|
|
173
|
+
choices = {};
|
|
174
|
+
for (const [value, choice] of list) {
|
|
175
|
+
if (!CHOICE.test(value))
|
|
176
|
+
throw new DataSourceIssue(`${at}.choices has an invalid value: ${value}`);
|
|
177
|
+
if (!plain(choice))
|
|
178
|
+
throw new DataSourceIssue(`${at}.choices.${value} must be { label }`);
|
|
179
|
+
only(choice, ['label', 'tone'], `${at}.choices.${value}`);
|
|
180
|
+
if (choice.tone !== undefined && !CHOICE_TONES.includes(choice.tone))
|
|
181
|
+
throw new DataSourceIssue(`${at}.choices.${value}.tone must be one of ${CHOICE_TONES.join(', ')}`);
|
|
182
|
+
choices[value] = Object.freeze({
|
|
183
|
+
label: label(choice.label, `${at}.choices.${value}.label`),
|
|
184
|
+
...(choice.tone === undefined ? {} : { tone: choice.tone }),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
fields[name] = Object.freeze({
|
|
189
|
+
type: item.type,
|
|
190
|
+
label: label(item.label, `${at}.label`),
|
|
191
|
+
...(item.display === undefined ? {} : { display: item.display }),
|
|
192
|
+
...(choices === undefined ? {} : { choices: Object.freeze(choices) }),
|
|
193
|
+
...(item.hidden ? { hidden: true } : {}),
|
|
194
|
+
...(item.unique || item.type === 'id' ? { unique: true } : {}),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const fieldNames = new Set(Object.keys(fields));
|
|
198
|
+
const scopes = names(input.scopes, `${where}.scopes`, DATA_LIMITS.scopes);
|
|
199
|
+
if ((scopes === undefined) !== (input.scope === undefined))
|
|
200
|
+
throw new DataSourceIssue(`${where}: scopes and scope go together (the names and the function)`);
|
|
201
|
+
if (input.scope !== undefined && typeof input.scope !== 'function')
|
|
202
|
+
throw new DataSourceIssue(`${where}.scope must be a function`);
|
|
203
|
+
const scopeSet = new Set(scopes ?? []);
|
|
204
|
+
const scopesOf = (value, at) => {
|
|
205
|
+
if (value === undefined)
|
|
206
|
+
return undefined;
|
|
207
|
+
if (!scopes)
|
|
208
|
+
throw new DataSourceIssue(`${at} names scopes, but the data source declares none`);
|
|
209
|
+
return names(value, at, DATA_LIMITS.scopes, scopeSet);
|
|
210
|
+
};
|
|
211
|
+
const sorts = {};
|
|
212
|
+
for (const [name, item] of entries(input.sorts, `${where}.sorts`, DATA_LIMITS.sorts, true)) {
|
|
213
|
+
const at = `${where}.sorts.${name}`;
|
|
214
|
+
only(item, ['label', 'by', 'scopes'], at);
|
|
215
|
+
const by = item.by;
|
|
216
|
+
if (!Array.isArray(by) || by.length === 0 || by.length > DATA_LIMITS.sortColumns)
|
|
217
|
+
throw new DataSourceIssue(`${at}.by must be 1 to ${DATA_LIMITS.sortColumns} [field, direction] pairs`);
|
|
218
|
+
const pairs = by.map((pair, index) => {
|
|
219
|
+
if (!Array.isArray(pair) ||
|
|
220
|
+
pair.length !== 2 ||
|
|
221
|
+
typeof pair[0] !== 'string' ||
|
|
222
|
+
!fieldNames.has(pair[0]) ||
|
|
223
|
+
(pair[1] !== 'asc' && pair[1] !== 'desc'))
|
|
224
|
+
throw new DataSourceIssue(`${at}.by[${index}] must be [a declared field, 'asc' or 'desc']`);
|
|
225
|
+
const type = fields[pair[0]]?.type;
|
|
226
|
+
if (type !== undefined && UNSORTABLE.has(type))
|
|
227
|
+
throw new DataSourceIssue(`${at}.by[${index}]: a ${type} field cannot be sorted by`);
|
|
228
|
+
return Object.freeze([pair[0], pair[1]]);
|
|
229
|
+
});
|
|
230
|
+
if (new Set(pairs.map((pair) => pair[0])).size !== pairs.length)
|
|
231
|
+
throw new DataSourceIssue(`${at}.by names a field twice`);
|
|
232
|
+
const last = pairs.at(-1)?.[0] ?? '';
|
|
233
|
+
if (!fields[last]?.unique)
|
|
234
|
+
throw new DataSourceIssue(`${at}.by must end with a unique field (an id, or one marked unique): the cursor needs it`);
|
|
235
|
+
sorts[name] = Object.freeze({
|
|
236
|
+
label: label(item.label, `${at}.label`),
|
|
237
|
+
by: Object.freeze(pairs),
|
|
238
|
+
...(item.scopes === undefined
|
|
239
|
+
? {}
|
|
240
|
+
: { scopes: scopesOf(item.scopes, `${at}.scopes`) }),
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
const sortNames = new Set(Object.keys(sorts));
|
|
244
|
+
if (scopes)
|
|
245
|
+
for (const scope of scopes)
|
|
246
|
+
if (!Object.values(sorts).some((sort) => !sort.scopes || sort.scopes.includes(scope)))
|
|
247
|
+
throw new DataSourceIssue(`${where}: scope ${scope} has no sort`);
|
|
248
|
+
let search;
|
|
249
|
+
if (input.search !== undefined) {
|
|
250
|
+
const at = `${where}.search`;
|
|
251
|
+
const item = input.search;
|
|
252
|
+
if (!plain(item))
|
|
253
|
+
throw new DataSourceIssue(`${at} must be an object`);
|
|
254
|
+
only(item, ['label', 'fields', 'minLength', 'maxLength', 'sorts', 'scopes'], at);
|
|
255
|
+
const searched = names(item.fields, `${at}.fields`, 8, fieldNames);
|
|
256
|
+
if (!searched)
|
|
257
|
+
throw new DataSourceIssue(`${at}.fields is required`);
|
|
258
|
+
for (const field of searched)
|
|
259
|
+
if (fields[field]?.hidden)
|
|
260
|
+
throw new DataSourceIssue(`${at}.fields: ${field} is hidden`);
|
|
261
|
+
const min = item.minLength ?? 1;
|
|
262
|
+
const max = item.maxLength ?? 100;
|
|
263
|
+
if (!Number.isInteger(min) ||
|
|
264
|
+
!Number.isInteger(max) ||
|
|
265
|
+
min < 1 ||
|
|
266
|
+
max > DATA_LIMITS.valueChars ||
|
|
267
|
+
min > max)
|
|
268
|
+
throw new DataSourceIssue(`${at}: minLength and maxLength must be 1 to ${DATA_LIMITS.valueChars}`);
|
|
269
|
+
search = Object.freeze({
|
|
270
|
+
label: label(item.label, `${at}.label`),
|
|
271
|
+
fields: searched,
|
|
272
|
+
minLength: min,
|
|
273
|
+
maxLength: max,
|
|
274
|
+
...(item.sorts === undefined
|
|
275
|
+
? {}
|
|
276
|
+
: {
|
|
277
|
+
sorts: names(item.sorts, `${at}.sorts`, DATA_LIMITS.sorts, sortNames),
|
|
278
|
+
}),
|
|
279
|
+
...(item.scopes === undefined
|
|
280
|
+
? {}
|
|
281
|
+
: { scopes: scopesOf(item.scopes, `${at}.scopes`) }),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const filters = {};
|
|
285
|
+
for (const [name, item] of entries(input.filters, `${where}.filters`, DATA_LIMITS.filters, false)) {
|
|
286
|
+
const at = `${where}.filters.${name}`;
|
|
287
|
+
only(item, ['label', 'field', 'kind', 'multiple', 'sorts', 'scopes'], at);
|
|
288
|
+
if (item.multiple !== undefined &&
|
|
289
|
+
(typeof item.multiple !== 'boolean' || item.kind !== 'choice'))
|
|
290
|
+
throw new DataSourceIssue(`${at}.multiple is true or false, on a choice filter`);
|
|
291
|
+
if (typeof item.field !== 'string' || !fieldNames.has(item.field))
|
|
292
|
+
throw new DataSourceIssue(`${at}.field must be a declared field`);
|
|
293
|
+
const field = fields[item.field];
|
|
294
|
+
if (item.kind !== 'choice' && item.kind !== 'equal' && item.kind !== 'range')
|
|
295
|
+
throw new DataSourceIssue(`${at}.kind must be choice, equal or range`);
|
|
296
|
+
if (item.kind === 'choice' && !field.choices)
|
|
297
|
+
throw new DataSourceIssue(`${at}: a choice filter needs a field with choices`);
|
|
298
|
+
if (item.kind === 'range' && !['number', 'money', 'date', 'datetime'].includes(field.type))
|
|
299
|
+
throw new DataSourceIssue(`${at}: a range filter needs a number, money, date or datetime field`);
|
|
300
|
+
if (UNFILTERABLE.has(field.type))
|
|
301
|
+
throw new DataSourceIssue(`${at}: a ${field.type} field cannot be filtered`);
|
|
302
|
+
filters[name] = Object.freeze({
|
|
303
|
+
label: label(item.label, `${at}.label`),
|
|
304
|
+
field: item.field,
|
|
305
|
+
kind: item.kind,
|
|
306
|
+
...(item.multiple ? { multiple: true } : {}),
|
|
307
|
+
...(item.sorts === undefined
|
|
308
|
+
? {}
|
|
309
|
+
: {
|
|
310
|
+
sorts: names(item.sorts, `${at}.sorts`, DATA_LIMITS.sorts, sortNames),
|
|
311
|
+
}),
|
|
312
|
+
...(item.scopes === undefined
|
|
313
|
+
? {}
|
|
314
|
+
: { scopes: scopesOf(item.scopes, `${at}.scopes`) }),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const actions = {};
|
|
318
|
+
for (const [name, item] of entries(input.actions, `${where}.actions`, DATA_LIMITS.actions, false)) {
|
|
319
|
+
const at = `${where}.actions.${name}`;
|
|
320
|
+
only(item, ['label', 'href', 'action', 'permission'], at);
|
|
321
|
+
if ((item.href === undefined) === (item.action === undefined))
|
|
322
|
+
throw new DataSourceIssue(`${at} needs href or action (one of them)`);
|
|
323
|
+
if (item.href !== undefined) {
|
|
324
|
+
if (typeof item.href !== 'string' ||
|
|
325
|
+
!HREF.test(item.href) ||
|
|
326
|
+
item.href.split('/').includes('..'))
|
|
327
|
+
throw new DataSourceIssue(`${at}.href must be a path such as /members/{id}`);
|
|
328
|
+
for (const [, place] of item.href.matchAll(/\{([^}]*)\}/g))
|
|
329
|
+
if (!place || !fieldNames.has(place) || fields[place]?.hidden)
|
|
330
|
+
throw new DataSourceIssue(`${at}.href: {${place}} is not a declared field`);
|
|
331
|
+
}
|
|
332
|
+
if (item.action !== undefined &&
|
|
333
|
+
(typeof item.action !== 'string' ||
|
|
334
|
+
item.action.length > 128 ||
|
|
335
|
+
!(NAME.test(item.action) || PERMISSION.test(item.action))))
|
|
336
|
+
throw new DataSourceIssue(`${at}.action must be a name, or <module>.<name>`);
|
|
337
|
+
if (item.permission !== undefined) {
|
|
338
|
+
if (typeof item.permission !== 'string' || !PERMISSION.test(item.permission))
|
|
339
|
+
throw new DataSourceIssue(`${at}.permission must be a permission key`);
|
|
340
|
+
permissionOf(item.permission, `${at}.permission`);
|
|
341
|
+
}
|
|
342
|
+
actions[name] = Object.freeze({
|
|
343
|
+
label: label(item.label, `${at}.label`),
|
|
344
|
+
...(item.href === undefined ? {} : { href: item.href }),
|
|
345
|
+
...(item.action === undefined ? {} : { action: item.action }),
|
|
346
|
+
...(item.permission === undefined ? {} : { permission: item.permission }),
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (input.permission !== undefined) {
|
|
350
|
+
if (typeof input.permission !== 'string' || !PERMISSION.test(input.permission))
|
|
351
|
+
throw new DataSourceIssue(`${where}.permission must be a permission key`);
|
|
352
|
+
permissionOf(input.permission, `${where}.permission`);
|
|
353
|
+
}
|
|
354
|
+
if (input.public !== undefined && input.public !== true)
|
|
355
|
+
throw new DataSourceIssue(`${where}.public is true or left out`);
|
|
356
|
+
if ((input.permission === undefined) === (input.public === undefined))
|
|
357
|
+
throw new DataSourceIssue(`${where} needs permission (a permission key) or public: true, one of them: a data source is never open by accident`);
|
|
358
|
+
let limit = { default: DATA_LIMITS.pageDefault, max: 100 };
|
|
359
|
+
if (input.limit !== undefined) {
|
|
360
|
+
const item = input.limit;
|
|
361
|
+
if (!plain(item))
|
|
362
|
+
throw new DataSourceIssue(`${where}.limit must be { default, max }`);
|
|
363
|
+
only(item, ['default', 'max'], `${where}.limit`);
|
|
364
|
+
const max = item.max ?? 100;
|
|
365
|
+
const first = item.default ?? Math.min(DATA_LIMITS.pageDefault, max);
|
|
366
|
+
if (!Number.isInteger(max) ||
|
|
367
|
+
!Number.isInteger(first) ||
|
|
368
|
+
max < 1 ||
|
|
369
|
+
max > DATA_LIMITS.pageMax ||
|
|
370
|
+
first < 1 ||
|
|
371
|
+
first > max)
|
|
372
|
+
throw new DataSourceIssue(`${where}.limit: 1 <= default <= max <= ${DATA_LIMITS.pageMax}`);
|
|
373
|
+
limit = { default: first, max: max };
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
fields: Object.freeze(fields),
|
|
377
|
+
sorts: Object.freeze(sorts),
|
|
378
|
+
...(search === undefined ? {} : { search }),
|
|
379
|
+
filters: Object.freeze(filters),
|
|
380
|
+
actions: Object.freeze(actions),
|
|
381
|
+
...(input.permission === undefined ? {} : { permission: input.permission }),
|
|
382
|
+
...(input.public === true ? { public: true } : {}),
|
|
383
|
+
...(scopes === undefined ? {} : { scopes }),
|
|
384
|
+
...(input.scope === undefined
|
|
385
|
+
? {}
|
|
386
|
+
: { scope: input.scope }),
|
|
387
|
+
limit: Object.freeze(limit),
|
|
388
|
+
read: input.read,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
const refuse = (reason, message, name) => ({
|
|
392
|
+
code: 'INVALID_QUERY',
|
|
393
|
+
reason,
|
|
394
|
+
message,
|
|
395
|
+
...(name === undefined ? {} : { name }),
|
|
396
|
+
});
|
|
397
|
+
const badCursor = (message) => ({
|
|
398
|
+
code: 'INVALID_CURSOR',
|
|
399
|
+
reason: 'cursor',
|
|
400
|
+
message,
|
|
401
|
+
});
|
|
402
|
+
const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
403
|
+
const DATETIME = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}(?::?\d{2})?)?$/;
|
|
404
|
+
const DECIMAL = /^-?\d{1,30}(?:\.\d{1,12})?$/;
|
|
405
|
+
const realDate = (text) => {
|
|
406
|
+
const match = DATE.exec(text.slice(0, 10));
|
|
407
|
+
if (!match)
|
|
408
|
+
return false;
|
|
409
|
+
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
410
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
411
|
+
return (date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day);
|
|
412
|
+
};
|
|
413
|
+
/** A value of `field` read from the query (text) — or undefined when it does not fit the kind. */
|
|
414
|
+
export function parseValue(field, text) {
|
|
415
|
+
if (text.length === 0 || text.length > DATA_LIMITS.valueChars)
|
|
416
|
+
return undefined;
|
|
417
|
+
switch (field.type) {
|
|
418
|
+
case 'number': {
|
|
419
|
+
if (!/^-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?$/.test(text))
|
|
420
|
+
return undefined;
|
|
421
|
+
const value = Number(text);
|
|
422
|
+
return Number.isFinite(value) ? value : undefined;
|
|
423
|
+
}
|
|
424
|
+
case 'money':
|
|
425
|
+
return DECIMAL.test(text) ? text : undefined;
|
|
426
|
+
case 'date':
|
|
427
|
+
return DATE.test(text) && realDate(text) ? text : undefined;
|
|
428
|
+
case 'datetime': {
|
|
429
|
+
if (!DATETIME.test(text) || !realDate(text))
|
|
430
|
+
return undefined;
|
|
431
|
+
// PostgreSQL writes `+00` (hours only), which Date.parse does not read: complete it.
|
|
432
|
+
const iso = text.replace(' ', 'T').replace(/([+-]\d{2})$/, '$1:00');
|
|
433
|
+
return Number.isNaN(Date.parse(iso)) ? undefined : text;
|
|
434
|
+
}
|
|
435
|
+
case 'boolean':
|
|
436
|
+
return text === 'true' ? true : text === 'false' ? false : undefined;
|
|
437
|
+
default:
|
|
438
|
+
if (field.choices && CHOSEN.has(field.type))
|
|
439
|
+
return Object.hasOwn(field.choices, text) ? text : undefined;
|
|
440
|
+
return text;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/** Whether a value a reader returned (a sort key for the cursor) fits the field's kind. */
|
|
444
|
+
function keyFits(field, value) {
|
|
445
|
+
if (field.type === 'number')
|
|
446
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
447
|
+
if (field.type === 'id')
|
|
448
|
+
return (typeof value === 'string' && value.length <= 256) || Number.isSafeInteger(value);
|
|
449
|
+
return typeof value === 'string' && parseValue(field, value) !== undefined;
|
|
450
|
+
}
|
|
451
|
+
const one = (value, name) => {
|
|
452
|
+
if (typeof value === 'string')
|
|
453
|
+
return value;
|
|
454
|
+
return refuse('parameter', `${name} must be given once, as text`, name);
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Checks a query (`fields`, `sort`, `limit`, `cursor`, `q`, `filter.<name>`, `filter.<name>.from`,
|
|
458
|
+
* `filter.<name>.to`) against a data source for a caller in `scope`. Anything not declared, not
|
|
459
|
+
* offered to the scope or not combinable with the sort is a problem, never ignored.
|
|
460
|
+
*/
|
|
461
|
+
export function checkQuery(source, query, scope) {
|
|
462
|
+
const fields = source.fields;
|
|
463
|
+
const offered = (scopes) => !scopes || scope === null || scopes.includes(scope);
|
|
464
|
+
const filterInputs = new Map();
|
|
465
|
+
for (const [key, value] of Object.entries(query)) {
|
|
466
|
+
if (['fields', 'sort', 'limit', 'cursor', 'q'].includes(key))
|
|
467
|
+
continue;
|
|
468
|
+
const match = /^filter\.([a-z][a-z0-9_]{0,63})(?:\.(from|to))?$/.exec(key);
|
|
469
|
+
if (!match)
|
|
470
|
+
return refuse('parameter', `Unknown parameter ${key}`, key);
|
|
471
|
+
const name = match[1];
|
|
472
|
+
const input = filterInputs.get(name) ?? {};
|
|
473
|
+
input[match[2] ?? 'value'] = value;
|
|
474
|
+
filterInputs.set(name, input);
|
|
475
|
+
}
|
|
476
|
+
if (query.fields === undefined)
|
|
477
|
+
return refuse('fields', 'fields is required: the fields to return, comma-separated');
|
|
478
|
+
const fieldText = one(query.fields, 'fields');
|
|
479
|
+
if (typeof fieldText !== 'string')
|
|
480
|
+
return fieldText;
|
|
481
|
+
const chosen = fieldText.split(',').map((name) => name.trim());
|
|
482
|
+
if (chosen.length === 0 ||
|
|
483
|
+
chosen.length > DATA_LIMITS.fields ||
|
|
484
|
+
new Set(chosen).size !== chosen.length)
|
|
485
|
+
return refuse('fields', 'fields must name distinct fields');
|
|
486
|
+
for (const name of chosen)
|
|
487
|
+
if (!Object.hasOwn(fields, name) || fields[name]?.hidden)
|
|
488
|
+
return refuse('field', `The data source has no field ${name}`, name);
|
|
489
|
+
const sortNames = Object.keys(source.sorts).filter((name) => offered(source.sorts[name]?.scopes));
|
|
490
|
+
let sortName = sortNames[0];
|
|
491
|
+
if (query.sort !== undefined) {
|
|
492
|
+
const text = one(query.sort, 'sort');
|
|
493
|
+
if (typeof text !== 'string')
|
|
494
|
+
return text;
|
|
495
|
+
if (!Object.hasOwn(source.sorts, text))
|
|
496
|
+
return refuse('sort', `The data source has no sort ${text}`, text);
|
|
497
|
+
if (!sortNames.includes(text))
|
|
498
|
+
return refuse('sort', `The sort ${text} is not offered to this caller`, text);
|
|
499
|
+
sortName = text;
|
|
500
|
+
}
|
|
501
|
+
const sort = source.sorts[sortName];
|
|
502
|
+
let pageSize = source.limit.default;
|
|
503
|
+
if (query.limit !== undefined) {
|
|
504
|
+
const text = one(query.limit, 'limit');
|
|
505
|
+
if (typeof text !== 'string')
|
|
506
|
+
return text;
|
|
507
|
+
if (!/^\d{1,4}$/.test(text) || Number(text) < 1 || Number(text) > source.limit.max)
|
|
508
|
+
return refuse('limit', `limit must be a whole number from 1 to ${source.limit.max}`, 'limit');
|
|
509
|
+
pageSize = Number(text);
|
|
510
|
+
}
|
|
511
|
+
let search = null;
|
|
512
|
+
if (query.q !== undefined) {
|
|
513
|
+
const text = one(query.q, 'q');
|
|
514
|
+
if (typeof text !== 'string')
|
|
515
|
+
return text;
|
|
516
|
+
const found = source.search;
|
|
517
|
+
if (!found)
|
|
518
|
+
return refuse('search', 'The data source has no search', 'q');
|
|
519
|
+
if (!offered(found.scopes))
|
|
520
|
+
return refuse('search', 'Search is not offered to this caller', 'q');
|
|
521
|
+
if (found.sorts && !found.sorts.includes(sortName))
|
|
522
|
+
return refuse('combination', `Search goes with the sorts ${found.sorts.join(', ')}`, sortName);
|
|
523
|
+
const trimmed = text.trim();
|
|
524
|
+
if (trimmed.length < (found.minLength ?? 1) || trimmed.length > (found.maxLength ?? 100))
|
|
525
|
+
return refuse('search', `q must be ${found.minLength ?? 1} to ${found.maxLength ?? 100} characters`, 'q');
|
|
526
|
+
search = Object.freeze({ text: trimmed, fields: found.fields });
|
|
527
|
+
}
|
|
528
|
+
const filters = [];
|
|
529
|
+
for (const [name, input] of [...filterInputs].sort(([a], [b]) => (a < b ? -1 : 1))) {
|
|
530
|
+
// An own entry only: `filter.constructor` names Object's constructor, not a filter (D-0199 review).
|
|
531
|
+
const filter = Object.hasOwn(source.filters, name) ? source.filters[name] : undefined;
|
|
532
|
+
if (!filter)
|
|
533
|
+
return refuse('filter', `The data source has no filter ${name}`, name);
|
|
534
|
+
if (!offered(filter.scopes))
|
|
535
|
+
return refuse('filter', `The filter ${name} is not offered to this caller`, name);
|
|
536
|
+
if (filter.sorts && !filter.sorts.includes(sortName))
|
|
537
|
+
return refuse('combination', `The filter ${name} goes with the sorts ${filter.sorts.join(', ')}`, name);
|
|
538
|
+
const field = fields[filter.field];
|
|
539
|
+
if (filter.kind === 'range') {
|
|
540
|
+
if (input.value !== undefined)
|
|
541
|
+
return refuse('filter', `The filter ${name} takes filter.${name}.from and/or .to`, name);
|
|
542
|
+
const bound = (value, side) => {
|
|
543
|
+
if (value === undefined)
|
|
544
|
+
return null;
|
|
545
|
+
const text = one(value, `filter.${name}.${side}`);
|
|
546
|
+
if (typeof text !== 'string')
|
|
547
|
+
return text;
|
|
548
|
+
const parsed = parseValue(field, text);
|
|
549
|
+
return parsed === undefined
|
|
550
|
+
? refuse('value', `filter.${name}.${side} is not a ${field.type}`, name)
|
|
551
|
+
: parsed;
|
|
552
|
+
};
|
|
553
|
+
const from = bound(input.from, 'from');
|
|
554
|
+
if (from !== null && typeof from === 'object')
|
|
555
|
+
return from;
|
|
556
|
+
const to = bound(input.to, 'to');
|
|
557
|
+
if (to !== null && typeof to === 'object')
|
|
558
|
+
return to;
|
|
559
|
+
if (from === null && to === null)
|
|
560
|
+
return refuse('filter', `The filter ${name} needs from or to`, name);
|
|
561
|
+
filters.push(Object.freeze({ name, field: filter.field, kind: 'range', from, to }));
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (input.from !== undefined || input.to !== undefined)
|
|
565
|
+
return refuse('filter', `The filter ${name} takes one filter.${name}`, name);
|
|
566
|
+
const text = one(input.value, `filter.${name}`);
|
|
567
|
+
if (typeof text !== 'string')
|
|
568
|
+
return text;
|
|
569
|
+
if (filter.kind === 'equal') {
|
|
570
|
+
const value = parseValue(field, text);
|
|
571
|
+
if (value === undefined)
|
|
572
|
+
return refuse('value', `filter.${name} is not a ${field.type}`, name);
|
|
573
|
+
filters.push(Object.freeze({ name, field: filter.field, kind: 'equal', value }));
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const values = text.split(',');
|
|
577
|
+
if (values.length > 1 && !filter.multiple)
|
|
578
|
+
return refuse('value', `filter.${name} takes one value`, name);
|
|
579
|
+
if (values.length > DATA_LIMITS.choiceValues || new Set(values).size !== values.length)
|
|
580
|
+
return refuse('value', `filter.${name} takes 1 to ${DATA_LIMITS.choiceValues} distinct values`, name);
|
|
581
|
+
for (const value of values)
|
|
582
|
+
if (!field.choices || !Object.hasOwn(field.choices, value))
|
|
583
|
+
return refuse('value', `filter.${name}: ${value} is not one of its choices`, name);
|
|
584
|
+
filters.push(Object.freeze({ name, field: filter.field, kind: 'choice', values: Object.freeze(values) }));
|
|
585
|
+
}
|
|
586
|
+
const by = sort.by.map(([field, direction]) => Object.freeze({ field, direction }));
|
|
587
|
+
const fingerprint = createHash('sha256')
|
|
588
|
+
.update(JSON.stringify([sortName, filters, search?.text ?? null, scope]))
|
|
589
|
+
.digest('base64url')
|
|
590
|
+
.slice(0, 16);
|
|
591
|
+
let after = null;
|
|
592
|
+
if (query.cursor !== undefined) {
|
|
593
|
+
const text = one(query.cursor, 'cursor');
|
|
594
|
+
if (typeof text !== 'string')
|
|
595
|
+
return badCursor('cursor must be given once');
|
|
596
|
+
const decoded = decodeCursor(text);
|
|
597
|
+
if (!decoded)
|
|
598
|
+
return badCursor('The cursor is not one this data source gave');
|
|
599
|
+
if (decoded.sort !== sortName || decoded.fingerprint !== fingerprint)
|
|
600
|
+
return badCursor('The cursor belongs to another sort, filter, search or scope: start from the first page');
|
|
601
|
+
if (decoded.values.length !== by.length)
|
|
602
|
+
return badCursor('The cursor does not fit the sort');
|
|
603
|
+
for (const [index, value] of decoded.values.entries())
|
|
604
|
+
if (!keyFits(fields[by[index]?.field ?? ''], value))
|
|
605
|
+
return badCursor('The cursor does not fit the sort');
|
|
606
|
+
after = decoded.values;
|
|
607
|
+
}
|
|
608
|
+
const select = [...new Set([...chosen, ...by.map((item) => item.field)])];
|
|
609
|
+
return {
|
|
610
|
+
fields: Object.freeze(chosen),
|
|
611
|
+
select: Object.freeze(select),
|
|
612
|
+
sort: Object.freeze({ name: sortName, by: Object.freeze(by) }),
|
|
613
|
+
after: after && Object.freeze(after),
|
|
614
|
+
filters: Object.freeze(filters),
|
|
615
|
+
search,
|
|
616
|
+
pageSize,
|
|
617
|
+
fingerprint,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
/** The cursor: `[1, sort, fingerprint, values]` as base64url JSON (opaque to callers). */
|
|
621
|
+
export function encodeCursor(sort, fingerprint, values) {
|
|
622
|
+
return Buffer.from(JSON.stringify([1, sort, fingerprint, values])).toString('base64url');
|
|
623
|
+
}
|
|
624
|
+
export function decodeCursor(text) {
|
|
625
|
+
if (text.length === 0 || text.length > DATA_LIMITS.cursorChars || !/^[A-Za-z0-9_-]+$/.test(text))
|
|
626
|
+
return undefined;
|
|
627
|
+
let value;
|
|
628
|
+
try {
|
|
629
|
+
value = JSON.parse(Buffer.from(text, 'base64url').toString('utf8'));
|
|
630
|
+
}
|
|
631
|
+
catch (error) {
|
|
632
|
+
// Not JSON: a cursor nobody gave. The caller answers INVALID_CURSOR (400); nothing to log.
|
|
633
|
+
if (error instanceof SyntaxError)
|
|
634
|
+
return undefined;
|
|
635
|
+
throw error;
|
|
636
|
+
}
|
|
637
|
+
if (!Array.isArray(value) ||
|
|
638
|
+
value.length !== 4 ||
|
|
639
|
+
value[0] !== 1 ||
|
|
640
|
+
typeof value[1] !== 'string' ||
|
|
641
|
+
typeof value[2] !== 'string' ||
|
|
642
|
+
!Array.isArray(value[3]))
|
|
643
|
+
return undefined;
|
|
644
|
+
return { sort: value[1], fingerprint: value[2], values: value[3] };
|
|
645
|
+
}
|
|
646
|
+
/** Why a reader's answer breaks the rules (DATA_SOURCE_FAILED), or undefined. */
|
|
647
|
+
export function rowProblem(rows, checked, fields, limit) {
|
|
648
|
+
if (!Array.isArray(rows))
|
|
649
|
+
return 'read must return an array of rows';
|
|
650
|
+
if (rows.length > limit)
|
|
651
|
+
return `read returned ${rows.length} rows; at most ${limit} were asked for`;
|
|
652
|
+
for (const [index, row] of rows.entries()) {
|
|
653
|
+
if (!plain(row))
|
|
654
|
+
return `row ${index} is not a plain object`;
|
|
655
|
+
for (const name of checked.select) {
|
|
656
|
+
const value = row[name];
|
|
657
|
+
if (value instanceof Date)
|
|
658
|
+
return `row ${index}: ${name} is a Date; return dates as text (full precision, as the database writes them)`;
|
|
659
|
+
if (value !== null &&
|
|
660
|
+
value !== undefined &&
|
|
661
|
+
!['string', 'number', 'boolean'].includes(typeof value))
|
|
662
|
+
return `row ${index}: ${name} is not a text, number, boolean or null`;
|
|
663
|
+
}
|
|
664
|
+
for (const { field } of checked.sort.by)
|
|
665
|
+
if (!keyFits(fields[field], row[field]))
|
|
666
|
+
return `row ${index}: the sort field ${field} is missing or not a ${fields[field]?.type}`;
|
|
667
|
+
}
|
|
668
|
+
return undefined;
|
|
669
|
+
}
|
|
670
|
+
const COLUMN = /^[A-Za-z_][A-Za-z0-9_]{0,62}(?:\.[A-Za-z_][A-Za-z0-9_]{0,62})?$/;
|
|
671
|
+
/**
|
|
672
|
+
* Builds the filter, cursor and order parts of a read for a SQL table (`columns` maps each field to
|
|
673
|
+
* its column, `m.created_at`). The cursor is a row comparison `(a, b) < ($1, $2)` on PostgreSQL when
|
|
674
|
+
* every sort column goes the same way, and the expanded form `a < ? OR (a = ? AND b < ?)` otherwise
|
|
675
|
+
* and always on MySQL and MariaDB, which use no row comparison as an index range (@dokebi/db AI.md
|
|
676
|
+
* §7.4). Placeholders are `$n` from `start` (PostgreSQL) or `?`. Scope and search stay the
|
|
677
|
+
* reader's: add their conditions (and parameters, from `next`) yourself.
|
|
678
|
+
*/
|
|
679
|
+
export function readSql(read, options) {
|
|
680
|
+
const params = [];
|
|
681
|
+
let number = options.start ?? 1;
|
|
682
|
+
const mark = (value) => {
|
|
683
|
+
params.push(value);
|
|
684
|
+
if (options.dialect !== 'postgres')
|
|
685
|
+
return '?';
|
|
686
|
+
const text = `$${number}`;
|
|
687
|
+
number += 1;
|
|
688
|
+
return text;
|
|
689
|
+
};
|
|
690
|
+
const column = (field) => {
|
|
691
|
+
const name = options.columns[field];
|
|
692
|
+
if (name === undefined || !COLUMN.test(name))
|
|
693
|
+
throw new DataSourceIssue(`readSql: field ${field} has no column (columns.${field} = a column name)`);
|
|
694
|
+
return name;
|
|
695
|
+
};
|
|
696
|
+
const conditions = [];
|
|
697
|
+
for (const filter of read.filters) {
|
|
698
|
+
const name = column(filter.field);
|
|
699
|
+
if (filter.kind === 'equal')
|
|
700
|
+
conditions.push(`${name} = ${mark(filter.value)}`);
|
|
701
|
+
else if (filter.kind === 'choice')
|
|
702
|
+
conditions.push(`${name} IN (${filter.values.map((value) => mark(value)).join(', ')})`);
|
|
703
|
+
else {
|
|
704
|
+
if (filter.from !== null)
|
|
705
|
+
conditions.push(`${name} >= ${mark(filter.from)}`);
|
|
706
|
+
if (filter.to !== null)
|
|
707
|
+
conditions.push(`${name} <= ${mark(filter.to)}`);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const by = read.sort.by.map(({ field, direction }) => ({ name: column(field), direction }));
|
|
711
|
+
const after = read.after;
|
|
712
|
+
if (after) {
|
|
713
|
+
const same = by.every((item) => item.direction === by[0]?.direction);
|
|
714
|
+
if (options.dialect === 'postgres' && same) {
|
|
715
|
+
const op = by[0]?.direction === 'desc' ? '<' : '>';
|
|
716
|
+
const left = by.map((item) => item.name).join(', ');
|
|
717
|
+
const right = after.map((value) => mark(value)).join(', ');
|
|
718
|
+
conditions.push(`(${left}) ${op} (${right})`);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
// a < ? OR (a = ? AND (b < ? OR (b = ? AND c < ?)))
|
|
722
|
+
const part = (index) => {
|
|
723
|
+
const item = by[index];
|
|
724
|
+
const op = item.direction === 'desc' ? '<' : '>';
|
|
725
|
+
const strict = `${item.name} ${op} ${mark(after[index])}`;
|
|
726
|
+
if (index === by.length - 1)
|
|
727
|
+
return strict;
|
|
728
|
+
return `${strict} OR (${item.name} = ${mark(after[index])} AND (${part(index + 1)}))`;
|
|
729
|
+
};
|
|
730
|
+
conditions.push(`(${part(0)})`);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return {
|
|
734
|
+
conditions: Object.freeze(conditions),
|
|
735
|
+
params: Object.freeze(params),
|
|
736
|
+
orderBy: by
|
|
737
|
+
.map((item) => `${item.name} ${item.direction === 'desc' ? 'DESC' : 'ASC'}`)
|
|
738
|
+
.join(', '),
|
|
739
|
+
limit: read.limit,
|
|
740
|
+
next: number,
|
|
741
|
+
};
|
|
742
|
+
}
|