Socket
Socket
Sign inDemoInstall

@sajari/sdk-node

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sajari/sdk-node - npm Package Compare versions

Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5

dist/pipeline/replace.d.ts

15

dist/client.js

@@ -11,3 +11,9 @@ "use strict";

var schema_1 = require("./schema");
/**
* @hidden
*/
var API_ENDPOINT = "api.sajari.com:443";
/**
* @hidden
*/
var USER_AGENT = "sdk-node-1.0.0";

@@ -50,2 +56,5 @@ // withEndpoint configures the client to use a custom endpoint.

exports.DefaultClient = DefaultClient;
/**
* @hidden
*/
var createClients = function (services, endpoint, credentials) {

@@ -59,2 +68,5 @@ var clients = {};

};
/**
* @hidden
*/
var createClient = function (service, endpoint, creds) {

@@ -71,2 +83,5 @@ var ServiceProto = proto_defs_1.default.lookup(service);

};
/**
* @hidden
*/
var createCallCredentials = function (key, secret) {

@@ -73,0 +88,0 @@ return grpc_1.credentials.createFromMetadataGenerator(function (params, callback) {

8

dist/pipeline/add.d.ts
import { sajari } from "../../generated/proto";
export interface Key {
field: string;
value: any;
}
export interface Record {
[id: string]: string | string[];
}
import { Key, Record } from "./utils";
/**

@@ -10,0 +4,0 @@ * @hidden

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../utils");
var utils_2 = require("./utils");
/**

@@ -10,3 +11,3 @@ * @hidden

pipeline: { name: pipeline },
records: records.map(function (record) { return createEngineRecord(record); }),
records: records.map(function (record) { return utils_2.createEngineRecord(record); }),
values: values

@@ -18,20 +19,2 @@ };

*/
var createEngineRecord = function (record) {
var values = Object.keys(record).reduce(function (obj, key) {
var value = record[key];
if (typeof value === "string") {
obj[key] = { single: value };
return obj;
}
else if (value instanceof Array) {
obj[key] = { repeated: { values: value } };
return obj;
}
return obj;
}, {});
return { values: values };
};
/**
* @hidden
*/
exports.processAddResponse = function (response) {

@@ -54,3 +37,3 @@ var keys = response.keys

if (!key) {
var err = utils_1.errorFromStatus(response.status);
var err = utils_1.errorFromStatuses(response.status);
if (!!err) {

@@ -57,0 +40,0 @@ return err;

import { Client } from "../client";
import { Session } from "../session";
import { Key, Record } from "./add";
import { KeyRecord, ReplaceResponse } from "./replace";
import { SearchResponse } from "./search";
import { Key, Record } from "./utils";
/**
* Pipeline is a handler for a named pipeline.
*/
export declare class Pipeline {

@@ -9,8 +13,23 @@ client: Client;

constructor(client: Client, name: string);
/**
* search runs a search query defined by a pipline with the given values and
* session. Returns the query results and returned values (which could have
* been modified in the pipeline).
*/
search(values: {
[k: string]: string;
}, session: Session): Promise<SearchResponse>;
/**
* Add a record to a collection using a pipeline, returning the unique
* key which can be used to retrieve the respective record.
*/
add(record: Record, values?: {
[k: string]: string;
}): Promise<Key>;
replaceMulti(keyRecords: KeyRecord[], values?: {
[k: string]: string;
}): Promise<ReplaceResponse[]>;
replace(keyRecord: KeyRecord, values?: {
[k: string]: string;
}): Promise<Key>;
}

@@ -9,5 +9,11 @@ "use strict";

var add_1 = require("./add");
var replace_1 = require("./replace");
var search_1 = require("./search");
/**
* @hidden
*/
var debug = debug_1.default("sajari:client:pipeline");
// Pipeline is a handler for a named pipeline.
/**
* Pipeline is a handler for a named pipeline.
*/
var Pipeline = /** @class */ (function () {

@@ -18,5 +24,7 @@ function Pipeline(client, name) {

}
// search runs a search query defined by a pipline with the given values and
// session. Returns the query results and returned values (which could have
// been modified in the pipeline).
/**
* search runs a search query defined by a pipline with the given values and
* session. Returns the query results and returned values (which could have
* been modified in the pipeline).
*/
Pipeline.prototype.search = function (values, session) {

@@ -42,4 +50,6 @@ var _this = this;

};
// Add a record to a collection using a pipeline, returning the unique
// key which can be used to retrieve the respective record.
/**
* Add a record to a collection using a pipeline, returning the unique
* key which can be used to retrieve the respective record.
*/
Pipeline.prototype.add = function (record, values) {

@@ -57,2 +67,5 @@ var _this = this;

}
if (response.response == null) {
return reject(new Error("sajari: empty response"));
}
var res = add_1.processAddResponse(response.response);

@@ -66,4 +79,39 @@ if (res instanceof Error) {

};
Pipeline.prototype.replaceMulti = function (keyRecords, values) {
var _this = this;
if (values === void 0) { values = {}; }
return new Promise(function (resolve, reject) {
var request = replace_1.createReplaceRequest(_this.name, keyRecords, values);
debug("replace request: %o", request);
debug("replace metadata: %o", _this.client.metadata.getMap());
// @ts-ignore: generated client method
_this.client.clients.Store.replace(request, _this.client.metadata, { deadline: utils_1.deadline(5) }, function (err, response) {
if (err) {
return reject(err);
}
if (response.response == null) {
return reject(new Error("sajari: empty response"));
}
var res = replace_1.parseReplaceResponse(response.response);
return resolve(res);
});
});
};
Pipeline.prototype.replace = function (keyRecord, values) {
var _this = this;
if (values === void 0) { values = {}; }
return new Promise(function (resolve, reject) {
_this.replaceMulti([keyRecord], values)
.then(function (response) {
var res = response[0];
if (res.error) {
return reject(res.error);
}
return resolve(res.key);
})
.catch(reject);
});
};
return Pipeline;
}());
exports.Pipeline = Pipeline;

@@ -54,3 +54,3 @@ "use strict";

}
var error = utils_1.errorFromStatus(response.status);
var error = utils_1.errorFromStatuses(response.status);
if (error) {

@@ -78,3 +78,3 @@ return reject(error);

}
var error = utils_1.errorFromStatus(response.status);
var error = utils_1.errorFromStatuses(response.status);
if (error) {

@@ -81,0 +81,0 @@ return reject(error);

@@ -9,3 +9,11 @@ import { sajari } from "../generated/proto";

*/
export declare const errorFromStatus: (status: sajari.rpc.Status[]) => MultiError | null;
export declare const valueToProto: (v: string | string[]) => sajari.engine.Value | null;
/**
* @hidden
*/
export declare const errorFromStatus: (status: sajari.rpc.Status) => Error | null;
/**
* @hidden
*/
export declare const errorFromStatuses: (status: sajari.rpc.Status[]) => MultiError | null;
export declare class MultiError extends Error {

@@ -12,0 +20,0 @@ errors: Error[];

@@ -17,2 +17,3 @@ "use strict";

var grpc_1 = require("grpc");
var proto_1 = require("../generated/proto");
/**

@@ -34,18 +35,32 @@ * @hidden

*/
exports.valueToProto = function (v) {
if (Array.isArray(v)) {
return new proto_1.sajari.engine.Value({ repeated: { values: v } });
}
else if (typeof v === "string") {
return new proto_1.sajari.engine.Value({ single: v });
}
return null;
};
/**
* @hidden
*/
exports.errorFromStatus = function (status) {
var errors = status
.map(function (callStatus) {
switch (callStatus.code) {
case grpc_1.status.OK:
return null;
case grpc_1.status.NOT_FOUND:
return new Error("sajari: no such record");
default:
var error = new Error(callStatus.message);
error.code = callStatus.code;
return error;
}
})
.filter(function (x) { return !!x; });
if (errors.length < 1) {
switch (status.code) {
case grpc_1.status.OK:
return null;
case grpc_1.status.NOT_FOUND:
return new Error("sajari: no such record");
default:
var error = new Error(status.message);
error.code = status.code;
return error;
}
};
/**
* @hidden
*/
exports.errorFromStatuses = function (status) {
var errors = status.map(exports.errorFromStatus).filter(function (x) { return !!x; });
if (errors.length === 0) {
return null;

@@ -52,0 +67,0 @@ }

{
"name": "@sajari/sdk-node",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc