@lowdefy/connection-redis 4.0.0-alpha.29 → 4.0.0-alpha.30

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.
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import { createClient } from 'redis';
17
+ import schema from './schema.js';
18
+ async function Redis({ request , connection }) {
19
+ const connectionObject = type.isString(connection.connection) ? {
20
+ url: connection.connection
21
+ } : connection.connection;
22
+ const client = new createClient(connectionObject);
23
+ client.on('error', (error)=>{
24
+ throw error;
25
+ });
26
+ const { command , parameters , modifiers } = request;
27
+ await client.connect();
28
+ if (!type.isFunction(client[command.toUpperCase()])) {
29
+ throw new Error(`Invalid redis command "${command}".`);
30
+ }
31
+ if (!type.isArray(parameters)) {
32
+ throw new Error(`Invalid parameters, command "${command}" parameters should be an array, received ${JSON.stringify(parameters)}.`);
33
+ }
34
+ const upperCaseModifiers = Object.entries(modifiers).reduce((acc, [key, value])=>{
35
+ acc[key.toUpperCase()] = value;
36
+ return acc;
37
+ }, {});
38
+ try {
39
+ const commandReturn = await client[command.toUpperCase()](...parameters, upperCaseModifiers);
40
+ await client.quit();
41
+ return commandReturn;
42
+ } catch (error) {
43
+ client.quit();
44
+ throw error;
45
+ }
46
+ }
47
+ Redis.schema = schema;
48
+ Redis.meta = {
49
+ checkRead: false,
50
+ checkWrite: false
51
+ };
52
+ export default Redis;
@@ -0,0 +1,49 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ $schema: 'http://json-schema.org/draft-07/schema#',
17
+ title: 'Lowdefy Request Schema - Redis',
18
+ type: 'object',
19
+ properties: {
20
+ command: {
21
+ type: 'string',
22
+ description: 'Redis command to execute.',
23
+ errorMessage: {
24
+ type: 'Redis request property "command" should be a string.'
25
+ }
26
+ },
27
+ parameters: {
28
+ type: 'array',
29
+ description: 'The parameters to use with the command.',
30
+ errorMessage: {
31
+ type: 'Redis request property "parameters" should be an array.'
32
+ }
33
+ },
34
+ modifiers: {
35
+ type: 'object',
36
+ description: 'The modifiers to use with the command.',
37
+ default: {},
38
+ errorMessage: {
39
+ type: 'Redis request property "modifiers" should be an object.'
40
+ }
41
+ }
42
+ },
43
+ required: [
44
+ 'command'
45
+ ],
46
+ errorMessage: {
47
+ type: 'Redis request properties should be an object.'
48
+ }
49
+ };
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import Redis from './Redis/Redis.js';
16
+ import schema from './schema.js';
17
+ export default {
18
+ schema,
19
+ requests: {
20
+ Redis
21
+ }
22
+ };
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ $schema: 'http://json-schema.org/draft-07/schema#',
17
+ title: 'Lowdefy Connection Schema - Redis',
18
+ type: 'object',
19
+ properties: {
20
+ connection: {
21
+ type: [
22
+ 'string',
23
+ 'object'
24
+ ],
25
+ description: 'Connection object or string to pass to the redis client.',
26
+ errorMessage: {
27
+ type: 'Redis connection property "connection" should be a string or object.'
28
+ }
29
+ }
30
+ },
31
+ require: [
32
+ 'connection'
33
+ ],
34
+ errorMessage: {
35
+ type: 'Redis connection properties should be an object.'
36
+ }
37
+ };
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { default as Redis } from './connections/Redis/Redis.js';
package/dist/types.js ADDED
@@ -0,0 +1,19 @@
1
+ /* eslint-disable import/namespace */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import * as connections from './connections.js';
16
+ export default {
17
+ connections: Object.keys(connections),
18
+ requests: Object.keys(connections).map((connection)=>Object.keys(connections[connection].requests)).flat()
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/connection-redis",
3
- "version": "4.0.0-alpha.29",
3
+ "version": "4.0.0-alpha.30",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -45,11 +45,11 @@
45
45
  "test": "jest --coverage"
46
46
  },
47
47
  "dependencies": {
48
- "@lowdefy/helpers": "4.0.0-alpha.29",
48
+ "@lowdefy/helpers": "4.0.0-alpha.30",
49
49
  "redis": "4.1.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@lowdefy/ajv": "4.0.0-alpha.29",
52
+ "@lowdefy/ajv": "4.0.0-alpha.30",
53
53
  "@swc/cli": "0.1.57",
54
54
  "@swc/core": "1.2.194",
55
55
  "@swc/jest": "0.2.21",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "621a191ebc0a1569ee6669dc74c12f8be5a8c7f3"
61
+ "gitHead": "c30cc4e28e221d9b73385cca8d339397d60da0e1"
62
62
  }