@nhtio/encoder 1.20251205.0 → 1.20260611.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/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { i as isObject, a as isArray, b as isSet, c as isMap, d as isLuxonSystemZone, e as isLuxonInterval, f as isLuxonDuration, g as isLuxonDateTime, D as DateTime, h as isPhoneObject, j as isTypedArray, k as isBigIntTypedArray, l as isPrimitive, m as isUniterableObject, n as isError, o as isBigInt, p as isNegativeZero, I as Info, q as Interval, r as Duration, P as Phone } from "./type_guards-BbzVmysZ.mjs";
1
+ import { i as isObject, a as isArray, b as isSet, c as isMap, d as isLuxonSystemZone, e as isLuxonInterval, f as isLuxonDuration, g as isLuxonDateTime, h as isPhoneObject, j as isTypedArray, k as isBigIntTypedArray, l as isPrimitive, m as isUniterableObject, n as isError, o as isBigInt, p as isUnsafeInteger, q as isNegativeInfinity, r as isPositiveInfinity, s as isNegativeZero, I as Info, t as Interval, D as DateTime, u as Duration, P as Phone } from "./type_guards-UkDoe__i.mjs";
2
2
  import { FunctionSerializer } from "./function_serializer.mjs";
3
- import { E as E_UNENCODABLE_VALUE, a as E_CIRCULAR_REFERENCE, b as E_ENCODING_FAILED, B as BaseException, c as E_UNDECODABLE_VALUE, d as E_NOT_AN_ENCODED_VALUE, e as E_INVALID_VERSION, f as E_INCOMPATIBLE_VERSION } from "./exceptions-B0rUZ1tH.mjs";
3
+ import { E as E_UNENCODABLE_VALUE, a as E_CIRCULAR_REFERENCE, b as E_ENCODING_FAILED, B as BaseException, c as E_UNDECODABLE_VALUE, d as E_NOT_AN_ENCODED_VALUE, e as E_INVALID_VERSION, f as E_INCOMPATIBLE_VERSION } from "./exceptions-WJOP87c3.mjs";
4
4
  var re = { exports: {} };
5
5
  var constants;
6
6
  var hasRequiredConstants;
@@ -2944,6 +2944,30 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
2944
2944
  _s: ""
2945
2945
  };
2946
2946
  }
2947
+ case isPositiveInfinity(value): {
2948
+ return {
2949
+ _t: "js:∞",
2950
+ _s: ""
2951
+ };
2952
+ }
2953
+ case isNegativeInfinity(value): {
2954
+ return {
2955
+ _t: "js:-∞",
2956
+ _s: ""
2957
+ };
2958
+ }
2959
+ case isUnsafeInteger(value): {
2960
+ return {
2961
+ _t: "js:unsafeInteger",
2962
+ _s: value.toString()
2963
+ };
2964
+ }
2965
+ case Number.isNaN(value): {
2966
+ return {
2967
+ _t: "js:NaN",
2968
+ _s: ""
2969
+ };
2970
+ }
2947
2971
  case isBigInt(value): {
2948
2972
  return {
2949
2973
  _t: "js:bigint",
@@ -2965,24 +2989,15 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
2965
2989
  throw new E_ENCODING_FAILED(value, e);
2966
2990
  }
2967
2991
  }
