@feathersjs/typebox 5.0.3 → 5.0.4

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.4](https://github.com/feathersjs/feathers/compare/v5.0.3...v5.0.4) (2023-04-12)
7
+
8
+ ### Bug Fixes
9
+
10
+ - Make sure all Readme files are up to date ([#3154](https://github.com/feathersjs/feathers/issues/3154)) ([a5f0b38](https://github.com/feathersjs/feathers/commit/a5f0b38bbf2a11486415a39533bcc6c67fb51e3e))
11
+ - **typebox:** Implement custom TypeBuilder for backwards compatibility ([#3150](https://github.com/feathersjs/feathers/issues/3150)) ([962bd87](https://github.com/feathersjs/feathers/commit/962bd87217212320b1a68f6556a16b8a6b8f757c))
12
+
6
13
  ## [5.0.3](https://github.com/feathersjs/feathers/compare/v5.0.2...v5.0.3) (2023-04-05)
7
14
 
8
15
  ### Bug Fixes
package/README.md CHANGED
@@ -14,7 +14,7 @@ npm install @feathersjs/typebox --save
14
14
 
15
15
  ## Documentation
16
16
 
17
- Refer to the [Feathers documentation](https://docs.feathersjs.com) for more details.
17
+ Refer to the [Feathers TypeBox documentation](https://feathersjs.com/api/schema/typebox.html) for more details.
18
18
 
19
19
  ## License
20
20
 
package/lib/index.d.ts CHANGED
@@ -1,12 +1,22 @@
1
- import { TObject, TInteger, TOptional, TSchema, TIntersect, ObjectOptions } from '@sinclair/typebox';
1
+ import { TObject, TInteger, TOptional, TSchema, TIntersect, ObjectOptions, ExtendedTypeBuilder, SchemaOptions, TNever, IntersectOptions } from '@sinclair/typebox';
2
2
  import { Validator, DataValidatorMap, Ajv } from '@feathersjs/schema';
3
3
  export * from '@sinclair/typebox';
4
4
  export * from './default-schemas';
5
- export declare const Intersect: {
6
- (allOf: [], options?: import("@sinclair/typebox").SchemaOptions): import("@sinclair/typebox").TNever;
7
- <T extends [TSchema]>(allOf: [...T], options?: import("@sinclair/typebox").SchemaOptions): T[0];
8
- <T_1 extends TSchema[]>(allOf: [...T_1], options?: import("@sinclair/typebox").IntersectOptions): TIntersect<T_1>;
9
- };
5
+ /**
6
+ * Feathers TypeBox customisations. Implements the 0.25.0 fallback for Intersect types.
7
+ * @see https://github.com/sinclairzx81/typebox/issues/373
8
+ */
9
+ export declare class FeathersTypeBuilder extends ExtendedTypeBuilder {
10
+ /** `[Standard]` Creates a Intersect type */
11
+ Intersect(allOf: [], options?: SchemaOptions): TNever;
12
+ /** `[Standard]` Creates a Intersect type */
13
+ Intersect<T extends [TObject]>(allOf: [...T], options?: SchemaOptions): T[0];
14
+ Intersect<T extends TObject[]>(allOf: [...T], options?: IntersectOptions): TIntersect<T>;
15
+ }
16
+ /**
17
+ * Exports our own type builder
18
+ */
19
+ export declare const Type: FeathersTypeBuilder;
10
20
  export type TDataSchemaMap = {
11
21
  create: TObject;
12
22
  update?: TObject;
@@ -54,7 +64,7 @@ export declare function sortDefinition<T extends TObject | TIntersect>(schema: T
54
64
  */
55
65
  export declare const queryProperty: <T extends TSchema, X extends {
56
66
  [key: string]: TSchema;
57
- }>(def: T, extension?: X) => TOptional<import("@sinclair/typebox").TUnion<[T, TIntersect<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
67
+ }>(def: T, extension?: X) => TOptional<import("@sinclair/typebox").TUnion<[T, import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
58
68
  $gt: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
59
69
  $gte: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
60
70
  $lt: T extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T>;
@@ -72,7 +82,7 @@ export declare const queryProperty: <T extends TSchema, X extends {
72
82
  */
73
83
  export declare const queryProperties: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TSchema[]>, X extends T["properties"] extends infer T_1 ? { [K in keyof T_1]?: {
74
84
  [key: string]: TSchema;
75
- }; } : never>(definition: T, extensions?: X) => TOptional<TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_1], TIntersect<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
85
+ }; } : never>(definition: T, extensions?: X) => TOptional<TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_1], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
76
86
  $gt: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
77
87
  $gte: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
78
88
  $lt: T["properties"][K_1] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_1] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_1] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_1]>;
@@ -92,12 +102,12 @@ export declare const queryProperties: <T extends TObject<import("@sinclair/typeb
92
102
  */
93
103
  export declare const querySyntax: <T extends TObject<import("@sinclair/typebox").TProperties> | TIntersect<TSchema[]>, X extends T["properties"] extends infer T_1 ? { [K in keyof T_1]?: {
94
104
  [key: string]: TSchema;
95
- }; } : never>(type: T, extensions?: X, options?: ObjectOptions) => TIntersect<[TObject<{
105
+ }; } : never>(type: T, extensions?: X, options?: ObjectOptions) => import("@sinclair/typebox").TComposite<[TObject<{
96
106
  $limit: TOptional<import("@sinclair/typebox").TNumber>;
97
107
  $skip: TOptional<import("@sinclair/typebox").TNumber>;
98
108
  $sort: TOptional<TObject<T["properties"] extends infer T_2 ? { [K_1 in keyof T_2]: TOptional<TInteger>; } : never>>;
99
109
  $select: TOptional<import("@sinclair/typebox").TUnsafe<(keyof T["properties"])[]>>;
100
- $and: TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[TOptional<TObject<T["properties"] extends infer T_3 ? { [K_2 in keyof T_3]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], TIntersect<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
110
+ $and: TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[TOptional<TObject<T["properties"] extends infer T_3 ? { [K_2 in keyof T_3]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
101
111
  $gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
102
112
  $gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
103
113
  $lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
@@ -106,7 +116,7 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
106
116
  $in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
107
117
  $nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
108
118
  }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_4 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_4]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>, TObject<{
109
- $or: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer T_3 ? { [K_2 in keyof T_3]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], TIntersect<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
119
+ $or: import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer T_5 ? { [K_2 in keyof T_5]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
110
120
  $gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
111
121
  $gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
112
122
  $lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
@@ -114,9 +124,9 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
114
124
  $ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
115
125
  $in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
116
126
  $nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
117
- }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_4 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_4]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>>;
127
+ }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_6 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_6]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>>;
118
128
  }>]>>>;
119
- $or: TOptional<import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer T_3 ? { [K_2 in keyof T_3]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], TIntersect<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
129
+ $or: TOptional<import("@sinclair/typebox").TArray<TOptional<TObject<T["properties"] extends infer T_7 ? { [K_2 in keyof T_7]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
120
130
  $gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
121
131
  $gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
122
132
  $lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
@@ -124,8 +134,8 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
124
134
  $ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
125
135
  $in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
126
136
  $nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
127
- }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_4 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_4]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>>>;
128
- }>, TOptional<TObject<T["properties"] extends infer T_5 ? { [K_2 in keyof T_5]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], TIntersect<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
137
+ }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_8 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_8]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>>>;
138
+ }>, TOptional<TObject<T["properties"] extends infer T_9 ? { [K_2 in keyof T_9]: TOptional<import("@sinclair/typebox").TUnion<[T["properties"][K_2], import("@sinclair/typebox").TComposite<[TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<{
129
139
  $gt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
130
140
  $gte: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
131
141
  $lt: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
@@ -133,5 +143,5 @@ export declare const querySyntax: <T extends TObject<import("@sinclair/typebox")
133
143
  $ne: T["properties"][K_2] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : T["properties"][K_2] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : T["properties"][K_2] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<T["properties"][K_2]>;
134
144
  $in: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
135
145
  $nin: TOptional<import("@sinclair/typebox").TArray<T["properties"][K_2]>>;
136
- }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_6 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_6]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>]>;
146
+ }, import("@sinclair/typebox").TProperties>>>, TObject<import("@sinclair/typebox").Evaluate<import("@sinclair/typebox").Assert<X[K_2] extends infer T_10 extends import("@sinclair/typebox").TProperties ? { [K_3 in keyof T_10]: X[K_2][K_3] extends import("@sinclair/typebox").TReadonlyOptional<infer U extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U> : X[K_2][K_3] extends import("@sinclair/typebox").TReadonly<infer U_1 extends TSchema> ? import("@sinclair/typebox").TReadonlyOptional<U_1> : X[K_2][K_3] extends TOptional<infer U_2 extends TSchema> ? TOptional<U_2> : TOptional<X[K_2][K_3]>; } : never, import("@sinclair/typebox").TProperties>>>]>]>>; } : never>>]>;
137
147
  export declare const ObjectIdSchema: () => import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString<string>, TObject<{}>]>;
