@aeriajs/types 0.0.18 → 0.0.20

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.
@@ -1,16 +1,17 @@
1
1
  import type { Collection } from '.';
2
2
  export declare enum ACErrors {
3
- AuthorizationError = "AUTHORIZATION_ERROR",
3
+ AssetNotFound = "ASSET_NOT_FOUND",
4
4
  AuthenticationError = "AUTHENTICATION_ERROR",
5
+ AuthorizationError = "AUTHORIZATION_ERROR",
6
+ FunctionNotFound = "FUNCTION_NOT_FOUND",
5
7
  ImmutabilityIncorrectChild = "IMMUTABILITY_INCORRECT_CHILD",
6
8
  ImmutabilityParentNotFound = "IMMUTABILITY_PARENT_NOT_FOUND",
7
9
  ImmutabilityTargetImmutable = "IMMUTABILITY_TARGET_IMMUTABLE",
10
+ InvalidLimit = "INVALID_LIMIT",
8
11
  OwnershipError = "OWNERSHIP_ERROR",
9
- ResourceNotFound = "RESOURCE_NOT_FOUND",
10
- AssetNotFound = "ASSET_NOT_FOUND",
11
- FunctionNotFound = "FUNCTION_NOT_FOUND",
12
- InvalidLimit = "INVALID_LIMIT"
12
+ ResourceNotFound = "RESOURCE_NOT_FOUND"
13
13
  }
