diff --git a/src/client/ClientStateManager.js b/src/client/ClientStateManager.js index eebb4949..8d8ce082 100644 --- a/src/client/ClientStateManager.js +++ b/src/client/ClientStateManager.js @@ -27,7 +27,7 @@ import BaseStateManager from '../common/BaseStateManager.js'; * * const server = new Server(config); * // define a class of shared state. - * server.stateManager.registerSchema('some-global-state', { + * server.stateManager.defineClass('some-global-state', { * myRandom: { * type: 'float', * default: 0, diff --git a/src/common/BasePlugin.js b/src/common/BasePlugin.js index c74e0560..5a31e121 100644 --- a/src/common/BasePlugin.js +++ b/src/common/BasePlugin.js @@ -88,7 +88,7 @@ class BasePlugin { * constructor(server, id) { * super(server, id); * - * this.server.stateManager.registerSchema(`my-plugin:${this.id}`, { + * this.server.stateManager.defineClass(`my-plugin:${this.id}`, { * someParam: { * type: 'boolean', * default: false, @@ -121,7 +121,7 @@ class BasePlugin { * constructor(server, id) { * super(server, id); * - * this.server.stateManager.registerSchema(`my-plugin:${this.id}`, { + * this.server.stateManager.defineClass(`my-plugin:${this.id}`, { * someParam: { * type: 'boolean', * default: false, diff --git a/src/common/ParameterBag.js b/src/common/ParameterBag.js index 72c0489d..bfe10b71 100644 --- a/src/common/ParameterBag.js +++ b/src/common/ParameterBag.js @@ -137,11 +137,11 @@ class ParameterBag { const def = description[name]; if (!Object.prototype.hasOwnProperty.call(def, 'type')) { - throw new TypeError(`[StateManager.registerSchema] Invalid class description - param "${name}": "type" key is required`); + throw new TypeError(`[StateManager.defineClass] Invalid class description - param "${name}": "type" key is required`); } if (!Object.prototype.hasOwnProperty.call(types, def.type)) { - throw new TypeError(`[StateManager.registerSchema] Invalid class description - param "${name}": "{ type: '${def.type}' }" does not exists`); + throw new TypeError(`[StateManager.defineClass] Invalid class description - param "${name}": "{ type: '${def.type}' }" does not exists`); } const required = types[def.type].required; @@ -152,10 +152,10 @@ class ParameterBag { // - default is always null for `event` params // - default is always null for `required` params if ('default' in def && def.default !== null) { - throw new TypeError(`[StateManager.registerSchema] Invalid class description for param ${name} - "default" propaerty is set and not null while the parameter definition is declared as "event" or "required"`); + throw new TypeError(`[StateManager.defineClass] Invalid class description for param ${name} - "default" propaerty is set and not null while the parameter definition is declared as "event" or "required"`); } } else if (!Object.prototype.hasOwnProperty.call(def, key)) { - throw new TypeError(`[StateManager.registerSchema] Invalid class description - param "${name}" (type "${def.type}"): "${key}" key is required`); + throw new TypeError(`[StateManager.defineClass] Invalid class description - param "${name}" (type "${def.type}"): "${key}" key is required`); } }); } diff --git a/src/common/SharedState.js b/src/common/SharedState.js index 06378ae4..afc95407 100644 --- a/src/common/SharedState.js +++ b/src/common/SharedState.js @@ -68,7 +68,7 @@ export const kSharedStatePromiseStore = Symbol('soundworks:shared-state-promise- * * const server = new Server(config); * // define a shared state class - * server.stateManager.registerSchema('some-global-state', { + * server.stateManager.defineClass('some-global-state', { * myRandom: { * type: 'float', * default: 0, @@ -387,7 +387,7 @@ ${JSON.stringify(initValues, null, 2)}`); * and resolves after all the `onUpdate` callbacks have resolved themselves, i.e.: * * ```js - * server.stateManager.registerSchema('test', { + * server.stateManager.defineClass('test', { * myBool: { type: 'boolean', default: false }, * }); * const a = await server.stateManager.create('a'); diff --git a/src/common/shared-state-types.js b/src/common/shared-state-types.js index 42922844..2568f705 100644 --- a/src/common/shared-state-types.js +++ b/src/common/shared-state-types.js @@ -6,7 +6,7 @@ /** * Description of a {@link SharedState} data structure that describes the structure - * of a class of {@link SharedState} to be registered by {@link ServerStateManager#registerSchema} + * of a class of {@link SharedState} to be registered by {@link ServerStateManager#defineClass} * * A `SharedStateClassDescription` is the blueprint, or the definition from which * shared states from a given class can be created. @@ -31,7 +31,7 @@ * } * }; * - * server.stateManager.registerSchema('my-class-name', myClassDescription); + * server.stateManager.defineClass('my-class-name', myClassDescription); */ /** diff --git a/src/server/Server.js b/src/server/Server.js index ac7b1c70..dc396fd8 100644 --- a/src/server/Server.js +++ b/src/server/Server.js @@ -238,7 +238,7 @@ class Server { }; // register audit state schema - this.#stateManager.registerSchema(AUDIT_STATE_NAME, auditClassDescription); + this.#stateManager.defineClass(AUDIT_STATE_NAME, auditClassDescription); logger.configure(this.#config.env.verbose); } diff --git a/src/server/ServerStateManager.js b/src/server/ServerStateManager.js index ac5147da..be48545f 100644 --- a/src/server/ServerStateManager.js +++ b/src/server/ServerStateManager.js @@ -31,6 +31,8 @@ import SharedStatePrivate, { kSharedStatePrivateDetachClient, } from './SharedStatePrivate.js'; +import logger from '../common/logger.js'; + const generateStateId = idGenerator(); const generateRemoteId = idGenerator(); @@ -78,7 +80,7 @@ export const kStateManagerClientsByNodeId = Symbol('soundworks:server-state-clie * * const server = new Server(config); * // declare and register the class of a shared state. - * server.stateManager.registerSchema('some-global-state', { + * server.stateManager.defineClass('some-global-state', { * myRandom: { * type: 'float', * default: 0, @@ -382,9 +384,7 @@ class ServerStateManager extends BaseStateManager { } /** - * Define a generic class from which {@link SharedState} can be created. - * - * _In a future revision, this method and its arguments will be renamed_ + * Define a generic class from which {@link SharedState}s can be created. * * @param {SharedStateClassName} className - Name of the class. * @param {SharedStateClassDescription} classDescription - Description of the class. @@ -393,7 +393,7 @@ class ServerStateManager extends BaseStateManager { * @see {@link ClientStateManager#create} * * @example - * server.stateManager.registerSchema('my-class', { + * server.stateManager.defineClass('my-class', { * myBoolean: { * type: 'boolean' * default: false, @@ -404,19 +404,19 @@ class ServerStateManager extends BaseStateManager { * min: -1, * max: 1 * } - * }) + * }); */ - registerSchema(className, classDescription) { + defineClass(className, classDescription) { if (!isString(className)) { - throw new Error(`[stateManager.registerSchema] Invalid class name "${className}", should be a string`); + throw new Error(`[stateManager.defineClass] Invalid class name "${className}", should be a string`); } if (this.#classes.has(className)) { - throw new Error(`[stateManager.registerSchema] Cannot define class with name: "${className}", class already exists`); + throw new Error(`[stateManager.defineClass] Cannot define class with name: "${className}", class already exists`); } if (!isPlainObject(classDescription)) { - throw new Error(`[stateManager.registerSchema] Invalid class description, should be an object`); + throw new Error(`[stateManager.defineClass] Invalid class description, should be an object`); } ParameterBag.validateDescription(classDescription); @@ -426,6 +426,14 @@ class ServerStateManager extends BaseStateManager { this.#hooksByClassName.set(className, new Set()); } + /** + * @deprecated Use {@link ServerStateManager#defineClass} instead. + */ + registerSchema(className, classDescription) { + logger.deprecated('ServerStateManager#registerSchema', 'ServerStateManager#defineClass', '4.0.0-alpha.29'); + this.defineClass(className, classDescription); + } + /** * Delete a whole class of {@link ShareState}. * @@ -481,7 +489,7 @@ class ServerStateManager extends BaseStateManager { * @returns {Fuction} deleteHook - Handler that deletes the hook when executed. * * @example - * server.stateManager.registerSchema('hooked', { + * server.stateManager.defineClass('hooked', { * value: { type: 'string', default: null, nullable: true }, * numUpdates: { type: 'integer', default: 0 }, * }); diff --git a/tests/essentials/Client.spec.js b/tests/essentials/Client.spec.js index 952af750..90a2b6f3 100644 --- a/tests/essentials/Client.spec.js +++ b/tests/essentials/Client.spec.js @@ -130,7 +130,7 @@ describe('# client::Client', () => { it(`should have inited the state manager`, async () => { const server = new Server(config); - server.stateManager.registerSchema('test', { a: { type: 'boolean', default: true } }); + server.stateManager.defineClass('test', { a: { type: 'boolean', default: true } }); await server.init(); await server.start(); diff --git a/tests/integration/ping-pong/src/server/index.js b/tests/integration/ping-pong/src/server/index.js index 72f52b80..ca9edcff 100644 --- a/tests/integration/ping-pong/src/server/index.js +++ b/tests/integration/ping-pong/src/server/index.js @@ -29,7 +29,7 @@ server.useDefaultApplicationTemplate(); * Register plugins and schemas */ // server.pluginManager.register('my-plugin', plugin); -// server.stateManager.registerSchema('my-schema', definition); +// server.stateManager.defineClass('my-schema', definition); /** * Launch application (init plugins, http server, etc.) diff --git a/tests/integration/test-browser/src/server/index.js b/tests/integration/test-browser/src/server/index.js index c8ccaf13..fb76317f 100644 --- a/tests/integration/test-browser/src/server/index.js +++ b/tests/integration/test-browser/src/server/index.js @@ -28,7 +28,7 @@ server.useDefaultApplicationTemplate(); /** * Register plugins and schemas */ -server.stateManager.registerSchema('globals', { +server.stateManager.defineClass('globals', { done: { type: 'boolean', nullable: true, diff --git a/tests/misc/PromiseStore.spec.js b/tests/misc/PromiseStore.spec.js index 00d0d855..8aea0707 100644 --- a/tests/misc/PromiseStore.spec.js +++ b/tests/misc/PromiseStore.spec.js @@ -51,7 +51,7 @@ describe('# PromiseStore', () => { describe(`## MISC`, () => { it(`check consistency of PromiseStore in SharedState`, async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const client = new Client({ role: 'test', ...config }); @@ -118,7 +118,7 @@ describe('# PromiseStore', () => { it(`stress test`, async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const client = new Client({ role: 'test', ...config }); diff --git a/tests/misc/deprecated.spec.js b/tests/misc/deprecated.spec.js index 37273cc0..be335e04 100644 --- a/tests/misc/deprecated.spec.js +++ b/tests/misc/deprecated.spec.js @@ -10,7 +10,7 @@ describe('# deprecated API', () => { describe('from v4.0.0-alpha.29', () => { it('SharedState#schemaName', async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const state = await server.stateManager.create('a'); @@ -22,7 +22,7 @@ describe('# deprecated API', () => { it('SharedStateCollection#schemaName', async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const collection = await server.stateManager.getCollection('a'); @@ -34,7 +34,7 @@ describe('# deprecated API', () => { it('SharedState#getSchema(name = null)', async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const state = await server.stateManager.create('a'); @@ -46,7 +46,7 @@ describe('# deprecated API', () => { it('SharedStateCollection#getSchema(name = null)', async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const collection = await server.stateManager.getCollection('a'); @@ -58,7 +58,7 @@ describe('# deprecated API', () => { it('SharedStateManager#getSchema()', async () => { const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); const classDescription = await server.stateManager.getClassDescription('a'); // actual diff --git a/tests/states/ParameterBag.spec.js b/tests/states/ParameterBag.spec.js index a9c6df0a..cdaa4547 100644 --- a/tests/states/ParameterBag.spec.js +++ b/tests/states/ParameterBag.spec.js @@ -14,15 +14,15 @@ describe('# [private] ParameterBag', () => { it('should check if schema is invalid', () => { assert.throw(() => ParameterBag.validateDescription({ noType: {} - }), TypeError, `[StateManager.registerSchema] Invalid class description - param "noType": "type" key is required`); + }), TypeError, `[StateManager.defineClass] Invalid class description - param "noType": "type" key is required`); assert.throw(() => ParameterBag.validateDescription({ invalidType: { type: 'invalid' } - }), TypeError, `[StateManager.registerSchema] Invalid class description - param "invalidType": "{ type: 'invalid' }" does not exists`); + }), TypeError, `[StateManager.defineClass] Invalid class description - param "invalidType": "{ type: 'invalid' }" does not exists`); assert.throw(() => ParameterBag.validateDescription({ myBoolean: { type: 'boolean' } - }), TypeError, `[StateManager.registerSchema] Invalid class description - param "myBoolean" (type "boolean"): "default" key is required`); + }), TypeError, `[StateManager.defineClass] Invalid class description - param "myBoolean" (type "boolean"): "default" key is required`); }); it(`should throw if "default" is declared when "event" is true`, () => { @@ -52,7 +52,7 @@ describe('# [private] ParameterBag', () => { it('should validate the given schema', () => { assert.throws(() => new ParameterBag({ invalidType: { type: 'invalid' } - }), TypeError, `[StateManager.registerSchema] Invalid class description - param "invalidType": "{ type: 'invalid' }" does not exists`); + }), TypeError, `[StateManager.defineClass] Invalid class description - param "invalidType": "{ type: 'invalid' }" does not exists`); }); it('should check initValues consistency', () => { diff --git a/tests/states/SharedState.spec.js b/tests/states/SharedState.spec.js index 778552f0..e4cbf459 100644 --- a/tests/states/SharedState.spec.js +++ b/tests/states/SharedState.spec.js @@ -17,8 +17,8 @@ describe('# SharedState', () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('a', a); - server.stateManager.registerSchema('b', b); + server.stateManager.defineClass('a', a); + server.stateManager.defineClass('b', b); await server.start(); // --------------------------------------------------- @@ -175,7 +175,7 @@ describe('# SharedState', () => { describe('## get(name) - ## getValues()', () => { it('get(name) `any` type should be a deep copy', async() => { - server.stateManager.registerSchema('any', { + server.stateManager.defineClass('any', { ref: { type: 'any', default: { @@ -196,7 +196,7 @@ describe('# SharedState', () => { }); it('getValues() `any` type should be a deep copy', async() => { - server.stateManager.registerSchema('any-all', { + server.stateManager.defineClass('any-all', { ref: { type: 'any', default: {}, @@ -213,7 +213,7 @@ describe('# SharedState', () => { describe('## getUnsafe(name) - state.getValuesUnsafe()', () => { it('get(name) `any` type should be a reference', async() => { - server.stateManager.registerSchema('any-unsafe', { + server.stateManager.defineClass('any-unsafe', { ref: { type: 'any', default: { @@ -231,7 +231,7 @@ describe('# SharedState', () => { }); it('getValuesUnsafe() `any` type be a reference', async() => { - server.stateManager.registerSchema('any-all-unsafe', { + server.stateManager.defineClass('any-all-unsafe', { ref: { type: 'any', default: {}, @@ -351,7 +351,7 @@ describe('# SharedState', () => { }); it('should not propagate event parameters on first call if `executeListener=true`', async () => { - server.stateManager.registerSchema('with-event', { + server.stateManager.defineClass('with-event', { bool: { type: 'boolean', event: true, }, int: { type: 'integer', default: 20, }, }); @@ -372,7 +372,7 @@ describe('# SharedState', () => { }); it('should copy stored value for "any" type to have a predictable behavior', async () => { - server.stateManager.registerSchema('test-any', { + server.stateManager.defineClass('test-any', { any: { type: 'any', nullable: true, @@ -555,7 +555,7 @@ describe('# SharedState - filtered attached state', () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('filtered', { + server.stateManager.defineClass('filtered', { bool: { type: 'boolean', default: false, @@ -775,7 +775,7 @@ describe(`# SharedState - Batched transport`, () => { localConfig.env.port = 8082; const server = new Server(localConfig); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); let batchedRequests = 0; diff --git a/tests/states/SharedStateCollection.spec.js b/tests/states/SharedStateCollection.spec.js index bb00972f..f1191024 100644 --- a/tests/states/SharedStateCollection.spec.js +++ b/tests/states/SharedStateCollection.spec.js @@ -17,8 +17,8 @@ describe(`# SharedStateCollection`, () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('a', a); - server.stateManager.registerSchema('b', b); + server.stateManager.defineClass('a', a); + server.stateManager.defineClass('b', b); await server.start(); // --------------------------------------------------- @@ -320,7 +320,7 @@ describe(`# SharedStateCollection`, () => { }); it('should not propagate event parameters on first call if `executeListener=true`', async () => { - server.stateManager.registerSchema('with-event', { + server.stateManager.defineClass('with-event', { bool: { type: 'boolean', event: true, }, int: { type: 'integer', default: 20, }, }); @@ -414,7 +414,7 @@ describe(`# SharedStateCollection`, () => { localConfig.env.port = 8083; const server = new Server(localConfig); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); await server.start(); let states = []; @@ -478,7 +478,7 @@ describe('# SharedStateCollection - filtered collection', () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('filtered', { + server.stateManager.defineClass('filtered', { bool: { type: 'boolean', default: false, diff --git a/tests/states/StateManager.spec.js b/tests/states/StateManager.spec.js index 5d7d9d83..4a6de1e2 100644 --- a/tests/states/StateManager.spec.js +++ b/tests/states/StateManager.spec.js @@ -24,8 +24,8 @@ describe(`# StateManager`, () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('a', a); - server.stateManager.registerSchema('b', b); + server.stateManager.defineClass('a', a); + server.stateManager.defineClass('b', b); await server.start(); @@ -40,16 +40,16 @@ describe(`# StateManager`, () => { server.stop(); }); - describe('## [server] registerSchema(className, definition)', () => { + describe('## [server] defineClass(className, definition)', () => { it('should throw if reusing same schema name', () => { assert.throws(() => { - server.stateManager.registerSchema('a', a); - }, Error, '[stateManager.registerSchema] Cannot define class with name: "a", class already exists'); + server.stateManager.defineClass('a', a); + }, Error, '[stateManager.defineClass] Cannot define class with name: "a", class already exists'); }); it ('should register same definition with another name', () => { - server.stateManager.registerSchema('aa', a); + server.stateManager.defineClass('aa', a); }); }); @@ -59,7 +59,7 @@ describe(`# StateManager`, () => { localConfig.env.port = 8082; const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); let errored = false; @@ -100,7 +100,7 @@ describe(`# StateManager`, () => { localConfig.env.port = 8082; const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); let errored = false; @@ -186,7 +186,7 @@ describe(`# StateManager`, () => { localConfig.env.port = 8082; const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); let errored = false; @@ -272,7 +272,7 @@ describe(`# StateManager`, () => { describe('## [server] deleteSchema(name)', () => { it('should call state.onDetach and state.onDelete on all states of its kind', async () => { - server.stateManager.registerSchema('a-delete', a); + server.stateManager.defineClass('a-delete', a); const a0 = await server.stateManager.create('a-delete'); const a1 = await server.stateManager.attach('a-delete', a0.id); @@ -301,7 +301,7 @@ describe(`# StateManager`, () => { // cf. https://github.com/collective-soundworks/soundworks/issues/71 it(`should not propagate deleted schema in observe`, async () => { - server.stateManager.registerSchema('a-delete-observe', a); + server.stateManager.defineClass('a-delete-observe', a); const state = await client.stateManager.create('a-delete-observe'); let deleteCalled = false;; @@ -333,7 +333,7 @@ describe(`# StateManager`, () => { localConfig.env.port = 8082; const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); let errored = false; @@ -696,7 +696,7 @@ describe(`# StateManager`, () => { localConfig.env.port = 8082; const server = new Server(config); - server.stateManager.registerSchema('a', a); + server.stateManager.defineClass('a', a); let errored = false; @@ -727,7 +727,7 @@ describe(`# StateManager`, () => { }; it('should properly execute hook', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues) => { updates.value = `${updates.name}-value`; return updates; @@ -775,7 +775,7 @@ describe(`# StateManager`, () => { it('hook API should be `hook(updates, currentValues, context)`', async () => { return new Promise(async (resolve, reject) => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues, context) => { try { assert.deepEqual(updates, { name: 'test' }); @@ -798,7 +798,7 @@ describe(`# StateManager`, () => { it('should not mess around when several states of same kind are created', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues) => { // just apply name to value updates.value = `${updates.name}-value`; @@ -823,7 +823,7 @@ describe(`# StateManager`, () => { }); it('should support asynchronous operation', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', async (updates, currentValues) => { return new Promise(resolve => { setTimeout(() => { @@ -850,7 +850,7 @@ describe(`# StateManager`, () => { }); it('should apply several hooks in registation order', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues) => { return { ...updates, value: 'ok-1' }; }); @@ -874,7 +874,7 @@ describe(`# StateManager`, () => { }); it('should unregister hooks properly', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues) => { return { ...updates, value: 'ok-1' }; }); @@ -902,7 +902,7 @@ describe(`# StateManager`, () => { }); it('should abort when explicitly returning `null`', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues) => { assert.ok('hook called'); return null; @@ -928,7 +928,7 @@ describe(`# StateManager`, () => { }); it('should abort when explicitly returning `null` (w/ immediate option)', async () => { - server.stateManager.registerSchema('hooked', { + server.stateManager.defineClass('hooked', { value: { type: 'string', default: null, @@ -957,7 +957,7 @@ describe(`# StateManager`, () => { }); it('should continue when implicitly returning `undefined`', async () => { - server.stateManager.registerSchema('hooked', hookSchema); + server.stateManager.defineClass('hooked', hookSchema); server.stateManager.registerUpdateHook('hooked', (updates, currentValues) => { if (updates.name === 'test-1') { diff --git a/tests/states/schema-options.spec.js b/tests/states/schema-options.spec.js index 2ea8e4ad..083f6def 100644 --- a/tests/states/schema-options.spec.js +++ b/tests/states/schema-options.spec.js @@ -22,8 +22,8 @@ describe('# SharedState - schema options', () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('a', a); - // server.stateManager.registerSchema('b', b); + server.stateManager.defineClass('a', a); + // server.stateManager.defineClass('b', b); await server.start(); @@ -67,7 +67,7 @@ describe('# SharedState - schema options', () => { it('[event=true] should behave correctly', async () => { return new Promise(async (resolve, reject) => { - server.stateManager.registerSchema('event-test', { + server.stateManager.defineClass('event-test', { value: { type: 'boolean', event: true, @@ -117,7 +117,7 @@ describe('# SharedState - schema options', () => { it('[filterChange=false] should behave correctly', async () => { return new Promise(async (resolve, reject) => { - server.stateManager.registerSchema('filter-change-test', { + server.stateManager.defineClass('filter-change-test', { value: { type: 'boolean', default: true, @@ -158,7 +158,7 @@ describe('# SharedState - schema options', () => { it('[immediate=true] (w/ [event=false, filterChange=true]) should behave correctly', async () => { return new Promise(async (resolve, reject) => { - server.stateManager.registerSchema('immediate-test', { + server.stateManager.defineClass('immediate-test', { immediateValue: { type: 'integer', default: 0, @@ -282,7 +282,7 @@ describe('# SharedState - schema options', () => { it('[immediate=true, event=true] should behave correctly', async () => { return new Promise(async (resolve, reject) => { try { - server.stateManager.registerSchema('immediate-test-2', { + server.stateManager.defineClass('immediate-test-2', { immediateValue: { type: 'integer', immediate: true, @@ -374,7 +374,7 @@ describe('# SharedState - schema options', () => { it('[immediate=true, filterChange=false] should behave correctly', async () => { return new Promise(async (resolve, reject) => { - server.stateManager.registerSchema('immediate-test-3', { + server.stateManager.defineClass('immediate-test-3', { immediateValue: { type: 'integer', default: 0, @@ -467,7 +467,7 @@ describe('# SharedState - schema options', () => { const server = new Server(localConfig); await server.start(); - server.stateManager.registerSchema('local-test', { + server.stateManager.defineClass('local-test', { value: { type: 'boolean', default: false, @@ -510,7 +510,7 @@ describe('# SharedState - schema options', () => { const server = new Server(localConfig); await server.start(); - server.stateManager.registerSchema('local-test', { + server.stateManager.defineClass('local-test', { local: { type: 'boolean', default: false, @@ -585,7 +585,7 @@ describe('# SharedState - schema options', () => { }, }; - server.stateManager.registerSchema('test-integer', schema); + server.stateManager.defineClass('test-integer', schema); const serverInteger = await server.stateManager.create('test-integer'); const serverResult = []; @@ -626,7 +626,7 @@ describe('# SharedState - schema options', () => { }, }; - server.stateManager.registerSchema('test-float', schema); + server.stateManager.defineClass('test-float', schema); const serverInteger = await server.stateManager.create('test-float'); const serverResult = []; diff --git a/tests/states/stress-tests.spec.js b/tests/states/stress-tests.spec.js index ab2f9bb4..f0c1868d 100644 --- a/tests/states/stress-tests.spec.js +++ b/tests/states/stress-tests.spec.js @@ -18,8 +18,8 @@ describe('# SharedStates - Stress test', () => { // server // --------------------------------------------------- server = new Server(config); - server.stateManager.registerSchema('a', a); - server.stateManager.registerSchema('b', b); + server.stateManager.defineClass('a', a); + server.stateManager.defineClass('b', b); await server.init(); await server.start();