Skip to content

Commit

Permalink
refactor: remove support for node 16
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add support for node 18 and fix all the dependecies issues
  • Loading branch information
jegj committed Oct 13, 2023
1 parent e162cad commit ad2d890
Show file tree
Hide file tree
Showing 17 changed files with 20,658 additions and 14,340 deletions.
11 changes: 5 additions & 6 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
ts: false
jsx: false
flow: false
check-coverage: true
coverage: true
node-arg: --allow-natives-syntax
"node-arg": [
"--no-warnings",
"--experimental-loader",
"esmock"
]
files:
- 'test/**/*.spec.js'
9 changes: 3 additions & 6 deletions lib/analyzer/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* lib/analyzer/index.js */
'use strict'

const { isAFilterFn, splitCopyStatement } = require('../utils')
const FN = require('../fn')
import { isAFilterFn, splitCopyStatement } from '../utils.js'
import FN from '../fn/index.js'

class Analyzer {
constructor (mapper, onVerboseMode = false, logger = console.warn) {
Expand Down Expand Up @@ -196,4 +193,4 @@ class Analyzer {
}
}

module.exports = Analyzer
export default Analyzer
11 changes: 5 additions & 6 deletions lib/fn/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* lib/fn/index.js */
'use strict'
import { faker } from '@faker-js/faker'
import pgfilter from './pgfilter/index.js'

const { faker } = require('@faker-js/faker')
const pgfilter = require('./pgfilter')

module.exports = {
export const library = {
pgfilter,
faker
}

export default library
11 changes: 4 additions & 7 deletions lib/fn/pgfilter/default.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/* lib/fn/pgfilter/default.js */
'use strict'

const zlen = function _zlen () {
export const zlen = function _zlen () {
return ''
}

const zlar = function _zlar () {
export const zlar = function _zlar () {
return '{}'
}

const nul = function _nul () {
export const nul = function _nul () {
return '\\N'
}

module.exports = {
export default {
zlen,
zlar,
nul
Expand Down
13 changes: 5 additions & 8 deletions lib/fn/pgfilter/filter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* lib/fn/pgfilter/filter.js */
'use strict'

const ftest = function _ftest (val, arg1, arg2, arg3) {
export const ftest = function _ftest (val, arg1, arg2, arg3) {
return {
val,
arg1: parseInt(arg1),
Expand All @@ -16,7 +13,7 @@ const ftest = function _ftest (val, arg1, arg2, arg3) {
* @param {string} ISO8601DUR
* @returns boolean True when the date does not match the range so must be filtered
*/
const fnow = function _fnow (val, ISO8601DUR) {
export const fnow = function _fnow (val, ISO8601DUR) {
if (!ISO8601DUR || typeof ISO8601DUR !== 'string') {
throw new Error('duration argument is required')
}
Expand All @@ -36,7 +33,7 @@ const fnow = function _fnow (val, ISO8601DUR) {
else return true
}

module.exports = {
fnow,
ftest
export default {
ftest,
fnow
}
12 changes: 7 additions & 5 deletions lib/fn/pgfilter/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* lib/fn/pgfilter/index.js */
'use strict'
import defaultFns from './default.js'
import filterFns from './filter.js'

module.exports = {
default: require('./default'),
filter: require('./filter')
export const library = {
default: defaultFns,
filter: filterFns
}

export default library
18 changes: 6 additions & 12 deletions lib/input.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/* lib/input.js */
'use strict'

const fs = require('fs')

const { inputFromSTDIN } = require('./utils')
const splitter = require('../lib/splitter')
const matcher = require('../lib/matcher')
const Analyzer = require('../lib/analyzer')
import fs from 'fs'
import { inputFromSTDIN } from './utils.js'
import splitter from '../lib/splitter.js'
import matcher from '../lib/matcher.js'
import Analyzer from '../lib/analyzer.js'

const _stdin = (analyzer, pgfilterCLIParseOpts) => {
process.stdin.setEncoding('utf8')
Expand All @@ -32,13 +28,11 @@ const _file = (analyzer, pgfilterCLIParseOpts) => {
).pipe(process.stdout)
}

const init = function _init (pgfilterCLIParseOpts) {
export const init = function _init (pgfilterCLIParseOpts) {
const analyzer = new Analyzer(pgfilterCLIParseOpts.file, pgfilterCLIParseOpts.verbose)
if (inputFromSTDIN(pgfilterCLIParseOpts)) {
_stdin(analyzer, pgfilterCLIParseOpts)
} else {
_file(analyzer, pgfilterCLIParseOpts)
}
}

module.exports = init
7 changes: 2 additions & 5 deletions lib/matcher/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* lib/matcher/index.js */

const { Transform } = require('stream')

const { isStartOfCopyStatement, isEndOfCopyStatement } = require('../utils')
import { Transform } from 'stream'
import { isStartOfCopyStatement, isEndOfCopyStatement } from '../utils'

const matcher = function _matcher (analyzer, { readableHighWaterMark = null, writableHighWaterMark = null } = { readableHighWaterMark: null, writableHighWaterMark: null }) {
const CopyTransform = new Transform({
Expand Down
8 changes: 2 additions & 6 deletions lib/splitter/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* lib/splitter */
import split2 from 'split2'

const split2 = require('split2')

const splitter = function splitter (matcher = null, mapper = null, options = {}) {
export const splitter = function splitter (matcher = null, mapper = null, options = {}) {
return split2(matcher, mapper, options)
}

module.exports = splitter
38 changes: 11 additions & 27 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* lib/utils.js */
'use strict'

const fs = require('fs')
import fs from 'fs'

const COPY_REGEX = /^COPY [\w.\w|\w]+ \((.+)\) FROM stdin;$/gm
const END_COPY_REGEX = /^\\\.$/gm
Expand All @@ -12,15 +9,15 @@ const matchRegex = function _matchRegex (line, regex) {
return !!result && result.length > 0
}

const isStartOfCopyStatement = function _isStartOfCopyStatement (line, regex = COPY_REGEX) {
export const isStartOfCopyStatement = function _isStartOfCopyStatement (line, regex = COPY_REGEX) {
return matchRegex(line, regex)
}

const isEndOfCopyStatement = function _isEndOfCopyStatement (line, regex = END_COPY_REGEX) {
export const isEndOfCopyStatement = function _isEndOfCopyStatement (line, regex = END_COPY_REGEX) {
return matchRegex(line, regex)
}

const splitCopyStatement = function _splitCopyStatement (line) {
export const splitCopyStatement = function _splitCopyStatement (line) {
const tokens = line.split(' ')
return [
tokens[0],
Expand All @@ -31,7 +28,7 @@ const splitCopyStatement = function _splitCopyStatement (line) {
]
}

const isAFilterFn = function _isAFilterFn (fnName) {
export const isAFilterFn = function _isAFilterFn (fnName) {
const tkns = fnName.split('.')
if (tkns.length === 3) {
return tkns[0] === 'pgfilter' && tkns[1] === 'filter'
Expand All @@ -40,7 +37,7 @@ const isAFilterFn = function _isAFilterFn (fnName) {
}
}

const handleSysErrors = (err, arg = 'argument') => {
export const handleSysErrors = (err, arg = 'argument') => {
switch (true) {
case err.code === 'ENOENT':
err.message = `'${arg}' must be a valid file path`
Expand All @@ -55,7 +52,7 @@ const handleSysErrors = (err, arg = 'argument') => {
return err
}

const validJSONFile = (file, arg, encode = UTF8) => {
export const validJSONFile = (file, arg, encode = UTF8) => {
let parsed; let err = null
try {
parsed = JSON.parse(fs.readFileSync(file, encode))
Expand All @@ -70,7 +67,7 @@ const validJSONFile = (file, arg, encode = UTF8) => {
return parsed
}

const validFile = (file, arg) => {
export const validFile = (file, arg) => {
let err = null
try {
fs.accessSync(file, fs.constants.R_OK)
Expand All @@ -85,15 +82,15 @@ const validFile = (file, arg) => {
return file
}

const validBackupFile = (file, arg) => {
export const validBackupFile = (file, arg) => {
if (file === null) {
return file
}

return validFile(file, arg)
}

const validBuffer = (buffer, arg) => {
export const validBuffer = (buffer, arg) => {
if (buffer !== undefined) {
let err = null
if (isNaN(buffer)) {
Expand All @@ -110,23 +107,10 @@ const validBuffer = (buffer, arg) => {
return buffer
}

const inputFromSTDIN = (yargsParsedOpts, prop = 'backup_file') => {
export const inputFromSTDIN = (yargsParsedOpts, prop = 'backup_file') => {
if (Object.prototype.hasOwnProperty.call(yargsParsedOpts, prop)) {
return yargsParsedOpts[prop] === null
} else {
return true
}
}

module.exports = {
isStartOfCopyStatement,
isEndOfCopyStatement,
splitCopyStatement,
isAFilterFn,
validJSONFile,
validBackupFile,
handleSysErrors,
validBuffer,
inputFromSTDIN,
validFile
}
Loading

0 comments on commit ad2d890

Please sign in to comment.