@awsless/awsless 0.0.364 → 0.0.366
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +19 -1
- package/dist/client.js +28 -0
- package/package.json +8 -7
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as _awsless_mqtt from '@awsless/mqtt';
|
|
2
|
+
import { QoS } from '@awsless/mqtt';
|
|
3
|
+
|
|
1
4
|
interface AuthResources {
|
|
2
5
|
}
|
|
3
6
|
declare const Auth: AuthResources;
|
|
@@ -51,4 +54,19 @@ declare const createHttpClient: <S extends Schema>(fetcher: HttpFetcher) => {
|
|
|
51
54
|
post<P_1 extends keyof S["POST"]>(routeKey: Extract<P_1, string>, props?: Props<GetRoute<S, "POST", P_1>>): Promise<GetRoute<S, "POST", P_1>["response"]>;
|
|
52
55
|
};
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
type MessageCallback = (payload: any) => void;
|
|
58
|
+
type ClientProps = {
|
|
59
|
+
endpoint: string;
|
|
60
|
+
authorizer: string;
|
|
61
|
+
token: string;
|
|
62
|
+
};
|
|
63
|
+
type ClientPropsProvider = () => Promise<ClientProps> | ClientProps;
|
|
64
|
+
declare const createPubSubClient: (props: ClientProps | ClientPropsProvider) => {
|
|
65
|
+
publish(topic: string, event: string, payload: unknown, qos: QoS): Promise<void>;
|
|
66
|
+
subscribe(topic: string, event: string, callback: MessageCallback): Promise<_awsless_mqtt.Unsubscribe>;
|
|
67
|
+
connected: boolean;
|
|
68
|
+
topics: string[];
|
|
69
|
+
destroy(): Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { Auth, type AuthResources, GraphQL, type GraphQLResources, type GraphQLSchema, type HTTP, type HttpFetcher, createHttpClient, createHttpFetcher, createPubSubClient, getAuthProps, getGraphQLProps };
|
package/dist/client.js
CHANGED
|
@@ -77,11 +77,39 @@ var createHttpClient = (fetcher) => {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
};
|
|
80
|
+
|
|
81
|
+
// src/lib/client/pubsub.ts
|
|
82
|
+
import { createClient } from "@awsless/mqtt";
|
|
83
|
+
var createPubSubClient = (props) => {
|
|
84
|
+
const mqtt = createClient(async () => {
|
|
85
|
+
const config = typeof props === "function" ? await props() : props;
|
|
86
|
+
return {
|
|
87
|
+
endpoint: `wss://${config.endpoint}/mqtt`,
|
|
88
|
+
username: `?x-amz-customauthorizer-name=${config.authorizer}`,
|
|
89
|
+
password: config.token
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
...mqtt,
|
|
94
|
+
publish(topic, event, payload, qos) {
|
|
95
|
+
return mqtt.publish(topic, JSON.stringify([event, payload]), qos);
|
|
96
|
+
},
|
|
97
|
+
subscribe(topic, event, callback) {
|
|
98
|
+
return mqtt.subscribe(topic, (message) => {
|
|
99
|
+
const [eventName, payload] = JSON.parse(message.toString("utf8"));
|
|
100
|
+
if (event === eventName) {
|
|
101
|
+
callback(payload);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
80
107
|
export {
|
|
81
108
|
Auth,
|
|
82
109
|
GraphQL,
|
|
83
110
|
createHttpClient,
|
|
84
111
|
createHttpFetcher,
|
|
112
|
+
createPubSubClient,
|
|
85
113
|
getAuthProps,
|
|
86
114
|
getGraphQLProps
|
|
87
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/awsless",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.366",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,15 +29,16 @@
|
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@awsless/iot": "^0.0.2",
|
|
32
|
-
"@awsless/s3": "^0.0.18",
|
|
33
32
|
"@awsless/lambda": "^0.0.26",
|
|
34
|
-
"@awsless/redis": "^0.0.12",
|
|
35
33
|
"@awsless/open-search": "^0.0.15",
|
|
34
|
+
"@awsless/redis": "^0.0.12",
|
|
35
|
+
"@awsless/s3": "^0.0.18",
|
|
36
|
+
"@awsless/validate": "^0.0.15",
|
|
36
37
|
"@awsless/sns": "^0.0.7",
|
|
37
38
|
"@awsless/sqs": "^0.0.7",
|
|
38
39
|
"@awsless/ssm": "^0.0.7",
|
|
39
|
-
"@awsless/
|
|
40
|
-
"@awsless/
|
|
40
|
+
"@awsless/weak-cache": "^0.0.1",
|
|
41
|
+
"@awsless/mqtt": "^0.0.2"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@arcanyx/cidr-slicer": "^0.3.0",
|
|
@@ -111,9 +112,9 @@
|
|
|
111
112
|
"@awsless/duration": "^0.0.1",
|
|
112
113
|
"@awsless/graphql": "^0.0.9",
|
|
113
114
|
"@awsless/size": "^0.0.1",
|
|
114
|
-
"@awsless/ts-file-cache": "^0.0.10",
|
|
115
115
|
"@awsless/validate": "^0.0.15",
|
|
116
|
-
"@awsless/formation": "^0.0.56"
|
|
116
|
+
"@awsless/formation": "^0.0.56",
|
|
117
|
+
"@awsless/ts-file-cache": "^0.0.10"
|
|
117
118
|
},
|
|
118
119
|
"scripts": {
|
|
119
120
|
"test": "pnpm code test",
|