Skip to content

Commit

Permalink
remove dependency on pouchdb-core
Browse files Browse the repository at this point in the history
it was causing undue trouble in types exports
  • Loading branch information
shimaore committed Dec 24, 2023
1 parent 5e4eddf commit 62ab3af
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 590 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:promise/recommended",
"standard-with-typescript"
],
Expand Down
Binary file modified .yarn/install-state.gz
Binary file not shown.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
},
"devDependencies": {
"@types/node": "20.10.5",
"@types/pouchdb-adapter-memory": "6.1.6",
"@types/pouchdb-core": "7.0.14",
"@types/uuid": "9.0.7",
"@typescript-eslint/eslint-plugin": "6.15.0",
"@typescript-eslint/parser": "6.15.0",
Expand All @@ -66,8 +64,6 @@
"eslint-plugin-promise": "6.1.1",
"memdown": "6.1.1",
"nyc": "15.1.0",
"pouchdb-adapter-memory": "8.0.1",
"pouchdb-core": "8.0.1",
"typescript": "5.3.3",
"ulidx": "2.2.1",
"uuid": "9.0.1"
Expand All @@ -77,7 +73,7 @@
"prepublishOnly": "yarn install && yarn build && yarn syntax",
"prelint": "yarn syntax",
"lint": "eslint --fix src/*.ts test/*.ts",
"pretest": "yarn install && yarn prepublishOnly && tsc --emitDeclarationOnly false",
"pretest": "yarn install && yarn prepublishOnly && yarn syntax:test",
"test": "nyc ava -c 1",
"syntax": "tsc",
"test:live": "podman build --ulimit nofile=1048576:1048576 -f test/Dockerfile ."
Expand Down
14 changes: 6 additions & 8 deletions src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter<keyof FreeSwitchR
private __uuid: string | undefined = undefined
private readonly __socket: Socket
private readonly logger: FreeSwitchResponseLogger
private __queue: Promise<null | unknown>
private __queue: Promise<true>
private readonly __later: Map<string, FreeSwitchEventData>

// The module provides statistics in the `stats` object if it is initialized. You may use it to collect your own call-related statistics.
Expand Down Expand Up @@ -493,7 +493,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter<keyof FreeSwitchR
})

// The object also provides a queue for operations which need to be submitted one after another on a given socket because FreeSwitch does not provide ways to map event socket requests and responses in the general case.
this.__queue = Promise.resolve(null)
this.__queue = Promise.resolve(true)
// The object also provides a mechanism to report events that might already have been triggered.
this.__later = new Map()
// We also must track connection close in order to prevent writing to a closed socket.
Expand Down Expand Up @@ -526,7 +526,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter<keyof FreeSwitchR
this.__socket.end()
}
this.removeAllListeners()
this.__queue = Promise.resolve(null)
this.__queue = Promise.resolve(true)
this.__later.clear()
}
this.once('socket.error', once_socket_star)
Expand Down Expand Up @@ -673,9 +673,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter<keyof FreeSwitchR
await q
return (await f())
})()
this.__queue = next.catch(function () {
return true
})
this.__queue = next.then(() => true, () => true)
return await next
}

Expand Down Expand Up @@ -789,7 +787,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter<keyof FreeSwitchR
}
// Typically `command/reply` will contain the status in the `Reply-Text` header while `api/response` will contain the status in the body.
const msg = `send ${command} ${JSON.stringify(args)}`
const sendHandler = async (): Promise<never | FreeSwitchEventData> => {
const sendHandler = async (): Promise<FreeSwitchEventData> => {
const p = this.onceAsync('freeswitch_command_reply', timeout, msg)
const q = this.write(command, args)
const [res] = (await Promise.all([p, q]))
Expand Down Expand Up @@ -1071,7 +1069,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter<keyof FreeSwitchR
})
}
const msg = `api ${command}`
const apiHandler = async (): Promise<never | { headers: StringMap, body: string, uuid?: string }> => {
const apiHandler = async (): Promise<{ headers: StringMap, body: string, uuid?: string }> => {
const p = this.onceAsync('freeswitch_api_response', timeout, msg)
const q = this.write(msg, {})
const [res] = (await Promise.all([p, q]))
Expand Down
32 changes: 12 additions & 20 deletions test/90-base-server-2cps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import {
stop
} from './utils.js'

import PouchDB from 'pouchdb-core'

import PouchDBAdapterMemory from 'pouchdb-adapter-memory'

import { second, sleep, clientLogger as logger, clientLogger, DoCatch } from './tools.js'

const domain = '127.0.0.1:5062'
Expand Down Expand Up @@ -54,33 +50,32 @@ const server2 = {
}
}

let db: PouchDB.Database<{ _id: string, comment: string, target: string }>

// We implement a small LCR database using PouchDB.
const ev = new FreeSwitchEventEmitter()

test.before(async function (t) {
const DB = PouchDB.plugin(PouchDBAdapterMemory).defaults({
adapter: 'memory'
})
db = new DB('routes')
await db.bulkDocs([
const db = new Map<string, { _id: string, comment: string, target: string }>()
db.set('route:',
{
_id: 'route:',
comment: 'default',
target: '324343'
},
}
)
db.set('route:1',
{
_id: 'route:1',
comment: 'NANPA',
target: '37382'
},
}
)
db.set('route:1435',
{
_id: 'route:1435',
comment: 'some state',
target: '738829'
}
])
)
const service = async function (call: FreeSwitchResponse, { data }: { data: StringMap }): Promise<void> {
const destination = data.variable_sip_req_user as string
if (destination.match(/^lcr7010-\d+$/) != null) {
Expand All @@ -101,18 +96,15 @@ test.before(async function (t) {
return results
})()).reverse()
// and these are retrieved from the database.
const { rows } = (await db.allDocs({
keys: ids,
include_docs: true
}))
const rows = ids.map(k => db.get(k))
// The first successful route is selected.
const doc = ((function () {
const results = []
const len = rows.length
for (let j = 0; j < len; j++) {
const row = rows[j]
if ('doc' in row && row.doc != null) {
results.push(row.doc)
if (row != null) {
results.push(row)
}
}
return results
Expand Down
1 change: 1 addition & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ COPY src /opt/src
RUN yarn build
COPY test /opt/test
COPY tsconfig.json /opt/
COPY tsconfig-test.json /opt/
RUN yarn syntax && yarn pretest
RUN ulimit -a && yarn test
Loading

0 comments on commit 62ab3af

Please sign in to comment.