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

ts-redis-orm

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-redis-orm - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

2

build/parser.d.ts
declare class Parser {
private _ISORegex;
parseStorageStringToValue(type: any, storageString: string): any;
parseValueToStorageString(type: any, value: any): string;
private _parseDate;
}
export declare const parser: Parser;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Parser {
constructor() {
this._ISORegex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
}
parseStorageStringToValue(type, storageString) {

@@ -21,3 +24,3 @@ let value;

try {
const temp = JSON.parse(storageString);
const temp = JSON.parse(storageString, this._parseDate);
if (Array.isArray(temp)) {

@@ -36,3 +39,3 @@ value = temp;

try {
value = JSON.parse(storageString);
value = JSON.parse(storageString, this._parseDate);
}

@@ -85,3 +88,11 @@ catch (err) {

}
_parseDate(key, value) {
if (typeof value === "string") {
if (value.match(this._ISORegex)) {
return new Date(value);
}
}
return value;
}
}
exports.parser = new Parser();

2

package.json
{
"name": "ts-redis-orm",
"version": "0.1.9",
"version": "0.1.10",
"description": "A full functional Redis Orm library written in Typescript.",

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

class Parser {
private _ISORegex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
public parseStorageStringToValue(type: any, storageString: string): any {

@@ -23,3 +25,3 @@ let value: any;

try {
const temp = JSON.parse(storageString);
const temp = JSON.parse(storageString, this._parseDate);
if (Array.isArray(temp)) {

@@ -37,3 +39,3 @@ value = temp;

try {
value = JSON.parse(storageString);
value = JSON.parse(storageString, this._parseDate);
} catch (err) {

@@ -97,4 +99,14 @@ value = undefined;

}
private _parseDate(key: string, value: any): any {
if (typeof value === "string") {
if (value.match(this._ISORegex)) {
return new Date(value);
}
}
return value;
}
}
export const parser = new Parser();
import {assert, expect } from "chai";
import {BaseEntity, Column, Entity} from "../src/";
type IObject = undefined | {
name: string;
createdAt: Date;
};
@Entity({connection: "default", table: "testing_export"})

@@ -28,3 +33,3 @@ class TestingExport extends BaseEntity {

@Column()
public object: any;
public object: IObject;
}

@@ -61,3 +66,3 @@

entity.array = new Array(Math.random() * 20 | 0).fill(1);
entity.object = {};
entity.object = {name: "redis", createdAt: new Date()};
promises.push(entity.save());

@@ -80,5 +85,7 @@ }

it("export and import from file", async () => {
const entity = await TestingExport.query().limit(1).first();
await TestingExport.export(exportFile);
await TestingExport.truncate("TestingExport");
await TestingExport.import(exportFile);
const foundEntity = await TestingExport.query().limit(1).first();

@@ -98,2 +105,13 @@ const currentAllExist = await TestingExport.all();

}
// validate the entity
assert.isDefined(entity);
assert.isDefined(foundEntity);
// validate object date is correct
if (entity && foundEntity && entity.object && foundEntity.object) {
assert.isTrue(entity.object.createdAt instanceof Date);
assert.isTrue(foundEntity.object.createdAt instanceof Date);
assert.equal(entity.object.createdAt.getTime(), foundEntity.object.createdAt.getTime());
}
});

@@ -100,0 +118,0 @@

@@ -7,2 +7,5 @@ import {assert, expect } from "chai";

type NullableString = string | null;
type IObject = undefined | {
createdAt: Date;
};

@@ -36,3 +39,3 @@ @Entity({connection: "default", table: "testing_general"})

@Column()
public object: any;
public object: IObject;
}

@@ -96,2 +99,3 @@

entity.uniqueNumber = id;
entity.object = {createdAt: new Date()};
await entity.save();

@@ -105,2 +109,7 @@ assert.isFalse(entity.isNew);

assert.deepEqual(entity.getValues(), newEntity.getValues());
if (newEntity.object) {
assert.isTrue(newEntity.object.createdAt instanceof Date);
assert.equal(entity.object.createdAt.getTime(), newEntity.object.createdAt.getTime());
}
}

@@ -388,3 +397,3 @@ });

entity.string1 = Math.random().toString();
entity.object = {};
entity.object = {createdAt: new Date()};
promises.push(entity.save());

@@ -391,0 +400,0 @@ }

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