Skip to content

Commit b05ea01

Browse files
SK-2007: fix insert call
2 parents 3660db4 + 4c5c160 commit b05ea01

File tree

7 files changed

+45
-56
lines changed

7 files changed

+45
-56
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions/checkout@v2
2828
- uses: actions/setup-node@v1
2929
with:
30-
node-version: 14.17.6
30+
node-version: 16.x.x
3131
- name: install modules
3232
run: npm install
3333

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skyflow-node",
3-
"version": "2.0.0-beta.2",
3+
"version": "2.0.0-beta.3",
44
"description": "Skyflow SDK for Node.js",
55
"main": "./lib/index.js",
66
"module": "./lib/index.js",

src/error/messages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const errorPrefix = `Skyflow Node SDK v${sdkDetails.version}`;
44

55
const errorMessages = {
66
CONFIG_MISSING: `${errorPrefix} Initialization failed. Skyflow config cannot be empty. Specify a valid skyflow config.`,
7-
INVALID_SKYFLOW_CONFIG: `${errorPrefix} Initialization failed. Invalid skyflow config. Vaults configs key missing in skyflow config.`,
7+
INVALID_SKYFLOW_CONFIG: `${errorPrefix} Initialization failed. Invalid skyflow config. Vault/Connection config key missing in skyflow config.`,
88
INVALID_TYPE_FOR_CONFIG: `${errorPrefix} Initialization failed. Invalid %s1 config. Specify a valid %s1 config.`,
99
EMPTY_VAULT_CONFIG: `${errorPrefix} Initialization failed. Vault config cannot be empty. Specify a valid vault config.`,
1010
EMPTY_CONNECTION_CONFIG: `${errorPrefix} Initialization failed. Connection config cannot be empty. Specify a valid connection config.`,

src/utils/validations/index.ts

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,22 @@ export const validateSkyflowConfig = (config: SkyflowConfig, logLevel: LogLevel
9191
if (config) {
9292
if (!Object.prototype.hasOwnProperty.call(config, 'vaultConfigs')) {
9393
printLog(logs.errorLogs.VAULT_CONFIG_KEY_MISSING, MessageType.ERROR, logLevel);
94+
}
95+
96+
const { vaultConfigs, connectionConfigs } = config;
97+
98+
// Count how many of the fields are defined
99+
const definedFields = [vaultConfigs, connectionConfigs].filter(Boolean).length;
100+
101+
// If none are present
102+
if (definedFields === 0) {
94103
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_SKYFLOW_CONFIG);
95104
}
96105

97106
if (config?.vaultConfigs && !Array.isArray(config.vaultConfigs)) {
98107
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TYPE_FOR_CONFIG, [VAULT])
99108
}
100109

101-
if (config?.vaultConfigs.length === 0) {
102-
throw new SkyflowError(SKYFLOW_ERROR_CODE.EMPTY_VAULT_CONFIG);
103-
}
104-
105110
if (config?.connectionConfigs && !Array.isArray(config?.connectionConfigs)) {
106111
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TYPE_FOR_CONFIG, [CONNECTION])
107112
}
@@ -321,15 +326,11 @@ function validateInsertInput(input: unknown, index: number): void {
321326
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
322327
}
323328

324-
// Iterate over the key-value pairs and check their types
325-
for (const [key, value] of entries) {
329+
// Iterate over the keys and check their types
330+
for (const [key] of entries) {
326331
if (key && typeof key !== 'string') {
327332
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
328333
}
329-
// update the data type accordingly
330-
if (value && typeof value !== 'string') {
331-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_INSERT, [index]);
332-
}
333334
}
334335

335336
} catch (error) {
@@ -349,15 +350,11 @@ function validateUpdateInput(input: unknown): void {
349350
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
350351
}
351352

352-
// Iterate over the key-value pairs and check their types
353-
for (const [key, value] of entries) {
353+
// Iterate over the keys and check their types
354+
for (const [key] of entries) {
354355
if (key && typeof key !== 'string') {
355356
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
356357
}
357-
// update the data type accordingly
358-
if (value && typeof value !== 'string') {
359-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_RECORD_IN_UPDATE);
360-
}
361358
}
362359

363360
} catch (error) {
@@ -377,15 +374,11 @@ function validateUpdateToken(input: unknown): void {
377374
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKEN_IN_UPDATE);
378375
}
379376

380-
// Iterate over the key-value pairs and check their types
381-
for (const [key, value] of entries) {
377+
// Iterate over the keys and check their types
378+
for (const [key] of entries) {
382379
if (key && typeof key !== 'string') {
383380
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKEN_IN_UPDATE);
384381
}
385-
// update the data type accordingly
386-
if (value && typeof value !== 'string') {
387-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_TOKEN_IN_UPDATE);
388-
}
389382
}
390383

