Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

orma

Package Overview
Dependencies
Maintainers
2
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orma - npm Package Compare versions

Comparing version 1.0.229 to 1.0.230

5

build/prepopulate/prepopulate.d.ts
import { OrmaMutation } from '../types/mutation/mutation_types';
import { OrmaQuery } from '../types/query/query_types';
import { OrmaSchema } from '../types/schema/schema_types';
export declare const prepopulate: (orma_query: (query: OrmaQuery<any, any>) => Promise<any>, orma_mutate: (mutation: OrmaMutation<any>) => Promise<any>, orma_schema: OrmaSchema) => Promise<void>;
type OrmaQueryFunction = (query: OrmaQuery<any, any>) => Promise<any>;
type OrmaMutateFunction = (mutation: OrmaMutation<any>) => Promise<any>;
export declare const prepopulate: (orma_query: OrmaQueryFunction, orma_mutate: OrmaMutateFunction, orma_schema: OrmaSchema) => Promise<void>;
export {};

45

build/prepopulate/prepopulate.js

@@ -6,4 +6,5 @@ "use strict";

const diff_mutation_1 = require("../mutate/diff/diff_mutation");
const prepopulate = async (orma_query, orma_mutate, orma_schema) => {
const get_prepopulate_query = async (orma_query, orma_schema) => {
var _a, _b;
let query = {};
const table_names = (0, schema_helpers_1.get_entity_names)(orma_schema);

@@ -26,24 +27,28 @@ for (const table_name of table_names) {

if (((_b = diff[table_name]) === null || _b === void 0 ? void 0 : _b.length) > 0) {
const create_count = diff[table_name].filter(el => el.$operation === 'create').length;
const update_count = diff[table_name].filter(el => el.$operation === 'update').length;
const delete_count = diff[table_name].filter(el => el.$operation === 'delete').length;
try {
await orma_mutate(diff);
// console.log(
// `✏️✏️✏️ Prepopulated ${table_name} with ${create_count} new rows and ${update_count} updated rows.`
// )
create_count > 0 &&
console.log(`Prepopulate: 🌱 ${create_count} rows added to ${table_name}`);
update_count > 0 &&
console.log(`Prepopulate: ✏️ ${update_count} rows update in ${table_name}`);
delete_count > 0 &&
console.log(`Prepopulate: ✂️ ${delete_count} rows deleted in ${table_name}`);
}
catch (error) {
console.error(`❌❌❌ Prepopulate failed for ${table_name}`);
throw error;
}
query[table_name] = diff[table_name];
}
}
return query;
};
const prepopulate = async (orma_query, orma_mutate, orma_schema) => {
const prepopulate_query = await get_prepopulate_query(orma_query, orma_schema);
try {
await orma_mutate(prepopulate_query);
Object.entries(prepopulate_query).forEach(async ([table_name, rows]) => {
const create_count = rows.filter(el => el.$operation === 'create').length;
const update_count = rows.filter(el => el.$operation === 'update').length;
const delete_count = rows.filter(el => el.$operation === 'delete').length;
create_count > 0 &&
console.log(`Prepopulate: 🌱 ${create_count} rows added to ${table_name}`);
update_count > 0 &&
console.log(`Prepopulate: ✏️ ${update_count} rows updated in ${table_name}`);
delete_count > 0 &&
console.log(`Prepopulate: ✂️ ${delete_count} rows deleted in ${table_name}`);
});
}
catch (error) {
console.error(`Prepopulate: ❌ failed`);
throw error;
}
};
exports.prepopulate = prepopulate;
{
"name": "orma",
"version": "1.0.229",
"version": "1.0.230",
"description": "A declarative relational syncronous orm",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -7,7 +7,11 @@ import { get_entity_names } from '../helpers/schema_helpers'

export const prepopulate = async (
orma_query: (query: OrmaQuery<any, any>) => Promise<any>,
orma_mutate: (mutation: OrmaMutation<any>) => Promise<any>,
type OrmaQueryFunction = (query: OrmaQuery<any, any>) => Promise<any>
type OrmaMutateFunction = (mutation: OrmaMutation<any>) => Promise<any>
const get_prepopulate_query = async (
orma_query: OrmaQueryFunction,
orma_schema: OrmaSchema
) => {
let query = {}
const table_names = get_entity_names(orma_schema)

@@ -38,18 +42,33 @@

if (diff[table_name]?.length > 0) {
const create_count = diff[table_name].filter(
el => el.$operation === 'create'
).length
const update_count = diff[table_name].filter(
el => el.$operation === 'update'
).length
const delete_count = diff[table_name].filter(
el => el.$operation === 'delete'
).length
query[table_name] = diff[table_name]
}
}
try {
await orma_mutate(diff)
// console.log(
// `✏️✏️✏️ Prepopulated ${table_name} with ${create_count} new rows and ${update_count} updated rows.`
// )
return query
}
export const prepopulate = async (
orma_query: OrmaQueryFunction,
orma_mutate: OrmaMutateFunction,
orma_schema: OrmaSchema
) => {
const prepopulate_query = await get_prepopulate_query(
orma_query,
orma_schema
)
try {
await orma_mutate(prepopulate_query)
Object.entries(prepopulate_query).forEach(
async ([table_name, rows]: any) => {
const create_count = rows.filter(
el => el.$operation === 'create'
).length
const update_count = rows.filter(
el => el.$operation === 'update'
).length
const delete_count = rows.filter(
el => el.$operation === 'delete'
).length
create_count > 0 &&

@@ -61,3 +80,3 @@ console.log(

console.log(
`Prepopulate: ✏️ ${update_count} rows update in ${table_name}`
`Prepopulate: ✏️ ${update_count} rows updated in ${table_name}`
)

@@ -68,8 +87,8 @@ delete_count > 0 &&

)
} catch (error) {
console.error(`❌❌❌ Prepopulate failed for ${table_name}`)
throw error
}
}
)
} catch (error) {
console.error(`Prepopulate: ❌ failed`)
throw error
}
}
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