Socket
Socket
Sign inDemoInstall

@alipay/faas-biz-server-sdk

Package Overview
Dependencies
Maintainers
0
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alipay/faas-biz-server-sdk - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4-alpha.0

11

dist/websocket/base/BaseDO.d.ts

@@ -7,2 +7,13 @@ import Chain from './Chain';

get id(): string;
/**
* save data to storage
* 持久化数据
* @example await instance.save();
* @return
*/
save(): Promise<void>;
/**
* get property
*/
get properties(): Promise<Record<string, any>>;
}

@@ -15,3 +15,25 @@ "use strict";

}
/**
* save data to storage
* 持久化数据
* @example await instance.save();
* @return
*/
async save() {
await this.dto?.save();
}
/**
* get property
*/
get properties() {
this.later(async () => {
await this.dto?.get();
if ('properties' in this.dto && typeof this.dto.properties === 'object') {
return this.dto?.properties;
}
});
// end of the chain
return this;
}
}
exports.default = BaseDO;

3

dist/websocket/base/Chain.d.ts
export default class Chain {
private laters;
private _laters;
protected afterChain(): Promise<void>;

@@ -21,2 +21,3 @@ /**

toString(): string;
protected get laters(): ((t: any) => any)[];
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Chain {
laters = [];
_laters = [];
async afterChain() {
this.laters = [];
this._laters = [];
}

@@ -14,3 +14,3 @@ /**

later(resolve) {
this.laters.push(resolve);
this._laters.push(resolve);
return this;

@@ -23,8 +23,8 @@ }

async ignite() {
const { laters } = this;
const { _laters } = this;
let result = null;
for (const later of laters) {
for (const later of _laters) {
result = await later(result);
}
this.laters = [];
this._laters = [];
await this.afterChain();

@@ -57,3 +57,6 @@ return result;

}
get laters() {
return this._laters;
}
}
exports.default = Chain;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.splitArray = exports.isEmptyObject = exports.pAll = exports.deserializeProperties = exports.serializeProperties = exports.serializeSet = exports.deserializeProperty = exports.serializeMap = void 0;
exports.serializeMap = serializeMap;
exports.deserializeProperty = deserializeProperty;
exports.serializeSet = serializeSet;
exports.serializeProperties = serializeProperties;
exports.deserializeProperties = deserializeProperties;
exports.pAll = pAll;
exports.isEmptyObject = isEmptyObject;
exports.splitArray = splitArray;
function serializeMap(map) {

@@ -9,3 +16,2 @@ const res = Object.fromEntries(map);

}
exports.serializeMap = serializeMap;
function deserializeProperty(map) {

@@ -22,3 +28,2 @@ if (map.__faas_ws_type__ === 'Map') {

}
exports.deserializeProperty = deserializeProperty;
function serializeSet(set) {

@@ -31,3 +36,2 @@ const res = {

}
exports.serializeSet = serializeSet;
function serializeProperties(property) {

@@ -50,3 +54,2 @@ const data = {

}
exports.serializeProperties = serializeProperties;
function deserializeProperties(property) {

@@ -61,3 +64,2 @@ const data = {

}
exports.deserializeProperties = deserializeProperties;
function pAll(tasks, concurrency = Infinity) {

@@ -95,7 +97,5 @@ return new Promise((resolve, reject) => {

}
exports.pAll = pAll;
function isEmptyObject(obj) {
return !obj || Object.keys(obj).length === 0;
}
exports.isEmptyObject = isEmptyObject;
function splitArray(arr, size) {

@@ -108,2 +108,1 @@ const res = [];

}
exports.splitArray = splitArray;

@@ -24,2 +24,3 @@ "use strict";

ws;
// private options: FaasWebSocketIOConfig;
Websocket = Socket_1.default;

@@ -33,2 +34,3 @@ constructor(options) {

this.currentConnectionId = options.currentConnectionId;
// this.options = options;
}

@@ -35,0 +37,0 @@ /**

@@ -18,3 +18,11 @@ import WSBaseStorage from '../storage/BaseStorage';

private fetched;
/**
* @type { Record<string, any> }
* @description 自定义属性
* @example { "key": "value" }
*/
properties: Record<string, any>;
constructor(id: string, namespace?: string);
setProperty(...args: Array<string | any>): Promise<void>;
getProperty(key: string | string[]): Promise<any>;
/**

@@ -21,0 +29,0 @@ * Fetch the data from the storage

@@ -10,2 +10,8 @@ "use strict";

fetched = false;
/**
* @type { Record<string, any> }
* @description 自定义属性
* @example { "key": "value" }
*/
properties = {};
constructor(id, namespace) {

@@ -18,2 +24,27 @@ this.id = id;

}
async setProperty(...args) {
if (!args || !args.length)
return;
await this.get();
// set property
for (let i = 0; i < args.length; i += 2) {
const nextKey = args[i];
const nextValue = args[i + 1];
this.properties[nextKey] = nextValue;
}
await this.update({
properties: this.properties,
});
}
async getProperty(key) {
await this.get();
if (Array.isArray(key)) {
return key.reduce((acc, k) => {
acc[k] = this.properties[k];
return acc;
}, {});
}
// get property
return this.properties[key];
}
/**

@@ -20,0 +51,0 @@ * Fetch the data from the storage

@@ -12,10 +12,2 @@ import WsSet from '../base/WsSet';

socketIds: string[];
/**
* @type { Record<string, any> }
* @description 房间属性
* @example { "key": "value" }
*/
properties: Record<string, any>;
setProperty(key: string, value: any): Promise<void>;
getProperty(key: string): Promise<any>;
update(data: {

@@ -22,0 +14,0 @@ sockets?: Array<Socket | string>;

@@ -20,21 +20,2 @@ "use strict";

socketIds = [];
/**
* @type { Record<string, any> }
* @description 房间属性
* @example { "key": "value" }
*/
properties = {};
async setProperty(key, value) {
await this.get();
// set property
this.properties[key] = value;
await this.update({
properties: this.properties,
});
}
async getProperty(key) {
await this.get();
// get property
return this.properties[key];
}
async update(data) {

@@ -41,0 +22,0 @@ if (!data || (!data.properties && (!data.sockets || !Array.isArray(data.sockets)))) {

@@ -5,3 +5,2 @@ import Base from './Base';

export default class Socket extends Base {
properties: Record<string, any>;
roomIds: string[];

@@ -11,4 +10,2 @@ static table: string;

toJSON(): Record<string, any>;
setProperty(key: string, value: any): Promise<void>;
getProperty(key: string): Promise<any>;
update(data: {

@@ -15,0 +12,0 @@ properties?: Record<string, any>;

@@ -13,3 +13,2 @@ "use strict";

class Socket extends Base_1.default {
properties = {};
roomIds = [];

@@ -29,15 +28,2 @@ static table = 'socket';

}
async setProperty(key, value) {
await this.get();
// set property
this.properties[key] = value;
await this.update({
properties: this.properties,
});
}
async getProperty(key) {
await this.get();
// get property
return this.properties[key];
}
async update(data) {

@@ -44,0 +30,0 @@ if (!data || (!data.properties && (!data.rooms || !Array.isArray(data.rooms)))) {

@@ -28,2 +28,3 @@ import Socket from './models/Socket';

* @example await room.setProperty('key', 'value');
* @example await room.setProperty('key1', 'value', 'key2', ['key', 'value']); // set multiple properties
* @param key

@@ -33,3 +34,3 @@ * @param value

*/
setProperty(key: string, value: any): this;
setProperty(...args: Array<string | any>): this;
private _getProperty;

@@ -75,3 +76,3 @@ /**

*/
sockets(): this;
get sockets(): this;
/**

@@ -83,3 +84,3 @@ * get sockets in the room

*/
members(): this;
get members(): this;
/**

@@ -86,0 +87,0 @@ * broadcast data to all sockets in the room

@@ -23,4 +23,4 @@ "use strict";

}
async _setProperty(key, value) {
await this.dto.setProperty(key, value);
async _setProperty(...args) {
await this.dto.setProperty(...args);
}

@@ -41,2 +41,3 @@ /**

* @example await room.setProperty('key', 'value');
* @example await room.setProperty('key1', 'value', 'key2', ['key', 'value']); // set multiple properties
* @param key

@@ -46,5 +47,5 @@ * @param value

*/
setProperty(key, value) {
setProperty(...args) {
this.later(async () => {
return await this._setProperty(key, value);
return await this._setProperty(...args);
});

@@ -124,3 +125,3 @@ return this;

*/
sockets() {
get sockets() {
this.later(async () => {

@@ -137,3 +138,3 @@ return await this.getSockets();

*/
members() {
get members() {
this.later(async () => {

@@ -140,0 +141,0 @@ return await this.getSockets();

@@ -32,3 +32,3 @@ import type WS from '@alipay/faas-server-sdk/lib/Websocket';

*/
setProperty(key: string, value: any): this;
setProperty(...args: Array<string | any>): this;
private _getProperty;

@@ -67,3 +67,3 @@ /**

*/
rooms(): this;
get rooms(): this;
/**

@@ -70,0 +70,0 @@ * emit event

@@ -32,4 +32,4 @@ "use strict";

}
async _setProperty(key, value) {
await this.dto.setProperty(key, value);
async _setProperty(...args) {
await this.dto.setProperty(...args);
}

@@ -44,5 +44,5 @@ /**

*/
setProperty(key, value) {
setProperty(...args) {
this.later(async () => {
return await this._setProperty(key, value);
return await this._setProperty(...args);
});

@@ -114,3 +114,3 @@ return this;

*/
rooms() {
get rooms() {
this.later(async () => {

@@ -117,0 +117,0 @@ return await this.dto.rooms();

{
"name": "@alipay/faas-biz-server-sdk",
"version": "1.1.3",
"version": "1.1.4-alpha.0",
"description": "支付宝云开发业务 SDK(函数端)",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -296,4 +296,4 @@

status?: CloseStatus,
// 是否不忽略连接存活状态,如果为 true,则会检查连接是否存活,如果存活则正常关闭连接
// 如果为 false 或者不设值,则检查连接是否存活,如果不存活,则会抛出错误, 且中断关闭操作
// 如果为 true,则检查连接是否存活,如果不存活,则会抛出错误, 且中断关闭操作
// 如果为 false 或者不设值,则会检查连接是否存活,如果存活则正常关闭连接,否则删除数据库中的连接信息
strict?: boolean

@@ -343,2 +343,4 @@ }): Promise<void>

// 设置单个值
await socket.setProperty('key', 'value');

@@ -356,2 +358,5 @@

// 设置多个值
await socket.setProperty('key', 'value', 'key1', 'value1', 'key2', new Map([['key', 'value']]));
```

@@ -365,6 +370,17 @@

await socket.getProperty('key');
await socket.getProperty('key'); // 返回 'value'
await socket.getProperty(['key', 'key1']); // 返回 { key: 'value', key1: 'value1' }
```
#### properties
获取 socket 所有属性
```javascript
await socket.properties;
```
#### isAlive

@@ -381,2 +397,89 @@

### Room API
#### 设置 room 属性
```javascript
// 设置单个值
await room.setProperty('key', 'value');
await room.setProperty('key1', ['value1', 'value2']);
await room.setProperty('key2', { key: 'value' });
await room.setProperty('key3', 1);
await room.setProperty('key4', new Map([['key', 'value']]));
await room.setProperty('key5', new Set(['value']));
// 设置多个值
await room.setProperty('key', 'value', 'key1', 'value1', 'key2', new Map([['key', 'value']]));
```
#### 获取 room 属性
```javascript
await room.getProperty('key'); // 返回 'value'
await room.getProperty(['key', 'key1']); // 返回 { key: 'value', key1: 'value1' }
```
#### properties
获取 room 所有属性
```javascript
await room.properties;
```
#### sockets
获取 room 所有连接
```javascript
await room.sockets;
```
#### members
获取 room 所有连接
```javascript
await room.members;
```
#### socketsIsAlive
获取 room 所有连接的存活状态
```javascript
await room.socketsIsAlive();
```
#### join
向 room 中加入连接
```javascript
await room.join(socket); // socket 为 FaasWebSocketIO.Websocket 实例
```
#### leave
从 room 中移除连接
```javascript
await room.leave(socket); // socket 为 FaasWebSocketIO.Websocket 实例
```
#### broadcast
向 room 中的所有连接广播消息
```javascript
await room.broadcast('data');
```
## 示例

@@ -383,0 +486,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc