@aeriajs/types 0.0.112 → 0.0.114

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,5 +1,5 @@
1
1
  import type { UserRole } from './token.js';
2
- export type AccessCondition = readonly UserRole[] | boolean | 'unauthenticated' | 'unauthenticated-only';
2
+ export type AccessCondition = undefined | boolean | readonly UserRole[] | 'unauthenticated' | 'unauthenticated-only';
3
3
  export type RoleFromAccessCondition<TAccessCondition extends AccessCondition | undefined> = undefined extends TAccessCondition ? null : TAccessCondition extends readonly (infer Role)[] ? Role : TAccessCondition extends true ? Exclude<UserRole, 'unauthenticated'> : TAccessCondition extends false ? never : TAccessCondition extends 'unauthenticated-only' ? 'unauthenticated' : TAccessCondition extends 'unauthenticated' ? UserRole : never;
4
4
  export declare enum ACError {
5
5
  AuthenticationError = "AUTHENTICATION_ERROR",
package/dist/config.d.ts CHANGED
@@ -2,6 +2,8 @@ import type { RouteContext } from './context.js';
2
2
  import type { RouteUri } from './http.js';
3
3
  import type { RateLimitingParams } from './security.js';
4
4
  import type { CollectionItem } from './collection.js';
5
+ import type { UserRole } from './token.js';
6
+ export type RolesHierarchy = Record<UserRole, readonly UserRole[] | boolean>;
5
7
  export type ApiConfig = {
6
8
  name?: string;
7
9
  secret?: string;
@@ -33,11 +35,12 @@ export type ApiConfig = {
33
35
  allowSignup?: boolean;
34
36
  mutableUserProperties: (keyof CollectionItem<'user'>)[];
35
37
  signupDefaults?: {
36
- roles?: string[];
38
+ roles?: readonly UserRole[];
37
39
  active?: boolean;
38
40
  };
39
41
  paginationLimit?: number;
40
42
  exposeFunctionsByDefault?: boolean | 'unauthenticated';
43
+ rolesHierarchy?: RolesHierarchy;
41
44
  };
42
45
  tokenUserProperties?: (keyof CollectionItem<'user'>)[];
43
46
  errorHandler?: <TError>(context: RouteContext, error: TError) => unknown | Promise<unknown>;
package/dist/context.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { Collection as MongoCollection } from 'mongodb';
2
- import type { AcceptedRole } from './token.js';
3
2
  import type { Collection } from './collection.js';
4
3
  import type { ApiConfig } from './config.js';
5
4
  import type { CollectionFunctions } from './functions.js';
@@ -11,6 +10,7 @@ import type { PackReferences, SchemaWithId } from './schema.js';
11
10
  import type { JsonSchema } from './property.js';
12
11
  import type { RateLimitingParams, RateLimitingError } from './security.js';
13
12
  import type { Token } from './token.js';
13
+ import type { AccessCondition } from './accessControl.js';
14
14
  export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
15
15
  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;
16
16
  type RestParameters<TFunction> = TFunction extends (payload: any, context: Context<any>, ...args: infer Rest) => unknown ? Rest : never;
@@ -38,9 +38,9 @@ export type ContextOptions = {
38
38
  inherited?: boolean;
39
39
  calledFunction?: string;
40
40
  };
41
- export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
41
+ export type RouteContext<TAccessCondition extends AccessCondition = false> = {
42
42
  collections: IndepthCollections;
43
- token: Token<TAcceptedRole>;
43
+ token: Token<TAccessCondition>;
44
44
  request: GenericRequest;
45
45
  response: GenericResponse;
46
46
  log: (message: string, details?: unknown) => Promise<unknown>;
@@ -66,5 +66,5 @@ export type CollectionContext<TDescription extends Description, TFunctions = Col
66
66
  calledFunction?: string;
67
67
  };
68
68
  export type Context<TDescription extends Description = Description, TFunctions = Collection['functions']> = RouteContext & CollectionContext<TDescription, TFunctions>;
69
- export type StrictContext<TAcceptedRole extends AcceptedRole = null, TDescription extends Description = any, TFunctions = Collection['functions']> = RouteContext<TAcceptedRole> & CollectionContext<TDescription, TFunctions>;
69
+ export type StrictContext<TAccessCondition extends AccessCondition = false, TDescription extends Description = any, TFunctions = Collection['functions']> = RouteContext<TAccessCondition> & CollectionContext<TDescription, TFunctions>;
70
70
  export {};
@@ -3,7 +3,10 @@ import type { PhosphorIcon } from '@phosphor-icons/core';
3
3
  import type { Condition } from './condition.js';
4
4
  import type { JsonSchema, PropertiesWithId } from './property.js';
5
5
  import type { OwnershipMode } from './security.js';
6
- export type DescriptionPreset = 'add' | 'crud' | 'duplicate' | 'remove' | 'removeAll' | 'owned' | 'timestamped' | 'view';
6
+ export declare const DESCRIPTION_PRESETS: readonly ["add", "crud", "duplicate", "remove", "removeAll", "owned", "timestamped", "view"];
7
+ export declare const LAYOUT_NAMES: readonly ["tabular", "grid", "list"];
8
+ export type DescriptionPreset = typeof DESCRIPTION_PRESETS[number];
9
+ export type LayoutName = typeof LAYOUT_NAMES[number];
7
10
  export type Icon = PhosphorIcon['name'];
8
11
  export type CollectionActionRoute = {
9
12
  route: {
@@ -23,19 +26,19 @@ export type CollectionActionFunction = {
23
26
  export type CollectionActionEvent = {
24
27
  event?: string;
25
28
  };
26
- export type CollectionActionBase<TDescription extends Description> = {
29
+ export type CollectionActionBase<TDescription extends Description = Description> = {
27
30
  label?: string;
28
31
  icon?: Icon;
29
32
  ask?: boolean;
30
33
  translate?: boolean;
34
+ button?: boolean;
31
35
  roles?: readonly string[];
32
36
  requires?: readonly PropertiesWithId<TDescription>[];
33
37
  };
34
- export type CollectionAction<TDescription extends Description> = CollectionActionBase<TDescription> & (CollectionActionRoute | CollectionActionFunction | CollectionActionEvent);
35
- export type CollectionActions<TDescription extends Description> = Record<string, CollectionAction<TDescription> & {
38
+ export type CollectionAction<TDescription extends Description = Description> = CollectionActionBase<TDescription> & (CollectionActionRoute | CollectionActionFunction | CollectionActionEvent);
39
+ export type CollectionActions<TDescription extends Description = Description> = Record<string, CollectionAction<TDescription> & {
36
40
  button?: boolean;
37
41
  } | null>;
38
- export type CollectionIndividualActions<TDescription extends Description> = Record<string, CollectionAction<TDescription> | null>;
39
42
  export type FormLayout<TDescription extends Description> = {
40
43
  fields?: Partial<Record<PropertiesWithId<TDescription>, FormLayoutField<TDescription>>>;
41
44
  };
@@ -64,7 +67,6 @@ export type FiltersPreset<TDescription extends Description> = {
64
67
  badgeFunction?: string;
65
68
  default?: boolean;
66
69
  };
67
- export type LayoutName = 'tabular' | 'grid' | 'list';
68
70
  export type LayoutOptions<TDescription extends Description = Description> = {
69
71
  title?: PropertiesWithId<TDescription>;
70
72
  picture?: PropertiesWithId<TDescription>;
@@ -77,12 +79,12 @@ export type Layout<TDescription extends Description = Description> = {
77
79
  name: LayoutName;
78
80
  options?: LayoutOptions<TDescription>;
79
81
  };
80
- export type SearchOptions<TDescription extends Description> = {
82
+ export type SearchOptions<TDescription extends Description = Description> = {
81
83
  indexes: readonly (keyof TDescription['properties'])[];
82
84
  placeholder?: string;
83
85
  exactMatches?: boolean;
84
86
  };
85
- export type RuntimeDescription<TDescription extends Description = Description> = Pick<TDescription, 'actions' | 'individualActions' | 'filters' | 'filtersPresets' | 'layout' | 'table' | 'tableMeta' | 'form' | 'tableLayout' | 'formLayout'>;
87
+ export type RuntimeDescription<TDescription extends Description = Description> = Partial<Pick<TDescription, 'actions' | 'individualActions' | 'filters' | 'filtersPresets' | 'layout' | 'table' | 'tableMeta' | 'form' | 'tableLayout' | 'formLayout'>>;
86
88
  export type Description<TDescription extends Description = any> = JsonSchema<TDescription> & {
87
89
  title?: string;
88
90
  categories?: readonly string[];
@@ -115,6 +117,6 @@ export type Description<TDescription extends Description = any> = JsonSchema<TDe
115
117
  formLayout?: Partial<FormLayout<TDescription>>;
116
118
  tableLayout?: Partial<TableLayout<TDescription>>;
117
119
  actions?: CollectionActions<TDescription>;
118
- individualActions?: CollectionIndividualActions<TDescription>;
120
+ individualActions?: CollectionActions<TDescription>;
119
121
  search?: SearchOptions<TDescription>;
120
122
  };
@@ -1,2 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LAYOUT_NAMES = exports.DESCRIPTION_PRESETS = void 0;
4
+ exports.DESCRIPTION_PRESETS = [
5
+ 'add',
6
+ 'crud',
7
+ 'duplicate',
8
+ 'remove',
9
+ 'removeAll',
10
+ 'owned',
11
+ 'timestamped',
12
+ 'view',
13
+ ];
14
+ exports.LAYOUT_NAMES = [
15
+ 'tabular',
16
+ 'grid',
17
+ 'list',
18
+ ];
@@ -1 +1,16 @@
1
1
  "use strict";
2
+ export const DESCRIPTION_PRESETS = [
3
+ "add",
4
+ "crud",
5
+ "duplicate",
6
+ "remove",
7
+ "removeAll",
8
+ "owned",
9
+ "timestamped",
10
+ "view"
11
+ ];
12
+ export const LAYOUT_NAMES = [
13
+ "tabular",
14
+ "grid",
15
+ "list"
16
+ ];
@@ -2,10 +2,14 @@ import type { PhosphorIcon } from '@phosphor-icons/core';
2
2
  import type { ObjectId } from 'mongodb';
3
3
  import type { Condition } from './condition.js';
4
4
  import type { RouteContext } from './context.js';
5
- export type PropertyArrayElement = 'checkbox' | 'radio' | 'select';
6
- export type PropertyInputType = 'text' | 'email' | 'password' | 'search' | 'time' | 'month';
7
- export type PropertyInputElement = 'input' | 'textarea';
8
- export type PropertyFormat = 'date' | 'date-time' | 'objectid';
5
+ export declare const PROPERTY_ARRAY_ELEMENTS: readonly ["checkbox", "radio", "select"];
6
+ export declare const PROPERTY_INPUT_TYPES: readonly ["text", "email", "password", "search", "time", "month"];
7
+ export declare const PROPERTY_INPUT_ELEMENTS: readonly ["input", "textarea"];
8
+ export declare const PROPERTY_FORMATS: readonly ["date", "date-time", "objectid"];
9
+ export type PropertyArrayElement = typeof PROPERTY_ARRAY_ELEMENTS[number];
10
+ export type PropertyInputType = typeof PROPERTY_INPUT_TYPES[number];
11
+ export type PropertyInputElement = typeof PROPERTY_INPUT_ELEMENTS[number];
12
+ export type PropertyFormat = typeof PROPERTY_FORMATS[number];
9
13
  export type PropertiesWithId<TJsonSchema extends JsonSchema> = Extract<keyof TJsonSchema['properties'], string> | '_id';
10
14
  export type RequiredProperties<TJsonSchema extends JsonSchema> = readonly PropertiesWithId<TJsonSchema>[] | Partial<Record<PropertiesWithId<TJsonSchema>, Condition<TJsonSchema> | boolean>>;
11
15
  export type JsonSchema<TJsonSchema extends JsonSchema = any> = {
@@ -21,10 +25,10 @@ export type RefProperty = {
21
25
  $ref: Exclude<keyof Collections, 'file'> & string;
22
26
  indexes?: readonly string[];
23
27
  select?: readonly string[];
24
- inline?: boolean;
28
+ populate?: readonly string[];
25
29
  form?: readonly string[];
30
+ inline?: boolean;
26
31
  purge?: boolean;
27
- populate?: readonly string[];
28
32
  populateDepth?: number;
29
33
  constraints?: Condition;
30
34
  };
@@ -72,8 +76,8 @@ export type StringProperty = {
72
76
  mask?: string | readonly string[];
73
77
  maskedValue?: boolean;
74
78
  placeholder?: string;
75
- element?: PropertyInputElement;
76
79
  inputType?: PropertyInputType;
80
+ element?: PropertyInputElement;
77
81
  };
78
82
  export type NumberProperty = {
79
83
  type: 'number' | 'integer';
package/dist/property.js CHANGED
@@ -1,2 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROPERTY_FORMATS = exports.PROPERTY_INPUT_ELEMENTS = exports.PROPERTY_INPUT_TYPES = exports.PROPERTY_ARRAY_ELEMENTS = void 0;
4
+ exports.PROPERTY_ARRAY_ELEMENTS = [
5
+ 'checkbox',
6
+ 'radio',
7
+ 'select',
8
+ ];
9
+ exports.PROPERTY_INPUT_TYPES = [
10
+ 'text',
11
+ 'email',
12
+ 'password',
13
+ 'search',
14
+ 'time',
15
+ 'month',
16
+ ];
17
+ exports.PROPERTY_INPUT_ELEMENTS = [
18
+ 'input',
19
+ 'textarea',
20
+ ];
21
+ exports.PROPERTY_FORMATS = [
22
+ 'date',
23
+ 'date-time',
24
+ 'objectid',
25
+ ];
package/dist/property.mjs CHANGED
@@ -1 +1,23 @@
1
1
  "use strict";
2
+ export const PROPERTY_ARRAY_ELEMENTS = [
3
+ "checkbox",
4
+ "radio",
5
+ "select"
6
+ ];
7
+ export const PROPERTY_INPUT_TYPES = [
8
+ "text",
9
+ "email",
10
+ "password",
11
+ "search",
12
+ "time",
13
+ "month"
14
+ ];
15
+ export const PROPERTY_INPUT_ELEMENTS = [
16
+ "input",
17
+ "textarea"
18
+ ];
19
+ export const PROPERTY_FORMATS = [
20
+ "date",
21
+ "date-time",
22
+ "objectid"
23
+ ];
package/dist/token.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import type { ObjectId } from 'mongodb';
2
2
  import type { PackReferences } from './schema.js';
3
+ import type { AccessCondition } from './accessControl.js';
3
4
  export type UserRole = (Collections['user']['item'] extends {
4
5
  roles: infer Roles;
5
6
  } ? Roles extends unknown[] ? Roles[number] extends infer UserDefinedRole ? UserDefinedRole extends string ? `${UserDefinedRole}${UserDefinedRole}` extends UserDefinedRole ? 'root' : UserDefinedRole : never : never : never : never) | 'root' | 'unauthenticated';
6
- export type AcceptedRole = UserRole | UserRole[] | null | unknown;
7
- export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null, TUserRole = UserRole, TUserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>> = {
7
+ export type AuthenticatedToken<TAccessCondition extends AccessCondition = true, TUserRole = UserRole, TUserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>> = {
8
8
  authenticated: true;
9
9
  sub: ObjectId | null;
10
- roles: readonly (TAcceptedRole extends null ? TUserRole : TAcceptedRole)[];
10
+ roles: TAccessCondition extends readonly unknown[] ? TAccessCondition : TAccessCondition extends true ? readonly TUserRole[] : TAccessCondition extends 'unauthenticated' ? readonly UserRole[] : readonly [];
11
11
  picture?: string;
12
12
  userinfo: Partial<TUserInfo | PackReferences<TUserInfo>>;
13
13
  };
@@ -19,4 +19,4 @@ export type TokenRecipient = {
19
19
  type: 'bearer';
20
20
  content: string;
21
21
  };
22
- 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>;
22
+ export type Token<TAccessCondition extends AccessCondition = false, TUserRole = UserRole, TUserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>> = (false extends TAccessCondition ? false : TAccessCondition extends 'unauthenticated' | 'unauthenticated-only' ? false : true) extends true ? AuthenticatedToken<TAccessCondition> : 'unauthenticated-only' extends TAccessCondition ? UnauthenticatedToken : AuthenticatedToken<true, TUserRole, TUserInfo> | UnauthenticatedToken;
@@ -27,16 +27,16 @@ export type PropertyValidationError = {
27
27
  };
28
28
  export type ValidationErrorInvalidProperties = {
29
29
  code: ValidationErrorCode.InvalidProperties;
30
- errors: Record<string, PropertyValidationError | ValidationError>;
30
+ details: Record<string, PropertyValidationError | ValidationError>;
31
31
  };
32
32
  export type ValidationErrorMissingProperties = {
33
33
  code: ValidationErrorCode.MissingProperties;
34
- errors: Record<string, {
34
+ details: Record<string, {
35
35
  type: 'missing';
36
36
  }>;
37
37
  };
38
38
  export type ValidationErrorEmptyTarget = {
39
39
  code: ValidationErrorCode.EmptyTarget;
40
- errors: {};
40
+ details: {};
41
41
  };
42
42
  export type ValidationError = ValidationErrorInvalidProperties | ValidationErrorMissingProperties | ValidationErrorEmptyTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.112",
3
+ "version": "0.0.114",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,7 +21,7 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
- "devDependencies": {
24
+ "peerDependencies": {
25
25
  "@phosphor-icons/core": "^2.1.1"
26
26
  },
27
27
  "scripts": {