@aeriajs/types 0.0.97 → 0.0.99

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/config.d.ts CHANGED
@@ -29,6 +29,7 @@ export type ApiConfig = {
29
29
  logSuccessfulAuthentications?: boolean;
30
30
  authenticationRateLimiting?: RateLimitingParams | null;
31
31
  allowSignup?: boolean;
32
+ allowInsecureOperators?: boolean;
32
33
  signupDefaults?: {
33
34
  roles?: string[];
34
35
  active?: boolean;
@@ -0,0 +1,123 @@
1
+ import { ACError } from './accessControl.js';
2
+ import { HTTPStatus } from './http.js';
3
+ import { ValidationErrorCode, TraverseError } from './validation.js';
4
+ export declare const insertErrorSchema: () => {
5
+ readonly type: "object";
6
+ readonly properties: {
7
+ readonly _tag: {
8
+ readonly const: "Error";
9
+ };
10
+ readonly result: {
11
+ readonly const: undefined;
12
+ };
13
+ readonly error: {
14
+ readonly type: "object";
15
+ readonly required: readonly ["httpStatus", "code"];
16
+ readonly properties: {
17
+ readonly httpStatus: {
18
+ readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.UnprocessableContent, HTTPStatus.BadRequest];
19
+ };
20
+ readonly code: {
21
+ readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ACError.MalformedInput, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties, TraverseError.InvalidDocumentId, TraverseError.InvalidTempfile];
22
+ };
23
+ readonly message: {
24
+ readonly type: "string";
25
+ };
26
+ readonly details: {
27
+ readonly type: "object";
28
+ readonly variable: true;
29
+ };
30
+ };
31
+ };
32
+ };
33
+ };
34
+ export declare const getErrorSchema: () => {
35
+ readonly type: "object";
36
+ readonly properties: {
37
+ readonly _tag: {
38
+ readonly const: "Error";
39
+ };
40
+ readonly result: {
41
+ readonly const: undefined;
42
+ };
43
+ readonly error: {
44
+ readonly type: "object";
45
+ readonly required: readonly ["httpStatus", "code"];
46
+ readonly properties: {
47
+ readonly httpStatus: {
48
+ readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.BadRequest];
49
+ };
50
+ readonly code: {
51
+ readonly enum: [ACError.ResourceNotFound, ACError.OwnershipError, ACError.InsecureOperator, ACError.MalformedInput];
52
+ };
53
+ readonly message: {
54
+ readonly type: "string";
55
+ };
56
+ readonly details: {
57
+ readonly type: "object";
58
+ readonly variable: true;
59
+ };
60
+ };
61
+ };
62
+ };
63
+ };
64
+ export declare const getAllErrorSchema: () => {
65
+ readonly type: "object";
66
+ readonly properties: {
67
+ readonly _tag: {
68
+ readonly const: "Error";
69
+ };
70
+ readonly result: {
71
+ readonly const: undefined;
72
+ };
73
+ readonly error: {
74
+ readonly type: "object";
75
+ readonly required: readonly ["httpStatus", "code"];
76
+ readonly properties: {
77
+ readonly httpStatus: {
78
+ readonly enum: [HTTPStatus.Forbidden];
79
+ };
80
+ readonly code: {
81
+ readonly enum: [ACError.OwnershipError, ACError.InsecureOperator, ACError.InvalidLimit];
82
+ };
83
+ readonly message: {
84
+ readonly type: "string";
85
+ };
86
+ readonly details: {
87
+ readonly type: "object";
88
+ readonly variable: true;
89
+ };
90
+ };
91
+ };
92
+ };
93
+ };
94
+ export declare const countErrorSchema: () => {
95
+ readonly type: "object";
96
+ readonly properties: {
97
+ readonly _tag: {
98
+ readonly const: "Error";
99
+ };
100
+ readonly result: {
101
+ readonly const: undefined;
102
+ };
103
+ readonly error: {
104
+ readonly type: "object";
105
+ readonly required: readonly ["httpStatus", "code"];
106
+ readonly properties: {
107
+ readonly httpStatus: {
108
+ readonly enum: [HTTPStatus.Forbidden];
109
+ };
110
+ readonly code: {
111
+ readonly enum: [ACError.OwnershipError, ACError.InvalidLimit];
112
+ };
113
+ readonly message: {
114
+ readonly type: "string";
115
+ };
116
+ readonly details: {
117
+ readonly type: "object";
118
+ readonly variable: true;
119
+ };
120
+ };
121
+ };
122
+ };
123
+ };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countErrorSchema = exports.getAllErrorSchema = exports.getErrorSchema = exports.insertErrorSchema = void 0;
4
+ const accessControl_js_1 = require("./accessControl.js");
5
+ const http_js_1 = require("./http.js");
6
+ const resultSchemas_js_1 = require("./resultSchemas.js");
7
+ const validation_js_1 = require("./validation.js");
8
+ const insertErrorSchema = () => (0, resultSchemas_js_1.endpointErrorSchema)({
9
+ httpStatus: [
10
+ http_js_1.HTTPStatus.Forbidden,
11
+ http_js_1.HTTPStatus.NotFound,
12
+ http_js_1.HTTPStatus.UnprocessableContent,
13
+ http_js_1.HTTPStatus.BadRequest,
14
+ ],
15
+ code: [
16
+ accessControl_js_1.ACError.InsecureOperator,
17
+ accessControl_js_1.ACError.OwnershipError,
18
+ accessControl_js_1.ACError.ResourceNotFound,
19
+ accessControl_js_1.ACError.TargetImmutable,
20
+ accessControl_js_1.ACError.MalformedInput,
21
+ validation_js_1.ValidationErrorCode.EmptyTarget,
22
+ validation_js_1.ValidationErrorCode.InvalidProperties,
23
+ validation_js_1.ValidationErrorCode.MissingProperties,
24
+ validation_js_1.TraverseError.InvalidDocumentId,
25
+ validation_js_1.TraverseError.InvalidTempfile,
26
+ ],
27
+ });
28
+ exports.insertErrorSchema = insertErrorSchema;
29
+ const getErrorSchema = () => (0, resultSchemas_js_1.endpointErrorSchema)({
30
+ httpStatus: [
31
+ http_js_1.HTTPStatus.Forbidden,
32
+ http_js_1.HTTPStatus.NotFound,
33
+ http_js_1.HTTPStatus.BadRequest,
34
+ ],
35
+ code: [
36
+ accessControl_js_1.ACError.ResourceNotFound,
37
+ accessControl_js_1.ACError.OwnershipError,
38
+ accessControl_js_1.ACError.InsecureOperator,
39
+ accessControl_js_1.ACError.MalformedInput,
40
+ ],
41
+ });
42
+ exports.getErrorSchema = getErrorSchema;
43
+ const getAllErrorSchema = () => (0, resultSchemas_js_1.endpointErrorSchema)({
44
+ httpStatus: [http_js_1.HTTPStatus.Forbidden],
45
+ code: [
46
+ accessControl_js_1.ACError.OwnershipError,
47
+ accessControl_js_1.ACError.InsecureOperator,
48
+ accessControl_js_1.ACError.InvalidLimit,
49
+ ],
50
+ });
51
+ exports.getAllErrorSchema = getAllErrorSchema;
52
+ const countErrorSchema = () => (0, resultSchemas_js_1.endpointErrorSchema)({
53
+ httpStatus: [http_js_1.HTTPStatus.Forbidden],
54
+ code: [
55
+ accessControl_js_1.ACError.OwnershipError,
56
+ accessControl_js_1.ACError.InvalidLimit,
57
+ ],
58
+ });
59
+ exports.countErrorSchema = countErrorSchema;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ import { ACError } from "./accessControl.mjs";
3
+ import { HTTPStatus } from "./http.mjs";
4
+ import { endpointErrorSchema } from "./resultSchemas.mjs";
5
+ import { ValidationErrorCode, TraverseError } from "./validation.mjs";
6
+ export const insertErrorSchema = () => endpointErrorSchema({
7
+ httpStatus: [
8
+ HTTPStatus.Forbidden,
9
+ HTTPStatus.NotFound,
10
+ HTTPStatus.UnprocessableContent,
11
+ HTTPStatus.BadRequest
12
+ ],
13
+ code: [
14
+ ACError.InsecureOperator,
15
+ ACError.OwnershipError,
16
+ ACError.ResourceNotFound,
17
+ ACError.TargetImmutable,
18
+ ACError.MalformedInput,
19
+ ValidationErrorCode.EmptyTarget,
20
+ ValidationErrorCode.InvalidProperties,
21
+ ValidationErrorCode.MissingProperties,
22
+ TraverseError.InvalidDocumentId,
23
+ TraverseError.InvalidTempfile
24
+ ]
25
+ });
26
+ export const getErrorSchema = () => endpointErrorSchema({
27
+ httpStatus: [
28
+ HTTPStatus.Forbidden,
29
+ HTTPStatus.NotFound,
30
+ HTTPStatus.BadRequest
31
+ ],
32
+ code: [
33
+ ACError.ResourceNotFound,
34
+ ACError.OwnershipError,
35
+ ACError.InsecureOperator,
36
+ ACError.MalformedInput
37
+ ]
38
+ });
39
+ export const getAllErrorSchema = () => endpointErrorSchema({
40
+ httpStatus: [HTTPStatus.Forbidden],
41
+ code: [
42
+ ACError.OwnershipError,
43
+ ACError.InsecureOperator,
44
+ ACError.InvalidLimit
45
+ ]
46
+ });
47
+ export const countErrorSchema = () => endpointErrorSchema({
48
+ httpStatus: [HTTPStatus.Forbidden],
49
+ code: [
50
+ ACError.OwnershipError,
51
+ ACError.InvalidLimit
52
+ ]
53
+ });
@@ -1,11 +1,10 @@
1
1
  import type { FilterOperators, StrictFilter as Filter, WithId, ObjectId } from 'mongodb';
