@feathersjs/typebox 5.0.0-pre.30

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 ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [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
+
8
+ ### Features
9
+
10
+ - **schema:** Make schemas validation library independent and add TypeBox support ([#2772](https://github.com/feathersjs/feathers/issues/2772)) ([44172d9](https://github.com/feathersjs/feathers/commit/44172d99b566d11d9ceda04f1d0bf72b6d05ce76))
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Feathers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @feathersjs/typebox
2
+
3
+ [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
4
+ [![Download Status](https://img.shields.io/npm/dm/@feathersjs/typebox.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/typebox)
5
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
6
+
7
+ > [TypeBox](https://github.com/sinclairzx81/typebox) integration for @feathersjs/schema
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ npm install @feathersjs/typebox --save
13
+ ```
14
+
15
+ ## Documentation
16
+
17
+ Refer to the [Feathers documentation](https://docs.feathersjs.com) for more details.
18
+
19
+ ## License
20
+
21
+ Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
+
23
+ Licensed under the [MIT license](LICENSE).
@@ -0,0 +1,88 @@
1
+ import { Static } from '@sinclair/typebox';
2
+ export declare const authenticationSettingsSchema: import("@sinclair/typebox").TObject<{
3
+ secret: import("@sinclair/typebox").TString<string>;
4
+ entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
5
+ entityId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
6
+ service: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
7
+ authStrategies: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>;
8
+ parseStrategies: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>>;
9
+ jwtOptions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{}>>;
10
+ jwt: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
11
+ header: import("@sinclair/typebox").TString<string>;
12
+ schemes: import("@sinclair/typebox").TString<string>;
13
+ }>>;
14
+ local: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
15
+ usernameField: import("@sinclair/typebox").TString<string>;
16
+ passwordField: import("@sinclair/typebox").TString<string>;
17
+ hashSize: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
18
+ errorMessage: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
19
+ entityUsernameField: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
20
+ entityPasswordField: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
21
+ }>>;
22
+ oauth: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
23
+ redirect: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
24
+ origins: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>>;
25
+ defaults: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
26
+ key: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
27
+ secret: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
28
+ }>>;
29
+ }>>;
30
+ }>;
31
+ export declare const sqlSettingsSchema: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
32
+ client: import("@sinclair/typebox").TString<string>;
33
+ connection: import("@sinclair/typebox").TString<string>;
34
+ }>>;
35
+ export declare const defaultAppConfiguration: import("@sinclair/typebox").TObject<{
36
+ authentication: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
37
+ secret: import("@sinclair/typebox").TString<string>;
38
+ entity: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
39
+ entityId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
40
+ service: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
41
+ authStrategies: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>;
42
+ parseStrategies: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>>;
43
+ jwtOptions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{}>>;
44
+ jwt: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
45
+ header: import("@sinclair/typebox").TString<string>;
46
+ schemes: import("@sinclair/typebox").TString<string>;
47
+ }>>;
48
+ local: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
49
+ usernameField: import("@sinclair/typebox").TString<string>;
50
+ passwordField: import("@sinclair/typebox").TString<string>;
51
+ hashSize: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
52
+ errorMessage: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
53
+ entityUsernameField: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
54
+ entityPasswordField: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
55
+ }>>;
56
+ oauth: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
57
+ redirect: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
58
+ origins: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>>;
59
+ defaults: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
60
+ key: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
61
+ secret: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
62
+ }>>;
63
+ }>>;
64
+ }>>;
65
+ paginate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
66
+ default: import("@sinclair/typebox").TNumber;
67
+ max: import("@sinclair/typebox").TNumber;
68
+ }>>;
69
+ origins: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString<string>>>;
70
+ mongodb: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString<string>>;
71
+ mysql: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
72
+ client: import("@sinclair/typebox").TString<string>;
73
+ connection: import("@sinclair/typebox").TString<string>;
74
+ }>>;
75
+ postgresql: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
76
+ client: import("@sinclair/typebox").TString<string>;
77
+ connection: import("@sinclair/typebox").TString<string>;
78
+ }>>;
79
+ sqlite: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
80
+ client: import("@sinclair/typebox").TString<string>;
81
+ connection: import("@sinclair/typebox").TString<string>;
82
+ }>>;
83
+ mssql: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
84
+ client: import("@sinclair/typebox").TString<string>;
85
+ connection: import("@sinclair/typebox").TString<string>;
86
+ }>>;
87
+ }>;
88
+ export declare type DefaultAppConfiguration = Static<typeof defaultAppConfiguration>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultAppConfiguration = exports.sqlSettingsSchema = exports.authenticationSettingsSchema = void 0;
4
+ const typebox_1 = require("@sinclair/typebox");
5
+ exports.authenticationSettingsSchema = typebox_1.Type.Object({
6
+ secret: typebox_1.Type.String({ description: 'The JWT signing secret' }),
7
+ entity: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'The name of the authentication entity (e.g. user)' })),
8
+ entityId: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'The name of the authentication entity id property' })),
9
+ service: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'The path of the entity service' })),
10
+ authStrategies: typebox_1.Type.Array(typebox_1.Type.String(), {
11
+ description: 'A list of authentication strategy names that are allowed to create JWT access tokens'
12
+ }),
13
+ parseStrategies: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String(), {
14
+ description: 'A list of authentication strategy names that should parse HTTP headers for authentication information (defaults to `authStrategies`)'
15
+ })),
16
+ jwtOptions: typebox_1.Type.Optional(typebox_1.Type.Object({})),
17
+ jwt: typebox_1.Type.Optional(typebox_1.Type.Object({
18
+ header: typebox_1.Type.String({ default: 'Authorization', description: 'The HTTP header containing the JWT' }),
19
+ schemes: typebox_1.Type.String({ description: 'An array of schemes to support' })
20
+ })),
21
+ local: typebox_1.Type.Optional(typebox_1.Type.Object({
22
+ usernameField: typebox_1.Type.String({ description: 'Name of the username field (e.g. `email`)' }),
23
+ passwordField: typebox_1.Type.String({ description: 'Name of the password field (e.g. `password`)' }),
24
+ hashSize: typebox_1.Type.Optional(typebox_1.Type.Number({ description: 'The BCrypt salt length' })),
25
+ errorMessage: typebox_1.Type.Optional(typebox_1.Type.String({ description: 'The error message to return on errors' })),
26
+ entityUsernameField: typebox_1.Type.Optional(typebox_1.Type.String({
27
+ description: 'Name of the username field on the entity if authentication request data and entity field names are different'
28
+ })),
29
+ entityPasswordField: typebox_1.Type.Optional(typebox_1.Type.String({
30
+ description: 'Name of the password field on the entity if authentication request data and entity field names are different'
31
+ }))
32
+ })),
33
+ oauth: typebox_1.Type.Optional(typebox_1.Type.Object({
34
+ redirect: typebox_1.Type.Optional(typebox_1.Type.String()),
35
+ origins: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String())),
36
+ defaults: typebox_1.Type.Optional(typebox_1.Type.Object({
37
+ key: typebox_1.Type.Optional(typebox_1.Type.String()),
38
+ secret: typebox_1.Type.Optional(typebox_1.Type.String())
39
+ }))
40
+ }))
41
+ });
42
+ exports.sqlSettingsSchema = typebox_1.Type.Optional(typebox_1.Type.Object({
43
+ client: typebox_1.Type.String(),
44
+ connection: typebox_1.Type.String()
45
+ }));
46
+ exports.defaultAppConfiguration = typebox_1.Type.Object({
47
+ authentication: typebox_1.Type.Optional(exports.authenticationSettingsSchema),
48
+ paginate: typebox_1.Type.Optional(typebox_1.Type.Object({
49
+ default: typebox_1.Type.Number(),
50
+ max: typebox_1.Type.Number()
51
+ }, { additionalProperties: false })),
52
+ origins: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String())),
53
+ mongodb: typebox_1.Type.Optional(typebox_1.Type.String()),
54
+ mysql: exports.sqlSettingsSchema,
55
+ postgresql: exports.sqlSettingsSchema,
56
+ sqlite: exports.sqlSettingsSchema,
57
+ mssql: exports.sqlSettingsSchema
58
+ }, { $id: 'ApplicationConfiguration', additionalProperties: false });
59
+ //# sourceMappingURL=default-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-schemas.js","sourceRoot":"","sources":["../src/default-schemas.ts"],"names":[],"mappings":";;;AAAA,+CAAgD;AAEnC,QAAA,4BAA4B,GAAG,cAAI,CAAC,MAAM,CAAC;IACtD,MAAM,EAAE,cAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;IAC9D,MAAM,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mDAAmD,EAAE,CAAC,CAAC;IACxG,QAAQ,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,mDAAmD,EAAE,CAAC,CAAC;IAC1G,OAAO,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC,CAAC;IACtF,cAAc,EAAE,cAAI,CAAC,KAAK,CAAC,cAAI,CAAC,MAAM,EAAE,EAAE;QACxC,WAAW,EAAE,sFAAsF;KACpG,CAAC;IACF,eAAe,EAAE,cAAI,CAAC,QAAQ,CAC5B,cAAI,CAAC,KAAK,CAAC,cAAI,CAAC,MAAM,EAAE,EAAE;QACxB,WAAW,EACT,sIAAsI;KACzI,CAAC,CACH;IACD,UAAU,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1C,GAAG,EAAE,cAAI,CAAC,QAAQ,CAChB,cAAI,CAAC,MAAM,CAAC;QACV,MAAM,EAAE,cAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,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,CAAC,cAAI,CAAC,MAAM,EAAE,CAAC;SACrC,CAAC,CACH;KACF,CAAC,CACH;CACF,CAAC,CAAA;AAEW,QAAA,iBAAiB,GAAG,cAAI,CAAC,QAAQ,CAC5C,cAAI,CAAC,MAAM,CAAC;IACV,MAAM,EAAE,cAAI,CAAC,MAAM,EAAE;IACrB,UAAU,EAAE,cAAI,CAAC,MAAM,EAAE;CAC1B,CAAC,CACH,CAAA;AAEY,QAAA,uBAAuB,GAAG,cAAI,CAAC,MAAM,CAChD;IACE,cAAc,EAAE,cAAI,CAAC,QAAQ,CAAC,oCAA4B,CAAC;IAC3D,QAAQ,EAAE,cAAI,CAAC,QAAQ,CACrB,cAAI,CAAC,MAAM,CACT;QACE,OAAO,EAAE,cAAI,CAAC,MAAM,EAAE;QACtB,GAAG,EAAE,cAAI,CAAC,MAAM,EAAE;KACnB,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAChC,CACF;IACD,OAAO,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,KAAK,CAAC,cAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,OAAO,EAAE,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,MAAM,EAAE,CAAC;IACrC,KAAK,EAAE,yBAAiB;IACxB,UAAU,EAAE,yBAAiB;IAC7B,MAAM,EAAE,yBAAiB;IACzB,KAAK,EAAE,yBAAiB;CACzB,EACD,EAAE,GAAG,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,KAAK,EAAE,CACjE,CAAA"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { TObject, TInteger, TOptional, TSchema, TIntersect } from '@sinclair/typebox';
2
+ export * from '@sinclair/typebox';
3
+ export * from './default-schemas';
4
+ export declare function sortDefinition<T extends TObject>(schema: T): TObject<T["properties"] extends infer T_1 ? { [K in keyof T_1]: TOptional<TInteger>; } : never>;
5
+ export declare const queryProperty: <T extends TSchema>(def: T) => TOptional<import("@sinclair/typebox").TUnion<[T, TObject<{
6
+ $gt: TOptional<T>;
7
+ $gte: TOptional<T>;
8
+ $lt: TOptional<T>;
9
+ $lte: TOptional<T>;
10
+ $ne: TOptional<T>;
11
+ $in: TOptional<import("@sinclair/typebox").TArray<T>>;
12
+ $nin: TOptional<import("@sinclair/typebox").TArray<T>>;
13
+ }>]>>;
14
+ export declare const queryProperties: <T extends TObject<import("@sinclair/typebox").TProperties>>(type: T) => TObject<T["properties"] extends infer T_1 ? { [K in keyof T_1]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K], TObject<{
15
+ $gt: TOptional<T["properties"][K]>;
16
+ $gte: TOptional<T["properties"][K]>;
17
+ $lt: TOptional<T["properties"][K]>;
18
+ $lte: TOptional<T["properties"][K]>;
19
+ $ne: TOptional<T["properties"][K]>;
20
+ $in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K]>>;
21
+ $nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K]>>;
22
+ }>]>>; } : never>;
23
+ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TObject<import("@sinclair/typebox").TProperties>[]>>(type: T) => TIntersect<[TObject<{
24
+ $limit: TOptional<import("@sinclair/typebox").TNumber>;
25
+ $skip: TOptional<import("@sinclair/typebox").TNumber>;
26
+ $sort: TOptional<TObject<T["properties"] extends infer T_1 ? { [K in keyof T_1]: TOptional<TInteger>; } : never>>;
27
+ $select: TOptional<import("@sinclair/typebox").TUnsafe<(keyof T["properties"])[]>>;
28
+ }>, TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_1], TObject<{
29
+ $gt: TOptional<T["properties"][K_1]>;
30
+ $gte: TOptional<T["properties"][K_1]>;
31
+ $lt: TOptional<T["properties"][K_1]>;
32
+ $lte: TOptional<T["properties"][K_1]>;
33
+ $ne: TOptional<T["properties"][K_1]>;
34
+ $in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_1]>>;
35
+ $nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_1]>>;
36
+ }>]>>; } : never>]>;
package/lib/index.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = void 0;
18
+ const typebox_1 = require("@sinclair/typebox");
19
+ __exportStar(require("@sinclair/typebox"), exports);
20
+ __exportStar(require("./default-schemas"), exports);
21
+ const arrayOfKeys = (type) => {
22
+ const keys = Object.keys(type.properties);
23
+ return typebox_1.Type.Unsafe({ type: 'array', items: { type: 'string', enum: keys } });
24
+ };
25
+ function sortDefinition(schema) {
26
+ const properties = Object.keys(schema.properties).reduce((res, key) => {
27
+ const result = res;
28
+ result[key] = typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: -1, maximum: 1 }));
29
+ return result;
30
+ }, {});
31
+ return {
32
+ type: 'object',
33
+ additionalProperties: false,
34
+ properties
35
+ };
36
+ }
37
+ exports.sortDefinition = sortDefinition;
38
+ const queryProperty = (def) => {
39
+ return typebox_1.Type.Optional(typebox_1.Type.Union([
40
+ def,
41
+ typebox_1.Type.Object({
42
+ $gt: typebox_1.Type.Optional(def),
43
+ $gte: typebox_1.Type.Optional(def),
44
+ $lt: typebox_1.Type.Optional(def),
45
+ $lte: typebox_1.Type.Optional(def),
46
+ $ne: typebox_1.Type.Optional(def),
47
+ $in: typebox_1.Type.Optional(typebox_1.Type.Array(def)),
48
+ $nin: typebox_1.Type.Optional(typebox_1.Type.Array(def))
49
+ })
50
+ ]));
51
+ };
52
+ exports.queryProperty = queryProperty;
53
+ const queryProperties = (type) => {
54
+ const properties = Object.keys(type.properties).reduce((res, key) => {
55
+ const result = res;
56
+ result[key] = (0, exports.queryProperty)(type.properties[key]);
57
+ return result;
58
+ }, {});
59
+ return {
60
+ type: 'object',
61
+ additionalProperties: false,
62
+ properties
63
+ };
64
+ };
65
+ exports.queryProperties = queryProperties;
66
+ const querySyntax = (type) => {
67
+ return typebox_1.Type.Intersect([
68
+ typebox_1.Type.Object({
69
+ $limit: typebox_1.Type.Optional(typebox_1.Type.Number({ minimum: 0 })),
70
+ $skip: typebox_1.Type.Optional(typebox_1.Type.Number({ minimum: 0 })),
71
+ $sort: typebox_1.Type.Optional(sortDefinition(type)),
72
+ $select: typebox_1.Type.Optional(arrayOfKeys(type))
73
+ }, { additionalProperties: false }),
74
+ (0, exports.queryProperties)(type)
75
+ ]);
76
+ };
77
+ exports.querySyntax = querySyntax;
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA2F;AAE3F,oDAAiC;AACjC,oDAAiC;AAEjC,MAAM,WAAW,GAAG,CAAoB,IAAO,EAAE,EAAE;IACjD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACzC,OAAO,cAAI,CAAC,MAAM,CAA4B,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;AACzG,CAAC,CAAA;AAED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+ "homepage": "https://feathersjs.com",
6
+ "main": "lib/",
7
+ "types": "lib/",
8
+ "keywords": [
9
+ "feathers",
10
+ "feathers-plugin"
11
+ ],
12
+ "license": "MIT",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/daffl"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git://github.com/feathersjs/feathers.git",
20
+ "directory": "packages/schema"
21
+ },
22
+ "author": {
23
+ "name": "Feathers contributors",
24
+ "email": "hello@feathersjs.com",
25
+ "url": "https://feathersjs.com"
26
+ },
27
+ "contributors": [],
28
+ "bugs": {
29
+ "url": "https://github.com/feathersjs/feathers/issues"
30
+ },
31
+ "engines": {
32
+ "node": ">= 12"
33
+ },
34
+ "files": [
35
+ "CHANGELOG.md",
36
+ "LICENSE",
37
+ "README.md",
38
+ "src/**",
39
+ "lib/**",
40
+ "*.d.ts",
41
+ "*.js"
42
+ ],
43
+ "scripts": {
44
+ "prepublish": "npm run compile",
45
+ "pack": "npm pack --pack-destination ../cli/test/build",
46
+ "compile": "shx rm -rf lib/ && tsc && npm run pack",
47
+ "mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
48
+ "test": "npm run compile && npm run mocha"
49
+ },
50
+ "directories": {
51
+ "lib": "lib"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "dependencies": {
57
+ "@sinclair/typebox": "^0.24.44"
58
+ },
59
+ "devDependencies": {
60
+ "@feathersjs/schema": "^5.0.0-pre.30",
61
+ "@types/mocha": "^10.0.0",
62
+ "@types/node": "^18.8.2",
63
+ "mocha": "^10.0.0",
64
+ "shx": "^0.3.4",
65
+ "typescript": "^4.8.4"
66
+ },
67
+ "gitHead": "b535c91197f4b997520e0a0e608793eeba791931"
68
+ }
@@ -0,0 +1,87 @@
1
+ import { Type, Static } from '@sinclair/typebox'
2
+
3
+ export const authenticationSettingsSchema = Type.Object({
4
+ secret: Type.String({ description: 'The JWT signing secret' }),
5
+ entity: Type.Optional(Type.String({ description: 'The name of the authentication entity (e.g. user)' })),
6
+ entityId: Type.Optional(Type.String({ description: 'The name of the authentication entity id property' })),
7
+ service: Type.Optional(Type.String({ description: 'The path of the entity service' })),
8
+ authStrategies: Type.Array(Type.String(), {
9
+ description: 'A list of authentication strategy names that are allowed to create JWT access tokens'
10
+ }),
11
+ parseStrategies: Type.Optional(
12
+ Type.Array(Type.String(), {
13
+ description:
14
+ 'A list of authentication strategy names that should parse HTTP headers for authentication information (defaults to `authStrategies`)'
15
+ })
16
+ ),
17
+ jwtOptions: Type.Optional(Type.Object({})),
18
+ jwt: Type.Optional(
19
+ Type.Object({
20
+ header: Type.String({ default: 'Authorization', description: 'The HTTP header containing the JWT' }),
21
+ schemes: Type.String({ description: 'An array of schemes to support' })
22
+ })
23
+ ),
24
+ local: Type.Optional(
25
+ Type.Object({
26
+ usernameField: Type.String({ description: 'Name of the username field (e.g. `email`)' }),
27
+ passwordField: Type.String({ description: 'Name of the password field (e.g. `password`)' }),
28
+ hashSize: Type.Optional(Type.Number({ description: 'The BCrypt salt length' })),
29
+ errorMessage: Type.Optional(Type.String({ description: 'The error message to return on errors' })),
30
+ entityUsernameField: Type.Optional(
31
+ Type.String({
32
+ description:
33
+ 'Name of the username field on the entity if authentication request data and entity field names are different'
34
+ })
35
+ ),
36
+ entityPasswordField: Type.Optional(
37
+ Type.String({
38
+ description:
39
+ 'Name of the password field on the entity if authentication request data and entity field names are different'
40
+ })
41
+ )
42
+ })
43
+ ),
44
+ oauth: Type.Optional(
45
+ Type.Object({
46
+ redirect: Type.Optional(Type.String()),
47
+ origins: Type.Optional(Type.Array(Type.String())),
48
+ defaults: Type.Optional(
49
+ Type.Object({
50
+ key: Type.Optional(Type.String()),
51
+ secret: Type.Optional(Type.String())
52
+ })
53
+ )
54
+ })
55
+ )
56
+ })
57
+
58
+ export const sqlSettingsSchema = Type.Optional(
59
+ Type.Object({
60
+ client: Type.String(),
61
+ connection: Type.String()
62
+ })
63
+ )
64
+
65
+ export const defaultAppConfiguration = Type.Object(
66
+ {
67
+ authentication: Type.Optional(authenticationSettingsSchema),
68
+ paginate: Type.Optional(
69
+ Type.Object(
70
+ {
71
+ default: Type.Number(),
72
+ max: Type.Number()
73
+ },
74
+ { additionalProperties: false }
75
+ )
76
+ ),
77
+ origins: Type.Optional(Type.Array(Type.String())),
78
+ mongodb: Type.Optional(Type.String()),
79
+ mysql: sqlSettingsSchema,
80
+ postgresql: sqlSettingsSchema,
81
+ sqlite: sqlSettingsSchema,
82
+ mssql: sqlSettingsSchema
83
+ },
84
+ { $id: 'ApplicationConfiguration', additionalProperties: false }
85
+ )
86
+
87
+ export type DefaultAppConfiguration = Static<typeof defaultAppConfiguration>
package/src/index.ts ADDED
@@ -0,0 +1,75 @@
1
+ import { Type, TObject, TInteger, TOptional, TSchema, TIntersect } from '@sinclair/typebox'
2
+
3
+ export * from '@sinclair/typebox'
4
+ export * from './default-schemas'
5
+
6
+ const arrayOfKeys = <T extends TObject>(type: T) => {
7
+ const keys = Object.keys(type.properties)
8
+ return Type.Unsafe<(keyof T['properties'])[]>({ type: 'array', items: { type: 'string', enum: keys } })
9
+ }
10
+
11
+ export function sortDefinition<T extends TObject>(schema: T) {
12
+ const properties = Object.keys(schema.properties).reduce((res, key) => {
13
+ const result = res as any
14
+
15
+ result[key] = Type.Optional(Type.Integer({ minimum: -1, maximum: 1 }))
16
+
17
+ return result
18
+ }, {} as { [K in keyof T['properties']]: TOptional<TInteger> })
19
+
20
+ return {
21
+ type: 'object',
22
+ additionalProperties: false,
23
+ properties
24
+ } as TObject<typeof properties>
25
+ }
26
+
27
+ export const queryProperty = <T extends TSchema>(def: T) => {
28
+ return Type.Optional(
29
+ Type.Union([
30
+ def,
31
+ Type.Object({
32
+ $gt: Type.Optional(def),
33
+ $gte: Type.Optional(def),
34
+ $lt: Type.Optional(def),
35
+ $lte: Type.Optional(def),
36
+ $ne: Type.Optional(def),
37
+ $in: Type.Optional(Type.Array(def)),
38
+ $nin: Type.Optional(Type.Array(def))
39
+ })
40
+ ])
41
+ )
42
+ }
43
+
44
+ type QueryProperty<T extends TSchema> = ReturnType<typeof queryProperty<T>>
45
+
46
+ export const queryProperties = <T extends TObject>(type: T) => {
47
+ const properties = Object.keys(type.properties).reduce((res, key) => {
48
+ const result = res as any
49
+
50
+ result[key] = queryProperty(type.properties[key])
51
+
52
+ return result
53
+ }, {} as { [K in keyof T['properties']]: QueryProperty<T['properties'][K]> })
54
+
55
+ return {
56
+ type: 'object',
57
+ additionalProperties: false,
58
+ properties
59
+ } as TObject<typeof properties>
60
+ }
61
+
62
+ export const querySyntax = <T extends TObject | TIntersect>(type: T) => {
63
+ return Type.Intersect([
64
+ Type.Object(
65
+ {
66
+ $limit: Type.Optional(Type.Number({ minimum: 0 })),
67
+ $skip: Type.Optional(Type.Number({ minimum: 0 })),
68
+ $sort: Type.Optional(sortDefinition(type)),
69
+ $select: Type.Optional(arrayOfKeys(type))
70
+ },
71
+ { additionalProperties: false }
72
+ ),
73
+ queryProperties(type)
74
+ ])
75
+ }