Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updating repo #79

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cjs
mjs
node_modules
.vscode/configurationCache.log
.vscode/dryrun.log
.vscode/targets.log
cjs
coverage
mjs
node_modules
5 changes: 2 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.github
.vscode
*.sh
*.test.*
jest.*
Makefile
src
test
tsconfig.json
tsconfig.*
wip
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
test:
pnpm exec jest
pnpm tsc
pnpm eslint src
pnpm jest --coverage

clean:
rm -Rf cjs mjs test/*.js
Expand All @@ -11,7 +13,7 @@ build-cjs:

build-mjs:
rm -Rf mjs
pnpm exec tsc -d --sourceMap --outDir mjs
pnpm exec tsc -p tsconfig.mjs.json

build: build-cjs build-mjs

Expand All @@ -20,11 +22,11 @@ rebuild: clean build
update:
pnpm up --latest

preversion: rebuild test
preversion: test rebuild

postversion:
git push
git push --tags
pnpm publish
pnpm publish --access public

.PHONY: test
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@prelude/eslint-config'
28 changes: 12 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"scripts": {
"test": "make test",
"build": "make build",
"preversion": "make preversion",
"postversion": "make postversion"
},
Expand All @@ -33,21 +34,16 @@
"author": "Mirek Rusin <[email protected]>",
"license": "MIT",
"devDependencies": {
"@appliedblockchain/eslint-config": "3.1.1",
"@babel/core": "7.22.1",
"@swc/core": "1.3.62",
"@swc/jest": "0.2.26",
"@tsconfig/node18": "2.0.1",
"@types/debug": "4.1.8",
"@types/jest": "29.5.2",
"@types/node": "20.2.5",
"@types/tedious": "4.0.9",
"@typescript-eslint/eslint-plugin": "5.59.8",
"@typescript-eslint/parser": "5.59.8",
"debug": "4.3.4",
"eslint": "8.42.0",
"jest": "29.5.0",
"tedious": "16.1.0",
"typescript": "5.1.3"
"@jest/globals": "^29.7.0",
"@prelude/eslint-config": "0.0.1",
"@swc/core": "1.7.14",
"@swc/jest": "0.2.36",
"@tsconfig/node20": "^20.1.4",
"@types/node": "22.5.0",
"@types/tedious": "4.0.14",
"eslint": "9.9.0",
"jest": "29.7.0",
"tedious": "19.0.0",
"typescript": "5.5.4"
}
}
1 change: 1 addition & 0 deletions src/assign-object.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('assigns auto values', () => {
Expand Down
1 change: 1 addition & 0 deletions src/assign.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('assigns auto values', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/defined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const defined =
const object_ = Object.assign({}, object)
for (const key in object) {
if (typeof object_[key] === 'undefined') {

// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete object_[key]
}
}
Expand Down
1 change: 1 addition & 0 deletions src/demargin.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('simple', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/demargin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ export const demargin =
throw new TypeError(`Expected value to be string, got ${value}.`)
}
const lines = value.split('\n')
if (lines.length && lines[0].split('').every(_ => _ === ' ')) {
if ((lines.length > 0) && lines[0].split('').every(_ => _ === ' ')) {
lines.shift()
}
if (lines.length && lines[lines.length - 1].split('').every(_ => _ === ' ')) {
if ((lines.length > 0) && lines[lines.length - 1].split('').every(_ => _ === ' ')) {
lines.pop()
}
let margin = Infinity
for (let i = 0; i < lines.length; i++) {
for (let j = 0; j < lines[i].length; j++) {
if (lines[i][j] !== ' ') {
margin = Math.min(margin, j)
for (const line of lines) {
for (let i = 0; i < line.length; i++) {
if (line[i] !== ' ') {
margin = Math.min(margin, i)
break
}
}
Expand Down
1 change: 1 addition & 0 deletions src/identifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('basic', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Identifier =
export function isPlain(value: string) {
return (
!keywords[value.toLowerCase()] &&
!!String(value).match(/^[a-z_@#][a-z0-9_]*$/i)
!!String(value).match(/^[a-z_@#]\w*$/i)
)
}

Expand Down
7 changes: 4 additions & 3 deletions src/in.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('in', () => {
expect(Tsql.in('foo', [ 1 ])!.toString()).toEqual('foo in (1)')
expect(Tsql.in('foo', [])!.toString()).toEqual('0=1')
expect(Tsql.in('foo', null)!.toString()).toEqual('0=1')
expect(String(Tsql.in('foo', [ 1 ]))).toEqual('foo in (1)')
expect(String(Tsql.in('foo', []))).toEqual('0=1')
expect(String(Tsql.in('foo', null))).toEqual('0=1')
expect(typeof Tsql.in('foo', undefined)).toBe('undefined')
expect(
Tsql.and(
Expand Down
2 changes: 1 addition & 1 deletion src/in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const in_ =
(l: S | string, r: undefined | null | unknown[]): undefined | S =>
typeof r === 'undefined' ?
undefined :
r && !isNull(r) && r.length ?
r && !isNull(r) && (r.length > 0) ?
tsql`${fallback(l, id)} in ${row(r)}` :
logicalFalse

Expand Down
2 changes: 1 addition & 1 deletion src/inline-table-of-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import tsql from './template.js'
*/
export const inlineTableOfColumn =
(table: Sid | string, column: Sid | string, values: unknown[]): S => {
if (!values.length) {
if (values.length === 0) {
throw new Error(`Can't generate literal table ${table} using column ${column} with an empty array of values.`)
}
const table_ = id(table)
Expand Down
1 change: 1 addition & 0 deletions src/inline-table-of-objects.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('literalTableOfObjects', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/insert-not-matched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const insertNotMatched =
throw new TypeError(`Expected array of values, got ${objects}.`)
}

if (!objects.length) {
if (objects.length === 0) {
return tsql`select 0;`
}

Expand Down
1 change: 1 addition & 0 deletions src/insert-object.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('insert-object', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/insert-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const insertObject =
(table: Sid | string, object: Record<string, unknown>, output?: S): S => {
const object_ = defined(object)
const keys = Object.keys(object_)
if (!keys.length) {
if (keys.length === 0) {
throw new TypeError(`Expected object with keys, got ${object_}.`)
}
const table_ = id(table)
Expand Down
9 changes: 5 additions & 4 deletions src/insert-objects.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Sql from './test/sql.js'
import { beforeAll, afterAll, afterEach, test, expect } from '@jest/globals'
import Client from './test/client.js'

let sql: Sql
let sql: Client

beforeAll(async () => {
sql = await Sql.random()
sql = await Client.random()
}, 30 * 1000)

afterAll(async () => {
Expand Down Expand Up @@ -44,7 +45,7 @@ test.each([
1000,
1001,
2000
])('insert %i records', async (length) => {
])('insert %i records', async length => {
const users = Array.from({ length }, (_, i) => ({ name: `user-${i}` }))
await sql.insertObjects('Users', users)
await expect(sql.count('Users')).resolves.toBe(length)
Expand Down
2 changes: 1 addition & 1 deletion src/insert-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const insertObjects =
throw new TypeError(`Expected array of values, got ${objects}.`)
}

if (!objects.length) {
if (objects.length === 0) {
return tsql`select 0;`
}

Expand Down
1 change: 1 addition & 0 deletions src/interpolate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('simple', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/interpolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Margin = {
open: boolean
}

function updateMargin(margin: Margin, value: string) {
function updateMargin(mutableMargin: Margin, value: string) {

// Locate start of last line.
const start = value.lastIndexOf('\n') + 1
Expand All @@ -27,8 +27,8 @@ function updateMargin(margin: Margin, value: string) {
const blanks = end === value.length

// Update margin.
margin.column = multiline ? column : margin.column + (margin.open ? column : 0)
margin.open = (margin.open || multiline) && blanks
mutableMargin.column = multiline ? column : mutableMargin.column + (mutableMargin.open ? column : 0)
mutableMargin.open = (mutableMargin.open || multiline) && blanks
}

/**
Expand All @@ -40,7 +40,7 @@ export const interpolate =
if (!Array.isArray(xs) || !Array.isArray(ys)) {
throw new TypeError(`Expected xs and ys to be an array, got ${xs} and ${ys}.`)
}
if (!xs.length && !ys.length) {
if ((xs.length === 0) && (ys.length === 0)) {
return []
}
if (xs.length - 1 !== ys.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/interpolate1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const interpolate1 =
if (!Array.isArray(xs)) {
throw new TypeError(`Expected xs to be an array, got ${xs}.`)
}
if (!xs.length) {
if (xs.length === 0) {
return []
}
const rs: (T | I)[] = [ xs[0] ]
Expand Down
1 change: 1 addition & 0 deletions src/is-null.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('is-null', () => {
Expand Down
1 change: 1 addition & 0 deletions src/json-modify.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('jsonModify', () => {
Expand Down
1 change: 1 addition & 0 deletions src/json-path.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('jsonPath', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/json-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const jsonPath =
if (mode) {
parts.push(mode)
}
if (parts.length) {
if (parts.length > 0) {
return `${parts.join(' ')} $.${path}`
}
return `$.${path}`
Expand Down
2 changes: 1 addition & 1 deletion src/keys-of-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const keysOfObjects =
if (!Array.isArray(objects)) {
throw new TypeError(`Expected array, got ${objects}.`)
}
if (!objects.length) {
if (objects.length === 0) {
throw new TypeError('Expected non empty array.')
}
const keys = Object.keys(objects[0]).sort()
Expand Down
2 changes: 1 addition & 1 deletion src/keywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ const keywords_ = [
]

/** An array of MSSQL keywords. */
const keywords: { [keyword: string]: undefined | true } =
const keywords: Record<string, undefined | true> =
keywords_.reduce((r, _) => ({ ...r, [_]: true }), {})

export default keywords
7 changes: 4 additions & 3 deletions src/lines.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('simple', () => {
expect(() => Tsql.lines([])).toThrow('Expected at least one line.')
expect(() => Tsql.lines([undefined, undefined])).toThrow('Expected at least one line.')
expect(Tsql.lines(['foo', 'bar'])?.toString()).toEqual(`N'foo'\nN'bar'`)
expect(Tsql.lines(['foo', undefined, 'bar'])?.toString()).toEqual(`N'foo'\nN'bar'`)
expect(() => Tsql.lines([ undefined, undefined ])).toThrow('Expected at least one line.')
expect(Tsql.lines([ 'foo', 'bar' ])?.toString()).toEqual('N\'foo\'\nN\'bar\'')
expect(Tsql.lines([ 'foo', undefined, 'bar' ])?.toString()).toEqual('N\'foo\'\nN\'bar\'')
})
1 change: 1 addition & 0 deletions src/margin-of-first-line.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import marginOfFirstLine from './margin-of-first-line.js'

test('marginOfFirstLine', () => {
Expand Down
1 change: 1 addition & 0 deletions src/margin-of-last-line.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import marginOfLastLine from './margin-of-last-line.js'

test('marginOfLastLine', () => {
Expand Down
1 change: 1 addition & 0 deletions src/margin.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('margin', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/merge-1n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const merge1n =
if (!Array.isArray(values)) {
throw new TypeError(`Expected array of values, got ${values}.`)
}
if (!values.length) {
if (values.length === 0) {
return tsql`delete from ${table_} where ${lcolumn_} = ${lid};`
}
return tsql`
Expand Down
1 change: 1 addition & 0 deletions src/merge1n.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('merge1n', () => {
Expand Down
1 change: 1 addition & 0 deletions src/modify-jsons.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from '@jest/globals'
import * as Tsql from './index.js'

test('modify-jsons', () => {
Expand Down
Loading