2
2
  import type { Result, ExtractError } from './result.js';
3
3
  import type { EndpointError } from './endpointError.js';
4
- import type { SchemaWithId, PackReferences } from './schema.js';
4
+ import type { SchemaWithId, InferSchema, PackReferences } from './schema.js';
5
5
  import type { JsonSchema } from './property.js';
6
- import type { ACError } from './accessControl.js';
7
- import type { ValidationErrorCode, TraverseError } from './validation.js';
8
- import type { HTTPStatus, WithACErrors } from './http.js';
6
+ import type { WithACErrors } from './http.js';
7
+ import type { countErrorSchema, getAllErrorSchema, getErrorSchema, insertErrorSchema } from './functionSchemas.js';
9
8
  export type UploadAuxProps = {
10
9
  parentId: string;
11
10
  propName: string;
@@ -70,10 +69,10 @@ export type RemoveFilePayload = UploadAuxProps & {
70
69
  _id: ObjectId | string;
71
70
  };
72
71
  };
73
- export type InsertReturnType<TDocument> = Result.Either<EndpointError<ACError.InsecureOperator | ACError.OwnershipError | ACError.ResourceNotFound | ACError.TargetImmutable | ACError.MalformedInput | ValidationErrorCode | TraverseError.InvalidDocumentId | TraverseError.InvalidTempfile, unknown, HTTPStatus.Forbidden | HTTPStatus.NotFound | HTTPStatus.UnprocessableContent | HTTPStatus.BadRequest>, TDocument>;
74
- export type GetReturnType<TDocument> = Result.Either<EndpointError<ACError.ResourceNotFound | ACError.OwnershipError | ACError.InsecureOperator | ACError.MalformedInput, unknown, HTTPStatus.Forbidden | HTTPStatus.NotFound | HTTPStatus.BadRequest>, TDocument>;
75
- export type GetAllReturnType<TDocument> = Result.Either<EndpointError<ACError.InvalidLimit | ACError.InsecureOperator | ACError.OwnershipError, unknown, HTTPStatus.Forbidden>, TDocument[]>;
76
- export type CountReturnType = Result.Either<EndpointError, number>;
72
+ export type InsertReturnType<TDocument> = Result.Either<ExtractError<InferSchema<ReturnType<typeof insertErrorSchema>>>, TDocument>;
73
+ export type GetReturnType<TDocument> = Result.Either<ExtractError<InferSchema<ReturnType<typeof getErrorSchema>>>, TDocument>;
74
+ export type GetAllReturnType<TDocument> = Result.Either<ExtractError<InferSchema<ReturnType<typeof getAllErrorSchema>>>, TDocument[]>;
75
+ export type CountReturnType = Result.Either<ExtractError<InferSchema<ReturnType<typeof countErrorSchema>>>, number>;
77
76
  export type RemoveReturnType<TDocument> = Result.Either<EndpointError, TDocument>;
