Skip to content

Warn about using deprecated features #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ Register a new middleware.
One of:
* `'connect'`: A new client connected to the server.
* `'op'`: An operation was loaded from the database.
* `'doc'`: DEPRECATED: A snapshot was loaded from the database. Please use 'readSnapshots'
* `'readSnapshots'`: Snapshot(s) were loaded from the database for a fetch or subscribe of a query or document
* `'query'`: A query is about to be sent to the database
* `'submit'`: An operation is about to be submitted to the database
Expand Down
12 changes: 12 additions & 0 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var projections = require('./projections');
var QueryEmitter = require('./query-emitter');
var StreamSocket = require('./stream-socket');
var SubmitRequest = require('./submit-request');
var warnDeprecatedDoc = true;
var warnDeprecatedAfterSubmit = true;

function Backend(options) {
if (!(this instanceof Backend)) return new Backend(options);
Expand Down Expand Up @@ -71,6 +73,11 @@ Backend.prototype.MIDDLEWARE_ACTIONS = {
};

Backend.prototype._shimDocAction = function() {
if (warnDeprecatedDoc) {
warnDeprecatedDoc = false;
console.warn('DEPRECATED: "doc" middleware action. Use "readSnapshots" instead. Pass `disableDocAction: true` option to ShareDB to disable the "doc" action and this warning.');
}

var backend = this;
this.use(this.MIDDLEWARE_ACTIONS.readSnapshots, function(request, callback) {
async.each(request.snapshots, function(snapshot, eachCb) {
Expand All @@ -83,6 +90,11 @@ Backend.prototype._shimDocAction = function() {
// Shim for backwards compatibility with deprecated middleware action name.
// The action 'after submit' is now 'afterSubmit'.
Backend.prototype._shimAfterSubmit = function() {
if (warnDeprecatedAfterSubmit) {
warnDeprecatedAfterSubmit = false;
console.warn('DEPRECATED: "after submit" middleware action. Use "afterSubmit" instead. Pass `disableSpaceDelimitedActions: true` option to ShareDB to disable the "after submit" action and this warning.');
}

var backend = this;
this.use(backend.MIDDLEWARE_ACTIONS.afterSubmit, function(request, callback) {
backend.trigger(backend.MIDDLEWARE_ACTIONS['after submit'], request.agent, request, callback);
Expand Down