@proj-airi/server-sdk 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-PRESENT Neko Ayaka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const WebSocket = require('crossws/websocket');
4
+ const defu = require('defu');
5
+
6
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
7
+
8
+ const WebSocket__default = /*#__PURE__*/_interopDefaultCompat(WebSocket);
9
+
10
+ class Client {
11
+ websocket;
12
+ constructor(options) {
13
+ const opts = defu.defu(options, { url: "ws://localhost:6121/ws", possibleEvents: [] });
14
+ this.websocket = new WebSocket__default(opts.url);
15
+ this.send({
16
+ type: "module:announce",
17
+ data: {
18
+ name: opts.name,
19
+ possibleEvents: opts.possibleEvents
20
+ }
21
+ });
22
+ }
23
+ send(data) {
24
+ this.websocket.send(JSON.stringify(data));
25
+ }
26
+ sendRaw(data) {
27
+ this.websocket.send(data);
28
+ }
29
+ }
30
+
31
+ exports.Client = Client;
@@ -0,0 +1,16 @@
1
+ import { WebSocketEvents, WebSocketEvent } from '@proj-airi/server-shared/types';
2
+ import { Blob } from 'node:buffer';
3
+
4
+ interface ClientOptions {
5
+ url?: string;
6
+ name: string;
7
+ possibleEvents?: Array<(keyof WebSocketEvents)>;
8
+ }
9
+ declare class Client {
10
+ private websocket;
11
+ constructor(options: ClientOptions);
12
+ send(data: WebSocketEvent): void;
13
+ sendRaw(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
14
+ }
15
+
16
+ export { Client, type ClientOptions };
@@ -0,0 +1,16 @@
1
+ import { WebSocketEvents, WebSocketEvent } from '@proj-airi/server-shared/types';
2
+ import { Blob } from 'node:buffer';
3
+
4
+ interface ClientOptions {
5
+ url?: string;
6
+ name: string;
7
+ possibleEvents?: Array<(keyof WebSocketEvents)>;
8
+ }
9
+ declare class Client {
10
+ private websocket;
11
+ constructor(options: ClientOptions);
12
+ send(data: WebSocketEvent): void;
13
+ sendRaw(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
14
+ }
15
+
16
+ export { Client, type ClientOptions };
@@ -0,0 +1,16 @@
1
+ import { WebSocketEvents, WebSocketEvent } from '@proj-airi/server-shared/types';
2
+ import { Blob } from 'node:buffer';
3
+
4
+ interface ClientOptions {
5
+ url?: string;
6
+ name: string;
7
+ possibleEvents?: Array<(keyof WebSocketEvents)>;
8
+ }
9
+ declare class Client {
10
+ private websocket;
11
+ constructor(options: ClientOptions);
12
+ send(data: WebSocketEvent): void;
13
+ sendRaw(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
14
+ }
15
+
16
+ export { Client, type ClientOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import WebSocket from 'crossws/websocket';
2
+ import { defu } from 'defu';
3
+
4
+ class Client {
5
+ websocket;
6
+ constructor(options) {
7
+ const opts = defu(options, { url: "ws://localhost:6121/ws", possibleEvents: [] });
8
+ this.websocket = new WebSocket(opts.url);
9
+ this.send({
10
+ type: "module:announce",
11
+ data: {
12
+ name: opts.name,
13
+ possibleEvents: opts.possibleEvents
14
+ }
15
+ });
16
+ }
17
+ send(data) {
18
+ this.websocket.send(JSON.stringify(data));
19
+ }
20
+ sendRaw(data) {
21
+ this.websocket.send(data);
22
+ }
23
+ }
24
+
25
+ export { Client };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@proj-airi/server-sdk",
3
+ "type": "module",
4
+ "version": "0.1.2",
5
+ "private": false,
6
+ "description": "Client-side SDK implementation for connecting to Airi server components and runtimes",
7
+ "author": {
8
+ "name": "Neko Ayaka",
9
+ "email": "neko@ayaka.moe",
10
+ "url": "https://github.com/nekomeowww"
11
+ },
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/moeru-ai/airi.git",
16
+ "directory": "packages/server-sdk"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.cjs"
23
+ }
24
+ },
25
+ "main": "./dist/index.cjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "README.md",
30
+ "dist",
31
+ "package.json"
32
+ ],
33
+ "dependencies": {
34
+ "crossws": "^0.3.1",
35
+ "defu": "^6.1.4",
36
+ "@proj-airi/server-shared": "^0.1.2"
37
+ },
38
+ "scripts": {
39
+ "dev": "pnpm run stub",
40
+ "stub": "unbuild --stub",
41
+ "build": "unbuild",
42
+ "package:publish": "pnpm build && pnpm publish --access public --no-git-checks"
43
+ }
44
+ }