78
77
  export type PaginatedGetAllReturnType<TDocument> = Result.Either<ExtractError<GetAllReturnType<TDocument>>, {
79
78
  data: TDocument[];
package/dist/index.d.ts CHANGED
@@ -7,9 +7,11 @@ export * from './contract.js';
7
7
  export * from './description.js';
8
8
  export * from './endpointError.js';
9
9
  export * from './functions.js';
10
+ export * from './functionSchemas.js';
10
11
  export * from './http.js';
11
12
  export * from './property.js';
12
13
  export * from './result.js';
14
+ export * from './resultSchemas.js';
13
15
  export * from './schema.js';
14
16
  export * from './security.js';
15
17
  export * from './token.js';
package/dist/index.js CHANGED
@@ -23,9 +23,11 @@ __exportStar(require("./contract.js"), exports);
23
23
  __exportStar(require("./description.js"), exports);
24
24
  __exportStar(require("./endpointError.js"), exports);
25
25
  __exportStar(require("./functions.js"), exports);
26
+ __exportStar(require("./functionSchemas.js"), exports);
26
27
  __exportStar(require("./http.js"), exports);
27
28
  __exportStar(require("./property.js"), exports);
28
29
  __exportStar(require("./result.js"), exports);
30
+ __exportStar(require("./resultSchemas.js"), exports);
29
31
  __exportStar(require("./schema.js"), exports);
30
32
  __exportStar(require("./security.js"), exports);
31
33
  __exportStar(require("./token.js"), exports);
package/dist/index.mjs CHANGED
@@ -8,9 +8,11 @@ export * from "./contract.mjs";
8
8
  export * from "./description.mjs";
9
9
  export * from "./endpointError.mjs";
10
10
  export * from "./functions.mjs";
11
+ export * from "./functionSchemas.mjs";
11
12
  export * from "./http.mjs";
12
13
  export * from "./property.mjs";
13
14
  export * from "./result.mjs";
15
+ export * from "./resultSchemas.mjs";
14
16
  export * from "./schema.mjs";
15
17
  export * from "./security.mjs";
16
18
  export * from "./token.mjs";
@@ -0,0 +1,89 @@
1
+ import type { Property } from './property.js';
2
+ import type { HTTPStatus } from './http.js';
3
+ export declare const errorSchema: <const TObject extends Property>(object: TObject) => {
4
+ readonly type: "object";
5
+ readonly properties: {
6
+ readonly _tag: {
7
+ readonly const: "Error";
8
+ };
9
+ readonly error: Property;
10
+ readonly result: {
11
+ readonly const: undefined;
12
+ };
13
+ };
14
+ };
15
+ export declare const resultSchema: <const TObject extends Property>(object: TObject) => {
16
+ readonly type: "object";
17
+ readonly properties: {
18
+ readonly _tag: {
19
+ readonly const: "Result";
20
+ };
21
+ readonly error: {
22
+ readonly const: undefined;
23
+ };
24
+ readonly result: Property;
25
+ };
26
+ };
27
+ export declare const endpointErrorSchema: <const THTTPStatus extends HTTPStatus[], const TCode extends string[]>(error: {
28
+ httpStatus: THTTPStatus;
29
+ code: TCode;
30
+ }) => {
31
+ readonly type: "object";
32
+ readonly properties: {
33
+ readonly _tag: {
34
+ readonly const: "Error";
35
+ };
36
+ readonly result: {
37
+ readonly const: undefined;
38
+ };
39
+ readonly error: {
40
+ readonly type: "object";
41
+ readonly required: readonly ["httpStatus", "code"];
42
+ readonly properties: {
43
+ readonly httpStatus: {
44
+ readonly enum: THTTPStatus;
45
+ };
46
+ readonly code: {
47
+ readonly enum: TCode;
48
+ };
49
+ readonly message: {
50
+ readonly type: "string";
51
+ };
52
+ readonly details: {
53
+ readonly type: "object";
54
+ readonly variable: true;
55
+ };
56
+ };
57
+ };
58
+ };
59
+ };
60
+ export declare const genericEndpointErrorSchema: () => {
61
+ readonly type: "object";
62
+ readonly properties: {
63
+ readonly _tag: {
64
+ readonly const: "Error";
65
+ };
66
+ readonly result: {
67
+ readonly const: undefined;
68
+ };
69
+ readonly error: {
70
+ readonly type: "object";
71
+ readonly required: readonly ["httpStatus", "code"];
72
+ readonly properties: {
73
+ readonly httpStatus: {
74
+ readonly type: "number";
75
+ };
76
+ readonly code: {
77
+ readonly type: "string";
78
+ };
79
+ readonly message: {
80
+ readonly type: "string";
81
+ };
82
+ readonly details: {
83
+ readonly type: "object";
84
+ readonly variable: true;
85
+ };
86
+ };
87
+ };
88
+ };
89
+ };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genericEndpointErrorSchema = exports.endpointErrorSchema = exports.resultSchema = exports.errorSchema = void 0;
4
+ const errorSchema = (object) => {
5
+ return {
6
+ type: 'object',
7
+ properties: {
8
+ _tag: {
9
+ const: 'Error',
10
+ },
11
+ error: object,
12
+ result: {
13
+ const: undefined,
14
+ },
15
+ },
16
+ };
17
+ };
18
+ exports.errorSchema = errorSchema;
19
+ const resultSchema = (object) => {
20
+ return {
21
+ type: 'object',
22
+ properties: {
23
+ _tag: {
24
+ const: 'Result',
25
+ },
26
+ error: {
27
+ const: undefined,
28
+ },
29
+ result: object,
30
+ },
31
+ };
32
+ };
33
+ exports.resultSchema = resultSchema;
34
+ const endpointErrorSchema = (error) => {
35
+ return {
36
+ type: 'object',
37
+ properties: {
38
+ _tag: {
39
+ const: 'Error',
40
+ },
41
+ result: {
42
+ const: undefined,
43
+ },
44
+ error: {
45
+ type: 'object',
46
+ required: [
47
+ 'httpStatus',
48
+ 'code',
49
+ ],
50
+ properties: {
51
+ httpStatus: {
52
+ enum: error.httpStatus,
53
+ },
54
+ code: {
55
+ enum: error.code,
56
+ },
57
+ message: {
58
+ type: 'string',
59
+ },
60
+ details: {
61
+ type: 'object',
62
+ variable: true,
63
+ },
64
+ },
65
+ },
66
+ },
67
+ };
68
+ };
69
+ exports.endpointErrorSchema = endpointErrorSchema;
70
+ const genericEndpointErrorSchema = () => {
71
+ return {
72
+ type: 'object',
73
+ properties: {
74
+ _tag: {
75
+ const: 'Error',
76
+ },
77
+ result: {
78
+ const: undefined,
79
+ },
80
+ error: {
81
+ type: 'object',
82
+ required: [
83
+ 'httpStatus',
84
+ 'code',
85
+ ],
86
+ properties: {
87
+ httpStatus: {
88
+ type: 'number',
89
+ },
90
+ code: {
91
+ type: 'string',
92
+ },
93
+ message: {
94
+ type: 'string',
95
+ },
96
+ details: {
97
+ type: 'object',
98
+ variable: true,
99
+ },
100
+ },
101
+ },
102
+ },
103
+ };
104
+ };
105
+ exports.genericEndpointErrorSchema = genericEndpointErrorSchema;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ export const errorSchema = (object) => {
3
+ return {
4
+ type: "object",
5
+ properties: {
6
+ _tag: {
7
+ const: "Error"
8
+ },
9
+ error: object,
10
+ result: {
11
+ const: void 0
12
+ }
13
+ }
14
+ };
15
+ };
16
+ export const resultSchema = (object) => {
17
+ return {
18
+ type: "object",
19
+ properties: {
20
+ _tag: {
21
+ const: "Result"
22
+ },
23
+ error: {
24
+ const: void 0
25
+ },
26
+ result: object
27
+ }
28
+ };
29
+ };
30
+ export const endpointErrorSchema = (error) => {
31
+ return {
32
+ type: "object",
33
+ properties: {
34
+ _tag: {
35
+ const: "Error"
36
+ },
37
+ result: {
38
+ const: void 0
39
+ },
40
+ error: {
41
+ type: "object",
42
+ required: [
43
+ "httpStatus",
44
+ "code"
45
+ ],
46
+ properties: {
47
+ httpStatus: {
48
+ enum: error.httpStatus
49
+ },
50
+ code: {
51
+ enum: error.code
52
+ },
53
+ message: {
54
+ type: "string"
55
+ },
56
+ details: {
57
+ type: "object",
58
+ variable: true
59
+ }
60
+ }
61
+ }
62
+ }
63
+ };
64
+ };
65
+ export const genericEndpointErrorSchema = () => {
66
+ return {
67
+ type: "object",
68
+ properties: {
69
+ _tag: {
70
+ const: "Error"
71
+ },
72
+ result: {
73
+ const: void 0
74
+ },
75
+ error: {
76
+ type: "object",
77
+ required: [
78
+ "httpStatus",
79
+ "code"
80
+ ],
81
+ properties: {
82
+ httpStatus: {
83
+ type: "number"
84
+ },
85
+ code: {
86
+ type: "string"
87
+ },
88
+ message: {
89
+ type: "string"
90
+ },
91
+ details: {
92
+ type: "object",
93
+ variable: true
94
+ }
95
+ }
96
+ }
97
+ }
98
+ };
99
+ };
package/dist/token.d.ts CHANGED
@@ -6,9 +6,9 @@ export type UserRole = (Collections['user']['item'] extends {
6
6
  export type AcceptedRole = UserRole | UserRole[] | null | unknown;
7
7
  export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null, TUserRole = UserRole, TUserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>> = {
8
8
  authenticated: true;
9
- sub: ObjectId;
9
+ sub: ObjectId | null;
10
10
  roles: readonly (TAcceptedRole extends null ? TUserRole : TAcceptedRole)[];
11
- userinfo: TUserInfo | PackReferences<TUserInfo>;
11
+ userinfo: Partial<TUserInfo | PackReferences<TUserInfo>>;
12
12
  };
13
13
  export type UnauthenticatedToken = {
14
14
  authenticated: false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.97",
3
+ "version": "0.0.99",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",