14
+ export declare const ACErrorMessages: Record<ACErrors, string>;
14
15
  export type Role<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection> = any> = {
15
16
  inherit?: readonly (keyof TAccessControl['roles'])[];
16
17
  grantEverything?: boolean;
@@ -1,16 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACErrors = void 0;
3
+ exports.ACErrorMessages = exports.ACErrors = void 0;
4
4
  var ACErrors;
5
5
  (function (ACErrors) {
6
- ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
6
+ ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
7
7
  ACErrors["AuthenticationError"] = "AUTHENTICATION_ERROR";
8
+ ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
9
+ ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
8
10
  ACErrors["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
9
11
  ACErrors["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
10
12
  ACErrors["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
13
+ ACErrors["InvalidLimit"] = "INVALID_LIMIT";
11
14
  ACErrors["OwnershipError"] = "OWNERSHIP_ERROR";
12
15
  ACErrors["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
13
- ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
14
- ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
15
- ACErrors["InvalidLimit"] = "INVALID_LIMIT";
16
16
  })(ACErrors || (exports.ACErrors = ACErrors = {}));
17
+ exports.ACErrorMessages = {
18
+ [ACErrors.AssetNotFound]: 'collection has no registered functions',
19
+ [ACErrors.AuthenticationError]: 'you have insufficient privileges',
20
+ [ACErrors.AuthorizationError]: 'you have insufficient privileges',
21
+ [ACErrors.FunctionNotFound]: 'function not found',
22
+ [ACErrors.ImmutabilityIncorrectChild]: 'specified limit is invalid',
23
+ [ACErrors.ImmutabilityParentNotFound]: 'specified limit is invalid',
24
+ [ACErrors.ImmutabilityTargetImmutable]: 'specified limit is invalid',
25
+ [ACErrors.InvalidLimit]: 'specified limit is invalid',
26
+ [ACErrors.OwnershipError]: 'you have insufficient privileges',
27
+ [ACErrors.ResourceNotFound]: 'collection not found',
28
+ };
@@ -1,13 +1,28 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  export var ACErrors;
2
15
  (function(ACErrors) {
3
- ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
16
+ ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
4
17
  ACErrors["AuthenticationError"] = "AUTHENTICATION_ERROR";
18
+ ACErrors["AuthorizationError"] = "AUTHORIZATION_ERROR";
19
+ ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
5
20
  ACErrors["ImmutabilityIncorrectChild"] = "IMMUTABILITY_INCORRECT_CHILD";
6
21
  ACErrors["ImmutabilityParentNotFound"] = "IMMUTABILITY_PARENT_NOT_FOUND";
7
22
  ACErrors["ImmutabilityTargetImmutable"] = "IMMUTABILITY_TARGET_IMMUTABLE";
23
+ ACErrors["InvalidLimit"] = "INVALID_LIMIT";
8
24
  ACErrors["OwnershipError"] = "OWNERSHIP_ERROR";
9
25
  ACErrors["ResourceNotFound"] = "RESOURCE_NOT_FOUND";
10
- ACErrors["AssetNotFound"] = "ASSET_NOT_FOUND";
11
- ACErrors["FunctionNotFound"] = "FUNCTION_NOT_FOUND";
12
- ACErrors["InvalidLimit"] = "INVALID_LIMIT";
13
26
  })(ACErrors || (ACErrors = {}));
27
+ var _obj;
28
+ export var ACErrorMessages = (_obj = {}, _define_property(_obj, "ASSET_NOT_FOUND", "collection has no registered functions"), _define_property(_obj, "AUTHENTICATION_ERROR", "you have insufficient privileges"), _define_property(_obj, "AUTHORIZATION_ERROR", "you have insufficient privileges"), _define_property(_obj, "FUNCTION_NOT_FOUND", "function not found"), _define_property(_obj, "IMMUTABILITY_INCORRECT_CHILD", "specified limit is invalid"), _define_property(_obj, "IMMUTABILITY_PARENT_NOT_FOUND", "specified limit is invalid"), _define_property(_obj, "IMMUTABILITY_TARGET_IMMUTABLE", "specified limit is invalid"), _define_property(_obj, "INVALID_LIMIT", "specified limit is invalid"), _define_property(_obj, "OWNERSHIP_ERROR", "you have insufficient privileges"), _define_property(_obj, "RESOURCE_NOT_FOUND", "collection not found"), _obj);
@@ -23,11 +23,14 @@ export type Filters<TDocument> = StrictFilter<any> & Partial<{
23
23
  _id: infer Id;
24
24
  } ? Id | string : Field : never) extends infer Field ? Field | StrictFilterOperators<Field> | null : never;
25
25
  }>;
26
- export type What<TDocument> = DocumentFilter<TDocument> extends infer Document ? Partial<{
26
+ type DocumentUpdateFilter<Document> = {
27
27
  [P in keyof Document]: Document[P] extends null ? null : Document[P] | StrictUpdateFilter<Document[P]>;
28
- }> & {
29
- _id?: ObjectId | string;
30
- } : never;
28
+ };
29
+ export type What<TDocument> = {
30
+ _id: ObjectId | string;
31
+ } & Partial<DocumentUpdateFilter<DocumentFilter<TDocument>>> | {
32
+ _id?: null;
33
+ } & Omit<PackReferences<TDocument>, '_id'>;
31
34
  export type Projection<TDocument> = keyof TDocument | '_id' extends infer DocumentProp ? TDocument extends string ? DocumentProp[] : string[] : never;
32
35
  export type QuerySort<TDocument> = Partial<Record<keyof WithId<TDocument>, 1 | -1>>;
33
36
  export type CollectionDocument<TDocument> = TDocument;
@@ -47,8 +50,8 @@ export type GetAllPayload<TDocument extends CollectionDocument<OptionalId<any>>>
47
50
  sort?: QuerySort<TDocument>;
48
51
  populate?: (keyof TDocument | string)[];
49
52
  };
50
- export type InsertPayload<TDocument extends CollectionDocument<any>, BypassTypeRestriction = false> = {
51
- what: BypassTypeRestriction extends true ? any : What<TDocument>;
53
+ export type InsertPayload<TDocument extends CollectionDocument<any>> = {
54
+ what: What<TDocument>;
52
55
  project?: Projection<TDocument>;
53
56
  };
54
57
  export type RemovePayload<TDocument extends CollectionDocument<OptionalId<any>>> = {
@@ -90,8 +90,11 @@ export type ArrayOfRefs = Omit<ArrayProperty, 'items'> & {
90
90
  export type GetterProperty = {
91
91
  getter: (document: any) => any;
92
92
  };
93
- export type MixedProperty = RefProperty | FileProperty | EnumProperty | ArrayProperty | ObjectProperty | StringProperty | NumberProperty | BooleanProperty | GetterProperty;
94
- export type NonCircularMixedProperty = NonCircularRefProperty | FileProperty | EnumProperty | ArrayProperty | ObjectProperty | StringProperty | NumberProperty | BooleanProperty | GetterProperty;
93
+ export type ConstProperty = {
94
+ const: string | number | boolean;
95
+ };
96
+ export type MixedProperty = RefProperty | FileProperty | EnumProperty | ArrayProperty | ObjectProperty | StringProperty | NumberProperty | BooleanProperty | GetterProperty | ConstProperty;
97
+ export type NonCircularMixedProperty = NonCircularRefProperty | FileProperty | EnumProperty | ArrayProperty | ObjectProperty | StringProperty | NumberProperty | BooleanProperty | GetterProperty | ConstProperty;
95
98
  export type PropertyBase = {
96
99
  description?: string;
97
100
  readOnly?: boolean;
package/dist/schema.d.ts CHANGED
@@ -33,6 +33,8 @@ export type InferProperty<T> = T extends TestType<{
33
33
  items: infer K;
34
34
  }> ? InferProperty<K>[] : T extends TestType<{
35
35
  getter: (doc: any) => infer K;
36
+ }> ? K : T extends TestType<{
37
+ const: infer K;
36
38
  }> ? K : never;
37
39
  export type InferSchema<TSchema> = MergeReferences<TSchema> extends infer MappedTypes ? TSchema extends {
38
40
  required: readonly [];
@@ -87,7 +89,7 @@ type MapReferences<TSchema> = TSchema extends {
87
89
  }>;
88
90
  }> ? K extends keyof Collections ? Collections[K]['item'][] : never : never : never;
89
91
  } : never;
90
- type PackReferencesAux<T> = T extends (...args: any[]) => any ? T : T extends {
92
+ type PackReferencesAux<T> = T extends (...args: any[]) => any ? T : T extends ObjectId ? T : T extends {
91
93
  _id: infer Id;
92
94
  } ? Id : T extends Record<string, any> ? PackReferences<T> : T extends any[] | readonly any[] ? PackReferencesAux<T[number]>[] : T;
93
95
  type CombineProperties<TSchema> = TSchema extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",