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

deno publish requires base classes to be exported or else "Failed ensuring public API type output is valid." #23658

Closed
andykais opened this issue May 2, 2024 · 3 comments · Fixed by #23661
Assignees
Labels
bug Something isn't working publish Related to "deno publish" subcommand

Comments

@andykais
Copy link

andykais commented May 2, 2024

Version: Deno 1.43.1

Checking for slow types in the public API...
Check file:///Users/andrew/Code/andykais/ts-rpc/client.ts
Check file:///Users/andrew/Code/andykais/ts-rpc/adapters/oak.ts
error: Failed ensuring public API type output is valid.

TS2304 [ERROR]: Cannot find name 'adapter_base'.
class ServerAdapter extends adapter_base.ServerAdapter {
                            ~~~~~~~~~~~~
    at file:///Users/andrew/Code/andykais/ts-rpc/adapters/oak.ts:36:29

You may have discovered a bug in Deno. Please open an issue at: https://github.com/denoland/deno/issues/
source code
import * as oak from 'jsr:@oak/oak'
import * as contracts from '../src/contracts.ts'
import * as adapter_base from './mod.ts'
import {ClientRealtimeEmitter, ApiController, ClientRequest} from '../server.ts'

type OakRouterContext = oak.RouterContext<string, Record<string | number, string>, Record<string, any>>
type OakRouterFunction = (ctx: OakRouterContext) => Promise

class ServerSentEventsAdapter extends adapter_base.ServerSentEventsAdapter {
#status_resolved: PromiseWithResolvers
#target: oak.ServerSentEventTarget

constructor(target: oak.ServerSentEventTarget) {
super()
this.#target = target
this.#status_resolved = Promise.withResolvers()
target.addEventListener('close', e => {
this.#status_resolved.resolve()
})
}

get status() {
return this.#status_resolved.promise
}

send(contract: contracts.EventContract) {
const success = this.#target.dispatchMessage(JSON.stringify(contract))
if (!success) {
throw new Error(Failed to dispatch message over server sent events adapter ${this.#target})
}
}
}

class ServerAdapter extends adapter_base.ServerAdapter {
async handle_server_sent_events_request(ctx: OakRouterContext) {
// TODO error out if x-rpc-connection-id is already present?
const target = await ctx.sendEvents()
const sse_adapter = new ServerSentEventsAdapter(target)

this.add_realtime_client(sse_adapter)

}

async handle_rpc_request(ctx: OakRouterContext) {
const request_contract: contracts.RequestContract = await ctx.request.body.json()
const connection_id = ctx.request.headers.get('x-rpc-connection-id')
const rpc_controller = this.load_controller(request_contract.namespace, connection_id)
const response_contract = await this.handle_request(rpc_controller, request_contract)
ctx.response.body = response_contract
}

static adapt<C, E>(rpc_class: typeof ApiController<C, E, any>, context: C): OakRouterFunction {
const adapter = new ServerAdapter(rpc_class, context)

return async (ctx: OakRouterContext) => {
  if (ctx.request.headers.get('accept') === 'text/event-stream') {
    await adapter.handle_server_sent_events_request(ctx)
  } else {
    await adapter.handle_rpc_request(ctx)
  }
}

}
}

export const adapt = ServerAdapter.adapt
export * from '../server.ts'

I can solve this issue by exporting adapter_base in this module. This is just a bit confusing for users to see this exported when using the library. Can someone confirm if this is an expected error?

export { adapter_base }

additional information

the source code is here https://github.com/andykais/ts-rpc/blob/deno-to-node-experiment/adapters/oak.ts (and this is the repo at the point in time that this issue was created https://github.com/andykais/ts-rpc/tree/dcff52451eacc06328153c74926acfe2e072ac2c)

@andykais
Copy link
Author

andykais commented May 2, 2024

holy crap that was a fast turnaround! I do think this may still be busted based on my github action (which appears to have used 1.43.1) https://github.com/andykais/ts-rpc/actions/runs/8931583359/job/24533936758. The code that deno publish attempted to upload: https://github.com/andykais/ts-rpc/blob/b29d43bd6703f04b17b8bbe24ea1c4acc2d7d4b7/adapters/oak.ts

@dsherret
Copy link
Member

dsherret commented May 2, 2024

I've been wanting to ensure bugs of this kind of fixed asap because they're quite painful.

It will be fixed in deno upgrade --canary once #23661 lands in the CLI and a full CI run occurs (and passes) on main.

@andykais
Copy link
Author

andykais commented May 3, 2024

👍 well thanks for the support. For now I can unblock myself with additional exports, Ill keep an eye on that pr though and close this issue out if my issue is fixed once that is released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working publish Related to "deno publish" subcommand
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants