Skip to content

Commit e6aeb95

Browse files
datastore - remove registerKind stub
1 parent cdd4138 commit e6aeb95

2 files changed

Lines changed: 0 additions & 144 deletions

File tree

lib/datastore/entity.js

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@
2121

2222
'use strict';
2323

24-
/** @type {object} */
25-
var entityMeta = {};
26-
27-
/** @const {regexp} Regular expression to verify a field name. */
28-
var FIELD_NAME_REGEX = /^[A-Za-z]*$/;
29-
30-
/** @const {regexp} Regular expression to verify a Kind. */
31-
var KIND_REGEX = /^[A-Za-z]*$/;
32-
33-
/** @const {regexp} Regular Expression to verify a namespace. */
34-
var NAMESPACE_REGEX = /^[A-Za-z]*$/;
35-
3624
/** @const {object} Map for query operation -> operation protocol value. */
3725
var OP_TO_OPERATOR = {
3826
'=': 'EQUAL',
@@ -43,16 +31,6 @@ var OP_TO_OPERATOR = {
4331
'HAS_ANCESTOR': 'HAS_ANCESTOR'
4432
};
4533

46-
/** @const {array} A list of native objects. */
47-
var PRIMITIVE_KINDS = [
48-
Object,
49-
Boolean,
50-
Number,
51-
String,
52-
Date,
53-
Buffer
54-
];
55-
5634
/** @const {object} Conversion map for query sign -> order protocol value. */
5735
var SIGN_TO_ORDER = {
5836
'-': 'DESCENDING',
@@ -592,102 +570,6 @@ function queryToQueryProto(q) {
592570

593571
module.exports.queryToQueryProto = queryToQueryProto;
594572

595-
/**
596-
* Register a kind and its field metadata globally. In order to perform CRUD
597-
* operations for a kind, you should register it with its field metadata.
598-
*
599-
* @private
600-
*
601-
* @todo Validate namespace, kind, and fieldMeta.
602-
*
603-
* @param {string} namespace - Namespace of the kind.
604-
* @param {string} kind - Name of the kind.
605-
* @param {object} fieldMeta - Metadata information about the fields.
606-
*
607-
* @example
608-
* registerKind('namespace', 'Author', {
609-
* name: { kind: String, indexed: false },
610-
* tags: { kind: String, multi: true }, // an array of string elements.
611-
* favArticles: { kind: KEY, multi: true },
612-
* contact: {
613-
* kind: {
614-
* telephone: { kind: String },
615-
* email: { kind: String }
616-
* }
617-
* }
618-
* });
619-
*/
620-
function registerKind(namespace, kind, fieldMeta) {
621-
// validate the input and put it to the dictionary
622-
namespace = namespace || '';
623-
if (!NAMESPACE_REGEX.test(namespace)) {
624-
throw new Error('Namespaces should match ' + NAMESPACE_REGEX);
625-
}
626-
if (!KIND_REGEX.test(kind)) {
627-
throw new Error('Kinds should match ' + KIND_REGEX);
628-
}
629-
630-
Object.keys(fieldMeta).forEach(function(fieldName) {
631-
validateField(fieldName, fieldMeta[fieldName]);
632-
});
633-
634-
if (!entityMeta[namespace]) {
635-
entityMeta[namespace] = {};
636-
}
637-
entityMeta[namespace][kind] = fieldMeta;
638-
}
639-
640-
module.exports.registerKind = registerKind;
641-
642-
/**
643-
* Get a Kind object.
644-
*
645-
* @private
646-
*
647-
* @param {string} namespace - The namespace of the kind.
648-
* @param {string} kind - The Datstore Kind.
649-
* @return {object}
650-
*/
651-
function getKind(namespace, kind) {
652-
return entityMeta[namespace] && entityMeta[namespace][kind];
653-
}
654-
655-
module.exports.getKind = getKind;
656-
657-
/**
658-
* Validate a field.
659-
*
660-
* @throws Throws an Error if the field doesn't validate.
661-
*
662-
* @param {string} name - Field name.
663-
* @param {object} field - Field metadata object.
664-
* @param {string} field.key - Field key.
665-
* @param {*} field.kind - Field Kind.
666-
*
667-
* @example
668-
* validateField('title', {
669-
* kind: String
670-
* });
671-
* // undefined (no errors thrown.)
672-
*/
673-
function validateField(name, field) {
674-
if (!FIELD_NAME_REGEX.test(name)) {
675-
throw new Error('Field name should match ' + FIELD_NAME_REGEX);
676-
}
677-
if (!field.kind) {
678-
throw new Error('Provide a kind for field ' + name);
679-
}
680-
if (typeof field.kind !== 'object' &&
681-
PRIMITIVE_KINDS.indexOf(field.kind) === -1) {
682-
throw new Error('Unknown kind for field ' + name);
683-
}
684-
if (typeof field.kind === 'object') {
685-
Object.keys(field.key).forEach(function(key) {
686-
validateField(key, field.key[key]);
687-
});
688-
}
689-
}
690-
691573
/**
692574
* Does a value exist?
693575
*

test/datastore/entity.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ var entity = require('../../lib/datastore/entity.js');
2323
var datastore = require('../../lib/datastore');
2424
var ByteBuffer = require('bytebuffer');
2525

26-
var blogPostMetadata = {
27-
title: { kind: String, indexed: true },
28-
tags: { kind: String, multi: true, indexed: true },
29-
publishedAt: { kind: Date },
30-
author: { kind: Object, indexed: true },
31-
isDraft: { kind: Boolean, indexed: true }
32-
};
33-
3426
var entityProto = {
3527
'property': [{
3628
'name': 'linkedTo',
@@ -121,24 +113,6 @@ var queryFilterProto = {
121113
group_by: []
122114
};
123115

124-
describe('registerKind', function() {
125-
it('should be able to register valid field metadata', function() {
126-
entity.registerKind('namespace', 'kind', blogPostMetadata);
127-
});
128-
129-
it('should set the namespace to "" if zero value or null', function() {
130-
entity.registerKind(null, 'kind', blogPostMetadata);
131-
var meta = entity.getKind('', 'kind');
132-
assert.strictEqual(meta, blogPostMetadata);
133-
});
134-
135-
it('should throw an exception if an invalid kind', function() {
136-
assert.throws(function() {
137-
entity.registerKind(null, '000', blogPostMetadata);
138-
}, /Kinds should match/);
139-
});
140-
});
141-
142116
describe('keyFromKeyProto', function() {
143117
var proto = {
144118
partition_id: { namespace: '', dataset_id: 'datasetId' },

0 commit comments

Comments
 (0)