tool-db 2.5.4 → 2.5.6

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.
@@ -1,4 +1,9 @@
1
- import { Peer } from "..";
1
+ import {
2
+ AllowedFunctionArguments,
3
+ AllowedFunctionReturn,
4
+ FunctionCodes,
5
+ Peer,
6
+ } from "..";
2
7
 
3
8
  export enum VerifyResult {
4
9
  CustomVerificationFailed = "CustomVerificationFailed",
@@ -53,6 +58,8 @@ export type MessageType =
53
58
  | "pong"
54
59
  | "query"
55
60
  | "queryAck"
61
+ | "function"
62
+ | "functionReturn"
56
63
  | "subscribe"
57
64
  | "get"
58
65
  | "put"
@@ -96,6 +103,18 @@ export interface QueryAckMessage extends BaseMessage {
96
103
  keys: string[];
97
104
  }
98
105
 
106
+ export interface FunctionMessage extends BaseMessage {
107
+ type: "function";
108
+ function: string;
109
+ args: AllowedFunctionArguments<any>;
110
+ }
111
+
112
+ export interface FunctionReturnMessage extends BaseMessage {
113
+ type: "functionReturn";
114
+ code: FunctionCodes;
115
+ return: AllowedFunctionReturn<any>;
116
+ }
117
+
99
118
  export interface SubscribeMessage extends BaseMessage {
100
119
  type: "subscribe";
101
120
  key: string;
@@ -126,6 +145,8 @@ export type ToolDbMessage =
126
145
  | PongMessage
127
146
  | QueryMessage
128
147
  | QueryAckMessage
148
+ | FunctionMessage
149
+ | FunctionReturnMessage
129
150
  | SubscribeMessage
130
151
  | GetMessage
131
152
  | PutMessage
@@ -93,5 +93,47 @@ export interface ToolDbOptions {
93
93
  * The name of the server (works like a domain)
94
94
  */
95
95
  serverName: string | undefined;
96
- // [extra: string]: any;
96
+ /*
97
+ * Used only for modules extra options
98
+ * Ideally should be uesd as an internal key within
99
+ * like "db.options.hybrid.url" to avoid conflicts between modules using the same keys
100
+ */
101
+ modules: {
102
+ [module: string]: any;
103
+ };
97
104
  }
105
+
106
+ export type GenericObject = { [key: string]: any };
107
+
108
+ export type AllowedFunctionArguments<A = GenericObject> = A;
109
+
110
+ export type AllowedFunctionReturn<R = unknown> = R;
111
+
112
+ export type FunctionCodes = "OK" | "ERR" | "NOT_FOUND";
113
+
114
+ export type ServerFunction<R, A = GenericObject> = (
115
+ args: AllowedFunctionArguments<A>
116
+ ) => Promise<AllowedFunctionReturn<R>>;
117
+
118
+ export interface FunctionReturnBase {
119
+ code: FunctionCodes;
120
+ }
121
+ export interface FunctionReturnOk<R> extends FunctionReturnBase {
122
+ return: AllowedFunctionReturn<R>;
123
+ code: "OK";
124
+ }
125
+
126
+ export interface FunctionReturnErr extends FunctionReturnBase {
127
+ return: string;
128
+ code: "ERR";
129
+ }
130
+
131
+ export interface FunctionReturnNotFound extends FunctionReturnBase {
132
+ return: string;
133
+ code: "NOT_FOUND";
134
+ }
135
+
136
+ export type FunctionReturn<R> =
137
+ | FunctionReturnOk<R>
138
+ | FunctionReturnErr
139
+ | FunctionReturnNotFound;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tool-db",
3
- "version": "2.5.4",
3
+ "version": "2.5.6",
4
4
  "description": "A decentralized database model for federated p2p networks.n",
5
5
  "author": "Manwe <manuel.etchegaray7@gmail.com>",
6
6
  "homepage": "https://github.com/Manwe-777/tool-db#readme",
@@ -28,5 +28,5 @@
28
28
  "typescript": "^4.7.4",
29
29
  "uglify-js": "^3.16.2"
30
30
  },
31
- "gitHead": "9497db7d2c5e79edc056f0bb1f2fcf21264b7654"
31
+ "gitHead": "ca8b876dcf1e78ad92d9369961d7479e07df0954"
32
32
  }