Comparing version 1.0.261 to 1.0.262
@@ -14,3 +14,3 @@ "use strict"; | ||
id: 2, | ||
title: 'pc', | ||
title: 'pc' | ||
}); | ||
@@ -25,4 +25,4 @@ }); | ||
body_html: 'Computer', | ||
old_column: 'hi', | ||
}, | ||
old_column: 'hi' | ||
} | ||
}; | ||
@@ -35,4 +35,4 @@ const modified = { | ||
body_html: 'Computer', | ||
new_column: 'ho', | ||
}, | ||
new_column: 'ho' | ||
} | ||
}; | ||
@@ -47,4 +47,4 @@ const update_obj = (0, diff_mutation_1.get_mutation_diff)(original, modified); | ||
title: 'pc', | ||
new_column: 'ho', | ||
}, | ||
new_column: 'ho' | ||
} | ||
}); | ||
@@ -56,3 +56,3 @@ }); | ||
{ id: 1, sku: 'deleteme' }, | ||
{ id: 2, sku: 'mysku' }, | ||
{ id: 2, sku: 'mysku' } | ||
]; | ||
@@ -65,4 +65,4 @@ const modified = [{ id: 2, sku: 'mysku' }]; | ||
id: 1, | ||
sku: 'deleteme', | ||
}, | ||
sku: 'deleteme' | ||
} | ||
]); | ||
@@ -78,4 +78,4 @@ }); | ||
$operation: 'create', | ||
sku: 'mysku', | ||
}, | ||
sku: 'mysku' | ||
} | ||
]); | ||
@@ -91,4 +91,4 @@ }); | ||
id: 2, | ||
sku: 'mysku2', | ||
}, | ||
sku: 'mysku2' | ||
} | ||
]); | ||
@@ -99,7 +99,7 @@ }); | ||
{ id: 1, label: 'a' }, | ||
{ id: 2, label: 'b' }, | ||
{ id: 2, label: 'b' } | ||
]; | ||
const modified = [ | ||
{ id: 2, label: 'b' }, | ||
{ id: 1, label: 'a' }, | ||
{ id: 1, label: 'a' } | ||
]; | ||
@@ -119,5 +119,5 @@ const update_obj = (0, diff_mutation_1.get_mutation_diff)(original, modified); | ||
$operation: 'create', | ||
title: 'computer', | ||
}, | ||
], | ||
title: 'computer' | ||
} | ||
] | ||
}); | ||
@@ -137,3 +137,3 @@ }); | ||
$operation: 'create', | ||
note: 'some data', | ||
note: 'some data' | ||
}); | ||
@@ -151,6 +151,6 @@ }); | ||
product_id: { | ||
$guid: 1, // no operation create here, since it is a guid | ||
}, | ||
}, | ||
], | ||
$guid: 1 // no operation create here, since it is a guid | ||
} | ||
} | ||
] | ||
}); | ||
@@ -165,7 +165,7 @@ }); | ||
{ | ||
url: 'test', | ||
}, | ||
], | ||
}, | ||
], | ||
url: 'test' | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
@@ -181,7 +181,7 @@ const update_obj = (0, diff_mutation_1.get_mutation_diff)(original, modified); | ||
$operation: 'create', | ||
url: 'test', | ||
}, | ||
], | ||
}, | ||
], | ||
url: 'test' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -202,7 +202,7 @@ }); | ||
$operation: 'delete', | ||
id: 2, | ||
}, | ||
], | ||
}, | ||
], | ||
id: 2 | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
@@ -212,8 +212,8 @@ }); | ||
const original = { | ||
images: [{ id: 1 }], | ||
images: [{ id: 1 }] | ||
}; | ||
const modified = { | ||
images: [ | ||
{ id: 1, $identifying_fields: ['id'], $operation: 'update' }, | ||
], | ||
{ id: 1, $identifying_fields: ['id'], $operation: 'update' } | ||
] | ||
}; | ||
@@ -227,7 +227,30 @@ const update_obj = (0, diff_mutation_1.get_mutation_diff)(original, modified); | ||
$identifying_fields: ['id'], | ||
$operation: 'update', | ||
}, | ||
], | ||
$operation: 'update' | ||
} | ||
] | ||
}); | ||
}); | ||
mocha_1.test.skip('handles deletes when entire array is removed', () => { | ||
const original = { | ||
users: [{ id: 1, posts: [{ id: 2 }] }] | ||
}; | ||
const modified = { | ||
users: [{ id: 1 }] | ||
}; | ||
const update_obj = (0, diff_mutation_1.get_mutation_diff)(original, modified); | ||
(0, chai_1.expect)(update_obj).to.deep.equal({ | ||
$operation: 'update', | ||
users: [ | ||
{ | ||
id: 1, | ||
posts: [ | ||
{ | ||
$operation: 'delete', | ||
id: 2 | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}); | ||
}); |
@@ -134,5 +134,12 @@ "use strict"; | ||
const piece_indices_by_value = (_c = fk_index[entity_field_operation_string]) !== null && _c !== void 0 ? _c : {}; | ||
// no_match type is only for foreign keys that dont match (check examples) | ||
// no_match type is only for foreign keys that dont match (check examples). | ||
// for no_match, we assume $guids are $read and not making any change, and so ignore them | ||
// (this isnt necessarily true, but not doing this can cause unnecessary constraints that make | ||
// cycles in the toposort so we make this assumption for now. Really we would want to know if the | ||
// $guid is read or write, and only make a constraint in the write case.) | ||
const key_guid_string = '{"$guid":'; | ||
const new_piece_indices = Object.keys(piece_indices_by_value) | ||
.filter(key => key !== value_string) | ||
.filter(key => key !== value_string && | ||
!(key === null || key === void 0 ? void 0 : key.startsWith(key_guid_string)) && | ||
!(value_string === null || value_string === void 0 ? void 0 : value_string.startsWith(key_guid_string))) | ||
.map(key => piece_indices_by_value[key]) | ||
@@ -139,0 +146,0 @@ .flat(); |
@@ -19,5 +19,5 @@ "use strict"; | ||
title: 'hi', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -31,5 +31,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
$where: { | ||
$eq: ['title', { $escape: 'hi' }], | ||
}, | ||
}, | ||
$eq: ['title', { $escape: 'hi' }] | ||
} | ||
} | ||
}); | ||
@@ -48,5 +48,5 @@ }); | ||
age: 20, | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -64,3 +64,3 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
{ | ||
$eq: ['email', { $escape: 'a@a.com' }], | ||
$eq: ['email', { $escape: 'a@a.com' }] | ||
}, | ||
@@ -70,8 +70,8 @@ { | ||
['first_name', 'last_name'], | ||
[{ $escape: 'john' }, { $escape: 'smith' }], | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
[{ $escape: 'john' }, { $escape: 'smith' }] | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
@@ -85,3 +85,3 @@ }); | ||
title: 'hi', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
@@ -92,3 +92,3 @@ { | ||
title: 'as', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
@@ -99,7 +99,7 @@ { | ||
user_id: 1, | ||
title: '123', | ||
}, | ||
title: '123' | ||
} | ||
].map((el, i) => ({ | ||
path: ['posts', i], | ||
record: el, | ||
record: el | ||
})); | ||
@@ -115,3 +115,3 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
{ | ||
$eq: ['id', { $escape: 14 }], | ||
$eq: ['id', { $escape: 14 }] | ||
}, | ||
@@ -121,8 +121,8 @@ { | ||
'title', | ||
[{ $escape: 'hi' }, { $escape: '123' }], | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
[{ $escape: 'hi' }, { $escape: '123' }] | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
@@ -139,5 +139,5 @@ }); | ||
views: 123, | ||
$identifying_fields: ['title'], | ||
}, | ||
}, | ||
$identifying_fields: ['title'] | ||
} | ||
} | ||
]; | ||
@@ -159,5 +159,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
first_name: 'john', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -173,5 +173,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
$where: { | ||
$eq: ['first_name', { $escape: 'john' }], | ||
}, | ||
}, | ||
$eq: ['first_name', { $escape: 'john' }] | ||
} | ||
} | ||
}); | ||
@@ -188,5 +188,5 @@ }); | ||
last_name: 'smith', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -204,6 +204,6 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
['first_name', 'last_name'], | ||
[{ $escape: 'john' }, { $escape: 'smith' }], | ||
], | ||
}, | ||
}, | ||
[{ $escape: 'john' }, { $escape: 'smith' }] | ||
] | ||
} | ||
} | ||
}); | ||
@@ -220,5 +220,5 @@ }); | ||
first_name: { $guid: 1 }, | ||
last_name: 'smith', | ||
}, | ||
}, | ||
last_name: 'smith' | ||
} | ||
} | ||
]; | ||
@@ -236,10 +236,10 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
{ | ||
$eq: ['email', { $escape: 'a@a.com' }], | ||
$eq: ['email', { $escape: 'a@a.com' }] | ||
}, | ||
{ | ||
$eq: ['last_name', { $escape: 'smith' }], | ||
}, | ||
], | ||
}, | ||
}, | ||
$eq: ['last_name', { $escape: 'smith' }] | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
@@ -255,4 +255,4 @@ }); | ||
title: 'title 1', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -265,4 +265,4 @@ { | ||
title: 'title 2', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -275,5 +275,5 @@ { | ||
email: 'a@a.com', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -289,5 +289,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
'title', | ||
[{ $escape: 'title 1' }, { $escape: 'title 2' }], | ||
], | ||
}, | ||
[{ $escape: 'title 1' }, { $escape: 'title 2' }] | ||
] | ||
} | ||
}, | ||
@@ -300,5 +300,5 @@ users: { | ||
$where: { | ||
$eq: ['email', { $escape: 'a@a.com' }], | ||
}, | ||
}, | ||
$eq: ['email', { $escape: 'a@a.com' }] | ||
} | ||
} | ||
}); | ||
@@ -313,8 +313,8 @@ }); | ||
field2: 'b', | ||
field3: 'c', | ||
field3: 'c' | ||
}, | ||
{ | ||
field1: 'a', | ||
field2: 'x', | ||
}, | ||
field2: 'x' | ||
} | ||
]; | ||
@@ -324,12 +324,12 @@ const records2 = [ | ||
field1: 'x', | ||
field2: 'b', | ||
field2: 'b' | ||
}, | ||
{ | ||
field1: 'a', | ||
field2: 'b', | ||
}, | ||
field2: 'b' | ||
} | ||
]; | ||
const result = (0, verify_uniqueness_1.get_duplicate_record_indices)(records1, records2, [ | ||
'field1', | ||
'field2', | ||
'field2' | ||
]); | ||
@@ -341,4 +341,4 @@ (0, chai_1.expect)(result).to.deep.equal([[0, 1]]); | ||
{ | ||
field1: 'a', | ||
}, | ||
field1: 'a' | ||
} | ||
]; | ||
@@ -348,3 +348,3 @@ const records2 = []; | ||
'field1', | ||
'field2', | ||
'field2' | ||
]); | ||
@@ -363,4 +363,4 @@ (0, chai_1.expect)(result).to.deep.equal([]); | ||
email: 'a', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -373,5 +373,5 @@ { | ||
label: 'hi', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -383,4 +383,4 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
id: 1, | ||
email: 'a', | ||
}, | ||
email: 'a' | ||
} | ||
], | ||
@@ -390,5 +390,5 @@ categories: [ | ||
id: 2, | ||
label: 'hi', | ||
}, | ||
], | ||
label: 'hi' | ||
} | ||
] | ||
}; | ||
@@ -399,3 +399,3 @@ const errors = (0, verify_uniqueness_1.get_database_uniqueness_errors)(global_test_schema_1.global_test_schema, mutation_pieces, piece_indices_by_entity, database_records_by_entity); | ||
['users', 0], | ||
['categories', 0], | ||
['categories', 0] | ||
]); | ||
@@ -411,4 +411,4 @@ }); | ||
line_1: 'a', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -420,5 +420,5 @@ { | ||
id: 12, | ||
line_1: 'c', | ||
}, | ||
}, | ||
line_1: 'c' | ||
} | ||
} | ||
]; | ||
@@ -430,5 +430,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
id: 12, | ||
line_1: 'b', | ||
}, | ||
], | ||
line_1: 'b' | ||
} | ||
] | ||
}; | ||
@@ -447,5 +447,5 @@ const errors = (0, verify_uniqueness_1.get_database_uniqueness_errors)(global_test_schema_1.global_test_schema, mutation_pieces, piece_indices_by_entity, database_records_by_entity); | ||
last_name: 'a', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -458,5 +458,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
first_name: 'john', | ||
last_name: 'b', | ||
}, | ||
], | ||
last_name: 'b' | ||
} | ||
] | ||
}; | ||
@@ -474,5 +474,5 @@ const errors = (0, verify_uniqueness_1.get_database_uniqueness_errors)(global_test_schema_1.global_test_schema, mutation_pieces, piece_indices_by_entity, database_records_by_entity); | ||
email: null, | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -484,5 +484,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
id: 12, | ||
email: null, | ||
}, | ||
], | ||
email: null | ||
} | ||
] | ||
}; | ||
@@ -500,5 +500,5 @@ const errors = (0, verify_uniqueness_1.get_database_uniqueness_errors)(global_test_schema_1.global_test_schema, mutation_pieces, piece_indices_by_entity, database_records_by_entity); | ||
email: {}, | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
]; | ||
@@ -510,5 +510,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
id: 12, | ||
email: null, | ||
}, | ||
], | ||
email: null | ||
} | ||
] | ||
}; | ||
@@ -528,5 +528,5 @@ const errors = (0, verify_uniqueness_1.get_database_uniqueness_errors)(global_test_schema_1.global_test_schema, mutation_pieces, piece_indices_by_entity, database_records_by_entity); | ||
last_name: 'smith', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -539,5 +539,5 @@ { | ||
last_name: 'doe', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
}, | ||
@@ -550,5 +550,5 @@ { | ||
last_name: 'smith', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 2], | ||
path: ['users', 2] | ||
}, | ||
@@ -560,6 +560,6 @@ { | ||
line_1: 'hi', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['addresses', 0], | ||
}, | ||
path: ['addresses', 0] | ||
} | ||
]; | ||
@@ -577,5 +577,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
id: 12, | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -586,6 +586,6 @@ { | ||
id: 12, | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
}, | ||
path: ['users', 1] | ||
} | ||
]; | ||
@@ -603,5 +603,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
email: [{}], | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -613,6 +613,6 @@ { | ||
email: [{}], | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
}, | ||
path: ['users', 1] | ||
} | ||
]; | ||
@@ -630,5 +630,5 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
email: 'a@a.com', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -640,6 +640,60 @@ { | ||
email: 'a@a.com', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
} | ||
]; | ||
const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); | ||
const errors = (0, verify_uniqueness_1.get_mutation_uniqueness_errors)(global_test_schema_1.global_test_schema, mutation_pieces, piece_indices_by_entity); | ||
(0, chai_1.expect)(errors.length).to.equal(0); | ||
}); | ||
(0, mocha_1.test)('handles partially null unique keys', () => { | ||
// none of these cause sql errors | ||
const mutation_pieces = [ | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: '1' | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: '2' | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: null | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: null | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1' | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1' | ||
}, | ||
path: ['tax_codes', 0] | ||
} | ||
]; | ||
@@ -646,0 +700,0 @@ const piece_indices_by_entity = get_piece_indices_by_entity(mutation_pieces); |
@@ -195,6 +195,10 @@ import { OrmaMutation } from '../types/mutation/mutation_types'; | ||
readonly $enum_values: readonly ["TAX1", "TAX2", "TAX3"]; | ||
readonly $not_null: true; | ||
}; | ||
readonly tax_subcode: { | ||
readonly $data_type: "varchar"; | ||
}; | ||
}; | ||
readonly $unique_keys: readonly [{ | ||
readonly $fields: readonly ["tax_code"]; | ||
readonly $fields: readonly ["tax_code", "tax_subcode"]; | ||
readonly $name: "tax_code_uq"; | ||
@@ -201,0 +205,0 @@ }]; |
@@ -12,31 +12,31 @@ "use strict"; | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
first_name: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
last_name: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
email: { | ||
$data_type: 'varchar', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
billing_address_id: { | ||
$data_type: 'int', | ||
$data_type: 'int' | ||
}, | ||
shipping_address_id: { | ||
$data_type: 'int', | ||
}, | ||
$data_type: 'int' | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
$unique_keys: [ | ||
{ | ||
$fields: ['email'], | ||
$fields: ['email'] | ||
}, | ||
{ | ||
$fields: ['first_name', 'last_name'], | ||
}, | ||
$fields: ['first_name', 'last_name'] | ||
} | ||
], | ||
@@ -48,4 +48,4 @@ $foreign_keys: [ | ||
$entity: 'addresses', | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -56,6 +56,6 @@ { | ||
$entity: 'addresses', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -68,11 +68,11 @@ posts: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
user_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
title: { | ||
$data_type: 'varchar', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
@@ -82,7 +82,7 @@ views: { | ||
$not_null: true, | ||
$default: 0, | ||
}, | ||
$default: 0 | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -92,4 +92,4 @@ $unique_keys: [ | ||
$name: 'unique_title', | ||
$fields: ['title'], | ||
}, | ||
$fields: ['title'] | ||
} | ||
], | ||
@@ -101,6 +101,6 @@ $foreign_keys: [ | ||
$entity: 'users', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -113,15 +113,15 @@ likes: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
user_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
post_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
}, | ||
$not_null: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -131,4 +131,4 @@ $unique_keys: [ | ||
$name: 'unique_user_id_post_id', | ||
$fields: ['user_id', 'post_id'], | ||
}, | ||
$fields: ['user_id', 'post_id'] | ||
} | ||
], | ||
@@ -140,4 +140,4 @@ $foreign_keys: [ | ||
$entity: 'users', | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -148,6 +148,6 @@ { | ||
$entity: 'posts', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -160,11 +160,11 @@ comments: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
post_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
}, | ||
$not_null: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -176,6 +176,6 @@ $foreign_keys: [ | ||
$entity: 'posts', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -188,13 +188,13 @@ addresses: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
line_1: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
resource_id: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
tax_code_id: { | ||
$data_type: 'int', | ||
}, | ||
$data_type: 'int' | ||
} | ||
}, | ||
@@ -204,7 +204,7 @@ $unique_keys: [ | ||
$fields: ['resource_id'], | ||
$name: 'resource_uq', | ||
}, | ||
$name: 'resource_uq' | ||
} | ||
], | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -216,6 +216,6 @@ $foreign_keys: [ | ||
$entity: 'tax_codes', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -228,3 +228,3 @@ tax_codes: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
@@ -234,13 +234,17 @@ tax_code: { | ||
$enum_values: ['TAX1', 'TAX2', 'TAX3'], | ||
$not_null: true | ||
}, | ||
tax_subcode: { | ||
$data_type: 'varchar' | ||
} | ||
}, | ||
$unique_keys: [ | ||
{ | ||
$fields: ['tax_code'], | ||
$name: 'tax_code_uq', | ||
}, | ||
$fields: ['tax_code', 'tax_subcode'], | ||
$name: 'tax_code_uq' | ||
} | ||
], | ||
$primary_key: { | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -253,3 +257,3 @@ categories: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
@@ -259,7 +263,7 @@ label: { | ||
$not_null: true, | ||
$precision: 10, | ||
$precision: 10 | ||
}, | ||
parent_category_id: { $data_type: 'int' }, | ||
resource_id: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
@@ -270,7 +274,7 @@ size: { | ||
$scale: 2, | ||
$unsigned: true, | ||
}, | ||
$unsigned: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -280,10 +284,11 @@ $unique_keys: [ | ||
$name: 'label_uq', | ||
$fields: ['label'], | ||
$fields: ['label'] | ||
}, | ||
{ | ||
$name: 'resource_uq', | ||
$fields: ['resource_id'], | ||
}, | ||
$fields: ['resource_id'] | ||
} | ||
], | ||
$foreign_keys: [{ | ||
$foreign_keys: [ | ||
{ | ||
$fields: ['parent_category_id'], | ||
@@ -293,4 +298,5 @@ $references: { | ||
$fields: ['id'] | ||
}, | ||
}] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -302,15 +308,15 @@ post_has_categories: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
category_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
main_category: { | ||
$data_type: 'tinyint', | ||
$precision: 1, | ||
}, | ||
$precision: 1 | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['post_id', 'category_id'], | ||
$fields: ['post_id', 'category_id'] | ||
}, | ||
@@ -323,4 +329,4 @@ $foreign_keys: [ | ||
$entity: 'posts', | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -332,7 +338,7 @@ { | ||
$entity: 'categories', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
}, | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -345,3 +351,3 @@ $cache: { | ||
to_entity: 'users', | ||
to_field: 'billing_address_id', | ||
to_field: 'billing_address_id' | ||
}, | ||
@@ -351,4 +357,4 @@ { | ||
to_entity: 'users', | ||
to_field: 'shipping_address_id', | ||
}, | ||
to_field: 'shipping_address_id' | ||
} | ||
], | ||
@@ -359,8 +365,8 @@ tax_codes: [ | ||
to_entity: 'addresses', | ||
to_field: 'tax_code_id', | ||
}, | ||
to_field: 'tax_code_id' | ||
} | ||
], | ||
users: [ | ||
{ from_field: 'id', to_entity: 'posts', to_field: 'user_id' }, | ||
{ from_field: 'id', to_entity: 'likes', to_field: 'user_id' }, | ||
{ from_field: 'id', to_entity: 'likes', to_field: 'user_id' } | ||
], | ||
@@ -372,3 +378,3 @@ posts: [ | ||
to_entity: 'comments', | ||
to_field: 'post_id', | ||
to_field: 'post_id' | ||
}, | ||
@@ -378,4 +384,4 @@ { | ||
to_entity: 'post_has_categories', | ||
to_field: 'post_id', | ||
}, | ||
to_field: 'post_id' | ||
} | ||
], | ||
@@ -386,3 +392,3 @@ categories: [ | ||
to_entity: 'post_has_categories', | ||
to_field: 'category_id', | ||
to_field: 'category_id' | ||
}, | ||
@@ -392,7 +398,7 @@ { | ||
to_entity: 'categories', | ||
to_field: 'parent_category_id', | ||
}, | ||
], | ||
}, | ||
}, | ||
to_field: 'parent_category_id' | ||
} | ||
] | ||
} | ||
} | ||
}; |
@@ -18,3 +18,3 @@ "use strict"; | ||
to_entity: 'addresses', | ||
from_field: 'billing_address_id', | ||
from_field: 'billing_address_id' | ||
}; | ||
@@ -24,3 +24,3 @@ // wrong entity | ||
// @ts-expect-error | ||
to_entity: 'products', | ||
to_entity: 'products' | ||
}; | ||
@@ -31,3 +31,3 @@ } | ||
from_field: 'id', | ||
to_entity: 'posts', | ||
to_entity: 'posts' | ||
}; | ||
@@ -37,3 +37,3 @@ // wrong edge direction | ||
// @ts-expect-error | ||
to_entity: 'addresses', | ||
to_entity: 'addresses' | ||
}; | ||
@@ -45,3 +45,3 @@ } | ||
from_field: 'id', | ||
to_entity: 'posts', | ||
to_entity: 'posts' | ||
}; | ||
@@ -51,3 +51,3 @@ // edge to parent | ||
to_entity: 'addresses', | ||
from_field: 'shipping_address_id', | ||
from_field: 'shipping_address_id' | ||
}; | ||
@@ -57,3 +57,3 @@ // only allow edges from users | ||
//@ts-expect-error | ||
to_entity: 'comments', | ||
to_entity: 'comments' | ||
}; | ||
@@ -60,0 +60,0 @@ } |
{ | ||
"name": "orma", | ||
"version": "1.0.261", | ||
"version": "1.0.262", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -13,3 +13,3 @@ import { expect } from 'chai' | ||
id: 2, | ||
title: 'pc', | ||
title: 'pc' | ||
}) | ||
@@ -24,4 +24,4 @@ }) | ||
body_html: 'Computer', | ||
old_column: 'hi', | ||
}, | ||
old_column: 'hi' | ||
} | ||
} | ||
@@ -34,4 +34,4 @@ const modified = { | ||
body_html: 'Computer', | ||
new_column: 'ho', | ||
}, | ||
new_column: 'ho' | ||
} | ||
} | ||
@@ -46,4 +46,4 @@ const update_obj = get_mutation_diff(original, modified) | ||
title: 'pc', | ||
new_column: 'ho', | ||
}, | ||
new_column: 'ho' | ||
} | ||
}) | ||
@@ -56,3 +56,3 @@ }) | ||
{ id: 1, sku: 'deleteme' }, | ||
{ id: 2, sku: 'mysku' }, | ||
{ id: 2, sku: 'mysku' } | ||
] | ||
@@ -66,4 +66,4 @@ const modified = [{ id: 2, sku: 'mysku' }] | ||
id: 1, | ||
sku: 'deleteme', | ||
}, | ||
sku: 'deleteme' | ||
} | ||
]) | ||
@@ -80,4 +80,4 @@ }) | ||
$operation: 'create', | ||
sku: 'mysku', | ||
}, | ||
sku: 'mysku' | ||
} | ||
]) | ||
@@ -94,4 +94,4 @@ }) | ||
id: 2, | ||
sku: 'mysku2', | ||
}, | ||
sku: 'mysku2' | ||
} | ||
]) | ||
@@ -102,7 +102,7 @@ }) | ||
{ id: 1, label: 'a' }, | ||
{ id: 2, label: 'b' }, | ||
{ id: 2, label: 'b' } | ||
] | ||
const modified = [ | ||
{ id: 2, label: 'b' }, | ||
{ id: 1, label: 'a' }, | ||
{ id: 1, label: 'a' } | ||
] | ||
@@ -124,5 +124,5 @@ const update_obj = get_mutation_diff(original, modified) | ||
$operation: 'create', | ||
title: 'computer', | ||
}, | ||
], | ||
title: 'computer' | ||
} | ||
] | ||
}) | ||
@@ -144,3 +144,3 @@ }) | ||
$operation: 'create', | ||
note: 'some data', | ||
note: 'some data' | ||
}) | ||
@@ -159,6 +159,6 @@ }) | ||
product_id: { | ||
$guid: 1, // no operation create here, since it is a guid | ||
}, | ||
}, | ||
], | ||
$guid: 1 // no operation create here, since it is a guid | ||
} | ||
} | ||
] | ||
}) | ||
@@ -173,7 +173,7 @@ }) | ||
{ | ||
url: 'test', | ||
}, | ||
], | ||
}, | ||
], | ||
url: 'test' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
@@ -190,7 +190,7 @@ const update_obj = get_mutation_diff(original, modified) | ||
$operation: 'create', | ||
url: 'test', | ||
}, | ||
], | ||
}, | ||
], | ||
url: 'test' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -212,7 +212,7 @@ }) | ||
$operation: 'delete', | ||
id: 2, | ||
}, | ||
], | ||
}, | ||
], | ||
id: 2 | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
@@ -222,8 +222,8 @@ }) | ||
const original = { | ||
images: [{ id: 1 }], | ||
images: [{ id: 1 }] | ||
} | ||
const modified = { | ||
images: [ | ||
{ id: 1, $identifying_fields: ['id'], $operation: 'update' }, | ||
], | ||
{ id: 1, $identifying_fields: ['id'], $operation: 'update' } | ||
] | ||
} | ||
@@ -238,7 +238,31 @@ const update_obj = get_mutation_diff(original, modified) | ||
$identifying_fields: ['id'], | ||
$operation: 'update', | ||
}, | ||
], | ||
$operation: 'update' | ||
} | ||
] | ||
}) | ||
}) | ||
test.skip('handles deletes when entire array is removed', () => { | ||
const original = { | ||
users: [{ id: 1, posts: [{ id: 2 }] }] | ||
} | ||
const modified = { | ||
users: [{ id: 1 }] | ||
} | ||
const update_obj = get_mutation_diff(original, modified) | ||
expect(update_obj).to.deep.equal({ | ||
$operation: 'update', | ||
users: [ | ||
{ | ||
id: 1, | ||
posts: [ | ||
{ | ||
$operation: 'delete', | ||
id: 2 | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
}) | ||
}) |
@@ -220,5 +220,16 @@ import { last } from '../../helpers/helpers' | ||
// no_match type is only for foreign keys that dont match (check examples) | ||
// no_match type is only for foreign keys that dont match (check examples). | ||
// for no_match, we assume $guids are $read and not making any change, and so ignore them | ||
// (this isnt necessarily true, but not doing this can cause unnecessary constraints that make | ||
// cycles in the toposort so we make this assumption for now. Really we would want to know if the | ||
// $guid is read or write, and only make a constraint in the write case.) | ||
const key_guid_string = '{"$guid":' | ||
const new_piece_indices = Object.keys(piece_indices_by_value) | ||
.filter(key => key !== value_string) | ||
.filter( | ||
key => | ||
key !== value_string && | ||
!key?.startsWith(key_guid_string) && | ||
!value_string?.startsWith(key_guid_string) | ||
) | ||
.map(key => piece_indices_by_value[key]) | ||
@@ -225,0 +236,0 @@ .flat() |
@@ -11,3 +11,3 @@ import { expect } from 'chai' | ||
get_mutation_uniqueness_errors, | ||
get_verify_uniqueness_query, | ||
get_verify_uniqueness_query | ||
} from './verify_uniqueness' | ||
@@ -25,5 +25,5 @@ | ||
title: 'hi', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -44,5 +44,5 @@ const piece_indices_by_entity = | ||
$where: { | ||
$eq: ['title', { $escape: 'hi' }], | ||
}, | ||
}, | ||
$eq: ['title', { $escape: 'hi' }] | ||
} | ||
} | ||
}) | ||
@@ -61,5 +61,5 @@ }) | ||
age: 20, | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -84,3 +84,3 @@ const piece_indices_by_entity = | ||
{ | ||
$eq: ['email', { $escape: 'a@a.com' }], | ||
$eq: ['email', { $escape: 'a@a.com' }] | ||
}, | ||
@@ -90,8 +90,8 @@ { | ||
['first_name', 'last_name'], | ||
[{ $escape: 'john' }, { $escape: 'smith' }], | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
[{ $escape: 'john' }, { $escape: 'smith' }] | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
@@ -105,3 +105,3 @@ }) | ||
title: 'hi', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
@@ -112,3 +112,3 @@ { | ||
title: 'as', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
@@ -119,7 +119,7 @@ { | ||
user_id: 1, | ||
title: '123', | ||
}, | ||
title: '123' | ||
} | ||
].map((el, i) => ({ | ||
path: ['posts', i], | ||
record: el, | ||
record: el | ||
})) as MutationPiece[] | ||
@@ -143,3 +143,3 @@ | ||
{ | ||
$eq: ['id', { $escape: 14 }], | ||
$eq: ['id', { $escape: 14 }] | ||
}, | ||
@@ -149,8 +149,8 @@ { | ||
'title', | ||
[{ $escape: 'hi' }, { $escape: '123' }], | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
[{ $escape: 'hi' }, { $escape: '123' }] | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
@@ -167,5 +167,5 @@ }) | ||
views: 123, | ||
$identifying_fields: ['title'], | ||
}, | ||
}, | ||
$identifying_fields: ['title'] | ||
} | ||
} | ||
] | ||
@@ -194,5 +194,5 @@ const piece_indices_by_entity = | ||
first_name: 'john', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -215,5 +215,5 @@ const piece_indices_by_entity = | ||
$where: { | ||
$eq: ['first_name', { $escape: 'john' }], | ||
}, | ||
}, | ||
$eq: ['first_name', { $escape: 'john' }] | ||
} | ||
} | ||
}) | ||
@@ -230,5 +230,5 @@ }) | ||
last_name: 'smith', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -253,6 +253,6 @@ const piece_indices_by_entity = | ||
['first_name', 'last_name'], | ||
[{ $escape: 'john' }, { $escape: 'smith' }], | ||
], | ||
}, | ||
}, | ||
[{ $escape: 'john' }, { $escape: 'smith' }] | ||
] | ||
} | ||
} | ||
}) | ||
@@ -269,5 +269,5 @@ }) | ||
first_name: { $guid: 1 }, | ||
last_name: 'smith', | ||
}, | ||
}, | ||
last_name: 'smith' | ||
} | ||
} | ||
] | ||
@@ -292,10 +292,10 @@ const piece_indices_by_entity = | ||
{ | ||
$eq: ['email', { $escape: 'a@a.com' }], | ||
$eq: ['email', { $escape: 'a@a.com' }] | ||
}, | ||
{ | ||
$eq: ['last_name', { $escape: 'smith' }], | ||
}, | ||
], | ||
}, | ||
}, | ||
$eq: ['last_name', { $escape: 'smith' }] | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
@@ -311,4 +311,4 @@ }) | ||
title: 'title 1', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -321,4 +321,4 @@ { | ||
title: 'title 2', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -331,5 +331,5 @@ { | ||
email: 'a@a.com', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -352,5 +352,5 @@ const piece_indices_by_entity = | ||
'title', | ||
[{ $escape: 'title 1' }, { $escape: 'title 2' }], | ||
], | ||
}, | ||
[{ $escape: 'title 1' }, { $escape: 'title 2' }] | ||
] | ||
} | ||
}, | ||
@@ -363,5 +363,5 @@ users: { | ||
$where: { | ||
$eq: ['email', { $escape: 'a@a.com' }], | ||
}, | ||
}, | ||
$eq: ['email', { $escape: 'a@a.com' }] | ||
} | ||
} | ||
}) | ||
@@ -376,8 +376,8 @@ }) | ||
field2: 'b', | ||
field3: 'c', | ||
field3: 'c' | ||
}, | ||
{ | ||
field1: 'a', | ||
field2: 'x', | ||
}, | ||
field2: 'x' | ||
} | ||
] | ||
@@ -387,8 +387,8 @@ const records2 = [ | ||
field1: 'x', | ||
field2: 'b', | ||
field2: 'b' | ||
}, | ||
{ | ||
field1: 'a', | ||
field2: 'b', | ||
}, | ||
field2: 'b' | ||
} | ||
] | ||
@@ -398,3 +398,3 @@ | ||
'field1', | ||
'field2', | ||
'field2' | ||
]) | ||
@@ -407,4 +407,4 @@ | ||
{ | ||
field1: 'a', | ||
}, | ||
field1: 'a' | ||
} | ||
] | ||
@@ -415,3 +415,3 @@ const records2 = [] | ||
'field1', | ||
'field2', | ||
'field2' | ||
]) | ||
@@ -431,4 +431,4 @@ | ||
email: 'a', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -441,5 +441,5 @@ { | ||
label: 'hi', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -453,4 +453,4 @@ const piece_indices_by_entity = | ||
id: 1, | ||
email: 'a', | ||
}, | ||
email: 'a' | ||
} | ||
], | ||
@@ -460,5 +460,5 @@ categories: [ | ||
id: 2, | ||
label: 'hi', | ||
}, | ||
], | ||
label: 'hi' | ||
} | ||
] | ||
} | ||
@@ -476,3 +476,3 @@ | ||
['users', 0], | ||
['categories', 0], | ||
['categories', 0] | ||
]) | ||
@@ -488,4 +488,4 @@ }) | ||
line_1: 'a', | ||
$identifying_fields: ['id'], | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
}, | ||
@@ -497,5 +497,5 @@ { | ||
id: 12, | ||
line_1: 'c', | ||
}, | ||
}, | ||
line_1: 'c' | ||
} | ||
} | ||
] | ||
@@ -509,5 +509,5 @@ const piece_indices_by_entity = | ||
id: 12, | ||
line_1: 'b', | ||
}, | ||
], | ||
line_1: 'b' | ||
} | ||
] | ||
} | ||
@@ -533,5 +533,5 @@ | ||
last_name: 'a', | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -546,5 +546,5 @@ const piece_indices_by_entity = | ||
first_name: 'john', | ||
last_name: 'b', | ||
}, | ||
], | ||
last_name: 'b' | ||
} | ||
] | ||
} | ||
@@ -569,5 +569,5 @@ | ||
email: null, | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -581,5 +581,5 @@ const piece_indices_by_entity = | ||
id: 12, | ||
email: null, | ||
}, | ||
], | ||
email: null | ||
} | ||
] | ||
} | ||
@@ -604,5 +604,5 @@ | ||
email: {}, | ||
$identifying_fields: ['id'], | ||
}, | ||
}, | ||
$identifying_fields: ['id'] | ||
} | ||
} | ||
] | ||
@@ -616,5 +616,5 @@ const piece_indices_by_entity = | ||
id: 12, | ||
email: null, | ||
}, | ||
], | ||
email: null | ||
} | ||
] | ||
} | ||
@@ -641,5 +641,5 @@ | ||
last_name: 'smith', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -652,5 +652,5 @@ { | ||
last_name: 'doe', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
}, | ||
@@ -663,5 +663,5 @@ { | ||
last_name: 'smith', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 2], | ||
path: ['users', 2] | ||
}, | ||
@@ -673,6 +673,6 @@ { | ||
line_1: 'hi', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['addresses', 0], | ||
}, | ||
path: ['addresses', 0] | ||
} | ||
] | ||
@@ -697,5 +697,5 @@ const piece_indices_by_entity = | ||
id: 12, | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -706,6 +706,6 @@ { | ||
id: 12, | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
}, | ||
path: ['users', 1] | ||
} | ||
] | ||
@@ -730,5 +730,5 @@ const piece_indices_by_entity = | ||
email: [{}], | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -740,6 +740,6 @@ { | ||
email: [{}], | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
}, | ||
path: ['users', 1] | ||
} | ||
] | ||
@@ -764,5 +764,5 @@ const piece_indices_by_entity = | ||
email: 'a@a.com', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 0], | ||
path: ['users', 0] | ||
}, | ||
@@ -774,6 +774,67 @@ { | ||
email: 'a@a.com', | ||
$identifying_fields: ['id'], | ||
$identifying_fields: ['id'] | ||
}, | ||
path: ['users', 1], | ||
path: ['users', 1] | ||
} | ||
] | ||
const piece_indices_by_entity = | ||
get_piece_indices_by_entity(mutation_pieces) | ||
const errors = get_mutation_uniqueness_errors( | ||
global_test_schema, | ||
mutation_pieces, | ||
piece_indices_by_entity | ||
) | ||
expect(errors.length).to.equal(0) | ||
}) | ||
test('handles partially null unique keys', () => { | ||
// none of these cause sql errors | ||
const mutation_pieces: MutationPiece[] = [ | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: '1' | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: '2' | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: null | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1', | ||
tax_subcode: null | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1' | ||
}, | ||
path: ['tax_codes', 0] | ||
}, | ||
{ | ||
record: { | ||
$operation: 'create', | ||
tax_code: 'TAX1' | ||
}, | ||
path: ['tax_codes', 0] | ||
} | ||
] | ||
@@ -780,0 +841,0 @@ const piece_indices_by_entity = |
@@ -13,31 +13,31 @@ import { OrmaMutation } from '../types/mutation/mutation_types' | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
first_name: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
last_name: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
email: { | ||
$data_type: 'varchar', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
billing_address_id: { | ||
$data_type: 'int', | ||
$data_type: 'int' | ||
}, | ||
shipping_address_id: { | ||
$data_type: 'int', | ||
}, | ||
$data_type: 'int' | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
$unique_keys: [ | ||
{ | ||
$fields: ['email'], | ||
$fields: ['email'] | ||
}, | ||
{ | ||
$fields: ['first_name', 'last_name'], | ||
}, | ||
$fields: ['first_name', 'last_name'] | ||
} | ||
], | ||
@@ -49,4 +49,4 @@ $foreign_keys: [ | ||
$entity: 'addresses', | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -57,6 +57,6 @@ { | ||
$entity: 'addresses', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -69,11 +69,11 @@ posts: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
user_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
title: { | ||
$data_type: 'varchar', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
@@ -83,7 +83,7 @@ views: { | ||
$not_null: true, | ||
$default: 0, | ||
}, | ||
$default: 0 | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -93,4 +93,4 @@ $unique_keys: [ | ||
$name: 'unique_title', | ||
$fields: ['title'], | ||
}, | ||
$fields: ['title'] | ||
} | ||
], | ||
@@ -102,6 +102,6 @@ $foreign_keys: [ | ||
$entity: 'users', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -114,15 +114,15 @@ likes: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
user_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
post_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
}, | ||
$not_null: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -132,4 +132,4 @@ $unique_keys: [ | ||
$name: 'unique_user_id_post_id', | ||
$fields: ['user_id', 'post_id'], | ||
}, | ||
$fields: ['user_id', 'post_id'] | ||
} | ||
], | ||
@@ -141,4 +141,4 @@ $foreign_keys: [ | ||
$entity: 'users', | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -149,6 +149,6 @@ { | ||
$entity: 'posts', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -161,11 +161,11 @@ comments: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
post_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
}, | ||
$not_null: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -177,6 +177,6 @@ $foreign_keys: [ | ||
$entity: 'posts', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -189,13 +189,13 @@ addresses: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
line_1: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
resource_id: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
tax_code_id: { | ||
$data_type: 'int', | ||
}, | ||
$data_type: 'int' | ||
} | ||
}, | ||
@@ -205,7 +205,7 @@ $unique_keys: [ | ||
$fields: ['resource_id'], | ||
$name: 'resource_uq', | ||
}, | ||
$name: 'resource_uq' | ||
} | ||
], | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -217,6 +217,6 @@ $foreign_keys: [ | ||
$entity: 'tax_codes', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -229,3 +229,3 @@ tax_codes: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
@@ -235,13 +235,17 @@ tax_code: { | ||
$enum_values: ['TAX1', 'TAX2', 'TAX3'], | ||
$not_null: true | ||
}, | ||
tax_subcode: { | ||
$data_type: 'varchar' | ||
} | ||
}, | ||
$unique_keys: [ | ||
{ | ||
$fields: ['tax_code'], | ||
$name: 'tax_code_uq', | ||
}, | ||
$fields: ['tax_code', 'tax_subcode'], | ||
$name: 'tax_code_uq' | ||
} | ||
], | ||
$primary_key: { | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -254,3 +258,3 @@ categories: { | ||
$auto_increment: true, | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
@@ -260,7 +264,7 @@ label: { | ||
$not_null: true, | ||
$precision: 10, | ||
$precision: 10 | ||
}, | ||
parent_category_id: { $data_type: 'int' }, | ||
resource_id: { | ||
$data_type: 'varchar', | ||
$data_type: 'varchar' | ||
}, | ||
@@ -271,7 +275,7 @@ size: { | ||
$scale: 2, | ||
$unsigned: true, | ||
}, | ||
$unsigned: true | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['id'], | ||
$fields: ['id'] | ||
}, | ||
@@ -281,16 +285,18 @@ $unique_keys: [ | ||
$name: 'label_uq', | ||
$fields: ['label'], | ||
$fields: ['label'] | ||
}, | ||
{ | ||
$name: 'resource_uq', | ||
$fields: ['resource_id'], | ||
}, | ||
$fields: ['resource_id'] | ||
} | ||
], | ||
$foreign_keys: [{ | ||
$fields: ['parent_category_id'], | ||
$references: { | ||
$entity: 'categories', | ||
$fields: ['id'] | ||
}, | ||
}] | ||
$foreign_keys: [ | ||
{ | ||
$fields: ['parent_category_id'], | ||
$references: { | ||
$entity: 'categories', | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
}, | ||
@@ -302,15 +308,15 @@ post_has_categories: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
category_id: { | ||
$data_type: 'int', | ||
$not_null: true, | ||
$not_null: true | ||
}, | ||
main_category: { | ||
$data_type: 'tinyint', | ||
$precision: 1, | ||
}, | ||
$precision: 1 | ||
} | ||
}, | ||
$primary_key: { | ||
$fields: ['post_id', 'category_id'], | ||
$fields: ['post_id', 'category_id'] | ||
}, | ||
@@ -323,4 +329,4 @@ $foreign_keys: [ | ||
$entity: 'posts', | ||
$fields: ['id'], | ||
}, | ||
$fields: ['id'] | ||
} | ||
}, | ||
@@ -332,7 +338,7 @@ { | ||
$entity: 'categories', | ||
$fields: ['id'], | ||
}, | ||
}, | ||
], | ||
}, | ||
$fields: ['id'] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
@@ -345,3 +351,3 @@ $cache: { | ||
to_entity: 'users', | ||
to_field: 'billing_address_id', | ||
to_field: 'billing_address_id' | ||
}, | ||
@@ -351,4 +357,4 @@ { | ||
to_entity: 'users', | ||
to_field: 'shipping_address_id', | ||
}, | ||
to_field: 'shipping_address_id' | ||
} | ||
], | ||
@@ -359,8 +365,8 @@ tax_codes: [ | ||
to_entity: 'addresses', | ||
to_field: 'tax_code_id', | ||
}, | ||
to_field: 'tax_code_id' | ||
} | ||
], | ||
users: [ | ||
{ from_field: 'id', to_entity: 'posts', to_field: 'user_id' }, | ||
{ from_field: 'id', to_entity: 'likes', to_field: 'user_id' }, | ||
{ from_field: 'id', to_entity: 'likes', to_field: 'user_id' } | ||
], | ||
@@ -372,3 +378,3 @@ posts: [ | ||
to_entity: 'comments', | ||
to_field: 'post_id', | ||
to_field: 'post_id' | ||
}, | ||
@@ -378,4 +384,4 @@ { | ||
to_entity: 'post_has_categories', | ||
to_field: 'post_id', | ||
}, | ||
to_field: 'post_id' | ||
} | ||
], | ||
@@ -386,3 +392,3 @@ categories: [ | ||
to_entity: 'post_has_categories', | ||
to_field: 'category_id', | ||
to_field: 'category_id' | ||
}, | ||
@@ -392,7 +398,7 @@ { | ||
to_entity: 'categories', | ||
to_field: 'parent_category_id', | ||
}, | ||
], | ||
}, | ||
}, | ||
to_field: 'parent_category_id' | ||
} | ||
] | ||
} | ||
} | ||
} as const satisfies OrmaSchema | ||
@@ -399,0 +405,0 @@ |
import { | ||
global_test_schema, | ||
GlobalTestSchema, | ||
GlobalTestSchema | ||
} from '../../test_data/global_test_schema' | ||
@@ -12,3 +12,3 @@ import { IsEqual } from '../helper_types' | ||
GetFieldType, | ||
GetParentEdges, | ||
GetParentEdges | ||
} from './schema_helper_types' | ||
@@ -39,3 +39,3 @@ | ||
to_entity: 'addresses', | ||
from_field: 'billing_address_id', | ||
from_field: 'billing_address_id' | ||
} | ||
@@ -46,3 +46,3 @@ | ||
// @ts-expect-error | ||
to_entity: 'products', | ||
to_entity: 'products' | ||
} | ||
@@ -56,3 +56,3 @@ } | ||
from_field: 'id', | ||
to_entity: 'posts', | ||
to_entity: 'posts' | ||
} | ||
@@ -63,3 +63,3 @@ | ||
// @ts-expect-error | ||
to_entity: 'addresses', | ||
to_entity: 'addresses' | ||
} | ||
@@ -74,3 +74,3 @@ } | ||
from_field: 'id', | ||
to_entity: 'posts', | ||
to_entity: 'posts' | ||
} | ||
@@ -81,3 +81,3 @@ | ||
to_entity: 'addresses', | ||
from_field: 'shipping_address_id', | ||
from_field: 'shipping_address_id' | ||
} | ||
@@ -88,3 +88,3 @@ | ||
//@ts-expect-error | ||
to_entity: 'comments', | ||
to_entity: 'comments' | ||
} | ||
@@ -112,4 +112,4 @@ } | ||
GetFieldType<GlobalTestSchema, 'tax_codes', 'tax_code'>, | ||
'TAX1' | 'TAX2' | 'TAX3' | null | ||
'TAX1' | 'TAX2' | 'TAX3' | ||
> = true | ||
} | ||
} |
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
1700287
41463