Socket
Socket
Sign inDemoInstall

@ts-safeql/eslint-plugin

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-safeql/eslint-plugin - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

lib/file.d.ts

3

lib/index.js

@@ -7,3 +7,4 @@ "use strict";

const rules_1 = __importDefault(require("./rules"));
module.exports = { rules: rules_1.default };
const check_sql_config_1 = require("./rules/check-sql.config");
module.exports = { rules: rules_1.default, defineConfig: check_sql_config_1.defineConfig };
//# sourceMappingURL=index.js.map

@@ -29,2 +29,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.RuleOptions = exports.Options = exports.UserConfigFile = exports.Config = void 0;
const shared_1 = require("@ts-safeql/shared");

@@ -42,2 +43,3 @@ const utils_1 = require("@typescript-eslint/utils");

const ts_pg_utils_1 = require("../utils/ts-pg.utils");
const check_sql_config_1 = require("./check-sql.config");
const check_sql_utils_1 = require("./check-sql.utils");

@@ -52,32 +54,76 @@ const messages = {

const baseSchema = zod_1.default.object({
/**
* Transform the end result of the type.
*
* For example:
* - `"${type}[]"` will transform the type to an array
* - `["Nullable", "Maybe"]` will replace `Nullable` with `Maybe` in the type
* - `["${type}[]", ["Nullable", "Maybe"]]` will do both
*/
transform: zod_1.default
.union([zod_1.default.string(), zod_1.default.array(zod_1.default.union([zod_1.default.string(), zod_1.default.tuple([zod_1.default.string(), zod_1.default.string()])]))])
.optional(),
/**
* Whether or not keep the connection alive. Change it only if you know what you're doing.
*/
keepAlive: zod_1.default.boolean().optional(),
});
const identifyByNameAndOperators = zod_1.default.object({
/**
* The name of the variable the holds the connection.
*
* For example "conn" for `conn.query(...)`
*/
name: zod_1.default.string(),
/**
* An array of operator names that executes raw queries inside the variable that holds the connection.
*
* For example ["$queryRaw", "$executeRaw"] for `Prisma.$queryRaw(...)` and `Prisma.$executeRaw(...)`
*/
operators: zod_1.default.array(zod_1.default.string()),
});
const identifyByTagName = zod_1.default.object({
/**
* The name of the tag that executes raw queries.
*
* For example "sql" for ```` sql`SELECT * FROM users` ````
*/
tagName: zod_1.default.string(),
});
const connectByMigrationSchema = zod_1.default.object({
/**
* The path where the migration files are located.
*/
migrationsDir: zod_1.default.string(),
/**
* THIS IS NOT THE PRODUCTION DATABASE.
*
* A connection url to the database.
* This is required since in order to run the migrations, a connection to postgres is required.
* Will be used only to create and drop the shadow database (see `databaseName`).
*/
connectionUrl: zod_1.default.string().optional(),
/**
* The name of the shadow database that will be created from the migration files.
*/
databaseName: zod_1.default.string(),
});
const connectByDatabaseUrl = zod_1.default.object({
/**
* The connection url to the database
*/
databaseUrl: zod_1.default.string(),
keepAlive: zod_1.default.boolean().optional(),
});
const schema = baseSchema.extend({
connections: zod_1.default.array(zod_1.default.union([
baseSchema.merge(connectByMigrationSchema.merge(identifyByNameAndOperators)),
baseSchema.merge(connectByMigrationSchema.merge(identifyByTagName)),
baseSchema.merge(connectByDatabaseUrl.merge(identifyByNameAndOperators)),
baseSchema.merge(connectByDatabaseUrl.merge(identifyByTagName)),
])),
const RuleOptionConnection = zod_1.default.union([
baseSchema.merge(connectByMigrationSchema.merge(identifyByNameAndOperators)),
baseSchema.merge(connectByMigrationSchema.merge(identifyByTagName)),
baseSchema.merge(connectByDatabaseUrl.merge(identifyByNameAndOperators)),
baseSchema.merge(connectByDatabaseUrl.merge(identifyByTagName)),
]);
exports.Config = zod_1.default.object({
connections: zod_1.default.union([zod_1.default.array(RuleOptionConnection), RuleOptionConnection]),
});
const ruleOptionsSchema = zod_1.default.array(schema).min(1).max(1);
exports.UserConfigFile = zod_1.default.object({ useConfigFile: zod_1.default.boolean() });
exports.Options = zod_1.default.union([exports.Config, exports.UserConfigFile]);
exports.RuleOptions = zod_1.default.array(exports.Options).min(1).max(1);
const workerPath = require.resolve("./check-sql.worker");

@@ -89,3 +135,6 @@ const generateSync = (0, synckit_1.createSyncFn)(workerPath, {

function check(params) {
for (const connection of params.context.options[0].connections) {
const connections = Array.isArray(params.config.connections)
? params.config.connections
: [params.config.connections];
for (const connection of connections) {
checkConnection(Object.assign(Object.assign({}, params), { connection }));

@@ -224,3 +273,3 @@ }

type: "problem",
schema: (0, zod_to_json_schema_1.default)(ruleOptionsSchema, { target: "openApi3" }),
schema: (0, zod_to_json_schema_1.default)(exports.RuleOptions, { target: "openApi3" }),
},

@@ -230,5 +279,6 @@ defaultOptions: [],

const projectDir = (0, node_utils_1.locateNearestPackageJsonDir)(context.getFilename());
const config = (0, check_sql_config_1.getConfigFromFileWithContext)({ context, projectDir });
return {
TaggedTemplateExpression(expr) {
check({ context, tag: expr, projectDir });
TaggedTemplateExpression(tag) {
check({ context, tag, config, projectDir });
},

@@ -235,0 +285,0 @@ };

{
"name": "@ts-safeql/eslint-plugin",
"version": "0.0.7",
"version": "0.0.8",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc