Socket
Socket
Sign inDemoInstall

orma

Package Overview
Dependencies
4
Maintainers
2
Versions
231
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.254 to 1.0.255

build/mutate/mutate.test.d.ts

6

build/mutate/verifications/mutation_connected.d.ts

@@ -9,3 +9,3 @@ import { OrmaError } from '../../helpers/error_handling';

export declare const get_mutation_connected_errors: (orma_schema: OrmaSchema, connection_edges: ConnectionEdges, mysql_function: MysqlFunction, guid_map: GuidMap, where_connecteds: WhereConnected<OrmaSchema>, mutation_pieces: MutationPiece[]) => Promise<OrmaError[]>;
export declare const get_ownership_queries: (orma_schema: OrmaSchema, connection_edges: ConnectionEdges, guid_map: GuidMap, where_connecteds: WhereConnected<OrmaSchema>, all_mutation_pieces: MutationPiece[]) => {
export declare const get_ownership_queries: (orma_schema: OrmaSchema, connection_edges: ConnectionEdges, guid_map: GuidMap, where_connecteds: WhereConnected<OrmaSchema>, mutation_pieces: MutationPiece[]) => {
$select: (string | number)[];

@@ -15,3 +15,3 @@ $from: string;

}[];
export declare const get_identifier_connected_wheres: (orma_schema: OrmaSchema, connection_edges: ConnectionEdges, guid_map: GuidMap, where_connected: WhereConnected<OrmaSchema>[number], mutation_pieces: MutationPiece[], entity: string) => any[];
export declare const get_foreign_key_connected_wheres: (connection_edges: ConnectionEdges, where_connected: WhereConnected<OrmaSchema>[number], mutation_pieces: MutationPiece[], entity: string) => any[];
export declare const get_identifier_connected_wheres: (orma_schema: OrmaSchema, connection_edges: ConnectionEdges, guid_map: GuidMap, where_connected: WhereConnected<OrmaSchema>[number], mutation_pieces: MutationPiece[], piece_indices: number[], entity: string) => any[];
export declare const get_foreign_key_connected_wheres: (connection_edges: ConnectionEdges, where_connected: WhereConnected<OrmaSchema>[number], mutation_pieces: MutationPiece[], piece_indices: number[], entity: string) => any[];

@@ -23,3 +23,3 @@ "use strict";

exports.get_mutation_connected_errors = get_mutation_connected_errors;
const get_ownership_queries = (orma_schema, connection_edges, guid_map, where_connecteds, all_mutation_pieces) => {
const get_ownership_queries = (orma_schema, connection_edges, guid_map, where_connecteds, mutation_pieces) => {
/*

@@ -51,9 +51,9 @@ algorithm:

*/
const mutation_pieces_by_entity = (0, helpers_1.group_by)(all_mutation_pieces, mutation_piece => (0, mutate_helpers_1.path_to_entity)(mutation_piece.path));
const entities = Object.keys(mutation_pieces_by_entity);
const piece_indices_by_entity = (0, helpers_1.group_by)(mutation_pieces.map((_, i) => i), i => (0, mutate_helpers_1.path_to_entity)(mutation_pieces[i].path));
const entities = Object.keys(piece_indices_by_entity);
const queries = where_connecteds.flatMap(where_connected => {
const wheres = entities.flatMap(entity => {
const mutation_pieces = mutation_pieces_by_entity[entity];
const primary_key_wheres = (0, exports.get_identifier_connected_wheres)(orma_schema, connection_edges, guid_map, where_connected, mutation_pieces, entity);
const foreign_key_wheres = (0, exports.get_foreign_key_connected_wheres)(connection_edges, where_connected, mutation_pieces, entity);
const piece_indices = piece_indices_by_entity[entity];
const primary_key_wheres = (0, exports.get_identifier_connected_wheres)(orma_schema, connection_edges, guid_map, where_connected, mutation_pieces, piece_indices, entity);
const foreign_key_wheres = (0, exports.get_foreign_key_connected_wheres)(connection_edges, where_connected, mutation_pieces, piece_indices, entity);
return [...foreign_key_wheres, ...primary_key_wheres];

@@ -68,3 +68,3 @@ });

$from: where_connected.$entity,
$where,
$where
};

@@ -76,8 +76,8 @@ return [query];

exports.get_ownership_queries = get_ownership_queries;
const get_identifier_connected_wheres = (orma_schema, connection_edges, guid_map, where_connected, mutation_pieces, entity) => {
const get_identifier_connected_wheres = (orma_schema, connection_edges, guid_map, where_connected, mutation_pieces, piece_indices, entity) => {
var _a;
const relevant_piece_indices = mutation_pieces.flatMap((mutation_piece, piece_index) => {
const relevant_piece_indices = piece_indices.flatMap(piece_index => {
// this query fetches data that is in the database but not in the mutation. Because creates
// are not yet in the database, all data must be in scope already, so we can safely ignore them
const is_create = mutation_piece.record.$operation === 'create';
const is_create = mutation_pieces[piece_index].record.$operation === 'create';
return is_create ? [] : [piece_index];

@@ -112,3 +112,3 @@ });

exports.get_identifier_connected_wheres = get_identifier_connected_wheres;
const get_foreign_key_connected_wheres = (connection_edges, where_connected, mutation_pieces, entity) => {
const get_foreign_key_connected_wheres = (connection_edges, where_connected, mutation_pieces, piece_indices, entity) => {
var _a;

@@ -120,4 +120,5 @@ // TODO: optimize by combining this with the one in the other function

.map(edge_path => {
const values = mutation_pieces
.map(({ record }) => {
const values = piece_indices
.map((piece_index) => {
const { record } = mutation_pieces[piece_index];
const field = edge_path[0].from_field;

@@ -141,3 +142,3 @@ const value = record[field];

const parent_where = {
$in: [parent_field, values],
$in: [parent_field, values]
};

@@ -173,4 +174,4 @@ if (search_ownership_path.length === 0) {

valid_owners,
invalid_owners,
},
invalid_owners
}
};

@@ -177,0 +178,0 @@ return [error];

@@ -256,3 +256,3 @@ "use strict";

];
const wheres = (0, mutation_connected_1.get_identifier_connected_wheres)(global_test_schema_1.global_test_schema, default_connection_edges, new Map(), get_test_where_connected('users'), mutation_pieces, 'posts');
const wheres = (0, mutation_connected_1.get_identifier_connected_wheres)(global_test_schema_1.global_test_schema, default_connection_edges, new Map(), get_test_where_connected('users'), mutation_pieces, [0], 'posts');
(0, chai_1.expect)(wheres).to.deep.equal([

@@ -299,3 +299,3 @@ {

// )
const wheres = (0, mutation_connected_1.get_identifier_connected_wheres)(global_test_schema_1.global_test_schema, default_connection_edges, new Map(), get_test_where_connected('addresses'), mutation_pieces, 'users');
const wheres = (0, mutation_connected_1.get_identifier_connected_wheres)(global_test_schema_1.global_test_schema, default_connection_edges, new Map(), get_test_where_connected('addresses'), mutation_pieces, [0], 'users');
(0, chai_1.expect)(wheres).to.deep.equal([

@@ -334,3 +334,3 @@ {

];
const wheres = (0, mutation_connected_1.get_identifier_connected_wheres)(global_test_schema_1.global_test_schema, default_connection_edges, new Map(), get_test_where_connected('users'), mutation_pieces, 'products');
const wheres = (0, mutation_connected_1.get_identifier_connected_wheres)(global_test_schema_1.global_test_schema, default_connection_edges, new Map(), get_test_where_connected('users'), mutation_pieces, [0], 'products');
(0, chai_1.expect)(wheres).to.deep.equal([]);

@@ -355,3 +355,3 @@ });

$values: [1],
}, mutation_pieces, 'posts');
}, mutation_pieces, [0], 'posts');
(0, chai_1.expect)(wheres).to.deep.equal([]);

@@ -382,3 +382,3 @@ });

];
const wheres = (0, mutation_connected_1.get_foreign_key_connected_wheres)(default_connection_edges, get_test_where_connected('users'), mutation_pieces, 'posts');
const wheres = (0, mutation_connected_1.get_foreign_key_connected_wheres)(default_connection_edges, get_test_where_connected('users'), mutation_pieces, [0, 1], 'posts');
(0, chai_1.expect)(wheres).to.deep.equal([

@@ -409,3 +409,3 @@ {

];
const wheres = (0, mutation_connected_1.get_foreign_key_connected_wheres)(default_connection_edges, get_test_where_connected('users'), mutation_pieces, 'comments');
const wheres = (0, mutation_connected_1.get_foreign_key_connected_wheres)(default_connection_edges, get_test_where_connected('users'), mutation_pieces, [0, 1], 'comments');
(0, chai_1.expect)(wheres).to.deep.equal([

@@ -437,3 +437,3 @@ {

];
const wheres = (0, mutation_connected_1.get_foreign_key_connected_wheres)(default_connection_edges, get_test_where_connected('users'), mutation_pieces, 'comments');
const wheres = (0, mutation_connected_1.get_foreign_key_connected_wheres)(default_connection_edges, get_test_where_connected('users'), mutation_pieces, [0], 'comments');
(0, chai_1.expect)(wheres).to.deep.equal([]);

@@ -440,0 +440,0 @@ });

@@ -116,2 +116,7 @@ /**

};
readonly $group_concat: {
readonly ast_to_sql: (args: any) => string;
readonly aggregate: true;
readonly min_args: 1;
};
readonly $multiply: {

@@ -118,0 +123,0 @@ readonly ast_to_sql: (args: any) => string;

@@ -175,2 +175,7 @@ "use strict";

},
$group_concat: {
ast_to_sql: args => `GROUP_CONCAT(${args.join(', ')})`,
aggregate: true,
min_args: 1
},
$multiply: {

@@ -177,0 +182,0 @@ ast_to_sql: args => `(${args.join(' * ')})`,

@@ -12,7 +12,7 @@ "use strict";

posts: {
users: {},
},
users: {}
}
}, [], [
[['posts'], [{ user_id: 1 }]],
[['posts', 'users'], [{ id: 1 }]],
[['posts', 'users'], [{ id: 1 }]]
]);

@@ -25,7 +25,7 @@ (0, chai_1.expect)(result).to.deep.equal({

{
id: 1,
},
],
},
],
id: 1
}
]
}
]
});

@@ -32,0 +32,0 @@ });

@@ -48,2 +48,7 @@ export declare const global_test_hydration: {

}];
readonly categories: readonly [{
readonly id: 1;
readonly label: "Root";
readonly parent_category_id: 1;
}];
};

@@ -13,3 +13,3 @@ "use strict";

billing_address_id: 1,
shipping_address_id: 2,
shipping_address_id: 2
},

@@ -20,3 +20,3 @@ {

email: 'bob@bob.com',
billing_address_id: 3,
billing_address_id: 3
},

@@ -27,4 +27,4 @@ {

last_name: 'Coal',
email: 'char@coal.com',
},
email: 'char@coal.com'
}
],

@@ -36,3 +36,3 @@ posts: [

title: 'First post!',
views: 2,
views: 2
},

@@ -43,3 +43,3 @@ {

title: 'Post #2',
views: 15,
views: 15
},

@@ -49,4 +49,4 @@ {

user_id: 3,
title: 'How to light a wood stove',
},
title: 'How to light a wood stove'
}
],

@@ -56,8 +56,8 @@ comments: [

id: 1,
post_id: 1,
post_id: 1
},
{
id: 2,
post_id: 3,
},
post_id: 3
}
],

@@ -68,5 +68,12 @@ addresses: [

line_1: '1 Road st',
resource_id: '1',
},
resource_id: '1'
}
],
categories: [
{
id: 1,
label: 'Root',
parent_category_id: 1
}
]
};
{
"name": "orma",
"version": "1.0.254",
"version": "1.0.255",
"description": "A declarative relational syncronous orm",

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

@@ -349,2 +349,3 @@ import { expect } from 'chai'

mutation_pieces,
[0],
'posts'

@@ -402,2 +403,3 @@ )

mutation_pieces,
[0],
'users'

@@ -446,2 +448,3 @@ )

mutation_pieces,
[0],
'products'

@@ -476,2 +479,3 @@ )

mutation_pieces,
[0],
'posts'

@@ -510,2 +514,3 @@ )

mutation_pieces,
[0, 1],
'posts'

@@ -544,2 +549,3 @@ )

mutation_pieces,
[0, 1],
'comments'

@@ -579,2 +585,3 @@ )

mutation_pieces,
[0],
'comments'

@@ -581,0 +588,0 @@ )

@@ -8,3 +8,3 @@ import { OrmaError } from '../../helpers/error_handling'

ConnectionEdges,
get_edge_paths_by_destination,
get_edge_paths_by_destination
} from '../../query/macros/where_connected_macro'

@@ -59,3 +59,3 @@ import { combine_wheres } from '../../query/query_helpers'

where_connecteds: WhereConnected<OrmaSchema>,
all_mutation_pieces: MutationPiece[]
mutation_pieces: MutationPiece[]
) => {

@@ -89,11 +89,11 @@ /*

const mutation_pieces_by_entity = group_by(
all_mutation_pieces,
mutation_piece => path_to_entity(mutation_piece.path)
const piece_indices_by_entity = group_by(
mutation_pieces.map((_, i) => i),
i => path_to_entity(mutation_pieces[i].path)
)
const entities = Object.keys(mutation_pieces_by_entity)
const entities = Object.keys(piece_indices_by_entity)
const queries = where_connecteds.flatMap(where_connected => {
const wheres = entities.flatMap(entity => {
const mutation_pieces = mutation_pieces_by_entity[entity]
const piece_indices = piece_indices_by_entity[entity]

@@ -106,2 +106,3 @@ const primary_key_wheres = get_identifier_connected_wheres(

mutation_pieces,
piece_indices,
entity

@@ -114,2 +115,3 @@ )

mutation_pieces,
piece_indices,
entity

@@ -130,3 +132,3 @@ )

$from: where_connected.$entity,
$where,
$where
}

@@ -146,13 +148,13 @@

mutation_pieces: MutationPiece[],
piece_indices: number[],
entity: string
) => {
const relevant_piece_indices = mutation_pieces.flatMap(
(mutation_piece, piece_index) => {
// this query fetches data that is in the database but not in the mutation. Because creates
// are not yet in the database, all data must be in scope already, so we can safely ignore them
const is_create = mutation_piece.record.$operation === 'create'
const relevant_piece_indices = piece_indices.flatMap(piece_index => {
// this query fetches data that is in the database but not in the mutation. Because creates
// are not yet in the database, all data must be in scope already, so we can safely ignore them
const is_create =
mutation_pieces[piece_index].record.$operation === 'create'
return is_create ? [] : [piece_index]
}
)
return is_create ? [] : [piece_index]
})
const identifying_where = get_identifying_where(

@@ -207,2 +209,3 @@ orma_schema,

mutation_pieces: MutationPiece[],
piece_indices: number[],
entity: string

@@ -219,4 +222,5 @@ ) => {

.map(edge_path => {
const values = mutation_pieces
.map(({ record }) => {
const values = piece_indices
.map((piece_index) => {
const { record } = mutation_pieces[piece_index]
const field = edge_path[0].from_field

@@ -242,3 +246,3 @@ const value = record[field]

const parent_where = {
$in: [parent_field, values],
$in: [parent_field, values]
}

@@ -291,4 +295,4 @@

valid_owners,
invalid_owners,
},
invalid_owners
}
}

@@ -295,0 +299,0 @@ return [error]

@@ -253,2 +253,7 @@ /**

},
$group_concat: {
ast_to_sql: args => `GROUP_CONCAT(${args.join(', ')})`,
aggregate: true,
min_args: 1
},
$multiply: {

@@ -255,0 +260,0 @@ ast_to_sql: args => `(${args.join(' * ')})`,

@@ -13,4 +13,4 @@ import { expect } from 'chai'

posts: {
users: {},
},
users: {}
}
},

@@ -20,3 +20,3 @@ [],

[['posts'], [{ user_id: 1 }]],
[['posts', 'users'], [{ id: 1 }]],
[['posts', 'users'], [{ id: 1 }]]
]

@@ -31,7 +31,7 @@ )

{
id: 1,
},
],
},
],
id: 1
}
]
}
]
})

@@ -38,0 +38,0 @@ })

@@ -12,3 +12,3 @@ import { GlobalTestMutation } from './global_test_schema'

billing_address_id: 1,
shipping_address_id: 2,
shipping_address_id: 2
},

@@ -19,3 +19,3 @@ {

email: 'bob@bob.com',
billing_address_id: 3,
billing_address_id: 3
},

@@ -26,4 +26,4 @@ {

last_name: 'Coal',
email: 'char@coal.com',
},
email: 'char@coal.com'
}
],

@@ -35,3 +35,3 @@ posts: [

title: 'First post!',
views: 2,
views: 2
},

@@ -42,3 +42,3 @@ {

title: 'Post #2',
views: 15,
views: 15
},

@@ -48,4 +48,4 @@ {

user_id: 3,
title: 'How to light a wood stove',
},
title: 'How to light a wood stove'
}
],

@@ -55,8 +55,8 @@ comments: [

id: 1,
post_id: 1,
post_id: 1
},
{
id: 2,
post_id: 3,
},
post_id: 3
}
],

@@ -67,5 +67,12 @@ addresses: [

line_1: '1 Road st',
resource_id: '1',
},
resource_id: '1'
}
],
categories: [
{
id: 1,
label: 'Root',
parent_category_id: 1
}
]
} as const satisfies GlobalTestMutation
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc