@ddd-ts/shape 0.0.36 → 0.0.38
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/LICENSE +21 -0
- package/dist/_.d.ts +6 -6
- package/dist/_.d.ts.map +1 -1
- package/dist/_.js +34 -51
- package/dist/_.mjs +36 -0
- package/dist/addons/microsecond-timestamp.js +62 -75
- package/dist/addons/microsecond-timestamp.mjs +61 -0
- package/dist/choice.d.ts +1 -1
- package/dist/choice.d.ts.map +1 -1
- package/dist/choice.js +43 -48
- package/dist/choice.mjs +44 -0
- package/dist/class.d.ts +1 -1
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +29 -30
- package/dist/class.mjs +30 -0
- package/dist/dict.d.ts +1 -1
- package/dist/dict.d.ts.map +1 -1
- package/dist/dict.js +40 -46
- package/dist/dict.mjs +41 -0
- package/dist/discriminated-union.d.ts +2 -2
- package/dist/discriminated-union.d.ts.map +1 -1
- package/dist/discriminated-union.js +59 -90
- package/dist/discriminated-union.mjs +64 -0
- package/dist/either.d.ts +2 -2
- package/dist/either.d.ts.map +1 -1
- package/dist/either.js +50 -61
- package/dist/either.mjs +51 -0
- package/dist/index.js +32 -30
- package/dist/index.mjs +15 -0
- package/dist/literal.d.ts +1 -1
- package/dist/literal.d.ts.map +1 -1
- package/dist/literal.js +26 -26
- package/dist/literal.mjs +27 -0
- package/dist/mapping.d.ts +1 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +44 -49
- package/dist/mapping.mjs +45 -0
- package/dist/multiple.d.ts +1 -1
- package/dist/multiple.d.ts.map +1 -1
- package/dist/multiple.js +118 -119
- package/dist/multiple.mjs +119 -0
- package/dist/nothing.d.ts +1 -1
- package/dist/nothing.d.ts.map +1 -1
- package/dist/nothing.js +18 -18
- package/dist/nothing.mjs +19 -0
- package/dist/optional.d.ts +1 -1
- package/dist/optional.d.ts.map +1 -1
- package/dist/optional.js +33 -40
- package/dist/optional.mjs +34 -0
- package/dist/primitive.d.ts +1 -1
- package/dist/primitive.d.ts.map +1 -1
- package/dist/primitive.js +29 -32
- package/dist/primitive.mjs +30 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.d.ts.map +1 -1
- package/package.json +21 -10
- package/dist/_.js.map +0 -1
- package/dist/addons/microsecond-timestamp.js.map +0 -1
- package/dist/choice.js.map +0 -1
- package/dist/choice.spec.js +0 -147
- package/dist/choice.spec.js.map +0 -1
- package/dist/class.js.map +0 -1
- package/dist/class.spec.js +0 -39
- package/dist/class.spec.js.map +0 -1
- package/dist/dict.js.map +0 -1
- package/dist/dict.spec.js +0 -180
- package/dist/dict.spec.js.map +0 -1
- package/dist/discriminated-union.js.map +0 -1
- package/dist/discriminated-union.spec.js +0 -262
- package/dist/discriminated-union.spec.js.map +0 -1
- package/dist/either.js.map +0 -1
- package/dist/either.spec.js +0 -232
- package/dist/either.spec.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/literal.js.map +0 -1
- package/dist/literal.spec.js +0 -162
- package/dist/literal.spec.js.map +0 -1
- package/dist/mapping.js.map +0 -1
- package/dist/mapping.spec.js +0 -207
- package/dist/mapping.spec.js.map +0 -1
- package/dist/multiple.js.map +0 -1
- package/dist/multiple.spec.js +0 -207
- package/dist/multiple.spec.js.map +0 -1
- package/dist/nothing.js.map +0 -1
- package/dist/nothing.spec.js +0 -172
- package/dist/nothing.spec.js.map +0 -1
- package/dist/optional.js.map +0 -1
- package/dist/optional.spec.js +0 -172
- package/dist/optional.spec.js.map +0 -1
- package/dist/primitive.js.map +0 -1
- package/dist/primitive.spec.js +0 -162
- package/dist/primitive.spec.js.map +0 -1
- package/dist/test.js +0 -45
- package/dist/test.js.map +0 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/multiple.ts
|
|
4
|
+
const Multiple = (of, base = Empty) => {
|
|
5
|
+
const longhand = Shape(of);
|
|
6
|
+
class $Multiple extends base {
|
|
7
|
+
constructor(value) {
|
|
8
|
+
super();
|
|
9
|
+
this.value = value;
|
|
10
|
+
}
|
|
11
|
+
static $shape = "multiple";
|
|
12
|
+
serialize() {
|
|
13
|
+
return $Multiple.$serialize(this.value);
|
|
14
|
+
}
|
|
15
|
+
static deserialize(value) {
|
|
16
|
+
return new this($Multiple.$deserialize(value));
|
|
17
|
+
}
|
|
18
|
+
static $deserialize(value) {
|
|
19
|
+
return value.map(longhand.$deserialize);
|
|
20
|
+
}
|
|
21
|
+
static $serialize(value) {
|
|
22
|
+
return value.map(longhand.$serialize);
|
|
23
|
+
}
|
|
24
|
+
[Symbol.iterator]() {
|
|
25
|
+
return this.value[Symbol.iterator]();
|
|
26
|
+
}
|
|
27
|
+
get map() {
|
|
28
|
+
return this.value.map.bind(this.value);
|
|
29
|
+
}
|
|
30
|
+
get reduce() {
|
|
31
|
+
return this.value.reduce.bind(this.value);
|
|
32
|
+
}
|
|
33
|
+
get filter() {
|
|
34
|
+
return this.value.filter.bind(this.value);
|
|
35
|
+
}
|
|
36
|
+
get forEach() {
|
|
37
|
+
return this.value.forEach.bind(this.value);
|
|
38
|
+
}
|
|
39
|
+
get some() {
|
|
40
|
+
return this.value.some.bind(this.value);
|
|
41
|
+
}
|
|
42
|
+
get every() {
|
|
43
|
+
return this.value.every.bind(this.value);
|
|
44
|
+
}
|
|
45
|
+
get find() {
|
|
46
|
+
return this.value.find.bind(this.value);
|
|
47
|
+
}
|
|
48
|
+
get findIndex() {
|
|
49
|
+
return this.value.findIndex.bind(this.value);
|
|
50
|
+
}
|
|
51
|
+
get indexOf() {
|
|
52
|
+
return this.value.indexOf.bind(this.value);
|
|
53
|
+
}
|
|
54
|
+
get lastIndexOf() {
|
|
55
|
+
return this.value.lastIndexOf.bind(this.value);
|
|
56
|
+
}
|
|
57
|
+
get includes() {
|
|
58
|
+
return this.value.includes.bind(this.value);
|
|
59
|
+
}
|
|
60
|
+
get keys() {
|
|
61
|
+
return this.value.keys.bind(this.value);
|
|
62
|
+
}
|
|
63
|
+
get values() {
|
|
64
|
+
return this.value.values.bind(this.value);
|
|
65
|
+
}
|
|
66
|
+
get entries() {
|
|
67
|
+
return this.value.entries.bind(this.value);
|
|
68
|
+
}
|
|
69
|
+
get at() {
|
|
70
|
+
return this.value.at.bind(this.value);
|
|
71
|
+
}
|
|
72
|
+
get concat() {
|
|
73
|
+
return this.value.concat.bind(this.value);
|
|
74
|
+
}
|
|
75
|
+
get flat() {
|
|
76
|
+
return this.value.flat.bind(this.value);
|
|
77
|
+
}
|
|
78
|
+
get splice() {
|
|
79
|
+
return this.value.splice.bind(this.value);
|
|
80
|
+
}
|
|
81
|
+
get flatMap() {
|
|
82
|
+
return this.value.flatMap.bind(this.value);
|
|
83
|
+
}
|
|
84
|
+
get push() {
|
|
85
|
+
return this.value.push.bind(this.value);
|
|
86
|
+
}
|
|
87
|
+
get pop() {
|
|
88
|
+
return this.value.pop.bind(this.value);
|
|
89
|
+
}
|
|
90
|
+
get sort() {
|
|
91
|
+
return this.value.sort.bind(this.value);
|
|
92
|
+
}
|
|
93
|
+
get slice() {
|
|
94
|
+
return this.value.slice.bind(this.value);
|
|
95
|
+
}
|
|
96
|
+
get length() {
|
|
97
|
+
return this.value.length;
|
|
98
|
+
}
|
|
99
|
+
get fill() {
|
|
100
|
+
return this.value.fill.bind(this.value);
|
|
101
|
+
}
|
|
102
|
+
get copyWithin() {
|
|
103
|
+
return this.value.copyWithin.bind(this.value);
|
|
104
|
+
}
|
|
105
|
+
get reverse() {
|
|
106
|
+
return this.value.reverse.bind(this.value);
|
|
107
|
+
}
|
|
108
|
+
get shift() {
|
|
109
|
+
return this.value.shift.bind(this.value);
|
|
110
|
+
}
|
|
111
|
+
get unshift() {
|
|
112
|
+
return this.value.unshift.bind(this.value);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return $Multiple;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { Multiple };
|
package/dist/nothing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractConstructor, Constructor, Empty } from "./_";
|
|
1
|
+
import { type AbstractConstructor, type Constructor, Empty } from "./_";
|
|
2
2
|
export type NothingShorthand = undefined;
|
|
3
3
|
export declare const Nothing: <B extends AbstractConstructor<{}> = typeof Empty>(config: void, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (...args: any[]) => {
|
|
4
4
|
serialize(): void;
|
package/dist/nothing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nothing.d.ts","sourceRoot":"","sources":["../src/nothing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"nothing.d.ts","sourceRoot":"","sources":["../src/nothing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAmB,KAAK,EAAE,MAAM,KAAK,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAEzC,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,yBAC/C,IAAI,SACN,CAAC;;;YAGW,SAAS;gBAGN,CAAC,SAAS,WAAW,QAChC,CAAC,SACA,IAAI,GACV,YAAY,CAAC,CAAC,CAAC;;;aAKF,IAAI;+BAIb,IAAI,KACR,YAAY,CAAC,CAAC,CAAC;;CAAW,CAOhC,CAAC"}
|
package/dist/nothing.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return $Nothing;
|
|
1
|
+
const require__ = require('./_.js');
|
|
2
|
+
|
|
3
|
+
//#region src/nothing.ts
|
|
4
|
+
const Nothing = (config, base = require__.Empty) => {
|
|
5
|
+
class $Nothing extends base {
|
|
6
|
+
static $shape = "nothing";
|
|
7
|
+
serialize() {}
|
|
8
|
+
static deserialize(value) {
|
|
9
|
+
return new this();
|
|
10
|
+
}
|
|
11
|
+
static $deserialize() {}
|
|
12
|
+
static $serialize() {}
|
|
13
|
+
static $inline;
|
|
14
|
+
}
|
|
15
|
+
return $Nothing;
|
|
17
16
|
};
|
|
18
|
-
|
|
19
|
-
//#
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.Nothing = Nothing;
|
package/dist/nothing.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Empty } from "./_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/nothing.ts
|
|
4
|
+
const Nothing = (config, base = Empty) => {
|
|
5
|
+
class $Nothing extends base {
|
|
6
|
+
static $shape = "nothing";
|
|
7
|
+
serialize() {}
|
|
8
|
+
static deserialize(value) {
|
|
9
|
+
return new this();
|
|
10
|
+
}
|
|
11
|
+
static $deserialize() {}
|
|
12
|
+
static $serialize() {}
|
|
13
|
+
static $inline;
|
|
14
|
+
}
|
|
15
|
+
return $Nothing;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Nothing };
|
package/dist/optional.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Definition, Expand, Shorthand, DefinitionOf, Constructor, AbstractConstructor, Empty } from "./_";
|
|
1
|
+
import { type Definition, type Expand, type Shorthand, type DefinitionOf, type Constructor, type AbstractConstructor, Empty } from "./_";
|
|
2
2
|
export type OptionalConfiguration = Definition | Shorthand;
|
|
3
3
|
type Matcher<V> = {
|
|
4
4
|
some: (value: V) => any;
|
package/dist/optional.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../src/optional.ts"],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|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
static $serialize(value) {
|
|
32
|
-
return value === undefined
|
|
33
|
-
? undefined
|
|
34
|
-
: (0, _1.Shape)(of).$serialize(value);
|
|
35
|
-
}
|
|
36
|
-
static $inline;
|
|
37
|
-
}
|
|
38
|
-
return $Optional;
|
|
1
|
+
const require__ = require('./_.js');
|
|
2
|
+
|
|
3
|
+
//#region src/optional.ts
|
|
4
|
+
const Optional = (of, base = require__.Empty) => {
|
|
5
|
+
class $Optional extends base {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
super();
|
|
8
|
+
this.value = value;
|
|
9
|
+
}
|
|
10
|
+
static $shape = "optional";
|
|
11
|
+
serialize() {
|
|
12
|
+
return $Optional.$serialize(this.value);
|
|
13
|
+
}
|
|
14
|
+
match(config) {
|
|
15
|
+
if (this.value === void 0) return config.none();
|
|
16
|
+
return config.some(this.value);
|
|
17
|
+
}
|
|
18
|
+
static deserialize(value) {
|
|
19
|
+
return new this(this.$deserialize(value));
|
|
20
|
+
}
|
|
21
|
+
static $deserialize(value) {
|
|
22
|
+
if (value === void 0) return;
|
|
23
|
+
return require__.Shape(of).$deserialize(value);
|
|
24
|
+
}
|
|
25
|
+
static $serialize(value) {
|
|
26
|
+
return value === void 0 ? void 0 : require__.Shape(of).$serialize(value);
|
|
27
|
+
}
|
|
28
|
+
static $inline;
|
|
29
|
+
}
|
|
30
|
+
return $Optional;
|
|
39
31
|
};
|
|
40
|
-
|
|
41
|
-
//#
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.Optional = Optional;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/optional.ts
|
|
4
|
+
const Optional = (of, base = Empty) => {
|
|
5
|
+
class $Optional extends base {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
super();
|
|
8
|
+
this.value = value;
|
|
9
|
+
}
|
|
10
|
+
static $shape = "optional";
|
|
11
|
+
serialize() {
|
|
12
|
+
return $Optional.$serialize(this.value);
|
|
13
|
+
}
|
|
14
|
+
match(config) {
|
|
15
|
+
if (this.value === void 0) return config.none();
|
|
16
|
+
return config.some(this.value);
|
|
17
|
+
}
|
|
18
|
+
static deserialize(value) {
|
|
19
|
+
return new this(this.$deserialize(value));
|
|
20
|
+
}
|
|
21
|
+
static $deserialize(value) {
|
|
22
|
+
if (value === void 0) return;
|
|
23
|
+
return Shape(of).$deserialize(value);
|
|
24
|
+
}
|
|
25
|
+
static $serialize(value) {
|
|
26
|
+
return value === void 0 ? void 0 : Shape(of).$serialize(value);
|
|
27
|
+
}
|
|
28
|
+
static $inline;
|
|
29
|
+
}
|
|
30
|
+
return $Optional;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { Optional };
|
package/dist/primitive.d.ts
CHANGED
package/dist/primitive.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive.d.ts","sourceRoot":"","sources":["../src/primitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"primitive.d.ts","sourceRoot":"","sources":["../src/primitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAiB,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,KAAK,CAAC;AAEpG,KAAK,YAAY,GAAG;IAClB;QAAC,iBAAiB;QAAE,MAAM;KAAC;IAC3B;Q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AAC,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEJ,eAAO,MAAM,SAAS,GACpB,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,qBAE7B,CAAC,SACC,CAAC,KACN,UAAU,CAAC,CAAC,EAAE,CAAC,CA4CjB,CAAC"}
|
package/dist/primitive.js
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
static $inline;
|
|
29
|
-
}
|
|
30
|
-
return $Primitive;
|
|
1
|
+
const require__ = require('./_.js');
|
|
2
|
+
|
|
3
|
+
//#region src/primitive.ts
|
|
4
|
+
const Primitive = (of, base = require__.Empty) => {
|
|
5
|
+
class $Primitive extends base {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
super();
|
|
8
|
+
this.value = value;
|
|
9
|
+
}
|
|
10
|
+
static $shape = "primitive";
|
|
11
|
+
serialize() {
|
|
12
|
+
return this.value;
|
|
13
|
+
}
|
|
14
|
+
static deserialize(value) {
|
|
15
|
+
return new this(this.$deserialize(value));
|
|
16
|
+
}
|
|
17
|
+
static $serialize(value) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
static $deserialize(value) {
|
|
21
|
+
if (of === Date && typeof value === "string") return new Date(value);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
static $inline;
|
|
25
|
+
}
|
|
26
|
+
return $Primitive;
|
|
31
27
|
};
|
|
32
|
-
|
|
33
|
-
//#
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.Primitive = Primitive;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Empty } from "./_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/primitive.ts
|
|
4
|
+
const Primitive = (of, base = Empty) => {
|
|
5
|
+
class $Primitive extends base {
|
|
6
|
+
constructor(value) {
|
|
7
|
+
super();
|
|
8
|
+
this.value = value;
|
|
9
|
+
}
|
|
10
|
+
static $shape = "primitive";
|
|
11
|
+
serialize() {
|
|
12
|
+
return this.value;
|
|
13
|
+
}
|
|
14
|
+
static deserialize(value) {
|
|
15
|
+
return new this(this.$deserialize(value));
|
|
16
|
+
}
|
|
17
|
+
static $serialize(value) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
static $deserialize(value) {
|
|
21
|
+
if (of === Date && typeof value === "string") return new Date(value);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
static $inline;
|
|
25
|
+
}
|
|
26
|
+
return $Primitive;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { Primitive };
|
package/dist/test.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constructor } from "./_";
|
|
1
|
+
import { type Constructor } from "./_";
|
|
2
2
|
type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;
|
|
3
3
|
export type Equals<X, Y> = IfEquals<X, Y, true, false>;
|
|
4
4
|
export declare function ex<Received>(received: Received): {
|
package/dist/test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,E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AI,EAAE,GAAG,EAAE,KACX,GAAG,GACJ,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,IAAI,GAChC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,CAAC,CAAA;KAAE,GACnC,QAAQ,SAAS,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,GACtD,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,IAAI,GAChC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,CAAC,CAAA;KAAE,GACnC,+BAA+B;EAItC"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts/shape",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "dist/index.js",
|
|
3
|
+
"version": "0.0.38",
|
|
5
4
|
"types": "dist/index.d.ts",
|
|
6
5
|
"license": "MIT",
|
|
7
6
|
"repository": {
|
|
8
7
|
"url": "git+https://github.com/ddd-ts/monorepo"
|
|
9
8
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
14
12
|
"dependencies": {
|
|
15
|
-
"@ddd-ts/traits": "0.0.
|
|
13
|
+
"@ddd-ts/traits": "0.0.38"
|
|
16
14
|
},
|
|
17
15
|
"devDependencies": {
|
|
18
|
-
"@ddd-ts/tools": "0.0.
|
|
19
|
-
"@ddd-ts/types": "0.0.
|
|
16
|
+
"@ddd-ts/tools": "0.0.38",
|
|
17
|
+
"@ddd-ts/types": "0.0.38",
|
|
20
18
|
"@types/jest": "^29.5.1"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.mjs",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsdown --config node_modules/@ddd-ts/tools/tsdown.config.js",
|
|
31
|
+
"test": "jest --config node_modules/@ddd-ts/tools/jest.config.js"
|
|
21
32
|
}
|
|
22
|
-
}
|
|
33
|
+
}
|
package/dist/_.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_.js","sourceRoot":"","sources":["../src/_.ts"],"names":[],"mappings":";;;AAmEA,sBAwCC;AAUD,0BAwBC;AA7ID,mCAAwD;AACxD,iCAAoD;AACpD,2CAA4D;AAC5D,yCAAoE;AACpE,uCAAsD;AACtD,uCAAgE;AAEhE,MAAsB,KAAK;CAAG;AAA9B,sBAA8B;AA4D9B,SAAgB,KAAK,CAGnB,SAAY,EAAE,OAAU,KAAY;IACpC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QACnE,OAAO,IAAA,iBAAO,EAAC,SAAS,EAAE,IAAI,CAAQ,CAAC;IACzC,CAAC;IAED,IACE,SAAS;QACT,QAAQ,IAAI,SAAS;QACrB,MAAM,IAAI,SAAS;QACnB,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,EAClC,CAAC;QACD,IAAK,SAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5C,OAAO,SAAgB,CAAC;QAC1B,CAAC;QACD,OAAO,IAAA,aAAK,EAAC,SAAgB,EAAE,IAAI,CAAQ,CAAC;IAC9C,CAAC;IACD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,IAAA,iBAAO,EAAC,SAAS,EAAE,IAAI,CAAQ,CAAC;IACzC,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,SAAgB,CAAC,EAAE,CAAC;QAC/D,OAAO,IAAA,qBAAS,EAAC,SAAgB,EAAE,IAAI,CAAQ,CAAC;IAClD,CAAC;IACD,IAAI,SAAS,IAAI,WAAW,IAAI,SAAS,EAAE,CAAC;QAC1C,OAAO,IAAA,aAAK,EAAC,SAAgB,EAAE,IAAI,CAAQ,CAAC;IAC9C,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,OAAQ,mBAAgB,CAAC,SAAS,CAAC,CAAC,CAAQ,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,IAAA,WAAI,EAAC,SAAgB,EAAE,IAAI,CAAQ,CAAC;IAC7C,CAAC;IAED,MAAM,IAAI,KAAK,CACb,+CAA+C,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAC3E,CAAC;AACJ,CAAC;AAUD,SAAgB,OAAO,CAMrB,IAAO,EACP,OAAgB;IAShB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YACzC,GAAG;gBACD,OAAQ,IAAI,CAAC,KAAa,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAW,CAAC;AACrB,CAAC","sourcesContent":["import { Class, IClass, ClassShorthand } from \"./class\";\nimport { Dict, IDict, DictShorthand } from \"./dict\";\nimport { Primitive, PrimitiveShorthand } from \"./primitive\";\nimport { Multiple, IMultiple, MultipleShorthand } from \"./multiple\";\nimport { Nothing, NothingShorthand } from \"./nothing\";\nimport { Literal, ILiteral, LiteralShorthand } from \"./literal\";\n\nexport abstract class Empty {}\n\nexport interface Constructor<T = any, P extends any[] = any[]> {\n new (...args: P): T;\n}\nexport type AbstractConstructor<\n T = any,\n P extends any[] = any[],\n> = abstract new (...args: P) => T;\n\nexport interface Definition {\n $shape: string;\n $inline: any;\n $serialize(value: any): any;\n $deserialize(value: any): any;\n}\n\nexport type MakeAbstract<T> = T extends new (\n ...params: infer P\n) => infer R\n ? Omit<T, \"\"> & (abstract new (...params: P) => R)\n : never;\n\nexport type Concrete<T extends AbstractConstructor<any>> =\n T extends abstract new (\n ...params: infer P\n ) => infer R\n ? Omit<T, \"\"> & {\n new (...params: P): R;\n }\n : never;\n\nexport type Shorthand =\n | Definition\n | DictShorthand\n | PrimitiveShorthand\n | MultipleShorthand\n | NothingShorthand\n | ClassShorthand\n | LiteralShorthand;\n\nexport type DefinitionOf<\n T extends Shorthand | Definition,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = T extends LiteralShorthand\n ? ILiteral<T, B>\n : T extends undefined\n ? ReturnType<typeof Nothing<B>>\n : T extends PrimitiveShorthand\n ? ReturnType<typeof Primitive<T, B>>\n : T extends MultipleShorthand\n ? IMultiple<T[0], B>\n : T extends ClassShorthand\n ? IClass<T, B>\n : T extends Definition\n ? T\n : T extends DictShorthand\n ? IDict<T, B>\n : never;\n\nexport function Shape<\n const S extends Definition | Shorthand,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(shorthand: S, base: B = Empty as any): DefinitionOf<S, B> {\n if (typeof shorthand === \"string\" || typeof shorthand === \"number\") {\n return Literal(shorthand, base) as any;\n }\n\n if (\n shorthand &&\n \"$shape\" in shorthand &&\n \"name\" in shorthand &&\n typeof shorthand.name === \"string\"\n ) {\n if ((shorthand as any).name.startsWith(\"$\")) {\n return shorthand as any;\n }\n return Class(shorthand as any, base) as any;\n }\n if (shorthand === undefined) {\n return Nothing(undefined, base) as any;\n }\n if ([String, Number, Date, Boolean].includes(shorthand as any)) {\n return Primitive(shorthand as any, base) as any;\n }\n if (shorthand && \"prototype\" in shorthand) {\n return Class(shorthand as any, base) as any;\n }\n\n if (Array.isArray(shorthand)) {\n return (Multiple as any)(shorthand[0] as any, base);\n }\n\n if (typeof shorthand === \"object\") {\n return Dict(shorthand as any, base) as any;\n }\n\n throw new Error(\n `Could not determine longhand from shorthand ${JSON.stringify(shorthand)}`,\n );\n}\n\nexport type Expand<T> = T extends { serialize(): any }\n ? T\n : T extends Date\n ? T\n : T extends Record<string, any>\n ? { [key in keyof T]: Expand<T[key]> }\n : T;\n\nexport function forward<\n T extends AbstractConstructor<{ value: any }>,\n const Forward extends T extends AbstractConstructor<{ value: infer U }>\n ? (keyof U)[]\n : never,\n>(\n base: T,\n forward: Forward,\n): MakeAbstract<\n T &\n (new (\n ...args: ConstructorParameters<T>\n ) => InstanceType<T> & {\n [K in Forward[number]]: InstanceType<T>[\"value\"][K];\n })\n> {\n for (const key of forward) {\n Object.defineProperty(base.prototype, key, {\n get() {\n return (this.value as any)[key].bind(this.value);\n },\n });\n }\n return base as any;\n}\n\nexport type MergeClasses<\n B extends AbstractConstructor,\n Current extends AbstractConstructor,\n> = abstract new (\n ...args: ConstructorParameters<Current>\n) => InstanceType<B> & InstanceType<Current>;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"microsecond-timestamp.js","sourceRoot":"","sources":["../../src/addons/microsecond-timestamp.ts"],"names":[],"mappings":";;;AAAA,MAAa,oBAAoB;IASV;IARrB,MAAM,CAAC,WAAW,GAAG,IAAI,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,CAAC,IAAI,GAAG,IA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AO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;;AAtFH,oDAuFC","sourcesContent":["export class MicrosecondTimestamp {\n static MILLISECOND = new MicrosecondTimestamp(BigInt(1_000));\n static SECOND = this.MILLISECOND.mult(1000);\n static MINUTE = this.SECOND.mult(60);\n static HOUR = this.MINUTE.mult(60);\n static DAY = this.HOUR.mult(24);\n static WEEK = this.DAY.mult(7);\n static MONTH = this.DAY.mult(30);\n\n constructor(readonly micros: bigint) {}\n\n isAfter(other: MicrosecondTimestamp): boolean {\n return this.micros > other.micros;\n }\n\n equals(other: MicrosecondTimestamp): boolean {\n return this.micros === other.micros;\n }\n\n isBefore(other: MicrosecondTimestamp): boolean {\n return this.micros < other.micros;\n }\n\n add(micros: bigint | MicrosecondTimestamp): MicrosecondTimestamp {\n const value =\n micros instanceof MicrosecondTimestamp ? micros.micros : micros;\n return new MicrosecondTimestamp(this.micros + value);\n }\n\n sub(micros: bigint | MicrosecondTimestamp): MicrosecondTimestamp {\n const value =\n micros instanceof MicrosecondTimestamp ? micros.micros : micros;\n return new MicrosecondTimestamp(this.micros - value);\n }\n\n mult(factor: number): MicrosecondTimestamp {\n return new MicrosecondTimestamp(this.micros * BigInt(factor));\n }\n\n static now(): MicrosecondTimestamp {\n return new MicrosecondTimestamp(BigInt(Date.now()) * BigInt(1000));\n }\n\n static fromNanoseconds(nanoseconds: bigint): MicrosecondTimestamp {\n return new MicrosecondTimestamp(nanoseconds / BigInt(1000));\n }\n\n static fromMicroseconds(microseconds: bigint): MicrosecondTimestamp {\n return new MicrosecondTimestamp(microseconds);\n }\n\n static deserialize(\n serialized: Date | MicrosecondTimestamp | bigint,\n ): MicrosecondTimestamp {\n if (serialized instanceof MicrosecondTimestamp) {\n return serialized;\n }\n if (typeof serialized === \"bigint\") {\n return new MicrosecondTimestamp(serialized);\n }\n\n if (\n \"microseconds\" in serialized &&\n typeof serialized.microseconds === \"bigint\"\n ) {\n return new MicrosecondTimestamp(serialized.microseconds);\n }\n\n const micros = BigInt(serialized.getTime()) * BigInt(1000);\n return new MicrosecondTimestamp(micros);\n }\n\n serialize() {\n const date = new Date(Number(this.micros / BigInt(1000)));\n (date as any).microseconds = this.micros;\n return date;\n }\n\n static sort(left: MicrosecondTimestamp, right: MicrosecondTimestamp): number {\n if (left.isAfter(right)) {\n return 1;\n }\n if (left.isBefore(right)) {\n return -1;\n }\n return 0;\n }\n}\n"]}
|
package/dist/choice.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"choice.js","sourceRoot":"","sources":["../src/choice.ts"],"names":[],"mappings":";;;AAAA,0BAAsE;AAe/D,MAAM,MAAM,GAAG,CAIpB,MAAS,EACT,OAAU,QAAY,EACP,EAAE;IAGjB,MAAe,OAAQ,SAAS,IAA+B;QAM1C;QALnB,MAAM,CAAC,MAAM,GAAG,QAAiB,CAAC;QAElC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC;QACpB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAEvB,YAAmB,KAAqB;YACtC,KAAK,EAAE,CAAC;YADS,UAAK,GAAL,KAAK,CAAgB;QAExC,CAAC;QAED,EAAE,CACA,KAAQ;YAKR,OAAO,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC;QAC9B,CAAC;QAED,KAAK,CAA6B,OAAU;YAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,OAAO;gBAAE,OAAO,OAAO,EAAE,CAAC;YAC9B,OAAQ,OAA4B,CAAC,CAAC,EAAE,CAAC;QAC3C,CAAC;QAED,SAAS;YACP,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAED,MAAM,CAAC,WAAW,CAEhB,KAAa;YAEb,OAAO,IAAK,IAAY,CAAC,KAAY,CAAoB,CAAC;QAC5D,CAAC;QACD,MAAM,CAAC,YAAY,CAEjB,KAAa;YAEb,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,CAAC,UAAU,CAEf,KAAa;YAEb,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,CAAC,OAAO,CAAS;QAEvB;YACE,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;gBAC3B,IAAY,CAAC,MAAM,CAAC,GAAG;oBACtB,OAAO,IAAI,IAAI,CAAC,MAAa,CAAC,CAAC;gBACjC,CAAC,CAAC;YACJ,CAAC;QACH,CAAC;;IAGH,OAAO,OAAc,CAAC;AACxB,CAAC,CAAC;AArEW,QAAA,MAAM,UAqEjB;AAgCF,oCAAoC","sourcesContent":["import { AbstractConstructor, Empty, Expand, Constructor } from \"./_\";\n\nexport type ChoiceMatcher<S extends string[]> =\n | {\n [key in S[number]]: () => any;\n }\n | ({\n _: () => any;\n } & {\n [key in S[number]]?: () => any;\n });\n\nexport type ChoiceMatcherResult<M extends ChoiceMatcher<any>> =\n M[keyof M] extends () => infer R ? R : never;\n\nexport const Choice = <\n const S extends string[],\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n config: S,\n base: B = Empty as any,\n): IChoice<S, B> => {\n type Inline = S[number];\n\n abstract class $Choice extends (base as any as Constructor<{}>) {\n static $shape = \"choice\" as const;\n\n static $of = config;\n static values = config;\n\n constructor(public value: Expand<Inline>) {\n super();\n }\n\n is<T extends Inline>(\n value: T,\n ): this is Omit<this, \"value\" | \"serialize\"> & {\n value: T;\n serialize(): T;\n } {\n return this.value === value;\n }\n\n match<M extends ChoiceMatcher<S>>(matcher: M): ChoiceMatcherResult<M> {\n const handler = matcher[this.value];\n if (handler) return handler();\n return (matcher as { _: () => any })._();\n }\n\n serialize(): Inline {\n return this.value;\n }\n\n static deserialize<T extends typeof $Choice>(\n this: T,\n value: Inline,\n ): InstanceType<T> {\n return new (this as any)(value as any) as InstanceType<T>;\n }\n static $deserialize<T extends typeof $Choice>(\n this: T,\n value: Inline,\n ): Inline {\n return value;\n }\n static $serialize<T extends typeof $Choice>(\n this: T,\n value: Inline,\n ): Inline {\n return value;\n }\n\n static $inline: Inline;\n\n static {\n for (const choice of config) {\n (this as any)[choice] = function <T extends Constructor>(this: T) {\n return new this(choice as any);\n };\n }\n }\n }\n\n return $Choice as any;\n};\n\nexport type IChoice<\n S extends string[],\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"\"> & {\n $shape: \"choice\";\n $of: S;\n values: S;\n deserialize<T extends Constructor>(\n this: T,\n value: S[number],\n ): InstanceType<T>;\n $deserialize<T>(this: T, value: S[number]): S[number];\n $serialize<T>(this: T, value: S[number]): S[number];\n $inline: S[number];\n} & (abstract new (\n value: S[number],\n ) => InstanceType<B> & {\n value: S[number];\n is<TH, T extends S[number]>(\n this: TH,\n value: T,\n ): this is Omit<TH, \"serialize\" | \"value\"> & {\n value: T;\n serialize(): T;\n };\n match<M extends ChoiceMatcher<S>>(matcher: M): ChoiceMatcherResult<M>;\n serialize(): S[number];\n }) & {\n [K in S[number]]: <T extends Constructor>(this: T) => InstanceType<T>;\n };\n//# sourceMappingURL=choice.d.ts.map\n"]}
|