@feathersjs/schema 5.0.0-pre.34 → 5.0.0-pre.35

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 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.35](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.34...v5.0.0-pre.35) (2023-01-12)
7
+
8
+ ### Features
9
+
10
+ - **generators:** Move core code generators to shared generators package ([#2982](https://github.com/feathersjs/feathers/issues/2982)) ([0328d22](https://github.com/feathersjs/feathers/commit/0328d2292153870bc43958f73d2c6f288a8cec17))
11
+ - **schema:** Allow to add additional operators to the query syntax ([#2941](https://github.com/feathersjs/feathers/issues/2941)) ([f324940](https://github.com/feathersjs/feathers/commit/f324940d5795b41e8c6fc113defb0beb7ab03a0a))
12
+
6
13
  # [5.0.0-pre.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
7
14
 
8
15
  ### Bug Fixes
@@ -29,7 +29,7 @@ export declare const getValidator: <T = any, R = T>(schema: JSONSchemaDefinition
29
29
  * @returns A map of validator functions
30
30
  */
31
31
  export declare const getDataValidator: (def: JSONSchemaDefinition | DataSchemaMap, validator: Ajv) => DataValidatorMap;
32
- export type PropertyQuery<D extends JSONSchema> = {
32
+ export type PropertyQuery<D extends JSONSchema, X> = {
33
33
  anyOf: [
34
34
  D,
35
35
  {
@@ -49,7 +49,7 @@ export type PropertyQuery<D extends JSONSchema> = {
49
49
  type: 'array';
50
50
  items: D;
51
51
  };
52
- };
52
+ } & X;
53
53
  }
54
54
  ];
55
55
  };
@@ -57,9 +57,12 @@ export type PropertyQuery<D extends JSONSchema> = {
57
57
  * Create a Feathers query syntax compatible JSON schema definition for a property definition.
58
58
  *
59
59
  * @param def The property definition (e.g. `{ type: 'string' }`)
60
+ * @param extensions Additional properties to add to the query property schema
60
61
  * @returns A JSON schema definition for the Feathers query syntax for this property.
61
62
  */
62
- export declare const queryProperty: <T extends import("json-schema-to-ts").JSONSchema7>(def: T) => {
63
+ export declare const queryProperty: <T extends import("json-schema-to-ts").JSONSchema7, X extends {
64
+ [key: string]: import("json-schema-to-ts").JSONSchema7;
65
+ }>(def: T, extensions?: X) => {
63
66
  readonly anyOf: readonly [any, {
64
67
  readonly type: "object";
65
68
  readonly additionalProperties: false;
@@ -77,29 +80,34 @@ export declare const queryProperty: <T extends import("json-schema-to-ts").JSONS
77
80
  readonly type: "array";
78
81
  readonly items: any;
79
82
  };
80
- };
83
+ } & X;
81
84
  }];
82
85
  };
83
- export declare const SUPPORTED_TYPES: string[];
84
86
  /**
85
87
  * Creates Feathers a query syntax compatible JSON schema for multiple properties.
86
88
  *
87
89
  * @param definitions A map of property definitions
90
+ * @param extensions Additional properties to add to the query property schema
88
91
  * @returns The JSON schema definition for the Feathers query syntax for multiple properties
89
92
  */
90
93
  export declare const queryProperties: <T extends {
91
94
  [key: string]: import("json-schema-to-ts").JSONSchema7;
92
- }>(definitions: T) => { [K in keyof T]: PropertyQuery<T[K]>; };
95
+ }, X extends { [K in keyof T]?: {
96
+ [key: string]: import("json-schema-to-ts").JSONSchema7;
97
+ }; }>(definitions: T, extensions?: X) => { [K_1 in keyof T]: PropertyQuery<T[K_1], X[K_1]>; };
93
98
  /**
94
99
  * Creates a JSON schema for the complete Feathers query syntax including `$limit`, $skip`
95
100
  * and `$sort` and `$select` for the allowed properties.
96
101
  *
97
102
  * @param definition The property definitions to create the query syntax schema for
103
+ * @param extensions Additional properties to add to the query property schema
98
104
  * @returns A JSON schema for the complete query syntax
99
105
  */
100
106
  export declare const querySyntax: <T extends {
101
107
  [key: string]: import("json-schema-to-ts").JSONSchema7;
102
- }>(definition: T) => {
108
+ }, X extends { [K in keyof T]?: {
109
+ [key: string]: import("json-schema-to-ts").JSONSchema7;
110
+ }; }>(definition: T, extensions?: X) => {
103
111
  readonly $limit: {
104
112
  readonly type: "number";
105
113
  readonly minimum: 0;
@@ -110,7 +118,7 @@ export declare const querySyntax: <T extends {
110
118
  };
111
119
  readonly $sort: {
112
120
  readonly type: "object";
113
- readonly properties: { [K in keyof T]: {
121
+ readonly properties: { [K_1 in keyof T]: {
114
122
  readonly type: 'number';
115
123
  readonly enum: [1, -1];
116
124
  }; };
@@ -128,7 +136,7 @@ export declare const querySyntax: <T extends {
128
136
  readonly items: {
129
137
  readonly type: "object";
130
138
  readonly additionalProperties: false;
131
- readonly properties: { [K_1 in keyof T]: PropertyQuery<T[K_1]>; };
139
+ readonly properties: { [K_2 in keyof T]: PropertyQuery<T[K_2], X[K_2]>; };
132
140
  };
133
141
  };
134
- } & { [K_1 in keyof T]: PropertyQuery<T[K_1]>; };
142
+ } & { [K_2 in keyof T]: PropertyQuery<T[K_2], X[K_2]>; };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.querySyntax = exports.queryProperties = exports.SUPPORTED_TYPES = exports.queryProperty = exports.getDataValidator = exports.getValidator = void 0;
3
+ exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.getDataValidator = exports.getValidator = void 0;
4
4
  const commons_1 = require("@feathersjs/commons");
5
5
  /**
6
6
  * Returns a compiled validation function for a schema and AJV validator instance.
@@ -44,9 +44,10 @@ exports.getDataValidator = getDataValidator;
44
44
  * Create a Feathers query syntax compatible JSON schema definition for a property definition.
45
45
  *
46
46
  * @param def The property definition (e.g. `{ type: 'string' }`)
47
+ * @param extensions Additional properties to add to the query property schema
47
48
  * @returns A JSON schema definition for the Feathers query syntax for this property.
48
49
  */
49
- const queryProperty = (def) => {
50
+ const queryProperty = (def, extensions = {}) => {
50
51
  const definition = commons_1._.omit(def, 'default');
51
52
  return {
52
53
  anyOf: [
@@ -67,28 +68,29 @@ const queryProperty = (def) => {
67
68
  $nin: {
68
69
  type: 'array',
69
70
  items: definition
70
- }
71
+ },
72
+ ...extensions
71
73
  }
72
74
  }
73
75
  ]
74
76
  };
75
77
  };
76
78
  exports.queryProperty = queryProperty;
77
- exports.SUPPORTED_TYPES = ['string', 'number', 'integer', 'boolean', 'null'];
78
79
  /**
79
80
  * Creates Feathers a query syntax compatible JSON schema for multiple properties.
80
81
  *
81
82
  * @param definitions A map of property definitions
83
+ * @param extensions Additional properties to add to the query property schema
82
84
  * @returns The JSON schema definition for the Feathers query syntax for multiple properties
83
85
  */
84
- const queryProperties = (definitions) => Object.keys(definitions).reduce((res, key) => {
86
+ const queryProperties = (definitions, extensions = {}) => Object.keys(definitions).reduce((res, key) => {
85
87
  const result = res;
86
88
  const definition = definitions[key];
87
- const { type, $ref } = definition;
88
- if ($ref || !exports.SUPPORTED_TYPES.includes(type)) {
89
- throw new Error(`Can not create query syntax schema for property '${key}'. Only types ${exports.SUPPORTED_TYPES.join(', ')} are allowed.`);
89
+ const { $ref } = definition;
90
+ if ($ref) {
91
+ throw new Error(`Can not create query syntax schema for reference property '${key}'`);
90
92
  }
91
- result[key] = (0, exports.queryProperty)(definition);
93
+ result[key] = (0, exports.queryProperty)(definition, extensions[key]);
92
94
  return result;
93
95
  }, {});
94
96
  exports.queryProperties = queryProperties;
@@ -97,11 +99,12 @@ exports.queryProperties = queryProperties;
97
99
  * and `$sort` and `$select` for the allowed properties.
98
100
  *
99
101
  * @param definition The property definitions to create the query syntax schema for
102
+ * @param extensions Additional properties to add to the query property schema
100
103
  * @returns A JSON schema for the complete query syntax
101
104
  */
102
- const querySyntax = (definition) => {
105
+ const querySyntax = (definition, extensions = {}) => {
103
106
  const keys = Object.keys(definition);
104
- const props = (0, exports.queryProperties)(definition);
107
+ const props = (0, exports.queryProperties)(definition, extensions);
105
108
  return {
106
109
  $limit: {
107
110
  type: 'number',
@@ -1 +1 @@
1
- {"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":";;;AAAA,iDAAuC;AAgBvC;;;;;;GAM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,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBACnC,MAAM,MAAM,GAAG,GAAU,CAAA;gBAEzB,MAAM,CAAC,GAAG,CAAC,GAAG;oBACZ,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;iBACd,CAAA;gBAED,OAAO,MAAM,CAAA;YACf,CAAC,EAAE,EAA6E,CAAC;SAClF;QACD,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,IAAI,CAAC,MAAM;YACrB,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAA0B,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACjE;SACF;QACD,GAAG,EAAE;YACH,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,KAAK;gBAC3B,UAAU,EAAE,KAAK;aAClB;SACF;QACD,GAAG,KAAK;KACA,CAAA;AACZ,CAAC,CAAA;AAlDY,QAAA,WAAW,eAkDvB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@feathersjs/schema",
3
3
  "description": "A common data schema definition format",
4
- "version": "5.0.0-pre.34",
4
+ "version": "5.0.0-pre.35",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -42,7 +42,7 @@
42
42
  ],
43
43
  "scripts": {
44
44
  "prepublish": "npm run compile",
45
- "pack": "npm pack --pack-destination ../cli/test/build",
45
+ "pack": "npm pack --pack-destination ../generators/test/build",
46
46
  "compile": "shx rm -rf lib/ && tsc && npm run pack",
47
47
  "mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
48
48
  "test": "npm run compile && npm run mocha"
@@ -54,24 +54,24 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@feathersjs/adapter-commons": "^5.0.0-pre.34",
58
- "@feathersjs/commons": "^5.0.0-pre.34",
59
- "@feathersjs/errors": "^5.0.0-pre.34",
60
- "@feathersjs/feathers": "^5.0.0-pre.34",
57
+ "@feathersjs/adapter-commons": "^5.0.0-pre.35",
58
+ "@feathersjs/commons": "^5.0.0-pre.35",
59
+ "@feathersjs/errors": "^5.0.0-pre.35",
60
+ "@feathersjs/feathers": "^5.0.0-pre.35",
61
61
  "@feathersjs/hooks": "^0.7.6",
62
62
  "@types/json-schema": "^7.0.11",
63
63
  "ajv": "^8.11.2",
64
64
  "ajv-formats": "^2.1.1",
65
- "json-schema-to-ts": "^2.6.1"
65
+ "json-schema-to-ts": "^2.6.2"
66
66
  },
67
67
  "devDependencies": {
68
- "@feathersjs/memory": "^5.0.0-pre.34",
68
+ "@feathersjs/memory": "^5.0.0-pre.35",
69
69
  "@types/mocha": "^10.0.1",
70
- "@types/node": "^18.11.10",
70
+ "@types/node": "^18.11.18",
71
71
  "ajv-formats": "^2.1.1",
72
- "mocha": "^10.1.0",
72
+ "mocha": "^10.2.0",
73
73
  "shx": "^0.3.4",
74
- "typescript": "^4.9.3"
74
+ "typescript": "^4.9.4"
75
75
  },
76
- "gitHead": "42cca600d00f0b3b9d89fa79be30fcd46bc50132"
76
+ "gitHead": "c641598d9a4de3ceda10f56cf2af288a4236b15e"
77
77
  }
@@ -63,7 +63,7 @@ export const getDataValidator = (
63
63
  }
64
64
  }
65
65
 
66
- export type PropertyQuery<D extends JSONSchema> = {
66
+ export type PropertyQuery<D extends JSONSchema, X> = {
67
67
  anyOf: [
68
68
  D,
69
69
  {
@@ -83,7 +83,7 @@ export type PropertyQuery<D extends JSONSchema> = {
83
83
  type: 'array'
84
84
  items: D
85
85
  }
86
- }
86
+ } & X
87
87
  }
88
88
  ]
89
89
  }
@@ -92,9 +92,13 @@ export type PropertyQuery<D extends JSONSchema> = {
92
92
  * Create a Feathers query syntax compatible JSON schema definition for a property definition.
93
93
  *
94
94
  * @param def The property definition (e.g. `{ type: 'string' }`)
95
+ * @param extensions Additional properties to add to the query property schema
95
96
  * @returns A JSON schema definition for the Feathers query syntax for this property.
96
97
  */
97
- export const queryProperty = <T extends JSONSchema>(def: T) => {
98
+ export const queryProperty = <T extends JSONSchema, X extends { [key: string]: JSONSchema }>(
99
+ def: T,
100
+ extensions: X = {} as X
101
+ ) => {
98
102
  const definition = _.omit(def, 'default')
99
103
  return {
100
104
  anyOf: [
@@ -115,50 +119,59 @@ export const queryProperty = <T extends JSONSchema>(def: T) => {
115
119
  $nin: {
116
120
  type: 'array',
117
121
  items: definition
118
- }
122
+ },
123
+ ...extensions
119
124
  }
120
125
  }
121
126
  ]
122
127
  } as const
123
128
  }
124
129
 
125
- export const SUPPORTED_TYPES = ['string', 'number', 'integer', 'boolean', 'null']
126
-
127
130
  /**
128
131
  * Creates Feathers a query syntax compatible JSON schema for multiple properties.
129
132
  *
130
133
  * @param definitions A map of property definitions
134
+ * @param extensions Additional properties to add to the query property schema
131
135
  * @returns The JSON schema definition for the Feathers query syntax for multiple properties
132
136
  */
133
- export const queryProperties = <T extends { [key: string]: JSONSchema }>(definitions: T) =>
137
+ export const queryProperties = <
138
+ T extends { [key: string]: JSONSchema },
139
+ X extends { [K in keyof T]?: { [key: string]: JSONSchema } }
140
+ >(
141
+ definitions: T,
142
+ extensions: X = {} as X
143
+ ) =>
134
144
  Object.keys(definitions).reduce((res, key) => {
135
145
  const result = res as any
136
146
  const definition = definitions[key]
137
- const { type, $ref } = definition as any
147
+ const { $ref } = definition as any
138
148
 
139
- if ($ref || !SUPPORTED_TYPES.includes(type)) {
140
- throw new Error(
141
- `Can not create query syntax schema for property '${key}'. Only types ${SUPPORTED_TYPES.join(
142
- ', '
143
- )} are allowed.`
144
- )
149
+ if ($ref) {
150
+ throw new Error(`Can not create query syntax schema for reference property '${key}'`)
145
151
  }
146
152
 
147
- result[key] = queryProperty(definition)
153
+ result[key] = queryProperty(definition as JSONSchemaDefinition, extensions[key as keyof T])
148
154
 
149
155
  return result
150
- }, {} as { [K in keyof T]: PropertyQuery<T[K]> })
156
+ }, {} as { [K in keyof T]: PropertyQuery<T[K], X[K]> })
151
157
 
152
158
  /**
153
159
  * Creates a JSON schema for the complete Feathers query syntax including `$limit`, $skip`
154
160
  * and `$sort` and `$select` for the allowed properties.
155
161
  *
156
162
  * @param definition The property definitions to create the query syntax schema for
163
+ * @param extensions Additional properties to add to the query property schema
157
164
  * @returns A JSON schema for the complete query syntax
158
165
  */
159
- export const querySyntax = <T extends { [key: string]: JSONSchema }>(definition: T) => {
166
+ export const querySyntax = <
167
+ T extends { [key: string]: JSONSchema },
168
+ X extends { [K in keyof T]?: { [key: string]: JSONSchema } }
169
+ >(
170
+ definition: T,
171
+ extensions: X = {} as X
172
+ ) => {
160
173
  const keys = Object.keys(definition)
161
- const props = queryProperties(definition)
174
+ const props = queryProperties(definition, extensions)
162
175
 
163
176
  return {
164
177
  $limit: {