33*/
44
55"use strict" ;
6+ /** @import { ObjectDeserializerContext, ObjectSerializerContext } from "./ObjectMiddleware" */
67
7- /** @typedef {EXPECTED_FUNCTION } CacheAssoc */
8+ /** @typedef {ObjectSerializerContext<EXPECTED_ANY>["write"] } CacheAssoc */
89
910/**
1011 * Defines the shared type used by this module.
11- * @template T
12- * @typedef {WeakMap<CacheAssoc, ObjectStructure<T>> }
12+ * @type {WeakMap<CacheAssoc, ObjectStructure<PropertyKey>> }
1313 */
1414const cache = new WeakMap ( ) ;
1515
1616/**
1717 * Represents ObjectStructure.
18- * @template T
18+ * @template {PropertyKey} K
1919 */
2020class ObjectStructure {
2121 constructor ( ) {
22- /** @type {undefined | keyof T [] } */
22+ /** @type {undefined | K [] } */
2323 this . keys = undefined ;
24- /** @type {undefined | Map<keyof T , ObjectStructure<T >> } */
24+ /** @type {undefined | Map<K , ObjectStructure<K >> } */
2525 this . children = undefined ;
2626 }
2727
2828 /**
2929 * Returns keys.
30- * @param {keyof T [] } keys keys
31- * @returns {keyof T [] } keys
30+ * @param {K [] } keys keys
31+ * @returns {K [] } keys
3232 */
3333 getKeys ( keys ) {
3434 if ( this . keys === undefined ) this . keys = keys ;
@@ -37,13 +37,14 @@ class ObjectStructure {
3737
3838 /**
3939 * Returns object structure.
40- * @param {keyof T } key key
41- * @returns {ObjectStructure<T > } object structure
40+ * @param {K } key key
41+ * @returns {ObjectStructure<K > } object structure
4242 */
4343 key ( key ) {
4444 if ( this . children === undefined ) this . children = new Map ( ) ;
4545 const child = this . children . get ( key ) ;
4646 if ( child !== undefined ) return child ;
47+ /** @type {ObjectStructure<K> } */
4748 const newChild = new ObjectStructure ( ) ;
4849 this . children . set ( key , newChild ) ;
4950 return newChild ;
@@ -52,13 +53,15 @@ class ObjectStructure {
5253
5354/**
5455 * Returns keys.
55- * @template T
56- * @param {(keyof T) [] } keys keys
56+ * @template {PropertyKey} K
57+ * @param {K [] } keys keys
5758 * @param {CacheAssoc } cacheAssoc cache assoc fn
58- * @returns {(keyof T) [] } keys
59+ * @returns {K [] } keys
5960 */
6061const getCachedKeys = ( keys , cacheAssoc ) => {
61- let root = cache . get ( cacheAssoc ) ;
62+ let root = /** @type {ObjectStructure<K> | undefined } */ (
63+ cache . get ( cacheAssoc )
64+ ) ;
6265 if ( root === undefined ) {
6366 root = new ObjectStructure ( ) ;
6467 cache . set ( cacheAssoc , root ) ;
@@ -75,7 +78,7 @@ class PlainObjectSerializer {
7578 * Serializes this instance into the provided serializer context.
7679 * @template {object} T
7780 * @param {T } obj plain object
78- * @param {import("./ObjectMiddleware"). ObjectSerializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]> } context context
81+ * @param {ObjectSerializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]> } context context
7982 */
8083 serialize ( obj , context ) {
8184 const keys = /** @type {(keyof T)[] } */ ( Object . keys ( obj ) ) ;
@@ -103,7 +106,7 @@ class PlainObjectSerializer {
103106 /**
104107 * Restores this instance from the provided deserializer context.
105108 * @template {object} T
106- * @param {import("./ObjectMiddleware"). ObjectDeserializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]> } context context
109+ * @param {ObjectDeserializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]> } context context
107110 * @returns {T } plain object
108111 */
109112 deserialize ( context ) {
0 commit comments