serialize(obj, context) {
		const ctx = { ...context, ...this.context };
		let current = obj;
		for (const middleware of this.serializeMiddlewares) {
			if (
				current &&
				typeof (/** @type {Promise<DeserializedValue>} */ (current).then) ===
					"function"
			) {
				current =
					/** @type {Promise<DeserializedValue>} */
					(current).then(data => data && middleware.serialize(data, ctx));
			} else if (current) {
				try {
					current = middleware.serialize(current, ctx);
				} catch (err) {
					current = Promise.reject(err);
				}
			} else break;
		}
		return /** @type {Promise<SerializedValue>} */ (current);
	}
@template ExtendedContext
@param {DeserializedValue | Promise<DeserializedValue>} obj object
@param {Context & ExtendedContext} context context object
@returns {Promise<SerializedValue>} result