@jskit-ai/crud-core 0.1.145 → 0.1.146
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/package.descriptor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
2
|
packageVersion: 1,
|
|
3
3
|
packageId: "@jskit-ai/crud-core",
|
|
4
|
-
version: "0.1.
|
|
4
|
+
version: "0.1.146",
|
|
5
5
|
kind: "runtime",
|
|
6
6
|
description: "Shared CRUD helpers used by CRUD modules.",
|
|
7
7
|
dependsOn: [
|
|
@@ -28,7 +28,7 @@ export default Object.freeze({
|
|
|
28
28
|
mutations: {
|
|
29
29
|
dependencies: {
|
|
30
30
|
runtime: {
|
|
31
|
-
"@jskit-ai/crud-core": "0.1.
|
|
31
|
+
"@jskit-ai/crud-core": "0.1.146"
|
|
32
32
|
},
|
|
33
33
|
dev: {}
|
|
34
34
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/crud-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.146",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@jskit-ai/realtime": "0.1.133",
|
|
35
35
|
"@jskit-ai/resource-crud-core": "0.1.79",
|
|
36
36
|
"@jskit-ai/shell-web": "0.1.137",
|
|
37
|
-
"@jskit-ai/users-core": "0.1.
|
|
37
|
+
"@jskit-ai/users-core": "0.1.149",
|
|
38
38
|
"@jskit-ai/users-web": "0.1.153"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
@@ -105,11 +105,47 @@ function createCrudParentFilterQueryValidator(resource = {}) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
function createStandardCrudListQueryValidators({
|
|
109
|
+
resource = {},
|
|
110
|
+
listFilterQueryValidator = null,
|
|
111
|
+
searchQueryValidator = listSearchQueryValidator,
|
|
112
|
+
includeQueryValidator = lookupIncludeQueryValidator
|
|
113
|
+
} = {}) {
|
|
114
|
+
const resolvedListFilterQueryValidator =
|
|
115
|
+
listFilterQueryValidator
|
|
116
|
+
?? resource?.contract?.listFilters?.queryValidator
|
|
117
|
+
?? null;
|
|
118
|
+
|
|
119
|
+
return [
|
|
120
|
+
createCrudCursorPaginationQueryValidator({
|
|
121
|
+
orderBy: resource?.defaultSort
|
|
122
|
+
}),
|
|
123
|
+
searchQueryValidator,
|
|
124
|
+
createCrudParentFilterQueryValidator(resource),
|
|
125
|
+
...(resolvedListFilterQueryValidator
|
|
126
|
+
? [resolvedListFilterQueryValidator]
|
|
127
|
+
: []),
|
|
128
|
+
includeQueryValidator,
|
|
129
|
+
jsonApiFieldsetsQueryValidator
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createStandardCrudViewQueryValidators({
|
|
134
|
+
includeQueryValidator = lookupIncludeQueryValidator
|
|
135
|
+
} = {}) {
|
|
136
|
+
return [
|
|
137
|
+
includeQueryValidator,
|
|
138
|
+
jsonApiFieldsetsQueryValidator
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
|
|
108
142
|
export {
|
|
109
143
|
createCrudCursorPaginationQueryValidator,
|
|
110
144
|
listSearchQueryValidator,
|
|
111
145
|
lookupIncludeQueryValidator,
|
|
112
146
|
jsonApiFieldsetsQueryValidator,
|
|
113
147
|
resolveCrudParentFilterKeys,
|
|
114
|
-
createCrudParentFilterQueryValidator
|
|
148
|
+
createCrudParentFilterQueryValidator,
|
|
149
|
+
createStandardCrudListQueryValidators,
|
|
150
|
+
createStandardCrudViewQueryValidators
|
|
115
151
|
};
|
|
@@ -8,11 +8,10 @@ import {
|
|
|
8
8
|
} from "@jskit-ai/kernel/shared/validators";
|
|
9
9
|
import { resolveCrudResourceScopeName } from "@jskit-ai/kernel/shared/support/crudLookup";
|
|
10
10
|
import {
|
|
11
|
-
|
|
11
|
+
createStandardCrudListQueryValidators,
|
|
12
|
+
createStandardCrudViewQueryValidators,
|
|
12
13
|
listSearchQueryValidator as defaultListSearchQueryValidator,
|
|
13
|
-
lookupIncludeQueryValidator as defaultLookupIncludeQueryValidator
|
|
14
|
-
jsonApiFieldsetsQueryValidator,
|
|
15
|
-
createCrudParentFilterQueryValidator
|
|
14
|
+
lookupIncludeQueryValidator as defaultLookupIncludeQueryValidator
|
|
16
15
|
} from "./listQueryValidators.js";
|
|
17
16
|
|
|
18
17
|
function isRecord(value) {
|
|
@@ -445,23 +444,19 @@ function createCrudJsonApiRouteContracts({
|
|
|
445
444
|
lookupIncludeQueryValidator = defaultLookupIncludeQueryValidator,
|
|
446
445
|
listFilterQueryValidator = null
|
|
447
446
|
} = {}) {
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const viewRouteQueryValidator = composeSchemaDefinitions([
|
|
462
|
-
lookupIncludeQueryValidator,
|
|
463
|
-
jsonApiFieldsetsQueryValidator
|
|
464
|
-
]);
|
|
447
|
+
const listRouteQueryValidator = composeSchemaDefinitions(
|
|
448
|
+
createStandardCrudListQueryValidators({
|
|
449
|
+
resource,
|
|
450
|
+
listFilterQueryValidator,
|
|
451
|
+
searchQueryValidator: listSearchQueryValidator,
|
|
452
|
+
includeQueryValidator: lookupIncludeQueryValidator
|
|
453
|
+
})
|
|
454
|
+
);
|
|
455
|
+
const viewRouteQueryValidator = composeSchemaDefinitions(
|
|
456
|
+
createStandardCrudViewQueryValidators({
|
|
457
|
+
includeQueryValidator: lookupIncludeQueryValidator
|
|
458
|
+
})
|
|
459
|
+
);
|
|
465
460
|
const recordRouteParamsValidator = routeParamsValidator
|
|
466
461
|
? composeSchemaDefinitions([
|
|
467
462
|
routeParamsValidator,
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
lookupIncludeQueryValidator,
|
|
12
12
|
createCrudCursorPaginationQueryValidator,
|
|
13
13
|
createCrudParentFilterQueryValidator,
|
|
14
|
+
createStandardCrudListQueryValidators,
|
|
15
|
+
createStandardCrudViewQueryValidators,
|
|
14
16
|
resolveCrudParentFilterKeys
|
|
15
17
|
} from "../src/server/listQueryValidators.js";
|
|
16
18
|
|
|
@@ -254,3 +256,49 @@ test("createCrudParentFilterQueryValidator keeps parent filters optional when me
|
|
|
254
256
|
});
|
|
255
257
|
assert.deepEqual(compiled.schema.querystring.required || [], []);
|
|
256
258
|
});
|
|
259
|
+
|
|
260
|
+
test("standard CRUD query validator groups remain plain and extensible", () => {
|
|
261
|
+
const listFilterQueryValidator = {
|
|
262
|
+
schema: createSchema({
|
|
263
|
+
currentness: {
|
|
264
|
+
type: "string",
|
|
265
|
+
required: false
|
|
266
|
+
}
|
|
267
|
+
}),
|
|
268
|
+
mode: "patch"
|
|
269
|
+
};
|
|
270
|
+
const resource = {
|
|
271
|
+
...createCrudResource(),
|
|
272
|
+
defaultSort: ["-createdAt"],
|
|
273
|
+
contract: {
|
|
274
|
+
listFilters: {
|
|
275
|
+
queryValidator: listFilterQueryValidator
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const listQueryValidator = composeSchemaDefinition(
|
|
281
|
+
...createStandardCrudListQueryValidators({ resource }),
|
|
282
|
+
{
|
|
283
|
+
schema: createSchema({
|
|
284
|
+
archived: {
|
|
285
|
+
type: "boolean",
|
|
286
|
+
required: false
|
|
287
|
+
}
|
|
288
|
+
}),
|
|
289
|
+
mode: "patch"
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
assert.deepEqual(
|
|
293
|
+
Object.keys(listQueryValidator.schema.getFieldDefinitions()).sort(),
|
|
294
|
+
["archived", "currentness", "cursor", "fields", "include", "limit", "q"]
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const viewQueryValidator = composeSchemaDefinition(
|
|
298
|
+
...createStandardCrudViewQueryValidators()
|
|
299
|
+
);
|
|
300
|
+
assert.deepEqual(
|
|
301
|
+
Object.keys(viewQueryValidator.schema.getFieldDefinitions()).sort(),
|
|
302
|
+
["fields", "include"]
|
|
303
|
+
);
|
|
304
|
+
});
|