generated from tpl/purs
chore: fmt
This commit is contained in:
parent
07306d60a0
commit
f8e31d1d67
27
bun/fmt.js
Normal file
27
bun/fmt.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/** @type {(parser: string, ps: string[]) => import("bun").Subprocess} */
|
||||||
|
const prettier = (parser, ps) =>
|
||||||
|
Bun.spawn(['bun', 'x', 'prettier', '--write', '--parser', parser, ...ps], {
|
||||||
|
stdout: 'inherit',
|
||||||
|
stderr: 'inherit',
|
||||||
|
})
|
||||||
|
|
||||||
|
const procs = [
|
||||||
|
prettier('babel', ['./src/**/*.js', './bun/**/*.js', './.prettierrc.cjs']),
|
||||||
|
prettier('json', ['./package.json', './jsconfig.json']),
|
||||||
|
Bun.spawn(
|
||||||
|
[
|
||||||
|
'bun',
|
||||||
|
'x',
|
||||||
|
'purs-tidy',
|
||||||
|
'format-in-place',
|
||||||
|
'src/**/*.purs',
|
||||||
|
'test/**/*.purs',
|
||||||
|
],
|
||||||
|
{
|
||||||
|
stdout: 'inherit',
|
||||||
|
stderr: 'inherit',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
await Promise.all(procs.map(p => p.exited))
|
16
jsconfig.json
Normal file
16
jsconfig.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": ["bun-types"],
|
||||||
|
"lib": ["esnext"],
|
||||||
|
"target": "esnext",
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"jsx": "react",
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"strict": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.js", "bun/**/*.js"]
|
||||||
|
}
|
10
package.json
10
package.json
@ -10,10 +10,16 @@
|
|||||||
"better-sqlite3": "^9.2.2",
|
"better-sqlite3": "^9.2.2",
|
||||||
"github-release-notes": "^0.17.1",
|
"github-release-notes": "^0.17.1",
|
||||||
"paluh-litps": "^0.1.4",
|
"paluh-litps": "^0.1.4",
|
||||||
"spago": "next"
|
"spago": "next",
|
||||||
|
"bun-types": "1.0.11",
|
||||||
|
"purs-tidy": "^0.10.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": "^5.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "paluh-litps compile --file README.md; mv README.purs test/README.purs",
|
"pretest": "paluh-litps compile --file README.md; mv README.purs test/README.purs",
|
||||||
"test": "spago test"
|
"test": "spago test",
|
||||||
|
"fmt": "bun bun/fmt.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,39 +6,46 @@
|
|||||||
// Putting this import into `PostgreSQL/Value.js` caused is a problem
|
// Putting this import into `PostgreSQL/Value.js` caused is a problem
|
||||||
// for the web bundlers etc.
|
// for the web bundlers etc.
|
||||||
|
|
||||||
import pg from 'pg';
|
import pg from 'pg'
|
||||||
|
|
||||||
// pg does strange thing converting DATE
|
// pg does strange thing converting DATE
|
||||||
// value to js Date, so we have
|
// value to js Date, so we have
|
||||||
// to prevent this craziness
|
// to prevent this craziness
|
||||||
pg.types.setTypeParser(1082 /* DATE_OID */, function(dateString) { return dateString; });
|
pg.types.setTypeParser(1082 /* DATE_OID */, function (dateString) {
|
||||||
|
return dateString
|
||||||
|
})
|
||||||
|
|
||||||
export const ffiConnect = function (config) {
|
export const ffiConnect = function (config) {
|
||||||
return function (pool) {
|
return function (pool) {
|
||||||
return function (onError, onSuccess) {
|
return function (onError, onSuccess) {
|
||||||
var p = pool.connect().then(function(client) {
|
var p = pool
|
||||||
onSuccess(config.right({
|
.connect()
|
||||||
|
.then(function (client) {
|
||||||
|
onSuccess(
|
||||||
|
config.right({
|
||||||
client: client,
|
client: client,
|
||||||
done: function () {
|
done: function () {
|
||||||
return client.release();
|
return client.release()
|
||||||
}
|
},
|
||||||
}));
|
}),
|
||||||
}).catch(function(err) {
|
)
|
||||||
var pgError = config.nullableLeft(err);
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
var pgError = config.nullableLeft(err)
|
||||||
if (pgError) {
|
if (pgError) {
|
||||||
onSuccess(pgError);
|
onSuccess(pgError)
|
||||||
} else {
|
} else {
|
||||||
onError(err);
|
onError(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return function (cancelError, cancelerError, cancelerSuccess) {
|
return function (cancelError, cancelerError, cancelerSuccess) {
|
||||||
p.cancel();
|
p.cancel()
|
||||||
cancelerSuccess();
|
cancelerSuccess()
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const ffiUnsafeQuery = function (config) {
|
export const ffiUnsafeQuery = function (config) {
|
||||||
// Either `Pool` or `Client` instance
|
// Either `Pool` or `Client` instance
|
||||||
@ -46,34 +53,37 @@ export const ffiUnsafeQuery = function(config) {
|
|||||||
return function (sql) {
|
return function (sql) {
|
||||||
return function (values) {
|
return function (values) {
|
||||||
return function (onError, onSuccess) {
|
return function (onError, onSuccess) {
|
||||||
var q = dbHandle.query({
|
var q = dbHandle
|
||||||
|
.query({
|
||||||
text: sql,
|
text: sql,
|
||||||
values: values,
|
values: values,
|
||||||
rowMode: 'array',
|
rowMode: 'array',
|
||||||
}).then(function(result) {
|
})
|
||||||
onSuccess(config.right(result));
|
.then(function (result) {
|
||||||
}).catch(function(err) {
|
onSuccess(config.right(result))
|
||||||
var pgError = config.nullableLeft(err);
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
var pgError = config.nullableLeft(err)
|
||||||
if (pgError) {
|
if (pgError) {
|
||||||
onSuccess(pgError);
|
onSuccess(pgError)
|
||||||
} else {
|
} else {
|
||||||
onError(err);
|
onError(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return function (cancelError, cancelerError, cancelerSuccess) {
|
return function (cancelError, cancelerError, cancelerSuccess) {
|
||||||
q.cancel();
|
q.cancel()
|
||||||
cancelerSuccess();
|
cancelerSuccess()
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const ffiSQLState = function (error) {
|
export const ffiSQLState = function (error) {
|
||||||
return error.code || null;
|
return error.code || null
|
||||||
};
|
}
|
||||||
|
|
||||||
export const ffiErrorDetail = function (error) {
|
export const ffiErrorDetail = function (error) {
|
||||||
return {
|
return {
|
||||||
@ -94,6 +104,6 @@ export const ffiErrorDetail = function (error) {
|
|||||||
constraint: error.constraint || '',
|
constraint: error.constraint || '',
|
||||||
file: error.file || '',
|
file: error.file || '',
|
||||||
line: error.line || '',
|
line: error.line || '',
|
||||||
routine: error.routine || ''
|
routine: error.routine || '',
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
import pg from 'pg';
|
import pg from 'pg'
|
||||||
|
|
||||||
export const ffiNew = function (config) {
|
export const ffiNew = function (config) {
|
||||||
return function () {
|
return function () {
|
||||||
return new pg.Pool(config);
|
return new pg.Pool(config)
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
export const totalCount = function (pool) {
|
export const totalCount = function (pool) {
|
||||||
return function () {
|
return function () {
|
||||||
return pool.totalCount;
|
return pool.totalCount
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const idleCount = function (pool) {
|
export const idleCount = function (pool) {
|
||||||
return function () {
|
return function () {
|
||||||
return pool.idleCount;
|
return pool.idleCount
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const waitingCount = function (pool) {
|
export const waitingCount = function (pool) {
|
||||||
return function () {
|
return function () {
|
||||||
return pool.waitingCount;
|
return pool.waitingCount
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
/* global Buffer, exports, require */
|
/* global Buffer, exports, require */
|
||||||
/* jshint -W097 */
|
/* jshint -W097 */
|
||||||
|
|
||||||
export const null_ = null;
|
export const null_ = null
|
||||||
|
|
||||||
export const instantToString = function (i) {
|
export const instantToString = function (i) {
|
||||||
return new Date(i).toUTCString();
|
return new Date(i).toUTCString()
|
||||||
};
|
}
|
||||||
|
|
||||||
export const instantFromString = function (Left) {
|
export const instantFromString = function (Left) {
|
||||||
return function (Right) {
|
return function (Right) {
|
||||||
return function (s) {
|
return function (s) {
|
||||||
try {
|
try {
|
||||||
return Right(Date.parse(s));
|
return Right(Date.parse(s))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Left("Date string parsing failed: \"" + s + "\", with: " + e);
|
return Left('Date string parsing failed: "' + s + '", with: ' + e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const unsafeIsBuffer = function (x) {
|
export const unsafeIsBuffer = function (x) {
|
||||||
return x instanceof Buffer;
|
return x instanceof Buffer
|
||||||
};
|
}
|
||||||
|
@ -21,10 +21,10 @@ import Polyform.Batteries.Int (validator) as Int
|
|||||||
import Polyform.Validator (runValidator)
|
import Polyform.Validator (runValidator)
|
||||||
import Type.Row (type (+))
|
import Type.Row (type (+))
|
||||||
|
|
||||||
validator ∷
|
validator
|
||||||
∀ err m.
|
∷ ∀ err m
|
||||||
Monad m ⇒
|
. Monad m
|
||||||
Env.Validator m (IntExpected + MissingValue + err) Env.Env Configuration
|
⇒ Env.Validator m (IntExpected + MissingValue + err) Env.Env Configuration
|
||||||
validator =
|
validator =
|
||||||
{ database: _, host: _, idleTimeoutMillis: _, max: _, password: _, port: _, user: _ }
|
{ database: _, host: _, idleTimeoutMillis: _, max: _, password: _, port: _, user: _ }
|
||||||
<$> Env.required "PG_DB" identity
|
<$> Env.required "PG_DB" identity
|
||||||
|
@ -54,10 +54,10 @@ withClientTransaction = PG.withClientTransaction runExceptT
|
|||||||
pgEqual :: forall a. Eq a => Show a => a -> a -> AppM Unit
|
pgEqual :: forall a. Eq a => Show a => a -> a -> AppM Unit
|
||||||
pgEqual a b = lift $ equal a b
|
pgEqual a b = lift $ equal a b
|
||||||
|
|
||||||
withRollback ∷
|
withRollback
|
||||||
Client →
|
∷ Client
|
||||||
AppM Unit →
|
→ AppM Unit
|
||||||
AppM Unit
|
→ AppM Unit
|
||||||
withRollback client action = begin *> action *> rollback
|
withRollback client action = begin *> action *> rollback
|
||||||
where
|
where
|
||||||
conn = fromClient client
|
conn = fromClient client
|
||||||
@ -66,19 +66,19 @@ withRollback client action = begin *> action *> rollback
|
|||||||
|
|
||||||
rollback = execute conn (Query "ROLLBACK TRANSACTION") Row0
|
rollback = execute conn (Query "ROLLBACK TRANSACTION") Row0
|
||||||
|
|
||||||
test ∷
|
test
|
||||||
Connection →
|
∷ Connection
|
||||||
String →
|
→ String
|
||||||
AppM Unit →
|
→ AppM Unit
|
||||||
TestSuite
|
→ TestSuite
|
||||||
test (Connection (Left _)) name action = Test.Unit.test name $ checkPGErrors $ action
|
test (Connection (Left _)) name action = Test.Unit.test name $ checkPGErrors $ action
|
||||||
|
|
||||||
test (Connection (Right client)) name action = Test.Unit.test name $ checkPGErrors $ withRollback client action
|
test (Connection (Right client)) name action = Test.Unit.test name $ checkPGErrors $ withRollback client action
|
||||||
|
|
||||||
transactionTest ∷
|
transactionTest
|
||||||
String →
|
∷ String
|
||||||
AppM Unit →
|
→ AppM Unit
|
||||||
TestSuite
|
→ TestSuite
|
||||||
transactionTest name action = Test.Unit.test name $ checkPGErrors $ action
|
transactionTest name action = Test.Unit.test name $ checkPGErrors $ action
|
||||||
|
|
||||||
checkPGErrors :: AppM Unit -> Aff Unit
|
checkPGErrors :: AppM Unit -> Aff Unit
|
||||||
@ -487,8 +487,8 @@ main = do
|
|||||||
equal (parseURI validUriToPoolConfigs.uri) (Just validUriToPoolConfigs.poolConfig)
|
equal (parseURI validUriToPoolConfigs.uri) (Just validUriToPoolConfigs.poolConfig)
|
||||||
equal (parseURI notValidConnUri) Nothing
|
equal (parseURI notValidConnUri) Nothing
|
||||||
|
|
||||||
validUriToPoolConfigs ::
|
validUriToPoolConfigs
|
||||||
{ uri :: PGConnectionURI
|
:: { uri :: PGConnectionURI
|
||||||
, poolConfig :: Configuration
|
, poolConfig :: Configuration
|
||||||
}
|
}
|
||||||
validUriToPoolConfigs =
|
validUriToPoolConfigs =
|
||||||
|
Loading…
Reference in New Issue
Block a user