package/lib/index.js CHANGED
@@ -14,15 +14,52 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ObjectIdSchema = exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = exports.StringEnum = exports.getDataValidator = exports.getValidator = exports.Intersect = void 0;
17
+ exports.ObjectIdSchema = exports.querySyntax = exports.queryProperties = exports.queryProperty = exports.sortDefinition = exports.StringEnum = exports.getDataValidator = exports.getValidator = exports.Type = exports.FeathersTypeBuilder = void 0;
18
18
  const typebox_1 = require("@sinclair/typebox");
19
19
  const schema_1 = require("@feathersjs/schema");
20
20
  __exportStar(require("@sinclair/typebox"), exports);
21
21
  __exportStar(require("./default-schemas"), exports);
22
- // Export new intersect
23
- exports.Intersect = typebox_1.Type.Intersect;
24
- // This is necessary to maintain backwards compatibility between 0.25 and 0.26
25
- typebox_1.Type.Intersect = typebox_1.Type.Composite;
22
+ /**
23
+ * Feathers TypeBox customisations. Implements the 0.25.0 fallback for Intersect types.
24
+ * @see https://github.com/sinclairzx81/typebox/issues/373
25
+ */
26
+ class FeathersTypeBuilder extends typebox_1.ExtendedTypeBuilder {
27
+ Intersect(allOf, options = {}) {
28
+ const [required, optional] = [new Set(), new Set()];
29
+ for (const object of allOf) {
30
+ for (const [key, property] of Object.entries(object.properties)) {
31
+ if (typebox_1.TypeGuard.TOptional(property) || typebox_1.TypeGuard.TReadonlyOptional(property))
32
+ optional.add(key);
33
+ }
34
+ }
35
+ for (const object of allOf) {
36
+ for (const key of Object.keys(object.properties)) {
37
+ if (!optional.has(key))
38
+ required.add(key);
39
+ }
40
+ }
41
+ const properties = {};
42
+ for (const object of allOf) {
43
+ for (const [key, schema] of Object.entries(object.properties)) {
44
+ properties[key] =
45
+ properties[key] === undefined
46
+ ? schema
47
+ : { [typebox_1.Kind]: 'Union', anyOf: [properties[key], { ...schema }] };
48
+ }
49
+ }
50
+ if (required.size > 0) {
51
+ return { ...options, [typebox_1.Kind]: 'Object', type: 'object', properties, required: [...required] };
52
+ }
53
+ else {
54
+ return { ...options, [typebox_1.Kind]: 'Object', type: 'object', properties };
55
+ }
56
+ }
57
+ }
58
+ exports.FeathersTypeBuilder = FeathersTypeBuilder;
59
+ /**
60
+ * Exports our own type builder
61
+ */
62
+ exports.Type = new FeathersTypeBuilder();
26
63
  /**
27
64
  * Returns a compiled validation function for a TypeBox object and AJV validator instance.
28
65
  *
@@ -50,12 +87,12 @@ exports.getDataValidator = getDataValidator;
50
87
  * @returns TypeBox.Type
51
88
  */
