Navigation Menu

Skip to content

Commit

Permalink
Shorten constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 2, 2012
1 parent b4f945e commit 62ee887
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
24 changes: 12 additions & 12 deletions lib/database/domain.js
Expand Up @@ -2,28 +2,28 @@ var nativeNroonga = require('nroonga');
var nroonga = require('../wrapped-nroonga');
var IndexField = require('./index-field').IndexField;

exports.MINIMUM_DOMAIN_NAME_LENGTH = 3;
exports.MAXIMUM_DOMAIN_NAME_LENGTH = 28;
exports.INVALID_DOMAIN_NAME_CHARACTER_PATTERN = /[^\-a-z0-9]/g;
exports.MINIMUM_NAME_LENGTH = 3;
exports.MAXIMUM_NAME_LENGTH = 28;
exports.INVALID_NAME_CHARACTER_PATTERN = /[^\-a-z0-9]/g;
exports.INVALID_TABLE_NAME_CHARACTER_PATTERN = /[^_a-z0-9]/g;

var DEFAULT_DOMAIN_ID =
exports.DEFAULT_DOMAIN_ID =
Domain.DEFAULT_DOMAIN_ID = '00000000000000000000000000';
var DEFAULT_ID =
exports.DEFAULT_ID =
Domain.DEFAULT_ID = '00000000000000000000000000';

function assertValidDomainName(domain) {
if (typeof domain != 'string')
throw new Error('domain name must be a string');

if (domain.length < exports.MINIMUM_DOMAIN_NAME_LENGTH)
if (domain.length < exports.MINIMUM_NAME_LENGTH)
throw new Error('too short domain name (minimum length = ' +
exports.MINIMUM_DOMAIN_NAME_LENGTH + ')');
exports.MINIMUM_NAME_LENGTH + ')');

if (domain.length > exports.MAXIMUM_DOMAIN_NAME_LENGTH)
if (domain.length > exports.MAXIMUM_NAME_LENGTH)
throw new Error('too long domain name (max length = ' +
exports.MAXIMUM_DOMAIN_NAME_LENGTH + ')');
exports.MAXIMUM_NAME_LENGTH + ')');

