@aeriajs/types 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright 2023 João Santos (joaosan177@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the “Software”), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # `@aeriajs/types`
2
+
3
+ ## Introduction
4
+
5
+ This package exports types used by `@aeriajs/*` packages.
6
+ Many types had to be put separately from their origin packages in order to build Aeria.
@@ -0,0 +1,30 @@
1
+ import type { Collection } from '.';
2
+ export declare enum ACErrors {
3
+ AuthorizationError = "AUTHORIZATION_ERROR",
4
+ AuthenticationError = "AUTHENTICATION_ERROR",
5
+ ImmutabilityIncorrectChild = "IMMUTABILITY_INCORRECT_CHILD",
6
+ ImmutabilityParentNotFound = "IMMUTABILITY_PARENT_NOT_FOUND",
7
+ ImmutabilityTargetImmutable = "IMMUTABILITY_TARGET_IMMUTABLE",
8
+ OwnershipError = "OWNERSHIP_ERROR",
9
+ ResourceNotFound = "RESOURCE_NOT_FOUND",
10
+ AssetNotFound = "ASSET_NOT_FOUND",
11
+ FunctionNotFound = "FUNCTION_NOT_FOUND",
12
+ InvalidLimit = "INVALID_LIMIT"
13
+ }
14
+ export type Role<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection> = any> = {
15
+ inherit?: readonly (keyof TAccessControl['roles'])[];
16
+ grantEverything?: boolean;
17
+ grant?: readonly (keyof TCollection['functions'])[];
18
+ forbid?: readonly (keyof TCollection['functions'])[];
19
+ };
20
+ export type Roles<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection> = any> = Record<string, Role<TCollection, TAccessControl>>;
21
+ export type InternalAccessControl<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection, TAccessControl> = any> = {
22
+ roles?: Roles<TCollection, TAccessControl>;
23
+ availableRoles?: keyof TAccessControl['roles'];
24
+ parent?: TAccessControl['roles'];
25
+ };
26
+ export type AccessControl<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection, TAccessControl> = any> = InternalAccessControl<TCollection, TAccessControl>;
27
+ export type ACProfile = {
28
+ readonly roles?: string[];
29
+ readonly allowed_functions?: string[];
30
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ACErrors = void 0;
4
+ var ACErrors;
5
+ (function (ACErrors) {
6
+ ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
7
+ ACErrors["AuthenticationError"] = "AUTHENTICATION_ERROR";
8
+ ACErrors["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
9
+ ACErrors["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
10
+ ACErrors["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
11
+ ACErrors["OwnershipError"] = "OWNERSHIP_ERROR";
12
+ ACErrors["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
13
+ ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
14
+ ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
15
+ ACErrors["InvalidLimit"] = "INVALID_LIMIT";
16
+ })(ACErrors || (exports.ACErrors = ACErrors = {}));
@@ -0,0 +1,13 @@
1
+ export var ACErrors;
2
+ (function(ACErrors) {
3
+ ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
4
+ ACErrors["AuthenticationError"] = "AUTHENTICATION_ERROR";
5
+ ACErrors["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
6
+ ACErrors["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
7
+ ACErrors["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
8
+ ACErrors["OwnershipError"] = "OWNERSHIP_ERROR";
9
+ ACErrors["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
10
+ ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
11
+ ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
12
+ ACErrors["InvalidLimit"] = "INVALID_LIMIT";
13
+ })(ACErrors || (ACErrors = {}));
package/dist/api.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import type { ObjectId, Context, Description, SecurityPolicy, AccessControl, PackReferences } from '.';
2
+ export type Collection<TCollection extends Collection = any> = {
3
+ description: Description;
4
+ item?: any;
5
+ security?: SecurityPolicy;
6
+ accessControl?: AccessControl<TCollection>;
7
+ functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
8
+ };
9
+ export type AssetType = keyof Collection;
10
+ export type FunctionPath = `${string}@${string}`;
11
+ export type UserACProfile = {
12
+ readonly roles: string[];
13
+ readonly allowed_functions?: string[];
14
+ };
15
+ export type DecodedToken = {
16
+ authenticated: true;
17
+ sub: ObjectId;
18
+ roles: string[];
19
+ userinfo: PackReferences<Collections['user']['item']>;
20
+ allowed_functions?: FunctionPath[];
21
+ } | {
22
+ authenticated: false;
23
+ sub: null;
24
+ };
package/dist/api.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/api.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,22 @@
1
+ import type { JsonSchema, PropertiesWithId } from './property';
2
+ export type FinalOperator = 'equal' | 'in' | 'gt' | 'lt' | 'gte' | 'lte';
3
+ export type FinalCondition<TSchema extends JsonSchema = any> = {
4
+ operator: FinalOperator;
5
+ term1: PropertiesWithId<TSchema>;
6
+ term2: any;
7
+ else?: any;
8
+ };
9
+ export type TruthyCondition<TSchema extends JsonSchema = any> = {
10
+ operator: 'truthy';
11
+ term1: PropertiesWithId<TSchema>;
12
+ };
13
+ export type OrCondition<TSchema extends JsonSchema = any> = {
14
+ or: readonly Condition<TSchema>[];
15
+ };
16
+ export type AndCondition<TSchema extends JsonSchema = any> = {
17
+ and: readonly Condition<TSchema>[];
18
+ };
19
+ export type NotCondition<TSchema extends JsonSchema = any> = {
20
+ not: Condition<TSchema>;
21
+ };
22
+ export type Condition<TSchema extends JsonSchema = any> = FinalCondition<TSchema> | TruthyCondition<TSchema> | AndCondition<TSchema> | OrCondition<TSchema> | NotCondition<TSchema>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,27 @@
1
+ import type { Context } from './context';
2
+ export type ApiConfig = {
3
+ secret?: string;
4
+ apiUrl?: string;
5
+ port?: number;
6
+ paginationLimit?: number;
7
+ database?: {
8
+ mongodbUrl?: string;
9
+ noDatabase?: boolean;
10
+ };
11
+ storage?: {
12
+ fs?: string;
13
+ tempFs?: string;
14
+ };
15
+ defaultUser?: {
16
+ username: string;
17
+ password: string;
18
+ };
19
+ allowSignup?: boolean;
20
+ signupDefaults?: Partial<{
21
+ roles: string[];
22
+ active: boolean;
23
+ }>;
24
+ logSuccessfulAuthentications?: boolean;
25
+ tokenUserProperties?: string[];
26
+ errorHandler?: <TError extends Error>(context: Context, error: TError) => any | Promise<any>;
27
+ };
package/dist/config.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,42 @@
1
+ import type { Collection as MongoCollection } from 'mongodb';
2
+ import type { GenericRequest, GenericResponse } from './http';
3
+ import type { Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, ApiConfig, CollectionDocument, CollectionFunctions } from '.';
4
+ export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
5
+ type OmitContextParameter<TFunction> = TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
6
+ type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
7
+ type UnionFunctions<TFunctions, TSchema extends CollectionDocument<any>> = {
8
+ [P in keyof TFunctions]: P extends keyof CollectionFunctions<any> ? CollectionFunctions<TSchema>[P] extends infer CollFunction ? CollFunction extends (...args: any[]) => any ? Extract<undefined, Parameters<CollFunction>[0]> extends never ? (payload: Parameters<CollFunction>[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : (payload?: Parameters<CollFunction>[0], ...args: RestParameters<TFunctions[P]>) => ReturnType<CollFunction> : never : never : OmitContextParameter<TFunctions[P]>;
9
+ };
10
+ export type IndepthCollection<TCollection> = TCollection extends {
11
+ description: infer InferredDescription;
12
+ functions: infer CollFunctions;
13
+ } ? Omit<TCollection, 'functions'> & {
14
+ functions: UnionFunctions<CollFunctions, SchemaWithId<InferredDescription>>;
15
+ originalFunctions: CollFunctions;
16
+ model: InferredDescription extends Description ? CollectionModel<InferredDescription> : never;
17
+ } : TCollection;
18
+ export type IndepthCollections = {
19
+ [P in keyof Collections]: IndepthCollection<Collections[P]>;
20
+ };
21
+ export type ContextOptions<TContext> = {
22
+ config?: ApiConfig;
23
+ parentContext?: TContext;
24
+ collectionName?: string;
25
+ token?: DecodedToken;
26
+ };
27
+ export type Context<TDescription extends Description = any, TFunctions = any> = {
28
+ description: TDescription;
29
+ collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
30
+ description: TDescription;
31
+ functions: TFunctions;
32
+ }> : TDescription;
33
+ collections: IndepthCollections;
34
+ functionPath: FunctionPath;
35
+ token: DecodedToken;
36
+ collectionName?: (keyof Collections & string) | string;
37
+ request: GenericRequest;
38
+ response: GenericResponse;
39
+ log: (message: string, details?: any) => Promise<any>;
40
+ config: ApiConfig;
41
+ };
42
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,107 @@
1
+ import type { IconStyle, PhosphorIcon } from '@phosphor-icons/core';
2
+ import type { JsonSchema, PropertiesWithId } from './property';
3
+ import type { Condition } from './condition';
4
+ export type CollectionPresets = 'crud' | 'duplicate' | 'remove' | 'removeAll' | 'owned' | 'timestamped' | 'view';
5
+ export type Icon = PhosphorIcon['name'] | `${IconStyle}:${PhosphorIcon['name']}`;
6
+ export type CollectionAction<TDescription extends Description> = Readonly<{
7
+ name: string;
8
+ icon?: Icon;
9
+ ask?: boolean;
10
+ selection?: boolean;
11
+ effect?: string;
12
+ button?: boolean;
13
+ translate?: boolean;
14
+ setItem?: boolean;
15
+ fetchItem?: boolean;
16
+ clearItem?: boolean;
17
+ params?: Record<string, any>;
18
+ query?: Record<string, any>;
19
+ requires?: readonly PropertiesWithId<TDescription>[];
20
+ }>;
21
+ export type CollectionActions<TDescription extends Description> = Record<string, null | CollectionAction<TDescription>>;
22
+ export type FormLayout<TDescription extends Description> = {
23
+ fields?: Partial<Record<PropertiesWithId<TDescription>, FormLayoutField<TDescription>>>;
24
+ };
25
+ export type FormLayoutField<TDescription extends Description> = {
26
+ span?: number;
27
+ verticalSpacing?: number;
28
+ separator?: true | 'top' | 'bottom';
29
+ if?: Condition<TDescription>;
30
+ component?: {
31
+ name: string;
32
+ props?: Record<string, any>;
33
+ };
34
+ };
35
+ export type TableLayout<TDescription extends Description> = {
36
+ actions: Partial<Record<keyof TDescription['individualActions'], {
37
+ button?: boolean | Condition<TDescription>;
38
+ if?: Condition<TDescription>;
39
+ }>>;
40
+ };
41
+ export type FiltersPreset<TDescription extends Description> = {
42
+ name?: string;
43
+ icon?: Icon;
44
+ filters?: Partial<Record<PropertiesWithId<TDescription> | `$${string}`, any>>;
45
+ table?: readonly PropertiesWithId<TDescription>[];
46
+ badgeFunction?: string;
47
+ default?: boolean;
48
+ };
49
+ export type CollectionOptions<TDescription extends Description> = {
50
+ queryPreset?: {
51
+ filters?: Partial<Record<PropertiesWithId<TDescription> | `$${string}`, any>>;
52
+ sort?: Partial<Record<PropertiesWithId<TDescription>, any>>;
53
+ };
54
+ };
55
+ export type LayoutName = 'tabular' | 'grid' | 'list';
56
+ export type LayoutOptions<TDescription extends Description = any> = {
57
+ picture?: PropertiesWithId<TDescription>;
58
+ title?: PropertiesWithId<TDescription>;
59
+ badge?: PropertiesWithId<TDescription>;
60
+ information?: PropertiesWithId<TDescription>;
61
+ active?: PropertiesWithId<TDescription>;
62
+ translateBadge?: boolean;
63
+ };
64
+ export type Layout<TDescription extends Description = any> = {
65
+ name: LayoutName;
66
+ options?: LayoutOptions<TDescription>;
67
+ };
68
+ export type SearchOptions<TDescription extends Description> = {
69
+ placeholder?: string;
70
+ indexes: readonly (keyof TDescription['properties'])[];
71
+ };
72
+ export type Description<TDescription extends Description = any> = JsonSchema<TDescription> & {
73
+ title?: string;
74
+ categories?: string[];
75
+ system?: boolean;
76
+ inline?: boolean;
77
+ preferred?: Record<string, Partial<TDescription | Description>>;
78
+ icon?: Icon;
79
+ options?: CollectionOptions<TDescription>;
80
+ indexes?: ReadonlyArray<string>;
81
+ defaults?: Record<string, any>;
82
+ owned?: boolean | 'always';
83
+ temporary?: {
84
+ index: keyof TDescription['properties'];
85
+ expireAfterSeconds: number;
86
+ };
87
+ timestamps?: false;
88
+ immutable?: boolean | ReadonlyArray<string>;
89
+ route?: ReadonlyArray<string>;
90
+ presets?: ReadonlyArray<CollectionPresets>;
91
+ table?: ReadonlyArray<PropertiesWithId<TDescription>>;
92
+ tableMeta?: ReadonlyArray<PropertiesWithId<TDescription>>;
93
+ filtersPresets?: Record<string, FiltersPreset<TDescription>>;
94
+ freshItem?: Partial<Record<PropertiesWithId<TDescription>, any>>;
95
+ form?: ReadonlyArray<PropertiesWithId<TDescription>> | Record<PropertiesWithId<TDescription>, string[]>;
96
+ writable?: ReadonlyArray<PropertiesWithId<TDescription>>;
97
+ filters?: ReadonlyArray<PropertiesWithId<TDescription> | {
98
+ property: PropertiesWithId<TDescription>;
99
+ default: string;
100
+ }>;
101
+ layout?: Layout<TDescription>;
102
+ formLayout?: Partial<FormLayout<TDescription>>;
103
+ tableLayout?: Partial<TableLayout<TDescription>>;
104
+ actions?: CollectionActions<TDescription>;
105
+ individualActions?: CollectionActions<TDescription>;
106
+ search?: SearchOptions<TDescription>;
107
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,9 @@
1
+ export type Left<T> = {
2
+ readonly _tag: 'Left';
3
+ readonly value: T;
4
+ };
5
+ export type Right<T> = {
6
+ readonly _tag: 'Right';
7
+ readonly value: T;
8
+ };
9
+ export type Either<L, R> = Left<L> | Right<R>;
package/dist/either.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,55 @@
1
+ import type { FilterOperators, UpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
2
+ import type { PackReferences, Either, ValidationError } from '.';
3
+ export type UploadAuxProps = {
4
+ parentId: string;
5
+ propertyName: string;
6
+ };
7
+ export type Filters<TDocument> = FilterOperators<TDocument>;
8
+ export type What<TDocument> = Omit<UpdateFilter<TDocument>, keyof TDocument> & {
9
+ [P in keyof TDocument]?: '_id' extends keyof TDocument[P] ? TDocument[P] | string : TDocument[P];
10
+ };
11
+ export type Projection<TDocument extends Record<string, any>> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
12
+ export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
13
+ export type CollectionDocument<TDocument> = Pick<TDocument, Extract<keyof TDocument, string>>;
14
+ export type CountPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
15
+ filters?: Filters<TDocument>;
16
+ };
17
+ export type GetPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
18
+ filters: Filters<TDocument>;
19
+ project?: Projection<TDocument>;
20
+ populate?: (keyof TDocument & string)[];
21
+ };
22
+ export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
23
+ filters?: Filters<TDocument>;
24
+ project?: Projection<TDocument>;
25
+ offset?: number;
26
+ limit?: number;
27
+ sort?: QuerySort<TDocument>;
28
+ populate?: (keyof TDocument & string)[];
29
+ };
30
+ export type InsertPayload<TDocument extends CollectionDocument<any>> = {
31
+ what: What<PackReferences<TDocument> & {
32
+ _id?: any;
33
+ }>;
34
+ project?: Projection<TDocument>;
35
+ };
36
+ export type RemovePayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
37
+ filters: Filters<TDocument>;
38
+ };
39
+ export type RemoveAllPayload = {
40
+ filters: (string | ObjectId)[];
41
+ };
42
+ export type RemoveFilePayload = UploadAuxProps & {
43
+ filters: {
44
+ _id: any;
45
+ };
46
+ };
47
+ export type CollectionFunctions<TDocument extends CollectionDocument<OptionalId<any>>> = {
48
+ count: (payload: CountPayload<TDocument>) => Promise<number>;
49
+ get: (payload: GetPayload<TDocument>) => Promise<TDocument | null>;
50
+ getAll: (payload?: GetAllPayload<TDocument>) => Promise<TDocument[]>;
51
+ insert: (payload: InsertPayload<TDocument>) => Promise<Either<ValidationError, TDocument>>;
52
+ remove: (payload: RemovePayload<TDocument>) => Promise<TDocument>;
53
+ removeAll: (payload: RemoveAllPayload) => Promise<any>;
54
+ removeFile: (payload: RemoveFilePayload) => Promise<any>;
55
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
package/dist/http.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import type { ServerResponse, IncomingMessage } from 'http';
3
+ import type { MapSchemaUnion } from './schema';
4
+ export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
5
+ export type RequestMethod = (typeof REQUEST_METHODS)[number];
6
+ export type GenericRequest = {
7
+ url: string;
8
+ method: RequestMethod;
9
+ headers: Record<string, any>;
10
+ body?: string;
11
+ query: Record<string, any>;
12
+ payload: Record<string, any>;
13
+ fragments: string[];
14
+ nodeRequest: IncomingMessage;
15
+ };
16
+ export type GenericResponse = ServerResponse;
17
+ export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? (payload?: any) => Promise<TRouteResponse> : TRoutePayload extends undefined ? () => Promise<TRouteResponse> : (payload: TRoutePayload) => Promise<TRouteResponse>) extends infer Function ? Record<TRouteMethod, Function> : never;
18
+ export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse = any, 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>>;
19
+ type UnwrapResponse<TResponse> = TResponse extends readonly any[] ? TResponse : TResponse[];
20
+ export type InferResponse<TResponse> = MapSchemaUnion<UnwrapResponse<TResponse>> extends infer InferredResponse ? InferredResponse | Promise<InferredResponse> : never;
21
+ export {};
package/dist/http.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REQUEST_METHODS = void 0;
4
+ exports.REQUEST_METHODS = [
5
+ 'GET',
6
+ 'HEAD',
7
+ 'POST',
8
+ 'PUT',
9
+ 'DELETE',
10
+ 'OPTIONS',
11
+ 'PATCH',
12
+ 'TRACE',
13
+ 'SEARCH',
14
+ ];
package/dist/http.mjs ADDED
@@ -0,0 +1,11 @@
1
+ export var REQUEST_METHODS = [
2
+ "GET",
3
+ "HEAD",
4
+ "POST",
5
+ "PUT",
6
+ "DELETE",
7
+ "OPTIONS",
8
+ "PATCH",
9
+ "TRACE",
10
+ "SEARCH"
11
+ ];
@@ -0,0 +1,15 @@
1
+ export * from './accessControl.js';
2
+ export * from './api.js';
3
+ export * from './condition.js';
4
+ export * from './config.js';
5
+ export * from './context.js';
6
+ export * from './description.js';
7
+ export * from './either.js';
8
+ export * from './functions.js';
9
+ export * from './http.js';
10
+ export * from './property.js';
11
+ export * from './schema.js';
12
+ export * from './security.js';
13
+ export * from './validation.js';
14
+ export { ObjectId, } from 'mongodb';
15
+ export type { WithId, OptionalId, } from 'mongodb';
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
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.ObjectId = void 0;
18
+ __exportStar(require("./accessControl.js"), exports);
19
+ __exportStar(require("./api.js"), exports);
20
+ __exportStar(require("./condition.js"), exports);
21
+ __exportStar(require("./config.js"), exports);
22
+ __exportStar(require("./context.js"), exports);
23
+ __exportStar(require("./description.js"), exports);
24
+ __exportStar(require("./either.js"), exports);
25
+ __exportStar(require("./functions.js"), exports);
26
+ __exportStar(require("./http.js"), exports);
27
+ __exportStar(require("./property.js"), exports);
28
+ __exportStar(require("./schema.js"), exports);
29
+ __exportStar(require("./security.js"), exports);
30
+ __exportStar(require("./validation.js"), exports);
31
+ var mongodb_1 = require("mongodb");
32
+ Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
package/dist/index.mjs ADDED
@@ -0,0 +1,14 @@
1
+ export * from "./accessControl.mjs";
2
+ export * from "./api.mjs";
3
+ export * from "./condition.mjs";
4
+ export * from "./config.mjs";
5
+ export * from "./context.mjs";
6
+ export * from "./description.mjs";
7
+ export * from "./either.mjs";
8
+ export * from "./functions.mjs";
9
+ export * from "./http.mjs";
10
+ export * from "./property.mjs";
11
+ export * from "./schema.mjs";
12
+ export * from "./security.mjs";
13
+ export * from "./validation.mjs";
14
+ export { ObjectId } from "mongodb";
@@ -0,0 +1,113 @@
1
+ import type { PhosphorIcon } from '@phosphor-icons/core';
2
+ import type { Condition } from '.';
3
+ export type PropertyArrayElement = 'checkbox' | 'radio' | 'select';
4
+ export type PropertyInputType = 'text' | 'email' | 'password' | 'search' | 'time' | 'month';
5
+ export type PropertyFormat = 'date' | 'date-time';
6
+ export type PropertiesWithId<TSchema extends JsonSchema> = keyof TSchema['properties'] | '_id';
7
+ export type RequiredProperties<TSchema extends JsonSchema> = ReadonlyArray<PropertiesWithId<TSchema>> | Partial<Record<PropertiesWithId<TSchema>, Condition<TSchema> | boolean>>;
8
+ export type JsonSchema<TJsonSchema extends JsonSchema = any> = {
9
+ $id: string;
10
+ type?: 'object';
11
+ required?: RequiredProperties<TJsonSchema>;
12
+ properties: Record<string, Property>;
13
+ };
14
+ export type NonCircularJsonSchema<TJsonSchema extends NonCircularJsonSchema = any> = Omit<JsonSchema<TJsonSchema>, 'properties'> & {
15
+ properties: Record<string, NonCircularProperty>;
16
+ };
17
+ export type RefProperty = {
18
+ $ref: Exclude<keyof Collections, 'file'> & string;
19
+ indexes?: ReadonlyArray<string>;
20
+ populate?: ReadonlyArray<string>;
21
+ select?: ReadonlyArray<string>;
22
+ inline?: boolean;
23
+ form?: ReadonlyArray<string>;
24
+ purge?: boolean;
25
+ constraints?: Condition;
26
+ };
27
+ export type NonCircularRefProperty = Omit<RefProperty, '$ref'> & {
28
+ $ref: string;
29
+ };
30
+ export type FileProperty = Omit<RefProperty, '$ref'> & {
31
+ $ref: 'file';
32
+ accept?: ReadonlyArray<string>;
33
+ extensions?: ReadonlyArray<string>;
34
+ };
35
+ export type EnumProperty = {
36
+ enum: ReadonlyArray<any>;
37
+ default?: any;
38
+ element?: PropertyArrayElement;
39
+ };
40
+ export type ArrayProperty = {
41
+ type: 'array';
42
+ items: Property;
43
+ uniqueItems?: boolean;
44
+ minItems?: number;
45
+ maxItems?: number;
46
+ element?: PropertyArrayElement;
47
+ };
48
+ export type FixedObjectProperty = {
49
+ properties: Record<string, Property>;
50
+ form?: ReadonlyArray<string>;
51
+ required?: ReadonlyArray<string>;
52
+ };
53
+ export type VariableObjectProperty = {
54
+ variable: true;
55
+ } | {
56
+ additionalProperties: Property;
57
+ };
58
+ export type ObjectProperty = (FixedObjectProperty | VariableObjectProperty) & {
59
+ type: 'object';
60
+ default?: any;
61
+ };
62
+ export type StringProperty = {
63
+ type: 'string';
64
+ minLength?: number;
65
+ maxLength?: number;
66
+ format?: PropertyFormat;
67
+ default?: string | Date;
68
+ mask?: string | ReadonlyArray<string>;
69
+ placeholder?: string;
70
+ element?: 'textarea';
71
+ inputType?: PropertyInputType;
72
+ };
73
+ export type NumberProperty = {
74
+ type: 'number' | 'integer';
75
+ minimum?: number;
76
+ maximum?: number;
77
+ exclusiveMinimum?: number;
78
+ exclusiveMaximum?: number;
79
+ default?: number;
80
+ placeholder?: string;
81
+ };
82
+ export type BooleanProperty = {
83
+ type: 'boolean';
84
+ default?: boolean;
85
+ element?: 'checkbox';
86
+ };
87
+ export type ArrayOfRefs = Omit<ArrayProperty, 'items'> & {
88
+ items: RefProperty;
89
+ };
90
+ export type LiteralProperty = {
91
+ literal: string | number | boolean;
92
+ };
93
+ export type GetterProperty = {
94
+ getter: (document: any) => any;
95
+ };
96
+ export type MixedProperty = RefProperty | FileProperty | EnumProperty | ArrayProperty | ObjectProperty | StringProperty | NumberProperty | BooleanProperty | LiteralProperty | GetterProperty;
97
+ export type NonCircularMixedProperty = NonCircularRefProperty | FileProperty | EnumProperty | ArrayProperty | ObjectProperty | StringProperty | NumberProperty | BooleanProperty | LiteralProperty | GetterProperty;
98
+ export type PropertyBase = {
99
+ description?: string;
100
+ readOnly?: boolean;
101
+ focus?: boolean;
102
+ icon?: PhosphorIcon['name'];
103
+ translate?: boolean;
104
+ hint?: string;
105
+ componentProps?: Record<string, any>;
106
+ noForm?: boolean;
107
+ noLabel?: boolean;
108
+ hidden?: boolean;
109
+ unique?: boolean;
110
+ isTimestamp?: boolean;
111
+ };
112
+ export type Property = PropertyBase & MixedProperty;
113
+ export type NonCircularProperty = PropertyBase & NonCircularMixedProperty;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,122 @@
1
+ import type { ObjectId } from 'mongodb';
2
+ type Owned = {
3
+ owner?: Collections['user']['item'];
4
+ };
5
+ type Timestamped = {
6
+ updated_at?: Date;
7
+ created_at?: Date;
8
+ };
9
+ type CaseOwned<TSchema, TType> = TSchema extends {
10
+ owned: true | string;
11
+ } ? TType & Owned : TType;
12
+ type CaseTimestamped<TSchema, TType> = TSchema extends {
13
+ timestamps: false;
14
+ } ? TType : TType & Timestamped;
15
+ type TestType<T> = T & Record<string, any>;
16
+ export type InferProperty<T> = T extends TestType<{
17
+ format: 'date' | 'date-time';
18
+ }> ? Date : T extends TestType<{
19
+ enum: ReadonlyArray<infer K>;
20
+ }> ? K : T extends TestType<{
21
+ type: 'string';
22
+ }> ? string : T extends TestType<{
23
+ type: 'number';
24
+ }> ? number : T extends TestType<{
25
+ type: 'boolean';
26
+ }> ? boolean : T extends TestType<{
27
+ properties: any;
28
+ }> ? Schema<T & {
29
+ timestamps: false;
30
+ }> : T extends TestType<{
31
+ type: 'object';
32
+ }> ? any : T extends TestType<{
33
+ literal: infer K;
34
+ }> ? K : T extends TestType<{
35
+ items: infer K;
36
+ }> ? InferProperty<K>[] : T extends TestType<{
37
+ getter: (doc: any) => infer K;
38
+ }> ? K : never;
39
+ export type InferSchema<TSchema> = MergeReferences<TSchema> extends infer MappedTypes ? TSchema extends {
40
+ required: readonly [];
41
+ } ? Partial<MappedTypes> : TSchema extends {
42
+ required: infer RequiredPropNames;
43
+ } ? RequiredPropNames extends readonly (keyof MappedTypes)[] ? Pick<MappedTypes, RequiredPropNames[number]> extends infer RequiredProps ? RequiredProps & Partial<Exclude<MappedTypes, keyof RequiredProps>> : never : never : MappedTypes : never;
44
+ export type Schema<TSchema> = CaseTimestamped<TSchema, CaseOwned<TSchema, InferSchema<TSchema>>>;
45
+ export type SchemaWithId<TSchema> = Schema<TSchema> & {
46
+ _id: ObjectId;
47
+ };
48
+ export type MapSchemaUnion<TSchema> = TSchema extends readonly (infer SchemaOption)[] ? SchemaOption extends any ? SchemaOption extends {
49
+ $ref: infer K;
50
+ } | {
51
+ items: {
52
+ $ref: infer K;
53
+ };
54
+ } ? K extends keyof Collections ? 'items' extends keyof SchemaOption ? Collections[K]['item'][] : Collections[K]['item'] : never : InferProperty<SchemaOption> : never : InferProperty<TSchema>;
55
+ export type ObjectToSchema<TObject, TRequired extends string[] | null = null> = TObject extends readonly [infer K] ? ValueToProperty<[K]> : keyof TObject extends never ? {
56
+ type: 'object';
57
+ } : {
58
+ [P in keyof TObject]: TObject[P] extends infer Value ? ValueToProperty<Value> : never;
59
+ } extends infer Properties ? TRequired extends null ? {
60
+ type: 'object';
61
+ properties: Properties;
62
+ } : {
63
+ type: 'object';
64
+ required: TRequired;
65
+ properties: Properties;
66
+ } : never;
67
+ export type PackReferences<T> = {
68
+ [P in keyof T]: PackReferencesAux<T[P]>;
69
+ };
70
+ export type FilterReadonlyProperties<TProperties> = {
71
+ [P in keyof TProperties as TProperties[P] extends {
72
+ readOnly: true;
73
+ } ? P : never]: InferProperty<TProperties[P]>;
74
+ };
75
+ type MapReferences<TSchema> = TSchema extends {
76
+ properties: infer Properties;
77
+ } ? {
78
+ -readonly [P in keyof Properties as Properties[P] extends TestType<{
79
+ $ref: string;
80
+ }> | TestType<{
81
+ items: {
82
+ $ref: string;
83
+ };
84
+ }> ? P : never]: Properties[P] extends infer Prop ? Prop extends TestType<{
85
+ $ref: infer K;
86
+ }> ? K extends keyof Collections ? Collections[K]['item'] : never : Prop extends TestType<{
87
+ items: TestType<{
88
+ $ref: infer K;
89
+ }>;
90
+ }> ? K extends keyof Collections ? Collections[K]['item'][] : never : never : never;
91
+ } : never;
92
+ type PackReferencesAux<T> = T extends (...args: any[]) => any ? T : T extends {
93
+ _id: infer Id;
94
+ } ? Id : T extends Record<string, any> ? PackReferences<T> : T extends any[] | readonly any[] ? PackReferencesAux<T[number]>[] : T;
95
+ type CombineProperties<TSchema> = TSchema extends {
96
+ properties: infer Properties;
97
+ } ? FilterReadonlyProperties<Properties> extends infer ReadonlyProperties ? Readonly<ReadonlyProperties> & {
98
+ [P in Exclude<keyof Properties, keyof ReadonlyProperties>]: InferProperty<Properties[P]>;
99
+ } : never : never;
100
+ type MergeReferences<TSchema> = CombineProperties<TSchema> extends infer CombinedProperties ? MapReferences<TSchema> extends infer MappedReferences ? MappedReferences & Omit<CombinedProperties, keyof MappedReferences> : never : never;
101
+ type ValueToProperty<TValue> = TValue extends `$${infer Ref}` ? {
102
+ $ref: Ref;
103
+ } : TValue extends string ? {
104
+ type: 'string';
105
+ } : TValue extends number ? {
106
+ type: 'number';
107
+ } : TValue extends boolean ? {
108
+ type: 'boolean';
109
+ } : TValue extends new () => Date ? {
110
+ type: 'string';
111
+ format: 'date';
112
+ } : TValue extends readonly [infer K] ? {
113
+ type: 'array';
114
+ items: ValueToProperty<K>;
115
+ } : TValue extends (infer K)[] ? {
116
+ enum: K;
117
+ } : TValue extends Record<string, any> ? keyof TValue extends never ? {
118
+ type: 'object';
119
+ } : {
120
+ type: 'object';
121
+ } & ObjectToSchema<TValue> : never;
122
+ export {};
package/dist/schema.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,10 @@
1
+ export type RateLimitingParams = {
2
+ limit?: number;
3
+ scale?: number;
4
+ increment?: number;
5
+ };
6
+ export type SecurityPolicy = {
7
+ allowQueryOperators?: string[];
8
+ rateLimiting?: Record<string, RateLimitingParams>;
9
+ accessControl?: any;
10
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,26 @@
1
+ export declare enum ValidationErrorCodes {
2
+ InvalidProperties = "INVALID_PROPERTIES",
3
+ MissingProperties = "MISSING_PROPERTIES",
4
+ EmptyTarget = "EMPTY_TARGET"
5
+ }
6
+ export type PropertyValidationErrorType = 'missing' | 'extraneous' | 'unmatching' | 'extraneous_element' | 'numeric_constraint';
7
+ export type PropertyValidationError = {
8
+ type: PropertyValidationErrorType;
9
+ index?: number;
10
+ details: {
11
+ expected: any;
12
+ got: string;
13
+ };
14
+ };
15
+ export type ValidationError = {
16
+ code: ValidationErrorCodes.InvalidProperties;
17
+ errors: Record<string, PropertyValidationError | ValidationError>;
18
+ } | {
19
+ code: ValidationErrorCodes.MissingProperties;
20
+ errors: Record<string, {
21
+ type: 'missing';
22
+ }>;
23
+ } | {
24
+ code: ValidationErrorCodes.EmptyTarget;
25
+ errors: {};
26
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationErrorCodes = void 0;
4
+ var ValidationErrorCodes;
5
+ (function (ValidationErrorCodes) {
6
+ ValidationErrorCodes["InvalidProperties"] = "INVALID_PROPERTIES";
7
+ ValidationErrorCodes["MissingProperties"] = "MISSING_PROPERTIES";
8
+ ValidationErrorCodes["EmptyTarget"] = "EMPTY_TARGET";
9
+ })(ValidationErrorCodes || (exports.ValidationErrorCodes = ValidationErrorCodes = {}));
@@ -0,0 +1,6 @@
1
+ export var ValidationErrorCodes;
2
+ (function(ValidationErrorCodes) {
3
+ ValidationErrorCodes["InvalidProperties"] = "INVALID_PROPERTIES";
4
+ ValidationErrorCodes["MissingProperties"] = "MISSING_PROPERTIES";
5
+ ValidationErrorCodes["EmptyTarget"] = "EMPTY_TARGET";
6
+ })(ValidationErrorCodes || (ValidationErrorCodes = {}));
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@aeriajs/types",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "keywords": [],
19
+ "author": "",
20
+ "license": "ISC",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "devDependencies": {
25
+ "@phosphor-icons/core": "^2.0.6",
26
+ "mongodb": "^6.1.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@phosphor-icons/core": "^2.0.6"
30
+ },
31
+ "scripts": {
32
+ "test": "echo skipping",
33
+ "lint": "eslint src",
34
+ "lint:fix": "eslint src --fix",
35
+ "build": "pnpm build:cjs && pnpm build:esm",
36
+ "build:cjs": "tsc",
37
+ "build:esm": "swc src/* -d dist --strip-leading-paths -C module.type=es6 --out-file-extension=mjs && pnpm build:esm-transform",
38
+ "build:esm-transform": "pnpm -w esm-transform $PWD/dist"
39
+ }
40
+ }