@jskit-ai/crud-core 0.2.3 → 0.2.4
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/locales/en.json +2 -1
- package/package.json +7 -7
- package/patterns/json-api-resource-package/PATTERN.md +102 -23
- package/patterns/json-api-resource-package/example/packages/books/package.json +3 -2
- package/patterns/json-api-resource-package/example/packages/books/src/server/types.js +5 -0
- package/src/server/createCrudServiceFromResource.js +14 -6
- package/src/server/createHooksToCollectChildren.js +123 -97
- package/src/server/defineCrudJsonApiFeature.js +40 -8
- package/src/server/fieldAccess.js +33 -25
- package/src/server/jsonApiModule/actions.js +151 -548
- package/src/server/jsonApiModule/assistantExtension.js +386 -0
- package/src/server/jsonApiModule/customActionId.js +12 -0
- package/src/server/jsonApiModule/repository.js +73 -21
- package/src/server/jsonApiModule/routes.js +44 -30
- package/src/server/jsonApiModule/service.js +37 -35
- package/src/server/jsonApiResourceContract.js +22 -18
- package/src/server/listFilterJsonRest.js +304 -0
- package/src/server/listFilterTypes.js +427 -0
- package/src/server/listFilters.js +26 -722
- package/src/server/listQueryValidators.js +26 -21
- package/src/server/lookupPathSupport.js +31 -18
- package/src/server/lookups.js +20 -34
- package/src/server/normalizeOptionalText.js +13 -0
- package/src/server/repositorySupport.js +11 -10
- package/src/server/resourceRuntime/compiledRuntime.js +284 -0
- package/src/server/resourceRuntime/index.js +167 -920
- package/src/server/resourceRuntime/listControls.js +333 -0
- package/src/server/resourceRuntime/lookupHydration.js +121 -186
- package/src/server/resourceRuntime/operationStages.js +140 -0
- package/src/server/resourceRuntime/recordValidation.js +65 -0
- package/src/server/routeContracts.js +44 -46
- package/src/server/serviceEvents.js +42 -118
- package/src/server/serviceMethods.js +34 -26
- package/src/server/types.js +156 -0
- package/test/assistantActionConformance.test.js +8 -5
- package/test/assistantPagination.integration.test.js +5 -3
- package/test/createCrudServiceFromResource.test.js +0 -18
- package/test/customActionId.test.js +12 -0
- package/test/defineCrudJsonApiFeature.test.js +193 -28
- package/test/errorCodes.test.js +18 -0
- package/test/jsonApiRepository.test.js +103 -3
- package/test/listFilters.test.js +7 -7
- package/test/listQueryValidators.test.js +1 -54
- package/test/serviceEvents.test.js +31 -81
- package/test/support/crudJsonApiActionOptions.js +37 -0
- package/src/server/crudModuleConfig.js +0 -181
- package/src/server/lookupHydration.js +0 -710
- package/test/crudModuleConfig.test.js +0 -33
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { RECORD_ID_PATTERN } from "@jskit-ai/kernel/shared/validators";
|
|
2
|
+
import { createSchema } from "json-rest-schema";
|
|
3
|
+
import {
|
|
4
|
+
isRecord,
|
|
5
|
+
normalizeText
|
|
6
|
+
} from "@jskit-ai/kernel/shared/support/normalize";
|
|
7
|
+
import {
|
|
8
|
+
CRUD_LIST_FILTER_INVALID_VALUES_REJECT,
|
|
9
|
+
CRUD_LIST_FILTER_INVALID_VALUES_DISCARD,
|
|
10
|
+
CRUD_LIST_FILTER_TYPE_FLAG,
|
|
11
|
+
CRUD_LIST_FILTER_TYPE_ENUM,
|
|
12
|
+
CRUD_LIST_FILTER_TYPE_ENUM_MANY,
|
|
13
|
+
CRUD_LIST_FILTER_TYPE_RECORD_ID,
|
|
14
|
+
CRUD_LIST_FILTER_TYPE_RECORD_ID_MANY,
|
|
15
|
+
CRUD_LIST_FILTER_TYPE_DATE,
|
|
16
|
+
CRUD_LIST_FILTER_TYPE_DATE_RANGE,
|
|
17
|
+
CRUD_LIST_FILTER_TYPE_NUMBER_RANGE,
|
|
18
|
+
CRUD_LIST_FILTER_TYPE_PRESENCE,
|
|
19
|
+
CRUD_LIST_FILTER_PRESENCE_PRESENT,
|
|
20
|
+
CRUD_LIST_FILTER_PRESENCE_MISSING,
|
|
21
|
+
INVALID_CRUD_LIST_FILTER_QUERY_VALUE,
|
|
22
|
+
normalizeCrudListFilterInvalidValues,
|
|
23
|
+
parseCrudListFilterQueryValue
|
|
24
|
+
} from "@jskit-ai/resource-crud-core/shared/crudListFilters";
|
|
25
|
+
|
|
26
|
+
const DATE_FILTER_VALUE_PATTERN_SOURCE = "\\d{4}-\\d{2}-\\d{2}";
|
|
27
|
+
const DATE_FILTER_PATTERN_SOURCE = `^${DATE_FILTER_VALUE_PATTERN_SOURCE}$`;
|
|
28
|
+
const DATE_RANGE_FILTER_PATTERN_SOURCE =
|
|
29
|
+
`^(?:${DATE_FILTER_VALUE_PATTERN_SOURCE}(?:\\.\\.(?:${DATE_FILTER_VALUE_PATTERN_SOURCE})?)?|\\.\\.${DATE_FILTER_VALUE_PATTERN_SOURCE})$`;
|
|
30
|
+
const NUMBER_FILTER_VALUE_PATTERN_SOURCE = "[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?";
|
|
31
|
+
const NUMBER_RANGE_FILTER_PATTERN_SOURCE =
|
|
32
|
+
`^(?:${NUMBER_FILTER_VALUE_PATTERN_SOURCE}(?:\\.\\.(?:${NUMBER_FILTER_VALUE_PATTERN_SOURCE})?)?|\\.\\.${NUMBER_FILTER_VALUE_PATTERN_SOURCE})$`;
|
|
33
|
+
const CRUD_LIST_FILTER_QUERY_TYPE = "crudListFilterQuery";
|
|
34
|
+
const crudListFilterSchemaFactory = createSchema.createFactory();
|
|
35
|
+
const looseTextTransportSchema = Object.freeze({
|
|
36
|
+
type: "string",
|
|
37
|
+
minLength: 0
|
|
38
|
+
});
|
|
39
|
+
const strictNumberRangeTransportSchema = Object.freeze({
|
|
40
|
+
anyOf: [
|
|
41
|
+
{
|
|
42
|
+
type: "string",
|
|
43
|
+
pattern: NUMBER_RANGE_FILTER_PATTERN_SOURCE
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "number"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
const looseStringOrNumberTransportSchema = Object.freeze({
|
|
51
|
+
anyOf: [
|
|
52
|
+
looseTextTransportSchema,
|
|
53
|
+
{
|
|
54
|
+
type: "number"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
const recordIdTransportSchema = Object.freeze({
|
|
59
|
+
anyOf: [
|
|
60
|
+
{
|
|
61
|
+
type: "string",
|
|
62
|
+
pattern: RECORD_ID_PATTERN
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "number",
|
|
66
|
+
minimum: 1
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
const flagTransportSchema = Object.freeze({
|
|
71
|
+
anyOf: [
|
|
72
|
+
{
|
|
73
|
+
type: "string",
|
|
74
|
+
minLength: 0
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: "boolean"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: "number"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
function cloneTransportSchema(value) {
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
return value.map((entry) => cloneTransportSchema(entry));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!value || typeof value !== "object") {
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return Object.fromEntries(
|
|
95
|
+
Object.entries(value).map(([key, entry]) => [key, cloneTransportSchema(entry)])
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function buildSingleOrMultiTransportSchema(itemSchema) {
|
|
100
|
+
return {
|
|
101
|
+
anyOf: [
|
|
102
|
+
cloneTransportSchema(itemSchema),
|
|
103
|
+
{
|
|
104
|
+
type: "array",
|
|
105
|
+
items: cloneTransportSchema(itemSchema),
|
|
106
|
+
minItems: 1
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function addDaysToDateFilterValue(value = "", days = 0) {
|
|
113
|
+
const normalizedValue = parseCrudListFilterQueryValue(
|
|
114
|
+
{ type: CRUD_LIST_FILTER_TYPE_DATE },
|
|
115
|
+
value,
|
|
116
|
+
{ invalidValues: CRUD_LIST_FILTER_INVALID_VALUES_REJECT }
|
|
117
|
+
);
|
|
118
|
+
if (
|
|
119
|
+
normalizedValue === INVALID_CRUD_LIST_FILTER_QUERY_VALUE ||
|
|
120
|
+
!normalizedValue ||
|
|
121
|
+
!Number.isInteger(days)
|
|
122
|
+
) {
|
|
123
|
+
return "";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const date = new Date(`${normalizedValue}T00:00:00.000Z`);
|
|
127
|
+
if (Number.isNaN(date.getTime())) {
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
date.setUTCDate(date.getUTCDate() + days);
|
|
132
|
+
const year = date.getUTCFullYear();
|
|
133
|
+
const month = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
134
|
+
const day = String(date.getUTCDate()).padStart(2, "0");
|
|
135
|
+
return `${year}-${month}-${day}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function buildAllowedValuesTransportSchema({ discardInvalidValues, allowedValues }) {
|
|
139
|
+
return discardInvalidValues
|
|
140
|
+
? cloneTransportSchema(looseTextTransportSchema)
|
|
141
|
+
: {
|
|
142
|
+
type: "string",
|
|
143
|
+
enum: allowedValues
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function applyEqualsFilterQuery(queryBuilder, value, column = "") {
|
|
148
|
+
if (column && value !== undefined) {
|
|
149
|
+
queryBuilder.where(column, value);
|
|
150
|
+
}
|
|
151
|
+
return queryBuilder;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function applyInFilterQuery(queryBuilder, value, column = "") {
|
|
155
|
+
if (column && Array.isArray(value) && value.length > 0) {
|
|
156
|
+
queryBuilder.whereIn(column, value);
|
|
157
|
+
}
|
|
158
|
+
return queryBuilder;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const FILTER_TYPE_SERVER_HANDLERS = Object.freeze({
|
|
162
|
+
[CRUD_LIST_FILTER_TYPE_FLAG]: Object.freeze({
|
|
163
|
+
buildTransportSchema() {
|
|
164
|
+
return cloneTransportSchema(flagTransportSchema);
|
|
165
|
+
},
|
|
166
|
+
applyQuery(queryBuilder, value, column = "") {
|
|
167
|
+
if (column && value === true) {
|
|
168
|
+
queryBuilder.where(column, true);
|
|
169
|
+
}
|
|
170
|
+
return queryBuilder;
|
|
171
|
+
}
|
|
172
|
+
}),
|
|
173
|
+
[CRUD_LIST_FILTER_TYPE_ENUM]: Object.freeze({
|
|
174
|
+
buildTransportSchema: buildAllowedValuesTransportSchema,
|
|
175
|
+
applyQuery: applyEqualsFilterQuery
|
|
176
|
+
}),
|
|
177
|
+
[CRUD_LIST_FILTER_TYPE_ENUM_MANY]: Object.freeze({
|
|
178
|
+
buildTransportSchema({ discardInvalidValues, allowedValues }) {
|
|
179
|
+
return buildSingleOrMultiTransportSchema(
|
|
180
|
+
discardInvalidValues
|
|
181
|
+
? looseTextTransportSchema
|
|
182
|
+
: {
|
|
183
|
+
type: "string",
|
|
184
|
+
enum: allowedValues
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
},
|
|
188
|
+
applyQuery: applyInFilterQuery
|
|
189
|
+
}),
|
|
190
|
+
[CRUD_LIST_FILTER_TYPE_RECORD_ID]: Object.freeze({
|
|
191
|
+
buildTransportSchema({ discardInvalidValues }) {
|
|
192
|
+
return discardInvalidValues
|
|
193
|
+
? cloneTransportSchema(looseStringOrNumberTransportSchema)
|
|
194
|
+
: cloneTransportSchema(recordIdTransportSchema);
|
|
195
|
+
},
|
|
196
|
+
applyQuery: applyEqualsFilterQuery
|
|
197
|
+
}),
|
|
198
|
+
[CRUD_LIST_FILTER_TYPE_RECORD_ID_MANY]: Object.freeze({
|
|
199
|
+
buildTransportSchema({ discardInvalidValues }) {
|
|
200
|
+
return buildSingleOrMultiTransportSchema(
|
|
201
|
+
discardInvalidValues
|
|
202
|
+
? looseStringOrNumberTransportSchema
|
|
203
|
+
: recordIdTransportSchema
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
applyQuery: applyInFilterQuery
|
|
207
|
+
}),
|
|
208
|
+
[CRUD_LIST_FILTER_TYPE_DATE]: Object.freeze({
|
|
209
|
+
buildTransportSchema({ discardInvalidValues }) {
|
|
210
|
+
return discardInvalidValues
|
|
211
|
+
? cloneTransportSchema(looseTextTransportSchema)
|
|
212
|
+
: {
|
|
213
|
+
type: "string",
|
|
214
|
+
pattern: DATE_FILTER_PATTERN_SOURCE
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
applyQuery(queryBuilder, value, column = "") {
|
|
218
|
+
if (!column || !value) {
|
|
219
|
+
return queryBuilder;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const nextDate = addDaysToDateFilterValue(value, 1);
|
|
223
|
+
queryBuilder.where(column, ">=", `${value} 00:00:00`);
|
|
224
|
+
if (nextDate) {
|
|
225
|
+
queryBuilder.where(column, "<", `${nextDate} 00:00:00`);
|
|
226
|
+
}
|
|
227
|
+
return queryBuilder;
|
|
228
|
+
}
|
|
229
|
+
}),
|
|
230
|
+
[CRUD_LIST_FILTER_TYPE_DATE_RANGE]: Object.freeze({
|
|
231
|
+
buildTransportSchema({ discardInvalidValues }) {
|
|
232
|
+
return discardInvalidValues
|
|
233
|
+
? cloneTransportSchema(looseTextTransportSchema)
|
|
234
|
+
: {
|
|
235
|
+
type: "string",
|
|
236
|
+
pattern: DATE_RANGE_FILTER_PATTERN_SOURCE
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
applyQuery(queryBuilder, value, column = "") {
|
|
240
|
+
if (!column) {
|
|
241
|
+
return queryBuilder;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (value?.from) {
|
|
245
|
+
queryBuilder.where(column, ">=", `${value.from} 00:00:00`);
|
|
246
|
+
}
|
|
247
|
+
if (value?.to) {
|
|
248
|
+
const nextDate = addDaysToDateFilterValue(value.to, 1);
|
|
249
|
+
if (nextDate) {
|
|
250
|
+
queryBuilder.where(column, "<", `${nextDate} 00:00:00`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return queryBuilder;
|
|
254
|
+
}
|
|
255
|
+
}),
|
|
256
|
+
[CRUD_LIST_FILTER_TYPE_NUMBER_RANGE]: Object.freeze({
|
|
257
|
+
buildTransportSchema({ discardInvalidValues }) {
|
|
258
|
+
return discardInvalidValues
|
|
259
|
+
? cloneTransportSchema(looseStringOrNumberTransportSchema)
|
|
260
|
+
: cloneTransportSchema(strictNumberRangeTransportSchema);
|
|
261
|
+
},
|
|
262
|
+
applyQuery(queryBuilder, value, column = "") {
|
|
263
|
+
if (!column) {
|
|
264
|
+
return queryBuilder;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (value?.min != null) {
|
|
268
|
+
queryBuilder.where(column, ">=", value.min);
|
|
269
|
+
}
|
|
270
|
+
if (value?.max != null) {
|
|
271
|
+
queryBuilder.where(column, "<=", value.max);
|
|
272
|
+
}
|
|
273
|
+
return queryBuilder;
|
|
274
|
+
}
|
|
275
|
+
}),
|
|
276
|
+
[CRUD_LIST_FILTER_TYPE_PRESENCE]: Object.freeze({
|
|
277
|
+
buildTransportSchema: buildAllowedValuesTransportSchema,
|
|
278
|
+
applyQuery(queryBuilder, value, column = "") {
|
|
279
|
+
if (!column) {
|
|
280
|
+
return queryBuilder;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (value === CRUD_LIST_FILTER_PRESENCE_PRESENT) {
|
|
284
|
+
queryBuilder.whereNotNull(column);
|
|
285
|
+
}
|
|
286
|
+
if (value === CRUD_LIST_FILTER_PRESENCE_MISSING) {
|
|
287
|
+
queryBuilder.whereNull(column);
|
|
288
|
+
}
|
|
289
|
+
return queryBuilder;
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
function normalizeCrudListFilterQueryFieldInput(filterDefinition) {
|
|
295
|
+
if (!isRecord(filterDefinition)) {
|
|
296
|
+
throw new TypeError("buildCrudListFilterQueryField requires a normalized filter definition object.");
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const key = normalizeText(filterDefinition.key);
|
|
300
|
+
const type = normalizeText(filterDefinition.type);
|
|
301
|
+
const queryKey = normalizeText(filterDefinition.queryKey);
|
|
302
|
+
if (!key || !type || !queryKey) {
|
|
303
|
+
throw new TypeError(
|
|
304
|
+
"buildCrudListFilterQueryField requires a normalized filter definition from defineCrudListFilters(...)."
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
if (!FILTER_TYPE_SERVER_HANDLERS[type]) {
|
|
308
|
+
throw new TypeError(`Unsupported CRUD list filter type "${type}".`);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return filterDefinition;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function buildCrudListFilterQueryField(filterDefinition, {
|
|
315
|
+
invalidValues = CRUD_LIST_FILTER_INVALID_VALUES_REJECT
|
|
316
|
+
} = {}) {
|
|
317
|
+
const invalidValueMode = normalizeCrudListFilterInvalidValues(invalidValues);
|
|
318
|
+
const filter = normalizeCrudListFilterQueryFieldInput(filterDefinition);
|
|
319
|
+
const filterContract = Object.freeze({
|
|
320
|
+
filter,
|
|
321
|
+
invalidValues: invalidValueMode
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
return Object.freeze({
|
|
325
|
+
type: CRUD_LIST_FILTER_QUERY_TYPE,
|
|
326
|
+
filterContract
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function buildFilterQueryFieldDefinition(filterDefinition, { invalidValues }) {
|
|
331
|
+
const field = buildCrudListFilterQueryField(filterDefinition, { invalidValues });
|
|
332
|
+
return {
|
|
333
|
+
[field.filterContract.filter.queryKey]: field
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The transport schema of a filter query field, from its contract (whose
|
|
339
|
+
* invalidValues buildCrudListFilterQueryField has already normalized).
|
|
340
|
+
*/
|
|
341
|
+
function buildFilterQueryTransportSchema(filter, { invalidValues }) {
|
|
342
|
+
const discardInvalidValues = invalidValues === CRUD_LIST_FILTER_INVALID_VALUES_DISCARD;
|
|
343
|
+
const allowedValues = (Array.isArray(filter.options) ? filter.options : []).map((entry) => entry.value);
|
|
344
|
+
const handler = FILTER_TYPE_SERVER_HANDLERS[filter.type];
|
|
345
|
+
return handler
|
|
346
|
+
? handler.buildTransportSchema({ discardInvalidValues, allowedValues })
|
|
347
|
+
: {};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
crudListFilterSchemaFactory.addType(CRUD_LIST_FILTER_QUERY_TYPE, Object.assign(
|
|
351
|
+
(context) => {
|
|
352
|
+
const contract = isRecord(context.definition.filterContract)
|
|
353
|
+
? context.definition.filterContract
|
|
354
|
+
: null;
|
|
355
|
+
const filter = contract?.filter;
|
|
356
|
+
const invalidValues = contract?.invalidValues;
|
|
357
|
+
|
|
358
|
+
if (!filter || !invalidValues) {
|
|
359
|
+
context.throwTypeError();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const parsedValue = parseCrudListFilterQueryValue(filter, context.value, {
|
|
363
|
+
invalidValues
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
if (parsedValue === INVALID_CRUD_LIST_FILTER_QUERY_VALUE) {
|
|
367
|
+
context.throwTypeError();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return parsedValue;
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
toJsonSchema({ definition }) {
|
|
374
|
+
const contract = isRecord(definition?.filterContract)
|
|
375
|
+
? definition.filterContract
|
|
376
|
+
: null;
|
|
377
|
+
const filter = contract?.filter;
|
|
378
|
+
const invalidValues = contract?.invalidValues;
|
|
379
|
+
|
|
380
|
+
if (!filter || !invalidValues) {
|
|
381
|
+
throw new Error(`Type "${CRUD_LIST_FILTER_QUERY_TYPE}" requires definition.filterContract for transport export.`);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return buildFilterQueryTransportSchema(filter, {
|
|
385
|
+
invalidValues
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
));
|
|
390
|
+
|
|
391
|
+
function createCrudListFilterQuerySchema(structure = {}) {
|
|
392
|
+
return crudListFilterSchemaFactory(structure);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function buildFilterQuerySchemaDefinition(filterEntries = [], {
|
|
396
|
+
invalidValues = CRUD_LIST_FILTER_INVALID_VALUES_REJECT
|
|
397
|
+
} = {}) {
|
|
398
|
+
const structure = {};
|
|
399
|
+
|
|
400
|
+
for (const filter of filterEntries) {
|
|
401
|
+
Object.assign(structure, buildFilterQueryFieldDefinition(filter, {
|
|
402
|
+
invalidValues
|
|
403
|
+
}));
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return Object.freeze({
|
|
407
|
+
schema: createCrudListFilterQuerySchema(structure),
|
|
408
|
+
mode: "patch"
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function applyDefaultFilterQuery(queryBuilder, filter = {}, value, column = "") {
|
|
413
|
+
const handler = FILTER_TYPE_SERVER_HANDLERS[filter.type];
|
|
414
|
+
return handler
|
|
415
|
+
? handler.applyQuery(queryBuilder, value, column)
|
|
416
|
+
: queryBuilder;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export {
|
|
420
|
+
recordIdTransportSchema,
|
|
421
|
+
cloneTransportSchema,
|
|
422
|
+
addDaysToDateFilterValue,
|
|
423
|
+
buildCrudListFilterQueryField,
|
|
424
|
+
createCrudListFilterQuerySchema,
|
|
425
|
+
buildFilterQuerySchemaDefinition,
|
|
426
|
+
applyDefaultFilterQuery
|
|
427
|
+
};
|