var invalidCharacter = domain.match(exports.INVALID_DOMAIN_NAME_CHARACTER_PATTERN) ||
var invalidCharacter = domain.match(exports.INVALID_NAME_CHARACTER_PATTERN) ||
domain.match(exports.INVALID_TABLE_NAME_CHARACTER_PATTERN);
if (invalidCharacter) {
var characters = Array.prototype.map.call(invalidCharacter, function(aCharacter) {
Expand Down Expand Up @@ -170,7 +170,7 @@ Domain.prototype = {
},

get id() {
return this._id === undefined ? DEFAULT_DOMAIN_ID : this._id ;
return this._id === undefined ? DEFAULT_ID : this._id ;
},
set id(value) {
return this._id = value;
Expand Down
20 changes: 10 additions & 10 deletions lib/database/index-field.js
@@ -1,10 +1,10 @@
var nroonga = require('../wrapped-nroonga');

exports.MINIMUM_FIELD_NAME_LENGTH = 3;
exports.MAXIMUM_FIELD_NAME_LENGTH = 64;
exports.INVALID_FIELD_NAME_CHARACTER_PATTERN = /[^_a-z0-9]/g;
exports.MINIMUM_NAME_LENGTH = 3;
exports.MAXIMUM_NAME_LENGTH = 64;
exports.INVALID_NAME_CHARACTER_PATTERN = /[^_a-z0-9]/g;
exports.INVALID_COLUMN_NAME_CHARACTER_PATTERN = /[^_a-z0-9]/g;
exports.RESERVED_FIELD_NAMES = [
exports.RESERVED_NAMES = [
'body',
'docid',
'text_relevance'
Expand All @@ -17,15 +17,15 @@ function assertValidFieldName(field) {
if (typeof field != 'string')
throw new Error('field name must be a string');

if (field.length < exports.MINIMUM_FIELD_NAME_LENGTH)
if (field.length < exports.MINIMUM_NAME_LENGTH)
throw new Error('too short field name (minimum length = ' +
exports.MINIMUM_FIELD_NAME_LENGTH + ')');
exports.MINIMUM_NAME_LENGTH + ')');

if (field.length > exports.MAXIMUM_FIELD_NAME_LENGTH)
if (field.length > exports.MAXIMUM_NAME_LENGTH)
throw new Error('too long field name (max length = ' +
exports.MAXIMUM_FIELD_NAME_LENGTH + ')');
exports.MAXIMUM_NAME_LENGTH + ')');

var invalidCharacter = field.match(exports.INVALID_FIELD_NAME_CHARACTER_PATTERN) ||
var invalidCharacter = field.match(exports.INVALID_NAME_CHARACTER_PATTERN) ||
field.match(exports.INVALID_COLUMN_NAME_CHARACTER_PATTERN);
if (invalidCharacter) {
var characters = Array.prototype.map.call(invalidCharacter, function(aCharacter) {
Expand All @@ -34,7 +34,7 @@ function assertValidFieldName(field) {
throw new Error(characters.join(', ') + ' cannot appear in a field name');
}

var index = exports.RESERVED_FIELD_NAMES.indexOf(field);
var index = exports.RESERVED_NAMES.indexOf(field);
if (index > -1) index = exports.RESERVED_COLUMN_NAMES.indexOf(field);
if (index > -1)
throw new Error(field + ' is a reserved field name');
Expand Down
12 changes: 6 additions & 6 deletions test/api-configuration.test.js
Expand Up @@ -250,16 +250,16 @@ suite('Configuration API', function() {
Created: 'true',
Deleted: 'false',
DocService: {
Endpoint: 'doc-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
Endpoint: 'doc-companies-' + Domain.DEFAULT_ID + '.localhost'
},
DomainId: Domain.DEFAULT_DOMAIN_ID + '/companies',
DomainId: Domain.DEFAULT_ID + '/companies',
DomainName: 'companies',
NumSearchableDocs: '0',
RequiresIndexDocuments: 'false',
SearchInstanceCount: '0',
SearchPartitionCount: '0',
SearchService: {
Endpoint: 'search-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
Endpoint: 'search-companies-' + Domain.DEFAULT_ID + '.localhost'
}
};
var status = response.body.CreateDomainResponse.CreateDomainResult.DomainStatus;
Expand Down Expand Up @@ -293,16 +293,16 @@ suite('Configuration API', function() {
Created: 'false',
Deleted: 'true',
DocService: {
Endpoint: 'doc-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
Endpoint: 'doc-companies-' + Domain.DEFAULT_ID + '.localhost'
},
DomainId: Domain.DEFAULT_DOMAIN_ID + '/companies',
DomainId: Domain.DEFAULT_ID + '/companies',
DomainName: 'companies',
NumSearchableDocs: '0',
RequiresIndexDocuments: 'false',
SearchInstanceCount: '0',
SearchPartitionCount: '0',
SearchService: {
Endpoint: 'search-companies-' + Domain.DEFAULT_DOMAIN_ID + '.localhost'
Endpoint: 'search-companies-' + Domain.DEFAULT_ID + '.localhost'
}
};
var status = response.body.DeleteDomainResponse.DeleteDomainResult.DomainStatus;
Expand Down
2 changes: 1 addition & 1 deletion test/database-domain.test.js
Expand Up @@ -218,7 +218,7 @@ suite('database', function() {

test('id from database (unknown table)', function() {
domain = new Domain('unknown', context);
assert.equal(domain.id, Domain.DEFAULT_DOMAIN_ID);
assert.equal(domain.id, Domain.DEFAULT_ID);
});

test('indexFields', function() {
Expand Down

0 comments on commit 62ee887

Please sign in to comment.