52
89
  function StringEnum(allowedValues) {
53
- return typebox_1.Type.Unsafe({ type: 'string', enum: allowedValues });
90
+ return exports.Type.Unsafe({ type: 'string', enum: allowedValues });
54
91
  }
55
92
  exports.StringEnum = StringEnum;
56
93
  const arrayOfKeys = (type) => {
57
94
  const keys = Object.keys(type.properties);
58
- return typebox_1.Type.Unsafe({
95
+ return exports.Type.Unsafe({
59
96
  type: 'array',
60
97
  maxItems: keys.length,
61
98
  items: {
@@ -73,10 +110,10 @@ const arrayOfKeys = (type) => {
73
110
  function sortDefinition(schema) {
74
111
  const properties = Object.keys(schema.properties).reduce((res, key) => {
75
112
  const result = res;
76
- result[key] = typebox_1.Type.Optional(typebox_1.Type.Integer({ minimum: -1, maximum: 1 }));
113
+ result[key] = exports.Type.Optional(exports.Type.Integer({ minimum: -1, maximum: 1 }));
77
114
  return result;
78
115
  }, {});
79
- return typebox_1.Type.Object(properties, { additionalProperties: false });
116
+ return exports.Type.Object(properties, { additionalProperties: false });
80
117
  }
81
118
  exports.sortDefinition = sortDefinition;
82
119
  /**
@@ -87,19 +124,19 @@ exports.sortDefinition = sortDefinition;
87
124
  * @param extension Additional properties to add to the property query
88
125
  * @returns The Feathers query syntax schema
89
126
  */
90
- const queryProperty = (def, extension = {}) => typebox_1.Type.Optional(typebox_1.Type.Union([
127
+ const queryProperty = (def, extension = {}) => exports.Type.Optional(exports.Type.Union([
91
128
  def,
92
- typebox_1.Type.Partial(typebox_1.Type.Intersect([
93
- typebox_1.Type.Object({
129
+ exports.Type.Partial(exports.Type.Composite([
130
+ exports.Type.Object({
94
131
  $gt: def,
95
132
  $gte: def,
96
133
  $lt: def,
97
134
  $lte: def,
98
135
  $ne: def,
99
- $in: typebox_1.Type.Array(def),
100
- $nin: typebox_1.Type.Array(def)
136
+ $in: exports.Type.Array(def),
137
+ $nin: exports.Type.Array(def)
101
138
  }),
102
- typebox_1.Type.Object(extension)
139
+ exports.Type.Object(extension)
103
140
  ], { additionalProperties: false }))
104
141
  ]));
105
142
  exports.queryProperty = queryProperty;
@@ -117,7 +154,7 @@ const queryProperties = (definition, extensions = {}) => {
117
154
  result[key] = (0, exports.queryProperty)(value, extensions[key]);
118
155
  return result;
119
156
  }, {});
120
- return typebox_1.Type.Optional(typebox_1.Type.Object(properties, { additionalProperties: false }));
157
+ return exports.Type.Optional(exports.Type.Object(properties, { additionalProperties: false }));
121
158
  };
122
159
  exports.queryProperties = queryProperties;
123
160
  /**
@@ -131,12 +168,12 @@ exports.queryProperties = queryProperties;
131
168
  */
132
169
  const querySyntax = (type, extensions = {}, options = { additionalProperties: false }) => {
133
170
  const propertySchema = (0, exports.queryProperties)(type, extensions);
134
- const $or = typebox_1.Type.Array(propertySchema);
135
- const $and = typebox_1.Type.Array(typebox_1.Type.Union([propertySchema, typebox_1.Type.Object({ $or })]));
136
- return typebox_1.Type.Intersect([
137
- typebox_1.Type.Partial(typebox_1.Type.Object({
138
- $limit: typebox_1.Type.Number({ minimum: 0 }),
139
- $skip: typebox_1.Type.Number({ minimum: 0 }),
171
+ const $or = exports.Type.Array(propertySchema);
172
+ const $and = exports.Type.Array(exports.Type.Union([propertySchema, exports.Type.Object({ $or })]));
173
+ return exports.Type.Composite([
174
+ exports.Type.Partial(exports.Type.Object({
175
+ $limit: exports.Type.Number({ minimum: 0 }),
176
+ $skip: exports.Type.Number({ minimum: 0 }),
140
177
  $sort: sortDefinition(type),
141
178
  $select: arrayOfKeys(type),
142
179
  $and,
@@ -146,6 +183,6 @@ const querySyntax = (type, extensions = {}, options = { additionalProperties: fa
146
183
  ], options);
147
184
  };
148
185
  exports.querySyntax = querySyntax;
149
- const ObjectIdSchema = () => typebox_1.Type.Union([typebox_1.Type.String({ objectid: true }), typebox_1.Type.Object({}, { additionalProperties: false })]);
186
+ const ObjectIdSchema = () => exports.Type.Union([exports.Type.String({ objectid: true }), exports.Type.Object({}, { additionalProperties: false })]);
150
187
  exports.ObjectIdSchema = ObjectIdSchema;
151
188
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA0G;AAC1G,+CAAiF;AAEjF,oDAAiC;AACjC,oDAAiC;AAEjC,uBAAuB;AACV,QAAA,SAAS,GAAG,cAAI,CAAC,SAAS,CAAA;AAEvC,8EAA8E;AAC9E,cAAI,CAAC,SAAS,GAAG,cAAI,CAAC,SAAgB,CAAA;AAQtC;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAiB,MAA4B,EAAE,SAAc,EAAmB,EAAE,CAC5G,mBAAU,CAAC,YAAY,CAAC,MAAa,EAAE,SAAS,CAAC,CAAA;AADtC,QAAA,YAAY,gBAC0B;AAEnD;;;;;;;;;GASG;AACI,MAAM,gBAAgB,GAAG,CAAC,GAA6B,EAAE,SAAc,EAAoB,EAAE,CAClG,mBAAU,CAAC,gBAAgB,CAAC,GAAU,EAAE,SAAS,CAAC,CAAA;AADvC,QAAA,gBAAgB,oBACuB;AAEpD;;;;GAIG;AACH,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E,YAAI,CAAC,OAAO,CACV,YAAI,CAAC,MAAM,CACT;YACE,MAAM,EAAE,YAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YACnC,KAAK,EAAE,YAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YAClC,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC;YAC3B,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC;YAC1B,IAAI;YACJ,GAAG;SACJ,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAChC,CACF;QACD,cAAc;KACf,EACD,OAAO,CACR,CAAA;AACH,CAAC,CAAA;AA/BY,QAAA,WAAW,eA+BvB;AAEM,MAAM,cAAc,GAAG,GAAG,EAAE,CACjC,YAAI,CAAC,KAAK,CAAC,CAAC,YAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,YAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;AADpF,QAAA,cAAc,kBACsE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@feathersjs/typebox",
3
3
  "description": "TypeBox integration for @feathersjs/schema",
4
- "version": "5.0.3",
4
+ "version": "5.0.4",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -54,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@feathersjs/schema": "^5.0.3",
57
+ "@feathersjs/schema": "^5.0.4",
58
58
  "@sinclair/typebox": "^0.26.8"
59
59
  },
60
60
  "devDependencies": {
@@ -64,5 +64,5 @@
64
64
  "shx": "^0.3.4",
65
65
  "typescript": "^5.0.3"
66
66
  },
67
- "gitHead": "a6ba4dfd08f537a7d4778bed4c45091cbe3802aa"
67
+ "gitHead": "376e89040991db500f1f327aa699322543315039"
68
68
  }
package/src/index.ts CHANGED
@@ -1,14 +1,66 @@
1
- import { Type, TObject, TInteger, TOptional, TSchema, TIntersect, ObjectOptions } from '@sinclair/typebox'
1
+ import {
2
+ TObject,
3
+ TInteger,
4
+ TOptional,
5
+ TSchema,
6
+ TIntersect,
7
+ ObjectOptions,
8
+ ExtendedTypeBuilder,
9
+ SchemaOptions,
10
+ TNever,
11
+ IntersectOptions,
12
+ TypeGuard,
13
+ Kind
14
+ } from '@sinclair/typebox'
2
15
  import { jsonSchema, Validator, DataValidatorMap, Ajv } from '@feathersjs/schema'
3
16
 
4
17
  export * from '@sinclair/typebox'
5
18
  export * from './default-schemas'
6
19
 
7
- // Export new intersect
8
- export const Intersect = Type.Intersect
20
+ /**
21
+ * Feathers TypeBox customisations. Implements the 0.25.0 fallback for Intersect types.
22
+ * @see https://github.com/sinclairzx81/typebox/issues/373
23
+ */
24
+ export class FeathersTypeBuilder extends ExtendedTypeBuilder {
25
+ /** `[Standard]` Creates a Intersect type */
26
+ public Intersect(allOf: [], options?: SchemaOptions): TNever
27
+ /** `[Standard]` Creates a Intersect type */
28
+ public Intersect<T extends [TObject]>(allOf: [...T], options?: SchemaOptions): T[0]
29
+ // /** `[Standard]` Creates a Intersect type */
30
+ public Intersect<T extends TObject[]>(allOf: [...T], options?: IntersectOptions): TIntersect<T>
31
+ public Intersect(allOf: TObject[], options: IntersectOptions = {}) {
32
+ const [required, optional] = [new Set<string>(), new Set<string>()]
33
+ for (const object of allOf) {
34
+ for (const [key, property] of Object.entries(object.properties)) {
35
+ if (TypeGuard.TOptional(property) || TypeGuard.TReadonlyOptional(property)) optional.add(key)
36
+ }
37
+ }
38
+ for (const object of allOf) {
39
+ for (const key of Object.keys(object.properties)) {
40
+ if (!optional.has(key)) required.add(key)
41
+ }
42
+ }
43
+ const properties = {} as Record<string, any>
44
+ for (const object of allOf) {
45
+ for (const [key, schema] of Object.entries(object.properties)) {
46
+ properties[key] =
47
+ properties[key] === undefined
48
+ ? schema
49
+ : { [Kind]: 'Union', anyOf: [properties[key], { ...schema }] }
50
+ }
51
+ }
52
+ if (required.size > 0) {
53
+ return { ...options, [Kind]: 'Object', type: 'object', properties, required: [...required] } as any
54
+ } else {
55
+ return { ...options, [Kind]: 'Object', type: 'object', properties } as any
56
+ }
57
+ }
58
+ }
9
59
 
10
- // This is necessary to maintain backwards compatibility between 0.25 and 0.26
11
- Type.Intersect = Type.Composite as any
60
+ /**
61
+ * Exports our own type builder
62
+ */
63
+ export const Type = new FeathersTypeBuilder()
12
64
 
13
65
  export type TDataSchemaMap = {
14
66
  create: TObject
@@ -94,7 +146,7 @@ export const queryProperty = <T extends TSchema, X extends { [key: string]: TSch
94
146
  Type.Union([
95
147
  def,
96
148
  Type.Partial(
97
- Type.Intersect(
149
+ Type.Composite(
98
150
  [
99
151
  Type.Object({
100
152
  $gt: def,
@@ -164,7 +216,7 @@ export const querySyntax = <
164
216
  const $or = Type.Array(propertySchema)
165
217
  const $and = Type.Array(Type.Union([propertySchema, Type.Object({ $or })]))
166
218
 
167
- return Type.Intersect(
219
+ return Type.Composite(
168
220
  [
169
221
  Type.Partial(
170
222
  Type.Object(