From e6aeb95c6c5d404214fe8d187eb14f05abbe1021 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Tue, 3 Feb 2015 10:16:40 -0500 Subject: [PATCH] datastore - remove registerKind stub --- lib/datastore/entity.js | 118 --------------------------------------- test/datastore/entity.js | 26 --------- 2 files changed, 144 deletions(-) diff --git a/lib/datastore/entity.js b/lib/datastore/entity.js index f5b14fe7fe1..adfe1186987 100644 --- a/lib/datastore/entity.js +++ b/lib/datastore/entity.js @@ -21,18 +21,6 @@ 'use strict'; -/** @type {object} */ -var entityMeta = {}; - -/** @const {regexp} Regular expression to verify a field name. */ -var FIELD_NAME_REGEX = /^[A-Za-z]*$/; - -/** @const {regexp} Regular expression to verify a Kind. */ -var KIND_REGEX = /^[A-Za-z]*$/; - -/** @const {regexp} Regular Expression to verify a namespace. */ -var NAMESPACE_REGEX = /^[A-Za-z]*$/; - /** @const {object} Map for query operation -> operation protocol value. */ var OP_TO_OPERATOR = { '=': 'EQUAL', @@ -43,16 +31,6 @@ var OP_TO_OPERATOR = { 'HAS_ANCESTOR': 'HAS_ANCESTOR' }; -/** @const {array} A list of native objects. */ -var PRIMITIVE_KINDS = [ - Object, - Boolean, - Number, - String, - Date, - Buffer -]; - /** @const {object} Conversion map for query sign -> order protocol value. */ var SIGN_TO_ORDER = { '-': 'DESCENDING', @@ -592,102 +570,6 @@ function queryToQueryProto(q) { module.exports.queryToQueryProto = queryToQueryProto; -/** - * Register a kind and its field metadata globally. In order to perform CRUD - * operations for a kind, you should register it with its field metadata. - * - * @private - * - * @todo Validate namespace, kind, and fieldMeta. - * - * @param {string} namespace - Namespace of the kind. - * @param {string} kind - Name of the kind. - * @param {object} fieldMeta - Metadata information about the fields. - * - * @example - * registerKind('namespace', 'Author', { - * name: { kind: String, indexed: false }, - * tags: { kind: String, multi: true }, // an array of string elements. - * favArticles: { kind: KEY, multi: true }, - * contact: { - * kind: { - * telephone: { kind: String }, - * email: { kind: String } - * } - * } - * }); - */ -function registerKind(namespace, kind, fieldMeta) { - // validate the input and put it to the dictionary - namespace = namespace || ''; - if (!NAMESPACE_REGEX.test(namespace)) { - throw new Error('Namespaces should match ' + NAMESPACE_REGEX); - } - if (!KIND_REGEX.test(kind)) { - throw new Error('Kinds should match ' + KIND_REGEX); - } - - Object.keys(fieldMeta).forEach(function(fieldName) { - validateField(fieldName, fieldMeta[fieldName]); - }); - - if (!entityMeta[namespace]) { - entityMeta[namespace] = {}; - } - entityMeta[namespace][kind] = fieldMeta; -} - -module.exports.registerKind = registerKind; - -/** - * Get a Kind object. - * - * @private - * - * @param {string} namespace - The namespace of the kind. - * @param {string} kind - The Datstore Kind. - * @return {object} - */ -function getKind(namespace, kind) { - return entityMeta[namespace] && entityMeta[namespace][kind]; -} - -module.exports.getKind = getKind; - -/** - * Validate a field. - * - * @throws Throws an Error if the field doesn't validate. - * - * @param {string} name - Field name. - * @param {object} field - Field metadata object. - * @param {string} field.key - Field key. - * @param {*} field.kind - Field Kind. - * - * @example - * validateField('title', { - * kind: String - * }); - * // undefined (no errors thrown.) - */ -function validateField(name, field) { - if (!FIELD_NAME_REGEX.test(name)) { - throw new Error('Field name should match ' + FIELD_NAME_REGEX); - } - if (!field.kind) { - throw new Error('Provide a kind for field ' + name); - } - if (typeof field.kind !== 'object' && - PRIMITIVE_KINDS.indexOf(field.kind) === -1) { - throw new Error('Unknown kind for field ' + name); - } - if (typeof field.kind === 'object') { - Object.keys(field.key).forEach(function(key) { - validateField(key, field.key[key]); - }); - } -} - /** * Does a value exist? * diff --git a/test/datastore/entity.js b/test/datastore/entity.js index e3bb9c2250e..88fecfabd66 100644 --- a/test/datastore/entity.js +++ b/test/datastore/entity.js @@ -23,14 +23,6 @@ var entity = require('../../lib/datastore/entity.js'); var datastore = require('../../lib/datastore'); var ByteBuffer = require('bytebuffer'); -var blogPostMetadata = { - title: { kind: String, indexed: true }, - tags: { kind: String, multi: true, indexed: true }, - publishedAt: { kind: Date }, - author: { kind: Object, indexed: true }, - isDraft: { kind: Boolean, indexed: true } -}; - var entityProto = { 'property': [{ 'name': 'linkedTo', @@ -121,24 +113,6 @@ var queryFilterProto = { group_by: [] }; -describe('registerKind', function() { - it('should be able to register valid field metadata', function() { - entity.registerKind('namespace', 'kind', blogPostMetadata); - }); - - it('should set the namespace to "" if zero value or null', function() { - entity.registerKind(null, 'kind', blogPostMetadata); - var meta = entity.getKind('', 'kind'); - assert.strictEqual(meta, blogPostMetadata); - }); - - it('should throw an exception if an invalid kind', function() { - assert.throws(function() { - entity.registerKind(null, '000', blogPostMetadata); - }, /Kinds should match/); - }); -}); - describe('keyFromKeyProto', function() { var proto = { partition_id: { namespace: '', dataset_id: 'datasetId' },