Comparing version 1.0.23 to 1.0.24
@@ -16,2 +16,3 @@ declare type type_string = 'Object' | 'Number' | 'Boolean' | 'String' | 'Null' | 'Array' | 'RegExp' | 'Function' | 'Undefined'; | ||
* Calls the processor on every object and array for deeply nested objects/arrays. Processort runs from the least deeply nested keys to the most deeply nested ones | ||
* Does not run on leaf keys (i.e. where value of key is not an object or array) | ||
* @param item | ||
@@ -18,0 +19,0 @@ * @param processor |
@@ -156,2 +156,3 @@ "use strict"; | ||
* Calls the processor on every object and array for deeply nested objects/arrays. Processort runs from the least deeply nested keys to the most deeply nested ones | ||
* Does not run on leaf keys (i.e. where value of key is not an object or array) | ||
* @param item | ||
@@ -158,0 +159,0 @@ * @param processor |
@@ -93,4 +93,4 @@ /** | ||
readonly char: "string"; | ||
readonly date: "data"; | ||
readonly datetime: "data"; | ||
readonly date: "date"; | ||
readonly datetime: "date"; | ||
readonly decimal: "number"; | ||
@@ -109,4 +109,4 @@ readonly double: "number"; | ||
readonly text: "string"; | ||
readonly time: "data"; | ||
readonly timestamp: "data"; | ||
readonly time: "date"; | ||
readonly timestamp: "date"; | ||
readonly tinyblob: "not_supported"; | ||
@@ -113,0 +113,0 @@ readonly tinyint: "boolean"; |
@@ -173,4 +173,4 @@ "use strict"; | ||
char: 'string', | ||
date: 'data', | ||
datetime: 'data', | ||
date: 'date', | ||
datetime: 'date', | ||
decimal: 'number', | ||
@@ -189,4 +189,4 @@ double: 'number', | ||
text: 'string', | ||
time: 'data', | ||
timestamp: 'data', | ||
time: 'date', | ||
timestamp: 'date', | ||
tinyblob: 'not_supported', | ||
@@ -193,0 +193,0 @@ tinyint: 'boolean', |
@@ -128,10 +128,2 @@ "use strict"; | ||
}); | ||
mocha_1.test('Should allow UPPERCASE mysql responses', function () { | ||
// see the hack around in orma_query where keys are mapped to lowercase | ||
// consider adding this transform to the actual generate database schema? | ||
chai_1.expect(1).to.equal(2); | ||
}); | ||
mocha_1.test('Should date types be called date? or data...', function () { | ||
chai_1.expect(1).to.equal(2); | ||
}); | ||
}); |
@@ -1,45 +0,108 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.verify_foreign_keys = void 0; | ||
var verify_foreign_keys = function (mutation, mutation_path, orma_schema) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/]; | ||
}); | ||
}); }; | ||
exports.verify_foreign_keys = verify_foreign_keys; | ||
// import { orma_schema } from '../introspector/introspector' | ||
// import { get_mutate_plan, operation } from './mutate' | ||
// export const verify_foreign_keys = async (mutation, mutation_path, orma_schema: orma_schema) => { | ||
// // this should probably be split into data collection (returns sql string) and checking (returns errors) | ||
// } | ||
// /** | ||
// * Updates and deletes need identifying keys to find which record to update/delete. In practice this is the primary key(s) | ||
// * or a unique key. This verification checks whether these identifying keys exist in the database | ||
// */ | ||
// export const get_verify_identifiers_sql = (operation: operation, mutation_records: Record<string, unknown>[], orma_schema: orma_schema) => { | ||
// /* | ||
// This will not catch something like [{ | ||
// $operation: 'update', | ||
// id: 1, | ||
// unique_key: 'something_else' | ||
// }, { | ||
// $operation: 'update', | ||
// unique_key: 'test' | ||
// }] | ||
// if they are actually the same object, i.e. { | ||
// id: 1, | ||
// unique_key: 'test' | ||
// } | ||
// In this case, the verification will pass (we dont know that the two mutations are actually affecting the | ||
// same record), but we will get a SQL error (the first update changes the unique_key so when the second one | ||
// runs, there is no record with unique_key of 'test'). | ||
// to get around this, we can first find all the primary keys for records, then compare them. If we find the same | ||
// primary key(s) more than once, or some record doesnt have a primary key, we can throw an error. Also | ||
// we need to ensure we are looking at all records for a given entity, even if that entity is in multiple nesting | ||
// locations of the mutation. | ||
// Algorithm: | ||
// */ | ||
// const errors = [] | ||
// } | ||
// export const get_verify_foreign_key_editing_sql = () => { | ||
// /* | ||
// Whenever we update or delete, we need to verify that we are not breaking a foreign key connection. | ||
// For updating, this is only relevant if we update a foreign key. For delete we need to find all its foreign | ||
// key children and make sure we are not deleting if it has any. Unless that child is already being deleted. | ||
// */ | ||
// } | ||
// export const get_verify_foreign_key_sql = () => { | ||
// /* | ||
// In a case like { | ||
// parents: { | ||
// $operation: 'update', | ||
// $id: 123, | ||
// $where: { | ||
// $eq: ['unique_key', 5] | ||
// } | ||
// }, | ||
// children:{ | ||
// $operation: 'create', | ||
// parent_id: 1 | ||
// } | ||
// } | ||
// If we originally had | ||
// parents = [{ | ||
// id: 1, | ||
// unique_key: 5 | ||
// }] | ||
// Similar situation if the update was actually a delete | ||
// we would have an issue if the update ran first. To catch this, we could pull in all the parent records, | ||
// do a search to make sure they all have their foreign keys (only for the ones that dont already), then | ||
// if we see we are modifying a record that we are trying to link to we can throw an error | ||
// */ | ||
// } | ||
// export const verify_identifying_keys_exist_OLD = async (connection, body, nest_paths, table_infos) => { | ||
// const checkpoint_count = nest_paths.length | ||
// const sql_checkpoint = make_sql_checkpoint(connection, checkpoint_count) | ||
// const errors = [] | ||
// await Promise.all(nest_paths.map(async nest_path => { | ||
// const table_name = get_table_name(nest_path) | ||
// const subpaths = get_subpaths(nest_path, body).filter(subpath => { | ||
// const operation = path(subpath, body)?.meta?.operation | ||
// return includes(operation, ['update', 'delete']) | ||
// }) | ||
// if (subpaths.length === 0) { | ||
// return await sql_checkpoint(undefined) | ||
// } | ||
// const supplied_rows = get_supplied_rows(body, subpaths) | ||
// const primary_key = get_primary_key_name(table_name, table_infos) | ||
// const supplied_primary_keys = pluck(primary_key, supplied_rows) | ||
// const query = ` | ||
// SELECT ${table_name}.${primary_key} FROM ${table_name} | ||
// WHERE ${table_name}.${primary_key} IN (${supplied_primary_keys.map(p_key => escape(p_key))}) | ||
// ` | ||
// const db_rows = await sql_checkpoint(query) | ||
// for (const i of range(0, supplied_rows.length)) { | ||
// const supplied_row = supplied_rows[i] | ||
// const subpath = subpaths[i] | ||
// const db_values = pluck(primary_key, db_rows) | ||
// const value = supplied_row[primary_key] | ||
// const primary_key_is_missing = !includes(value, db_values) | ||
// if (primary_key_is_missing) { | ||
// errors.push({ | ||
// message: `${primary_key} ${value} does not exist in ${table_name}.`, | ||
// path: append(primary_key, subpath), | ||
// invalid_data: value, | ||
// recommendation: `Please modify the update key so that it references an existing ${primary_key}.` | ||
// }) | ||
// } | ||
// } | ||
// })) | ||
// if (errors.length > 0) { | ||
// return Promise.reject(generate_error_response('missing_reference', errors)) | ||
// } | ||
// } |
import { orma_schema } from '../introspector/introspector'; | ||
export declare type mutate_function = (sql_strings: string[], sql_jsons: Record<string, unknown>[]) => Record<string, unknown>[]; | ||
export declare type operation = 'create' | 'update' | 'delete'; | ||
interface mutate_functions { | ||
@@ -18,5 +19,5 @@ create: mutate_function; | ||
export declare const get_mutate_plan: (mutation: any, orma_schema: orma_schema) => { | ||
operation: "update" | "create" | "delete"; | ||
operation: operation; | ||
paths: (string | number)[][]; | ||
}[][]; | ||
export {}; |
@@ -91,2 +91,5 @@ "use strict"; | ||
var parsed_commands = sorted_commands.map(function (command) { | ||
if (expression[command] === undefined) { | ||
return ''; | ||
} | ||
var command_parser = sql_command_parsers[command]; | ||
@@ -101,3 +104,3 @@ if (!command_parser) { | ||
return command_parser(parsed_args, path); | ||
}); | ||
}).filter(function (el) { return el !== ''; }); | ||
return parsed_commands.join(' '); | ||
@@ -104,0 +107,0 @@ }; |
@@ -72,2 +72,10 @@ "use strict"; | ||
}); | ||
mocha_1.test('ignores undefined properties', function () { | ||
var json = { | ||
$having: undefined | ||
}; | ||
var sql = sql_formatter_1.format(query_1.json_to_sql(json)); | ||
var goal = sql_formatter_1.format(''); | ||
chai_1.expect(sql).to.equal(goal); | ||
}); | ||
}); | ||
@@ -74,0 +82,0 @@ mocha_1.describe('get_query_plan', function () { |
{ | ||
"name": "orma", | ||
"version": "1.0.23", | ||
"version": "1.0.24", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
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
253541
5918