diff --git a/src/client/ClientStateManager.js b/src/client/ClientStateManager.js index f2f1af85..eebb4949 100644 --- a/src/client/ClientStateManager.js +++ b/src/client/ClientStateManager.js @@ -3,15 +3,16 @@ import BaseStateManager from '../common/BaseStateManager.js'; /** * @callback ClientStateManager~ObserveCallback * @async - * @param {String} schemaName - name of the schema - * @param {Number} stateId - id of the state - * @param {Number} nodeId - id of the node that created the state + * @param {String} className - Name of the shared state class. + * @param {Number} stateId - Id of the state. + * @param {Number} nodeId - Id of the node that created the state. */ /** * The `ClientStateManager` allows to create new {@link SharedState}s, or attach - * to {@link SharedState}s created by other nodes (clients or server). It - * can also track all the {@link SharedState}s created by other nodes. + * to {@link SharedState}s created by other nodes (clients or server) on the network. + * + * It can also observe all the {@link SharedState}s created on the network. * * An instance of `ClientStateManager` is automatically created by the `soundworks.Client` * at initialization (cf. {@link client.Client#stateManager}). @@ -25,7 +26,7 @@ import BaseStateManager from '../common/BaseStateManager.js'; * import { Server } from '@soundworks/server/index.js'; * * const server = new Server(config); - * // declare and register the schema of a shared state. + * // define a class of shared state. * server.stateManager.registerSchema('some-global-state', { * myRandom: { * type: 'float', diff --git a/src/common/BaseStateManager.js b/src/common/BaseStateManager.js index 3fa5bca9..effdb733 100644 --- a/src/common/BaseStateManager.js +++ b/src/common/BaseStateManager.js @@ -33,7 +33,7 @@ export const kStateManagerClient = Symbol('soundworks:state-manager-client'); * * @callback stateManagerObserveCallback * @async - * @param {string} schemaName - name of the schema + * @param {string} className - name of the class * @param {number} stateId - id of the state * @param {number} nodeId - id of the node that created the state */ @@ -47,9 +47,9 @@ export const kStateManagerClient = Symbol('soundworks:state-manager-client'); /** @private */ class BaseStateManager { #statesById = new Map(); - #cachedSchemas = new Map(); // - #observeListeners = new Set(); // Set <[observedSchemaName, callback, options]> - #observeRequestCallbacks = new Map(); // Map + #cachedClasses = new Map(); // + #observeListeners = new Set(); // Set <[observedClassName, callback, options]> + #observeRequestCallbacks = new Map(); // Map #promiseStore = null; #status = 'idle'; @@ -61,10 +61,10 @@ class BaseStateManager { } /** @private */ - #filterObserve(observedSchemaName, schemaName, creatorId, options) { + #filterObserve(observedClassName, className, creatorId, options) { let filter = true; - // schema name filter filer - if (observedSchemaName === null || observedSchemaName === schemaName) { + + if (observedClassName === null || observedClassName === className) { filter = false; } // filter state created by client if excludeLocal is true @@ -95,19 +95,19 @@ class BaseStateManager { // --------------------------------------------- // CREATE // --------------------------------------------- - - this[kStateManagerClient].transport.addListener(CREATE_RESPONSE, (reqId, stateId, remoteId, schemaName, schema, initValues) => { - - // cache schema when first dealing it to save some bandwidth - if (!this.#cachedSchemas.has(schemaName)) { - this.#cachedSchemas.set(schemaName, schema); + this[kStateManagerClient].transport.addListener(CREATE_RESPONSE, (reqId, stateId, remoteId, className, classDescription, initValues) => { + // cache class description to save some bandwidth + // @note: when we make the class dynamic, we will need some mecanism to + // invalidate the cached description + if (!this.#cachedClasses.has(className)) { + this.#cachedClasses.set(className, classDescription); } - schema = this.#cachedSchemas.get(schemaName); + classDescription = this.#cachedClasses.get(className); - const state = new SharedState(stateId, remoteId, schemaName, schema, this[kStateManagerClient], true, this, initValues, null); - this.#statesById.set(state.id, state); + const state = new SharedState(stateId, remoteId, className, classDescription, this[kStateManagerClient], true, this, initValues, null); + this.#statesById.set(state.id, state); this.#promiseStore.resolve(reqId, state); }); @@ -118,20 +118,19 @@ class BaseStateManager { // --------------------------------------------- // ATTACH (when creator, is attached by default) // --------------------------------------------- - this[kStateManagerClient].transport.addListener(ATTACH_RESPONSE, (reqId, stateId, remoteId, schemaName, schema, currentValues, filter) => { - // cache schema when first dealing with it to save some bandwidth - // note: when we make the schemas dynamic at some point - // the server should be able to invalidate the schema and send - // it again despite the caching. - if (!this.#cachedSchemas.has(schemaName)) { - this.#cachedSchemas.set(schemaName, schema); + this[kStateManagerClient].transport.addListener(ATTACH_RESPONSE, (reqId, stateId, remoteId, className, classDescription, currentValues, filter) => { + // cache class description to save some bandwidth + // @note: when we make the class dynamic, we will need some mecanism to + // invalidate the cached description + if (!this.#cachedClasses.has(className)) { + this.#cachedClasses.set(className, classDescription); } - schema = this.#cachedSchemas.get(schemaName); + classDescription = this.#cachedClasses.get(className); - const state = new SharedState(stateId, remoteId, schemaName, schema, this[kStateManagerClient], false, this, currentValues, filter); - this.#statesById.set(state.id, state); + const state = new SharedState(stateId, remoteId, className, classDescription, this[kStateManagerClient], false, this, currentValues, filter); + this.#statesById.set(state.id, state); this.#promiseStore.resolve(reqId, state); }); @@ -143,20 +142,20 @@ class BaseStateManager { // OBSERVE PEERS (be notified when a state is created, lazy) // --------------------------------------------- this[kStateManagerClient].transport.addListener(OBSERVE_RESPONSE, async (reqId, ...list) => { - // retrieve the callback that have been stored in observe to make sure + // retrieve the callback that have been stored in `observe()` to make sure // we don't call another callback that may have been registered earlier. const observeInfos = this.#observeRequestCallbacks.get(reqId); - const [observedSchemaName, callback, options] = observeInfos; + const [observedClassName, callback, options] = observeInfos; // move observeInfos from `_observeRequestCallbacks` to `_observeListeners` - // to guarantee order of execution, @see not in `.observe` + // to guarantee future order of execution this.#observeRequestCallbacks.delete(reqId); this.#observeListeners.add(observeInfos); - const promises = list.map(([schemaName, stateId, nodeId]) => { - const filter = this.#filterObserve(observedSchemaName, schemaName, nodeId, options); + const promises = list.map(([className, stateId, nodeId]) => { + const filter = this.#filterObserve(observedClassName, className, nodeId, options); if (!filter) { - return callback(schemaName, stateId, nodeId); + return callback(className, stateId, nodeId); } else { return Promise.resolve(); } @@ -175,39 +174,39 @@ class BaseStateManager { this.#promiseStore.resolve(reqId, unsubscribe); }); - // Observe error can occur if observed schema name does not exists + // Observe error occur if observed class name does not exists this[kStateManagerClient].transport.addListener(OBSERVE_ERROR, (reqId, msg) => { this.#observeRequestCallbacks.delete(reqId); this.#promiseStore.reject(reqId, msg); }); - this[kStateManagerClient].transport.addListener(OBSERVE_NOTIFICATION, (schemaName, stateId, nodeId) => { + this[kStateManagerClient].transport.addListener(OBSERVE_NOTIFICATION, (className, stateId, nodeId) => { this.#observeListeners.forEach(observeInfos => { - const [observedSchemaName, callback, options] = observeInfos; - const filter = this.#filterObserve(observedSchemaName, schemaName, nodeId, options); + const [observedClassName, callback, options] = observeInfos; + const filter = this.#filterObserve(observedClassName, className, nodeId, options); if (!filter) { - callback(schemaName, stateId, nodeId); + callback(className, stateId, nodeId); } }); }); // --------------------------------------------- - // Clear cache when schema is deleted + // Clear cache when a shared state class is deleted // --------------------------------------------- - this[kStateManagerClient].transport.addListener(DELETE_SCHEMA, schemaName => { - this.#cachedSchemas.delete(schemaName); + this[kStateManagerClient].transport.addListener(DELETE_SCHEMA, className => { + this.#cachedClasses.delete(className); }); // --------------------------------------------- - // GET SCHEMA + // Get class description // --------------------------------------------- - this[kStateManagerClient].transport.addListener(GET_SCHEMA_RESPONSE, (reqId, schemaName, schema) => { - if (!this.#cachedSchemas.has(schemaName)) { - this.#cachedSchemas.set(schemaName, schema); + this[kStateManagerClient].transport.addListener(GET_SCHEMA_RESPONSE, (reqId, className, classDescription) => { + if (!this.#cachedClasses.has(className)) { + this.#cachedClasses.set(className, classDescription); } - // return a populated schema - const parameterBag = new ParameterBag(schema); + // return a full class description + const parameterBag = new ParameterBag(classDescription); this.#promiseStore.resolve(reqId, parameterBag.getDescription()); }); @@ -219,51 +218,50 @@ class BaseStateManager { } /** - * Return the schema from a given registered schema name + * Return a class description from a given class name * - * @param {SharedStateClassName} schemaName - Name of the schema as given on registration + * @param {SharedStateClassName} className - Name of the shared state class * (cf. ServerStateManager) * @return {SharedStateClassDescription} * @example - * const schema = await client.stateManager.getSchema('my-class'); + * const classDescription = await client.stateManager.getSchema('my-class'); */ - async getSchema(schemaName) { + async getSchema(className) { if (this.#status !== 'inited') { throw new DOMException(`Cannot execute 'getSchema' on 'StateManager': state manager is not inited. This method can be safely called only once 'client' or 'server' is inited itself`, 'InvalidStateError'); } - if (this.#cachedSchemas.has(schemaName)) { - const schema = this.#cachedSchemas.get(schemaName); - // return a populated schema - const parameterBag = new ParameterBag(schema); + if (this.#cachedClasses.has(className)) { + const classDescription = this.#cachedClasses.get(className); + // return a full class description + const parameterBag = new ParameterBag(classDescription); return parameterBag.getDescription(); } return new Promise((resolve, reject) => { const reqId = this.#promiseStore.add(resolve, reject, 'get-schema'); - this[kStateManagerClient].transport.emit(GET_SCHEMA_REQUEST, reqId, schemaName); + this[kStateManagerClient].transport.emit(GET_SCHEMA_REQUEST, reqId, className); }); } /** - * Create a {@link SharedState} instance from a registered schema. + * Create a {@link SharedState} instance from a registered class. * - * @param {string} schemaName - Name of the schema as given on registration - * (cf. ServerStateManager) - * @param {Object.} [initValues={}] - Default values for the state. + * @param {SharedStateClassName} className - Name of the class. + * @param {Object.} [initValues={}] - Default values of the created shared state. * @returns {Promise} * @example * const state = await client.stateManager.create('my-class'); */ - async create(schemaName, initValues = {}) { + async create(className, initValues = {}) { if (this.#status !== 'inited') { throw new DOMException(`Cannot execute 'create' on 'StateManager': state manager is not inited. This method can be safely called only once 'client' or 'server' is inited itself`, 'InvalidStateError'); } return new Promise((resolve, reject) => { const reqId = this.#promiseStore.add(resolve, reject, 'create-request'); - const requireSchema = this.#cachedSchemas.has(schemaName) ? false : true; - this[kStateManagerClient].transport.emit(CREATE_REQUEST, reqId, schemaName, requireSchema, initValues); + const requireDescription = this.#cachedClasses.has(className) ? false : true; + this[kStateManagerClient].transport.emit(CREATE_REQUEST, reqId, className, requireDescription, initValues); }); } @@ -271,7 +269,7 @@ class BaseStateManager { * Attach to an existing {@link SharedState} instance. * * @overload - * @param {string} schemaName + * @param {SharedStateClassName} className - Name of the class. * @returns {Promise} * * @example @@ -281,7 +279,7 @@ class BaseStateManager { * Attach to an existing {@link SharedState} instance. * * @overload - * @param {string} schemaName - Name of the schema + * @param {SharedStateClassName} className - Name of the class. * @param {number} stateId - Id of the state * @returns {Promise} * @@ -292,7 +290,7 @@ class BaseStateManager { * Attach to an existing {@link SharedState} instance. * * @overload - * @param {string} schemaName - Name of the schema + * @param {SharedStateClassName} className - Name of the class. * @param {string[]} filter - List of parameters of interest * @returns {Promise} * @@ -303,7 +301,7 @@ class BaseStateManager { * Attach to an existing {@link SharedState} instance. * * @overload - * @param {string} schemaName - Name of the schema + * @param {SharedStateClassName} className - Name of the class. * @param {number} stateId - Id of the state * @param {string[]} filter - List of parameters of interest * @returns {Promise} @@ -315,14 +313,14 @@ class BaseStateManager { * Attach to an existing {@link SharedState} instance. * * Alternative signatures: - * - `stateManager.attach(schemaName)` - * - `stateManager.attach(schemaName, stateId)` - * - `stateManager.attach(schemaName, filter)` - * - `stateManager.attach(schemaName, stateId, filter)` + * - `stateManager.attach(className)` + * - `stateManager.attach(className, stateId)` + * - `stateManager.attach(className, filter)` + * - `stateManager.attach(className, stateId, filter)` * - * @param {string} schemaName - Name of the schema as given on registration + * @param {SharedStateClassName} className - Name of the class. * @param {number|string[]} [stateIdOrFilter] - Id of the state to attach to. If `null`, - * attach to the first state found with the given schema name (usefull for + * attach to the first state found with the given class name (usefull for * globally shared states owned by the server). * @param {string[]} [filter] - List of parameters of interest in the * returned state. If set to `null`, no filter is applied. @@ -331,14 +329,14 @@ class BaseStateManager { * @example * const state = await client.stateManager.attach('my-class'); */ - async attach(schemaName, stateIdOrFilter = null, filter = null) { + async attach(className, stateIdOrFilter = null, filter = null) { if (this.#status !== 'inited') { throw new DOMException(`Cannot execute 'attach' on 'StateManager': state manager is not inited. This method can be safely called only once 'client' or 'server' is inited itself`, 'InvalidStateError'); } let stateId = null; - if (!isString(schemaName)) { + if (!isString(className)) { throw new TypeError(`Cannot execute 'attach' on 'StateManager': argument 1 should be either a number or an array`); } @@ -371,8 +369,8 @@ class BaseStateManager { return new Promise((resolve, reject) => { const reqId = this.#promiseStore.add(resolve, reject, 'attach-request'); - const requireSchema = this.#cachedSchemas.has(schemaName) ? false : true; - this[kStateManagerClient].transport.emit(ATTACH_REQUEST, reqId, schemaName, stateId, requireSchema, filter); + const requireDescription = this.#cachedClasses.has(className) ? false : true; + this[kStateManagerClient].transport.emit(ATTACH_REQUEST, reqId, className, stateId, requireDescription, filter); }); } @@ -383,9 +381,9 @@ class BaseStateManager { * @param {stateManagerObserveCallback} callback - Function to execute when a * new {@link SharedState} is created on the network. * @example - * client.stateManager.observe(async (schemaName, stateId) => { - * if (schemaName === 'my-shared-state-class') { - * const attached = await client.stateManager.attach(schemaName, stateId); + * client.stateManager.observe(async (className, stateId) => { + * if (className === 'my-shared-state-class') { + * const attached = await client.stateManager.attach(className, stateId); * } * }); */ @@ -394,13 +392,13 @@ class BaseStateManager { * that are created on the network. * * @overload - * @param {SharedStateClassName} schemaName - Observe only ${@link SharedState} + * @param {SharedStateClassName} className - Observe only ${@link SharedState} * of given name. * @param {stateManagerObserveCallback} callback - Function to execute when a * new {@link SharedState} is created on the network. * @example - * client.stateManager.observe('my-shared-state-class', async (schemaName, stateId) => { - * const attached = await client.stateManager.attach(schemaName, stateId); + * client.stateManager.observe('my-shared-state-class', async (className, stateId) => { + * const attached = await client.stateManager.attach(className, stateId); * }); */ /** @@ -414,9 +412,9 @@ class BaseStateManager { * @param {boolean} options.excludeLocal=false - If set to true, exclude states * created by the same node from the collection. * @example - * client.stateManager.observe(async (schemaName, stateId) => { - * if (schemaName === 'my-shared-state-class') { - * const attached = await client.stateManager.attach(schemaName, stateId); + * client.stateManager.observe(async (className, stateId) => { + * if (className === 'my-shared-state-class') { + * const attached = await client.stateManager.attach(className, stateId); * } * }, { excludeLocal: true }); */ @@ -425,7 +423,7 @@ class BaseStateManager { * that are created on the network, excluding the ones created by the current node. * * @overload - * @param {SharedStateClassName} schemaName - Observe only ${@link SharedState} + * @param {SharedStateClassName} className - Observe only ${@link SharedState} * of given name. * @param {stateManagerObserveCallback} callback - Function to execute when a * new {@link SharedState} is created on the network. @@ -433,8 +431,8 @@ class BaseStateManager { * @param {boolean} options.excludeLocal=false - If set to true, exclude states * created by the same node from the collection. * @example - * client.stateManager.observe('my-shared-state-class', async (schemaName, stateId) => { - * const attached = await client.stateManager.attach(schemaName, stateId); + * client.stateManager.observe('my-shared-state-class', async (className, stateId) => { + * const attached = await client.stateManager.attach(className, stateId); * }, { excludeLocal: true }); */ /** @@ -444,18 +442,18 @@ class BaseStateManager { * - The order of execution is not guaranted between nodes, i.e. a state attached * in the `observe` callback can be instantiated before the `async create` method * resolves on the creator node. - * - Filtering, i.e. `observedSchemaName` and `options.excludeLocal` are handled + * - Filtering, i.e. `observedClassName` and `options.excludeLocal` are handled * on the node side, the server just notify all state creation activity and * the node executes the given callbacks according to the different filter rules. * Such strategy allows to simply share the observe notifications between all observers. * * Alternative signatures: * - `stateManager.observe(callback)` - * - `stateManager.observe(schemaName, callback)` + * - `stateManager.observe(className, callback)` * - `stateManager.observe(callback, options)` - * - `stateManager.observe(schemaName, callback, options)` + * - `stateManager.observe(className, callback, options)` * - * @param {string} [schemaName] - optionnal schema name to filter the observed + * @param {SharedStateClassName} [className] - Optionnal class name to filter the observed * states. * @param {stateManagerObserveCallback} * callback - Function to be called when a new state is created on the network. @@ -467,9 +465,9 @@ class BaseStateManager { * function which allows to stop observing the states on the network. * * @example - * client.stateManager.observe(async (schemaName, stateId) => { - * if (schemaName === 'my-shared-state-class') { - * const attached = await client.stateManager.attach(schemaName, stateId); + * client.stateManager.observe(async (className, stateId) => { + * if (className === 'my-shared-state-class') { + * const attached = await client.stateManager.attach(className, stateId); * } * }); */ @@ -482,7 +480,7 @@ class BaseStateManager { excludeLocal: false, }; - let observedSchemaName; + let observedClassName; let callback; let options; @@ -493,29 +491,29 @@ class BaseStateManager { throw new TypeError(`[stateManager] Invalid arguments, argument 1 should be a function"`); } - observedSchemaName = null; + observedClassName = null; callback = args[0]; options = defaultOptions; break; } case 2: { - // variation: .observe(schemaName, callback) + // variation: .observe(className, callback) if (isString(args[0])) { if (!isFunction(args[1])) { throw new TypeError(`[stateManager] Invalid arguments, argument 2 should be a function"`); } - observedSchemaName = args[0]; + observedClassName = args[0]; callback = args[1]; options = defaultOptions; - // variation: .observe(callback, options) API + // variation: .observe(callback, options) } else if (isFunction(args[0])) { if (!isPlainObject(args[1])) { throw new TypeError(`[stateManager] Invalid arguments, argument 2 should be an object"`); } - observedSchemaName = null; + observedClassName = null; callback = args[0]; options = Object.assign(defaultOptions, args[1]); @@ -526,7 +524,7 @@ class BaseStateManager { break; } case 3: { - // variation: .observe(schemaName, callback, options) + // variation: .observe(className, callback, options) if (!isString(args[0])) { throw new TypeError(`[stateManager] Invalid arguments, argument 1 should be a string"`); } @@ -539,7 +537,7 @@ class BaseStateManager { throw new TypeError(`[stateManager] Invalid arguments, argument 2 should be an object"`); } - observedSchemaName = args[0]; + observedClassName = args[0]; callback = args[1]; options = Object.assign(defaultOptions, args[2]); @@ -556,17 +554,17 @@ class BaseStateManager { const reqId = this.#promiseStore.add(resolve, reject, 'observe-request'); // store the callback for execution on the response. the returned Promise // is fullfiled once callback has been executed with each existing states - const observeInfos = [observedSchemaName, callback, options]; + const observeInfos = [observedClassName, callback, options]; this.#observeRequestCallbacks.set(reqId, observeInfos); // NOTE: do not store in `_observeListeners` yet as it can produce race // conditions, e.g.: // ``` - // await client.stateManager.observe(async (schemaName, stateId, nodeId) => {}); + // await client.stateManager.observe(async (className, stateId, nodeId) => {}); // // client now receives OBSERVE_NOTIFICATIONS // await otherClient.stateManager.create('a'); // // second observer added in between - // client.stateManager.observe(async (schemaName, stateId, nodeId) => {}); + // client.stateManager.observe(async (className, stateId, nodeId) => {}); // ```` // OBSERVE_NOTIFICATION is received before the OBSERVE_RESPONSE, then the // second observer is called twice: @@ -577,50 +575,50 @@ class BaseStateManager { // // cf. unit test `observe should properly behave in race condition` - this[kStateManagerClient].transport.emit(OBSERVE_REQUEST, reqId, observedSchemaName); + this[kStateManagerClient].transport.emit(OBSERVE_REQUEST, reqId, observedClassName); }); } /** - * Returns a collection of all the states created from the schema name. + * Returns a collection of all the states created from a given shared state class. * * @overload - * @param {string} schemaName - Name of the schema. + * @param {SharedStateClassName} className - Name of the shared state class. * @returns {Promise} * * @example - * const collection = await client.stateManager.getCollection(schemaName); + * const collection = await client.stateManager.getCollection(className); */ /** - * Returns a collection of all the states created from the schema name. + * Returns a collection of all the states created from a given shared state class. * * @overload - * @param {string} schemaName - Name of the schema. + * @param {SharedStateClassName} className - Name of the shared state class. * @param {SharedStateParameterName[]} filter - Filter parameter of interest for each * state of the collection. * @returns {Promise} * * @example - * const collection = await client.stateManager.getCollection(schemaName, ['my-param']); + * const collection = await client.stateManager.getCollection(className, ['my-param']); */ /** - * Returns a collection of all the states created from the schema name. + * Returns a collection of all the states created from a given shared state class. * * @overload - * @param {string} schemaName - Name of the schema. + * @param {SharedStateClassName} className - Name of the shared state class. * @param {object} options - Options. * @param {boolean} options.excludeLocal=false - If set to true, exclude states * created by the same node from the collection. * @returns {Promise} * * @example - * const collection = await client.stateManager.getCollection(schemaName, { excludeLocal: true }); + * const collection = await client.stateManager.getCollection(className, { excludeLocal: true }); */ /** - * Returns a collection of all the states created from the schema name. + * Returns a collection of all the states created from a given shared state class. * * @overload - * @param {string} schemaName - Name of the schema. + * @param {SharedStateClassName} className - Name of the shared state class. * @param {SharedStateParameterName[]} filter - Filter parameter of interest for each * state of the collection. * @param {object} options - Options. @@ -629,18 +627,18 @@ class BaseStateManager { * @returns {Promise} * * @example - * const collection = await client.stateManager.getCollection(schemaName, ['my-param'], { excludeLocal: true }); + * const collection = await client.stateManager.getCollection(className, ['my-param'], { excludeLocal: true }); */ /** - * Returns a collection of all the states created from the schema name. + * Returns a collection of all the states created from a given shared state class. * * Alternative signatures: - * - `stateManager.getCollection(schemaName)` - * - `stateManager.getCollection(schemaName, filter)` - * - `stateManager.getCollection(schemaName, options)` - * - `stateManager.getCollection(schemaName, filter, options)` + * - `stateManager.getCollection(className)` + * - `stateManager.getCollection(className, filter)` + * - `stateManager.getCollection(className, options)` + * - `stateManager.getCollection(className, filter, options)` * - * @param {string} schemaName - Name of the schema. + * @param {SharedStateClassName} className - Name of the shared state class. * @param {array|null} [filter=null] - Filter parameter of interest for each * state of the collection. If set to `null`, no filter applied. * @param {object} [options={}] - Options. @@ -649,15 +647,15 @@ class BaseStateManager { * @returns {Promise} * * @example - * const collection = await client.stateManager.getCollection(schemaName); + * const collection = await client.stateManager.getCollection(className); */ - async getCollection(schemaName, filterOrOptions = null, options = {}) { + async getCollection(className, filterOrOptions = null, options = {}) { if (this.#status !== 'inited') { throw new DOMException(`Cannot execute 'getCollection' on 'StateManager': state manager is not inited. This method can be safely called only once 'client' or 'server' is inited itself`, 'InvalidStateError'); } - if (!isString(schemaName)) { - throw new TypeError(`Cannot execute 'getCollection' on 'StateManager': 'schemaName' should be a string"`); + if (!isString(className)) { + throw new TypeError(`Cannot execute 'getCollection' on 'StateManager': 'className' should be a string"`); } let filter; @@ -689,7 +687,7 @@ class BaseStateManager { } } - const collection = new SharedStateCollection(this, schemaName, filter, options); + const collection = new SharedStateCollection(this, className, filter, options); await collection._init(); return collection;