@tableland/sdk
Advanced tools
Comparing version 4.0.0-pre.6 to 4.0.0-pre.7
@@ -8,15 +8,9 @@ "use strict"; | ||
const firstSearch = /(?<create>^CREATE\s+TABLE\s+)(?<name>\S+)(?<schema>\s*\(.*\)[;]?$)/i; | ||
// Match _anything_ between pairs of "", ``, '', or [] | ||
const secondSearch = /(?<=^")(.*?)(?="$)|(?<=^\[)(.*?)(?=\]$)|(?<=^')(.*?)(?='$)|(?<=^`)(.*?)(?=`$)|(^[^[`'].*?[^\]'`]$)/; | ||
const escapeChars = /"|'|`|\]|\[/; | ||
async function prepareCreateTable({ statement, chainId, first, }) { | ||
const { prefix, name: tableName } = await (0, parser_js_1.validateTableName)(`${first}_${chainId}`, true); | ||
const stmt = statement.replace(firstSearch, function (_, create, name, schema) { | ||
const newName = name.replace(secondSearch, function (sub, ...args) { | ||
if (sub != null) { | ||
return tableName; | ||
} | ||
/* c8 ignore next */ | ||
return sub; | ||
}); | ||
return create + newName + schema; | ||
// If this name has any escape chars, escape the whole thing. | ||
const newName = escapeChars.test(name) ? `[${tableName}]` : tableName; | ||
return `${create.trim()} ${newName.trim()} ${schema.trim()}`; | ||
}); | ||
@@ -23,0 +17,0 @@ return { statement: stmt, chainId, prefix }; |
@@ -5,15 +5,9 @@ import { validateTableName } from "../helpers/parser.js"; | ||
const firstSearch = /(?<create>^CREATE\s+TABLE\s+)(?<name>\S+)(?<schema>\s*\(.*\)[;]?$)/i; | ||
// Match _anything_ between pairs of "", ``, '', or [] | ||
const secondSearch = /(?<=^")(.*?)(?="$)|(?<=^\[)(.*?)(?=\]$)|(?<=^')(.*?)(?='$)|(?<=^`)(.*?)(?=`$)|(^[^[`'].*?[^\]'`]$)/; | ||
const escapeChars = /"|'|`|\]|\[/; | ||
export async function prepareCreateTable({ statement, chainId, first, }) { | ||
const { prefix, name: tableName } = await validateTableName(`${first}_${chainId}`, true); | ||
const stmt = statement.replace(firstSearch, function (_, create, name, schema) { | ||
const newName = name.replace(secondSearch, function (sub, ...args) { | ||
if (sub != null) { | ||
return tableName; | ||
} | ||
/* c8 ignore next */ | ||
return sub; | ||
}); | ||
return create + newName + schema; | ||
// If this name has any escape chars, escape the whole thing. | ||
const newName = escapeChars.test(name) ? `[${tableName}]` : tableName; | ||
return `${create.trim()} ${newName.trim()} ${schema.trim()}`; | ||
}); | ||
@@ -20,0 +14,0 @@ return { statement: stmt, chainId, prefix }; |
{ | ||
"name": "@tableland/sdk", | ||
"version": "4.0.0-pre.6", | ||
"version": "4.0.0-pre.7", | ||
"description": "A database client and helpers for the Tableland network", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -9,5 +9,3 @@ import { type SignerConfig } from "../helpers/config.js"; | ||
/(?<create>^CREATE\s+TABLE\s+)(?<name>\S+)(?<schema>\s*\(.*\)[;]?$)/i; | ||
// Match _anything_ between pairs of "", ``, '', or [] | ||
const secondSearch = | ||
/(?<=^")(.*?)(?="$)|(?<=^\[)(.*?)(?=\]$)|(?<=^')(.*?)(?='$)|(?<=^`)(.*?)(?=`$)|(^[^[`'].*?[^\]'`]$)/; | ||
const escapeChars = /"|'|`|\]|\[/; | ||
@@ -41,10 +39,5 @@ export interface PrepareParams { | ||
function (_, create: string, name: string, schema: string) { | ||
const newName = name.replace(secondSearch, function (sub, ...args) { | ||
if (sub != null) { | ||
return tableName; | ||
} | ||
/* c8 ignore next */ | ||
return sub; | ||
}); | ||
return create + newName + schema; | ||
// If this name has any escape chars, escape the whole thing. | ||
const newName = escapeChars.test(name) ? `[${tableName}]` : tableName; | ||
return `${create.trim()} ${newName.trim()} ${schema.trim()}`; | ||
} | ||
@@ -51,0 +44,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
412351
8154