montycat 1.1.3 → 1.1.4
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/classes/generic.js +2 -9
- package/dist/core/inmemory.js +2 -2
- package/dist/core/persistent.d.ts +39 -11
- package/dist/core/persistent.js +41 -13
- package/package.json +1 -1
package/dist/classes/generic.js
CHANGED
|
@@ -132,19 +132,15 @@ class GenericKV {
|
|
|
132
132
|
* @returns A promise that resolves with the retrieved keys.
|
|
133
133
|
*/
|
|
134
134
|
static async getBulk({ bulkKeys = [], bulkCustomKeys = [], limitOutput = { start: 0, stop: 0 }, withPointers = false, keyIncluded = false, pointersMetadata = false, volumes = [], latestVolume = false } = {}) {
|
|
135
|
-
if (pointersMetadata && withPointers) {
|
|
136
|
-
throw new Error("You select both pointers value and pointers metadata. Choose one");
|
|
137
|
-
}
|
|
138
135
|
try {
|
|
139
136
|
if (bulkCustomKeys.length)
|
|
140
137
|
bulkKeys = bulkKeys.concat(convertCustomKeys(bulkCustomKeys));
|
|
141
138
|
const selectedOptions = [
|
|
142
139
|
bulkKeys.length > 0,
|
|
143
|
-
volumes.length > 0,
|
|
144
|
-
latestVolume
|
|
140
|
+
volumes.length > 0 || latestVolume || (limitOutput.start !== 0 || limitOutput.stop !== 0),
|
|
145
141
|
].filter(Boolean).length;
|
|
146
142
|
if (selectedOptions !== 1) {
|
|
147
|
-
throw new Error("
|
|
143
|
+
throw new Error("Please provide keys or volumes/latest volume or limit.");
|
|
148
144
|
}
|
|
149
145
|
this.command = "get_bulk";
|
|
150
146
|
const query = convertToBinaryQuery(this, { bulkKeys, limitOutput, withPointers, keyIncluded, pointersMetadata, volumes, latestVolume });
|
|
@@ -204,9 +200,6 @@ class GenericKV {
|
|
|
204
200
|
* @return A promise that resolves with the result of the lookup.
|
|
205
201
|
*/
|
|
206
202
|
static async lookupValuesWhere({ searchCriteria = {}, limitOutput = { start: 0, stop: 0 }, withPointers = false, schema = null, keyIncluded = false, pointersMetadata = false } = {}) {
|
|
207
|
-
if (pointersMetadata && withPointers) {
|
|
208
|
-
throw new Error("You select both pointers value and pointers metadata. Choose one");
|
|
209
|
-
}
|
|
210
203
|
try {
|
|
211
204
|
this.command = "lookup_values";
|
|
212
205
|
const query = convertToBinaryQuery(this, { searchCriteria, limitOutput, withPointers, schema, keyIncluded, pointersMetadata });
|
package/dist/core/inmemory.js
CHANGED
|
@@ -151,8 +151,8 @@ class InMemory extends GenericKV {
|
|
|
151
151
|
* @returns A promise that resolves with the retrieved keys.
|
|
152
152
|
*/
|
|
153
153
|
static async getKeys({ volumes = [], latestVolume = false } = {}) {
|
|
154
|
-
if (
|
|
155
|
-
throw new Error("
|
|
154
|
+
if ((!volumes || volumes.length === 0) && !latestVolume) {
|
|
155
|
+
throw new Error("Please provide volumes/latest volume.");
|
|
156
156
|
}
|
|
157
157
|
this.command = "get_keys";
|
|
158
158
|
const query = convertToBinaryQuery(this, { volumes, latestVolume });
|
|
@@ -15,6 +15,35 @@ declare class Persistent extends GenericKV {
|
|
|
15
15
|
password: string;
|
|
16
16
|
[key: string]: any;
|
|
17
17
|
});
|
|
18
|
+
/**
|
|
19
|
+
* Subscribes to changes in the persistent store based on the provided options.
|
|
20
|
+
* @param callback - A callback function to handle incoming data.
|
|
21
|
+
* @param key - A specific key to subscribe to.
|
|
22
|
+
* @param customKey - A custom key to subscribe to.
|
|
23
|
+
* @return A promise that resolves with the result of the subscription.
|
|
24
|
+
* Note: Subscriptions are only allowed on non-persistent keyspaces, so this method will throw an error if called on a persistent keyspace.
|
|
25
|
+
* The effective key for the subscription is determined by the presence of a custom key or a regular key, with the custom key taking precedence if both are provided.
|
|
26
|
+
* The subscription query is constructed with the appropriate parameters and sent to the server using the runQuery function, with the callback function passed to handle incoming data.
|
|
27
|
+
* If the subscription is successful, the promise will resolve with the result of the subscription; otherwise, it will reject with an error.
|
|
28
|
+
* Error handling is implemented to ensure that subscriptions are not allowed on persistent keyspaces, and that a key is provided for the subscription.
|
|
29
|
+
* The method is designed to facilitate real-time updates and notifications for changes in the keyspace, allowing clients to react to data changes as they occur.
|
|
30
|
+
* Overall, this method provides a mechanism for clients to stay informed about changes in the persistent store, while enforcing the constraints of the keyspace type and ensuring that necessary parameters are provided for the subscription.
|
|
31
|
+
* @throws Will throw an error if subscriptions are attempted on a persistent keyspace or if no key is provided for the subscription.
|
|
32
|
+
* @example
|
|
33
|
+
* Persistent.subscribe({
|
|
34
|
+
* callback: (data) => {
|
|
35
|
+
* console.log("Received data:", data);
|
|
36
|
+
* },
|
|
37
|
+
* key: "myKey"
|
|
38
|
+
* });
|
|
39
|
+
* @example
|
|
40
|
+
* Persistent.subscribe({
|
|
41
|
+
* callback: (data) => {
|
|
42
|
+
* console.log("Received data for custom key:", data);
|
|
43
|
+
* },
|
|
44
|
+
* customKey: "myCustomKey"
|
|
45
|
+
* });
|
|
46
|
+
*/
|
|
18
47
|
static subscribe({ callback, key, customKey }: {
|
|
19
48
|
callback?: (data: any) => void;
|
|
20
49
|
key?: string;
|
|
@@ -29,9 +58,8 @@ declare class Persistent extends GenericKV {
|
|
|
29
58
|
value?: any;
|
|
30
59
|
}): Promise<any>;
|
|
31
60
|
/**
|
|
32
|
-
* Inserts a key
|
|
33
|
-
* @param
|
|
34
|
-
* @param value - The value to insert.
|
|
61
|
+
* Inserts a custom key into the persistent store.
|
|
62
|
+
* @param customKey - The custom key to insert.
|
|
35
63
|
* @return A promise that resolves with the result of the insertion.
|
|
36
64
|
*/
|
|
37
65
|
static insertCustomKey({ customKey }: {
|
|
@@ -60,19 +88,19 @@ declare class Persistent extends GenericKV {
|
|
|
60
88
|
value?: any;
|
|
61
89
|
}): Promise<any>;
|
|
62
90
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param
|
|
65
|
-
* @
|
|
66
|
-
* @return A promise that resolves with the retrieved value.
|
|
91
|
+
* Inserts multiple key-value pairs into the persistent store in bulk.
|
|
92
|
+
* @param bulk - An array of key-value pairs to insert.
|
|
93
|
+
* @return A promise that resolves with the result of the bulk insertion.
|
|
67
94
|
*/
|
|
68
95
|
static insertBulk({ bulk }?: {
|
|
69
96
|
bulk?: any[];
|
|
70
97
|
}): Promise<any>;
|
|
71
98
|
/**
|
|
72
|
-
* Retrieves
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
75
|
-
* @
|
|
99
|
+
* Retrieves keys from the persistent store based on provided options.
|
|
100
|
+
* @param limitOutput - An object specifying the start and stop limits for output.
|
|
101
|
+
* @param latestVolume - A boolean indicating whether to retrieve keys from the latest volume.
|
|
102
|
+
* @param volumes - An array of volume names to retrieve keys from.
|
|
103
|
+
* @returns A promise that resolves with the retrieved keys.
|
|
76
104
|
*/
|
|
77
105
|
static getKeys({ limitOutput, latestVolume, volumes }?: {
|
|
78
106
|
limitOutput?: {
|
package/dist/core/persistent.js
CHANGED
|
@@ -14,6 +14,35 @@ class Persistent extends GenericKV {
|
|
|
14
14
|
super(options);
|
|
15
15
|
this.keyspace = options.keyspace;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Subscribes to changes in the persistent store based on the provided options.
|
|
19
|
+
* @param callback - A callback function to handle incoming data.
|
|
20
|
+
* @param key - A specific key to subscribe to.
|
|
21
|
+
* @param customKey - A custom key to subscribe to.
|
|
22
|
+
* @return A promise that resolves with the result of the subscription.
|
|
23
|
+
* Note: Subscriptions are only allowed on non-persistent keyspaces, so this method will throw an error if called on a persistent keyspace.
|
|
24
|
+
* The effective key for the subscription is determined by the presence of a custom key or a regular key, with the custom key taking precedence if both are provided.
|
|
25
|
+
* The subscription query is constructed with the appropriate parameters and sent to the server using the runQuery function, with the callback function passed to handle incoming data.
|
|
26
|
+
* If the subscription is successful, the promise will resolve with the result of the subscription; otherwise, it will reject with an error.
|
|
27
|
+
* Error handling is implemented to ensure that subscriptions are not allowed on persistent keyspaces, and that a key is provided for the subscription.
|
|
28
|
+
* The method is designed to facilitate real-time updates and notifications for changes in the keyspace, allowing clients to react to data changes as they occur.
|
|
29
|
+
* Overall, this method provides a mechanism for clients to stay informed about changes in the persistent store, while enforcing the constraints of the keyspace type and ensuring that necessary parameters are provided for the subscription.
|
|
30
|
+
* @throws Will throw an error if subscriptions are attempted on a persistent keyspace or if no key is provided for the subscription.
|
|
31
|
+
* @example
|
|
32
|
+
* Persistent.subscribe({
|
|
33
|
+
* callback: (data) => {
|
|
34
|
+
* console.log("Received data:", data);
|
|
35
|
+
* },
|
|
36
|
+
* key: "myKey"
|
|
37
|
+
* });
|
|
38
|
+
* @example
|
|
39
|
+
* Persistent.subscribe({
|
|
40
|
+
* callback: (data) => {
|
|
41
|
+
* console.log("Received data for custom key:", data);
|
|
42
|
+
* },
|
|
43
|
+
* customKey: "myCustomKey"
|
|
44
|
+
* });
|
|
45
|
+
*/
|
|
17
46
|
static async subscribe({ callback, key, customKey }) {
|
|
18
47
|
const effectiveKey = customKey ? convertCustomKey(customKey) : (key || null);
|
|
19
48
|
const queryObj = {
|
|
@@ -38,9 +67,8 @@ class Persistent extends GenericKV {
|
|
|
38
67
|
return runQuery(this, query);
|
|
39
68
|
}
|
|
40
69
|
/**
|
|
41
|
-
* Inserts a key
|
|
42
|
-
* @param
|
|
43
|
-
* @param value - The value to insert.
|
|
70
|
+
* Inserts a custom key into the persistent store.
|
|
71
|
+
* @param customKey - The custom key to insert.
|
|
44
72
|
* @return A promise that resolves with the result of the insertion.
|
|
45
73
|
*/
|
|
46
74
|
static async insertCustomKey({ customKey }) {
|
|
@@ -82,10 +110,9 @@ class Persistent extends GenericKV {
|
|
|
82
110
|
return runQuery(this, query);
|
|
83
111
|
}
|
|
84
112
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @param
|
|
87
|
-
* @
|
|
88
|
-
* @return A promise that resolves with the retrieved value.
|
|
113
|
+
* Inserts multiple key-value pairs into the persistent store in bulk.
|
|
114
|
+
* @param bulk - An array of key-value pairs to insert.
|
|
115
|
+
* @return A promise that resolves with the result of the bulk insertion.
|
|
89
116
|
*/
|
|
90
117
|
static async insertBulk({ bulk = [] } = {}) {
|
|
91
118
|
if (!bulk || bulk.length === 0) {
|
|
@@ -96,14 +123,15 @@ class Persistent extends GenericKV {
|
|
|
96
123
|
return runQuery(this, query);
|
|
97
124
|
}
|
|
98
125
|
/**
|
|
99
|
-
* Retrieves
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
102
|
-
* @
|
|
126
|
+
* Retrieves keys from the persistent store based on provided options.
|
|
127
|
+
* @param limitOutput - An object specifying the start and stop limits for output.
|
|
128
|
+
* @param latestVolume - A boolean indicating whether to retrieve keys from the latest volume.
|
|
129
|
+
* @param volumes - An array of volume names to retrieve keys from.
|
|
130
|
+
* @returns A promise that resolves with the retrieved keys.
|
|
103
131
|
*/
|
|
104
132
|
static async getKeys({ limitOutput = { start: 0, stop: 0 }, latestVolume = false, volumes = [] } = {}) {
|
|
105
|
-
if (
|
|
106
|
-
throw new Error("
|
|
133
|
+
if ((!volumes || volumes.length === 0) && !latestVolume && (!limitOutput || (limitOutput.start === 0 && limitOutput.stop === 0))) {
|
|
134
|
+
throw new Error("Please provide volumes/latest volume or limit.");
|
|
107
135
|
}
|
|
108
136
|
this.command = "get_keys";
|
|
109
137
|
const query = convertToBinaryQuery(this, { limitOutput, latestVolume, volumes });
|