@tsed/core 8.33.0 → 8.35.0

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/lib/esm/index.js CHANGED
@@ -62,6 +62,7 @@ export * from "./utils/isSerializable.js";
62
62
  export * from "./utils/isStream.js";
63
63
  export * from "./utils/isString.js";
64
64
  export * from "./utils/isSymbol.js";
65
+ export * from "./utils/isTemporal.js";
65
66
  export * from "./utils/methodsOf.js";
66
67
  export * from "./utils/nameOf.js";
67
68
  export * from "./utils/objectKeys.js";
@@ -1,11 +1,11 @@
1
+ import { DecoratorTypes } from "./DecoratorTypes.js";
2
+ import { Metadata } from "./Metadata.js";
1
3
  import { decoratorTypeOf } from "../utils/decoratorTypeOf.js";
2
4
  import { deepClone } from "../utils/deepClone.js";
3
5
  import { deepMerge } from "../utils/deepMerge.js";
4
6
  import { descriptorOf } from "../utils/descriptorOf.js";
5
7
  import { isSymbol } from "../utils/isSymbol.js";
6
8
  import { nameOf } from "../utils/nameOf.js";
7
- import { DecoratorTypes } from "./DecoratorTypes.js";
8
- import { Metadata } from "./Metadata.js";
9
9
  /**
10
10
  * Metadata key used to reference the class-level store.
11
11
  * @ignore
@@ -1,5 +1,5 @@
1
- import { getInheritedClass } from "./ancestorOf.js";
2
1
  import { classOf } from "./classOf.js";
2
+ import { getInheritedClass } from "./ancestorOf.js";
3
3
  import { nameOf } from "./nameOf.js";
4
4
  /**
5
5
  * Returns all ancestor classes in the prototype chain of the target.
@@ -1,11 +1,12 @@
1
1
  import { isArrayOrArrayClass } from "./isArray.js";
2
2
  import { isArrowFn } from "./isArrowFn.js";
3
3
  import { isBuffer } from "./isBuffer.js";
4
- import { isDate } from "./isDate.js";
5
4
  import { isClassObject } from "./isPlainObject.js";
5
+ import { isDate } from "./isDate.js";
6
6
  import { isPrimitiveOrPrimitiveClass } from "./isPrimitive.js";
7
7
  import { isPromise } from "./isPromise.js";
8
8
  import { isSymbol } from "./isSymbol.js";
9
+ import { isTemporal } from "./isTemporal.js";
9
10
  /**
10
11
  * Determines whether a given value represents a class (constructor function).
11
12
  *
@@ -26,6 +27,7 @@ export function isClass(target) {
26
27
  isPrimitiveOrPrimitiveClass(target) ||
27
28
  isClassObject(target) ||
28
29
  isDate(target) ||
30
+ isTemporal(target) ||
29
31
  isPromise(target) ||
30
32
  isArrayOrArrayClass(target) ||
31
33
  isBuffer(target));
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Names of the `Temporal.*` types that serialize to/from an ISO-8601 string. Kept in sync with
3
+ * the `TemporalMapper` registered by `@tsed/json-mapper`.
4
+ */
5
+ const TEMPORAL_TYPE_NAMES = [
6
+ "Instant",
7
+ "ZonedDateTime",
8
+ "PlainDate",
9
+ "PlainDateTime",
10
+ "PlainTime",
11
+ "PlainYearMonth",
12
+ "PlainMonthDay",
13
+ "Duration"
14
+ ];
15
+ /**
16
+ * Checks if a value is a `Temporal.*` constructor (e.g. `Temporal.Instant`) or an instance of one.
17
+ *
18
+ * Like {@link isDate}, these types map to a JSON schema `string`: every `Temporal.*` type exposes a
19
+ * static `from(string)` factory and an ISO-8601 `toString()`. The global `Temporal` object is
20
+ * absent on older runtimes (Node < 24), so the check is guarded and returns `false` there.
21
+ *
22
+ * @public
23
+ * @since v8.34.0
24
+ */
25
+ export function isTemporal(target) {
26
+ const Temporal = globalThis.Temporal;
27
+ if (!target || !Temporal) {
28
+ return false;
29
+ }
30
+ return TEMPORAL_TYPE_NAMES.some((name) => {
31
+ const ctor = Temporal[name];
32
+ return !!ctor && (target === ctor || target instanceof ctor);
33
+ });
34
+ }
@@ -62,6 +62,7 @@ export * from "./utils/isSerializable.js";
62
62
  export * from "./utils/isStream.js";
63
63
  export * from "./utils/isString.js";
64
64
  export * from "./utils/isSymbol.js";
65
+ export * from "./utils/isTemporal.js";
65
66
  export * from "./utils/methodsOf.js";
66
67
  export * from "./utils/nameOf.js";
67
68
  export * from "./utils/objectKeys.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks if a value is a `Temporal.*` constructor (e.g. `Temporal.Instant`) or an instance of one.
3
+ *
4
+ * Like {@link isDate}, these types map to a JSON schema `string`: every `Temporal.*` type exposes a
5
+ * static `from(string)` factory and an ISO-8601 `toString()`. The global `Temporal` object is
6
+ * absent on older runtimes (Node < 24), so the check is guarded and returns `false` there.
7
+ *
8
+ * @public
9
+ * @since v8.34.0
10
+ */
11
+ export declare function isTemporal(target: any): boolean;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tsed/core",
3
+ "version": "8.35.0",
3
4
  "description": "Core module for Ts.ED Framework",
4
- "type": "module",
5
- "version": "8.33.0",
6
5
  "source": "./src/index.ts",
6
+ "type": "module",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
@@ -39,10 +39,11 @@
39
39
  "tslib": ">=2.7.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@tsed/barrels": "8.33.0",
42
+ "@tsed/barrels": "8.35.0",
43
43
  "@tsed/monorepo-utils": "3.0.0",
44
- "@tsed/typescript": "8.33.0",
45
- "@tsed/vitest": "8.33.0",
44
+ "@tsed/typescript": "8.35.0",
45
+ "@tsed/vitest": "8.35.0",
46
+ "temporal-polyfill": "1.0.1",
46
47
  "typescript": "6.0.2",
47
48
  "vitest": "4.1.4"
48
49
  },
@@ -0,0 +1,6 @@
1
+ import {Temporal} from "temporal-polyfill";
2
+
3
+ // Provide the global `Temporal` on runtimes that don't ship it natively yet (e.g. Node < 24),
4
+ // so the `isTemporal` specs run in CI instead of throwing. Native `Temporal` (Node >= 24/26) takes
5
+ // precedence and the polyfill is a no-op there.
6
+ (globalThis as {Temporal?: unknown}).Temporal ??= Temporal;