@aeriajs/types 0.0.86 → 0.0.87
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/dist/collection.d.ts +3 -3
- package/dist/condition.d.ts +9 -9
- package/dist/context.d.ts +13 -12
- package/dist/contract.d.ts +1 -1
- package/dist/description.d.ts +9 -9
- package/dist/functions.d.ts +18 -19
- package/dist/http.d.ts +3 -3
- package/dist/index.d.ts +0 -1
- package/dist/property.d.ts +5 -5
- package/dist/schema.d.ts +3 -3
- package/dist/security.d.ts +6 -5
- package/dist/token.d.ts +7 -5
- package/dist/validation.d.ts +5 -3
- package/dist/validation.js +2 -0
- package/dist/validation.mjs +2 -0
- package/package.json +1 -1
package/dist/collection.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WithId } from 'mongodb';
|
|
1
2
|
import type { AccessCondition } from './accessControl.js';
|
|
2
3
|
import type { CollectionSecurityPolicy, CollectionMiddleware } from './security.js';
|
|
3
4
|
import type { Context } from './context.js';
|
|
@@ -5,13 +6,12 @@ import type { Contract } from './contract.js';
|
|
|
5
6
|
import type { Description } from './description.js';
|
|
6
7
|
export type Collection<TCollection extends Collection = any> = {
|
|
7
8
|
description: Description;
|
|
8
|
-
item
|
|
9
|
+
item: WithId<unknown>;
|
|
9
10
|
functions?: Record<string, (payload: any, context: Context<any>, ...args: any[]) => any>;
|
|
10
11
|
contracts?: Record<string, Contract>;
|
|
11
12
|
exposedFunctions?: Record<string, AccessCondition>;
|
|
12
13
|
security?: CollectionSecurityPolicy<TCollection>;
|
|
13
|
-
middlewares?: CollectionMiddleware<
|
|
14
|
+
middlewares?: CollectionMiddleware<TCollection['item']> | CollectionMiddleware<TCollection['item']>[];
|
|
14
15
|
};
|
|
15
16
|
export type CollectionItem<TCollectionName extends keyof Collections> = Omit<Collections[TCollectionName]['item'], '_id'>;
|
|
16
17
|
export type CollectionItemWithId<TCollectionName extends keyof Collections> = Collections[TCollectionName]['item'];
|
|
17
|
-
export type AssetType = keyof Collection;
|
package/dist/condition.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import type { JsonSchema, PropertiesWithId } from './property.js';
|
|
2
2
|
export type FinalOperator = 'equal' | 'in' | 'gt' | 'lt' | 'gte' | 'lte';
|
|
3
|
-
export type FinalCondition<TSchema extends JsonSchema
|
|
3
|
+
export type FinalCondition<TSchema extends JsonSchema> = {
|
|
4
4
|
operator: FinalOperator;
|
|
5
5
|
term1: PropertiesWithId<TSchema>;
|
|
6
|
-
term2:
|
|
6
|
+
term2: unknown;
|
|
7
7
|
fromState?: boolean;
|
|
8
8
|
};
|
|
9
|
-
export type RegexCondition<TSchema extends JsonSchema
|
|
9
|
+
export type RegexCondition<TSchema extends JsonSchema> = {
|
|
10
10
|
operator: 'regex';
|
|
11
11
|
term1: PropertiesWithId<TSchema>;
|
|
12
12
|
term2: string;
|
|
13
13
|
fromState?: boolean;
|
|
14
14
|
regexOptions?: string;
|
|
15
15
|
};
|
|
16
|
-
export type TruthyCondition<TSchema extends JsonSchema
|
|
16
|
+
export type TruthyCondition<TSchema extends JsonSchema> = {
|
|
17
17
|
operator: 'truthy';
|
|
18
18
|
term1: PropertiesWithId<TSchema>;
|
|
19
19
|
};
|
|
20
|
-
export type OrCondition<TSchema extends JsonSchema
|
|
20
|
+
export type OrCondition<TSchema extends JsonSchema> = {
|
|
21
21
|
or: readonly Condition<TSchema>[];
|
|
22
22
|
};
|
|
23
|
-
export type AndCondition<TSchema extends JsonSchema
|
|
23
|
+
export type AndCondition<TSchema extends JsonSchema> = {
|
|
24
24
|
and: readonly Condition<TSchema>[];
|
|
25
25
|
};
|
|
26
|
-
export type NotCondition<TSchema extends JsonSchema
|
|
26
|
+
export type NotCondition<TSchema extends JsonSchema> = {
|
|
27
27
|
not: Condition<TSchema>;
|
|
28
28
|
};
|
|
29
|
-
export type Condition<TSchema extends JsonSchema =
|
|
30
|
-
else?:
|
|
29
|
+
export type Condition<TSchema extends JsonSchema = JsonSchema> = (FinalCondition<TSchema> | RegexCondition<TSchema> | TruthyCondition<TSchema> | AndCondition<TSchema> | OrCondition<TSchema> | NotCondition<TSchema>) & {
|
|
30
|
+
else?: unknown;
|
|
31
31
|
};
|
package/dist/context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Collection as MongoCollection } from 'mongodb';
|
|
1
|
+
import type { Collection as MongoCollection, WithId } from 'mongodb';
|
|
2
2
|
import type { AcceptedRole } from './token.js';
|
|
3
3
|
import type { Collection } from './collection.js';
|
|
4
4
|
import type { ApiConfig } from './config.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { CollectionFunctions } from './functions.js';
|
|
6
6
|
import type { Description } from './description.js';
|
|
7
7
|
import type { Result } from './result.js';
|
|
8
8
|
import type { EndpointError } from './endpointError.js';
|
|
@@ -11,15 +11,16 @@ import type { PackReferences, SchemaWithId } from './schema.js';
|
|
|
11
11
|
import type { RateLimitingParams, RateLimitingError } from './security.js';
|
|
12
12
|
import type { Token } from './token.js';
|
|
13
13
|
export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
|
|
14
|
-
type OmitContextParameter<TFunction> = TFunction extends () =>
|
|
15
|
-
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context<any>, ...args: infer Rest) =>
|
|
16
|
-
type UnionFunctions<TFunctions, TSchema extends
|
|
17
|
-
[P in keyof TFunctions]: (P extends keyof CollectionFunctions
|
|
14
|
+
type OmitContextParameter<TFunction> = TFunction extends () => unknown ? TFunction : TFunction extends (payload: undefined, ...args: any[]) => infer Return ? () => Return : TFunction extends (payload: infer Payload, context: Context<any>, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
15
|
+
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context<any>, ...args: infer Rest) => unknown ? Rest : never;
|
|
16
|
+
type UnionFunctions<TFunctions, TSchema extends WithId<unknown>> = {
|
|
17
|
+
[P in keyof TFunctions]: (P extends keyof CollectionFunctions ? CollectionFunctions<TSchema>[P] extends infer CollFunction ? CollFunction extends (...args: infer Args) => unknown ? Extract<undefined, Args[0]> extends never ? (payload: Args[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : (payload?: Args[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : never : never : OmitContextParameter<TFunctions[P]>) extends (...args: infer Args) => infer Return ? Return extends Promise<unknown> ? (...args: Args) => Return : (...args: Args) => Promise<Return> : never;
|
|
18
18
|
};
|
|
19
19
|
export type IndepthCollection<TCollection> = TCollection extends {
|
|
20
20
|
description: infer InferredDescription;
|
|
21
21
|
functions?: infer CollFunctions;
|
|
22
22
|
} ? Omit<TCollection, 'functions'> & {
|
|
23
|
+
item: SchemaWithId<InferredDescription>;
|
|
23
24
|
functions: UnionFunctions<CollFunctions, SchemaWithId<InferredDescription>>;
|
|
24
25
|
originalFunctions: CollFunctions;
|
|
25
26
|
model: InferredDescription extends Description ? CollectionModel<InferredDescription> : never;
|
|
@@ -31,7 +32,7 @@ export type IndepthCollections = {
|
|
|
31
32
|
export type ContextOptions = {
|
|
32
33
|
config?: ApiConfig;
|
|
33
34
|
parentContext?: RouteContext | Context;
|
|
34
|
-
collectionName?: string
|
|
35
|
+
collectionName?: Extract<keyof Collections, string>;
|
|
35
36
|
token?: Token;
|
|
36
37
|
inherited?: boolean;
|
|
37
38
|
calledFunction?: string;
|
|
@@ -41,7 +42,7 @@ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
|
|
|
41
42
|
token: Token<TAcceptedRole>;
|
|
42
43
|
request: GenericRequest;
|
|
43
44
|
response: GenericResponse;
|
|
44
|
-
log: (message: string, details?:
|
|
45
|
+
log: (message: string, details?: unknown) => Promise<unknown>;
|
|
45
46
|
error: <const THTTPStatus extends HTTPStatus, const TEndpointError extends EndpointError>(httpStatus: THTTPStatus, error: TEndpointError) => Result.Error<TEndpointError & {
|
|
46
47
|
httpStatus: THTTPStatus;
|
|
47
48
|
}>;
|
|
@@ -55,14 +56,14 @@ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
|
|
|
55
56
|
inherited: boolean;
|
|
56
57
|
calledFunction: string;
|
|
57
58
|
};
|
|
58
|
-
export type CollectionContext<TDescription extends Description
|
|
59
|
+
export type CollectionContext<TDescription extends Description, TFunctions = Collection['functions']> = {
|
|
59
60
|
description: TDescription;
|
|
60
|
-
collectionName?:
|
|
61
|
+
collectionName?: Extract<keyof Collections, string>;
|
|
61
62
|
collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
|
|
62
63
|
description: TDescription;
|
|
63
64
|
functions: TFunctions;
|
|
64
65
|
}> : IndepthCollection<any>;
|
|
65
66
|
};
|
|
66
|
-
export type Context<TDescription extends Description = Description, TFunctions =
|
|
67
|
-
export type StrictContext<TAcceptedRole extends AcceptedRole = null, TDescription extends Description = any, TFunctions =
|
|
67
|
+
export type Context<TDescription extends Description = Description, TFunctions = Collection['functions']> = RouteContext & CollectionContext<TDescription, TFunctions>;
|
|
68
|
+
export type StrictContext<TAcceptedRole extends AcceptedRole = null, TDescription extends Description = any, TFunctions = Collection['functions']> = RouteContext<TAcceptedRole> & CollectionContext<TDescription, TFunctions>;
|
|
68
69
|
export {};
|
package/dist/contract.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export type Contract = ContractBase & {
|
|
|
15
15
|
query?: Property | Property[];
|
|
16
16
|
};
|
|
17
17
|
export type ContractWithRoles = ContractRoles & Contract;
|
|
18
|
-
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperties<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferProperties<TContract['response']> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never :
|
|
18
|
+
export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperties<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferProperties<TContract['response']> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never : unknown) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
|
|
19
19
|
export declare const defineContract: <const TContractWithRoles extends ContractWithRoles>(contract: TContractWithRoles) => TContractWithRoles;
|
package/dist/description.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export type CollectionActionRoute = {
|
|
|
11
11
|
setItem?: boolean;
|
|
12
12
|
fetchItem?: boolean;
|
|
13
13
|
clearItem?: boolean;
|
|
14
|
-
params?: Record<string,
|
|
15
|
-
query?: Record<string,
|
|
14
|
+
params?: Record<string, unknown>;
|
|
15
|
+
query?: Record<string, unknown>;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
export type CollectionActionFunction = {
|
|
@@ -46,7 +46,7 @@ export type FormLayoutField<TDescription extends Description> = {
|
|
|
46
46
|
if?: Condition<TDescription>;
|
|
47
47
|
component?: {
|
|
48
48
|
name: string;
|
|
49
|
-
props?: Record<string,
|
|
49
|
+
props?: Record<string, unknown>;
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
export type TableLayoutAction<TDescription extends Description> = {
|
|
@@ -59,13 +59,13 @@ export type TableLayout<TDescription extends Description> = {
|
|
|
59
59
|
export type FiltersPreset<TDescription extends Description> = {
|
|
60
60
|
label?: string;
|
|
61
61
|
icon?: Icon;
|
|
62
|
-
filters?: Partial<Record<PropertiesWithId<TDescription> | `$${string}`,
|
|
62
|
+
filters?: Partial<Record<PropertiesWithId<TDescription> | `$${string}`, unknown>>;
|
|
63
63
|
table?: readonly PropertiesWithId<TDescription>[];
|
|
64
64
|
badgeFunction?: string;
|
|
65
65
|
default?: boolean;
|
|
66
66
|
};
|
|
67
67
|
export type LayoutName = 'tabular' | 'grid' | 'list';
|
|
68
|
-
export type LayoutOptions<TDescription extends Description =
|
|
68
|
+
export type LayoutOptions<TDescription extends Description = Description> = {
|
|
69
69
|
title?: PropertiesWithId<TDescription>;
|
|
70
70
|
picture?: PropertiesWithId<TDescription>;
|
|
71
71
|
badge?: PropertiesWithId<TDescription>;
|
|
@@ -73,7 +73,7 @@ export type LayoutOptions<TDescription extends Description = any> = {
|
|
|
73
73
|
active?: PropertiesWithId<TDescription>;
|
|
74
74
|
translateBadge?: boolean;
|
|
75
75
|
};
|
|
76
|
-
export type Layout<TDescription extends Description =
|
|
76
|
+
export type Layout<TDescription extends Description = Description> = {
|
|
77
77
|
name: LayoutName;
|
|
78
78
|
options?: LayoutOptions<TDescription>;
|
|
79
79
|
};
|
|
@@ -82,7 +82,7 @@ export type SearchOptions<TDescription extends Description> = {
|
|
|
82
82
|
placeholder?: string;
|
|
83
83
|
exactMatches?: boolean;
|
|
84
84
|
};
|
|
85
|
-
export type RuntimeDescription<TDescription extends Description =
|
|
85
|
+
export type RuntimeDescription<TDescription extends Description = Description> = Pick<TDescription, 'actions' | 'individualActions' | 'filters' | 'filtersPresets' | 'layout' | 'table' | 'tableMeta' | 'form' | 'tableLayout' | 'formLayout'>;
|
|
86
86
|
export type Description<TDescription extends Description = any> = JsonSchema<TDescription> & {
|
|
87
87
|
title?: string;
|
|
88
88
|
categories?: readonly string[];
|
|
@@ -90,14 +90,14 @@ export type Description<TDescription extends Description = any> = JsonSchema<TDe
|
|
|
90
90
|
preferred?: Record<string, RuntimeDescription<TDescription>>;
|
|
91
91
|
icon?: Icon;
|
|
92
92
|
indexes?: readonly PropertiesWithId<TDescription>[];
|
|
93
|
-
defaults?: Record<string,
|
|
93
|
+
defaults?: Record<string, unknown>;
|
|
94
94
|
owned?: OwnershipMode;
|
|
95
95
|
temporary?: {
|
|
96
96
|
index: keyof TDescription['properties'];
|
|
97
97
|
expireAfterSeconds: number;
|
|
98
98
|
};
|
|
99
99
|
timestamps?: false;
|
|
100
|
-
immutable?: boolean | readonly (keyof TDescription['properties'])[] | ((doc: WithId<
|
|
100
|
+
immutable?: boolean | readonly (keyof TDescription['properties'])[] | ((doc: WithId<unknown>) => boolean | Promise<boolean>);
|
|
101
101
|
route?: readonly string[];
|
|
102
102
|
presets?: readonly DescriptionPreset[];
|
|
103
103
|
table?: readonly PropertiesWithId<TDescription>[];
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FilterOperators, StrictFilter as Filter, WithId,
|
|
1
|
+
import type { FilterOperators, StrictFilter as Filter, WithId, ObjectId } from 'mongodb';
|
|
2
2
|
import type { Result } from './result.js';
|
|
3
3
|
import type { EndpointError, StrictEndpointError } from './endpointError.js';
|
|
4
4
|
import type { PackReferences } from './schema.js';
|
|
@@ -17,7 +17,7 @@ export type Pagination = {
|
|
|
17
17
|
};
|
|
18
18
|
type FilterProperty<T> = T extends ObjectId ? T | string : T;
|
|
19
19
|
type DocumentFilter<TDocument> = PackReferences<TDocument> extends infer Document ? {
|
|
20
|
-
[P in keyof Document]: Document[P] extends (infer E)[] ? FilterProperty<E>[] : FilterProperty<Document[P]
|
|
20
|
+
[P in keyof Document]: null | (Document[P] extends (infer E)[] ? FilterProperty<E>[] : FilterProperty<Document[P]>);
|
|
21
21
|
} : never;
|
|
22
22
|
type RemoveAny<T> = {
|
|
23
23
|
[P in keyof T as 0 extends (T[P] & 1) ? never : P]: T[P];
|
|
@@ -27,27 +27,26 @@ export type StrictFilterOperators<TDocument> = RemoveAny<FilterOperators<Documen
|
|
|
27
27
|
export type Filters<TDocument> = StrictFilter<TDocument> & Partial<{
|
|
28
28
|
[P in keyof TDocument | `${Extract<keyof TDocument, string>}.${string}`]: (P extends keyof TDocument ? TDocument[P] extends infer Field ? Field extends ObjectId ? Field | string : Field extends {
|
|
29
29
|
_id: infer Id;
|
|
30
|
-
} ? Id | string : Field : never :
|
|
30
|
+
} ? Id | string : Field : never : unknown) extends infer Field ? Field | StrictFilterOperators<Field> | null : never;
|
|
31
31
|
}>;
|
|
32
32
|
export type What<TDocument> = ({
|
|
33
33
|
_id: ObjectId | string;
|
|
34
34
|
} & Partial<Omit<PackReferences<TDocument>, '_id'>> | {
|
|
35
35
|
_id?: null;
|
|
36
|
-
} & Omit<PackReferences<TDocument>, '_id'>) extends infer
|
|
37
|
-
[P in keyof
|
|
36
|
+
} & Omit<PackReferences<TDocument>, '_id'>) extends infer InferredDocument ? {
|
|
37
|
+
[P in keyof InferredDocument]: InferredDocument[P] | null;
|
|
38
38
|
} : never;
|
|
39
39
|
export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? [DocumentProp] extends [string] ? DocumentProp[] : string[] : never;
|
|
40
40
|
export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
|
|
41
|
-
export type
|
|
42
|
-
export type CountPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
|
|
41
|
+
export type CountPayload<TDocument extends WithId<unknown>> = {
|
|
43
42
|
filters?: Filters<TDocument>;
|
|
44
43
|
};
|
|
45
|
-
export type GetPayload<TDocument extends
|
|
44
|
+
export type GetPayload<TDocument extends WithId<unknown>> = {
|
|
46
45
|
filters: Filters<TDocument>;
|
|
47
46
|
project?: Projection<TDocument>;
|
|
48
47
|
populate?: (keyof TDocument)[];
|
|
49
48
|
};
|
|
50
|
-
export type GetAllPayload<TDocument extends
|
|
49
|
+
export type GetAllPayload<TDocument extends WithId<unknown>> = {
|
|
51
50
|
filters?: Filters<TDocument>;
|
|
52
51
|
project?: Projection<TDocument>;
|
|
53
52
|
offset?: number;
|
|
@@ -55,19 +54,19 @@ export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>>
|
|
|
55
54
|
sort?: QuerySort<TDocument>;
|
|
56
55
|
populate?: (keyof TDocument)[];
|
|
57
56
|
};
|
|
58
|
-
export type InsertPayload<TDocument extends
|
|
57
|
+
export type InsertPayload<TDocument extends WithId<unknown>> = {
|
|
59
58
|
what: What<TDocument>;
|
|
60
59
|
project?: Projection<TDocument>;
|
|
61
60
|
};
|
|
62
|
-
export type RemovePayload<TDocument extends
|
|
61
|
+
export type RemovePayload<TDocument extends WithId<unknown>> = {
|
|
63
62
|
filters: Filters<TDocument>;
|
|
64
63
|
};
|
|
65
64
|
export type RemoveAllPayload = {
|
|
66
|
-
filters: (
|
|
65
|
+
filters: (ObjectId | string)[];
|
|
67
66
|
};
|
|
68
67
|
export type RemoveFilePayload = UploadAuxProps & {
|
|
69
68
|
filters: {
|
|
70
|
-
_id:
|
|
69
|
+
_id: ObjectId | string;
|
|
71
70
|
};
|
|
72
71
|
};
|
|
73
72
|
export type InsertReturnType<TDocument> = Result.Either<StrictEndpointError<ACError.InsecureOperator | ACError.OwnershipError | ACError.ResourceNotFound | ACError.TargetImmutable | ValidationErrorCode | TraverseError.InvalidDocumentId | TraverseError.InvalidTempfile, unknown, HTTPStatus.Forbidden | HTTPStatus.NotFound | HTTPStatus.UnprocessableContent>, TDocument>;
|
|
@@ -79,22 +78,22 @@ export type PaginatedGetAllReturnType<TDocument> = Result.Either<EndpointError,
|
|
|
79
78
|
data: TDocument[];
|
|
80
79
|
pagination: Pagination;
|
|
81
80
|
}>;
|
|
82
|
-
export type CollectionFunctions<TDocument extends
|
|
81
|
+
export type CollectionFunctions<TDocument extends WithId<unknown> = WithId<unknown>> = {
|
|
83
82
|
count: (payload: CountPayload<TDocument>) => Promise<CountReturnType>;
|
|
84
83
|
get: (payload: GetPayload<TDocument>) => Promise<GetReturnType<TDocument>>;
|
|
85
84
|
getAll: (payload?: GetAllPayload<TDocument>) => Promise<GetAllReturnType<TDocument>>;
|
|
86
85
|
insert: (payload: InsertPayload<TDocument>) => Promise<InsertReturnType<TDocument>>;
|
|
87
86
|
remove: (payload: RemovePayload<TDocument>) => Promise<RemoveReturnType<TDocument>>;
|
|
88
|
-
removeAll: (payload: RemoveAllPayload) => Promise<
|
|
89
|
-
removeFile: (payload: RemoveFilePayload) => Promise<
|
|
87
|
+
removeAll: (payload: RemoveAllPayload) => Promise<unknown>;
|
|
88
|
+
removeFile: (payload: RemoveFilePayload) => Promise<unknown>;
|
|
90
89
|
};
|
|
91
|
-
export type CollectionFunctionsSDK<TDocument extends
|
|
90
|
+
export type CollectionFunctionsSDK<TDocument extends WithId<unknown> = WithId<unknown>> = {
|
|
92
91
|
count: (payload: CountPayload<TDocument>) => Promise<WithACErrors<CountReturnType>>;
|
|
93
92
|
get: (payload: GetPayload<TDocument>) => Promise<WithACErrors<GetReturnType<TDocument>>>;
|
|
94
93
|
getAll: (payload?: GetAllPayload<TDocument>) => Promise<WithACErrors<PaginatedGetAllReturnType<TDocument>>>;
|
|
95
94
|
insert: (payload: InsertPayload<TDocument>) => Promise<WithACErrors<InsertReturnType<TDocument>>>;
|
|
96
95
|
remove: (payload: RemovePayload<TDocument>) => Promise<WithACErrors<RemoveReturnType<TDocument>>>;
|
|
97
|
-
removeAll: (payload: RemoveAllPayload) => Promise<
|
|
98
|
-
removeFile: (payload: RemoveFilePayload) => Promise<
|
|
96
|
+
removeAll: (payload: RemoveAllPayload) => Promise<unknown>;
|
|
97
|
+
removeFile: (payload: RemoveFilePayload) => Promise<unknown>;
|
|
99
98
|
};
|
|
100
99
|
export {};
|
package/dist/http.d.ts
CHANGED
|
@@ -29,10 +29,10 @@ export type GenericResponse = ServerResponse & {
|
|
|
29
29
|
[STREAMED_RESPONSE]?: boolean;
|
|
30
30
|
};
|
|
31
31
|
type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<infer PCode> ? PCode : never;
|
|
32
|
-
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<
|
|
32
|
+
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<string, unknown, infer PHTTPStatus> ? PHTTPStatus : never;
|
|
33
33
|
export type NativeError = ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated;
|
|
34
34
|
export type NativeHTTPErrorStatus = HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests;
|
|
35
35
|
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, unknown> ? Result.Either<ExtractError<TRouteResponse> | StrictEndpointError<ExtractCode<InferredError> | NativeError, unknown, ExtractHTTPStatus<InferredError> | NativeHTTPErrorStatus>, ExtractResult<TRouteResponse>> : TRouteResponse | Result.Error<StrictEndpointError<NativeError, unknown, NativeHTTPErrorStatus>>;
|
|
36
|
-
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? <T = TRouteResponse>(payload?:
|
|
37
|
-
export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse =
|
|
36
|
+
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? <T = TRouteResponse>(payload?: unknown) => Promise<WithACErrors<T>> : TRoutePayload extends undefined ? <T = TRouteResponse>() => Promise<WithACErrors<T>> : <T = TRouteResponse>(payload: TRoutePayload) => Promise<WithACErrors<T>>) extends infer Function ? Record<TRouteMethod, Function> : never;
|
|
37
|
+
export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse = unknown, TRoutePayload = null> = TRoute extends `/${infer RouteTail}` ? MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload> : TRoute extends `${infer Route}/${infer RouteTail}` ? Record<Route, MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload>> : TRoute extends `(${string}` ? Record<string, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>> : Record<TRoute, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>>;
|
|
38
38
|
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/property.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type PropertyArrayElement = 'checkbox' | 'radio' | 'select';
|
|
|
6
6
|
export type PropertyInputType = 'text' | 'email' | 'password' | 'search' | 'time' | 'month';
|
|
7
7
|
export type PropertyInputElement = 'input' | 'textarea';
|
|
8
8
|
export type PropertyFormat = 'date' | 'date-time';
|
|
9
|
-
export type PropertiesWithId<TSchema extends JsonSchema> = keyof TSchema['properties'] | '_id';
|
|
9
|
+
export type PropertiesWithId<TSchema extends JsonSchema> = Extract<keyof TSchema['properties'], string> | '_id';
|
|
10
10
|
export type RequiredProperties<TSchema extends JsonSchema> = readonly PropertiesWithId<TSchema>[] | Partial<Record<PropertiesWithId<TSchema>, Condition<TSchema> | boolean>>;
|
|
11
11
|
export type JsonSchema<TJsonSchema extends JsonSchema = any> = {
|
|
12
12
|
$id: string;
|
|
@@ -37,8 +37,8 @@ export type FileProperty = Omit<RefProperty, '$ref'> & {
|
|
|
37
37
|
extensions?: readonly string[];
|
|
38
38
|
};
|
|
39
39
|
export type EnumProperty = {
|
|
40
|
-
enum: readonly
|
|
41
|
-
default?:
|
|
40
|
+
enum: readonly unknown[];
|
|
41
|
+
default?: unknown;
|
|
42
42
|
element?: PropertyArrayElement;
|
|
43
43
|
};
|
|
44
44
|
export type ArrayProperty = {
|
|
@@ -63,7 +63,7 @@ export type VariableObjectProperty = {
|
|
|
63
63
|
};
|
|
64
64
|
export type ObjectProperty = (FixedObjectProperty | VariableObjectProperty) & {
|
|
65
65
|
type: 'object';
|
|
66
|
-
default?:
|
|
66
|
+
default?: unknown;
|
|
67
67
|
};
|
|
68
68
|
export type StringProperty = {
|
|
69
69
|
type: 'string';
|
|
@@ -112,7 +112,7 @@ export type PropertyBase = {
|
|
|
112
112
|
icon?: PhosphorIcon['name'];
|
|
113
113
|
translate?: boolean;
|
|
114
114
|
hint?: string;
|
|
115
|
-
componentProps?: Record<string,
|
|
115
|
+
componentProps?: Record<string, unknown>;
|
|
116
116
|
noForm?: boolean;
|
|
117
117
|
noLabel?: boolean;
|
|
118
118
|
hidden?: boolean;
|
package/dist/schema.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type Schema<TSchema> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferS
|
|
|
49
49
|
export type SchemaWithId<TSchema> = Schema<TSchema> & {
|
|
50
50
|
_id: ObjectId;
|
|
51
51
|
};
|
|
52
|
-
export type InferProperties<TSchema> = TSchema extends readonly
|
|
52
|
+
export type InferProperties<TSchema> = TSchema extends readonly unknown[] ? TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends unknown ? SchemaOption extends {
|
|
53
53
|
$ref: infer K;
|
|
54
54
|
} | {
|
|
55
55
|
items: {
|
|
@@ -81,9 +81,9 @@ type MapReferences<TSchema> = TSchema extends {
|
|
|
81
81
|
}>;
|
|
82
82
|
}> ? K extends keyof Collections ? Collections[K]['item'][] : never : never : never;
|
|
83
83
|
} : never;
|
|
84
|
-
type PackReferencesAux<T> = T extends (...args:
|
|
84
|
+
type PackReferencesAux<T> = T extends (...args: unknown[]) => unknown ? T : T extends ObjectId ? T : T extends {
|
|
85
85
|
_id: infer Id;
|
|
86
|
-
} ? Id : T extends Record<string,
|
|
86
|
+
} ? Id : T extends Record<string, unknown> ? PackReferences<T> : T extends unknown[] | readonly unknown[] ? PackReferencesAux<T[number]>[] : T;
|
|
87
87
|
type CombineProperties<TSchema> = TSchema extends {
|
|
88
88
|
properties: infer Properties;
|
|
89
89
|
} ? FilterReadonlyProperties<Properties> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
|
package/dist/security.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from './context.js';
|
|
2
2
|
import type { What } from './functions.js';
|
|
3
3
|
import type { Result } from './result.js';
|
|
4
|
+
import type { QuerySort } from './functions.js';
|
|
4
5
|
export type OwnershipMode = boolean | 'always' | 'on-write';
|
|
5
6
|
export declare enum RateLimitingError {
|
|
6
7
|
Unauthenticated = "UNAUTHENTICATED",
|
|
@@ -32,24 +33,24 @@ export type CollectionSecurityPolicy<TCollection extends {
|
|
|
32
33
|
}> = {
|
|
33
34
|
functions?: Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
|
|
34
35
|
};
|
|
35
|
-
export type CollectionProps<TPayload
|
|
36
|
+
export type CollectionProps<TPayload> = {
|
|
36
37
|
propName?: string;
|
|
37
38
|
parentId?: string;
|
|
38
39
|
childId?: string;
|
|
39
40
|
payload: TPayload;
|
|
40
41
|
};
|
|
41
42
|
export type CollectionReadPayload = {
|
|
42
|
-
filters: Record<string,
|
|
43
|
-
sort?:
|
|
43
|
+
filters: Record<string, unknown> | unknown[];
|
|
44
|
+
sort?: QuerySort<unknown>;
|
|
44
45
|
limit?: number;
|
|
45
46
|
offset?: number;
|
|
46
47
|
};
|
|
47
48
|
export type CollectionWritePayload = {
|
|
48
|
-
what: What<Record<string,
|
|
49
|
+
what: What<Record<string, unknown>>;
|
|
49
50
|
};
|
|
50
51
|
export type GenericMiddlewareNext<TPayload, TReturn> = (payload: TPayload, context: Context) => TReturn;
|
|
51
52
|
export type MiddlewareNext = <TPayload, TReturn>(payload: TPayload, context: Context) => TReturn;
|
|
52
|
-
export type Middleware<TPayload =
|
|
53
|
+
export type Middleware<TPayload = unknown, TReturn = unknown, TReturnNext extends GenericMiddlewareNext<TPayload, TReturn> = GenericMiddlewareNext<TPayload, TReturn>> = (payload: TPayload, context: Context, next: TReturnNext) => TReturn;
|
|
53
54
|
export type CollectionMiddleware<TDocument> = {
|
|
54
55
|
beforeRead?: Middleware<CollectionReadPayload, Promise<Result.Either<any, TDocument | TDocument[]>>>;
|
|
55
56
|
beforeWrite?: Middleware<CollectionWritePayload, Promise<Result.Either<any, TDocument>>>;
|
package/dist/token.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { ObjectId } from 'mongodb';
|
|
2
2
|
import type { PackReferences } from './schema.js';
|
|
3
|
-
export type UserRole = (Collections['user']['item']
|
|
3
|
+
export type UserRole = (Collections['user']['item'] extends {
|
|
4
|
+
roles: infer Roles;
|
|
5
|
+
} ? Roles extends unknown[] ? Roles[number] extends infer UserDefinedRole ? UserDefinedRole extends string ? `${UserDefinedRole}${UserDefinedRole}` extends UserDefinedRole ? 'root' : UserDefinedRole : never : never : never : never) | 'root' | 'unauthenticated';
|
|
4
6
|
export type AcceptedRole = UserRole | UserRole[] | null | unknown;
|
|
5
|
-
export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null
|
|
7
|
+
export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null, TUserRole = UserRole, TUserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>> = {
|
|
6
8
|
authenticated: true;
|
|
7
9
|
sub: ObjectId;
|
|
8
|
-
roles: readonly (TAcceptedRole extends null ?
|
|
9
|
-
userinfo:
|
|
10
|
+
roles: readonly (TAcceptedRole extends null ? TUserRole : TAcceptedRole)[];
|
|
11
|
+
userinfo: TUserInfo | PackReferences<TUserInfo>;
|
|
10
12
|
};
|
|
11
13
|
export type UnauthenticatedToken = {
|
|
12
14
|
authenticated: false;
|
|
@@ -16,4 +18,4 @@ export type TokenRecipient = {
|
|
|
16
18
|
type: 'bearer';
|
|
17
19
|
content: string;
|
|
18
20
|
};
|
|
19
|
-
export type Token<TAcceptedRole extends AcceptedRole = null
|
|
21
|
+
export type Token<TAcceptedRole extends AcceptedRole = null, TUserRole = UserRole, TUserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>> = (null extends TAcceptedRole ? true : 'unauthenticated' extends TAcceptedRole ? true : false) extends true ? AuthenticatedToken<null, TUserRole, TUserInfo> | UnauthenticatedToken : AuthenticatedToken<TAcceptedRole>;
|
package/dist/validation.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare enum PropertyValidationErrorCode {
|
|
|
8
8
|
Extraneous = "EXTRANEOUS_PROPERTY",
|
|
9
9
|
Unmatching = "UNMATCHING_PROPERTIES",
|
|
10
10
|
ExtraneousElement = "EXTRANEOUS_ELEMENT",
|
|
11
|
+
MoreItemsExpected = "MORE_ITEMS_EXPECTED",
|
|
12
|
+
LessItemsExpected = "LESS_ITEMS_EXPECTED",
|
|
11
13
|
NumericConstraint = "NUMERIC_CONSTRAINT"
|
|
12
14
|
}
|
|
13
15
|
export declare enum TraverseError {
|
|
@@ -17,9 +19,9 @@ export declare enum TraverseError {
|
|
|
17
19
|
export type PropertyValidationError = {
|
|
18
20
|
type: PropertyValidationErrorCode;
|
|
19
21
|
index?: number;
|
|
20
|
-
details
|
|
21
|
-
expected:
|
|
22
|
-
got:
|
|
22
|
+
details?: {
|
|
23
|
+
expected: unknown;
|
|
24
|
+
got: unknown;
|
|
23
25
|
};
|
|
24
26
|
};
|
|
25
27
|
export type ValidationErrorInvalidProperties = {
|
package/dist/validation.js
CHANGED
|
@@ -13,6 +13,8 @@ var PropertyValidationErrorCode;
|
|
|
13
13
|
PropertyValidationErrorCode["Extraneous"] = "EXTRANEOUS_PROPERTY";
|
|
14
14
|
PropertyValidationErrorCode["Unmatching"] = "UNMATCHING_PROPERTIES";
|
|
15
15
|
PropertyValidationErrorCode["ExtraneousElement"] = "EXTRANEOUS_ELEMENT";
|
|
16
|
+
PropertyValidationErrorCode["MoreItemsExpected"] = "MORE_ITEMS_EXPECTED";
|
|
17
|
+
PropertyValidationErrorCode["LessItemsExpected"] = "LESS_ITEMS_EXPECTED";
|
|
16
18
|
PropertyValidationErrorCode["NumericConstraint"] = "NUMERIC_CONSTRAINT";
|
|
17
19
|
})(PropertyValidationErrorCode || (exports.PropertyValidationErrorCode = PropertyValidationErrorCode = {}));
|
|
18
20
|
var TraverseError;
|
package/dist/validation.mjs
CHANGED
|
@@ -10,6 +10,8 @@ export var PropertyValidationErrorCode = /* @__PURE__ */ ((PropertyValidationErr
|
|
|
10
10
|
PropertyValidationErrorCode2["Extraneous"] = "EXTRANEOUS_PROPERTY";
|
|
11
11
|
PropertyValidationErrorCode2["Unmatching"] = "UNMATCHING_PROPERTIES";
|
|
12
12
|
PropertyValidationErrorCode2["ExtraneousElement"] = "EXTRANEOUS_ELEMENT";
|
|
13
|
+
PropertyValidationErrorCode2["MoreItemsExpected"] = "MORE_ITEMS_EXPECTED";
|
|
14
|
+
PropertyValidationErrorCode2["LessItemsExpected"] = "LESS_ITEMS_EXPECTED";
|
|
13
15
|
PropertyValidationErrorCode2["NumericConstraint"] = "NUMERIC_CONSTRAINT";
|
|
14
16
|
return PropertyValidationErrorCode2;
|
|
15
17
|
})(PropertyValidationErrorCode || {});
|