391384
} catch (error) {
@@ -434,42 +427,42 @@ export const validateInsertOptions = (insertOptions?: InsertOptions) => {
434427
};
435428

436429
const validateTokensMapWithTokenStrict = (
437-
data: object,
438-
tokens: object
430+
data: object,
431+
tokens: object
439432
) => {
440-
const dataKeys = Object.keys(data);
433+
const dataKeys = Object.keys(data);
441434

442-
for (const key of dataKeys) {
443-
if (!tokens.hasOwnProperty(key)) {
444-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT);
435+
for (const key of dataKeys) {
436+
if (!tokens.hasOwnProperty(key)) {
437+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT);
438+
}
445439
}
446-
}
447440
};
448441

449442
export const validateTokensForInsertRequest = (
450-
insertRequest?: InsertRequest,
451-
insertOptions?: InsertOptions
443+
insertRequest?: InsertRequest,
444+
insertOptions?: InsertOptions
452445
) => {
453-
if (insertRequest && insertOptions && insertOptions.getTokenMode()) {
454-
if (
455-
(insertOptions.getTokenMode() == TokenMode.ENABLE ||
456-
insertOptions.getTokenMode() == TokenMode.ENABLE_STRICT) && !insertOptions.getTokens()
457-
) {
458-
throw new SkyflowError(SKYFLOW_ERROR_CODE.NO_TOKENS_WITH_TOKEN_MODE);
459-
}
460-
461-
if((insertOptions.getTokenMode() == TokenMode.ENABLE_STRICT) && insertOptions.getTokens()) {
462-
if(insertRequest.data.length!=insertOptions.getTokens()?.length) {
463-
throw new SkyflowError(SKYFLOW_ERROR_CODE.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT);
446+
if (insertRequest && insertOptions && insertOptions.getTokenMode()) {
447+
if (
448+
(insertOptions.getTokenMode() == TokenMode.ENABLE ||
449+
insertOptions.getTokenMode() == TokenMode.ENABLE_STRICT) && !insertOptions.getTokens()
450+
) {
451+
throw new SkyflowError(SKYFLOW_ERROR_CODE.NO_TOKENS_WITH_TOKEN_MODE);
464452
}
465453

466-
if(insertOptions.getTokens()) {
467-
for(let i=0;i<insertRequest.data.length;i++) {
468-
validateTokensMapWithTokenStrict(insertRequest.data[i], insertOptions.getTokens()![i])
454+
if ((insertOptions.getTokenMode() == TokenMode.ENABLE_STRICT) && insertOptions.getTokens()) {
455+
if (insertRequest.data.length != insertOptions.getTokens()?.length) {
456+
throw new SkyflowError(SKYFLOW_ERROR_CODE.INSUFFICIENT_TOKENS_PASSED_FOR_TOKEN_MODE_ENABLE_STRICT);
457+
}
458+
459+
if (insertOptions.getTokens()) {
460+
for (let i = 0; i < insertRequest.data.length; i++) {
461+
validateTokensMapWithTokenStrict(insertRequest.data[i], insertOptions.getTokens()![i])
462+
}
463+
}
469464
}
470465
}
471-
}
472-
}
473466
};
474467

475468
export const validateInsertRequest = (insertRequest: InsertRequest, insertOptions?: InsertOptions, logLevel: LogLevel = LogLevel.ERROR) => { //

src/vault/skyflow/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Skyflow {
3535

3636
this.commonCredentials = config?.skyflowCredentials;
3737
printLog(logs.infoLogs.VALIDATING_VAULT_CONFIG, MessageType.LOG, this.logLevel);
38-
config.vaultConfigs.map(vaultConfig => {
38+
config.vaultConfigs?.map(vaultConfig => {
3939
this.addVaultConfig(vaultConfig);
4040
});
4141
printLog(logs.infoLogs.VALIDATING_CONNECTION_CONFIG, MessageType.LOG, this.logLevel);

src/vault/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ConnectionController from "../controller/connections";
77
import VaultClient from "../client";
88

99
export interface SkyflowConfig {
10-
vaultConfigs: VaultConfig[];
10+
vaultConfigs?: VaultConfig[];
1111
connectionConfigs?: ConnectionConfig[];
1212
skyflowCredentials?: Credentials;
1313
logLevel?: LogLevel;

test/vault/skyflow/skyflow.test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ describe('Skyflow initialization', () => {
6969
})).toThrowError(invalidVaultConfigError);
7070
});
7171

72-
test('should throw error when empty vaultConfig is passed', () => {
73-
expect(() => new Skyflow({ vaultConfigs: [] })).toThrowError(emptyVaultConfigError);
74-
});
75-
7672
test('should throw error when invalid connectionConfig is passed', () => {
7773
expect(() => new Skyflow({
7874
vaultConfigs: [{

0 commit comments

Comments
 (0)