Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xapp/dynamo-service

Package Overview
Dependencies
Maintainers
5
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xapp/dynamo-service - npm Package Compare versions

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

xapp-dynamo-service-1.0.0-alpha.3.tgz

@@ -31,2 +31,54 @@ "use strict";

});
it("Tests that the object was added through a processor if it is set undefined.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
process: () => date
});
const obj = schema.convertObjectToSchema({ "Test": undefined });
expect(obj["Test"]).to.equal(date.toISOString());
});
it("Tests that the object was added through a processor if it is not even added to the original.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
process: () => date
});
const obj = schema.convertObjectToSchema({});
expect(obj["Test"]).to.equal(date.toISOString());
});
it("Tests that the object remains undefined if the user set it as undefined with no processor.", () => {
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date"
});
const obj = schema.convertObjectToSchema({ "Test": undefined });
expect(obj).to.deep.equal({ "Test": undefined });
});
it("Tests that the object remains undefined if the user didn't event set it and with no processor.", () => {
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date"
});
const obj = schema.convertObjectToSchema({});
expect(obj).to.deep.equal({});
});
},
makeUpdateObjectTests: () => {
it("Tests that the object being set to undefined is converted if a processor returns a default.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
process: () => date
});
const obj = schema.convertUpdateObjectToSchema({ set: { "Test": undefined } });
expect(obj).to.deep.equal({ set: { "Test": date.toISOString() } });
});
it("Tests that the object not setting the parameter is not converted if a processor returns a default.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
process: () => date
});
const obj = schema.convertUpdateObjectToSchema({ set: {} });
expect(obj).to.deep.equal({ set: {} });
});
}

@@ -46,2 +98,35 @@ });

});
it("Tests that the object is processed before the conversion.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
dateFormat: "Timestamp",
process: () => date
});
const obj = schema.convertObjectToSchema({ "Test": new Date(2019, 1, 1) });
expect(typeof obj["Test"], "The date object was not converted.").to.equal("number");
expect(obj["Test"]).to.equal(date.getTime());
});
},
makeUpdateObjectTests: () => {
it("Tests that the object being set to undefined is converted if a processor returns a default.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
dateFormat: "Timestamp",
process: () => date
});
const obj = schema.convertUpdateObjectToSchema({ set: { "Test": undefined } });
expect(obj).to.deep.equal({ set: { "Test": date.getTime() } });
});
it("Tests that the object not setting the parameter is not converted if a processor returns a default.", () => {
const date = new Date(2018, 1, 1);
const schema = new DateSchemaBuilder_1.default("Test", {
type: "Date",
dateFormat: "Timestamp",
process: () => date
});
const obj = schema.convertUpdateObjectToSchema({ set: {} });
expect(obj).to.deep.equal({ set: {} });
});
}

@@ -48,0 +133,0 @@ });

8

dist/service/TableService/SchemaBuilder/Date/DateSchemaBuilder.js

@@ -20,11 +20,11 @@ "use strict";

return {
toObj: (item) => new Date(item).getTime(),
fromObj: (item) => new Date(item)
toObj: (item) => (item) ? new Date(item).getTime() : undefined,
fromObj: (item) => (item) ? new Date(item) : undefined
};
}
return {
toObj: (item) => new Date(item).toISOString(),
fromObj: (item) => new Date(item)
toObj: (item) => (item) ? new Date(item).toISOString() : undefined,
fromObj: (item) => (item) ? new Date(item) : undefined
};
}
exports.default = DateSchemaBuilder;

@@ -11,4 +11,5 @@ import NormalSchemaBuilder, { NormalSchema } from "../NormalSchemaBuilder";

makeObjectTests?: TestExtension<SB, DT>;
makeUpdateObjectTests?: TestExtension<SB, DT>;
}
export declare function buildNormalSchemaTests<SB extends NormalSchemaBuilder = NormalSchemaBuilder, DT = unknown>(props: NormalSchemaBuilderTestProps<SB, DT>): void;
export declare function checkForErrors(callback: () => string[], expectedErrors?: string[]): void;

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

