@@ -129,6 +129,64 @@ Dataset.prototype.key = function(keyConfig) {
129
129
return new entity . Key ( keyConfig ) ;
130
130
} ;
131
131
132
+ /**
133
+ * Register a Kind's schema. You can later refer to the schema to validate an
134
+ * entity. See `validateKind` for an example.
135
+ *
136
+ * @param {string } kind - Name of the kind.
137
+ * @param {object } schema - Schema to register to the kind.
138
+ *
139
+ * @example
140
+ * ds.registerKind('Person', {
141
+ * name: {
142
+ * type: String
143
+ * },
144
+ * age: {
145
+ * type: datastore.int
146
+ * }
147
+ * });
148
+ */
149
+ Dataset . prototype . registerKind = function ( kind , schema ) {
150
+ var namespace = this . namespace ;
151
+ if ( util . is ( kind , 'object' ) ) {
152
+ namespace = kind . namespace ;
153
+ schema = kind . schema ;
154
+ kind = kind . name ;
155
+ }
156
+ entity . registerKind ( namespace , kind , schema ) ;
157
+ } ;
158
+
159
+ /**
160
+ * Validate a registered Kind's schema against an entity. This can be useful
161
+ * before saving a new entity to the Datastore.
162
+ *
163
+ * @param {string } kind - Name of the kind.
164
+ * @param {object } ent - Object to validate against the kind's schema.
165
+ * @return {booelan }
166
+ *
167
+ * @example
168
+ * // See how we registered the "Person" schema in the `registerKind` example.
169
+ *
170
+ * ds.validateKind('Person', {
171
+ * name: 'Abe Vigoda',
172
+ * age: datastore.int(93)
173
+ * });
174
+ * // true (`name` is a String, and `age` is an integer)
175
+ *
176
+ * ds.validateKind('Person', {
177
+ * name: 'Abe Vigoda'
178
+ * });
179
+ * // false (missing the `age` property)
180
+ */
181
+ Dataset . prototype . validateKind = function ( kind , ent ) {
182
+ var namespace = this . namespace ;
183
+ if ( util . is ( kind , 'object' ) ) {
184
+ namespace = kind . namespace ;
185
+ ent = kind . entity ;
186
+ kind = kind . name ;
187
+ }
188
+ return entity . validateKind ( namespace , kind , ent ) ;
189
+ } ;
132
190
133
191
/**
134
192
* Create a query from the current dataset to query the specified kinds, scoped
0 commit comments