-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
111 changed files
with
10,507 additions
and
7,326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,17 @@ | |
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [["@ts-safeql/eslint-plugin", "@ts-safeql/generate", "@ts-safeql/shared"]], | ||
"fixed": [ | ||
[ | ||
"@ts-safeql/eslint-plugin", | ||
"@ts-safeql/generate", | ||
"@ts-safeql/shared", | ||
"@ts-safeql/sql-ast" | ||
] | ||
], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
"@ts-safeql/eslint-plugin": minor | ||
"@ts-safeql/generate": minor | ||
"@ts-safeql/sql-tag": minor | ||
"@ts-safeql/docs": minor | ||
--- | ||
|
||
This release introduces a lot of (internal) changes, but to be honest, I'm too lazy to write them all down so I'll mention the highlights: | ||
|
||
### SafeQL supports Flat Config! 🎉 | ||
|
||
You can now use SafeQL with the new ESLint [Flat Config](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file) API: | ||
|
||
```js | ||
// eslint.config.js | ||
|
||
import safeql from "@ts-safeql/eslint-plugin/config"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
export default tseslint.config( | ||
// ... | ||
safeql.configs.connections({ | ||
// ... | ||
}), | ||
); | ||
``` | ||
|
||
### SafeQL is now built for both ESM and CJS | ||
|
||
Up until now, I built SafeQL using only TSC (targeting CJS). In order to support both ESM and CJS, I had to use a different build system. I chose to use [unbuild](https://github.com/unjs/unbuild) because it's awesome. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"eslint.experimental.useFlatConfig": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @ts-check | ||
|
||
import safeql from "@ts-safeql/eslint-plugin/config"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
export default tseslint.config( | ||
...tseslint.configs.recommendedTypeCheckedOnly, | ||
safeql.configs.connections({ | ||
databaseUrl: "postgres://postgres:postgres@localhost:5432/safeql_basic_flat_config", | ||
targets: [{ tag: "sql", transform: "{type}[]" }], | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@ts-safeql-demos/basic-flat-config", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc --watch", | ||
"setup": "tsx src/setup.ts", | ||
"lint": "eslint src", | ||
"lint!": "eslint src --fix" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.15.11", | ||
"@eslint/js": "^8.56.0", | ||
"@types/eslint": "^8.56.10", | ||
"eslint": "^8.57.0", | ||
"tsx": "^4.9.1", | ||
"typescript": "^5.4.5", | ||
"typescript-eslint": "^7.8.0" | ||
}, | ||
"dependencies": { | ||
"@ts-safeql/eslint-plugin": "workspace:*", | ||
"postgres": "^3.3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import postgres from "postgres"; | ||
|
||
type ID = number; | ||
|
||
export async function check(idsFromParameter: ID[]) { | ||
const sql = postgres(); | ||
|
||
await sql<{ id: number }[]>` | ||
SELECT id | ||
FROM person | ||
WHERE TRUE | ||
AND id = ${idsFromParameter[0] > 5 ? 5 : 5} | ||
AND id = ANY(${idsFromParameter}) | ||
AND name = ${"John"} -- string literal | ||
`; | ||
|
||
// Conditional expression | ||
await sql<{ id: number }[]>`SELECT id FROM starship WHERE id = ${ | ||
idsFromParameter[0] > 5 ? 5 : 5 | ||
}`; | ||
|
||
// Nullish coalescing operator | ||
const x = 5 as number | null; | ||
await sql<{ id: number }[]>`SELECT id FROM starship WHERE id = ${x ?? 10}`; | ||
|
||
interface AgencyIdNameType { | ||
id: number; | ||
name: string; | ||
} | ||
|
||
await sql<AgencyIdNameType[]>`SELECT id, name FROM person`; | ||
|
||
interface AgencyIdNameInterface { | ||
id: number; | ||
name: string; | ||
} | ||
|
||
await sql<AgencyIdNameInterface[]>`SELECT id, name FROM person`; | ||
await sql<{ id: number; name: string }[]>`SELECT id, name FROM person`; | ||
|
||
await sql.end(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { execSync } from "child_process"; | ||
import postgres from "postgres"; | ||
|
||
const DATABASE_NAME = "safeql_basic_flat_config"; | ||
|
||
async function main() { | ||
// 1. Drop the database if exists | ||
console.log("Dropping database if exists..."); | ||
execSync(`psql -c "DROP DATABASE IF EXISTS ${DATABASE_NAME} WITH (FORCE);"`); | ||
|
||
// 2. Create a new database | ||
console.log("Creating database..."); | ||
execSync(`psql -U postgres -c "CREATE DATABASE ${DATABASE_NAME};"`); | ||
|
||
// 3. Connect to the database | ||
console.log("Connecting to database..."); | ||
const sql = postgres(`postgres://postgres@localhost:5432/${DATABASE_NAME}`); | ||
|
||
// 4. Create tables | ||
console.log("Creating tables..."); | ||
await sql.unsafe(` | ||
CREATE TABLE person ( | ||
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
name VARCHAR(255) NOT NULL | ||
); | ||
CREATE TABLE starship ( | ||
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
name VARCHAR(255) NOT NULL, | ||
captain_id INTEGER REFERENCES person(id) | ||
); | ||
`); | ||
|
||
console.log("✅ Done!"); | ||
await sql.end(); | ||
} | ||
|
||
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.node.json", | ||
"compilerOptions": { | ||
"noEmit": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"eslint.experimental.useFlatConfig": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @ts-check | ||
|
||
import safeql from "@ts-safeql/eslint-plugin/config"; | ||
import tseslint from "typescript-eslint"; | ||
|
||
export default tseslint.config( | ||
...tseslint.configs.recommendedTypeCheckedOnly, | ||
safeql.configs.useConfigFile | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@ts-safeql-demos/config-file-flat-config", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc --watch", | ||
"setup": "tsx src/setup.ts", | ||
"lint": "eslint src", | ||
"lint!": "eslint src --fix" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.15.11", | ||
"@eslint/js": "^8.56.0", | ||
"@types/eslint": "^8.56.10", | ||
"eslint": "^8.57.0", | ||
"tsx": "^4.9.1", | ||
"typescript": "^5.4.5", | ||
"typescript-eslint": "^7.8.0" | ||
}, | ||
"dependencies": { | ||
"@ts-safeql/eslint-plugin": "workspace:*", | ||
"postgres": "^3.3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from "@ts-safeql/eslint-plugin"; | ||
|
||
export default defineConfig({ | ||
connections: { | ||
databaseUrl: "postgres://postgres:postgres@localhost:5432/safeql_config_file_flat_config", | ||
targets: [{ tag: "sql", transform: "{type}[]" }], | ||
}, | ||
}); |
Oops, something went wrong.