@dudousxd/nestjs-authz-mikro-orm 0.4.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @dudousxd/nestjs-authz-mikro-orm
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#18](https://github.com/DavideCarvalho/nestjs-authz/pull/18) [`a5662a2`](https://github.com/DavideCarvalho/nestjs-authz/commit/a5662a2b599d826ae3a0d08e6ad71da7f2e425dc) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Ship typed MikroORM repositories for the four authz entities, and a schema factory for custom table names.
8
+
9
+ - New `AuthzRoleRepository`, `AuthzPermissionRepository`, `AuthzRolePermissionRepository` and `AuthzUserRoleRepository` (empty `EntityRepository` subclasses), bound to the entities via `repository: () => ...` on each `EntitySchema` plus an `[EntityRepositoryType]` marker on each entity class. `em.getRepository(RoleEntity)` now returns — and is typed as — `AuthzRoleRepository`, and `MikroOrmModule.forFeature([...AUTHZ_ENTITY_CLASSES])` registers each repository class as its own DI token, so host apps inject by type instead of threading the entity class through every `em.find(RoleEntity, ...)`.
10
+ - New `createAuthzEntitySchemas(tableNames?)` — the supported way to relocate the authz tables. It carries the repository binding and derives the index names from the given table names; hand-writing a replacement `EntitySchema` (the previously documented path) silently dropped both. `AUTHZ_ENTITIES` and `RoleEntitySchema` … `UserRoleEntitySchema` are now produced by this factory with the default names, so they are unchanged.
11
+ - New `AUTHZ_ENTITY_CLASSES` export (the four classes in dependency order) for `MikroOrmModule.forFeature()`, which matches on `meta.class`.
12
+ - `ensureAuthzSchema` / `authzSchemaSql` now read the four physical table names off the live metadata instead of hard-coding the `authz_*` literals, so relocated tables are created too.
13
+
14
+ `EntityRepository`, `EntityRepositoryType` and the `repository` option on `EntitySchemaMetadata` all live in `@mikro-orm/core` on both MikroORM 6 and 7, so this adds no peer and no decorator import. Verified against the v6 suite and the pinned `@mikro-orm/core@7` integration suite.
15
+
16
+ `MikroOrmAuthzStore` is unchanged.
17
+
3
18
  ## 0.4.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -36,10 +36,56 @@ import { AUTHZ_ENTITIES } from '@dudousxd/nestjs-authz-mikro-orm';
36
36
  await MikroORM.init({ entities: [...AUTHZ_ENTITIES /* , your entities */] });
