@anievo-id/rbac-evolution-sequelize 0.0.0-stage → 1.7.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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/index.cjs +188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +81 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +181 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AniEvo-ID
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @anievo-id/rbac-evolution-sequelize
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Sequelize](https://sequelize.org) 6 adapter for [RBAC Evolution](https://github.com/AniEvo-ID/rbac-evolution):
|
|
4
|
+
PostgreSQL, MySQL / MariaDB, SQLite and SQL Server through your Sequelize instance.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm i @anievo-id/rbac-evolution @anievo-id/rbac-evolution-sequelize
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
// migrations/20261119000000-rbac.js (sequelize-cli): creates the five rbac tables
|
|
16
|
+
module.exports = require('@anievo-id/rbac-evolution-sequelize').rbacMigration()
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createRbac } from '@anievo-id/rbac-evolution'
|
|
21
|
+
import { sequelizeAdapter } from '@anievo-id/rbac-evolution-sequelize'
|
|
22
|
+
|
|
23
|
+
export const rbac = createRbac({ adapter: sequelizeAdapter(sequelize) })
|
|
24
|
+
|
|
25
|
+
// Inside a transaction: the rbac writes commit or roll back with yours.
|
|
26
|
+
await sequelize.transaction((t) =>
|
|
27
|
+
createRbac({ adapter: sequelizeAdapter(t), cache: false }).for({ type: 'user', id: 1 }).assignRole('writer'),
|
|
28
|
+
)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- The same tables as the Kysely, TypeORM, Drizzle and Prisma adapters.
|
|
32
|
+
- `rbacMigration()` works with sequelize-cli and Umzug; `rbacExpiryMigration()` adds the `expires_at` columns for
|
|
33
|
+
`sequelizeAdapter(sequelize, { expiry: true })`.
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
|
|
37
|
+
https://creation.anievo.id/rbac-evolution/adapters/sequelize
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var rbacEvolutionKysely = require('@anievo-id/rbac-evolution-kysely');
|
|
4
|
+
var kysely = require('kysely');
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
var DIALECTS = {
|
|
8
|
+
postgres: "postgres",
|
|
9
|
+
mysql: "mysql",
|
|
10
|
+
mariadb: "mysql",
|
|
11
|
+
sqlite: "sqlite",
|
|
12
|
+
mssql: "mssql"
|
|
13
|
+
};
|
|
14
|
+
var isTransaction = (source) => typeof source.commit === "function";
|
|
15
|
+
var sequelizeOf = (source) => {
|
|
16
|
+
const instance = isTransaction(source) ? source.sequelize : source;
|
|
17
|
+
if (typeof instance?.query !== "function") {
|
|
18
|
+
throw new TypeError("rbac-evolution-sequelize: expected a Sequelize instance or transaction");
|
|
19
|
+
}
|
|
20
|
+
return instance;
|
|
21
|
+
};
|
|
22
|
+
var dialectOf = (source) => {
|
|
23
|
+
const name = sequelizeOf(source).getDialect();
|
|
24
|
+
const dialect = DIALECTS[name];
|
|
25
|
+
if (!dialect) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`rbac-evolution-sequelize: the "${name}" dialect is not supported (PostgreSQL, MySQL / MariaDB, SQLite and SQL Server are)`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return dialect;
|
|
31
|
+
};
|
|
32
|
+
var toBindSql = (sql, dialect) => {
|
|
33
|
+
if (dialect === "postgres") return sql;
|
|
34
|
+
if (dialect === "mssql") return sql.replace(/@(\d+)/g, "$$$1");
|
|
35
|
+
let n = 0;
|
|
36
|
+
return sql.replace(/\?/g, () => `$${++n}`);
|
|
37
|
+
};
|
|
38
|
+
var mssqlValue = (value) => value instanceof Date ? value.toISOString().replace("T", " ").replace("Z", "") : value;
|
|
39
|
+
var kindOf = (compiled, dialect) => {
|
|
40
|
+
const node = compiled.query;
|
|
41
|
+
if (node.kind === "SelectQueryNode" || node.returning !== void 0 || node.output !== void 0) return "SELECT";
|
|
42
|
+
if (node.kind === "InsertQueryNode" && dialect === "mysql") return "INSERT";
|
|
43
|
+
if (node.kind === "DeleteQueryNode") return dialect === "mssql" ? "BULKUPDATE" : "BULKDELETE";
|
|
44
|
+
return "RAW";
|
|
45
|
+
};
|
|
46
|
+
var SequelizeConnection = class {
|
|
47
|
+
constructor(sequelize, dialect, joined) {
|
|
48
|
+
this.sequelize = sequelize;
|
|
49
|
+
this.dialect = dialect;
|
|
50
|
+
this.joined = joined;
|
|
51
|
+
this.transaction = joined;
|
|
52
|
+
}
|
|
53
|
+
sequelize;
|
|
54
|
+
dialect;
|
|
55
|
+
joined;
|
|
56
|
+
transaction;
|
|
57
|
+
async executeQuery(compiled) {
|
|
58
|
+
const type = kindOf(compiled, this.dialect);
|
|
59
|
+
let sql = toBindSql(compiled.sql, this.dialect);
|
|
60
|
+
if (type === "SELECT" && this.dialect === "sqlite" && compiled.query.kind !== "SelectQueryNode") sql = `/* rows */ ${sql}`;
|
|
61
|
+
const result = await this.sequelize.query(sql, {
|
|
62
|
+
bind: this.dialect === "mssql" ? compiled.parameters.map(mssqlValue) : [...compiled.parameters],
|
|
63
|
+
type,
|
|
64
|
+
raw: true,
|
|
65
|
+
...this.transaction ? { transaction: this.transaction } : {}
|
|
66
|
+
});
|
|
67
|
+
if (type === "SELECT") return { rows: result };
|
|
68
|
+
if (type === "INSERT") {
|
|
69
|
+
const [insertId, affected] = result;
|
|
70
|
+
return {
|
|
71
|
+
rows: [],
|
|
72
|
+
...typeof insertId === "number" ? { insertId: BigInt(insertId) } : {},
|
|
73
|
+
...typeof affected === "number" ? { numAffectedRows: BigInt(affected) } : {}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if ((type === "BULKDELETE" || type === "BULKUPDATE") && typeof result === "number") {
|
|
77
|
+
return { rows: [], numAffectedRows: BigInt(result) };
|
|
78
|
+
}
|
|
79
|
+
return { rows: [] };
|
|
80
|
+
}
|
|
81
|
+
// eslint-disable-next-line require-yield
|
|
82
|
+
async *streamQuery() {
|
|
83
|
+
throw new Error("rbac-evolution-sequelize: streaming is not supported");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var SequelizeDriver = class {
|
|
87
|
+
constructor(source, dialect) {
|
|
88
|
+
this.source = source;
|
|
89
|
+
this.dialect = dialect;
|
|
90
|
+
}
|
|
91
|
+
source;
|
|
92
|
+
dialect;
|
|
93
|
+
async init() {
|
|
94
|
+
}
|
|
95
|
+
async acquireConnection() {
|
|
96
|
+
const joined = isTransaction(this.source) ? this.source : void 0;
|
|
97
|
+
return new SequelizeConnection(sequelizeOf(this.source), this.dialect, joined);
|
|
98
|
+
}
|
|
99
|
+
async beginTransaction(connection) {
|
|
100
|
+
const c = connection;
|
|
101
|
+
if (!c.joined) c.transaction = await sequelizeOf(this.source).transaction();
|
|
102
|
+
}
|
|
103
|
+
async commitTransaction(connection) {
|
|
104
|
+
const c = connection;
|
|
105
|
+
if (c.joined) return;
|
|
106
|
+
await c.transaction?.commit();
|
|
107
|
+
c.transaction = void 0;
|
|
108
|
+
}
|
|
109
|
+
async rollbackTransaction(connection) {
|
|
110
|
+
const c = connection;
|
|
111
|
+
if (c.joined) return;
|
|
112
|
+
await c.transaction?.rollback();
|
|
113
|
+
c.transaction = void 0;
|
|
114
|
+
}
|
|
115
|
+
async releaseConnection() {
|
|
116
|
+
}
|
|
117
|
+
async destroy() {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var PARTS = {
|
|
121
|
+
postgres: {
|
|
122
|
+
adapter: () => new kysely.PostgresAdapter(),
|
|
123
|
+
compiler: () => new kysely.PostgresQueryCompiler(),
|
|
124
|
+
introspector: (db) => new kysely.PostgresIntrospector(db)
|
|
125
|
+
},
|
|
126
|
+
mysql: {
|
|
127
|
+
adapter: () => new kysely.MysqlAdapter(),
|
|
128
|
+
compiler: () => new kysely.MysqlQueryCompiler(),
|
|
129
|
+
introspector: (db) => new kysely.MysqlIntrospector(db)
|
|
130
|
+
},
|
|
131
|
+
sqlite: {
|
|
132
|
+
adapter: () => new kysely.SqliteAdapter(),
|
|
133
|
+
compiler: () => new kysely.SqliteQueryCompiler(),
|
|
134
|
+
introspector: (db) => new kysely.SqliteIntrospector(db)
|
|
135
|
+
},
|
|
136
|
+
mssql: {
|
|
137
|
+
adapter: () => new kysely.MssqlAdapter(),
|
|
138
|
+
compiler: () => new kysely.MssqlQueryCompiler(),
|
|
139
|
+
introspector: (db) => new kysely.MssqlIntrospector(db)
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
function sequelizeDialect(source) {
|
|
143
|
+
const dialect = dialectOf(source);
|
|
144
|
+
const parts = PARTS[dialect];
|
|
145
|
+
return {
|
|
146
|
+
createAdapter: parts.adapter,
|
|
147
|
+
createDriver: () => new SequelizeDriver(source, dialect),
|
|
148
|
+
createQueryCompiler: parts.compiler,
|
|
149
|
+
createIntrospector: parts.introspector
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/index.ts
|
|
154
|
+
var kyselyOf = (source) => new kysely.Kysely({ dialect: sequelizeDialect(source) });
|
|
155
|
+
function sequelizeAdapter(source, options = {}) {
|
|
156
|
+
return rbacEvolutionKysely.kyselyAdapter(kyselyOf(source), { dialect: dialectOf(source), prefix: options.prefix, expiry: options.expiry });
|
|
157
|
+
}
|
|
158
|
+
var instanceOf = (arg) => {
|
|
159
|
+
const target = "context" in arg ? arg.context : arg;
|
|
160
|
+
return "sequelize" in target && typeof target.sequelize === "object" ? target.sequelize : target;
|
|
161
|
+
};
|
|
162
|
+
function rbacMigration(options = {}) {
|
|
163
|
+
return {
|
|
164
|
+
up: async (arg) => {
|
|
165
|
+
const sequelize = instanceOf(arg);
|
|
166
|
+
await rbacEvolutionKysely.createRbacTables(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) });
|
|
167
|
+
},
|
|
168
|
+
down: (arg) => rbacEvolutionKysely.dropRbacTables(kyselyOf(instanceOf(arg)), options)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function rbacExpiryMigration(options = {}) {
|
|
172
|
+
return {
|
|
173
|
+
up: async (arg) => {
|
|
174
|
+
const sequelize = instanceOf(arg);
|
|
175
|
+
await rbacEvolutionKysely.addRbacExpiryColumns(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) });
|
|
176
|
+
},
|
|
177
|
+
down: (arg) => rbacEvolutionKysely.dropRbacExpiryColumns(kyselyOf(instanceOf(arg)), options)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
exports.dialectOf = dialectOf;
|
|
182
|
+
exports.rbacExpiryMigration = rbacExpiryMigration;
|
|
183
|
+
exports.rbacMigration = rbacMigration;
|
|
184
|
+
exports.sequelizeAdapter = sequelizeAdapter;
|
|
185
|
+
exports.sequelizeDialect = sequelizeDialect;
|
|
186
|
+
exports.toBindSql = toBindSql;
|
|
187
|
+
//# sourceMappingURL=index.cjs.map
|
|
188
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dialect.ts","../src/index.ts"],"names":["PostgresAdapter","PostgresQueryCompiler","PostgresIntrospector","MysqlAdapter","MysqlQueryCompiler","MysqlIntrospector","SqliteAdapter","SqliteQueryCompiler","SqliteIntrospector","MssqlAdapter","MssqlQueryCompiler","MssqlIntrospector","Kysely","kyselyAdapter","createRbacTables","dropRbacTables","addRbacExpiryColumns","dropRbacExpiryColumns"],"mappings":";;;;;;AA2CA,IAAM,QAAA,GAAwC;AAAA,EAC5C,QAAA,EAAU,UAAA;AAAA,EACV,KAAA,EAAO,OAAA;AAAA,EACP,OAAA,EAAS,OAAA;AAAA,EACT,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT,CAAA;AAEA,IAAM,aAAA,GAAgB,CAAC,MAAA,KACrB,OAAQ,OAAgC,MAAA,KAAW,UAAA;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ution-kysely'\nimport {\n type CompiledQuery,\n type DatabaseConnection,\n type DatabaseIntrospector,\n type Dialect,\n type DialectAdapter,\n type Driver,\n type Kysely,\n MssqlAdapter,\n MssqlIntrospector,\n MssqlQueryCompiler,\n MysqlAdapter,\n MysqlIntrospector,\n MysqlQueryCompiler,\n PostgresAdapter,\n PostgresIntrospector,\n PostgresQueryCompiler,\n type QueryCompiler,\n type QueryResult,\n SqliteAdapter,\n SqliteIntrospector,\n SqliteQueryCompiler,\n} from 'kysely'\n\n/** A Sequelize 6 transaction, structurally. */\nexport interface SequelizeTransaction {\n /** Set at runtime by Sequelize 6 (its typings leave it out). */\n readonly sequelize?: SequelizeInstance\n commit(): Promise<void>\n rollback(): Promise<void>\n}\n\n/** The part of a Sequelize 6 instance the adapter uses. */\nexport interface SequelizeInstance {\n getDialect(): string\n // `options` is `{ bind, type, raw, transaction? }`; typed loosely so Sequelize's overloads accept it.\n query(sql: string, options: object): Promise<unknown>\n transaction(options?: object): Promise<SequelizeTransaction>\n}\n\nexport type SequelizeSource = SequelizeInstance | SequelizeTransaction\n\nconst DIALECTS: Record<string, RbacDialect> = {\n postgres: 'postgres',\n mysql: 'mysql',\n mariadb: 'mysql',\n sqlite: 'sqlite',\n mssql: 'mssql',\n}\n\nconst isTransaction = (source: SequelizeSource): source is SequelizeTransaction =>\n typeof (source as SequelizeTransaction).commit === 'function'\n\n/** The Sequelize instance of an instance or a transaction. */\nexport const sequelizeOf = (source: SequelizeSource): SequelizeInstance => {\n const instance = isTransaction(source) ? source.sequelize : source\n if (typeof instance?.query !== 'function') {\n throw new TypeError('rbac-evolution-sequelize: expected a Sequelize instance or transaction')\n }\n return instance\n}\n\n/** The rbac dialect of a Sequelize dialect (`sequelize.getDialect()`). */\nexport const dialectOf = (source: SequelizeSource): RbacDialect => {\n const name = sequelizeOf(source).getDialect()\n const dialect = DIALECTS[name]\n if (!dialect) {\n throw new Error(\n `rbac-evolution-sequelize: the \"${name}\" dialect is not supported (PostgreSQL, MySQL / MariaDB, SQLite and SQL Server are)`,\n )\n }\n return dialect\n}\n\n/**\n * Kysely's placeholders (`$1` on PostgreSQL, `?` on MySQL and SQLite, `@1` on SQL Server) as Sequelize bind\n * parameters (`$1`, `$2`, ...), which Sequelize turns into each driver's own. Compiled queries hold no literals with\n * these characters: every value is a parameter.\n */\nexport const toBindSql = (sql: string, dialect: RbacDialect): string => {\n if (dialect === 'postgres') return sql\n if (dialect === 'mssql') return sql.replace(/@(\\d+)/g, '$$$1')\n let n = 0\n return sql.replace(/\\?/g, () => `$${++n}`)\n}\n\n/**\n * Sequelize binds every SQL Server parameter that isn't a number, boolean or Buffer as NVarChar, which tedious rejects\n * for a Date. A UTC `YYYY-MM-DD HH:mm:ss.sss` string converts to the `datetime2` column whatever the DATEFORMAT, and\n * matches what tedious reads back (`useUTC`, its default and Sequelize's).\n */\nconst mssqlValue = (value: unknown): unknown =>\n value instanceof Date ? value.toISOString().replace('T', ' ').replace('Z', '') : value\n\ntype Kind = 'SELECT' | 'INSERT' | 'BULKDELETE' | 'BULKUPDATE' | 'RAW'\n\n/**\n * The Sequelize query type that gives back what Kysely needs: the rows of a select (or of an INSERT with\n * RETURNING / OUTPUT), the insert id of a MySQL INSERT, the deleted row count of a DELETE.\n */\nconst kindOf = (compiled: CompiledQuery, dialect: RbacDialect): Kind => {\n const node = compiled.query as { kind: string; returning?: unknown; output?: unknown }\n if (node.kind === 'SelectQueryNode' || node.returning !== undefined || node.output !== undefined) return 'SELECT'\n if (node.kind === 'InsertQueryNode' && dialect === 'mysql') return 'INSERT'\n // SQL Server: Sequelize reads a BULKDELETE count from an `AFFECTEDROWS` column its own SQL adds, but a BULKUPDATE\n // count from the driver's row count, which a plain DELETE has too.\n if (node.kind === 'DeleteQueryNode') return dialect === 'mssql' ? 'BULKUPDATE' : 'BULKDELETE'\n return 'RAW'\n}\n\nclass SequelizeConnection implements DatabaseConnection {\n transaction: SequelizeTransaction | undefined\n\n constructor(\n private readonly sequelize: SequelizeInstance,\n private readonly dialect: RbacDialect,\n /** The caller's transaction: the adapter joins it instead of starting one. */\n readonly joined: SequelizeTransaction | undefined,\n ) {\n this.transaction = joined\n }\n\n async executeQuery<R>(compiled: CompiledQuery): Promise<QueryResult<R>> {\n const type = kindOf(compiled, this.dialect)\n let sql = toBindSql(compiled.sql, this.dialect)\n // Sequelize's SQLite driver runs any SQL starting with `insert into` / `update` (after trimming) with sqlite3's\n // `run()`, which drops the rows of RETURNING. A leading comment makes it use `all()`, which returns them.\n if (type === 'SELECT' && this.dialect === 'sqlite' && compiled.query.kind !== 'SelectQueryNode') sql = `/* rows */ ${sql}`\n const result = await this.sequelize.query(sql, {\n bind: this.dialect === 'mssql' ? compiled.parameters.map(mssqlValue) : [...compiled.parameters],\n type,\n raw: true,\n ...(this.transaction ? { transaction: this.transaction } : {}),\n })\n if (type === 'SELECT') return { rows: result as R[] }\n if (type === 'INSERT') {\n const [insertId, affected] = result as [unknown, unknown]\n return {\n rows: [],\n ...(typeof insertId === 'number' ? { insertId: BigInt(insertId) } : {}),\n ...(typeof affected === 'number' ? { numAffectedRows: BigInt(affected) } : {}),\n }\n }\n if ((type === 'BULKDELETE' || type === 'BULKUPDATE') && typeof result === 'number') {\n return { rows: [], numAffectedRows: BigInt(result) }\n }\n return { rows: [] }\n }\n\n // eslint-disable-next-line require-yield\n async *streamQuery(): AsyncIterableIterator<QueryResult<never>> {\n throw new Error('rbac-evolution-sequelize: streaming is not supported')\n }\n}\n\nclass SequelizeDriver implements Driver {\n constructor(\n private readonly source: SequelizeSource,\n private readonly dialect: RbacDialect,\n ) {}\n\n async init(): Promise<void> {}\n\n async acquireConnection(): Promise<DatabaseConnection> {\n const joined = isTransaction(this.source) ? this.source : undefined\n return new SequelizeConnection(sequelizeOf(this.source), this.dialect, joined)\n }\n\n async beginTransaction(connection: DatabaseConnection): Promise<void> {\n const c = connection as SequelizeConnection\n if (!c.joined) c.transaction = await sequelizeOf(this.source).transaction()\n }\n\n async commitTransaction(connection: DatabaseConnection): Promise<void> {\n const c = connection as SequelizeConnection\n if (c.joined) return\n await c.transaction?.commit()\n c.transaction = undefined\n }\n\n async rollbackTransaction(connection: DatabaseConnection): Promise<void> {\n const c = connection as SequelizeConnection\n if (c.joined) return\n await c.transaction?.rollback()\n c.transaction = undefined\n }\n\n async releaseConnection(): Promise<void> {}\n\n async destroy(): Promise<void> {}\n}\n\nconst PARTS: Record<\n RbacDialect,\n {\n adapter: () => DialectAdapter\n compiler: () => QueryCompiler\n introspector: (db: Kysely<any>) => DatabaseIntrospector // eslint-disable-line @typescript-eslint/no-explicit-any\n }\n> = {\n postgres: {\n adapter: () => new PostgresAdapter(),\n compiler: () => new PostgresQueryCompiler(),\n introspector: (db) => new PostgresIntrospector(db),\n },\n mysql: {\n adapter: () => new MysqlAdapter(),\n compiler: () => new MysqlQueryCompiler(),\n introspector: (db) => new MysqlIntrospector(db),\n },\n sqlite: {\n adapter: () => new SqliteAdapter(),\n compiler: () => new SqliteQueryCompiler(),\n introspector: (db) => new SqliteIntrospector(db),\n },\n mssql: {\n adapter: () => new MssqlAdapter(),\n compiler: () => new MssqlQueryCompiler(),\n introspector: (db) => new MssqlIntrospector(db),\n },\n}\n\n/**\n * A Kysely dialect that runs every query through `sequelize.query()`: on the pool, or in the caller's transaction\n * when given one (`sequelizeAdapter(t)` inside `sequelize.transaction(async (t) => ...)`).\n */\nexport function sequelizeDialect(source: SequelizeSource): Dialect {\n const dialect = dialectOf(source)\n const parts = PARTS[dialect]\n return {\n createAdapter: parts.adapter,\n createDriver: () => new SequelizeDriver(source, dialect),\n createQueryCompiler: parts.compiler,\n createIntrospector: parts.introspector,\n }\n}\n","import {\n type KyselyRbacAdapter,\n type RbacMigrationOptions,\n type RbacTableOptions,\n addRbacExpiryColumns,\n createRbacTables,\n dropRbacExpiryColumns,\n dropRbacTables,\n kyselyAdapter,\n} from '@anievo-id/rbac-evolution-kysely'\nimport { Kysely } from 'kysely'\nimport { type SequelizeInstance, type SequelizeSource, dialectOf, sequelizeDialect } from './dialect'\n\nexport {\n dialectOf,\n sequelizeDialect,\n toBindSql,\n type SequelizeInstance,\n type SequelizeSource,\n type SequelizeTransaction,\n} from './dialect'\nexport type { RbacTableNames, RbacTableOptions } from '@anievo-id/rbac-evolution-kysely'\n\nexport interface SequelizeAdapterOptions extends RbacTableOptions {\n /**\n * Store an expiry per role assignment and direct permission (`assignRole(role, { expiresAt })`). Needs the\n * `expires_at` column (`rbacMigration({ expiry: true })`, or `rbacExpiryMigration()` for existing tables).\n * Default: `false`.\n */\n expiry?: boolean | undefined\n}\n\n/** The adapter type: the Kysely adapter, running its queries through `sequelize.query()`. */\nexport type SequelizeRbacAdapter = KyselyRbacAdapter\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst kyselyOf = (source: SequelizeSource): Kysely<any> => new Kysely({ dialect: sequelizeDialect(source) })\n\n/**\n * Creates a Sequelize-backed `RbacAdapter` for PostgreSQL, MySQL / MariaDB, SQLite and SQL Server.\n *\n * ```ts\n * const rbac = createRbac({ adapter: sequelizeAdapter(sequelize) })\n * // inside a transaction: the adapter runs in it\n * await sequelize.transaction((t) => createRbac({ adapter: sequelizeAdapter(t) }).for(user).assignRole('writer'))\n * ```\n */\nexport function sequelizeAdapter(source: SequelizeSource, options: SequelizeAdapterOptions = {}): SequelizeRbacAdapter {\n return kyselyAdapter(kyselyOf(source), { dialect: dialectOf(source), prefix: options.prefix, expiry: options.expiry })\n}\n\n/**\n * What a migration gets: sequelize-cli passes the QueryInterface first, Umzug passes `{ context }` (set `context` to\n * the QueryInterface or the Sequelize instance).\n */\ntype MigrationArgument = { sequelize: SequelizeInstance } | SequelizeInstance | { context: { sequelize: SequelizeInstance } | SequelizeInstance }\n\nconst instanceOf = (arg: MigrationArgument): SequelizeInstance => {\n const target = 'context' in arg ? arg.context : arg\n return 'sequelize' in target && typeof (target as { sequelize?: unknown }).sequelize === 'object'\n ? (target as { sequelize: SequelizeInstance }).sequelize\n : (target as SequelizeInstance)\n}\n\n/** A migration for sequelize-cli (`up(queryInterface)`) and Umzug (`up({ context })`). */\nexport interface RbacSequelizeMigration {\n up(arg: MigrationArgument): Promise<void>\n down(arg: MigrationArgument): Promise<void>\n}\n\n/**\n * A migration that creates the five rbac tables (and their indexes), like `createRbacTables` of the Kysely package.\n *\n * ```js\n * // migrations/20261119000000-rbac.js (sequelize-cli)\n * module.exports = require('@anievo-id/rbac-evolution-sequelize').rbacMigration()\n * ```\n */\nexport function rbacMigration(options: RbacTableOptions & Pick<RbacMigrationOptions, 'expiry'> = {}): RbacSequelizeMigration {\n return {\n up: async (arg) => {\n const sequelize = instanceOf(arg)\n await createRbacTables(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) })\n },\n down: (arg) => dropRbacTables(kyselyOf(instanceOf(arg)), options),\n }\n}\n\n/** A migration that adds the `expires_at` columns to existing tables, for `{ expiry: true }`. */\nexport function rbacExpiryMigration(options: RbacTableOptions = {}): RbacSequelizeMigration {\n return {\n up: async (arg) => {\n const sequelize = instanceOf(arg)\n await addRbacExpiryColumns(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) })\n },\n down: (arg) => dropRbacExpiryColumns(kyselyOf(instanceOf(arg)), options),\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { RbacDialect, RbacTableOptions, KyselyRbacAdapter, RbacMigrationOptions } from '@anievo-id/rbac-evolution-kysely';
|
|
2
|
+
export { RbacTableNames, RbacTableOptions } from '@anievo-id/rbac-evolution-kysely';
|
|
3
|
+
import { Dialect } from 'kysely';
|
|
4
|
+
|
|
5
|
+
/** A Sequelize 6 transaction, structurally. */
|
|
6
|
+
interface SequelizeTransaction {
|
|
7
|
+
/** Set at runtime by Sequelize 6 (its typings leave it out). */
|
|
8
|
+
readonly sequelize?: SequelizeInstance;
|
|
9
|
+
commit(): Promise<void>;
|
|
10
|
+
rollback(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** The part of a Sequelize 6 instance the adapter uses. */
|
|
13
|
+
interface SequelizeInstance {
|
|
14
|
+
getDialect(): string;
|
|
15
|
+
query(sql: string, options: object): Promise<unknown>;
|
|
16
|
+
transaction(options?: object): Promise<SequelizeTransaction>;
|
|
17
|
+
}
|
|
18
|
+
type SequelizeSource = SequelizeInstance | SequelizeTransaction;
|
|
19
|
+
/** The rbac dialect of a Sequelize dialect (`sequelize.getDialect()`). */
|
|
20
|
+
declare const dialectOf: (source: SequelizeSource) => RbacDialect;
|
|
21
|
+
/**
|
|
22
|
+
* Kysely's placeholders (`$1` on PostgreSQL, `?` on MySQL and SQLite, `@1` on SQL Server) as Sequelize bind
|
|
23
|
+
* parameters (`$1`, `$2`, ...), which Sequelize turns into each driver's own. Compiled queries hold no literals with
|
|
24
|
+
* these characters: every value is a parameter.
|
|
25
|
+
*/
|
|
26
|
+
declare const toBindSql: (sql: string, dialect: RbacDialect) => string;
|
|
27
|
+
/**
|
|
28
|
+
* A Kysely dialect that runs every query through `sequelize.query()`: on the pool, or in the caller's transaction
|
|
29
|
+
* when given one (`sequelizeAdapter(t)` inside `sequelize.transaction(async (t) => ...)`).
|
|
30
|
+
*/
|
|
31
|
+
declare function sequelizeDialect(source: SequelizeSource): Dialect;
|
|
32
|
+
|
|
33
|
+
interface SequelizeAdapterOptions extends RbacTableOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Store an expiry per role assignment and direct permission (`assignRole(role, { expiresAt })`). Needs the
|
|
36
|
+
* `expires_at` column (`rbacMigration({ expiry: true })`, or `rbacExpiryMigration()` for existing tables).
|
|
37
|
+
* Default: `false`.
|
|
38
|
+
*/
|
|
39
|
+
expiry?: boolean | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The adapter type: the Kysely adapter, running its queries through `sequelize.query()`. */
|
|
42
|
+
type SequelizeRbacAdapter = KyselyRbacAdapter;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Sequelize-backed `RbacAdapter` for PostgreSQL, MySQL / MariaDB, SQLite and SQL Server.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const rbac = createRbac({ adapter: sequelizeAdapter(sequelize) })
|
|
48
|
+
* // inside a transaction: the adapter runs in it
|
|
49
|
+
* await sequelize.transaction((t) => createRbac({ adapter: sequelizeAdapter(t) }).for(user).assignRole('writer'))
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function sequelizeAdapter(source: SequelizeSource, options?: SequelizeAdapterOptions): SequelizeRbacAdapter;
|
|
53
|
+
/**
|
|
54
|
+
* What a migration gets: sequelize-cli passes the QueryInterface first, Umzug passes `{ context }` (set `context` to
|
|
55
|
+
* the QueryInterface or the Sequelize instance).
|
|
56
|
+
*/
|
|
57
|
+
type MigrationArgument = {
|
|
58
|
+
sequelize: SequelizeInstance;
|
|
59
|
+
} | SequelizeInstance | {
|
|
60
|
+
context: {
|
|
61
|
+
sequelize: SequelizeInstance;
|
|
62
|
+
} | SequelizeInstance;
|
|
63
|
+
};
|
|
64
|
+
/** A migration for sequelize-cli (`up(queryInterface)`) and Umzug (`up({ context })`). */
|
|
65
|
+
interface RbacSequelizeMigration {
|
|
66
|
+
up(arg: MigrationArgument): Promise<void>;
|
|
67
|
+
down(arg: MigrationArgument): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A migration that creates the five rbac tables (and their indexes), like `createRbacTables` of the Kysely package.
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* // migrations/20261119000000-rbac.js (sequelize-cli)
|
|
74
|
+
* module.exports = require('@anievo-id/rbac-evolution-sequelize').rbacMigration()
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function rbacMigration(options?: RbacTableOptions & Pick<RbacMigrationOptions, 'expiry'>): RbacSequelizeMigration;
|
|
78
|
+
/** A migration that adds the `expires_at` columns to existing tables, for `{ expiry: true }`. */
|
|
79
|
+
declare function rbacExpiryMigration(options?: RbacTableOptions): RbacSequelizeMigration;
|
|
80
|
+
|
|
81
|
+
export { type RbacSequelizeMigration, type SequelizeAdapterOptions, type SequelizeInstance, type SequelizeRbacAdapter, type SequelizeSource, type SequelizeTransaction, dialectOf, rbacExpiryMigration, rbacMigration, sequelizeAdapter, sequelizeDialect, toBindSql };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { RbacDialect, RbacTableOptions, KyselyRbacAdapter, RbacMigrationOptions } from '@anievo-id/rbac-evolution-kysely';
|
|
2
|
+
export { RbacTableNames, RbacTableOptions } from '@anievo-id/rbac-evolution-kysely';
|
|
3
|
+
import { Dialect } from 'kysely';
|
|
4
|
+
|
|
5
|
+
/** A Sequelize 6 transaction, structurally. */
|
|
6
|
+
interface SequelizeTransaction {
|
|
7
|
+
/** Set at runtime by Sequelize 6 (its typings leave it out). */
|
|
8
|
+
readonly sequelize?: SequelizeInstance;
|
|
9
|
+
commit(): Promise<void>;
|
|
10
|
+
rollback(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** The part of a Sequelize 6 instance the adapter uses. */
|
|
13
|
+
interface SequelizeInstance {
|
|
14
|
+
getDialect(): string;
|
|
15
|
+
query(sql: string, options: object): Promise<unknown>;
|
|
16
|
+
transaction(options?: object): Promise<SequelizeTransaction>;
|
|
17
|
+
}
|
|
18
|
+
type SequelizeSource = SequelizeInstance | SequelizeTransaction;
|
|
19
|
+
/** The rbac dialect of a Sequelize dialect (`sequelize.getDialect()`). */
|
|
20
|
+
declare const dialectOf: (source: SequelizeSource) => RbacDialect;
|
|
21
|
+
/**
|
|
22
|
+
* Kysely's placeholders (`$1` on PostgreSQL, `?` on MySQL and SQLite, `@1` on SQL Server) as Sequelize bind
|
|
23
|
+
* parameters (`$1`, `$2`, ...), which Sequelize turns into each driver's own. Compiled queries hold no literals with
|
|
24
|
+
* these characters: every value is a parameter.
|
|
25
|
+
*/
|
|
26
|
+
declare const toBindSql: (sql: string, dialect: RbacDialect) => string;
|
|
27
|
+
/**
|
|
28
|
+
* A Kysely dialect that runs every query through `sequelize.query()`: on the pool, or in the caller's transaction
|
|
29
|
+
* when given one (`sequelizeAdapter(t)` inside `sequelize.transaction(async (t) => ...)`).
|
|
30
|
+
*/
|
|
31
|
+
declare function sequelizeDialect(source: SequelizeSource): Dialect;
|
|
32
|
+
|
|
33
|
+
interface SequelizeAdapterOptions extends RbacTableOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Store an expiry per role assignment and direct permission (`assignRole(role, { expiresAt })`). Needs the
|
|
36
|
+
* `expires_at` column (`rbacMigration({ expiry: true })`, or `rbacExpiryMigration()` for existing tables).
|
|
37
|
+
* Default: `false`.
|
|
38
|
+
*/
|
|
39
|
+
expiry?: boolean | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The adapter type: the Kysely adapter, running its queries through `sequelize.query()`. */
|
|
42
|
+
type SequelizeRbacAdapter = KyselyRbacAdapter;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Sequelize-backed `RbacAdapter` for PostgreSQL, MySQL / MariaDB, SQLite and SQL Server.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const rbac = createRbac({ adapter: sequelizeAdapter(sequelize) })
|
|
48
|
+
* // inside a transaction: the adapter runs in it
|
|
49
|
+
* await sequelize.transaction((t) => createRbac({ adapter: sequelizeAdapter(t) }).for(user).assignRole('writer'))
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function sequelizeAdapter(source: SequelizeSource, options?: SequelizeAdapterOptions): SequelizeRbacAdapter;
|
|
53
|
+
/**
|
|
54
|
+
* What a migration gets: sequelize-cli passes the QueryInterface first, Umzug passes `{ context }` (set `context` to
|
|
55
|
+
* the QueryInterface or the Sequelize instance).
|
|
56
|
+
*/
|
|
57
|
+
type MigrationArgument = {
|
|
58
|
+
sequelize: SequelizeInstance;
|
|
59
|
+
} | SequelizeInstance | {
|
|
60
|
+
context: {
|
|
61
|
+
sequelize: SequelizeInstance;
|
|
62
|
+
} | SequelizeInstance;
|
|
63
|
+
};
|
|
64
|
+
/** A migration for sequelize-cli (`up(queryInterface)`) and Umzug (`up({ context })`). */
|
|
65
|
+
interface RbacSequelizeMigration {
|
|
66
|
+
up(arg: MigrationArgument): Promise<void>;
|
|
67
|
+
down(arg: MigrationArgument): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A migration that creates the five rbac tables (and their indexes), like `createRbacTables` of the Kysely package.
|
|
71
|
+
*
|
|
72
|
+
* ```js
|
|
73
|
+
* // migrations/20261119000000-rbac.js (sequelize-cli)
|
|
74
|
+
* module.exports = require('@anievo-id/rbac-evolution-sequelize').rbacMigration()
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function rbacMigration(options?: RbacTableOptions & Pick<RbacMigrationOptions, 'expiry'>): RbacSequelizeMigration;
|
|
78
|
+
/** A migration that adds the `expires_at` columns to existing tables, for `{ expiry: true }`. */
|
|
79
|
+
declare function rbacExpiryMigration(options?: RbacTableOptions): RbacSequelizeMigration;
|
|
80
|
+
|
|
81
|
+
export { type RbacSequelizeMigration, type SequelizeAdapterOptions, type SequelizeInstance, type SequelizeRbacAdapter, type SequelizeSource, type SequelizeTransaction, dialectOf, rbacExpiryMigration, rbacMigration, sequelizeAdapter, sequelizeDialect, toBindSql };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { kyselyAdapter, dropRbacTables, createRbacTables, dropRbacExpiryColumns, addRbacExpiryColumns } from '@anievo-id/rbac-evolution-kysely';
|
|
2
|
+
import { MssqlIntrospector, MssqlQueryCompiler, MssqlAdapter, SqliteIntrospector, SqliteQueryCompiler, SqliteAdapter, MysqlIntrospector, MysqlQueryCompiler, MysqlAdapter, PostgresIntrospector, PostgresQueryCompiler, PostgresAdapter, Kysely } from 'kysely';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
var DIALECTS = {
|
|
6
|
+
postgres: "postgres",
|
|
7
|
+
mysql: "mysql",
|
|
8
|
+
mariadb: "mysql",
|
|
9
|
+
sqlite: "sqlite",
|
|
10
|
+
mssql: "mssql"
|
|
11
|
+
};
|
|
12
|
+
var isTransaction = (source) => typeof source.commit === "function";
|
|
13
|
+
var sequelizeOf = (source) => {
|
|
14
|
+
const instance = isTransaction(source) ? source.sequelize : source;
|
|
15
|
+
if (typeof instance?.query !== "function") {
|
|
16
|
+
throw new TypeError("rbac-evolution-sequelize: expected a Sequelize instance or transaction");
|
|
17
|
+
}
|
|
18
|
+
return instance;
|
|
19
|
+
};
|
|
20
|
+
var dialectOf = (source) => {
|
|
21
|
+
const name = sequelizeOf(source).getDialect();
|
|
22
|
+
const dialect = DIALECTS[name];
|
|
23
|
+
if (!dialect) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`rbac-evolution-sequelize: the "${name}" dialect is not supported (PostgreSQL, MySQL / MariaDB, SQLite and SQL Server are)`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return dialect;
|
|
29
|
+
};
|
|
30
|
+
var toBindSql = (sql, dialect) => {
|
|
31
|
+
if (dialect === "postgres") return sql;
|
|
32
|
+
if (dialect === "mssql") return sql.replace(/@(\d+)/g, "$$$1");
|
|
33
|
+
let n = 0;
|
|
34
|
+
return sql.replace(/\?/g, () => `$${++n}`);
|
|
35
|
+
};
|
|
36
|
+
var mssqlValue = (value) => value instanceof Date ? value.toISOString().replace("T", " ").replace("Z", "") : value;
|
|
37
|
+
var kindOf = (compiled, dialect) => {
|
|
38
|
+
const node = compiled.query;
|
|
39
|
+
if (node.kind === "SelectQueryNode" || node.returning !== void 0 || node.output !== void 0) return "SELECT";
|
|
40
|
+
if (node.kind === "InsertQueryNode" && dialect === "mysql") return "INSERT";
|
|
41
|
+
if (node.kind === "DeleteQueryNode") return dialect === "mssql" ? "BULKUPDATE" : "BULKDELETE";
|
|
42
|
+
return "RAW";
|
|
43
|
+
};
|
|
44
|
+
var SequelizeConnection = class {
|
|
45
|
+
constructor(sequelize, dialect, joined) {
|
|
46
|
+
this.sequelize = sequelize;
|
|
47
|
+
this.dialect = dialect;
|
|
48
|
+
this.joined = joined;
|
|
49
|
+
this.transaction = joined;
|
|
50
|
+
}
|
|
51
|
+
sequelize;
|
|
52
|
+
dialect;
|
|
53
|
+
joined;
|
|
54
|
+
transaction;
|
|
55
|
+
async executeQuery(compiled) {
|
|
56
|
+
const type = kindOf(compiled, this.dialect);
|
|
57
|
+
let sql = toBindSql(compiled.sql, this.dialect);
|
|
58
|
+
if (type === "SELECT" && this.dialect === "sqlite" && compiled.query.kind !== "SelectQueryNode") sql = `/* rows */ ${sql}`;
|
|
59
|
+
const result = await this.sequelize.query(sql, {
|
|
60
|
+
bind: this.dialect === "mssql" ? compiled.parameters.map(mssqlValue) : [...compiled.parameters],
|
|
61
|
+
type,
|
|
62
|
+
raw: true,
|
|
63
|
+
...this.transaction ? { transaction: this.transaction } : {}
|
|
64
|
+
});
|
|
65
|
+
if (type === "SELECT") return { rows: result };
|
|
66
|
+
if (type === "INSERT") {
|
|
67
|
+
const [insertId, affected] = result;
|
|
68
|
+
return {
|
|
69
|
+
rows: [],
|
|
70
|
+
...typeof insertId === "number" ? { insertId: BigInt(insertId) } : {},
|
|
71
|
+
...typeof affected === "number" ? { numAffectedRows: BigInt(affected) } : {}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if ((type === "BULKDELETE" || type === "BULKUPDATE") && typeof result === "number") {
|
|
75
|
+
return { rows: [], numAffectedRows: BigInt(result) };
|
|
76
|
+
}
|
|
77
|
+
return { rows: [] };
|
|
78
|
+
}
|
|
79
|
+
// eslint-disable-next-line require-yield
|
|
80
|
+
async *streamQuery() {
|
|
81
|
+
throw new Error("rbac-evolution-sequelize: streaming is not supported");
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var SequelizeDriver = class {
|
|
85
|
+
constructor(source, dialect) {
|
|
86
|
+
this.source = source;
|
|
87
|
+
this.dialect = dialect;
|
|
88
|
+
}
|
|
89
|
+
source;
|
|
90
|
+
dialect;
|
|
91
|
+
async init() {
|
|
92
|
+
}
|
|
93
|
+
async acquireConnection() {
|
|
94
|
+
const joined = isTransaction(this.source) ? this.source : void 0;
|
|
95
|
+
return new SequelizeConnection(sequelizeOf(this.source), this.dialect, joined);
|
|
96
|
+
}
|
|
97
|
+
async beginTransaction(connection) {
|
|
98
|
+
const c = connection;
|
|
99
|
+
if (!c.joined) c.transaction = await sequelizeOf(this.source).transaction();
|
|
100
|
+
}
|
|
101
|
+
async commitTransaction(connection) {
|
|
102
|
+
const c = connection;
|
|
103
|
+
if (c.joined) return;
|
|
104
|
+
await c.transaction?.commit();
|
|
105
|
+
c.transaction = void 0;
|
|
106
|
+
}
|
|
107
|
+
async rollbackTransaction(connection) {
|
|
108
|
+
const c = connection;
|
|
109
|
+
if (c.joined) return;
|
|
110
|
+
await c.transaction?.rollback();
|
|
111
|
+
c.transaction = void 0;
|
|
112
|
+
}
|
|
113
|
+
async releaseConnection() {
|
|
114
|
+
}
|
|
115
|
+
async destroy() {
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var PARTS = {
|
|
119
|
+
postgres: {
|
|
120
|
+
adapter: () => new PostgresAdapter(),
|
|
121
|
+
compiler: () => new PostgresQueryCompiler(),
|
|
122
|
+
introspector: (db) => new PostgresIntrospector(db)
|
|
123
|
+
},
|
|
124
|
+
mysql: {
|
|
125
|
+
adapter: () => new MysqlAdapter(),
|
|
126
|
+
compiler: () => new MysqlQueryCompiler(),
|
|
127
|
+
introspector: (db) => new MysqlIntrospector(db)
|
|
128
|
+
},
|
|
129
|
+
sqlite: {
|
|
130
|
+
adapter: () => new SqliteAdapter(),
|
|
131
|
+
compiler: () => new SqliteQueryCompiler(),
|
|
132
|
+
introspector: (db) => new SqliteIntrospector(db)
|
|
133
|
+
},
|
|
134
|
+
mssql: {
|
|
135
|
+
adapter: () => new MssqlAdapter(),
|
|
136
|
+
compiler: () => new MssqlQueryCompiler(),
|
|
137
|
+
introspector: (db) => new MssqlIntrospector(db)
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function sequelizeDialect(source) {
|
|
141
|
+
const dialect = dialectOf(source);
|
|
142
|
+
const parts = PARTS[dialect];
|
|
143
|
+
return {
|
|
144
|
+
createAdapter: parts.adapter,
|
|
145
|
+
createDriver: () => new SequelizeDriver(source, dialect),
|
|
146
|
+
createQueryCompiler: parts.compiler,
|
|
147
|
+
createIntrospector: parts.introspector
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/index.ts
|
|
152
|
+
var kyselyOf = (source) => new Kysely({ dialect: sequelizeDialect(source) });
|
|
153
|
+
function sequelizeAdapter(source, options = {}) {
|
|
154
|
+
return kyselyAdapter(kyselyOf(source), { dialect: dialectOf(source), prefix: options.prefix, expiry: options.expiry });
|
|
155
|
+
}
|
|
156
|
+
var instanceOf = (arg) => {
|
|
157
|
+
const target = "context" in arg ? arg.context : arg;
|
|
158
|
+
return "sequelize" in target && typeof target.sequelize === "object" ? target.sequelize : target;
|
|
159
|
+
};
|
|
160
|
+
function rbacMigration(options = {}) {
|
|
161
|
+
return {
|
|
162
|
+
up: async (arg) => {
|
|
163
|
+
const sequelize = instanceOf(arg);
|
|
164
|
+
await createRbacTables(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) });
|
|
165
|
+
},
|
|
166
|
+
down: (arg) => dropRbacTables(kyselyOf(instanceOf(arg)), options)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function rbacExpiryMigration(options = {}) {
|
|
170
|
+
return {
|
|
171
|
+
up: async (arg) => {
|
|
172
|
+
const sequelize = instanceOf(arg);
|
|
173
|
+
await addRbacExpiryColumns(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) });
|
|
174
|
+
},
|
|
175
|
+
down: (arg) => dropRbacExpiryColumns(kyselyOf(instanceOf(arg)), options)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { dialectOf, rbacExpiryMigration, rbacMigration, sequelizeAdapter, sequelizeDialect, toBindSql };
|
|
180
|
+
//# sourceMappingURL=index.js.map
|
|
181
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dialect.ts","../src/index.ts"],"names":[],"mappings":";;;;AA2CA,IAAM,QAAA,GAAwC;AAAA,EAC5C,QAAA,EAAU,UAAA;AAAA,EACV,KAAA,EAAO,OAAA;AAAA,EACP,OAAA,EAAS,OAAA;AAAA,EACT,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT,CAAA;AAEA,IAAM,aAAA,GAAgB,CAAC,MAAA,KACrB,OAAQ,OAAgC,MAAA,KAAW,UAAA;AAG9C,IAAM,WAAA,GAAc,CAAC,MAAA,KAA+C;AACzE,EAAA,MAAM,QAAA,GAAW,aAAA,CAAc,MAAM,CAAA,GAAI,OAAO,SAAA,GAAY,MAAA;AAC5D,EAAA,IAAI,OAAO,QAAA,EAAU,KAAA,KAAU,UAAA,EAAY;AACzC,IAAA,MAAM,IAAI,UAAU,wEAAwE,CAAA;AAAA,EAC9F;AACA,EAAA,OAAO,QAAA;AACT,CAAA;AAGO,IAAM,SAAA,GAAY,CAAC,MAAA,KAAyC;AACjE,EAAA,MAAM,IAAA,GAAO,WAAA,CAAY,MAAM,CAAA,CAAE,UAAA,EAAW;AAC5C,EAAA,MAAM,OAAA,GAAU,SAAS,IAAI,CAAA;AAC7B,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,kCAAkC,IAAI,CAAA,mFAAA;AAAA,KACxC;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAOO,IAAM,SAAA,GAAY,CAAC,GAAA,EAAa,OAAA,KAAiC;AACtE,EAAA,IAAI,OAAA,KAAY,YAAY,OAAO,GAAA;AACnC,EAAA,IAAI,YAAY,OAAA,EAAS,OAAO,GAAA,CAAI,OAAA,CAA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AAC1F,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,OAAO,GAAA,KAAQ;AACjB,MAAA,MAAM,SAAA,GAAY,WAAW,GAAG,CAAA;AAChC,MAAA,MAAM,oBAAA,CAAqB,QAAA,CAAS,SAAS,CAAA,EAAG,EAAE,GAAG,OAAA,EAAS,OAAA,EAAS,SAAA,CAAU,SAAS,CAAA,EAAG,CAAA;AAAA,IAC/F,CAAA;AAAA,IACA,IAAA,EAAM,CAAC,GAAA,KAAQ,qBAAA,CAAsB,SAAS,UAAA,CAAW,GAAG,CAAC,CAAA,EAAG,OAAO;AAAA,GACzE;AACF","file":"index.js","sourcesContent":["import type { RbacDialect } from '@anievo-id/rbac-evolution-kysely'\nimport {\n type CompiledQuery,\n type DatabaseConnection,\n type DatabaseIntrospector,\n type Dialect,\n type DialectAdapter,\n type Driver,\n type Kysely,\n MssqlAdapter,\n MssqlIntrospector,\n MssqlQueryCompiler,\n MysqlAdapter,\n MysqlIntrospector,\n MysqlQueryCompiler,\n PostgresAdapter,\n PostgresIntrospector,\n PostgresQueryCompiler,\n type QueryCompiler,\n type QueryResult,\n SqliteAdapter,\n SqliteIntrospector,\n SqliteQueryCompiler,\n} from 'kysely'\n\n/** A Sequelize 6 transaction, structurally. */\nexport interface SequelizeTransaction {\n /** Set at runtime by Sequelize 6 (its typings leave it out). */\n readonly sequelize?: SequelizeInstance\n commit(): Promise<void>\n rollback(): Promise<void>\n}\n\n/** The part of a Sequelize 6 instance the adapter uses. */\nexport interface SequelizeInstance {\n getDialect(): string\n // `options` is `{ bind, type, raw, transaction? }`; typed loosely so Sequelize's overloads accept it.\n query(sql: string, options: object): Promise<unknown>\n transaction(options?: object): Promise<SequelizeTransaction>\n}\n\nexport type SequelizeSource = SequelizeInstance | SequelizeTransaction\n\nconst DIALECTS: Record<string, RbacDialect> = {\n postgres: 'postgres',\n mysql: 'mysql',\n mariadb: 'mysql',\n sqlite: 'sqlite',\n mssql: 'mssql',\n}\n\nconst isTransaction = (source: SequelizeSource): source is SequelizeTransaction =>\n typeof (source as SequelizeTransaction).commit === 'function'\n\n/** The Sequelize instance of an instance or a transaction. */\nexport const sequelizeOf = (source: SequelizeSource): SequelizeInstance => {\n const instance = isTransaction(source) ? source.sequelize : source\n if (typeof instance?.query !== 'function') {\n throw new TypeError('rbac-evolution-sequelize: expected a Sequelize instance or transaction')\n }\n return instance\n}\n\n/** The rbac dialect of a Sequelize dialect (`sequelize.getDialect()`). */\nexport const dialectOf = (source: SequelizeSource): RbacDialect => {\n const name = sequelizeOf(source).getDialect()\n const dialect = DIALECTS[name]\n if (!dialect) {\n throw new Error(\n `rbac-evolution-sequelize: the \"${name}\" dialect is not supported (PostgreSQL, MySQL / MariaDB, SQLite and SQL Server are)`,\n )\n }\n return dialect\n}\n\n/**\n * Kysely's placeholders (`$1` on PostgreSQL, `?` on MySQL and SQLite, `@1` on SQL Server) as Sequelize bind\n * parameters (`$1`, `$2`, ...), which Sequelize turns into each driver's own. Compiled queries hold no literals with\n * these characters: every value is a parameter.\n */\nexport const toBindSql = (sql: string, dialect: RbacDialect): string => {\n if (dialect === 'postgres') return sql\n if (dialect === 'mssql') return sql.replace(/@(\\d+)/g, '$$$1')\n let n = 0\n return sql.replace(/\\?/g, () => `$${++n}`)\n}\n\n/**\n * Sequelize binds every SQL Server parameter that isn't a number, boolean or Buffer as NVarChar, which tedious rejects\n * for a Date. A UTC `YYYY-MM-DD HH:mm:ss.sss` string converts to the `datetime2` column whatever the DATEFORMAT, and\n * matches what tedious reads back (`useUTC`, its default and Sequelize's).\n */\nconst mssqlValue = (value: unknown): unknown =>\n value instanceof Date ? value.toISOString().replace('T', ' ').replace('Z', '') : value\n\ntype Kind = 'SELECT' | 'INSERT' | 'BULKDELETE' | 'BULKUPDATE' | 'RAW'\n\n/**\n * The Sequelize query type that gives back what Kysely needs: the rows of a select (or of an INSERT with\n * RETURNING / OUTPUT), the insert id of a MySQL INSERT, the deleted row count of a DELETE.\n */\nconst kindOf = (compiled: CompiledQuery, dialect: RbacDialect): Kind => {\n const node = compiled.query as { kind: string; returning?: unknown; output?: unknown }\n if (node.kind === 'SelectQueryNode' || node.returning !== undefined || node.output !== undefined) return 'SELECT'\n if (node.kind === 'InsertQueryNode' && dialect === 'mysql') return 'INSERT'\n // SQL Server: Sequelize reads a BULKDELETE count from an `AFFECTEDROWS` column its own SQL adds, but a BULKUPDATE\n // count from the driver's row count, which a plain DELETE has too.\n if (node.kind === 'DeleteQueryNode') return dialect === 'mssql' ? 'BULKUPDATE' : 'BULKDELETE'\n return 'RAW'\n}\n\nclass SequelizeConnection implements DatabaseConnection {\n transaction: SequelizeTransaction | undefined\n\n constructor(\n private readonly sequelize: SequelizeInstance,\n private readonly dialect: RbacDialect,\n /** The caller's transaction: the adapter joins it instead of starting one. */\n readonly joined: SequelizeTransaction | undefined,\n ) {\n this.transaction = joined\n }\n\n async executeQuery<R>(compiled: CompiledQuery): Promise<QueryResult<R>> {\n const type = kindOf(compiled, this.dialect)\n let sql = toBindSql(compiled.sql, this.dialect)\n // Sequelize's SQLite driver runs any SQL starting with `insert into` / `update` (after trimming) with sqlite3's\n // `run()`, which drops the rows of RETURNING. A leading comment makes it use `all()`, which returns them.\n if (type === 'SELECT' && this.dialect === 'sqlite' && compiled.query.kind !== 'SelectQueryNode') sql = `/* rows */ ${sql}`\n const result = await this.sequelize.query(sql, {\n bind: this.dialect === 'mssql' ? compiled.parameters.map(mssqlValue) : [...compiled.parameters],\n type,\n raw: true,\n ...(this.transaction ? { transaction: this.transaction } : {}),\n })\n if (type === 'SELECT') return { rows: result as R[] }\n if (type === 'INSERT') {\n const [insertId, affected] = result as [unknown, unknown]\n return {\n rows: [],\n ...(typeof insertId === 'number' ? { insertId: BigInt(insertId) } : {}),\n ...(typeof affected === 'number' ? { numAffectedRows: BigInt(affected) } : {}),\n }\n }\n if ((type === 'BULKDELETE' || type === 'BULKUPDATE') && typeof result === 'number') {\n return { rows: [], numAffectedRows: BigInt(result) }\n }\n return { rows: [] }\n }\n\n // eslint-disable-next-line require-yield\n async *streamQuery(): AsyncIterableIterator<QueryResult<never>> {\n throw new Error('rbac-evolution-sequelize: streaming is not supported')\n }\n}\n\nclass SequelizeDriver implements Driver {\n constructor(\n private readonly source: SequelizeSource,\n private readonly dialect: RbacDialect,\n ) {}\n\n async init(): Promise<void> {}\n\n async acquireConnection(): Promise<DatabaseConnection> {\n const joined = isTransaction(this.source) ? this.source : undefined\n return new SequelizeConnection(sequelizeOf(this.source), this.dialect, joined)\n }\n\n async beginTransaction(connection: DatabaseConnection): Promise<void> {\n const c = connection as SequelizeConnection\n if (!c.joined) c.transaction = await sequelizeOf(this.source).transaction()\n }\n\n async commitTransaction(connection: DatabaseConnection): Promise<void> {\n const c = connection as SequelizeConnection\n if (c.joined) return\n await c.transaction?.commit()\n c.transaction = undefined\n }\n\n async rollbackTransaction(connection: DatabaseConnection): Promise<void> {\n const c = connection as SequelizeConnection\n if (c.joined) return\n await c.transaction?.rollback()\n c.transaction = undefined\n }\n\n async releaseConnection(): Promise<void> {}\n\n async destroy(): Promise<void> {}\n}\n\nconst PARTS: Record<\n RbacDialect,\n {\n adapter: () => DialectAdapter\n compiler: () => QueryCompiler\n introspector: (db: Kysely<any>) => DatabaseIntrospector // eslint-disable-line @typescript-eslint/no-explicit-any\n }\n> = {\n postgres: {\n adapter: () => new PostgresAdapter(),\n compiler: () => new PostgresQueryCompiler(),\n introspector: (db) => new PostgresIntrospector(db),\n },\n mysql: {\n adapter: () => new MysqlAdapter(),\n compiler: () => new MysqlQueryCompiler(),\n introspector: (db) => new MysqlIntrospector(db),\n },\n sqlite: {\n adapter: () => new SqliteAdapter(),\n compiler: () => new SqliteQueryCompiler(),\n introspector: (db) => new SqliteIntrospector(db),\n },\n mssql: {\n adapter: () => new MssqlAdapter(),\n compiler: () => new MssqlQueryCompiler(),\n introspector: (db) => new MssqlIntrospector(db),\n },\n}\n\n/**\n * A Kysely dialect that runs every query through `sequelize.query()`: on the pool, or in the caller's transaction\n * when given one (`sequelizeAdapter(t)` inside `sequelize.transaction(async (t) => ...)`).\n */\nexport function sequelizeDialect(source: SequelizeSource): Dialect {\n const dialect = dialectOf(source)\n const parts = PARTS[dialect]\n return {\n createAdapter: parts.adapter,\n createDriver: () => new SequelizeDriver(source, dialect),\n createQueryCompiler: parts.compiler,\n createIntrospector: parts.introspector,\n }\n}\n","import {\n type KyselyRbacAdapter,\n type RbacMigrationOptions,\n type RbacTableOptions,\n addRbacExpiryColumns,\n createRbacTables,\n dropRbacExpiryColumns,\n dropRbacTables,\n kyselyAdapter,\n} from '@anievo-id/rbac-evolution-kysely'\nimport { Kysely } from 'kysely'\nimport { type SequelizeInstance, type SequelizeSource, dialectOf, sequelizeDialect } from './dialect'\n\nexport {\n dialectOf,\n sequelizeDialect,\n toBindSql,\n type SequelizeInstance,\n type SequelizeSource,\n type SequelizeTransaction,\n} from './dialect'\nexport type { RbacTableNames, RbacTableOptions } from '@anievo-id/rbac-evolution-kysely'\n\nexport interface SequelizeAdapterOptions extends RbacTableOptions {\n /**\n * Store an expiry per role assignment and direct permission (`assignRole(role, { expiresAt })`). Needs the\n * `expires_at` column (`rbacMigration({ expiry: true })`, or `rbacExpiryMigration()` for existing tables).\n * Default: `false`.\n */\n expiry?: boolean | undefined\n}\n\n/** The adapter type: the Kysely adapter, running its queries through `sequelize.query()`. */\nexport type SequelizeRbacAdapter = KyselyRbacAdapter\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst kyselyOf = (source: SequelizeSource): Kysely<any> => new Kysely({ dialect: sequelizeDialect(source) })\n\n/**\n * Creates a Sequelize-backed `RbacAdapter` for PostgreSQL, MySQL / MariaDB, SQLite and SQL Server.\n *\n * ```ts\n * const rbac = createRbac({ adapter: sequelizeAdapter(sequelize) })\n * // inside a transaction: the adapter runs in it\n * await sequelize.transaction((t) => createRbac({ adapter: sequelizeAdapter(t) }).for(user).assignRole('writer'))\n * ```\n */\nexport function sequelizeAdapter(source: SequelizeSource, options: SequelizeAdapterOptions = {}): SequelizeRbacAdapter {\n return kyselyAdapter(kyselyOf(source), { dialect: dialectOf(source), prefix: options.prefix, expiry: options.expiry })\n}\n\n/**\n * What a migration gets: sequelize-cli passes the QueryInterface first, Umzug passes `{ context }` (set `context` to\n * the QueryInterface or the Sequelize instance).\n */\ntype MigrationArgument = { sequelize: SequelizeInstance } | SequelizeInstance | { context: { sequelize: SequelizeInstance } | SequelizeInstance }\n\nconst instanceOf = (arg: MigrationArgument): SequelizeInstance => {\n const target = 'context' in arg ? arg.context : arg\n return 'sequelize' in target && typeof (target as { sequelize?: unknown }).sequelize === 'object'\n ? (target as { sequelize: SequelizeInstance }).sequelize\n : (target as SequelizeInstance)\n}\n\n/** A migration for sequelize-cli (`up(queryInterface)`) and Umzug (`up({ context })`). */\nexport interface RbacSequelizeMigration {\n up(arg: MigrationArgument): Promise<void>\n down(arg: MigrationArgument): Promise<void>\n}\n\n/**\n * A migration that creates the five rbac tables (and their indexes), like `createRbacTables` of the Kysely package.\n *\n * ```js\n * // migrations/20261119000000-rbac.js (sequelize-cli)\n * module.exports = require('@anievo-id/rbac-evolution-sequelize').rbacMigration()\n * ```\n */\nexport function rbacMigration(options: RbacTableOptions & Pick<RbacMigrationOptions, 'expiry'> = {}): RbacSequelizeMigration {\n return {\n up: async (arg) => {\n const sequelize = instanceOf(arg)\n await createRbacTables(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) })\n },\n down: (arg) => dropRbacTables(kyselyOf(instanceOf(arg)), options),\n }\n}\n\n/** A migration that adds the `expires_at` columns to existing tables, for `{ expiry: true }`. */\nexport function rbacExpiryMigration(options: RbacTableOptions = {}): RbacSequelizeMigration {\n return {\n up: async (arg) => {\n const sequelize = instanceOf(arg)\n await addRbacExpiryColumns(kyselyOf(sequelize), { ...options, dialect: dialectOf(sequelize) })\n },\n down: (arg) => dropRbacExpiryColumns(kyselyOf(instanceOf(arg)), options),\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anievo-id/rbac-evolution-sequelize",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "Sequelize adapter for rbac-evolution: PostgreSQL, MySQL / MariaDB, SQLite and SQL Server through your Sequelize instance.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "AniEvo-ID (https://github.com/AniEvo-ID)",
|
|
7
|
+
"homepage": "https://creation.anievo.id/rbac-evolution/adapters/sequelize",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/AniEvo-ID/rbac-evolution/issues"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/AniEvo-ID/rbac-evolution.git",
|
|
15
|
+
"directory": "packages/sequelize"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"rbac",
|
|
19
|
+
"permissions",
|
|
20
|
+
"roles",
|
|
21
|
+
"authorization",
|
|
22
|
+
"sequelize",
|
|
23
|
+
"postgresql",
|
|
24
|
+
"mysql",
|
|
25
|
+
"sqlite",
|
|
26
|
+
"sqlserver"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/index.d.cts",
|
|
40
|
+
"default": "./dist/index.cjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
],
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"kysely": "^0.28.0",
|
|
53
|
+
"@anievo-id/rbac-evolution": "^1.7.0",
|
|
54
|
+
"@anievo-id/rbac-evolution-kysely": "^1.7.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"sequelize": "^6.1.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"mysql2": "^3.15.3",
|
|
61
|
+
"pg": "^8.13.0",
|
|
62
|
+
"pg-hstore": "^2.3.4",
|
|
63
|
+
"sequelize": "^6.37.8",
|
|
64
|
+
"sqlite3": "^5.1.7",
|
|
65
|
+
"tedious": "^18.6.1",
|
|
66
|
+
"tsup": "^8.3.0",
|
|
67
|
+
"typescript": "^5.7.0",
|
|
68
|
+
"vitest": "^2.1.0"
|
|
69
|
+
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=20"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsup",
|
|
75
|
+
"dev": "tsup --watch",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
77
|
+
"test": "vitest run --passWithNoTests",
|
|
78
|
+
"clean": "rm -rf dist .turbo"
|
|
79
|
+
}
|
|
6
80
|
}
|