You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@based/functions

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@based/functions - npm Package Compare versions

Comparing version

to
3.2.0

145

dist/functions.d.ts

@@ -0,1 +1,3 @@

/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import type { Required } from 'utility-types';

@@ -14,2 +16,3 @@ import { Context, HttpSession } from './context.js';

export type HttpResponse<P = any, K = any> = (based: BasedFunctionClient, payload: P, responseData: K, send: SendHttpResponse, ctx: Context<HttpSession>) => Promise<void>;
export type BasedHttpFunction<P = any> = (based: BasedFunctionClient, payload: P, send: SendHttpResponse, ctx: Context<HttpSession>) => Promise<void>;
export type BasedFunction<P = any, K = any> = (based: BasedFunctionClient, payload: P, ctx: Context) => Promise<K>;

@@ -53,4 +56,56 @@ export type BasedAppFunction = (based: BasedFunctionClient, assets: {

/** In addition to the name, a function can have a custom path for HTTP requests.
* For example: `path: 'my/custom/path'` will result in the function being
* available with a request to `env.based.io/my/custom/path`
*
* For example:
*
* ```ts
* {
* name: 'myFunction',
* path: '/my/custom/path'
* }
* ```
*
* Will result in the function being available with a request to:
* `env.based.io/my/custom/path` or `env.based.io/myFunction/my/custom/path`
*
* ----
* **Query Parameters Matching**
*
* You can also use pattern matching to get parameters from the path.
* If set, the matched parameters will be injected into the payload argument.
*
* ----
* *Rules:*
* - The paths are strict and case-insensitive.
* - The paths matches with or without `/` in the end of the path.
* ----
* `/users` or `/my-page`
* - Static and required path.
* - Static paths are not included in the payload because they're not dynamic.
* ----
* `/users/:userId`
* - Static path and required parameter `userId` with any value.
* - If the parameter `userId` was missing, the path will not match, and your function will not be invoked.
* ----
* `/users/:userId?`
* - Static path and optional parameter `userId` with any value.
* - Returns `''` if the parameter `userId` was missing.
* ----
* `/product/:description*`
* - Static path and optional parameter `description` (0 or many).
* - Returns and Array of strings with all the consecutive values, eg. `/big/book/blue`
* - Returns `[]` if the parameter `description` was missing.
* ----
* `/product/:description+`
* - Static path and required parameter `description` (1 or many).
* - Returns and Array of strings with all the consecutive values, eg. `/big/book/blue`.
* - If the parameter `description` was missing, the path will not match, and your function will not be invoked.
* ----
* **Query String Parameters**
*
* Dont need to be included in the path, they will be merged and included in the payload automatically.
* ----
* **Reserved words**
*
* `token`
* - If you define an parameter named 'token' or use 'token' as query string, the value will not be included in the payload, instead it will be user internally to keep your AuthState updated.
*/

@@ -78,17 +133,18 @@ path?: string;

authorize?: Authorize;
/** Relay allows functions to relay traffic to another `@based/server`
`Currently not supported for `stream`
/** Relay allows functions to relay traffic to another `@based/server`.
*
* Currently not supported for `stream`.
```js
new BasedServer({
clients: { events: BasedClient },
functions: {
specs:
somethingToRelay: {
relay: { client: 'events', target: 'hello' },
type: 'function'
})
}
}
})
new BasedServer({
clients: { events: BasedClient },
functions: {
specs: {
somethingToRelay: {
relay: { client: 'events', target: 'hello' },
type: 'function'
}
}
}
})
```

@@ -105,6 +161,13 @@ */

};
type FunctionConfigSharedComplete = Required<FunctionConfigShared, 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'>;
export type BasedFunctionTypes = 'channel' | 'query' | 'function' | 'stream' | 'app' | 'job';
export type PathToken = {
type: 0 | 1 | 2;
value?: Buffer;
modifier?: 0 | 63 | 43 | 42;
};
type FunctionConfigSharedComplete = Required<FunctionConfigShared, 'maxPayloadSize' | 'rateLimitTokens' | 'version' | 'name'> & {
tokens?: PathToken[];
};
export type BasedFunctionTypes = 'channel' | 'query' | 'function' | 'stream' | 'app' | 'job' | 'http';
type BasedChannelFunctionConfig = {
/** Function type `channel, function, query, stream, authorize` */
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'channel';

@@ -114,9 +177,10 @@ /** Channel subscriber

```js
const subscribe = (based, payload, id, update) => {
let cnt = 0
const interval = setInterval(() => {
update(++cnt)
})
return () => clearInterval(cnt)
}
const subscribe = (based, payload, id, update) => {
let cnt = 0
const interval = setInterval(() => {
update(++cnt)
})
return () => clearInterval(cnt)
}
```

@@ -128,5 +192,5 @@ */

```js
const publisher = (based, payload, msg, id) => {
publishToChannel(id, msg)
}
const publisher = (based, payload, msg, id) => {
publishToChannel(id, msg)
}
```

@@ -145,3 +209,3 @@ */

type BasedCallFunctionConfig = {
/** Function type `channel, function, query, stream` */
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'function';

@@ -151,4 +215,10 @@ fn?: BasedFunction;

};
type BasedHttpFunctionConfig = {
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'http';
path: string;
fn: BasedHttpFunction;
};
type BasedQueryFunctionConfig = {
/** Function type `channel, function, query, stream` */
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'query';

@@ -163,3 +233,3 @@ fn?: BasedQueryFunction;

type BasedStreamFunctionConfig = {
/** Function type `channel, function, query, stream` */
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'stream';

@@ -169,4 +239,6 @@ fn: BasedStreamFunction;

type BasedAppFunctionConfig = {
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'app';
main: string;
/** The path your main file will be served through HTTP */
path?: string;

@@ -177,9 +249,10 @@ favicon?: string;

type BasedJobFunctionConfig = {
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'job';
fn?: BasedFunction;
};
export type BasedFunctionConfig<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig & FunctionConfigShared : T extends 'function' ? BasedCallFunctionConfig & FunctionConfigShared : T extends 'query' ? BasedQueryFunctionConfig & FunctionConfigShared : T extends 'stream' ? BasedStreamFunctionConfig & FunctionConfigShared : T extends 'job' ? BasedJobFunctionConfig & FunctionConfigShared : T extends 'app' ? BasedAppFunctionConfig & FunctionConfigShared : (BasedChannelFunctionConfig & FunctionConfigShared) | (BasedCallFunctionConfig & FunctionConfigShared) | (BasedQueryFunctionConfig & FunctionConfigShared) | (BasedStreamFunctionConfig & FunctionConfigShared) | (BasedJobFunctionConfig & FunctionConfigShared) | (BasedAppFunctionConfig & FunctionConfigShared);
export type BasedFunctionConfigComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig & FunctionConfigSharedComplete : T extends 'function' ? BasedCallFunctionConfig & FunctionConfigSharedComplete : T extends 'query' ? BasedQueryFunctionConfig & FunctionConfigSharedComplete : T extends 'stream' ? BasedStreamFunctionConfig & FunctionConfigSharedComplete : T extends 'job' ? BasedJobFunctionConfig & FunctionConfigSharedComplete : T extends 'app' ? BasedAppFunctionConfig & FunctionConfigSharedComplete : (BasedChannelFunctionConfig & FunctionConfigSharedComplete) | (BasedCallFunctionConfig & FunctionConfigSharedComplete) | (BasedQueryFunctionConfig & FunctionConfigSharedComplete) | (BasedStreamFunctionConfig & FunctionConfigSharedComplete) | (BasedJobFunctionConfig & FunctionConfigSharedComplete) | (BasedAppFunctionConfig & FunctionConfigSharedComplete);
export type BasedFunctionConfig<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig & FunctionConfigShared : T extends 'function' ? BasedCallFunctionConfig & FunctionConfigShared : T extends 'query' ? BasedQueryFunctionConfig & FunctionConfigShared : T extends 'stream' ? BasedStreamFunctionConfig & FunctionConfigShared : T extends 'job' ? BasedJobFunctionConfig & FunctionConfigShared : T extends 'app' ? BasedAppFunctionConfig & FunctionConfigShared : T extends 'http' ? BasedHttpFunctionConfig & FunctionConfigShared : (BasedChannelFunctionConfig & FunctionConfigShared) | (BasedCallFunctionConfig & FunctionConfigShared) | (BasedQueryFunctionConfig & FunctionConfigShared) | (BasedStreamFunctionConfig & FunctionConfigShared) | (BasedJobFunctionConfig & FunctionConfigShared) | (BasedAppFunctionConfig & FunctionConfigShared) | (BasedHttpFunctionConfig & FunctionConfigShared);
export type BasedFunctionConfigComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = T extends 'channel' ? BasedChannelFunctionConfig & FunctionConfigSharedComplete : T extends 'function' ? BasedCallFunctionConfig & FunctionConfigSharedComplete : T extends 'query' ? BasedQueryFunctionConfig & FunctionConfigSharedComplete : T extends 'stream' ? BasedStreamFunctionConfig & FunctionConfigSharedComplete : T extends 'job' ? BasedJobFunctionConfig & FunctionConfigSharedComplete : T extends 'app' ? BasedAppFunctionConfig & FunctionConfigSharedComplete : T extends 'http' ? BasedHttpFunctionConfig & FunctionConfigSharedComplete : (BasedChannelFunctionConfig & FunctionConfigSharedComplete) | (BasedCallFunctionConfig & FunctionConfigSharedComplete) | (BasedQueryFunctionConfig & FunctionConfigSharedComplete) | (BasedStreamFunctionConfig & FunctionConfigSharedComplete) | (BasedJobFunctionConfig & FunctionConfigSharedComplete) | (BasedAppFunctionConfig & FunctionConfigSharedComplete) | (BasedHttpFunctionConfig & FunctionConfigSharedComplete);
export type BasedAuthorizeFunctionConfig = {
/** Function type `authorize` */
/** Function type `app, http, channel, function, query, stream, authorize, job` */
type: 'authorize';

@@ -189,3 +262,5 @@ fn?: Authorize;

export type BasedRoute<T extends BasedFunctionTypes = BasedFunctionTypes, R extends keyof BasedFunctionConfig = 'type' | 'name'> = Required<Partial<BasedFunctionConfig<T>>, R>;
export type BasedRouteComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = Required<Partial<BasedFunctionConfig<T>>, 'type' | 'name' | 'maxPayloadSize' | 'rateLimitTokens'>;
export type BasedRouteComplete<T extends BasedFunctionTypes = BasedFunctionTypes> = Required<Partial<BasedFunctionConfig<T>>, 'type' | 'name' | 'maxPayloadSize' | 'rateLimitTokens'> & {
tokens?: PathToken[];
};
export declare function isBasedRoute<T extends BasedFunctionTypes>(type: T, route: any): route is BasedRoute<T>;

@@ -192,0 +267,0 @@ export declare function isAnyBasedRoute(route: any): route is BasedRoute;

@@ -13,2 +13,3 @@ export function isBasedRoute(type, route) {

route.type === 'function' ||
route.type === 'http' ||
route.type === 'stream') &&

@@ -15,0 +16,0 @@ typeof route.name === 'string');

@@ -0,1 +1,6 @@

/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import { Duplex, Readable } from "node:stream";

@@ -2,0 +7,0 @@ import util from "node:util";

{
"name": "@based/functions",
"version": "3.1.2",
"version": "3.2.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "type": "module",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet