Skip to content

Commit

Permalink
fix: imports are not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fmvilas committed Oct 30, 2024
1 parent 2335548 commit ca4281b
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 107 deletions.
5 changes: 2 additions & 3 deletions packages/gleequore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"files": [
"dist",
"./src/index.d.ts"
"dist"
],
"types": "./src/index.d.ts",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
Expand Down
92 changes: 0 additions & 92 deletions packages/gleequore/src/index.d.ts

This file was deleted.

91 changes: 88 additions & 3 deletions packages/gleequore/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import GleeQuoreRouter, {
ChannelMiddlewareTuple,
GenericMiddleware,
} from './lib/router.js'
import GleeQuoreMessage, { IGleeQuoreMessageConstructor } from './lib/message.js'
import GleeQuoreMessage, { IGleeQuoreMessageConstructor, QueryParam } from './lib/message.js'
import { matchChannel, getParams, getMessagesSchema } from '@asyncapi/glee-shared-utils'
import { duplicateMessage } from './lib/utils.js'
import GleeQuoreConnection from './lib/connection.js'
Expand All @@ -20,8 +20,87 @@ import json2string from './middlewares/json2string.js'
import validate from './middlewares/validate.js'
import existsInAsyncAPI from './middlewares/existsInAsyncAPI.js'
import validateConnection from './middlewares/validateConnection.js'
import { AsyncAPIDocumentInterface } from '@asyncapi/parser'
import { AdapterRecord, AuthFunctionInfo, ClusterAdapterRecord, GleeQuoreFunction, GleeQuoreLifecycleFunction, GleeQuoreLifecycleEvent, GleeQuoreFunctionEvent, GleeQuoreAuthFunctionEvent, GleeQuoreAdapterOptions } from './index.d.js'
import type { AsyncAPIDocumentInterface, ServerInterface } from '@asyncapi/parser'

export interface AuthFunctionInfo {
clientAuth?: GleeQuoreAuthFunction
serverAuth?: GleeQuoreAuthFunction
}

export type AuthProps = {
getToken: () => string
getUserPass: () => {
username: string
password: string
}
getCert: () => string
getOauthToken: () => string
getHttpAPIKeys: (name: string) => string
getAPIKeys: () => string
}

export type GleeQuoreClusterAdapterConfig = {
adapter?: string | typeof GleeQuoreClusterAdapter
name?: string
url: string
}

export type GleeQuoreFunctionEvent = {
request: GleeQuoreMessage
app: GleeQuore
serverName: string
connection?: GleeQuoreConnection
payload?: any
query?: QueryParam
headers?: { [key: string]: string }
channel?: string
}

export type GleeQuoreLifecycleEvent = Omit<GleeQuoreFunctionEvent, "request">

export type GleeQuoreAuthFunctionEvent = {
app: GleeQuore
authProps: AuthProps
done: any
serverName: string
doc: any
}

export type GleeQuoreFunction = (
event: GleeQuoreFunctionEvent
) => Promise<any> | any

export type GleeQuoreLifecycleFunction = (
event: GleeQuoreLifecycleEvent
) => Promise<any> | any

export type GleeQuoreAuthFunction = (
event: GleeQuoreAuthFunctionEvent
) => Promise<GleeQuoreAuthFunctionEvent> | void

export interface GleeQuoreAdapterOptions {
glee: GleeQuore;
serverName: string;
server: ServerInterface;
parsedAsyncAPI: AsyncAPIDocumentInterface;
config?: object
}

export type AdapterRecord = {
Adapter: typeof GleeQuoreAdapter
instance?: GleeQuoreAdapter
serverName: string
server: ServerInterface
asyncapi: AsyncAPIDocumentInterface
config?: object
}

export type ClusterAdapterRecord = {
Adapter: typeof GleeQuoreClusterAdapter
instance?: GleeQuoreClusterAdapter,
clusterName?: string,
clusterURL?: string
}

const debug = Debug('gleequore')

Expand Down Expand Up @@ -641,3 +720,9 @@ export default class GleeQuore {
return [...new Set(serverNames)] // Dedupe the array
}
}

export { default as GleeQuoreAdapter } from './lib/adapter.js'
export { default as GleeQuoreMessage } from './lib/message.js'
export { default as GleeQuoreConnection } from './lib/connection.js'
export { default as GleeQuoreClusterAdapter } from './lib/cluster.js'
export { default as GleeQuoreError } from './errors.js'
5 changes: 3 additions & 2 deletions packages/gleequore/src/lib/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import GleeQuoreConnection from './connection.js'
import GleeQuore from '../index.js'
import GleeQuoreMessage from './message.js'
import { resolveFunctions, validateData } from '@asyncapi/glee-shared-utils'
import { AuthProps, GleeQuoreAdapterOptions } from '../index.d.js'
import type { IValidateDataReturn } from '@asyncapi/glee-shared-utils'
import { AuthProps, GleeQuoreAdapterOptions } from '../index.js'
import GleeQuoreError from '../errors.js'

export type EnrichedEvent = {
Expand Down Expand Up @@ -258,7 +259,7 @@ class GleeQuoreAdapter extends EventEmitter {
throw new Error('Method `send` is not implemented.')
}

validate(data: any, schema: object, triggerError = false) {
validate(data: any, schema: object, triggerError = false): IValidateDataReturn {
const { isValid, errors, humanReadableError } = validateData(data, schema)
if (!isValid && triggerError) {
throw new GleeQuoreError({ humanReadableError, errors })
Expand Down
4 changes: 2 additions & 2 deletions packages/gleequore/src/lib/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import EventEmitter from 'events'
import GleeQuoreConnection from './connection.js'
import { OperationInterface } from '@asyncapi/parser'

type MessageHeaders = { [key: string]: any }
type QueryParam = { [key: string]: string } | { [key: string]: string[] }
export type MessageHeaders = { [key: string]: any }
export type QueryParam = { [key: string]: string } | { [key: string]: string[] }

export interface IGleeQuoreMessageConstructor {
payload?: any
Expand Down
4 changes: 4 additions & 0 deletions packages/gleequore/try.js → packages/gleequore/try.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const { document: asyncapi } = await parser.parse({
},
})

if (!asyncapi) {
throw new Error('Not a valid AsyncAPI document')
}

const gleeQuore = new GleeQuore(asyncapi)

// gleeQuore.addAdapter(HttpAdapter, 'test', {
Expand Down
7 changes: 3 additions & 4 deletions packages/gleequore/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"esModuleInterop": true,
"moduleResolution": "nodenext",
"module": "NodeNext",
"rootDir": "./src"
"rootDir": "./src",
"declaration": true
},
"include": [
"./src/**/*"
],
"include": ["./src/**/*"],
"exclude": [
"node_modules",
"lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Ajv from 'ajv'
import betterAjvErrors from 'better-ajv-errors'
import { pathToRegexp } from 'path-to-regexp'

interface IValidateDataReturn {
export interface IValidateDataReturn {
errors?: void | betterAjvErrors.IOutputError[]
humanReadableError?: void | betterAjvErrors.IOutputError[]
isValid: boolean | PromiseLike<any>
Expand Down

0 comments on commit ca4281b

Please sign in to comment.