@feathersjs/schema 5.0.0-pre.30 → 5.0.0-pre.31
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 +7 -0
- package/lib/json-schema.d.ts +7 -8
- package/lib/json-schema.js +4 -3
- package/lib/json-schema.js.map +1 -1
- package/package.json +6 -7
- package/src/json-schema.ts +10 -13
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-pre.31](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.30...v5.0.0-pre.31) (2022-10-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **cli:** Generate full client test suite and improve typed client ([#2788](https://github.com/feathersjs/feathers/issues/2788)) ([57119b6](https://github.com/feathersjs/feathers/commit/57119b6bb2797f7297cf054268a248c093ecd538))
|
|
11
|
+
- **cli:** Improve generated schema definitions ([#2783](https://github.com/feathersjs/feathers/issues/2783)) ([474a9fd](https://github.com/feathersjs/feathers/commit/474a9fda2107e9bcf357746320a8e00cda8182b6))
|
|
12
|
+
|
|
6
13
|
# [5.0.0-pre.30](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.29...v5.0.0-pre.30) (2022-10-07)
|
|
7
14
|
|
|
8
15
|
### Features
|
package/lib/json-schema.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { JSONSchema } from 'json-schema-to-ts';
|
|
2
|
-
import { TObject } from '@sinclair/typebox';
|
|
3
2
|
import { JSONSchemaDefinition, Ajv, Validator } from './schema';
|
|
4
3
|
export declare type DataSchemaMap = {
|
|
5
|
-
create: JSONSchemaDefinition
|
|
6
|
-
update?: JSONSchemaDefinition
|
|
7
|
-
patch?: JSONSchemaDefinition
|
|
4
|
+
create: JSONSchemaDefinition;
|
|
5
|
+
update?: JSONSchemaDefinition;
|
|
6
|
+
patch?: JSONSchemaDefinition;
|
|
8
7
|
};
|
|
9
8
|
export declare type DataValidatorMap = {
|
|
10
9
|
create: Validator;
|
|
@@ -18,7 +17,7 @@ export declare type DataValidatorMap = {
|
|
|
18
17
|
* @param validator The AJV validation instance
|
|
19
18
|
* @returns A compiled validation function
|
|
20
19
|
*/
|
|
21
|
-
export declare const getValidator: <T = any, R = T>(schema: JSONSchemaDefinition
|
|
20
|
+
export declare const getValidator: <T = any, R = T>(schema: JSONSchemaDefinition, validator: Ajv) => Validator<T, R>;
|
|
22
21
|
/**
|
|
23
22
|
* Returns compiled validation functions to validate data for the `create`, `update` and `patch`
|
|
24
23
|
* service methods. If not passed explicitly, the `update` validator will be the same as the `create`
|
|
@@ -29,7 +28,7 @@ export declare const getValidator: <T = any, R = T>(schema: JSONSchemaDefinition
|
|
|
29
28
|
* @param validator The Ajv instance to use as the validator
|
|
30
29
|
* @returns A map of validator functions
|
|
31
30
|
*/
|
|
32
|
-
export declare const getDataValidator: (def: JSONSchemaDefinition |
|
|
31
|
+
export declare const getDataValidator: (def: JSONSchemaDefinition | DataSchemaMap, validator: Ajv) => DataValidatorMap;
|
|
33
32
|
export declare type PropertyQuery<D extends JSONSchema> = {
|
|
34
33
|
anyOf: [
|
|
35
34
|
D,
|
|
@@ -84,12 +83,12 @@ export declare const queryProperty: <T extends import("json-schema-to-ts").JSONS
|
|
|
84
83
|
/**
|
|
85
84
|
* Creates Feathers a query syntax compatible JSON schema for multiple properties.
|
|
86
85
|
*
|
|
87
|
-
* @param
|
|
86
|
+
* @param definitions A map of property definitions
|
|
88
87
|
* @returns The JSON schema definition for the Feathers query syntax for multiple properties
|
|
89
88
|
*/
|
|
90
89
|
export declare const queryProperties: <T extends {
|
|
91
90
|
[key: string]: import("json-schema-to-ts").JSONSchema7;
|
|
92
|
-
}>(
|
|
91
|
+
}>(definitions: T) => { [K in keyof T]: PropertyQuery<T[K]>; };
|
|
93
92
|
/**
|
|
94
93
|
* Creates a JSON schema for the complete Feathers query syntax including `$limit`, $skip`
|
|
95
94
|
* and `$sort` and `$select` for the allowed properties.
|
package/lib/json-schema.js
CHANGED
|
@@ -77,12 +77,13 @@ exports.queryProperty = queryProperty;
|
|
|
77
77
|
/**
|
|
78
78
|
* Creates Feathers a query syntax compatible JSON schema for multiple properties.
|
|
79
79
|
*
|
|
80
|
-
* @param
|
|
80
|
+
* @param definitions A map of property definitions
|
|
81
81
|
* @returns The JSON schema definition for the Feathers query syntax for multiple properties
|
|
82
82
|
*/
|
|
83
|
-
const queryProperties = (
|
|
83
|
+
const queryProperties = (definitions) => Object.keys(definitions).reduce((res, key) => {
|
|
84
84
|
const result = res;
|
|
85
|
-
|
|
85
|
+
const definition = definitions[key];
|
|
86
|
+
result[key] = (0, exports.queryProperty)(definition);
|
|
86
87
|
return result;
|
|
87
88
|
}, {});
|
|
88
89
|
exports.queryProperties = queryProperties;
|
package/lib/json-schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":";;;AAAA,iDAAuC;
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":";;;AAAA,iDAAuC;AAgBvC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAiB,MAA4B,EAAE,SAAc,EAAmB,EAAE,CAC5G,SAAS,CAAC,OAAO,CAAC;IAChB,MAAM,EAAE,IAAI;IACZ,GAAI,MAAc;CACnB,CAA2B,CAAA;AAJjB,QAAA,YAAY,gBAIK;AAE9B;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAAG,CAC9B,GAAyC,EACzC,SAAc,EACI,EAAE;IACpB,MAAM,MAAM,GAAG,CAAE,GAAW,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,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
|
3
3
|
"description": "A common data schema definition format",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.31",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -54,18 +54,17 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
58
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
59
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
57
|
+
"@feathersjs/commons": "^5.0.0-pre.31",
|
|
58
|
+
"@feathersjs/errors": "^5.0.0-pre.31",
|
|
59
|
+
"@feathersjs/feathers": "^5.0.0-pre.31",
|
|
60
60
|
"@feathersjs/hooks": "^0.7.5",
|
|
61
61
|
"@types/json-schema": "^7.0.11",
|
|
62
62
|
"ajv": "^8.11.0",
|
|
63
63
|
"ajv-formats": "^2.1.1",
|
|
64
|
-
"json-schema": "^0.4.0",
|
|
65
64
|
"json-schema-to-ts": "^2.5.5"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
68
|
-
"@feathersjs/memory": "^5.0.0-pre.
|
|
67
|
+
"@feathersjs/memory": "^5.0.0-pre.31",
|
|
69
68
|
"@types/mocha": "^10.0.0",
|
|
70
69
|
"@types/node": "^18.8.2",
|
|
71
70
|
"ajv-formats": "^2.1.1",
|
|
@@ -73,5 +72,5 @@
|
|
|
73
72
|
"shx": "^0.3.4",
|
|
74
73
|
"typescript": "^4.8.4"
|
|
75
74
|
},
|
|
76
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "4500dbeb8cea566678cf88b3313a88efd93a2ed9"
|
|
77
76
|
}
|
package/src/json-schema.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { _ } from '@feathersjs/commons'
|
|
2
2
|
import { JSONSchema } from 'json-schema-to-ts'
|
|
3
|
-
import { TObject } from '@sinclair/typebox'
|
|
4
3
|
import { JSONSchemaDefinition, Ajv, Validator } from './schema'
|
|
5
4
|
|
|
6
5
|
export type DataSchemaMap = {
|
|
7
|
-
create: JSONSchemaDefinition
|
|
8
|
-
update?: JSONSchemaDefinition
|
|
9
|
-
patch?: JSONSchemaDefinition
|
|
6
|
+
create: JSONSchemaDefinition
|
|
7
|
+
update?: JSONSchemaDefinition
|
|
8
|
+
patch?: JSONSchemaDefinition
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export type DataValidatorMap = {
|
|
@@ -22,10 +21,7 @@ export type DataValidatorMap = {
|
|
|
22
21
|
* @param validator The AJV validation instance
|
|
23
22
|
* @returns A compiled validation function
|
|
24
23
|
*/
|
|
25
|
-
export const getValidator = <T = any, R = T>(
|
|
26
|
-
schema: JSONSchemaDefinition | TObject,
|
|
27
|
-
validator: Ajv
|
|
28
|
-
): Validator<T, R> =>
|
|
24
|
+
export const getValidator = <T = any, R = T>(schema: JSONSchemaDefinition, validator: Ajv): Validator<T, R> =>
|
|
29
25
|
validator.compile({
|
|
30
26
|
$async: true,
|
|
31
27
|
...(schema as any)
|
|
@@ -42,7 +38,7 @@ export const getValidator = <T = any, R = T>(
|
|
|
42
38
|
* @returns A map of validator functions
|
|
43
39
|
*/
|
|
44
40
|
export const getDataValidator = (
|
|
45
|
-
def: JSONSchemaDefinition |
|
|
41
|
+
def: JSONSchemaDefinition | DataSchemaMap,
|
|
46
42
|
validator: Ajv
|
|
47
43
|
): DataValidatorMap => {
|
|
48
44
|
const schema = ((def as any).create ? def : { create: def }) as DataSchemaMap
|
|
@@ -129,14 +125,15 @@ export const queryProperty = <T extends JSONSchema>(def: T) => {
|
|
|
129
125
|
/**
|
|
130
126
|
* Creates Feathers a query syntax compatible JSON schema for multiple properties.
|
|
131
127
|
*
|
|
132
|
-
* @param
|
|
128
|
+
* @param definitions A map of property definitions
|
|
133
129
|
* @returns The JSON schema definition for the Feathers query syntax for multiple properties
|
|
134
130
|
*/
|
|
135
|
-
export const queryProperties = <T extends { [key: string]: JSONSchema }>(
|
|
136
|
-
Object.keys(
|
|
131
|
+
export const queryProperties = <T extends { [key: string]: JSONSchema }>(definitions: T) =>
|
|
132
|
+
Object.keys(definitions).reduce((res, key) => {
|
|
137
133
|
const result = res as any
|
|
134
|
+
const definition = definitions[key]
|
|
138
135
|
|
|
139
|
-
result[key] = queryProperty(definition
|
|
136
|
+
result[key] = queryProperty(definition)
|
|
140
137
|
|
|
141
138
|
return result
|
|
142
139
|
}, {} as { [K in keyof T]: PropertyQuery<T[K]> })
|