@stacksjs/database 0.75.112 → 0.75.113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,4 @@
1
+ /** Check trusted table/column names before composing a scoped operation. */
2
+ export declare function assertSqlIdentifier(name: string): void;
1
3
  /** Lock a scoped row until the caller's transaction commits. SQLite transactions serialize writers. */
2
4
  export declare function lockRow(connection: { unsafe?: (query: string, params?: unknown[]) => PromiseLike<Record<string, unknown>[]> }, table: string, filters: Record<string, string | number | null>): Promise<Record<string, unknown> | undefined>;
package/dist/row-lock.js CHANGED
@@ -1 +1 @@
1
- import{sqlHelpers}from"./sql-helpers";import{getDatabaseDialect}from"./utils";export async function lockRow(connection,table,filters){const dialect=sqlHelpers(getDatabaseDialect()),quote=dialect.isMysql?"`":'"',identifier=(name)=>{if(!/^[a-z_][a-z_0-9]*$/i.test(name))throw Error(`Invalid SQL identifier: ${name}`);return`${quote}${name}${quote}`},values=[],conditions=Object.entries(filters).map(([name,value])=>{if(value===null)return`${identifier(name)} IS NULL`;values.push(value);return`${identifier(name)} = ${dialect.param(values.length)}`});if(!conditions.length)throw Error("A row lock requires a scope");const suffix=dialect.isPostgres||dialect.isMysql?" FOR UPDATE":"";if(!connection.unsafe)throw Error("Row locks require a database connection");return(await connection.unsafe(`SELECT * FROM ${identifier(table)} WHERE ${conditions.join(" AND ")}${suffix}`,values))?.[0]}
1
+ import{sqlHelpers}from"./sql-helpers";import{getDatabaseDialect}from"./utils";export function assertSqlIdentifier(name){if(!/^[a-z_][a-z_0-9]*$/i.test(name))throw Error(`Invalid SQL identifier: ${name}`)}export async function lockRow(connection,table,filters){const dialect=sqlHelpers(getDatabaseDialect()),quote=dialect.isMysql?"`":'"',identifier=(name)=>{assertSqlIdentifier(name);return`${quote}${name}${quote}`},values=[],conditions=Object.entries(filters).map(([name,value])=>{if(value===null)return`${identifier(name)} IS NULL`;values.push(value);return`${identifier(name)} = ${dialect.param(values.length)}`});if(!conditions.length)throw Error("A row lock requires a scope");const suffix=dialect.isPostgres||dialect.isMysql?" FOR UPDATE":"";if(!connection.unsafe)throw Error("Row locks require a database connection");const rows=await connection.unsafe(`SELECT * FROM ${identifier(table)} WHERE ${conditions.join(" AND ")}${suffix}`,values);if(rows.length>1)throw Error("A row lock requires a unique scope");return rows[0]}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/database",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.112",
5
+ "version": "0.75.113",
6
6
  "description": "The Stacks database integration.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -66,26 +66,26 @@
66
66
  "prepublishOnly": "bun run build"
67
67
  },
68
68
  "dependencies": {
69
- "@stacksjs/config": "0.75.112",
70
- "@stacksjs/env": "0.75.112",
71
- "@stacksjs/error-handling": "0.75.112",
72
- "@stacksjs/faker": "^0.75.112",
73
- "@stacksjs/features": "0.75.112",
74
- "@stacksjs/logging": "0.75.112",
75
- "@stacksjs/model-meta": "0.75.112",
76
- "@stacksjs/path": "0.75.112",
77
- "@stacksjs/query-builder": "^0.75.112",
78
- "@stacksjs/security": "0.75.112",
79
- "@stacksjs/storage": "0.75.112",
80
- "@stacksjs/strings": "0.75.112",
69
+ "@stacksjs/config": "0.75.113",
70
+ "@stacksjs/env": "0.75.113",
71
+ "@stacksjs/error-handling": "0.75.113",
72
+ "@stacksjs/faker": "^0.75.113",
73
+ "@stacksjs/features": "0.75.113",
74
+ "@stacksjs/logging": "0.75.113",
75
+ "@stacksjs/model-meta": "0.75.113",
76
+ "@stacksjs/path": "0.75.113",
77
+ "@stacksjs/query-builder": "^0.75.113",
78
+ "@stacksjs/security": "0.75.113",
79
+ "@stacksjs/storage": "0.75.113",
80
+ "@stacksjs/strings": "0.75.113",
81
81
  "@stacksjs/ts-validation": "^0.5.6",
82
82
  "bun-query-builder": "^0.3.5",
83
83
  "dynamodb-tooling": "^0.3.6"
84
84
  },
85
85
  "devDependencies": {
86
- "@stacksjs/cli": "0.75.112",
87
- "@stacksjs/router": "0.75.112",
88
- "@stacksjs/utils": "0.75.112",
86
+ "@stacksjs/cli": "0.75.113",
87
+ "@stacksjs/router": "0.75.113",
88
+ "@stacksjs/utils": "0.75.113",
89
89
  "better-dx": "^0.2.24"
90
90
  }
91
91
  }