New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@strapi/database

Package Overview
Dependencies
Maintainers
8
Versions
1535
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@strapi/database - npm Package Compare versions

Comparing version 4.1.11 to 4.1.12

lib/__tests__/lifecycles.test.js

38

lib/entity-manager.js

@@ -116,3 +116,3 @@ 'use strict';

async findOne(uid, params) {
await db.lifecycles.run('beforeFindOne', uid, { params });
const states = await db.lifecycles.run('beforeFindOne', uid, { params });

@@ -124,3 +124,3 @@ const result = await this.createQueryBuilder(uid)

await db.lifecycles.run('afterFindOne', uid, { params, result });
await db.lifecycles.run('afterFindOne', uid, { params, result }, states);

@@ -132,3 +132,3 @@ return result;

async findMany(uid, params) {
await db.lifecycles.run('beforeFindMany', uid, { params });
const states = await db.lifecycles.run('beforeFindMany', uid, { params });

@@ -139,3 +139,3 @@ const result = await this.createQueryBuilder(uid)

await db.lifecycles.run('afterFindMany', uid, { params, result });
await db.lifecycles.run('afterFindMany', uid, { params, result }, states);

@@ -145,4 +145,4 @@ return result;

async count(uid, params = {}) {
await db.lifecycles.run('beforeCount', uid, { params });
async count(uid, params) {
const states = await db.lifecycles.run('beforeCount', uid, { params });

@@ -157,3 +157,3 @@ const res = await this.createQueryBuilder(uid)

await db.lifecycles.run('afterCount', uid, { params, result });
await db.lifecycles.run('afterCount', uid, { params, result }, states);

@@ -164,3 +164,3 @@ return result;

async create(uid, params = {}) {
await db.lifecycles.run('beforeCreate', uid, { params });
const states = await db.lifecycles.run('beforeCreate', uid, { params });

@@ -192,3 +192,3 @@ const metadata = db.metadata.get(uid);

await db.lifecycles.run('afterCreate', uid, { params, result });
await db.lifecycles.run('afterCreate', uid, { params, result }, states);

@@ -200,3 +200,3 @@ return result;

async createMany(uid, params = {}) {
await db.lifecycles.run('beforeCreateMany', uid, { params });
const states = await db.lifecycles.run('beforeCreateMany', uid, { params });

@@ -222,3 +222,3 @@ const metadata = db.metadata.get(uid);

await db.lifecycles.run('afterCreateMany', uid, { params, result });
await db.lifecycles.run('afterCreateMany', uid, { params, result }, states);

@@ -229,3 +229,3 @@ return result;

async update(uid, params = {}) {
await db.lifecycles.run('beforeUpdate', uid, { params });
const states = await db.lifecycles.run('beforeUpdate', uid, { params });

@@ -273,3 +273,3 @@ const metadata = db.metadata.get(uid);

await db.lifecycles.run('afterUpdate', uid, { params, result });
await db.lifecycles.run('afterUpdate', uid, { params, result }, states);

@@ -281,3 +281,3 @@ return result;

async updateMany(uid, params = {}) {
await db.lifecycles.run('beforeUpdateMany', uid, { params });
const states = await db.lifecycles.run('beforeUpdateMany', uid, { params });

@@ -300,3 +300,3 @@ const metadata = db.metadata.get(uid);

await db.lifecycles.run('afterUpdateMany', uid, { params, result });
await db.lifecycles.run('afterUpdateMany', uid, { params, result }, states);

@@ -307,3 +307,3 @@ return result;

async delete(uid, params = {}) {
await db.lifecycles.run('beforeDelete', uid, { params });
const states = await db.lifecycles.run('beforeDelete', uid, { params });

@@ -336,3 +336,3 @@ const { where, select, populate } = params;

await db.lifecycles.run('afterDelete', uid, { params, result: entity });
await db.lifecycles.run('afterDelete', uid, { params, result: entity }, states);

@@ -344,3 +344,3 @@ return entity;

async deleteMany(uid, params = {}) {
await db.lifecycles.run('beforeDeleteMany', uid, { params });
const states = await db.lifecycles.run('beforeDeleteMany', uid, { params });

@@ -356,3 +356,3 @@ const { where } = params;

await db.lifecycles.run('afterDelete', uid, { params, result });
await db.lifecycles.run('afterDeleteMany', uid, { params, result }, states);

@@ -359,0 +359,0 @@ return result;

@@ -46,3 +46,4 @@ import { Database } from '../';

clear(): void;
run(action: Action, uid: string, properties: any): Promise<void>;
run(action: Action, uid: string, properties: any): Promise<Map<any, any>>;
run(action: Action, uid: string, properties: any, states: Map<any, any>): Promise<Map<any, any>>;
createEvent(action: Action, uid: string, properties: any): Event;

@@ -49,0 +50,0 @@ }

@@ -33,3 +33,9 @@ 'use strict';

createEvent(action, uid, properties) {
/**
* @param {string} action
* @param {string} uid
* @param {{ params?: any, result?: any }} properties
* @param {Map<any, any>} state
*/
createEvent(action, uid, properties, state) {
const model = db.metadata.get(uid);

@@ -40,2 +46,3 @@

model,
state,
...properties,

@@ -45,7 +52,18 @@ };

async run(action, uid, properties) {
for (const subscriber of subscribers) {
/**
* @param {string} action
* @param {string} uid
* @param {{ params?: any, result?: any }} properties
* @param {Map<any, any>} states
*/
async run(action, uid, properties, states = new Map()) {
for (let i = 0; i < subscribers.length; i++) {
const subscriber = subscribers[i];
if (typeof subscriber === 'function') {
const event = this.createEvent(action, uid, properties);
const state = states.get(subscriber) || {};
const event = this.createEvent(action, uid, properties, state);
await subscriber(event);
if (event.state) {
states.set(subscriber, event.state || state);
}
continue;

@@ -58,7 +76,13 @@ }

if (hasAction && hasModel) {
const event = this.createEvent(action, uid, properties);
const state = states.get(subscriber) || {};
const event = this.createEvent(action, uid, properties, state);
await subscriber[action](event);
if (event.state) {
states.set(subscriber, event.state);
}
}
}
return states;
},

@@ -65,0 +89,0 @@ };

@@ -5,8 +5,13 @@ 'use strict';

const fse = require('fs-extra');
const Umzug = require('umzug');
const { Umzug } = require('umzug');
const createStorage = require('./storage');
const wrapTransaction = db => fn => () =>
db.getConnection().transaction(trx => Promise.resolve(fn(trx)));
// TODO: check multiple commands in one sql statement
const migrationResolver = path => {
const migrationResolver = ({ name, path, context }) => {
const { db } = context;
// if sql file run with knex raw

@@ -17,3 +22,4 @@ if (path.match(/\.sql$/)) {

return {
up: knex => knex.raw(sql),
name,
up: wrapTransaction(db)(knex => knex.raw(sql)),
down() {},

@@ -24,3 +30,8 @@ };

// NOTE: we can add some ts register if we want to handle ts migration files at some point
return require(path);
const migration = require(path);
return {
name,
up: wrapTransaction(db)(migration.up),
down: wrapTransaction(db)(migration.down),
};
};

@@ -33,13 +44,8 @@

const wrapFn = fn => db => db.getConnection().transaction(trx => Promise.resolve(fn(trx)));
const storage = createStorage({ db, tableName: 'strapi_migrations' });
return new Umzug({
storage,
storage: createStorage({ db, tableName: 'strapi_migrations' }),
context: { db },
migrations: {
path: migrationDir,
pattern: /\.(js|sql)$/,
params: [db],
wrap: wrapFn,
customResolver: migrationResolver,
glob: ['*.{js,sql}', { cwd: migrationDir }],
resolve: migrationResolver,
},

@@ -46,0 +52,0 @@ });

@@ -17,7 +17,7 @@ 'use strict';

return {
async logMigration(migrationName) {
async logMigration({ name }) {
await db
.getConnection()
.insert({
name: migrationName,
name,
time: new Date(),

@@ -28,7 +28,7 @@ })

async unlogMigration(migrationName) {
async unlogMigration({ name }) {
await db
.getConnection(tableName)
.del()
.where({ name: migrationName });
.where({ name });
},

@@ -35,0 +35,0 @@

{
"name": "@strapi/database",
"version": "4.1.11",
"version": "4.1.12",
"description": "Strapi's database layer",

@@ -39,3 +39,3 @@ "homepage": "https://strapi.io",

"lodash": "4.17.21",
"umzug": "2.3.0"
"umzug": "3.1.1"
},

@@ -46,3 +46,3 @@ "engines": {

},
"gitHead": "698ae33e0007811ce24b568cc5d873d7a4d2a832"
"gitHead": "ab698015cfc4f43fa0ce2ae94ec59e00a67e4cda"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc