Comparing version 1.0.248 to 1.0.249
@@ -20,4 +20,4 @@ "use strict"; | ||
{ name: 'John', age: 25 }, | ||
{ name: 'Jane', age: 30 }, | ||
], | ||
{ name: 'Jane', age: 30 } | ||
] | ||
}; | ||
@@ -32,19 +32,19 @@ const $entities = { | ||
$not_null: true, | ||
$unsigned: true, | ||
$unsigned: true | ||
}, | ||
name: { | ||
$data_type: 'varchar', | ||
$not_null: true, | ||
}, | ||
$not_null: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['user_id'], | ||
$name: 'user_id_pk', | ||
$name: 'user_id_pk' | ||
}, | ||
$unique_keys: [{ $fields: ['name'], $name: 'name_uq' }], | ||
}, | ||
$unique_keys: [{ $fields: ['name'], $name: 'name_uq' }] | ||
} | ||
}; | ||
const orma_schema = { | ||
$entities, | ||
$cache: (0, introspector_1.generate_orma_schema_cache)($entities), | ||
$cache: (0, introspector_1.generate_orma_schema_cache)($entities) | ||
}; | ||
@@ -57,4 +57,4 @@ const mutation_plan = (0, mutate_1.orma_mutate_prepare)(orma_schema, mutation); | ||
{ | ||
sql_string: 'CREATE TABLE users (user_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, age INTEGER)', | ||
}, | ||
sql_string: 'CREATE TABLE users (user_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, age INTEGER)' | ||
} | ||
]); | ||
@@ -72,4 +72,4 @@ await (0, mutate_1.orma_mutate_run)(orma_schema, (0, database_adapters_1.sqlite3_adapter)(db), mutation_plan); | ||
$field: 'id', | ||
$values: [1, 3], | ||
}, | ||
$values: [1, 3] | ||
} | ||
], | ||
@@ -90,11 +90,11 @@ users: { | ||
{ | ||
$lte: ['views', { $escape: 5 }], | ||
$lte: ['views', { $escape: 5 }] | ||
}, | ||
{ | ||
$like: ['title', { $escape: 'First%' }], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
$like: ['title', { $escape: 'First%' }] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}; | ||
@@ -109,4 +109,4 @@ const original = await (0, integration_setup_test_1.test_query)(query); | ||
posts: [ | ||
{ id: 1, title: 'First post!', views: 2, user_id: 1 }, | ||
], | ||
{ id: 1, title: 'First post!', views: 2, user_id: 1 } | ||
] | ||
}, | ||
@@ -122,7 +122,7 @@ { | ||
views: 0, | ||
user_id: 3, | ||
}, | ||
], | ||
}, | ||
], | ||
user_id: 3 | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -138,5 +138,5 @@ const modified = (0, helpers_1.clone)(original); | ||
$where: { | ||
$eq: ['id', { $escape: 1 }], | ||
}, | ||
}, | ||
$eq: ['id', { $escape: 1 }] | ||
} | ||
} | ||
}); | ||
@@ -147,5 +147,5 @@ (0, chai_1.expect)(res_after_mutation).to.deep.equal({ | ||
id: 1, | ||
views: 3, | ||
}, | ||
], | ||
views: 3 | ||
} | ||
] | ||
}); | ||
@@ -168,9 +168,9 @@ }); | ||
title: 'First post!', | ||
user_id: { $guid: 'a' }, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
user_id: { $guid: 'a' } | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
@@ -185,3 +185,3 @@ await (0, integration_setup_test_1.test_mutate)(mutation); | ||
$where: { | ||
$eq: ['email', { $escape: 'aa@a.com' }], | ||
$eq: ['email', { $escape: 'aa@a.com' }] | ||
}, | ||
@@ -192,9 +192,9 @@ likes: { | ||
$where: { | ||
$eq: ['post_id', { $escape: 1 }], | ||
$eq: ['post_id', { $escape: 1 }] | ||
}, | ||
posts: { | ||
title: true, | ||
}, | ||
}, | ||
}, | ||
title: true | ||
} | ||
} | ||
} | ||
}); | ||
@@ -212,7 +212,7 @@ (0, chai_1.expect)(result).to.deep.equal({ | ||
post_id: 1, | ||
posts: [{ title: 'First post!' }], | ||
}, | ||
], | ||
}, | ||
], | ||
posts: [{ title: 'First post!' }] | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -232,7 +232,7 @@ }); | ||
line_1: '123 guid test st', | ||
resource_id: '1', | ||
}, | ||
], | ||
}, | ||
], | ||
resource_id: '1' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -245,3 +245,3 @@ const result = await (0, integration_setup_test_1.test_query)({ | ||
$where: { | ||
$eq: ['id', { $escape: 1 }], | ||
$eq: ['id', { $escape: 1 }] | ||
}, | ||
@@ -251,5 +251,5 @@ addresses: { | ||
line_1: true, | ||
$foreign_key: ['billing_address_id'], | ||
}, | ||
}, | ||
$foreign_key: ['billing_address_id'] | ||
} | ||
} | ||
}); | ||
@@ -265,7 +265,7 @@ (0, chai_1.expect)(result).to.deep.equal({ | ||
id: 1, | ||
line_1: '123 guid test st', | ||
}, | ||
], | ||
}, | ||
], | ||
line_1: '123 guid test st' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -287,9 +287,9 @@ }); | ||
{ | ||
user_id: { $guid: 'a' }, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
user_id: { $guid: 'a' } | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -305,9 +305,9 @@ const query = { | ||
id: true, | ||
user_id: true, | ||
}, | ||
user_id: true | ||
} | ||
}, | ||
$where: { | ||
$eq: ['email', { $escape: 'ab@c.com' }], | ||
}, | ||
}, | ||
$eq: ['email', { $escape: 'ab@c.com' }] | ||
} | ||
} | ||
}; | ||
@@ -319,3 +319,3 @@ const result = await (0, integration_setup_test_1.test_query)(query); | ||
$operation: 'delete', | ||
users: result.users, | ||
users: result.users | ||
}); | ||
@@ -331,4 +331,4 @@ const result_after_delete = await (0, integration_setup_test_1.test_query)(query); | ||
title: 'asd test', | ||
user_id: 1234, | ||
}, | ||
user_id: 1234 | ||
} | ||
], | ||
@@ -339,5 +339,5 @@ users: [ | ||
email: 'ab@c.com', | ||
first_name: 'asd', | ||
}, | ||
], | ||
first_name: 'asd' | ||
} | ||
] | ||
}); | ||
@@ -350,8 +350,8 @@ const query = { | ||
user_id: true, | ||
title: true, | ||
title: true | ||
}, | ||
$where: { | ||
$eq: ['email', { $escape: 'ab@c.com' }], | ||
}, | ||
}, | ||
$eq: ['email', { $escape: 'ab@c.com' }] | ||
} | ||
} | ||
}; | ||
@@ -368,7 +368,7 @@ const result = await (0, integration_setup_test_1.test_query)(query); | ||
user_id: 1234, | ||
title: 'asd test', | ||
}, | ||
], | ||
}, | ||
], | ||
title: 'asd test' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -382,5 +382,5 @@ }); | ||
id: 12345, | ||
line_1: 'ASD TEST', | ||
}, | ||
], | ||
line_1: 'ASD TEST' | ||
} | ||
] | ||
}); | ||
@@ -392,4 +392,4 @@ const query = { | ||
$field: 'id', | ||
$values: [1], | ||
}, | ||
$values: [1] | ||
} | ||
], | ||
@@ -400,5 +400,5 @@ addresses: { | ||
$where: { | ||
$eq: ['id', { $escape: 12345 }], | ||
}, | ||
}, | ||
$eq: ['id', { $escape: 12345 }] | ||
} | ||
} | ||
}; | ||
@@ -412,5 +412,5 @@ const result = await (0, integration_setup_test_1.test_query)(query); | ||
id: 12345, | ||
line_1: 'ASD TEST', | ||
}, | ||
], | ||
line_1: 'ASD TEST' | ||
} | ||
] | ||
}); | ||
@@ -426,5 +426,5 @@ }); | ||
title: 'unique title', | ||
user_id: 1, | ||
}, | ||
], | ||
user_id: 1 | ||
} | ||
] | ||
}); | ||
@@ -437,5 +437,5 @@ try { | ||
id: 1, | ||
title: 'unique title', | ||
}, | ||
], | ||
title: 'unique title' | ||
} | ||
] | ||
}); | ||
@@ -453,5 +453,5 @@ (0, chai_1.expect)(undefined).to.equal('Expected an error to be thrown'); | ||
title: 'unique title', | ||
user_id: 1, | ||
}, | ||
], | ||
user_id: 1 | ||
} | ||
] | ||
}); | ||
@@ -463,5 +463,5 @@ await (0, integration_setup_test_1.test_mutate)({ | ||
id: 12345, | ||
title: 'unique title', | ||
}, | ||
], | ||
title: 'unique title' | ||
} | ||
] | ||
}); | ||
@@ -476,5 +476,5 @@ }); | ||
title: 'unique title', | ||
user_id: 1, | ||
}, | ||
], | ||
user_id: 1 | ||
} | ||
] | ||
}); | ||
@@ -485,5 +485,5 @@ await (0, integration_setup_test_1.test_mutate)({ | ||
{ | ||
id: 12345, | ||
}, | ||
], | ||
id: 12345 | ||
} | ||
] | ||
}); | ||
@@ -499,4 +499,4 @@ }); | ||
last_name: 'b', | ||
email: 'a@b.com', | ||
}, | ||
email: 'a@b.com' | ||
} | ||
], | ||
@@ -507,5 +507,5 @@ posts: [ | ||
title: 'unique title', | ||
user_id: 123, | ||
}, | ||
], | ||
user_id: 123 | ||
} | ||
] | ||
}); | ||
@@ -518,4 +518,4 @@ await (0, integration_setup_test_1.test_mutate)({ | ||
id: { $guid: 1 }, | ||
email: 'a@b.com', | ||
}, | ||
email: 'a@b.com' | ||
} | ||
], | ||
@@ -526,5 +526,5 @@ likes: [ | ||
user_id: { $guid: 1 }, | ||
post_id: 1231, | ||
}, | ||
], | ||
post_id: 1231 | ||
} | ||
] | ||
}); | ||
@@ -537,4 +537,4 @@ }); | ||
id: true, | ||
$where: { $eq: [{ $escape: 1 }, { $escape: 2 }] }, | ||
}, | ||
$where: { $eq: [{ $escape: 1 }, { $escape: 2 }] } | ||
} | ||
}); | ||
@@ -547,15 +547,15 @@ (0, chai_1.expect)(res.posts).to.equal(undefined); | ||
id: { | ||
$escape: { $guid: 'a' }, | ||
$escape: { $guid: 'a' } | ||
}, | ||
my_title: { | ||
$escape: ['hi'], | ||
$escape: ['hi'] | ||
}, | ||
total_views: { | ||
$escape: 1, | ||
$escape: 1 | ||
}, | ||
users: { | ||
id: true, | ||
id: true | ||
}, | ||
$limit: 1, | ||
}, | ||
$limit: 1 | ||
} | ||
}); | ||
@@ -570,7 +570,7 @@ (0, chai_1.expect)(res).to.deep.equal({ | ||
{ | ||
id: 1, | ||
}, | ||
], | ||
}, | ||
], | ||
id: 1 | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -584,6 +584,6 @@ }); | ||
title: true, | ||
$limit: 1, | ||
$limit: 1 | ||
}, | ||
$limit: 1, | ||
}, | ||
$limit: 1 | ||
} | ||
}); | ||
@@ -603,7 +603,7 @@ //@ts-ignore | ||
{ | ||
$operation: 'update', | ||
}, | ||
], | ||
}, | ||
], | ||
$operation: 'update' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -619,7 +619,7 @@ // test passes if it doesnt crash | ||
{ | ||
$operation: 'update', | ||
}, | ||
], | ||
}, | ||
], | ||
$operation: 'update' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -626,0 +626,0 @@ // test passes if it doesnt crash |
@@ -117,3 +117,3 @@ "use strict"; | ||
entity, | ||
record, | ||
record | ||
})) { | ||
@@ -128,3 +128,3 @@ return []; | ||
const value = record[edge.from_field]; | ||
const value_string = JSON.stringify(value); | ||
const value_string = get_value_string(value); | ||
const new_piece_indices = (_b = (_a = fk_index === null || fk_index === void 0 ? void 0 : fk_index[entity_field_operation_string]) === null || _a === void 0 ? void 0 : _a[value_string]) !== null && _b !== void 0 ? _b : []; | ||
@@ -145,3 +145,3 @@ return new_piece_indices; | ||
const entity_field_operation_string = `${entity},${field},${operation}`; | ||
const value_string = JSON.stringify(value); | ||
const value_string = get_value_string(value); | ||
if (!fk_index[entity_field_operation_string]) { | ||
@@ -155,2 +155,5 @@ fk_index[entity_field_operation_string] = {}; | ||
}; | ||
const get_value_string = value => | ||
// dont include $read or $write props in guids | ||
JSON.stringify((value === null || value === void 0 ? void 0 : value.$guid) ? { $guid: value.$guid } : value); | ||
/** | ||
@@ -172,3 +175,3 @@ * Sorts mutation pieces in the order they will be executed and also gives batches that say what to run in parallel | ||
start_index, | ||
end_index: start_index + toposort_tier.length, | ||
end_index: start_index + toposort_tier.length | ||
}); | ||
@@ -183,3 +186,3 @@ }); | ||
index: batch_index, | ||
mutation_batch, | ||
mutation_batch | ||
}); | ||
@@ -186,0 +189,0 @@ } |
@@ -13,12 +13,12 @@ "use strict"; | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 0], | ||
path: ['users', 0, 'posts', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 1], | ||
}, | ||
path: ['users', 0, 'posts', 1] | ||
} | ||
]; | ||
@@ -30,4 +30,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
}; | ||
@@ -41,8 +41,8 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { $operation: 'create', user_id: 2 }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { user_id: 2, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 0], | ||
}, | ||
path: ['users', 0, 'posts', 0] | ||
} | ||
]; | ||
@@ -54,4 +54,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
}; | ||
@@ -64,5 +64,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { id: 1, user_id: 2, $operation: 'update' }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ record: { id: 2, $operation: 'create' }, path: ['users', 0] }, | ||
{ record: { id: 2, $operation: 'create' }, path: ['users', 0] } | ||
]; | ||
@@ -74,4 +74,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -84,3 +84,3 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
{ record: { id: 3, $operation: 'update' }, path: ['users', 1] }, | ||
{ record: { id: 2, $operation: 'update' }, path: ['posts', 0] }, | ||
{ record: { id: 2, $operation: 'update' }, path: ['posts', 0] } | ||
]; | ||
@@ -91,3 +91,3 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
mutation_pieces, | ||
mutation_batches: [{ start_index: 0, end_index: 3 }], | ||
mutation_batches: [{ start_index: 0, end_index: 3 }] | ||
}; | ||
@@ -100,8 +100,8 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { user_id: { $guid: 2 }, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 0], | ||
path: ['users', 0, 'posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 2 }, $operation: 'create' }, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
]; | ||
@@ -113,4 +113,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -123,8 +123,8 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { id: { $guid: 1 }, $operation: 'delete' }, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'delete' }, | ||
path: ['users', 0, 'posts', 0], | ||
}, | ||
path: ['users', 0, 'posts', 0] | ||
} | ||
]; | ||
@@ -136,4 +136,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -147,16 +147,16 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
}, | ||
{ | ||
record: { id: 2, $operation: 'delete' }, | ||
path: ['users', 0, 'posts', 0], | ||
path: ['users', 0, 'posts', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 1, 'posts', 0], | ||
path: ['users', 1, 'posts', 0] | ||
}, | ||
{ | ||
record: { id: 3, post_id: 2, $operation: 'delete' }, | ||
path: ['users', 0, 'posts', 0, 'comments', 0], | ||
}, | ||
path: ['users', 0, 'posts', 0, 'comments', 0] | ||
} | ||
]; | ||
@@ -170,8 +170,8 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
mutation_pieces[3], | ||
mutation_pieces[2], | ||
mutation_pieces[2] | ||
], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 3 }, | ||
{ start_index: 3, end_index: 5 }, | ||
], | ||
{ start_index: 3, end_index: 5 } | ||
] | ||
}; | ||
@@ -182,3 +182,3 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
const mutation_pieces = [ | ||
{ record: { $operation: 'update' }, path: ['users', 0] }, | ||
{ record: { $operation: 'update' }, path: ['users', 0] } | ||
]; | ||
@@ -188,3 +188,3 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
mutation_pieces, | ||
mutation_batches: [{ start_index: 0, end_index: 1 }], | ||
mutation_batches: [{ start_index: 0, end_index: 1 }] | ||
}; | ||
@@ -197,8 +197,8 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0], | ||
}, | ||
path: ['posts', 0, 'users', 0] | ||
} | ||
]; | ||
@@ -210,4 +210,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -220,12 +220,12 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0], | ||
path: ['posts', 0, 'users', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0, 'posts', 0], | ||
}, | ||
path: ['posts', 0, 'users', 0, 'posts', 0] | ||
} | ||
]; | ||
@@ -237,8 +237,8 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
mutation_pieces[0], | ||
mutation_pieces[2], | ||
mutation_pieces[2] | ||
], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
}; | ||
@@ -253,10 +253,10 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
id: 1, | ||
user_id: { $guid: 1 }, | ||
user_id: { $guid: 1 } | ||
}, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0], | ||
}, | ||
path: ['posts', 0, 'users', 0] | ||
} | ||
]; | ||
@@ -268,4 +268,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -287,5 +287,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
id: 2, | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -296,6 +296,6 @@ { | ||
id: 1, | ||
user_id: 1, | ||
user_id: 1 | ||
}, | ||
path: ['posts', 1], | ||
}, | ||
path: ['posts', 1] | ||
} | ||
]; | ||
@@ -307,4 +307,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -320,5 +320,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
id: 1, | ||
user_id: 2, | ||
user_id: 2 | ||
}, | ||
path: ['posts', 1], | ||
path: ['posts', 1] | ||
}, | ||
@@ -331,6 +331,6 @@ { | ||
id: 2, | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
]; | ||
@@ -342,4 +342,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -353,5 +353,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
$operation: 'delete', | ||
id: 1, | ||
id: 1 | ||
}, | ||
path: ['addresses', 0], | ||
path: ['addresses', 0] | ||
}, | ||
@@ -362,6 +362,6 @@ { | ||
id: 1, | ||
billing_address_id: null, | ||
billing_address_id: null | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
]; | ||
@@ -373,4 +373,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -385,5 +385,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
$operation: 'create', | ||
user_id: 2, | ||
user_id: 2 | ||
}, | ||
path: ['posts', 1], | ||
path: ['posts', 1] | ||
}, | ||
@@ -395,6 +395,6 @@ { | ||
id: 2, | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
]; | ||
@@ -406,4 +406,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -418,5 +418,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
$operation: 'update', | ||
user_id: 2, | ||
user_id: 2 | ||
}, | ||
path: ['posts', 1], | ||
path: ['posts', 1] | ||
}, | ||
@@ -428,6 +428,6 @@ { | ||
id: 2, | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
]; | ||
@@ -439,4 +439,4 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
@@ -452,5 +452,5 @@ (0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' } | ||
}, | ||
path: ['categories', 0], | ||
path: ['categories', 0] | ||
}, | ||
@@ -461,6 +461,6 @@ { | ||
id: 2, | ||
parent_category_id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' } | ||
}, | ||
path: ['categories', 1], | ||
}, | ||
path: ['categories', 1] | ||
} | ||
]; | ||
@@ -472,7 +472,36 @@ const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
(0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
}); | ||
(0, mocha_1.test)('handles $guids with $read and $write', () => { | ||
// must first update to the new id, then create using the new updated id | ||
const mutation_pieces = [ | ||
{ | ||
record: { | ||
$operation: 'create', | ||
user_id: { $guid: 'a', $read: true } | ||
}, | ||
path: ['posts', 1] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
email: 'aa@a.com', | ||
id: { $guid: 'a', $write: true } | ||
}, | ||
path: ['users', 0] | ||
} | ||
]; | ||
const mutate_plan = (0, mutation_batches_1.get_mutation_batches)(global_test_schema_1.global_test_schema, mutation_pieces); | ||
const goal = { | ||
mutation_pieces: [mutation_pieces[1], mutation_pieces[0]], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
}; | ||
(0, chai_1.expect)(mutate_plan).to.deep.equal(goal); | ||
}); | ||
}); | ||
@@ -486,5 +515,5 @@ (0, mocha_1.describe)(mutation_batches_1.run_mutation_plan.name, () => { | ||
$operation: 'create', | ||
id: 1, | ||
id: 1 | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -494,5 +523,5 @@ { | ||
$operation: 'create', | ||
id: 2, | ||
id: 2 | ||
}, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
}, | ||
@@ -502,11 +531,11 @@ { | ||
$operation: 'create', | ||
id: 3, | ||
id: 3 | ||
}, | ||
path: ['users', 2], | ||
}, | ||
path: ['users', 2] | ||
} | ||
], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
}; | ||
@@ -518,3 +547,3 @@ let i = 0; | ||
index: 0, | ||
mutation_batch: mutation_plan.mutation_batches[0], | ||
mutation_batch: mutation_plan.mutation_batches[0] | ||
}); | ||
@@ -525,3 +554,3 @@ } | ||
index: 1, | ||
mutation_batch: mutation_plan.mutation_batches[1], | ||
mutation_batch: mutation_plan.mutation_batches[1] | ||
}); | ||
@@ -528,0 +557,0 @@ } |
@@ -599,3 +599,3 @@ "use strict"; | ||
"label" VARCHAR(450) NOT NULL, | ||
"status" TEXT CHECK (status IN ("running", "pending", "paused")), | ||
"status" TEXT CHECK (status IN ('running', 'pending', 'paused')), | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
@@ -602,0 +602,0 @@ "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
{ | ||
"name": "orma", | ||
"version": "1.0.248", | ||
"version": "1.0.249", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -10,3 +10,3 @@ import { expect } from 'chai' | ||
GlobalTestMutation, | ||
GlobalTestQuery, | ||
GlobalTestQuery | ||
} from '../test_data/global_test_schema' | ||
@@ -17,3 +17,3 @@ import { OrmaSchema } from '../types/schema/schema_types' | ||
test_mutate, | ||
test_query, | ||
test_query | ||
} from './integration_setup.test' | ||
@@ -23,3 +23,3 @@ import { remove_file } from '../helpers/file_helpers' | ||
close_sqlite_database, | ||
open_sqlite_database, | ||
open_sqlite_database | ||
} from './integration_test_helpers' | ||
@@ -35,4 +35,4 @@ | ||
{ name: 'John', age: 25 }, | ||
{ name: 'Jane', age: 30 }, | ||
], | ||
{ name: 'Jane', age: 30 } | ||
] | ||
} as { | ||
@@ -55,19 +55,19 @@ $operation: 'create' | ||
$not_null: true, | ||
$unsigned: true, | ||
$unsigned: true | ||
}, | ||
name: { | ||
$data_type: 'varchar', | ||
$not_null: true, | ||
}, | ||
$not_null: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['user_id'], | ||
$name: 'user_id_pk', | ||
$name: 'user_id_pk' | ||
}, | ||
$unique_keys: [{ $fields: ['name'], $name: 'name_uq' }], | ||
}, | ||
$unique_keys: [{ $fields: ['name'], $name: 'name_uq' }] | ||
} | ||
} | ||
const orma_schema: OrmaSchema = { | ||
$entities, | ||
$cache: generate_orma_schema_cache($entities), | ||
$cache: generate_orma_schema_cache($entities) | ||
} | ||
@@ -84,4 +84,4 @@ | ||
sql_string: | ||
'CREATE TABLE users (user_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, age INTEGER)', | ||
}, | ||
'CREATE TABLE users (user_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, age INTEGER)' | ||
} | ||
]) | ||
@@ -101,4 +101,4 @@ await orma_mutate_run(orma_schema, sqlite3_adapter(db), mutation_plan) | ||
$field: 'id', | ||
$values: [1, 3], | ||
}, | ||
$values: [1, 3] | ||
} | ||
], | ||
@@ -119,11 +119,11 @@ users: { | ||
{ | ||
$lte: ['views', { $escape: 5 }], | ||
$lte: ['views', { $escape: 5 }] | ||
}, | ||
{ | ||
$like: ['title', { $escape: 'First%' }], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
$like: ['title', { $escape: 'First%' }] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} as const satisfies GlobalTestQuery | ||
@@ -140,4 +140,4 @@ | ||
posts: [ | ||
{ id: 1, title: 'First post!', views: 2, user_id: 1 }, | ||
], | ||
{ id: 1, title: 'First post!', views: 2, user_id: 1 } | ||
] | ||
}, | ||
@@ -153,7 +153,7 @@ { | ||
views: 0, | ||
user_id: 3, | ||
}, | ||
], | ||
}, | ||
], | ||
user_id: 3 | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -172,5 +172,5 @@ const modified = clone(original) | ||
$where: { | ||
$eq: ['id', { $escape: 1 }], | ||
}, | ||
}, | ||
$eq: ['id', { $escape: 1 }] | ||
} | ||
} | ||
} as const satisfies GlobalTestQuery) | ||
@@ -182,5 +182,5 @@ | ||
id: 1, | ||
views: 3, | ||
}, | ||
], | ||
views: 3 | ||
} | ||
] | ||
}) | ||
@@ -203,9 +203,9 @@ }) | ||
title: 'First post!', | ||
user_id: { $guid: 'a' }, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
user_id: { $guid: 'a' } | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} as const | ||
@@ -222,3 +222,3 @@ await test_mutate(mutation) | ||
$where: { | ||
$eq: ['email', { $escape: 'aa@a.com' }], | ||
$eq: ['email', { $escape: 'aa@a.com' }] | ||
}, | ||
@@ -229,9 +229,9 @@ likes: { | ||
$where: { | ||
$eq: ['post_id', { $escape: 1 }], | ||
$eq: ['post_id', { $escape: 1 }] | ||
}, | ||
posts: { | ||
title: true, | ||
}, | ||
}, | ||
}, | ||
title: true | ||
} | ||
} | ||
} | ||
}) | ||
@@ -250,7 +250,7 @@ | ||
post_id: 1, | ||
posts: [{ title: 'First post!' }], | ||
}, | ||
], | ||
}, | ||
], | ||
posts: [{ title: 'First post!' }] | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -270,7 +270,7 @@ }) | ||
line_1: '123 guid test st', | ||
resource_id: '1', | ||
}, | ||
], | ||
}, | ||
], | ||
resource_id: '1' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -284,3 +284,3 @@ | ||
$where: { | ||
$eq: ['id', { $escape: 1 }], | ||
$eq: ['id', { $escape: 1 }] | ||
}, | ||
@@ -290,5 +290,5 @@ addresses: { | ||
line_1: true, | ||
$foreign_key: ['billing_address_id'], | ||
}, | ||
}, | ||
$foreign_key: ['billing_address_id'] | ||
} | ||
} | ||
}) | ||
@@ -305,7 +305,7 @@ | ||
id: 1, | ||
line_1: '123 guid test st', | ||
}, | ||
], | ||
}, | ||
], | ||
line_1: '123 guid test st' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -326,9 +326,9 @@ }) | ||
{ | ||
user_id: { $guid: 'a' }, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
user_id: { $guid: 'a' } | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -345,9 +345,9 @@ | ||
id: true, | ||
user_id: true, | ||
}, | ||
user_id: true | ||
} | ||
}, | ||
$where: { | ||
$eq: ['email', { $escape: 'ab@c.com' }], | ||
}, | ||
}, | ||
$eq: ['email', { $escape: 'ab@c.com' }] | ||
} | ||
} | ||
} as const | ||
@@ -363,3 +363,3 @@ const result = await test_query(query) | ||
$operation: 'delete', | ||
users: result.users, | ||
users: result.users | ||
}) | ||
@@ -376,4 +376,4 @@ | ||
title: 'asd test', | ||
user_id: 1234, | ||
}, | ||
user_id: 1234 | ||
} | ||
], | ||
@@ -384,5 +384,5 @@ users: [ | ||
email: 'ab@c.com', | ||
first_name: 'asd', | ||
}, | ||
], | ||
first_name: 'asd' | ||
} | ||
] | ||
}) | ||
@@ -396,8 +396,8 @@ | ||
user_id: true, | ||
title: true, | ||
title: true | ||
}, | ||
$where: { | ||
$eq: ['email', { $escape: 'ab@c.com' }], | ||
}, | ||
}, | ||
$eq: ['email', { $escape: 'ab@c.com' }] | ||
} | ||
} | ||
} as const | ||
@@ -415,7 +415,7 @@ const result = await test_query(query) | ||
user_id: 1234, | ||
title: 'asd test', | ||
}, | ||
], | ||
}, | ||
], | ||
title: 'asd test' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -429,5 +429,5 @@ }) | ||
id: 12345, | ||
line_1: 'ASD TEST', | ||
}, | ||
], | ||
line_1: 'ASD TEST' | ||
} | ||
] | ||
}) | ||
@@ -440,4 +440,4 @@ | ||
$field: 'id', | ||
$values: [1], | ||
}, | ||
$values: [1] | ||
} | ||
], | ||
@@ -448,5 +448,5 @@ addresses: { | ||
$where: { | ||
$eq: ['id', { $escape: 12345 }], | ||
}, | ||
}, | ||
$eq: ['id', { $escape: 12345 }] | ||
} | ||
} | ||
} as const | ||
@@ -461,5 +461,5 @@ const result = await test_query(query) | ||
id: 12345, | ||
line_1: 'ASD TEST', | ||
}, | ||
], | ||
line_1: 'ASD TEST' | ||
} | ||
] | ||
}) | ||
@@ -475,5 +475,5 @@ }) | ||
title: 'unique title', | ||
user_id: 1, | ||
}, | ||
], | ||
user_id: 1 | ||
} | ||
] | ||
}) | ||
@@ -487,5 +487,5 @@ | ||
id: 1, | ||
title: 'unique title', | ||
}, | ||
], | ||
title: 'unique title' | ||
} | ||
] | ||
}) | ||
@@ -502,5 +502,5 @@ expect(undefined).to.equal('Expected an error to be thrown') | ||
title: 'unique title', | ||
user_id: 1, | ||
}, | ||
], | ||
user_id: 1 | ||
} | ||
] | ||
}) | ||
@@ -513,5 +513,5 @@ | ||
id: 12345, | ||
title: 'unique title', | ||
}, | ||
], | ||
title: 'unique title' | ||
} | ||
] | ||
}) | ||
@@ -526,5 +526,5 @@ }) | ||
title: 'unique title', | ||
user_id: 1, | ||
}, | ||
], | ||
user_id: 1 | ||
} | ||
] | ||
}) | ||
@@ -536,5 +536,5 @@ | ||
{ | ||
id: 12345, | ||
}, | ||
], | ||
id: 12345 | ||
} | ||
] | ||
}) | ||
@@ -550,4 +550,4 @@ }) | ||
last_name: 'b', | ||
email: 'a@b.com', | ||
}, | ||
email: 'a@b.com' | ||
} | ||
], | ||
@@ -558,5 +558,5 @@ posts: [ | ||
title: 'unique title', | ||
user_id: 123, | ||
}, | ||
], | ||
user_id: 123 | ||
} | ||
] | ||
}) | ||
@@ -570,4 +570,4 @@ | ||
id: { $guid: 1 }, | ||
email: 'a@b.com', | ||
}, | ||
email: 'a@b.com' | ||
} | ||
], | ||
@@ -578,5 +578,5 @@ likes: [ | ||
user_id: { $guid: 1 }, | ||
post_id: 1231, | ||
}, | ||
], | ||
post_id: 1231 | ||
} | ||
] | ||
}) | ||
@@ -589,4 +589,4 @@ }) | ||
id: true, | ||
$where: { $eq: [{ $escape: 1 }, { $escape: 2 }] }, | ||
}, | ||
$where: { $eq: [{ $escape: 1 }, { $escape: 2 }] } | ||
} | ||
} as const satisfies GlobalTestQuery) | ||
@@ -600,15 +600,15 @@ | ||
id: { | ||
$escape: { $guid: 'a' }, | ||
$escape: { $guid: 'a' } | ||
}, | ||
my_title: { | ||
$escape: ['hi'], | ||
$escape: ['hi'] | ||
}, | ||
total_views: { | ||
$escape: 1, | ||
$escape: 1 | ||
}, | ||
users: { | ||
id: true, | ||
id: true | ||
}, | ||
$limit: 1, | ||
}, | ||
$limit: 1 | ||
} | ||
} as const satisfies GlobalTestQuery) | ||
@@ -624,7 +624,7 @@ | ||
{ | ||
id: 1, | ||
}, | ||
], | ||
}, | ||
], | ||
id: 1 | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -637,6 +637,6 @@ }) | ||
title: true, | ||
$limit: 1, | ||
$limit: 1 | ||
}, | ||
$limit: 1, | ||
}, | ||
$limit: 1 | ||
} | ||
} as const satisfies GlobalTestQuery) | ||
@@ -657,7 +657,7 @@ | ||
{ | ||
$operation: 'update', | ||
}, | ||
], | ||
}, | ||
], | ||
$operation: 'update' | ||
} | ||
] | ||
} | ||
] | ||
} as const satisfies GlobalTestMutation) | ||
@@ -674,7 +674,7 @@ | ||
{ | ||
$operation: 'update', | ||
}, | ||
], | ||
}, | ||
], | ||
$operation: 'update' | ||
} | ||
] | ||
} | ||
] | ||
} as const satisfies GlobalTestMutation) | ||
@@ -681,0 +681,0 @@ |
@@ -5,3 +5,3 @@ import { last } from '../../helpers/helpers' | ||
get_child_edges, | ||
get_parent_edges, | ||
get_parent_edges | ||
} from '../../helpers/schema_helpers' | ||
@@ -17,3 +17,3 @@ import { toposort } from '../../helpers/toposort' | ||
MutationPlanConstraint, | ||
mutation_plan_constraints, | ||
mutation_plan_constraints | ||
} from './mutation_plan_constraints' | ||
@@ -199,3 +199,3 @@ | ||
entity, | ||
record, | ||
record | ||
}) | ||
@@ -211,3 +211,3 @@ ) { | ||
const value = record[edge.from_field] | ||
const value_string = JSON.stringify(value) | ||
const value_string = get_value_string(value) | ||
const new_piece_indices = | ||
@@ -241,3 +241,3 @@ fk_index?.[entity_field_operation_string]?.[value_string] ?? | ||
const entity_field_operation_string = `${entity},${field},${operation}` | ||
const value_string = JSON.stringify(value) | ||
const value_string = get_value_string(value) | ||
if (!fk_index[entity_field_operation_string]) { | ||
@@ -253,2 +253,6 @@ fk_index[entity_field_operation_string] = {} | ||
const get_value_string = value => | ||
// dont include $read or $write props in guids | ||
JSON.stringify(value?.$guid ? { $guid: value.$guid } : value) | ||
/** | ||
@@ -273,3 +277,3 @@ * Sorts mutation pieces in the order they will be executed and also gives batches that say what to run in parallel | ||
start_index, | ||
end_index: start_index + toposort_tier.length, | ||
end_index: start_index + toposort_tier.length | ||
}) | ||
@@ -299,3 +303,3 @@ }) | ||
index: batch_index, | ||
mutation_batch, | ||
mutation_batch | ||
}) | ||
@@ -302,0 +306,0 @@ } |
import { expect } from 'chai' | ||
import { describe, test } from 'mocha' | ||
import { global_test_schema } from '../../../test_data/global_test_schema' | ||
import { | ||
GlobalTestMutation, | ||
global_test_schema, | ||
} from '../../../test_data/global_test_schema' | ||
import { apply_nesting_mutation_macro } from '../../macros/nesting_mutation_macro' | ||
import { | ||
get_mutation_batches, | ||
MutationPiece, | ||
MutationPlan, | ||
run_mutation_plan, | ||
get_mutation_batches, | ||
run_mutation_plan | ||
} from '../mutation_batches' | ||
@@ -21,12 +17,12 @@ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 0], | ||
path: ['users', 0, 'posts', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 1], | ||
}, | ||
path: ['users', 0, 'posts', 1] | ||
} | ||
] | ||
@@ -43,4 +39,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
} | ||
@@ -55,8 +51,8 @@ | ||
record: { $operation: 'create', user_id: 2 }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { user_id: 2, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 0], | ||
}, | ||
path: ['users', 0, 'posts', 0] | ||
} | ||
] | ||
@@ -73,4 +69,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
} | ||
@@ -84,5 +80,5 @@ | ||
record: { id: 1, user_id: 2, $operation: 'update' }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ record: { id: 2, $operation: 'create' }, path: ['users', 0] }, | ||
{ record: { id: 2, $operation: 'create' }, path: ['users', 0] } | ||
] | ||
@@ -98,4 +94,4 @@ const mutate_plan = get_mutation_batches( | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -109,3 +105,3 @@ | ||
{ record: { id: 3, $operation: 'update' }, path: ['users', 1] }, | ||
{ record: { id: 2, $operation: 'update' }, path: ['posts', 0] }, | ||
{ record: { id: 2, $operation: 'update' }, path: ['posts', 0] } | ||
] | ||
@@ -120,3 +116,3 @@ const mutate_plan = get_mutation_batches( | ||
mutation_pieces, | ||
mutation_batches: [{ start_index: 0, end_index: 3 }], | ||
mutation_batches: [{ start_index: 0, end_index: 3 }] | ||
} | ||
@@ -130,8 +126,8 @@ | ||
record: { user_id: { $guid: 2 }, $operation: 'create' }, | ||
path: ['users', 0, 'posts', 0], | ||
path: ['users', 0, 'posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 2 }, $operation: 'create' }, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
] | ||
@@ -148,4 +144,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -159,8 +155,8 @@ | ||
record: { id: { $guid: 1 }, $operation: 'delete' }, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'delete' }, | ||
path: ['users', 0, 'posts', 0], | ||
}, | ||
path: ['users', 0, 'posts', 0] | ||
} | ||
] | ||
@@ -176,4 +172,4 @@ const mutate_plan = get_mutation_batches( | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -188,16 +184,16 @@ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
}, | ||
{ | ||
record: { id: 2, $operation: 'delete' }, | ||
path: ['users', 0, 'posts', 0], | ||
path: ['users', 0, 'posts', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['users', 1, 'posts', 0], | ||
path: ['users', 1, 'posts', 0] | ||
}, | ||
{ | ||
record: { id: 3, post_id: 2, $operation: 'delete' }, | ||
path: ['users', 0, 'posts', 0, 'comments', 0], | ||
}, | ||
path: ['users', 0, 'posts', 0, 'comments', 0] | ||
} | ||
] | ||
@@ -216,8 +212,8 @@ | ||
mutation_pieces[3], | ||
mutation_pieces[2], | ||
mutation_pieces[2] | ||
], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 3 }, | ||
{ start_index: 3, end_index: 5 }, | ||
], | ||
{ start_index: 3, end_index: 5 } | ||
] | ||
} | ||
@@ -229,3 +225,3 @@ | ||
const mutation_pieces: MutationPiece[] = [ | ||
{ record: { $operation: 'update' }, path: ['users', 0] }, | ||
{ record: { $operation: 'update' }, path: ['users', 0] } | ||
] | ||
@@ -240,3 +236,3 @@ | ||
mutation_pieces, | ||
mutation_batches: [{ start_index: 0, end_index: 1 }], | ||
mutation_batches: [{ start_index: 0, end_index: 1 }] | ||
} | ||
@@ -250,8 +246,8 @@ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0], | ||
}, | ||
path: ['posts', 0, 'users', 0] | ||
} | ||
] | ||
@@ -268,4 +264,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -279,12 +275,12 @@ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0], | ||
path: ['posts', 0, 'users', 0] | ||
}, | ||
{ | ||
record: { user_id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0, 'posts', 0], | ||
}, | ||
path: ['posts', 0, 'users', 0, 'posts', 0] | ||
} | ||
] | ||
@@ -301,8 +297,8 @@ | ||
mutation_pieces[0], | ||
mutation_pieces[2], | ||
mutation_pieces[2] | ||
], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
} | ||
@@ -318,10 +314,10 @@ | ||
id: 1, | ||
user_id: { $guid: 1 }, | ||
user_id: { $guid: 1 } | ||
}, | ||
path: ['posts', 0], | ||
path: ['posts', 0] | ||
}, | ||
{ | ||
record: { id: { $guid: 1 }, $operation: 'create' }, | ||
path: ['posts', 0, 'users', 0], | ||
}, | ||
path: ['posts', 0, 'users', 0] | ||
} | ||
] | ||
@@ -338,4 +334,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -359,5 +355,5 @@ | ||
id: 2, // update id by email, so this needs to happen after the delete | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -368,6 +364,6 @@ { | ||
id: 1, | ||
user_id: 1, | ||
user_id: 1 | ||
}, | ||
path: ['posts', 1], | ||
}, | ||
path: ['posts', 1] | ||
} | ||
] | ||
@@ -384,4 +380,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -398,5 +394,5 @@ | ||
id: 1, | ||
user_id: 2, | ||
user_id: 2 | ||
}, | ||
path: ['posts', 1], | ||
path: ['posts', 1] | ||
}, | ||
@@ -409,6 +405,6 @@ { | ||
id: 2, // update id by email, so this needs to happen after the delete | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
] | ||
@@ -425,4 +421,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -437,5 +433,5 @@ | ||
$operation: 'delete', | ||
id: 1, | ||
id: 1 | ||
}, | ||
path: ['addresses', 0], | ||
path: ['addresses', 0] | ||
}, | ||
@@ -446,6 +442,6 @@ { | ||
id: 1, | ||
billing_address_id: null, | ||
billing_address_id: null | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
] | ||
@@ -462,4 +458,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -475,5 +471,5 @@ | ||
$operation: 'create', | ||
user_id: 2, | ||
user_id: 2 | ||
}, | ||
path: ['posts', 1], | ||
path: ['posts', 1] | ||
}, | ||
@@ -485,6 +481,6 @@ { | ||
id: 2, // update id by email, so this needs to happen first | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
] | ||
@@ -501,4 +497,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -514,5 +510,5 @@ | ||
$operation: 'update', | ||
user_id: 2, | ||
user_id: 2 | ||
}, | ||
path: ['posts', 1], | ||
path: ['posts', 1] | ||
}, | ||
@@ -524,6 +520,6 @@ { | ||
id: 2, // update id by email, so this needs to happen first | ||
$identifying_fields: ['email'], | ||
$identifying_fields: ['email'] | ||
}, | ||
path: ['users', 0], | ||
}, | ||
path: ['users', 0] | ||
} | ||
] | ||
@@ -540,4 +536,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -554,5 +550,5 @@ | ||
id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' } | ||
}, | ||
path: ['categories', 0], | ||
path: ['categories', 0] | ||
}, | ||
@@ -563,6 +559,6 @@ { | ||
id: 2, | ||
parent_category_id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' } | ||
}, | ||
path: ['categories', 1], | ||
}, | ||
path: ['categories', 1] | ||
} | ||
] | ||
@@ -579,4 +575,4 @@ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 }, | ||
], | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
@@ -586,2 +582,37 @@ | ||
}) | ||
test('handles $guids with $read and $write', () => { | ||
// must first update to the new id, then create using the new updated id | ||
const mutation_pieces: MutationPiece[] = [ | ||
{ | ||
record: { | ||
$operation: 'create', | ||
user_id: { $guid: 'a', $read: true } | ||
}, | ||
path: ['posts', 1] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
email: 'aa@a.com', | ||
id: { $guid: 'a', $write: true } | ||
}, | ||
path: ['users', 0] | ||
} | ||
] | ||
const mutate_plan = get_mutation_batches( | ||
global_test_schema, | ||
mutation_pieces | ||
) | ||
const goal = { | ||
mutation_pieces: [mutation_pieces[1], mutation_pieces[0]], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 2 } | ||
] | ||
} | ||
expect(mutate_plan).to.deep.equal(goal) | ||
}) | ||
}) | ||
@@ -598,5 +629,5 @@ describe(run_mutation_plan.name, () => { | ||
$operation: 'create', | ||
id: 1, | ||
id: 1 | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -606,5 +637,5 @@ { | ||
$operation: 'create', | ||
id: 2, | ||
id: 2 | ||
}, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
}, | ||
@@ -614,11 +645,11 @@ { | ||
$operation: 'create', | ||
id: 3, | ||
id: 3 | ||
}, | ||
path: ['users', 2], | ||
}, | ||
path: ['users', 2] | ||
} | ||
], | ||
mutation_batches: [ | ||
{ start_index: 0, end_index: 1 }, | ||
{ start_index: 1, end_index: 3 }, | ||
], | ||
{ start_index: 1, end_index: 3 } | ||
] | ||
} | ||
@@ -631,3 +662,3 @@ | ||
index: 0, | ||
mutation_batch: mutation_plan.mutation_batches[0], | ||
mutation_batch: mutation_plan.mutation_batches[0] | ||
}) | ||
@@ -637,3 +668,3 @@ } else { | ||
index: 1, | ||
mutation_batch: mutation_plan.mutation_batches[1], | ||
mutation_batch: mutation_plan.mutation_batches[1] | ||
}) | ||
@@ -640,0 +671,0 @@ } |
@@ -677,3 +677,3 @@ import { expect } from 'chai' | ||
"label" VARCHAR(450) NOT NULL, | ||
"status" TEXT CHECK (status IN ("running", "pending", "paused")), | ||
"status" TEXT CHECK (status IN ('running', 'pending', 'paused')), | ||
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
@@ -680,0 +680,0 @@ "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
251
TODO.md
@@ -86,2 +86,253 @@ Bugs | ||
$from: 'items' | ||
} | ||
- refactor | ||
- new syntax | ||
- query | ||
- asd | ||
- asd | ||
- asd | ||
- asd | ||
- asd | ||
1. | ||
current: | ||
- most concise (least indentation and lines of code) | ||
- $ are annoying to type and double-click to select doesnt select them | ||
- probably source of slow types | ||
- $ are ugly and makes things seem complicated | ||
- medium difficulty to get list of selected things ( Object.keys(items).filter(el => el[0] !== '$') ) | ||
- cant select renamed things with a $ without having a separate $select syntax (e.g. having $operation: 'create' on each returned row) | ||
{ | ||
$where_connected: [], | ||
items: { | ||
id: true, | ||
my_sku: 'sku', | ||
_mutable: { | ||
$escape: false | ||
} | ||
lowercase_sku: { | ||
$lower: 'sku' | ||
} | ||
my_variants: { | ||
$from: 'variants', | ||
asin: true, | ||
products: { | ||
vendors: { | ||
name: true | ||
} | ||
} | ||
}, | ||
$order_by: [{ | ||
$desc: 'id' | ||
}], | ||
$where: { | ||
$or: [{ | ||
$eq: ['id', { | ||
$escape: 1 | ||
}] | ||
}], | ||
$any_path: [['variants'], { | ||
$in: ['ASIN', { | ||
$escape: ['a', 'b'] | ||
}] | ||
}] | ||
} | ||
} | ||
} | ||
option 1 (object select and separate nest): | ||
- allows user to choose inline (e.g. mysql does it in the select) subqueries, vs orma nested subqueries (done as separate queries) | ||
- no $ | ||
- indentation is doubled from option 1 | ||
- possibility of selecting and nesting something with the same name (which is impossible to represent if the output is a json object) | ||
{ | ||
where_connected: [], | ||
nest: { | ||
items: { | ||
select: { | ||
id: true, | ||
my_sku: 'sku', | ||
_mutable: { | ||
escape: false | ||
} | ||
lowercase_sku: { | ||
lower: 'sku' | ||
} | ||
}, | ||
nest: { | ||
my_variants: { | ||
from: 'variants', | ||
select: { | ||
asin: true | ||
}, | ||
nest: { | ||
products: { | ||
nest: { | ||
vendors: { | ||
select: { | ||
name: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
order_by: [{ | ||
desc: 'id' | ||
}], | ||
where: { | ||
or: [{ | ||
eq: ['id', { | ||
escape: 1 | ||
}] | ||
}], | ||
any_path: [['variants'], { | ||
in: ['ASIN', { | ||
escape: ['a', 'b'] | ||
}] | ||
}] | ||
} | ||
} | ||
} | ||
} | ||
option 2 (object select and combined nest): | ||
- similar to option 1 | ||
- no clear way to do inline selects (maybe would need an extra keyword or something) | ||
- slightly less lines of code than option 1 | ||
- impossible to select and nest something with the same name (since the query object matches the result object) | ||
{ | ||
where_connected: [], | ||
select: { | ||
items: { | ||
select: { | ||
id: true, | ||
my_sku: 'sku', | ||
_mutable: { | ||
escape: false | ||
} | ||
lowercase_sku: { | ||
lower: 'sku' | ||
}, | ||
my_variants: { | ||
from: 'variants', | ||
select: { | ||
asin: true | ||
products: { | ||
select: { | ||
vendors: { | ||
select: { | ||
name: true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
order_by: [{ | ||
desc: 'id' | ||
}], | ||
where: { | ||
or: [{ | ||
eq: ['id', { | ||
escape: 1 | ||
}] | ||
}], | ||
any_path: [['variants'], { | ||
in: ['ASIN', { | ||
escape: ['a', 'b'] | ||
}] | ||
}] | ||
} | ||
} | ||
} | ||
} | ||
option 3 (array select and separate array nest): | ||
- lose tons of typesafety due to arrays | ||
- looks bad and confusing | ||
- hard to work with programattically | ||
- find if something is selected | ||
- object: items.select.id | ||
- array: items.find(el => el === 'id' || el?.as?.[1] === 'id') | ||
- prop into something (in a way that wont break if something else is added to the query) | ||
- object: items.nest.variants.nest.vendors.select.name | ||
- array: items.nest | ||
.find(el => el?.as[1] === 'my_variants') | ||
?.find(el => el.from === 'products') | ||
?.find(el => el.from === 'vendors') | ||
?.select?.find(el => el === 'name') | ||
- array code wont have proper type guarantees because find could return null | ||
- query syntax allow selecting the same thing multiple times which in theory matches sql better, but the query output would also need to return an array instead of an object to take advantage of this | ||
{ | ||
nest: [{ | ||
select: [ | ||
'id', | ||
{ as: ['sku', 'my_sku'] }, | ||
{ | ||
as: ['_mutable', { | ||
escape: false | ||
}] | ||
}, | ||
{ | ||
as: ['lowercase_sku', { | ||
escape: 'sku' | ||
}] | ||
}, | ||
], | ||
from: 'items', | ||
nest: [{ | ||
$as: [{ | ||
select: ['asin'], | ||
from: 'variants', | ||
nest: [{ | ||
from: 'products', | ||
nest: [{ | ||
from: 'vendors', | ||
select: ['name'] | ||
}] | ||
}] | ||
}, 'my_variants'] | ||
}], | ||
order_by: [{ | ||
desc: 'id' | ||
}], | ||
where: { | ||
or: [{ | ||
eq: ['id', { | ||
escape: 1 | ||
}] | ||
}], | ||
any_path: [['variants'], { | ||
in: ['ASIN', { | ||
escape: ['a', 'b'] | ||
}] | ||
}] | ||
} | ||
}] | ||
} | ||
Mutation syntax: | ||
current: | ||
{ | ||
$operation: 'create' | ||
items: [{ | ||
id: { $guid: 'a'}, | ||
sku: '1234', | ||
variants: [{ | ||
}] | ||
}] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1673402
40802