Skip to content

Commit

Permalink
correct arc.ws._api type
Browse files Browse the repository at this point in the history
also remove some old JSDoc since it's mixing with .d.ts in a confusing way for consumers
  • Loading branch information
tbeseda committed Feb 2, 2024
1 parent 662f70f commit 5247ebd
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 79 deletions.
23 changes: 1 addition & 22 deletions src/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,5 @@ let subFactory = require('./subscribe')
module.exports = function eventsAndQueuesFactory (arc, type) {
let publish = pubFactory(arc, type)
let subscribe = subFactory(type)
return {
/**
* `arc.events|queues.publish`
* publish events and queues
*
* @param {Object} params
* @param {String} params.name - the event name (required)
* @param {Object} params.payload - a json event payload (required)
* @param {Function} callback - a node style errback (optional)
* @returns {Promise} - returned if no callback is supplied
*/
publish,

/**
* `arc.events|queues.subscribe`
* listen for events and queues
*
* @param {Function} handler - a single event handler function
* @returns {Lambda} - a Lambda function sig
*/
subscribe
}
return { publish, subscribe }
}
2 changes: 1 addition & 1 deletion src/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let { join } = require('path')
* In order to keep this method sync, it does not use reflection to get fingerprint status
* - Not checking @static fingerprint true (which we used to read from the .arc file) is possibly dangerous, so ensure asset path is valid
* - ? TODO: add fingerprint state to env vars in Arc 6 to restore config safety?
* @param {string} path - the path to the asset (eg. /index.js)
* @param {string} asset - the path to the asset (eg. /index.js)
* @returns {string} path - the resolved asset path (eg. /_static/index-xxx.js)
*/
module.exports = function _static (asset, options = {}) {
Expand Down
39 changes: 0 additions & 39 deletions src/ws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ function instantiateAPI () {
})
}

/**
* arc.ws._api
*
* Get the raw WebSocket client
*
* @param {Function} callback - a node style errback (optional)
* @returns {Promise} - returned if no callback is supplied
*/
function _api (callback) {
if (callback) instantiateAPI()
.then(client => callback(null, client.ApiGatewayManagementApi))
Expand All @@ -48,17 +40,6 @@ function _api (callback) {
})
}

/**
* arc.ws.send
*
* Publish WebSocket events
*
* @param {Object} params
* @param {String} params.id - the ws connection id (required)
* @param {Object} params.payload - an event payload (required)
* @param {Function} callback - a node style errback (optional)
* @returns {Promise} - returned if no callback is supplied
*/
function send ({ id, payload }, callback) {
if (callback) instantiateAPI()
.then(client => {
Expand Down Expand Up @@ -87,16 +68,6 @@ function send ({ id, payload }, callback) {
})
}

/**
* arc.ws.close
*
* Terminate a WebSocket client connection
*
* @param {Object} params
* @param {String} params.id - the ws connection id (required)
* @param {Function} callback - a node style errback (optional)
* @returns {Promise} - returned if no callback is supplied
*/
function close ({ id }, callback) {
if (callback) instantiateAPI()
.then(client => {
Expand All @@ -123,16 +94,6 @@ function close ({ id }, callback) {
})
}

/**
* arc.ws.info
*
* Get info on a WebSocket client connection
*
* @param {Object} params
* @param {String} params.id - the ws connection id (required)
* @param {Function} callback - a node style errback (optional)
* @returns {Promise} - returned if no callback is supplied
*/
function info ({ id }, callback) {
if (callback) instantiateAPI()
.then(client => {
Expand Down
15 changes: 0 additions & 15 deletions types/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ import type { SendMessageResponse as SqsPublishResponse } from "@aws-lite/sqs-ty
// Turn off automatic exporting
export { };

// // import { PublishResponse } from "@aws-sdk/client-sns"; // @3.503.1
// interface PublishResponse {
// MessageId?: string;
// SequenceNumber?: string;
// }

// // import { SendMessageResult } from "@aws-sdk/client-sqs"; // @3.503.1
// interface SendMessageResult {
// MD5OfMessageBody?: string;
// MD5OfMessageAttributes?: string;
// MD5OfMessageSystemAttributes?: string;
// MessageId?: string;
// SequenceNumber?: string;
// }

interface Params<Payload> {
name: string;
payload: Payload;
Expand Down
6 changes: 5 additions & 1 deletion types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import arc from "../";
import type { HttpHandler, HttpAsyncHandler } from "../"
import type { HttpMethods, HttpRequest, HttpResponse } from "./http";

// SERVICES
const servicesResult = await arc.services();
expectType<Record<string, any>>(servicesResult);

// EVENTS
const eventsPublishArg = { name: "test", payload: { foo: "bar" } };
const eventsPublishResult = await arc.events.publish(eventsPublishArg);
Expand Down Expand Up @@ -124,7 +128,7 @@ await myTable.scanAll({
})

// WS
expectType<AwsLiteClient["ApiGatewayManagementApi"]>(arc.ws._api);
expectType<AwsLiteClient["ApiGatewayManagementApi"]>(await arc.ws._api());
expectType<void>(await arc.ws.send({ id: "foo", payload: { bar: "baz" } }));
expectType<void>(await arc.ws.close({ id: "foo" }));
expectType<GetConnectionResponse>(
Expand Down
3 changes: 2 additions & 1 deletion types/ws.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type CloseParams = { id: string };
type InfoParams = { id: string };

export interface ArcWebSocket {
_api: AwsLiteClient["ApiGatewayManagementApi"];
_api(): Promise<AwsLiteClient["ApiGatewayManagementApi"]>;
_api(callback: Callback<AwsLiteClient["ApiGatewayManagementApi"]>): void;

send(params: SendParams): Promise<void>;
send(params: SendParams, callback: Callback<void>): void;
Expand Down

0 comments on commit 5247ebd

Please sign in to comment.