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

fix: imports are not working correctly #864

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changeset/green-beds-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@asyncapi/glee-shared-utils": patch
"@asyncapi/gleequore": patch
---

Importing gleequore doesn't work correctly. It imports the types but doesn't let you import the implementation so it's unusable. This is fixed in this release.
13 changes: 12 additions & 1 deletion packages/gleequore/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export default {
'^nimma/legacy$': '<rootDir>/../../node_modules/nimma/dist/legacy/cjs/index.js',
'^nimma/fallbacks$':
'<rootDir>/../../node_modules/nimma/dist/legacy/cjs/fallbacks/index.js',
'^@asyncapi/glee-shared-utils$': '<rootDir>/../../packages/shared-utils/index.ts'
},
transform: {},
transform: {
'^.+\\.tsx?$': ['ts-jest', {
useESM: true,
tsconfig: {
rootDir: "../../",
baseUrl: ".",
}
}]
},
roots: ['<rootDir>/src/', '<rootDir>/test/', '<rootDir>/../../packages/shared-utils/'],
modulePaths: ['<rootDir>/src/', '<rootDir>/../../packages/shared-utils/'],
}
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
3 changes: 0 additions & 3 deletions packages/gleequore/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { describe, it, jest, beforeEach, expect } from '@jest/globals';
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
import GleeQuore from '../src/index';
import { EventEmitter } from 'events';
import { Parser } from '@asyncapi/parser'
import { GleeQuoreAuthFunction, GleeQuoreAuthFunctionEvent } from '../src/index.d';
import GleeQuoreConnection from '../src/lib/connection';

const asyncapiDocumentAsJS = {
asyncapi: '3.0.0',
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
Loading