toObj: Sinon.stub().callsFake((item) => item),
fromObj: Sinon.stub().callsFake((item) => item + "-1")
fromObj: Sinon.stub().callsFake((item) => (item != null) ? item + "-1" : item)
};

@@ -125,7 +125,7 @@ const schema = schemaBuilder("Test", { process: c1 });

toObj: Sinon.stub().callsFake((item) => item),
fromObj: Sinon.stub().callsFake((item) => item + "-1")
fromObj: Sinon.stub().callsFake((item) => (item != null) ? item + "-1" : item)
};
const c2 = {
toObj: Sinon.stub().callsFake((item) => item),
fromObj: Sinon.stub().callsFake((item) => item + "-2")
fromObj: Sinon.stub().callsFake((item) => (item != null) ? item + "-2" : item)
};

@@ -147,4 +147,4 @@ const c3 = {

it("Tests that the object is ignored if the key is not in it.", () => {
const p1 = Sinon.stub().callsFake((item) => item + "-1");
const p2 = Sinon.stub().callsFake((item) => item + "-2");
const p1 = Sinon.stub().callsFake((item) => (item != null) ? item + "-1" : item);
const p2 = Sinon.stub().callsFake((item) => (item != null) ? item + "-2" : item);
const schema = schemaBuilder("Test", { process: [p1, p2] });

@@ -161,4 +161,4 @@ const obj = schema.convertObjectToSchema({

it("Tests that the processors worked.", () => {
const p1 = Sinon.stub().callsFake((item) => item + "-1");
const p2 = Sinon.stub().callsFake((item) => item + "-2");
const p1 = Sinon.stub().callsFake((item) => (item != null) ? item + "-1" : item);
const p2 = Sinon.stub().callsFake((item) => (item != null) ? item + "-2" : item);
const schema = schemaBuilder("Test", { process: [p1, p2] });

@@ -182,4 +182,4 @@ const obj = schema.convertObjectToSchema({

it("Tests that the processors worked.", () => {
const p1 = Sinon.stub().callsFake((item) => item + "-1");
const p2 = Sinon.stub().callsFake((item) => item + "-2");
const p1 = Sinon.stub().callsFake((item) => (item != null) ? item + "-1" : item);
const p2 = Sinon.stub().callsFake((item) => (item != null) ? item + "-2" : item);
const schema = schemaBuilder("Test", { process: [p1, p2] });

@@ -200,2 +200,6 @@ const obj = schema.convertUpdateObjectToSchema({

});
const { makeUpdateObjectTests } = props;
if (makeUpdateObjectTests) {
makeUpdateObjectTests(schemaBuilder);
}
});

@@ -202,0 +206,0 @@ }

@@ -42,14 +42,16 @@ "use strict";

convertObjectToSchema(baseObject) {
if (baseObject[this.key] == null) {
const hasProperty = baseObject.hasOwnProperty(this.key);
const original = baseObject[this.key];
let current = original;
for (const processor of this.processors) {
current = processor.toObj(current);
}
if (!hasProperty && current == null) {
return baseObject;
}
const copy = Object.assign({}, baseObject);
for (const processor of this.processors) {
copy[this.key] = processor.toObj(copy[this.key]);
}
return copy;
return Object.assign({}, baseObject, { [this.key]: current });
}
convertUpdateObjectToSchema(baseObject) {
const copy = Object.assign({}, baseObject);
if (copy.set) {
if (copy.set && copy.set.hasOwnProperty(this.key)) {
copy.set = this.convertObjectToSchema(copy.set);

@@ -60,3 +62,3 @@ }

convertObjectFromSchema(dynamoBaseObject) {
if (dynamoBaseObject[this.key] == null) {
if (!dynamoBaseObject.hasOwnProperty(this.key)) {
return dynamoBaseObject;

@@ -63,0 +65,0 @@ }

{
"name": "@xapp/dynamo-service",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"description": "A dynamo help class which will help maintain data integrity.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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