2968
- case isBigIntTypedArray(value): {
2969
- try {
2970
- return {
2971
- _t: `js:bigintTypedArray`,
2972
- _s: toStructuredData(serialize(value, { lossy: true, json: true }), seen)
2973
- };
2974
- } catch (e) {
2975
- if (e instanceof BaseException) {
2976
- throw e;
2977
- }
2978
- throw new E_ENCODING_FAILED(value, e);
2979
- }
2980
- }
2992
+ case isBigIntTypedArray(value):
2981
2993
  case isTypedArray(value): {
2982
2994
  try {
2983
2995
  return {
2984
- _t: `js:native`,
2985
- _s: serialize(value, { lossy: true, json: true })
2996
+ _t: `js:typedArray`,
2997
+ _s: toStructuredData({
2998
+ ctor: value.constructor.name,
2999
+ values: Array.from(value).map((v) => toStructuredData(v))
3000
+ })
2986
3001
  };
2987
3002
  } catch (e) {
2988
3003
  if (e instanceof BaseException) {
@@ -3010,14 +3025,12 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
3010
3025
  throw new E_CIRCULAR_REFERENCE();
3011
3026
  }
3012
3027
  seen.add(value);
3013
- const dto = value instanceof DateTime ? value : DateTime.fromObject(value.c, { zone: value.zone }).setLocale(
3014
- value.loc.locale
3015
- );
3028
+ const dto = value;
3016
3029
  return {
3017
3030
  _t: "luxon:DateTime",
3018
3031
  _s: toStructuredData(
3019
3032
  {
3020
- v: dto.toRFC2822(),
3033
+ v: dto.toMillis(),
3021
3034
  z: dto.zoneName,
3022
3035
  l: dto.locale,
3023
3036
  c: dto.outputCalendar,
@@ -3118,7 +3131,7 @@ const toStructuredData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
3118
3131
  seen.add(value);
3119
3132
  return {
3120
3133
  _t: "js:Array",
3121
- _s: btoa(JSON.stringify(value.map((item) => toStructuredData(item, seen))))
3134
+ _s: utoa(JSON.stringify(value.map((item) => toStructuredData(item, seen))))
3122
3135
  };
3123
3136
  }
3124
3137
  case isObject(value): {
@@ -3178,15 +3191,27 @@ const fromStructuredData = (data) => {
3178
3191
  });
3179
3192
  return set;
3180
3193
  }
3194
+ case "js:NaN": {
3195
+ return Number.NaN;
3196
+ }
3197
+ case "js:unsafeInteger": {
3198
+ return Number(data._s);
3199
+ }
3200
+ case "js:-∞": {
3201
+ return Number.NEGATIVE_INFINITY;
3202
+ }
3203
+ case "js:∞": {
3204
+ return Number.POSITIVE_INFINITY;
3205
+ }
3181
3206
  case "js:negativeZero": {
3182
3207
  return -0;
3183
3208
  }
3184
3209
  case "js:bigint": {
3185
3210
  return BigInt(data._s);
3186
3211
  }
3187
- case "js:bigintTypedArray": {
3188
- const deserialized = fromStructuredData(data._s);
3189
- return deserialize(deserialized);
3212
+ case "js:typedArray": {
3213
+ const { ctor, values } = fromStructuredData(data._s);
3214
+ return new globalThis[ctor](values.map(fromStructuredData));
3190
3215
  }
3191
3216
  case "js:native": {
3192
3217
  return deserialize(data._s);
@@ -3197,13 +3222,16 @@ const fromStructuredData = (data) => {
3197
3222
  }
3198
3223
  case "luxon:DateTime": {
3199
3224
  const obj = fromStructuredData(data._s);
3200
- return DateTime.fromRFC2822(obj.v, {
3201
- // setZone: true,
3225
+ const options2 = {
3202
3226
  zone: obj.z,
3203
3227
  locale: obj.l,
3204
3228
  outputCalendar: obj.c,
3205
3229
  numberingSystem: obj.n
3206
- });
3230
+ };
3231
+ if (typeof obj.v !== "number") {
3232
+ return DateTime.fromRFC2822(obj.v, options2);
3233
+ }
3234
+ return DateTime.fromMillis(obj.v, options2);
3207
3235
  }
3208
3236
  case "luxon:Duration": {
3209
3237
  const obj = fromStructuredData(data._s);
@@ -3240,11 +3268,11 @@ const { parse: $parse, stringify: $stringify } = JSON;
3240
3268
  const options = { json: true, lossy: true };
3241
3269
  const parse = (str) => deserialize($parse(str));
3242
3270
  const stringify = (any) => $stringify(serialize(any, options));
3243
- const version = "1.20251205.0";
3271
+ const version = "1.20260611.0";
3244
3272
  const encode = (what) => {
3245
3273
  const structured = toStructuredData(what);
3246
3274
  const serialized = serialize(structured, { lossy: true, json: true });
3247
- const json = stringify({ version: "1.20251205.0", serialized });
3275
+ const json = stringify({ version: "1.20260611.0", serialized });
3248
3276
  return utoa(json);
3249
3277
  };
3250
3278
  const decode = (base64) => {
@@ -3255,11 +3283,11 @@ const decode = (base64) => {
3255
3283
  throw new E_NOT_AN_ENCODED_VALUE(base64);
3256
3284
  }
3257
3285
  const { version: payloadVersion, serialized } = parsed;
3258
- if (semverExports.valid("1.20251205.0")) {
3286
+ if (semverExports.valid("1.20260611.0")) {
3259
3287
  if (!semverExports.valid(semverExports.coerce(payloadVersion))) {
3260
3288
  throw new E_INVALID_VERSION(payloadVersion);
3261
3289
  }
3262
- if (semverExports.gt(semverExports.coerce(payloadVersion), "1.20251205.0")) {
3290
+ if (semverExports.gt(semverExports.coerce(payloadVersion), "1.20260611.0")) {
3263
3291
  throw new E_INCOMPATIBLE_VERSION(payloadVersion);
3264
3292
  }
3265
3293
  }