type-store 0.4.2 → 0.4.4
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.
- package/package.json +6 -5
- package/postgres/time_range.sql +7 -0
- package/type-store.js +59 -4
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-store",
|
|
3
3
|
"description": "type ecosystem",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.4",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"repository": "codenautas/type-store",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "type-store.js",
|
|
9
9
|
"files": [
|
|
10
10
|
"type-store.js",
|
|
11
|
-
"postgres-interval4client.js"
|
|
11
|
+
"postgres-interval4client.js",
|
|
12
|
+
"postgres"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"big.js": "^6.2.
|
|
15
|
+
"big.js": "^6.2.2",
|
|
15
16
|
"best-globals": "^1.1.6",
|
|
16
17
|
"js-to-html": "^1.3.2",
|
|
17
|
-
"json4all": "^1.
|
|
18
|
-
"like-ar": "^0.5.
|
|
18
|
+
"json4all": "^1.4.0",
|
|
19
|
+
"like-ar": "^0.5.1"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
22
|
"expect.js": "^0.3.1",
|
package/type-store.js
CHANGED
|
@@ -761,11 +761,66 @@ TypeStore.type.timestamp.prototype.toPlainString=function toPlainString(typedVal
|
|
|
761
761
|
return typedValue.toYmdHmsM();
|
|
762
762
|
};
|
|
763
763
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
764
|
+
// https://www.postgresql.org/docs/current/sql-createtype.html
|
|
765
|
+
TypeStore.type.time = function TypeArrayTime(){ TypeBase.apply(this, arguments); };
|
|
766
|
+
TypeStore.type.time.prototype = Object.create(TypeBase.prototype);
|
|
767
|
+
TypeStore.type.time.prototype.typeDbPg='time';
|
|
768
|
+
TypeStore.type.time.prototype.pgSpecialParse=true;
|
|
769
|
+
TypeStore.type.time.prototype.toPlainString=function toPlainString(typedValue){
|
|
770
|
+
return typedValue+'';
|
|
767
771
|
};
|
|
768
|
-
|
|
772
|
+
TypeStore.type.time.prototype.pg_OID=1083;
|
|
773
|
+
TypeStore.type.time.prototype.partDefs=[
|
|
774
|
+
{name:'hours' , optative:false, sufix:':' },
|
|
775
|
+
{name:'minutes', optative:false, sufix:':' , twoDigits:true },
|
|
776
|
+
{name:'seconds', optative:false, sufix:'' , twoDigits:true },
|
|
777
|
+
];
|
|
778
|
+
// constructorFunction:new PostgresInterval().constructor,
|
|
779
|
+
TypeStore.type.time.prototype.regExp=/^\s*(?:(\d+)\s*(?:h|:|hours?|horas?))?\s*(?:(\d+)\s*(?:m|:|'|min|minutes?|minutos?)?)?\s*(?:(\d+)\s*(?:s|"|sec|seg|seconds?|segundos?)?)?\s*?$/i;
|
|
780
|
+
TypeStore.type.time.prototype.fromString=function fromString(stringWithTime){
|
|
781
|
+
var value = this.toLocalString(stringWithTime);
|
|
782
|
+
if (value.length <1 ) throw new TypeError("NOT time")
|
|
783
|
+
return value;
|
|
784
|
+
};
|
|
785
|
+
TypeStore.type.time.prototype.isValidTypedData=function isValidTypedData(object){
|
|
786
|
+
return object === null || this.regExp.test(object);
|
|
787
|
+
};
|
|
788
|
+
TypeStore.type.time.prototype.toLocalParts=function toLocalParts(typedValue,fPart,fParts){
|
|
789
|
+
var str = this.toPlainString(typedValue);
|
|
790
|
+
var rta = [];
|
|
791
|
+
str.replace(/^\s*0?([1-2]?\d)\:(\d\d)(\:(\d\d))?$/, function(str, hour, minutes, dot, seconds){
|
|
792
|
+
rta.push(fPart(hour,"time-hour"));
|
|
793
|
+
rta.push(fPart(':',"time-colon"));
|
|
794
|
+
rta.push(fPart(minutes,"time-min"));
|
|
795
|
+
if (seconds != '00' && seconds != null) {
|
|
796
|
+
rta.push(fPart(':',"time-colon"));
|
|
797
|
+
rta.push(fPart(seconds,"time-sec"));
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
return fParts(rta, "time");
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
// https://www.postgresql.org/docs/current/sql-createtype.html
|
|
804
|
+
// https://www.postgresql.org/docs/current/rangetypes.html
|
|
805
|
+
|
|
806
|
+
/** @param {{typeName:string, pg_OID?:number, typeDbPg?:string}} param */
|
|
807
|
+
function rangeOf(param){
|
|
808
|
+
var result = function TypeRangeof(){ TypeBase.apply(this, arguments); };
|
|
809
|
+
result.prototype.toPlainString=function toPlainString(typedValue){
|
|
810
|
+
return typedValue;
|
|
811
|
+
};
|
|
812
|
+
result.prototype.fromString=function fromString(textValue){
|
|
813
|
+
return textValue;
|
|
814
|
+
};
|
|
815
|
+
result.prototype.typeDbPg=param.typeDbPg || param.typeName+'_range';
|
|
816
|
+
if (param.pg_OID) result.prototype.pg_OID=param.pg_OID;
|
|
817
|
+
return result
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
TypeStore.type.time_range=rangeOf({typeName:'time'});
|
|
821
|
+
TypeStore.type.tsrange=rangeOf({typeName:'timestamp', typeDbPg:'tsrange', pg_OID:3908});
|
|
822
|
+
|
|
823
|
+
|
|
769
824
|
// PostgresInterval.prototype.typeStore={type:'interval'};
|
|
770
825
|
|
|
771
826
|
json4all.addType(bestGlobals.TimeInterval,{
|