@nmtjs/type 0.15.0-beta.51 → 0.15.0-beta.53
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/dist/temporal/global.d.ts +2 -2
- package/dist/temporal/global.js +9 -9
- package/dist/temporal/global.js.map +1 -1
- package/dist/temporal/index.d.ts +9 -0
- package/dist/temporal/index.js +10 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/polyfill.d.ts +10 -8
- package/dist/temporal/polyfill.js +25 -8
- package/dist/temporal/polyfill.js.map +1 -1
- package/dist/types/temporal.d.ts +17 -15
- package/dist/types/temporal.js +20 -10
- package/dist/types/temporal.js.map +1 -1
- package/package.json +12 -8
- package/src/temporal/global.ts +12 -9
- package/src/temporal/index.ts +20 -0
- package/src/temporal/polyfill.ts +60 -7
- package/src/types/temporal.ts +82 -61
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import 'temporal
|
|
2
|
-
import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from '../types/temporal.ts';
|
|
1
|
+
import { DurationType, InstantType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from '../types/temporal.ts';
|
|
3
2
|
export declare const plainDate: () => PlainDateType;
|
|
4
3
|
export declare const plainDatetime: () => PlainDateTimeType;
|
|
5
4
|
export declare const plainTime: () => PlainTimeType;
|
|
6
5
|
export declare const zonedDatetime: () => ZonedDateTimeType;
|
|
6
|
+
export declare const instant: () => InstantType;
|
|
7
7
|
export declare const duration: () => DurationType;
|
|
8
8
|
export declare const plainYearMonth: () => PlainYearMonthType;
|
|
9
9
|
export declare const plainMonthDay: () => PlainMonthDayType;
|
package/dist/temporal/global.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import 'temporal
|
|
2
|
-
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const duration = DurationType.factory.bind(DurationType, Temporal);
|
|
8
|
-
export const plainYearMonth = PlainYearMonthType.factory.bind(PlainYearMonthType, Temporal);
|
|
9
|
-
export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType, Temporal);
|
|
1
|
+
import { DurationType, InstantType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, } from '../types/temporal.js';
|
|
2
|
+
export const plainDate = PlainDateType.factory.bind(PlainDateType, globalThis.Temporal);
|
|
3
|
+
export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType, globalThis.Temporal);
|
|
4
|
+
export const plainTime = PlainTimeType.factory.bind(PlainTimeType, globalThis.Temporal);
|
|
5
|
+
export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType, globalThis.Temporal);
|
|
6
|
+
export const instant = InstantType.factory.bind(InstantType, globalThis.Temporal);
|
|
7
|
+
export const duration = DurationType.factory.bind(DurationType, globalThis.Temporal);
|
|
8
|
+
export const plainYearMonth = PlainYearMonthType.factory.bind(PlainYearMonthType, globalThis.Temporal);
|
|
9
|
+
export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType, globalThis.Temporal);
|
|
10
10
|
//# sourceMappingURL=global.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/temporal/global.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/temporal/global.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sBAAsB,CAAA;AAE7B,MAAM,CAAC,MAAM,SAAS,GAAwB,aAAa,CAAC,OAAO,CAAC,IAAI,CACtE,aAAa,EACb,UAAU,CAAC,QAAQ,CACpB,CAAA;AACD,MAAM,CAAC,MAAM,aAAa,GACxB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;AACxE,MAAM,CAAC,MAAM,SAAS,GAAwB,aAAa,CAAC,OAAO,CAAC,IAAI,CACtE,aAAa,EACb,UAAU,CAAC,QAAQ,CACpB,CAAA;AACD,MAAM,CAAC,MAAM,aAAa,GACxB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;AACxE,MAAM,CAAC,MAAM,OAAO,GAAsB,WAAW,CAAC,OAAO,CAAC,IAAI,CAChE,WAAW,EACX,UAAU,CAAC,QAAQ,CACpB,CAAA;AACD,MAAM,CAAC,MAAM,QAAQ,GAAuB,YAAY,CAAC,OAAO,CAAC,IAAI,CACnE,YAAY,EACZ,UAAU,CAAC,QAAQ,CACpB,CAAA;AACD,MAAM,CAAC,MAAM,cAAc,GACzB,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;AAC1E,MAAM,CAAC,MAAM,aAAa,GACxB,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DurationType, InstantType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from '../types/temporal.ts';
|
|
2
|
+
export declare const plainDate: typeof PlainDateType.factory;
|
|
3
|
+
export declare const plainDatetime: typeof PlainDateTimeType.factory;
|
|
4
|
+
export declare const plainTime: typeof PlainTimeType.factory;
|
|
5
|
+
export declare const zonedDatetime: typeof ZonedDateTimeType.factory;
|
|
6
|
+
export declare const instant: typeof InstantType.factory;
|
|
7
|
+
export declare const duration: typeof DurationType.factory;
|
|
8
|
+
export declare const plainYearMonth: typeof PlainYearMonthType.factory;
|
|
9
|
+
export declare const plainMonthDay: typeof PlainMonthDayType.factory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DurationType, InstantType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, } from '../types/temporal.js';
|
|
2
|
+
export const plainDate = PlainDateType.factory.bind(PlainDateType);
|
|
3
|
+
export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType);
|
|
4
|
+
export const plainTime = PlainTimeType.factory.bind(PlainTimeType);
|
|
5
|
+
export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType);
|
|
6
|
+
export const instant = InstantType.factory.bind(InstantType);
|
|
7
|
+
export const duration = DurationType.factory.bind(DurationType);
|
|
8
|
+
export const plainYearMonth = PlainYearMonthType.factory.bind(PlainYearMonthType);
|
|
9
|
+
export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType);
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/temporal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,sBAAsB,CAAA;AAE7B,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;AAClE,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;AAC9E,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;AAClE,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;AAC9E,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;AAC5D,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;AAC/D,MAAM,CAAC,MAAM,cAAc,GACzB,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
1
|
+
import { Temporal } from 'temporal-polyfill';
|
|
2
|
+
import { DurationType, InstantType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType } from '../types/temporal.ts';
|
|
3
|
+
export declare const plainDate: () => PlainDateType<typeof Temporal>;
|
|
4
|
+
export declare const plainDatetime: () => PlainDateTimeType<typeof Temporal>;
|
|
5
|
+
export declare const plainTime: () => PlainTimeType<typeof Temporal>;
|
|
6
|
+
export declare const zonedDatetime: () => ZonedDateTimeType<typeof Temporal>;
|
|
7
|
+
export declare const instant: () => InstantType<typeof Temporal>;
|
|
8
|
+
export declare const duration: () => DurationType<typeof Temporal>;
|
|
9
|
+
export declare const plainYearMonth: () => PlainYearMonthType<typeof Temporal>;
|
|
10
|
+
export declare const plainMonthDay: () => PlainMonthDayType<typeof Temporal>;
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { Temporal } from 'temporal-polyfill';
|
|
2
|
-
import { DurationType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, } from '../types/temporal.js';
|
|
3
|
-
export const plainDate = PlainDateType.factory.bind(PlainDateType,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const
|
|
2
|
+
import { DurationType, InstantType, PlainDateTimeType, PlainDateType, PlainMonthDayType, PlainTimeType, PlainYearMonthType, ZonedDateTimeType, } from '../types/temporal.js';
|
|
3
|
+
export const plainDate = PlainDateType.factory.bind(PlainDateType,
|
|
4
|
+
// @ts-expect-error
|
|
5
|
+
Temporal);
|
|
6
|
+
export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType,
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
Temporal);
|
|
9
|
+
export const plainTime = PlainTimeType.factory.bind(PlainTimeType,
|
|
10
|
+
// @ts-expect-error
|
|
11
|
+
Temporal);
|
|
12
|
+
export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType,
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
Temporal);
|
|
15
|
+
export const instant = InstantType.factory.bind(InstantType,
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
Temporal);
|
|
18
|
+
export const duration = DurationType.factory.bind(DurationType,
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
Temporal);
|
|
21
|
+
export const plainYearMonth = PlainYearMonthType.factory.bind(PlainYearMonthType,
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
Temporal);
|
|
24
|
+
export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType,
|
|
25
|
+
// @ts-expect-error
|
|
26
|
+
Temporal);
|
|
10
27
|
//# sourceMappingURL=polyfill.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/temporal/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,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,IAAI,CAC3D,kBAAkB;AAClB,mBAAmB;AACnB,QAAQ,CAIT,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,IAAI,CACzD,iBAAiB;AACjB,mBAAmB;AACnB,QAAQ,CAIT,CAAA"}
|
package/dist/types/temporal.d.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import type { Temporal } from 'temporal-spec';
|
|
2
1
|
import type { ZodMiniString } from 'zod/mini';
|
|
3
2
|
import { TransformType } from './custom.ts';
|
|
4
3
|
type EncodeType = ZodMiniString<string>;
|
|
5
|
-
export declare class PlainDateType extends TransformType<
|
|
6
|
-
static factory(implementation:
|
|
4
|
+
export declare class PlainDateType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['PlainDate']>, EncodeType> {
|
|
5
|
+
static factory<T extends typeof Temporal>(implementation: T): PlainDateType<T>;
|
|
7
6
|
}
|
|
8
|
-
export declare class PlainDateTimeType extends TransformType<
|
|
9
|
-
static factory(implementation:
|
|
7
|
+
export declare class PlainDateTimeType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['PlainDateTime']>, EncodeType> {
|
|
8
|
+
static factory<T extends typeof Temporal>(implementation: T): PlainDateTimeType<T>;
|
|
10
9
|
}
|
|
11
|
-
export declare class ZonedDateTimeType extends TransformType<
|
|
12
|
-
static factory(implementation:
|
|
10
|
+
export declare class ZonedDateTimeType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['ZonedDateTime']>, EncodeType> {
|
|
11
|
+
static factory<T extends typeof Temporal>(implementation: T): ZonedDateTimeType<T>;
|
|
13
12
|
}
|
|
14
|
-
export declare class
|
|
15
|
-
static factory(implementation:
|
|
13
|
+
export declare class InstantType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['Instant']>, EncodeType> {
|
|
14
|
+
static factory<T extends typeof Temporal>(implementation: T): InstantType<T>;
|
|
16
15
|
}
|
|
17
|
-
export declare class
|
|
18
|
-
static factory(implementation:
|
|
16
|
+
export declare class PlainTimeType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['PlainTime']>, EncodeType> {
|
|
17
|
+
static factory<T extends typeof Temporal>(implementation: T): PlainTimeType<T>;
|
|
19
18
|
}
|
|
20
|
-
export declare class
|
|
21
|
-
static factory(implementation:
|
|
19
|
+
export declare class DurationType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['Duration']>, EncodeType> {
|
|
20
|
+
static factory<T extends typeof Temporal>(implementation: T): DurationType<T>;
|
|
22
21
|
}
|
|
23
|
-
export declare class
|
|
24
|
-
static factory(implementation:
|
|
22
|
+
export declare class PlainYearMonthType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['PlainYearMonth']>, EncodeType> {
|
|
23
|
+
static factory<T extends typeof Temporal>(implementation: T): PlainYearMonthType<T>;
|
|
24
|
+
}
|
|
25
|
+
export declare class PlainMonthDayType<T extends typeof Temporal = typeof Temporal> extends TransformType<InstanceType<T['PlainMonthDay']>, EncodeType> {
|
|
26
|
+
static factory<T extends typeof Temporal>(implementation: T): PlainMonthDayType<T>;
|
|
25
27
|
}
|
|
26
28
|
export {};
|
package/dist/types/temporal.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { iso, regex, string } from 'zod/mini';
|
|
2
2
|
import { CustomType, TransformType } from './custom.js';
|
|
3
|
-
const createTemporalTransformer = (implementation, type, decode = (value) =>
|
|
3
|
+
const createTemporalTransformer = (implementation, type, decode = (value) => {
|
|
4
|
+
if (typeof value === 'string')
|
|
5
|
+
return implementation[type].from(value);
|
|
6
|
+
else
|
|
7
|
+
return value;
|
|
8
|
+
}, encode = (value) => value.toString({
|
|
4
9
|
calendarName: 'never',
|
|
5
10
|
smallestUnit: 'microsecond',
|
|
6
11
|
timeZoneName: 'never',
|
|
@@ -31,19 +36,24 @@ export class PlainDateTimeType extends TransformType {
|
|
|
31
36
|
}
|
|
32
37
|
export class ZonedDateTimeType extends TransformType {
|
|
33
38
|
static factory(implementation) {
|
|
34
|
-
const transformer = createTemporalTransformer(implementation, 'ZonedDateTime', (value) => implementation.
|
|
35
|
-
.withTimeZone('UTC')
|
|
36
|
-
.toString({
|
|
37
|
-
smallestUnit: 'milliseconds',
|
|
38
|
-
timeZoneName: 'never',
|
|
39
|
-
calendarName: 'never',
|
|
40
|
-
offset: 'never',
|
|
41
|
-
}) + 'Z');
|
|
39
|
+
const transformer = createTemporalTransformer(implementation, 'ZonedDateTime', (value) => implementation.ZonedDateTime.from(value), (value) => value.toString({ smallestUnit: 'microsecond' }));
|
|
42
40
|
return CustomType.factory({
|
|
43
41
|
decode: transformer.decode,
|
|
44
42
|
encode: transformer.encode,
|
|
43
|
+
type: string(),
|
|
44
|
+
error: 'Invalid zoned datetime format',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class InstantType extends TransformType {
|
|
49
|
+
static factory(implementation) {
|
|
50
|
+
const decode = (value) => implementation.Instant.from(value);
|
|
51
|
+
const encode = (value) => value.toJSON();
|
|
52
|
+
return CustomType.factory({
|
|
53
|
+
decode,
|
|
54
|
+
encode,
|
|
45
55
|
type: iso.datetime(),
|
|
46
|
-
error: 'Invalid
|
|
56
|
+
error: 'Invalid instant format',
|
|
47
57
|
});
|
|
48
58
|
}
|
|
49
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/types/temporal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"temporal.js","sourceRoot":"","sources":["../../src/types/temporal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAYvD,MAAM,yBAAyB,GAAG,CAChC,cAAiB,EACjB,IAAO,EACP,MAAM,GAAG,C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}
|
package/package.json
CHANGED
|
@@ -20,36 +20,40 @@
|
|
|
20
20
|
"module-sync": "./dist/types/*.js"
|
|
21
21
|
},
|
|
22
22
|
"./temporal": {
|
|
23
|
+
"types": "./dist/temporal/index.d.ts",
|
|
24
|
+
"import": "./dist/temporal/index.js",
|
|
25
|
+
"module-sync": "./dist/temporal/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./temporal/global": {
|
|
23
28
|
"types": "./dist/temporal/global.d.ts",
|
|
24
29
|
"import": "./dist/temporal/global.js",
|
|
25
30
|
"module-sync": "./dist/temporal/global.js"
|
|
26
31
|
},
|
|
27
|
-
"./temporal
|
|
32
|
+
"./temporal/polyfill": {
|
|
28
33
|
"types": "./dist/temporal/polyfill.d.ts",
|
|
29
34
|
"import": "./dist/temporal/polyfill.js",
|
|
30
35
|
"module-sync": "./dist/temporal/polyfill.js"
|
|
31
36
|
}
|
|
32
37
|
},
|
|
33
38
|
"dependencies": {
|
|
34
|
-
"@standard-schema/spec": "^1.1.0"
|
|
35
|
-
"temporal-spec": "^0.3.0"
|
|
39
|
+
"@standard-schema/spec": "^1.1.0"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
|
-
"temporal-polyfill": "^0.3.
|
|
42
|
+
"temporal-polyfill": "^0.3.2",
|
|
39
43
|
"zod": "^4.3.5",
|
|
40
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
44
|
+
"@nmtjs/common": "0.15.0-beta.53"
|
|
41
45
|
},
|
|
42
46
|
"devDependencies": {
|
|
43
|
-
"temporal-polyfill": "^0.3.
|
|
47
|
+
"temporal-polyfill": "^0.3.2",
|
|
44
48
|
"zod": "^4.3.5",
|
|
45
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
49
|
+
"@nmtjs/common": "0.15.0-beta.53"
|
|
46
50
|
},
|
|
47
51
|
"peerDependenciesMeta": {
|
|
48
52
|
"temporal-polyfill": {
|
|
49
53
|
"optional": true
|
|
50
54
|
}
|
|
51
55
|
},
|
|
52
|
-
"version": "0.15.0-beta.
|
|
56
|
+
"version": "0.15.0-beta.53",
|
|
53
57
|
"scripts": {
|
|
54
58
|
"clean-build": "rm -rf ./dist"
|
|
55
59
|
}
|
package/src/temporal/global.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import 'temporal-spec/global'
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
DurationType,
|
|
3
|
+
InstantType,
|
|
5
4
|
PlainDateTimeType,
|
|
6
5
|
PlainDateType,
|
|
7
6
|
PlainMonthDayType,
|
|
@@ -12,21 +11,25 @@ import {
|
|
|
12
11
|
|
|
13
12
|
export const plainDate: () => PlainDateType = PlainDateType.factory.bind(
|
|
14
13
|
PlainDateType,
|
|
15
|
-
Temporal,
|
|
14
|
+
globalThis.Temporal,
|
|
16
15
|
)
|
|
17
16
|
export const plainDatetime: () => PlainDateTimeType =
|
|
18
|
-
PlainDateTimeType.factory.bind(PlainDateTimeType, Temporal)
|
|
17
|
+
PlainDateTimeType.factory.bind(PlainDateTimeType, globalThis.Temporal)
|
|
19
18
|
export const plainTime: () => PlainTimeType = PlainTimeType.factory.bind(
|
|
20
19
|
PlainTimeType,
|
|
21
|
-
Temporal,
|
|
20
|
+
globalThis.Temporal,
|
|
22
21
|
)
|
|
23
22
|
export const zonedDatetime: () => ZonedDateTimeType =
|
|
24
|
-
ZonedDateTimeType.factory.bind(ZonedDateTimeType, Temporal)
|
|
23
|
+
ZonedDateTimeType.factory.bind(ZonedDateTimeType, globalThis.Temporal)
|
|
24
|
+
export const instant: () => InstantType = InstantType.factory.bind(
|
|
25
|
+
InstantType,
|
|
26
|
+
globalThis.Temporal,
|
|
27
|
+
)
|
|
25
28
|
export const duration: () => DurationType = DurationType.factory.bind(
|
|
26
29
|
DurationType,
|
|
27
|
-
Temporal,
|
|
30
|
+
globalThis.Temporal,
|
|
28
31
|
)
|
|
29
32
|
export const plainYearMonth: () => PlainYearMonthType =
|
|
30
|
-
PlainYearMonthType.factory.bind(PlainYearMonthType, Temporal)
|
|
33
|
+
PlainYearMonthType.factory.bind(PlainYearMonthType, globalThis.Temporal)
|
|
31
34
|
export const plainMonthDay: () => PlainMonthDayType =
|
|
32
|
-
PlainMonthDayType.factory.bind(PlainMonthDayType, Temporal)
|
|
35
|
+
PlainMonthDayType.factory.bind(PlainMonthDayType, globalThis.Temporal)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DurationType,
|
|
3
|
+
InstantType,
|
|
4
|
+
PlainDateTimeType,
|
|
5
|
+
PlainDateType,
|
|
6
|
+
PlainMonthDayType,
|
|
7
|
+
PlainTimeType,
|
|
8
|
+
PlainYearMonthType,
|
|
9
|
+
ZonedDateTimeType,
|
|
10
|
+
} from '../types/temporal.ts'
|
|
11
|
+
|
|
12
|
+
export const plainDate = PlainDateType.factory.bind(PlainDateType)
|
|
13
|
+
export const plainDatetime = PlainDateTimeType.factory.bind(PlainDateTimeType)
|
|
14
|
+
export const plainTime = PlainTimeType.factory.bind(PlainTimeType)
|
|
15
|
+
export const zonedDatetime = ZonedDateTimeType.factory.bind(ZonedDateTimeType)
|
|
16
|
+
export const instant = InstantType.factory.bind(InstantType)
|
|
17
|
+
export const duration = DurationType.factory.bind(DurationType)
|
|
18
|
+
export const plainYearMonth =
|
|
19
|
+
PlainYearMonthType.factory.bind(PlainYearMonthType)
|
|
20
|
+
export const plainMonthDay = PlainMonthDayType.factory.bind(PlainMonthDayType)
|
package/src/temporal/polyfill.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Temporal } from 'temporal-polyfill'
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
DurationType,
|
|
5
|
+
InstantType,
|
|
5
6
|
PlainDateTimeType,
|
|
6
7
|
PlainDateType,
|
|
7
8
|
PlainMonthDayType,
|
|
@@ -10,22 +11,74 @@ import {
|
|
|
10
11
|
ZonedDateTimeType,
|
|
11
12
|
} from '../types/temporal.ts'
|
|
12
13
|
|
|
13
|
-
export const plainDate = PlainDateType.factory.bind(
|
|
14
|
+
export const plainDate = PlainDateType.factory.bind(
|
|
15
|
+
PlainDateType,
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
Temporal,
|
|
18
|
+
) as () => PlainDateType<
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
typeof Temporal
|
|
21
|
+
>
|
|
22
|
+
|
|
14
23
|
export const plainDatetime = PlainDateTimeType.factory.bind(
|
|
15
24
|
PlainDateTimeType,
|
|
25
|
+
// @ts-expect-error
|
|
16
26
|
Temporal,
|
|
17
|
-
)
|
|
18
|
-
|
|
27
|
+
) as () => PlainDateTimeType<
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
typeof Temporal
|
|
30
|
+
>
|
|
31
|
+
|
|
32
|
+
export const plainTime = PlainTimeType.factory.bind(
|
|
33
|
+
PlainTimeType,
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
Temporal,
|
|
36
|
+
) as () => PlainTimeType<
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
typeof Temporal
|
|
39
|
+
>
|
|
40
|
+
|
|
19
41
|
export const zonedDatetime = ZonedDateTimeType.factory.bind(
|
|
20
42
|
ZonedDateTimeType,
|
|
43
|
+
// @ts-expect-error
|
|
21
44
|
Temporal,
|
|
22
|
-
)
|
|
23
|
-
|
|
45
|
+
) as () => ZonedDateTimeType<
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
typeof Temporal
|
|
48
|
+
>
|
|
49
|
+
|
|
50
|
+
export const instant = InstantType.factory.bind(
|
|
51
|
+
InstantType,
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
Temporal,
|
|
54
|
+
) as () => InstantType<
|
|
55
|
+
// @ts-expect-error
|
|
56
|
+
typeof Temporal
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export const duration = DurationType.factory.bind(
|
|
60
|
+
DurationType,
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
Temporal,
|
|
63
|
+
) as () => DurationType<
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
typeof Temporal
|
|
66
|
+
>
|
|
67
|
+
|
|
24
68
|
export const plainYearMonth = PlainYearMonthType.factory.bind(
|
|
25
69
|
PlainYearMonthType,
|
|
70
|
+
// @ts-expect-error
|
|
26
71
|
Temporal,
|
|
27
|
-
)
|
|
72
|
+
) as () => PlainYearMonthType<
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
typeof Temporal
|
|
75
|
+
>
|
|
76
|
+
|
|
28
77
|
export const plainMonthDay = PlainMonthDayType.factory.bind(
|
|
29
78
|
PlainMonthDayType,
|
|
79
|
+
// @ts-expect-error
|
|
30
80
|
Temporal,
|
|
31
|
-
)
|
|
81
|
+
) as () => PlainMonthDayType<
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
typeof Temporal
|
|
84
|
+
>
|
package/src/types/temporal.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Temporal } from 'temporal-spec'
|
|
2
1
|
import type { ZodMiniString } from 'zod/mini'
|
|
3
2
|
import { iso, regex, string } from 'zod/mini'
|
|
4
3
|
|
|
@@ -9,34 +8,38 @@ type Types = Exclude<
|
|
|
9
8
|
'Now' | 'Instant' | 'Calendar' | 'TimeZone'
|
|
10
9
|
>
|
|
11
10
|
|
|
12
|
-
type TemporalTransformer<T extends Types> = {
|
|
13
|
-
decode: (value: string) =>
|
|
14
|
-
encode: (value:
|
|
11
|
+
type TemporalTransformer<T extends typeof Temporal, U extends Types> = {
|
|
12
|
+
decode: (value: string) => InstanceType<T[U]>
|
|
13
|
+
encode: (value: InstanceType<T[U]>) => string
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
const createTemporalTransformer = <T extends Types>(
|
|
18
|
-
implementation:
|
|
19
|
-
type:
|
|
20
|
-
decode = (value: string
|
|
21
|
-
|
|
16
|
+
const createTemporalTransformer = <T extends typeof Temporal, U extends Types>(
|
|
17
|
+
implementation: T,
|
|
18
|
+
type: U,
|
|
19
|
+
decode = (value: string | InstanceType<T[U]>) => {
|
|
20
|
+
if (typeof value === 'string') return implementation[type].from(value)
|
|
21
|
+
else return value
|
|
22
|
+
},
|
|
23
|
+
encode = (value: ReturnType<T[U]['from']>) =>
|
|
22
24
|
value.toString({
|
|
23
25
|
calendarName: 'never',
|
|
24
26
|
smallestUnit: 'microsecond',
|
|
25
27
|
timeZoneName: 'never',
|
|
26
28
|
}),
|
|
27
29
|
) => {
|
|
28
|
-
return { decode, encode } as TemporalTransformer<T>
|
|
30
|
+
return { decode, encode } as TemporalTransformer<T, U>
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
type EncodeType = ZodMiniString<string>
|
|
32
34
|
|
|
33
|
-
export class PlainDateType
|
|
34
|
-
Temporal
|
|
35
|
-
|
|
36
|
-
>
|
|
37
|
-
|
|
35
|
+
export class PlainDateType<
|
|
36
|
+
T extends typeof Temporal = typeof Temporal,
|
|
37
|
+
> extends TransformType<InstanceType<T['PlainDate']>, EncodeType> {
|
|
38
|
+
static factory<T extends typeof Temporal>(
|
|
39
|
+
implementation: T,
|
|
40
|
+
): PlainDateType<T> {
|
|
38
41
|
const transformer = createTemporalTransformer(implementation, 'PlainDate')
|
|
39
|
-
return CustomType.factory<
|
|
42
|
+
return CustomType.factory<InstanceType<T['PlainDate']>, EncodeType>({
|
|
40
43
|
decode: transformer.decode,
|
|
41
44
|
encode: transformer.encode,
|
|
42
45
|
type: iso.date(),
|
|
@@ -45,16 +48,17 @@ export class PlainDateType extends TransformType<
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
export class PlainDateTimeType
|
|
49
|
-
Temporal
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
|
|
51
|
+
export class PlainDateTimeType<
|
|
52
|
+
T extends typeof Temporal = typeof Temporal,
|
|
53
|
+
> extends TransformType<InstanceType<T['PlainDateTime']>, EncodeType> {
|
|
54
|
+
static factory<T extends typeof Temporal>(
|
|
55
|
+
implementation: T,
|
|
56
|
+
): PlainDateTimeType<T> {
|
|
53
57
|
const transformer = createTemporalTransformer(
|
|
54
58
|
implementation,
|
|
55
59
|
'PlainDateTime',
|
|
56
60
|
)
|
|
57
|
-
return CustomType.factory<
|
|
61
|
+
return CustomType.factory<InstanceType<T['PlainDateTime']>, EncodeType>({
|
|
58
62
|
decode: transformer.decode,
|
|
59
63
|
encode: transformer.encode,
|
|
60
64
|
type: iso.datetime({ local: true }),
|
|
@@ -63,41 +67,52 @@ export class PlainDateTimeType extends TransformType<
|
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
|
|
66
|
-
export class ZonedDateTimeType
|
|
67
|
-
Temporal
|
|
68
|
-
|
|
69
|
-
>
|
|
70
|
-
|
|
70
|
+
export class ZonedDateTimeType<
|
|
71
|
+
T extends typeof Temporal = typeof Temporal,
|
|
72
|
+
> extends TransformType<InstanceType<T['ZonedDateTime']>, EncodeType> {
|
|
73
|
+
static factory<T extends typeof Temporal>(
|
|
74
|
+
implementation: T,
|
|
75
|
+
): ZonedDateTimeType<T> {
|
|
71
76
|
const transformer = createTemporalTransformer(
|
|
72
77
|
implementation,
|
|
73
78
|
'ZonedDateTime',
|
|
74
|
-
(value) => implementation.
|
|
75
|
-
(value) =>
|
|
76
|
-
value
|
|
77
|
-
.withTimeZone('UTC')
|
|
78
|
-
.toString({
|
|
79
|
-
smallestUnit: 'milliseconds',
|
|
80
|
-
timeZoneName: 'never',
|
|
81
|
-
calendarName: 'never',
|
|
82
|
-
offset: 'never',
|
|
83
|
-
}) + 'Z',
|
|
79
|
+
(value) => implementation.ZonedDateTime.from(value),
|
|
80
|
+
(value) => value.toString({ smallestUnit: 'microsecond' }),
|
|
84
81
|
)
|
|
85
|
-
return CustomType.factory<
|
|
82
|
+
return CustomType.factory<InstanceType<T['ZonedDateTime']>, EncodeType>({
|
|
86
83
|
decode: transformer.decode,
|
|
87
84
|
encode: transformer.encode,
|
|
88
|
-
type:
|
|
89
|
-
error: 'Invalid datetime format',
|
|
85
|
+
type: string(),
|
|
86
|
+
error: 'Invalid zoned datetime format',
|
|
90
87
|
})
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
export class
|
|
95
|
-
Temporal
|
|
96
|
-
|
|
97
|
-
> {
|
|
98
|
-
|
|
91
|
+
export class InstantType<
|
|
92
|
+
T extends typeof Temporal = typeof Temporal,
|
|
93
|
+
> extends TransformType<InstanceType<T['Instant']>, EncodeType> {
|
|
94
|
+
static factory<T extends typeof Temporal>(implementation: T): InstantType<T> {
|
|
95
|
+
const decode = (value: string) =>
|
|
96
|
+
implementation.Instant.from(value) as InstanceType<T['Instant']>
|
|
97
|
+
const encode = (value: InstanceType<T['Instant']>) => value.toJSON()
|
|
98
|
+
|
|
99
|
+
return CustomType.factory<InstanceType<T['Instant']>, EncodeType>({
|
|
100
|
+
decode,
|
|
101
|
+
encode,
|
|
102
|
+
type: iso.datetime(),
|
|
103
|
+
error: 'Invalid instant format',
|
|
104
|
+
}) as InstantType<T>
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class PlainTimeType<
|
|
109
|
+
T extends typeof Temporal = typeof Temporal,
|
|
110
|
+
> extends TransformType<InstanceType<T['PlainTime']>, EncodeType> {
|
|
111
|
+
static factory<T extends typeof Temporal>(
|
|
112
|
+
implementation: T,
|
|
113
|
+
): PlainTimeType<T> {
|
|
99
114
|
const transformer = createTemporalTransformer(implementation, 'PlainTime')
|
|
100
|
-
return CustomType.factory<
|
|
115
|
+
return CustomType.factory<InstanceType<T['PlainTime']>, EncodeType>({
|
|
101
116
|
decode: transformer.decode,
|
|
102
117
|
encode: transformer.encode,
|
|
103
118
|
type: iso.time(),
|
|
@@ -106,10 +121,14 @@ export class PlainTimeType extends TransformType<
|
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
123
|
|
|
109
|
-
export class DurationType
|
|
110
|
-
|
|
124
|
+
export class DurationType<
|
|
125
|
+
T extends typeof Temporal = typeof Temporal,
|
|
126
|
+
> extends TransformType<InstanceType<T['Duration']>, EncodeType> {
|
|
127
|
+
static factory<T extends typeof Temporal>(
|
|
128
|
+
implementation: T,
|
|
129
|
+
): DurationType<T> {
|
|
111
130
|
const transformer = createTemporalTransformer(implementation, 'Duration')
|
|
112
|
-
return CustomType.factory<
|
|
131
|
+
return CustomType.factory<InstanceType<T['Duration']>, EncodeType>({
|
|
113
132
|
decode: transformer.decode,
|
|
114
133
|
encode: transformer.encode,
|
|
115
134
|
type: iso.duration(),
|
|
@@ -118,16 +137,17 @@ export class DurationType extends TransformType<Temporal.Duration, EncodeType> {
|
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
139
|
|
|
121
|
-
export class PlainYearMonthType
|
|
122
|
-
Temporal
|
|
123
|
-
|
|
124
|
-
>
|
|
125
|
-
|
|
140
|
+
export class PlainYearMonthType<
|
|
141
|
+
T extends typeof Temporal = typeof Temporal,
|
|
142
|
+
> extends TransformType<InstanceType<T['PlainYearMonth']>, EncodeType> {
|
|
143
|
+
static factory<T extends typeof Temporal>(
|
|
144
|
+
implementation: T,
|
|
145
|
+
): PlainYearMonthType<T> {
|
|
126
146
|
const transformer = createTemporalTransformer(
|
|
127
147
|
implementation,
|
|
128
148
|
'PlainYearMonth',
|
|
129
149
|
)
|
|
130
|
-
return CustomType.factory<
|
|
150
|
+
return CustomType.factory<InstanceType<T['PlainYearMonth']>, EncodeType>({
|
|
131
151
|
decode: transformer.decode,
|
|
132
152
|
encode: transformer.encode,
|
|
133
153
|
type: string().check(regex(/^\d{4}-\d{2}$/)),
|
|
@@ -136,16 +156,17 @@ export class PlainYearMonthType extends TransformType<
|
|
|
136
156
|
}
|
|
137
157
|
}
|
|
138
158
|
|
|
139
|
-
export class PlainMonthDayType
|
|
140
|
-
Temporal
|
|
141
|
-
|
|
142
|
-
>
|
|
143
|
-
|
|
159
|
+
export class PlainMonthDayType<
|
|
160
|
+
T extends typeof Temporal = typeof Temporal,
|
|
161
|
+
> extends TransformType<InstanceType<T['PlainMonthDay']>, EncodeType> {
|
|
162
|
+
static factory<T extends typeof Temporal>(
|
|
163
|
+
implementation: T,
|
|
164
|
+
): PlainMonthDayType<T> {
|
|
144
165
|
const transformer = createTemporalTransformer(
|
|
145
166
|
implementation,
|
|
146
167
|
'PlainMonthDay',
|
|
147
168
|
)
|
|
148
|
-
return CustomType.factory<
|
|
169
|
+
return CustomType.factory<InstanceType<T['PlainMonthDay']>, EncodeType>({
|
|
149
170
|
decode: transformer.decode,
|
|
150
171
|
encode: transformer.encode,
|
|
151
172
|
type: string().check(regex(/^\d{2}-\d{2}$/)),
|