37
37
  ```
38
38
 
39
- > BYO table names: MikroORM resolves table names from entity metadata at discovery time,
40
- > so override them by re-declaring these entities with your own `EntitySchema({ tableName })`
41
- > (the `RoleEntitySchema` … `UserRoleEntitySchema` exports are the defaults); the store +
42
- > schema helpers operate purely through the `EntityManager` and never assume a literal name.
39
+ ### BYO table names
40
+
41
+ MikroORM resolves table names from entity metadata at discovery time. Build your own set of
42
+ schemas with `createAuthzEntitySchemas` and register those instead:
43
+
44
+ ```ts
45
+ import { createAuthzEntitySchemas } from '@dudousxd/nestjs-authz-mikro-orm';
46
+
47
+ const authz = createAuthzEntitySchemas({ roles: 'app_roles', userRole: 'app_user_role' });
48
+ await MikroORM.init({ entities: [...authz.all /* , your entities */] });
49
+ ```
50
+
51
+ Any subset of `roles` / `permissions` / `rolePermission` / `userRole` may be overridden; the
52
+ rest keep their defaults. The factory carries the custom repository binding and derives the
53
+ index names from your table names, so nothing is lost by relocating the tables — hand-writing
54
+ `new EntitySchema({ class: RoleEntity, tableName })` instead silently drops both. The store and
55
+ the schema helpers read the physical names back off the live metadata and never assume a
56
+ literal name.
57
+
58
+ ## Repositories
59
+
60
+ Each entity is bound to a typed repository, so app code injects it by type rather than passing
61
+ the entity class to every `EntityManager` call:
62
+
63
+ ```ts
64
+ import { AUTHZ_ENTITY_CLASSES, AuthzRoleRepository } from '@dudousxd/nestjs-authz-mikro-orm';
65
+ import { MikroOrmModule } from '@mikro-orm/nestjs';
66
+
67
+ @Module({
68
+ // forFeature matches on the entity CLASS — pass these, not the schemas.
69
+ imports: [MikroOrmModule.forFeature([...AUTHZ_ENTITY_CLASSES])],
70
+ })
71
+ export class RolesModule {}
72
+
73
+ @Injectable()
74
+ export class RolesService {
75
+ constructor(private readonly roles: AuthzRoleRepository) {}
76
+
77
+ findByName(name: string) {
78
+ return this.roles.findOne({ name });
79
+ }
80
+ }
81
+ ```
82
+
83
+ Without `@mikro-orm/nestjs`, `em.getRepository(RoleEntity)` returns the same instance and is
84
+ typed as `AuthzRoleRepository`. The four classes are `AuthzRoleRepository`,
85
+ `AuthzPermissionRepository`, `AuthzRolePermissionRepository` and `AuthzUserRoleRepository`;
86
+ their bodies are empty — this package ships no query surface beyond `MikroOrmAuthzStore`.
87
+
88
+ `MikroOrmAuthzStore` is unaffected — it still takes an `EntityManager` and owns no connection.
43
89
 
44
90
  ## Usage
45
91
 
@@ -1,9 +1,10 @@
1
- import { EntitySchema } from '@mikro-orm/core';
1
+ import { EntityRepositoryType, EntitySchema } from '@mikro-orm/core';
2
+ import { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository } from './repositories.js';
2
3
  /**
3
- * Default table names — the {@link EntitySchema} definitions below carry these as their
4
- * `tableName`. MikroORM resolves the physical table from the entity metadata (not at
5
- * runtime), so an app that wants different names re-declares these schemas; the store +
6
- * schema helpers operate purely through the EntityManager and never assume a literal name.
4
+ * Default physical table names. MikroORM resolves the table from entity metadata, so an app
5
+ * that wants different names builds its own set of schemas with
6
+ * {@link createAuthzEntitySchemas}; the store + schema helpers operate purely through the
7
+ * EntityManager and read the physical names back off the live metadata.
7
8
  */
8
9
  export declare const DEFAULT_TABLE_NAMES: {
9
10
  readonly roles: "authz_roles";
@@ -11,6 +12,13 @@ export declare const DEFAULT_TABLE_NAMES: {
11
12
  readonly rolePermission: "authz_role_permission";
12
13
  readonly userRole: "authz_user_role";
13
14
  };
15
+ /** Physical table names for the four authz tables. */
16
+ export interface AuthzTableNames {
17
+ roles: string;
18
+ permissions: string;
19
+ rolePermission: string;
20
+ userRole: string;
21
+ }
14
22
  /**
15
23
  * The entities are described with {@link EntitySchema} (the schema-first definition style)
16
24
  * rather than property decorators. This is the ONE definition surface that lives entirely
@@ -28,47 +36,89 @@ export declare const DEFAULT_TABLE_NAMES: {
28
36
  * carry a default — `ensureAuthzSchema` only ever runs the non-destructive `safe` diff
29
37
  * (create table + add-missing-column), and `ADD COLUMN NOT NULL` without a default fails
30
38
  * on a populated table.
39
+ *
40
+ * `[EntityRepositoryType]` is a `declare`d marker: it carries no runtime field (the symbol is
41
+ * skipped by MikroORM's property discovery either way) and only tells the type system what
42
+ * `em.getRepository(RoleEntity)` returns.
31
43
  */
32
44
  /**
33
45
  * A named role (e.g. `editor`). Permissions are attached via {@link RolePermissionEntity};
34
46
  * users are attached via {@link UserRoleEntity}.
35
47
  */
36
48
  export declare class RoleEntity {
49
+ [EntityRepositoryType]?: AuthzRoleRepository;
37
50
  id: string;
38
51
  name: string;
39
52
  guard?: string | null;
40
53
  createdAt: Date;
41
54
  }
42
- export declare const RoleEntitySchema: EntitySchema<RoleEntity, never>;
43
55
  /** A named permission (e.g. `posts.publish`). Granted to roles via {@link RolePermissionEntity}. */
44
56
  export declare class PermissionEntity {
57
+ [EntityRepositoryType]?: AuthzPermissionRepository;
45
58
  id: string;
46
59
  name: string;
47
60
  guard?: string | null;
48
61
  createdAt: Date;
49
62
  }
50
- export declare const PermissionEntitySchema: EntitySchema<PermissionEntity, never>;
51
63
  /** Pivot: role ↔ permission. Composite PK `(roleId, permissionId)`. */
52
64
  export declare class RolePermissionEntity {
65
+ [EntityRepositoryType]?: AuthzRolePermissionRepository;
53
66
  roleId: string;
54
67
  permissionId: string;
55
68
  }
56
- export declare const RolePermissionEntitySchema: EntitySchema<RolePermissionEntity, never>;
57
69
  /**
58
70
  * Pivot: user ↔ role. References the user BY ID ONLY — this package NEVER defines or
59
71
  * owns a users table. `userType` lets the same table key polymorphic principals
60
72
  * (mirrors nestjs-context's `UserRef` shape).
61
73
  */
62
74
  export declare class UserRoleEntity {
75
+ [EntityRepositoryType]?: AuthzUserRoleRepository;
63
76
  userType: string;
64
77
  userId: string;
65
78
  roleId: string;
66
79
  }
80
+ /** The four {@link EntitySchema} definitions produced by {@link createAuthzEntitySchemas}. */
81
+ export interface AuthzEntitySchemas {
82
+ role: EntitySchema<RoleEntity>;
83
+ permission: EntitySchema<PermissionEntity>;
84
+ rolePermission: EntitySchema<RolePermissionEntity>;
85
+ userRole: EntitySchema<UserRoleEntity>;
86
+ /** All four, in dependency order — spread into `entities: [...]`. */
87
+ all: [
88
+ EntitySchema<RoleEntity>,
89
+ EntitySchema<PermissionEntity>,
90
+ EntitySchema<RolePermissionEntity>,
91
+ EntitySchema<UserRoleEntity>
92
+ ];
93
+ }
94
+ /**
95
+ * Build the four authz {@link EntitySchema} definitions, optionally under your own table
96
+ * names — this is the supported way to relocate the tables:
97
+ *
98
+ * ```ts
99
+ * const authz = createAuthzEntitySchemas({ roles: 'app_roles' });
100
+ * await MikroORM.init({ entities: [...authz.all] });
101
+ * ```
102
+ *
103
+ * Going through the factory (rather than hand-writing `new EntitySchema({ tableName })`)
104
+ * keeps the custom repository binding and the index names attached to the renamed tables;
105
+ * a hand-rolled re-declaration silently drops both.
106
+ */
107
+ export declare function createAuthzEntitySchemas(tableNames?: Partial<AuthzTableNames>): AuthzEntitySchemas;
108
+ export declare const RoleEntitySchema: EntitySchema<RoleEntity, never>;
109
+ export declare const PermissionEntitySchema: EntitySchema<PermissionEntity, never>;
110
+ export declare const RolePermissionEntitySchema: EntitySchema<RolePermissionEntity, never>;
67
111
  export declare const UserRoleEntitySchema: EntitySchema<UserRoleEntity, never>;
68
112
  /**
69
113
  * All entity SCHEMAS, in dependency order — pass to `entities: [...]` registration. These
70
114
  * are the {@link EntitySchema} objects MikroORM discovers; the store keys on the plain
71
115
  * classes ({@link RoleEntity} etc.), which the schemas are bound to via `class`.
72
116
  */
73
- export declare const AUTHZ_ENTITIES: readonly [EntitySchema<RoleEntity, never>, EntitySchema<PermissionEntity, never>, EntitySchema<RolePermissionEntity, never>, EntitySchema<UserRoleEntity, never>];
117
+ export declare const AUTHZ_ENTITIES: [EntitySchema<RoleEntity, never>, EntitySchema<PermissionEntity, never>, EntitySchema<RolePermissionEntity, never>, EntitySchema<UserRoleEntity, never>];
118
+ /**
119
+ * The four entity CLASSES, in the same order. Pass these (not the schemas) to
120
+ * `MikroOrmModule.forFeature()` — it matches on `meta.class`, and only then does it register
121
+ * {@link AuthzRoleRepository} & friends as DI tokens.
122
+ */
123
+ export declare const AUTHZ_ENTITY_CLASSES: readonly [typeof RoleEntity, typeof PermissionEntity, typeof RolePermissionEntity, typeof UserRoleEntity];
74
124
  //# sourceMappingURL=entities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,qBAAa,UAAU;IACrB,EAAE,EAAG,MAAM,CAAC;IACZ,IAAI,EAAG,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAG,IAAI,CAAC;CAClB;AAED,eAAO,MAAM,gBAAgB,iCAc3B,CAAC;AAEH,oGAAoG;AACpG,qBAAa,gBAAgB;IAC3B,EAAE,EAAG,MAAM,CAAC;IACZ,IAAI,EAAG,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAG,IAAI,CAAC;CAClB;AAED,eAAO,MAAM,sBAAsB,uCAcjC,CAAC;AAEH,uEAAuE;AACvE,qBAAa,oBAAoB;IAC/B,MAAM,EAAG,MAAM,CAAC;IAChB,YAAY,EAAG,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,0BAA0B,2CAOrC,CAAC;AAEH;;;;GAIG;A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E,6BAA6B,CAAC;IAC/D,MAAM,EAAG,MAAM,CAAC;IAChB,YAAY,EAAG,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,qBAAa,cAAc;IACjB,CAAC,oBAAoB,CAAC,CAAC,EAAE,uBAAuB,CAAC;IACzD,QAAQ,EAAG,MAAM,CAAC;IAClB,MAAM,EAAG,MAAM,CAAC;IAChB,MAAM,EAAG,MAAM,CAAC;CACjB;AAED,8FAA8F;AAC9F,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;IAC/B,UAAU,EAAE,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAC3C,cAAc,EAAE,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACnD,QAAQ,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IACvC,qEAAqE;IACrE,GAAG,EAAE;QACH,YAAY,CAAC,UAAU,CAAC;QACxB,YAAY,CAAC,gBAAgB,CAAC;QAC9B,YAAY,CAAC,oBAAoB,CAAC;QAClC,YAAY,CAAC,cAAc,CAAC;KAC7B,CAAC;CACH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,GAAE,OAAO,CAAC,eAAe,CAAM,GACxC,kBAAkB,CAkEpB;AAID,eAAO,MAAM,gBAAgB,iCAAsB,CAAC;AACpD,eAAO,MAAM,sBAAsB,uCAA4B,CAAC;AAChE,eAAO,MAAM,0BAA0B,2CAAgC,CAAC;AACxE,eAAO,MAAM,oBAAoB,qCAA0B,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,cAAc,0JAAqB,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,2GAKvB,CAAC"}
package/dist/entities.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { EntitySchema } from '@mikro-orm/core';
2
+ import { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository, } from './repositories.js';
2
3
  /**
3
- * Default table names — the {@link EntitySchema} definitions below carry these as their
4
- * `tableName`. MikroORM resolves the physical table from the entity metadata (not at
5
- * runtime), so an app that wants different names re-declares these schemas; the store +
6
- * schema helpers operate purely through the EntityManager and never assume a literal name.
4
+ * Default physical table names. MikroORM resolves the table from entity metadata, so an app
5
+ * that wants different names builds its own set of schemas with
6
+ * {@link createAuthzEntitySchemas}; the store + schema helpers operate purely through the
7
+ * EntityManager and read the physical names back off the live metadata.
7
8
  */
8
9
  export const DEFAULT_TABLE_NAMES = {
9
10
  roles: 'authz_roles',
@@ -28,6 +29,10 @@ export const DEFAULT_TABLE_NAMES = {
28
29
  * carry a default — `ensureAuthzSchema` only ever runs the non-destructive `safe` diff
29
30
  * (create table + add-missing-column), and `ADD COLUMN NOT NULL` without a default fails
30
31
  * on a populated table.
32
+ *
33
+ * `[EntityRepositoryType]` is a `declare`d marker: it carries no runtime field (the symbol is
34
+ * skipped by MikroORM's property discovery either way) and only tells the type system what
35
+ * `em.getRepository(RoleEntity)` returns.
31
36
  */
32
37
  /**
33
38
  * A named role (e.g. `editor`). Permissions are attached via {@link RolePermissionEntity};
@@ -39,21 +44,6 @@ export class RoleEntity {
39
44
  guard;
40
45
  createdAt;
41
46
  }
42
- export const RoleEntitySchema = new EntitySchema({
43
- class: RoleEntity,
44
- tableName: DEFAULT_TABLE_NAMES.roles,
45
- properties: {
46
- id: { type: 'string', length: 191, primary: true },
47
- name: {
48
- type: 'string',
49
- length: 191,
50
- unique: true,
51
- index: 'authz_roles_name_uniq',
52
- },
53
- guard: { type: 'string', nullable: true },
54
- createdAt: { type: 'datetime' },
55
- },
56
- });
57
47
  /** A named permission (e.g. `posts.publish`). Granted to roles via {@link RolePermissionEntity}. */
58
48
  export class PermissionEntity {
59
49
  id;
@@ -61,34 +51,11 @@ export class PermissionEntity {
61
51
  guard;
62
52
  createdAt;
63
53
  }
64
- export const PermissionEntitySchema = new EntitySchema({
65
- class: PermissionEntity,
66
- tableName: DEFAULT_TABLE_NAMES.permissions,
67
- properties: {
68
- id: { type: 'string', length: 191, primary: true },
69
- name: {
70
- type: 'string',
71
- length: 191,
72
- unique: true,
73
- index: 'authz_permissions_name_uniq',
74
- },
75
- guard: { type: 'string', nullable: true },
76
- createdAt: { type: 'datetime' },
77
- },
78
- });
79
54
  /** Pivot: role ↔ permission. Composite PK `(roleId, permissionId)`. */
80
55
  export class RolePermissionEntity {
81
56
  roleId;
82
57
  permissionId;
83
58
  }
84
- export const RolePermissionEntitySchema = new EntitySchema({
85
- class: RolePermissionEntity,
86
- tableName: DEFAULT_TABLE_NAMES.rolePermission,
87
- properties: {
88
- roleId: { type: 'string', length: 191, primary: true },
89
- permissionId: { type: 'string', length: 191, primary: true },
90
- },
91
- });
92
59
  /**
93
60
  * Pivot: user ↔ role. References the user BY ID ONLY — this package NEVER defines or
94
61
  * owns a users table. `userType` lets the same table key polymorphic principals
@@ -99,25 +66,101 @@ export class UserRoleEntity {
99
66
  userId;
100
67
  roleId;
101
68
  }
102
- export const UserRoleEntitySchema = new EntitySchema({
103
- class: UserRoleEntity,
104
- tableName: DEFAULT_TABLE_NAMES.userRole,
105
- properties: {
106
- userType: { type: 'string', length: 191, primary: true },
107
- userId: { type: 'string', length: 191, primary: true },
108
- roleId: { type: 'string', length: 191, primary: true },
109
- },
110
- indexes: [{ name: 'authz_user_role_user_idx', properties: ['userType', 'userId'] }],
111
- });
69
+ /**
70
+ * Build the four authz {@link EntitySchema} definitions, optionally under your own table
71
+ * names — this is the supported way to relocate the tables:
72
+ *
73
+ * ```ts
74
+ * const authz = createAuthzEntitySchemas({ roles: 'app_roles' });
75
+ * await MikroORM.init({ entities: [...authz.all] });
76
+ * ```
77
+ *
78
+ * Going through the factory (rather than hand-writing `new EntitySchema({ tableName })`)
79
+ * keeps the custom repository binding and the index names attached to the renamed tables;
80
+ * a hand-rolled re-declaration silently drops both.
81
+ */
82
+ export function createAuthzEntitySchemas(tableNames = {}) {
83
+ const names = { ...DEFAULT_TABLE_NAMES, ...tableNames };
84
+ const role = new EntitySchema({
85
+ class: RoleEntity,
86
+ tableName: names.roles,
87
+ repository: () => AuthzRoleRepository,
88
+ properties: {
89
+ id: { type: 'string', length: 191, primary: true },
90
+ name: {
91
+ type: 'string',
92
+ length: 191,
93
+ unique: true,
94
+ index: `${names.roles}_name_uniq`,
95
+ },
96
+ guard: { type: 'string', nullable: true },
97
+ createdAt: { type: 'datetime' },
98
+ },
99
+ });
100
+ const permission = new EntitySchema({
101
+ class: PermissionEntity,
102
+ tableName: names.permissions,
103
+ repository: () => AuthzPermissionRepository,
104
+ properties: {
105
+ id: { type: 'string', length: 191, primary: true },
106
+ name: {
107
+ type: 'string',
108
+ length: 191,
109
+ unique: true,
110
+ index: `${names.permissions}_name_uniq`,
111
+ },
112
+ guard: { type: 'string', nullable: true },
113
+ createdAt: { type: 'datetime' },
114
+ },
115
+ });
116
+ const rolePermission = new EntitySchema({
117
+ class: RolePermissionEntity,
118
+ tableName: names.rolePermission,
119
+ repository: () => AuthzRolePermissionRepository,
120
+ properties: {
121
+ roleId: { type: 'string', length: 191, primary: true },
122
+ permissionId: { type: 'string', length: 191, primary: true },
123
+ },
124
+ });
125
+ const userRole = new EntitySchema({
126
+ class: UserRoleEntity,
127
+ tableName: names.userRole,
128
+ repository: () => AuthzUserRoleRepository,
129
+ properties: {
130
+ userType: { type: 'string', length: 191, primary: true },
131
+ userId: { type: 'string', length: 191, primary: true },
132
+ roleId: { type: 'string', length: 191, primary: true },
133
+ },
134
+ indexes: [{ name: `${names.userRole}_user_idx`, properties: ['userType', 'userId'] }],
135
+ });
136
+ return {
137
+ role,
138
+ permission,
139
+ rolePermission,
140
+ userRole,
141
+ all: [role, permission, rolePermission, userRole],
142
+ };
143
+ }
144
+ const defaultSchemas = createAuthzEntitySchemas();
145
+ export const RoleEntitySchema = defaultSchemas.role;
146
+ export const PermissionEntitySchema = defaultSchemas.permission;
147
+ export const RolePermissionEntitySchema = defaultSchemas.rolePermission;
148
+ export const UserRoleEntitySchema = defaultSchemas.userRole;
112
149
  /**
113
150
  * All entity SCHEMAS, in dependency order — pass to `entities: [...]` registration. These
114
151
  * are the {@link EntitySchema} objects MikroORM discovers; the store keys on the plain
115
152
  * classes ({@link RoleEntity} etc.), which the schemas are bound to via `class`.
116
153
  */
117
- export const AUTHZ_ENTITIES = [
118
- RoleEntitySchema,
119
- PermissionEntitySchema,
120
- RolePermissionEntitySchema,
121
- UserRoleEntitySchema,
154
+ export const AUTHZ_ENTITIES = defaultSchemas.all;
155
+ /**
156
+ * The four entity CLASSES, in the same order. Pass these (not the schemas) to
157
+ * `MikroOrmModule.forFeature()` — it matches on `meta.class`, and only then does it register
158
+ * {@link AuthzRoleRepository} & friends as DI tokens.
159
+ */
160
+ export const AUTHZ_ENTITY_CLASSES = [
161
+ RoleEntity,
162
+ PermissionEntity,
163
+ RolePermissionEntity,
164
+ UserRoleEntity,
122
165
  ];
123
166
  //# sourceMappingURL=entities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entities.js","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,mBAAmB;IAChC,cAAc,EAAE,uBAAuB;IACvC,QAAQ,EAAE,iBAAiB;CACnB,CAAC;AAEX;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,MAAM,OAAO,UAAU;IACrB,EAAE,CAAU;IACZ,IAAI,CAAU;IACd,KAAK,CAAiB;IACtB,SAAS,CAAQ;CAClB;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAAa;IAC3D,KAAK,EAAE,UAAU;IACjB,SAAS,EAAE,mBAAmB,CAAC,KAAK;IACpC,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,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,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE;YACtD,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE;SACvD;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,WAAW,EAAE,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC;KACtF,CAAC,CAAC;IAEH,OAAO;QACL,IAAI;QACJ,UAAU;QACV,cAAc;QACd,QAAQ;QACR,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,cAAc,GAAG,wBAAwB,EAAE,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,CAAC,UAAU,CAAC;AAChE,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CAAC,cAAc,CAAC;AACxE,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC,QAAQ,CAAC;AAE5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,UAAU;IACV,gBAAgB;IAChB,oBAAoB;IACpB,cAAc;CACN,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { AUTHZ_ENTITIES, DEFAULT_TABLE_NAMES, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
1
+ export { AUTHZ_ENTITIES, AUTHZ_ENTITY_CLASSES, createAuthzEntitySchemas, DEFAULT_TABLE_NAMES, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
2
+ export type { AuthzEntitySchemas, AuthzTableNames } from './entities.js';
3
+ export { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository, } from './repositories.js';
2
4
  export { authzSchemaSql, ensureAuthzSchema } from './schema.js';
3
5
  export { MikroOrmAuthzStore } from './mikro-orm-authz.store.js';
4
6
  export type { UserAuthz } from './mikro-orm-authz.store.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,2BAA2B,EAC3B,sBAAsB,EACtB,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGzE,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,2BAA2B,EAC3B,sBAAsB,EACtB,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
- export { AUTHZ_ENTITIES, DEFAULT_TABLE_NAMES, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
1
+ export { AUTHZ_ENTITIES, AUTHZ_ENTITY_CLASSES, createAuthzEntitySchemas, DEFAULT_TABLE_NAMES, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
2
+ // VALUE exports on purpose: these classes are the DI tokens `MikroOrmModule.forFeature()`
3
+ // registers, so `export type` would compile green and be `undefined` at runtime.
4
+ export { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository, } from './repositories.js';
2
5
  export { authzSchemaSql, ensureAuthzSchema } from './schema.js';
3
6
  export { MikroOrmAuthzStore } from './mikro-orm-authz.store.js';
4
7
  export { AUTHZ_RBAC_OPTIONS, AUTHZ_RBAC_STORE, AuthzRbacModule, defaultUserRefMapper, } from './authz-rbac.module.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAEvB,0FAA0F;AAC1F,iFAAiF;AACjF,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { EntityRepository } from '@mikro-orm/core';
2
+ import type { PermissionEntity, RoleEntity, RolePermissionEntity, UserRoleEntity } from './entities.js';
3
+ /**
4
+ * Typed repositories for the four authz entities, so a host app injects `AuthzRoleRepository`
5
+ * by type instead of threading the entity class through `em.find(RoleEntity, ...)` at every
6
+ * call site.
7
+ *
8
+ * The binding is two-sided: `repository: () => ...` on each `EntitySchema` (what
9
+ * `em.getRepository()` and `MikroOrmModule.forFeature()` read at runtime) plus the
10
+ * `[EntityRepositoryType]` marker on each entity class (what makes the return type narrow).
11
+ *
12
+ * `EntityRepository` is exported from `@mikro-orm/core` on both MikroORM 6 and 7, so this
13
+ * needs no extra peer and no decorator import.
14
+ *
15
+ * The bodies are intentionally empty — this package ships no query surface beyond
16
+ * `MikroOrmAuthzStore`; they exist to give the four entities an injectable identity.
17
+ */
18
+ export declare class AuthzRoleRepository extends EntityRepository<RoleEntity> {
19
+ }
20
+ export declare class AuthzPermissionRepository extends EntityRepository<PermissionEntity> {
21
+ }
22
+ export declare class AuthzRolePermissionRepository extends EntityRepository<RolePermissionEntity> {
23
+ }
24
+ export declare class AuthzUserRoleRepository extends EntityRepository<UserRoleEntity> {
25
+ }
26
+ //# sourceMappingURL=repositories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repositories.d.ts","sourceRoot":"","sources":["../src/repositories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,cAAc,EACf,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;GAcG;AACH,qBAAa,mBAAoB,SAAQ,gBAAgB,CAAC,UAAU,CAAC;CAAG;AAExE,qBAAa,yBAA0B,SAAQ,gBAAgB,CAAC,gBAAgB,CAAC;CAAG;AAEpF,qBAAa,6BAA8B,SAAQ,gBAAgB,CAAC,oBAAoB,CAAC;CAAG;AAE5F,qBAAa,uBAAwB,SAAQ,gBAAgB,CAAC,cAAc,CAAC;CAAG"}
@@ -0,0 +1,25 @@
1
+ import { EntityRepository } from '@mikro-orm/core';
2
+ /**
3
+ * Typed repositories for the four authz entities, so a host app injects `AuthzRoleRepository`
4
+ * by type instead of threading the entity class through `em.find(RoleEntity, ...)` at every
5
+ * call site.
6
+ *
7
+ * The binding is two-sided: `repository: () => ...` on each `EntitySchema` (what
8
+ * `em.getRepository()` and `MikroOrmModule.forFeature()` read at runtime) plus the
9
+ * `[EntityRepositoryType]` marker on each entity class (what makes the return type narrow).
10
+ *
11
+ * `EntityRepository` is exported from `@mikro-orm/core` on both MikroORM 6 and 7, so this
12
+ * needs no extra peer and no decorator import.
13
+ *
14
+ * The bodies are intentionally empty — this package ships no query surface beyond
15
+ * `MikroOrmAuthzStore`; they exist to give the four entities an injectable identity.
16
+ */
17
+ export class AuthzRoleRepository extends EntityRepository {
18
+ }
19
+ export class AuthzPermissionRepository extends EntityRepository {
20
+ }
21
+ export class AuthzRolePermissionRepository extends EntityRepository {
22
+ }
23
+ export class AuthzUserRoleRepository extends EntityRepository {
24
+ }
25
+ //# sourceMappingURL=repositories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repositories.js","sourceRoot":"","sources":["../src/repositories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAQnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,mBAAoB,SAAQ,gBAA4B;CAAG;AAExE,MAAM,OAAO,yBAA0B,SAAQ,gBAAkC;CAAG;AAEpF,MAAM,OAAO,6BAA8B,SAAQ,gBAAsC;CAAG;AAE5F,MAAM,OAAO,uBAAwB,SAAQ,gBAAgC;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAwC/D;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAGvF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAQxF"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA4D/D;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAGvF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAQxF"}
package/dist/schema.js CHANGED
@@ -1,10 +1,20 @@
1
- /** The four authz table names — used to filter the schema diff down to our tables. */
2
- const AUTHZ_TABLES = [
3
- 'authz_roles',
4
- 'authz_permissions',
5
- 'authz_role_permission',
6
- 'authz_user_role',
1
+ import { DEFAULT_TABLE_NAMES, PermissionEntity, RoleEntity, RolePermissionEntity, UserRoleEntity, } from './entities.js';
2
+ /** Entity class → the table name to fall back to when the entity is not registered. */
3
+ const AUTHZ_ENTITY_TABLE_DEFAULTS = [
4
+ [RoleEntity, DEFAULT_TABLE_NAMES.roles],
5
+ [PermissionEntity, DEFAULT_TABLE_NAMES.permissions],
6
+ [RolePermissionEntity, DEFAULT_TABLE_NAMES.rolePermission],
7
+ [UserRoleEntity, DEFAULT_TABLE_NAMES.userRole],
7
8
  ];
9
+ /**
10
+ * The four authz table names — used to filter the schema diff down to our tables. Read off
11
+ * the live metadata so a host that relocated the tables (see `createAuthzEntitySchemas`)
12
+ * still gets them created.
13
+ */
14
+ function authzTables(em) {
15
+ const metadata = em.getMetadata();
16
+ return AUTHZ_ENTITY_TABLE_DEFAULTS.map(([entity, fallback]) => metadata.find(entity.name)?.tableName ?? fallback);
17
+ }
8
18
  /** Resolve an {@link EntityManager} from a {@link MikroORM} or an EM. */
9
19
  function toEm(ormOrEm) {
10
20
  return isOrm(ormOrEm) ? ormOrEm.em : ormOrEm;
@@ -25,11 +35,12 @@ function generatorFor(em) {
25
35
  }
26
36
  /** Statements (split, trimmed) from the non-destructive schema diff that touch our tables. */
27
37
  async function authzStatements(em) {
38
+ const tables = authzTables(em);
28
39
  const sql = await generatorFor(em).getUpdateSchemaSQL({ safe: true, wrap: false });
29
40
  return sql
30
41
  .split(';')
31
42
  .map((s) => s.trim())
32
- .filter((s) => s.length > 0 && AUTHZ_TABLES.some((t) => new RegExp(`\\b${t}\\b`, 'i').test(s)));
43
+ .filter((s) => s.length > 0 && tables.some((t) => new RegExp(`\\b${t}\\b`, 'i').test(s)));
33
44
  }
34
45
  /**
35
46
  * Returns the non-destructive SQL needed to bring only the authz RBAC tables up to date
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA,sFAAsF;AACtF,MAAM,YAAY,GAAG;IACnB,aAAa;IACb,mBAAmB;IACn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AC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAiC;IACpE,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAiC;IACvE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,EAAE,CAAC,CAAC;IAC7C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACpC,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IACtC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,MAAM,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-authz-mikro-orm",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "MikroORM RBAC persistence for @dudousxd/nestjs-authz — roles, permissions, and a Gate seam (zero connection ownership).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,7 +49,7 @@
49
49
  "rxjs": "^7.8.1",
50
50
  "typescript": "^5.4.0",
51
51
  "vitest": "^3.0.0",
52
- "@dudousxd/nestjs-authz": "^0.6.3"
52
+ "@dudousxd/nestjs-authz": "^0.6.4"
53
53
  },
54
54
  "engines": {
55
55
  "node": ">=20"