@feathersjs/typebox
Advanced tools
Comparing version 5.0.0-pre.30 to 5.0.0-pre.31
@@ -6,2 +6,8 @@ # Change Log | ||
# [5.0.0-pre.31](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.30...v5.0.0-pre.31) (2022-10-12) | ||
### Features | ||
- **cli:** Improve generated schema definitions ([#2783](https://github.com/feathersjs/feathers/issues/2783)) ([474a9fd](https://github.com/feathersjs/feathers/commit/474a9fda2107e9bcf357746320a8e00cda8182b6)) | ||
# [5.0.0-pre.30](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.29...v5.0.0-pre.30) (2022-10-07) | ||
@@ -8,0 +14,0 @@ |
import { TObject, TInteger, TOptional, TSchema, TIntersect } from '@sinclair/typebox'; | ||
import { Validator, DataValidatorMap, Ajv } from '@feathersjs/schema'; | ||
export * from '@sinclair/typebox'; | ||
export * from './default-schemas'; | ||
export declare type TDataSchemaMap = { | ||
create: TObject; | ||
update?: TObject; | ||
patch?: TObject; | ||
}; | ||
/** | ||
* Returns a compiled validation function for a TypeBox object and AJV validator instance. | ||
* | ||
* @param schema The JSON schema definition | ||
* @param validator The AJV validation instance | ||
* @returns A compiled validation function | ||
*/ | ||
export declare const getValidator: <T = any, R = T>(schema: TObject, validator: Ajv) => Validator<T, R>; | ||
/** | ||
* Returns compiled validation functions to validate data for the `create`, `update` and `patch` | ||
* service methods. If not passed explicitly, the `update` validator will be the same as the `create` | ||
* and `patch` will be the `create` validator with no required fields. | ||
* | ||
* @param def Either general TypeBox object definition or a mapping of `create`, `update` and `patch` | ||
* to their respective type object | ||
* @param validator The Ajv instance to use as the validator | ||
* @returns A map of validator functions | ||
*/ | ||
export declare const getDataValidator: (def: TObject | TDataSchemaMap, validator: Ajv) => DataValidatorMap; | ||
export declare function sortDefinition<T extends TObject>(schema: T): TObject<T["properties"] extends infer T_1 ? { [K in keyof T_1]: TOptional<TInteger>; } : never>; | ||
@@ -23,2 +48,9 @@ export declare const queryProperty: <T extends TSchema>(def: T) => TOptional<import("@sinclair/typebox").TUnion<[T, TObject<{ | ||
}>]>>; } : never>; | ||
/** | ||
* Creates a TypeBox schema for the complete Feathers query syntax including `$limit`, $skip` | ||
* and `$sort` and `$select` for the allowed properties. | ||
* | ||
* @param type The properties to create the query syntax for | ||
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties | ||
*/ | ||
export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TObject<import("@sinclair/typebox").TProperties>[]>>(type: T) => TIntersect<[TObject<{ | ||
@@ -25,0 +57,0 @@ $limit: TOptional<import("@sinclair/typebox").TNumber>; |
@@ -17,6 +17,28 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = void 0; | ||
exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = exports.getDataValidator = exports.getValidator = void 0; | ||
const typebox_1 = require("@sinclair/typebox"); | ||
const schema_1 = require("@feathersjs/schema"); | ||
__exportStar(require("@sinclair/typebox"), exports); | ||
__exportStar(require("./default-schemas"), exports); | ||
/** | ||
* Returns a compiled validation function for a TypeBox object and AJV validator instance. | ||
* | ||
* @param schema The JSON schema definition | ||
* @param validator The AJV validation instance | ||
* @returns A compiled validation function | ||
*/ | ||
const getValidator = (schema, validator) => schema_1.jsonSchema.getValidator(schema, validator); | ||
exports.getValidator = getValidator; | ||
/** | ||
* Returns compiled validation functions to validate data for the `create`, `update` and `patch` | ||
* service methods. If not passed explicitly, the `update` validator will be the same as the `create` | ||
* and `patch` will be the `create` validator with no required fields. | ||
* | ||
* @param def Either general TypeBox object definition or a mapping of `create`, `update` and `patch` | ||
* to their respective type object | ||
* @param validator The Ajv instance to use as the validator | ||
* @returns A map of validator functions | ||
*/ | ||
const getDataValidator = (def, validator) => schema_1.jsonSchema.getDataValidator(def, validator); | ||
exports.getDataValidator = getDataValidator; | ||
const arrayOfKeys = (type) => { | ||
@@ -67,2 +89,9 @@ const keys = Object.keys(type.properties); | ||
exports.queryProperties = queryProperties; | ||
/** | ||
* Creates a TypeBox schema for the complete Feathers query syntax including `$limit`, $skip` | ||
* and `$sort` and `$select` for the allowed properties. | ||
* | ||
* @param type The properties to create the query syntax for | ||
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties | ||
*/ | ||
const querySyntax = (type) => { | ||
@@ -69,0 +98,0 @@ return typebox_1.Type.Intersect([ |
{ | ||
"name": "@feathersjs/typebox", | ||
"description": "TypeBox integration for @feathersjs/schema", | ||
"version": "5.0.0-pre.30", | ||
"version": "5.0.0-pre.31", | ||
"homepage": "https://feathersjs.com", | ||
@@ -57,6 +57,6 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/schema": "^5.0.0-pre.31", | ||
"@sinclair/typebox": "^0.24.44" | ||
}, | ||
"devDependencies": { | ||
"@feathersjs/schema": "^5.0.0-pre.30", | ||
"@types/mocha": "^10.0.0", | ||
@@ -68,3 +68,3 @@ "@types/node": "^18.8.2", | ||
}, | ||
"gitHead": "b535c91197f4b997520e0a0e608793eeba791931" | ||
"gitHead": "4500dbeb8cea566678cf88b3313a88efd93a2ed9" | ||
} |
import { Type, TObject, TInteger, TOptional, TSchema, TIntersect } from '@sinclair/typebox' | ||
import { jsonSchema, Validator, DataValidatorMap, Ajv } from '@feathersjs/schema' | ||
@@ -6,2 +7,31 @@ export * from '@sinclair/typebox' | ||
export type TDataSchemaMap = { | ||
create: TObject | ||
update?: TObject | ||
patch?: TObject | ||
} | ||
/** | ||
* Returns a compiled validation function for a TypeBox object and AJV validator instance. | ||
* | ||
* @param schema The JSON schema definition | ||
* @param validator The AJV validation instance | ||
* @returns A compiled validation function | ||
*/ | ||
export const getValidator = <T = any, R = T>(schema: TObject, validator: Ajv): Validator<T, R> => | ||
jsonSchema.getValidator(schema as any, validator) | ||
/** | ||
* Returns compiled validation functions to validate data for the `create`, `update` and `patch` | ||
* service methods. If not passed explicitly, the `update` validator will be the same as the `create` | ||
* and `patch` will be the `create` validator with no required fields. | ||
* | ||
* @param def Either general TypeBox object definition or a mapping of `create`, `update` and `patch` | ||
* to their respective type object | ||
* @param validator The Ajv instance to use as the validator | ||
* @returns A map of validator functions | ||
*/ | ||
export const getDataValidator = (def: TObject | TDataSchemaMap, validator: Ajv): DataValidatorMap => | ||
jsonSchema.getDataValidator(def as any, validator) | ||
const arrayOfKeys = <T extends TObject>(type: T) => { | ||
@@ -63,2 +93,9 @@ const keys = Object.keys(type.properties) | ||
/** | ||
* Creates a TypeBox schema for the complete Feathers query syntax including `$limit`, $skip` | ||
* and `$sort` and `$select` for the allowed properties. | ||
* | ||
* @param type The properties to create the query syntax for | ||
* @returns A TypeBox object representing the complete Feathers query syntax for the given properties | ||
*/ | ||
export const querySyntax = <T extends TObject | TIntersect>(type: T) => { | ||
@@ -65,0 +102,0 @@ return Type.Intersect([ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35620
5
499
2
+ Added@babel/runtime@7.26.0(transitive)
+ Added@feathersjs/adapter-commons@5.0.31(transitive)
+ Added@feathersjs/commons@5.0.31(transitive)
+ Added@feathersjs/errors@5.0.31(transitive)
+ Added@feathersjs/feathers@5.0.31(transitive)
+ Added@feathersjs/hooks@0.9.0(transitive)
+ Added@feathersjs/schema@5.0.31(transitive)
+ Added@types/json-schema@7.0.15(transitive)
+ Addedajv@8.17.1(transitive)
+ Addedajv-formats@3.0.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-uri@3.0.3(transitive)
+ Addedjson-schema-to-ts@3.1.1(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedts-algebra@2.0.0(transitive)
+ Addedtypescript@5.7.2(transitive)