@aeriajs/types 0.0.48 → 0.0.49
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/accessControl.d.ts +3 -2
- package/dist/collection.d.ts +17 -0
- package/dist/config.d.ts +3 -1
- package/dist/context.d.ts +10 -5
- package/dist/contract.d.ts +5 -1
- package/dist/description.d.ts +1 -1
- package/dist/functions.d.ts +4 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/dist/monad.d.ts +21 -0
- package/dist/property.d.ts +1 -1
- package/dist/security.d.ts +3 -2
- package/dist/token.d.ts +20 -0
- package/package.json +1 -1
- package/dist/api.d.ts +0 -30
- package/dist/either.d.ts +0 -9
- package/dist/error.d.ts +0 -6
- /package/dist/{api.js → collection.js} +0 -0
- /package/dist/{api.mjs → collection.mjs} +0 -0
- /package/dist/{either.js → monad.js} +0 -0
- /package/dist/{either.mjs → monad.mjs} +0 -0
- /package/dist/{error.js → token.js} +0 -0
- /package/dist/{error.mjs → token.mjs} +0 -0
package/dist/accessControl.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export type UserRole = Collections['user']['item']['roles'][number] | 'root' | '
|
|
2
|
-
export type AccessCondition = readonly UserRole[] | boolean | 'unauthenticated' | 'unauthenticated-only';
|
|
1
|
+
export type UserRole = (Collections['user']['item']['roles'][number] extends infer UserDefinedRole ? UserDefinedRole extends string ? `${UserDefinedRole}${UserDefinedRole}` extends UserDefinedRole ? 'root' : UserDefinedRole : never : never) | 'root' | 'unauthenticated';
|
|
3
2
|
export type AcceptedRole = UserRole | UserRole[] | null | unknown;
|
|
3
|
+
export type AccessCondition = readonly UserRole[] | boolean | 'unauthenticated' | 'unauthenticated-only';
|
|
4
|
+
export type RoleFromAccessCondition<TAccessCondition extends AccessCondition | undefined> = undefined extends TAccessCondition ? null : number extends keyof TAccessCondition ? TAccessCondition[number] : TAccessCondition extends true ? Exclude<UserRole, 'unauthenticated'> : TAccessCondition extends false ? never : TAccessCondition extends 'unauthenticated-only' ? 'unauthenticated' : TAccessCondition extends 'unauthenticated' ? UserRole : never;
|
|
4
5
|
export declare enum ACErrors {
|
|
5
6
|
AssetNotFound = "ASSET_NOT_FOUND",
|
|
6
7
|
AuthenticationError = "AUTHENTICATION_ERROR",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AccessCondition } from './accessControl.js';
|
|
2
|
+
import type { CollectionSecurityPolicy } from './security.js';
|
|
3
|
+
import type { Context } from './context.js';
|
|
4
|
+
import type { Contract } from './contract.js';
|
|
5
|
+
import type { Description } from './description.js';
|
|
6
|
+
export type Collection<TCollection extends Collection = any> = {
|
|
7
|
+
description: Description;
|
|
8
|
+
item?: any;
|
|
9
|
+
security?: CollectionSecurityPolicy<TCollection>;
|
|
10
|
+
functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
|
|
11
|
+
contracts?: Record<string, Contract>;
|
|
12
|
+
exposedFunctions?: Record<string, AccessCondition>;
|
|
13
|
+
};
|
|
14
|
+
export type CollectionItem<TCollectionName extends keyof Collections> = Omit<Collections[TCollectionName]['item'], '_id'>;
|
|
15
|
+
export type CollectionItemWithId<TCollectionName extends keyof Collections> = Collections[TCollectionName]['item'];
|
|
16
|
+
export type AssetType = keyof Collection;
|
|
17
|
+
export type FunctionPath = `/${string}/${string}`;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { RouteContext
|
|
1
|
+
import type { RouteContext } from './context.js';
|
|
2
|
+
import type { RouteUri } from './http.js';
|
|
3
|
+
import type { RateLimitingParams } from './security.js';
|
|
2
4
|
export type ApiConfig = {
|
|
3
5
|
secret?: string;
|
|
4
6
|
baseUrl?: RouteUri;
|
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { Collection as MongoCollection } from 'mongodb';
|
|
2
|
+
import type { AcceptedRole } from './accessControl.js';
|
|
3
|
+
import type { ApiConfig } from './config.js';
|
|
4
|
+
import type { CollectionDocument, CollectionFunctions } from './functions.js';
|
|
5
|
+
import type { Description } from './description.js';
|
|
6
|
+
import type { Either, EndpointError, EndpointErrorContent } from './monad.js';
|
|
7
|
+
import type { FunctionPath } from './collection.js';
|
|
2
8
|
import type { GenericRequest, GenericResponse } from './http.js';
|
|
3
|
-
import type {
|
|
9
|
+
import type { PackReferences, SchemaWithId } from './schema.js';
|
|
10
|
+
import type { RateLimitingParams, RateLimitingErrors } from './security.js';
|
|
11
|
+
import type { Token } from './token.js';
|
|
4
12
|
export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
|
|
5
13
|
type OmitContextParameter<TFunction> = TFunction extends () => any ? TFunction : TFunction extends (payload: undefined, ...args: any[]) => infer Return ? () => Return : TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
6
14
|
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
|
|
@@ -33,10 +41,7 @@ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
|
|
|
33
41
|
request: GenericRequest;
|
|
34
42
|
response: GenericResponse;
|
|
35
43
|
log: (message: string, details?: any) => Promise<any>;
|
|
36
|
-
error: (error:
|
|
37
|
-
$isError: true;
|
|
38
|
-
error: EndpointError;
|
|
39
|
-
};
|
|
44
|
+
error: <TEndpointErrorContent extends EndpointErrorContent>(error: TEndpointErrorContent) => EndpointError<TEndpointErrorContent>;
|
|
40
45
|
limitRate: (params: RateLimitingParams) => Promise<Either<RateLimitingErrors, {
|
|
41
46
|
hits: number;
|
|
42
47
|
points: number;
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Context } from './context.js';
|
|
2
|
+
import type { InferProperty } from './schema.js';
|
|
3
|
+
import type { InferResponse } from './http.js';
|
|
4
|
+
import type { Property } from './property.js';
|
|
5
|
+
import type { UserRole } from './accessControl.js';
|
|
2
6
|
export type ContractBase = {
|
|
3
7
|
builtin?: boolean;
|
|
4
8
|
};
|
package/dist/description.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IconStyle, PhosphorIcon } from '@phosphor-icons/core';
|
|
2
|
-
import type { JsonSchema, PropertiesWithId } from './property.js';
|
|
3
2
|
import type { Condition } from './condition.js';
|
|
3
|
+
import type { JsonSchema, PropertiesWithId } from './property.js';
|
|
4
4
|
import type { OwnershipMode } from './security.js';
|
|
5
5
|
export type CollectionPresets = 'crud' | 'duplicate' | 'remove' | 'removeAll' | 'owned' | 'timestamped' | 'view';
|
|
6
6
|
export type Icon = PhosphorIcon['name'] | `${IconStyle}:${PhosphorIcon['name']}`;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { FilterOperators, StrictFilter as Filter, StrictUpdateFilter, WithId, OptionalId, ObjectId } from 'mongodb';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ACErrors } from './accessControl.js';
|
|
3
|
+
import type { Either } from './monad.js';
|
|
4
|
+
import type { PackReferences } from './schema.js';
|
|
5
|
+
import type { ValidationError } from './validation.js';
|
|
3
6
|
export type UploadAuxProps = {
|
|
4
7
|
parentId: string;
|
|
5
8
|
propertyName: string;
|
package/dist/http.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ServerResponse, IncomingMessage } from 'http';
|
|
3
|
-
import type { MapSchemaUnion } from '.';
|
|
3
|
+
import type { MapSchemaUnion } from './schema.js';
|
|
4
4
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
5
5
|
export type RouteUri = `/${string}`;
|
|
6
6
|
export type RequestMethod = (typeof REQUEST_METHODS)[number];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export * from './accessControl.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './collection.js';
|
|
3
3
|
export * from './condition.js';
|
|
4
4
|
export * from './config.js';
|
|
5
5
|
export * from './context.js';
|
|
6
6
|
export * from './contract.js';
|
|
7
7
|
export * from './description.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './error.js';
|
|
8
|
+
export * from './monad.js';
|
|
10
9
|
export * from './functions.js';
|
|
11
10
|
export * from './http.js';
|
|
12
11
|
export * from './property.js';
|
|
13
12
|
export * from './schema.js';
|
|
14
13
|
export * from './security.js';
|
|
14
|
+
export * from './token.js';
|
|
15
15
|
export * from './validation.js';
|
|
16
16
|
export type { WithId, OptionalId, } from 'mongodb';
|
package/dist/index.js
CHANGED
|
@@ -15,17 +15,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./accessControl.js"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./collection.js"), exports);
|
|
19
19
|
__exportStar(require("./condition.js"), exports);
|
|
20
20
|
__exportStar(require("./config.js"), exports);
|
|
21
21
|
__exportStar(require("./context.js"), exports);
|
|
22
22
|
__exportStar(require("./contract.js"), exports);
|
|
23
23
|
__exportStar(require("./description.js"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./error.js"), exports);
|
|
24
|
+
__exportStar(require("./monad.js"), exports);
|
|
26
25
|
__exportStar(require("./functions.js"), exports);
|
|
27
26
|
__exportStar(require("./http.js"), exports);
|
|
28
27
|
__exportStar(require("./property.js"), exports);
|
|
29
28
|
__exportStar(require("./schema.js"), exports);
|
|
30
29
|
__exportStar(require("./security.js"), exports);
|
|
30
|
+
__exportStar(require("./token.js"), exports);
|
|
31
31
|
__exportStar(require("./validation.js"), exports);
|
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export * from "./accessControl.mjs";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./collection.mjs";
|
|
4
4
|
export * from "./condition.mjs";
|
|
5
5
|
export * from "./config.mjs";
|
|
6
6
|
export * from "./context.mjs";
|
|
7
7
|
export * from "./contract.mjs";
|
|
8
8
|
export * from "./description.mjs";
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./error.mjs";
|
|
9
|
+
export * from "./monad.mjs";
|
|
11
10
|
export * from "./functions.mjs";
|
|
12
11
|
export * from "./http.mjs";
|
|
13
12
|
export * from "./property.mjs";
|
|
14
13
|
export * from "./schema.mjs";
|
|
15
14
|
export * from "./security.mjs";
|
|
15
|
+
export * from "./token.mjs";
|
|
16
16
|
export * from "./validation.mjs";
|
package/dist/monad.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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 EndpointErrorContent = {
|
|
10
|
+
httpCode?: number;
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
details?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
export type EndpointError<T extends EndpointErrorContent> = {
|
|
16
|
+
readonly _tag: 'Error';
|
|
17
|
+
readonly error: T;
|
|
18
|
+
};
|
|
19
|
+
export type ExtractLeft<T> = T extends Left<infer L> ? L : never;
|
|
20
|
+
export type ExtractRight<T> = T extends Right<infer R> ? R : never;
|
|
21
|
+
export type Either<L, R> = Left<L> | Right<R>;
|
package/dist/property.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PhosphorIcon } from '@phosphor-icons/core';
|
|
2
|
-
import type { Condition } from '.';
|
|
2
|
+
import type { Condition } from './condition.js';
|
|
3
3
|
export type PropertyArrayElement = 'checkbox' | 'radio' | 'select';
|
|
4
4
|
export type PropertyInputType = 'text' | 'email' | 'password' | 'search' | 'time' | 'month';
|
|
5
5
|
export type PropertyFormat = 'date' | 'date-time';
|
package/dist/security.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Collection } from './api.js';
|
|
2
1
|
export type OwnershipMode = boolean | 'always' | 'on-write';
|
|
3
2
|
export declare enum RateLimitingErrors {
|
|
4
3
|
Unauthenticated = "UNAUTHENTICATED",
|
|
@@ -25,6 +24,8 @@ export type SecurityPolicy = {
|
|
|
25
24
|
rateLimiting?: RateLimitingParams;
|
|
26
25
|
logging?: LoggingParams;
|
|
27
26
|
};
|
|
28
|
-
export type CollectionSecurityPolicy<TCollection extends
|
|
27
|
+
export type CollectionSecurityPolicy<TCollection extends {
|
|
28
|
+
functions?: Record<string, (...args: any[]) => unknown>;
|
|
29
|
+
}> = {
|
|
29
30
|
functions?: Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
|
|
30
31
|
};
|
package/dist/token.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ObjectId } from 'mongodb';
|
|
2
|
+
import type { PackReferences } from './schema.js';
|
|
3
|
+
import type { FunctionPath } from './collection.js';
|
|
4
|
+
import type { AcceptedRole } from './accessControl.js';
|
|
5
|
+
export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null> = {
|
|
6
|
+
authenticated: true;
|
|
7
|
+
sub: ObjectId;
|
|
8
|
+
roles: readonly (TAcceptedRole extends null ? string : TAcceptedRole)[];
|
|
9
|
+
allowed_functions?: readonly FunctionPath[];
|
|
10
|
+
userinfo: Omit<Collections['user']['item'], '_id' | 'roles'> extends infer UserItem ? UserItem | PackReferences<UserItem> : never;
|
|
11
|
+
};
|
|
12
|
+
export type UnauthenticatedToken = {
|
|
13
|
+
authenticated: false;
|
|
14
|
+
sub: null;
|
|
15
|
+
};
|
|
16
|
+
export type TokenRecipient = {
|
|
17
|
+
type: 'bearer';
|
|
18
|
+
content: string;
|
|
19
|
+
};
|
|
20
|
+
export type Token<TAcceptedRole extends AcceptedRole = null> = [TAcceptedRole] extends [null | 'unauthenticated'] ? AuthenticatedToken | UnauthenticatedToken : AuthenticatedToken<TAcceptedRole>;
|
package/package.json
CHANGED
package/dist/api.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { ObjectId } from 'mongodb';
|
|
2
|
-
import type { Context, Contract, Description, CollectionSecurityPolicy, PackReferences, AcceptedRole, AccessCondition } from '.';
|
|
3
|
-
export type Collection<TCollection extends Collection = any> = {
|
|
4
|
-
description: Description;
|
|
5
|
-
item?: any;
|
|
6
|
-
security?: CollectionSecurityPolicy<TCollection>;
|
|
7
|
-
functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
|
|
8
|
-
functionContracts?: Record<string, Contract>;
|
|
9
|
-
exposedFunctions?: Record<string, AccessCondition>;
|
|
10
|
-
};
|
|
11
|
-
export type CollectionItem<TCollectionName extends keyof Collections> = Omit<Collections[TCollectionName]['item'], '_id'>;
|
|
12
|
-
export type CollectionItemWithId<TCollectionName extends keyof Collections> = Collections[TCollectionName]['item'];
|
|
13
|
-
export type AssetType = keyof Collection;
|
|
14
|
-
export type FunctionPath = `/${string}/${string}`;
|
|
15
|
-
export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null> = {
|
|
16
|
-
authenticated: true;
|
|
17
|
-
sub: ObjectId;
|
|
18
|
-
roles: readonly (TAcceptedRole extends null ? string : TAcceptedRole)[];
|
|
19
|
-
allowed_functions?: readonly FunctionPath[];
|
|
20
|
-
userinfo: Collections['user']['item'] | PackReferences<Collections['user']['item']>;
|
|
21
|
-
};
|
|
22
|
-
export type UnauthenticatedToken = {
|
|
23
|
-
authenticated: false;
|
|
24
|
-
sub: null;
|
|
25
|
-
};
|
|
26
|
-
export type TokenRecipient = {
|
|
27
|
-
type: 'bearer';
|
|
28
|
-
content: string;
|
|
29
|
-
};
|
|
30
|
-
export type Token<TAcceptedRole extends AcceptedRole = null> = (TAcceptedRole extends any[] ? TAcceptedRole[number] : TAcceptedRole) extends infer NormalizedRole ? NormalizedRole extends null | 'guest' ? AuthenticatedToken | UnauthenticatedToken : AuthenticatedToken<NormalizedRole> : never;
|
package/dist/either.d.ts
DELETED
package/dist/error.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|