breeze-client 2.2.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +83 -63
  3. package/adapters/abstract-data-service-adapter.d.ts +120 -0
  4. package/adapters/abstract-data-service-adapter.js +395 -0
  5. package/adapters/abstract-data-service-adapter.js.map +1 -0
  6. package/adapters/adapter-ajax-fetch.d.ts +12 -0
  7. package/adapters/adapter-ajax-fetch.js +13 -0
  8. package/adapters/adapter-ajax-fetch.js.map +1 -0
  9. package/{adapter-ajax-post → adapters}/adapter-ajax-post.d.ts +40 -36
  10. package/{fesm2022/breeze-client-adapter-ajax-post.mjs → adapters/adapter-ajax-post.js} +80 -82
  11. package/adapters/adapter-ajax-post.js.map +1 -0
  12. package/{adapter-ajax-fetch → adapters}/adapter-core.d.ts +4 -4
  13. package/{fesm2022/breeze-client-adapter-uri-builder-json.mjs → adapters/adapter-core.js} +48 -91
  14. package/adapters/adapter-core.js.map +1 -0
  15. package/adapters/adapter-data-service-webapi.d.ts +9 -0
  16. package/{fesm2022/breeze-client-adapter-data-service-webapi.mjs → adapters/adapter-data-service-webapi.js} +105 -107
  17. package/adapters/adapter-data-service-webapi.js.map +1 -0
  18. package/adapters/adapter-model-library-backing-store.d.ts +32 -0
  19. package/adapters/adapter-model-library-backing-store.js +321 -0
  20. package/adapters/adapter-model-library-backing-store.js.map +1 -0
  21. package/adapters/adapter-uri-builder-json.d.ts +11 -0
  22. package/adapters/adapter-uri-builder-json.js +40 -0
  23. package/adapters/adapter-uri-builder-json.js.map +1 -0
  24. package/adapters/http.d.ts +52 -0
  25. package/adapters/http.js +202 -0
  26. package/adapters/http.js.map +1 -0
  27. package/angular/adapter-angular-httpclient.d.ts +21 -0
  28. package/angular/adapter-angular-httpclient.js +70 -0
  29. package/angular/adapter-angular-httpclient.js.map +1 -0
  30. package/breeze.d.ts +215 -0
  31. package/breeze.js +141 -0
  32. package/breeze.js.map +1 -0
  33. package/config/config.d.ts +212 -0
  34. package/config/config.js +392 -0
  35. package/config/config.js.map +1 -0
  36. package/config/configure.d.ts +66 -0
  37. package/config/configure.js +46 -0
  38. package/config/configure.js.map +1 -0
  39. package/config/default-adapters.d.ts +1 -0
  40. package/config/default-adapters.js +40 -0
  41. package/config/default-adapters.js.map +1 -0
  42. package/config/interface-registry.d.ts +191 -0
  43. package/config/interface-registry.js +5 -0
  44. package/config/interface-registry.js.map +1 -0
  45. package/{src → core}/assert-param.d.ts +52 -60
  46. package/core/assert-param.js +390 -0
  47. package/core/assert-param.js.map +1 -0
  48. package/core/core.d.ts +285 -0
  49. package/core/core.js +772 -0
  50. package/core/core.js.map +1 -0
  51. package/core/enum.d.ts +116 -0
  52. package/core/enum.js +167 -0
  53. package/core/enum.js.map +1 -0
  54. package/core/event.d.ts +169 -0
  55. package/core/event.js +338 -0
  56. package/core/event.js.map +1 -0
  57. package/entity/array.d.ts +3 -0
  58. package/entity/array.js +4 -0
  59. package/entity/array.js.map +1 -0
  60. package/entity/complex-array.d.ts +17 -0
  61. package/entity/complex-array.js +104 -0
  62. package/entity/complex-array.js.map +1 -0
  63. package/entity/default-property-interceptor.d.ts +1 -0
  64. package/entity/default-property-interceptor.js +496 -0
  65. package/entity/default-property-interceptor.js.map +1 -0
  66. package/{src → entity}/entity-action.d.ts +36 -42
  67. package/entity/entity-action.js +45 -0
  68. package/entity/entity-action.js.map +1 -0
  69. package/entity/entity-aspect.d.ts +457 -0
  70. package/entity/entity-aspect.js +1262 -0
  71. package/entity/entity-aspect.js.map +1 -0
  72. package/entity/entity-base.d.ts +55 -0
  73. package/entity/entity-base.js +41 -0
  74. package/entity/entity-base.js.map +1 -0
  75. package/entity/entity-group.d.ts +1 -0
  76. package/entity/entity-group.js +224 -0
  77. package/entity/entity-group.js.map +1 -0
  78. package/entity/entity-key.d.ts +95 -0
  79. package/entity/entity-key.js +189 -0
  80. package/entity/entity-key.js.map +1 -0
  81. package/{src → entity}/entity-state.d.ts +112 -84
  82. package/entity/entity-state.js +135 -0
  83. package/entity/entity-state.js.map +1 -0
  84. package/entity/key-generator.d.ts +57 -0
  85. package/entity/key-generator.js +155 -0
  86. package/entity/key-generator.js.map +1 -0
  87. package/entity/observable-array.d.ts +25 -0
  88. package/entity/observable-array.js +230 -0
  89. package/entity/observable-array.js.map +1 -0
  90. package/entity/primitive-array.d.ts +12 -0
  91. package/entity/primitive-array.js +71 -0
  92. package/entity/primitive-array.js.map +1 -0
  93. package/entity/relation-array.d.ts +24 -0
  94. package/entity/relation-array.js +176 -0
  95. package/entity/relation-array.js.map +1 -0
  96. package/entity/unattached-children-map.d.ts +1 -0
  97. package/entity/unattached-children-map.js +105 -0
  98. package/entity/unattached-children-map.js.map +1 -0
  99. package/generate-entity-classes.js +1176 -0
  100. package/manager/entity-manager.d.ts +801 -0
  101. package/manager/entity-manager.js +2395 -0
  102. package/manager/entity-manager.js.map +1 -0
  103. package/{src → manager}/save-options.d.ts +48 -42
  104. package/manager/save-options.js +51 -0
  105. package/manager/save-options.js.map +1 -0
  106. package/{src → metadata}/data-service.d.ts +229 -184
  107. package/metadata/data-service.js +246 -0
  108. package/metadata/data-service.js.map +1 -0
  109. package/metadata/data-type.d.ts +122 -0
  110. package/metadata/data-type.js +465 -0
  111. package/metadata/data-type.js.map +1 -0
  112. package/metadata/entity-metadata.d.ts +1193 -0
  113. package/metadata/entity-metadata.js +2502 -0
  114. package/metadata/entity-metadata.js.map +1 -0
  115. package/{src → metadata}/local-query-comparison-options.d.ts +65 -59
  116. package/metadata/local-query-comparison-options.js +69 -0
  117. package/metadata/local-query-comparison-options.js.map +1 -0
  118. package/{src → metadata}/naming-convention.d.ts +75 -72
  119. package/metadata/naming-convention.js +97 -0
  120. package/metadata/naming-convention.js.map +1 -0
  121. package/mixins/mixin-get-entity-graph.d.ts +63 -0
  122. package/{fesm2022/breeze-client-mixin-get-entity-graph.mjs → mixins/mixin-get-entity-graph.js} +331 -253
  123. package/mixins/mixin-get-entity-graph.js.map +1 -0
  124. package/mixins/mixin-save-queuing.d.ts +98 -0
  125. package/{fesm2022/breeze-client-mixin-save-queuing.mjs → mixins/mixin-save-queuing.js} +493 -365
  126. package/mixins/mixin-save-queuing.js.map +1 -0
  127. package/package.json +63 -94
  128. package/query/entity-query.d.ts +521 -0
  129. package/query/entity-query.js +1149 -0
  130. package/query/entity-query.js.map +1 -0
  131. package/{src → query}/mapping-context.d.ts +44 -46
  132. package/query/mapping-context.js +412 -0
  133. package/query/mapping-context.js.map +1 -0
  134. package/query/predicate.d.ts +394 -0
  135. package/query/predicate.js +1294 -0
  136. package/query/predicate.js.map +1 -0
  137. package/query/property-path.d.ts +252 -0
  138. package/query/property-path.js +2 -0
  139. package/query/property-path.js.map +1 -0
  140. package/{src → query}/query-options.d.ts +143 -119
  141. package/query/query-options.js +180 -0
  142. package/query/query-options.js.map +1 -0
  143. package/rxjs/breeze-rxjs.d.ts +72 -0
  144. package/rxjs/breeze-rxjs.js +117 -0
  145. package/rxjs/breeze-rxjs.js.map +1 -0
  146. package/validation/validate.d.ts +583 -0
  147. package/validation/validate.js +961 -0
  148. package/validation/validate.js.map +1 -0
  149. package/{src → validation}/validation-options.d.ts +67 -63
  150. package/validation/validation-options.js +70 -0
  151. package/validation/validation-options.js.map +1 -0
  152. package/adapter-ajax-angularjs/adapter-ajax-angularjs.d.ts +0 -17
  153. package/adapter-ajax-angularjs/adapter-core.d.ts +0 -4
  154. package/adapter-ajax-angularjs/index.d.ts +0 -5
  155. package/adapter-ajax-fetch/adapter-ajax-fetch.d.ts +0 -18
  156. package/adapter-ajax-fetch/index.d.ts +0 -5
  157. package/adapter-ajax-httpclient/adapter-ajax-httpclient.d.ts +0 -13
  158. package/adapter-ajax-httpclient/adapter-core.d.ts +0 -4
  159. package/adapter-ajax-httpclient/index.d.ts +0 -5
  160. package/adapter-ajax-jquery/adapter-ajax-jquery.d.ts +0 -15
  161. package/adapter-ajax-jquery/index.d.ts +0 -5
  162. package/adapter-ajax-post/index.d.ts +0 -5
  163. package/adapter-data-service-odata/adapter-core.d.ts +0 -4
  164. package/adapter-data-service-odata/adapter-data-service-odata.d.ts +0 -17
  165. package/adapter-data-service-odata/index.d.ts +0 -5
  166. package/adapter-data-service-webapi/adapter-data-service-webapi.d.ts +0 -15
  167. package/adapter-data-service-webapi/index.d.ts +0 -5
  168. package/adapter-model-library-backing-store/adapter-model-library-backing-store.d.ts +0 -10
  169. package/adapter-model-library-backing-store/index.d.ts +0 -5
  170. package/adapter-model-library-ko/adapter-model-library-ko.d.ts +0 -10
  171. package/adapter-model-library-ko/index.d.ts +0 -5
  172. package/adapter-uri-builder-json/adapter-core.d.ts +0 -4
  173. package/adapter-uri-builder-json/adapter-uri-builder-json.d.ts +0 -8
  174. package/adapter-uri-builder-json/index.d.ts +0 -5
  175. package/adapter-uri-builder-odata/adapter-core.d.ts +0 -4
  176. package/adapter-uri-builder-odata/adapter-uri-builder-odata.d.ts +0 -8
  177. package/adapter-uri-builder-odata/index.d.ts +0 -5
  178. package/esm2022/adapter-ajax-angularjs/adapter-ajax-angularjs.mjs +0 -135
  179. package/esm2022/adapter-ajax-angularjs/adapter-core.mjs +0 -49
  180. package/esm2022/adapter-ajax-angularjs/breeze-client-adapter-ajax-angularjs.mjs +0 -5
  181. package/esm2022/adapter-ajax-fetch/adapter-ajax-fetch.mjs +0 -135
  182. package/esm2022/adapter-ajax-fetch/adapter-core.mjs +0 -49
  183. package/esm2022/adapter-ajax-fetch/breeze-client-adapter-ajax-fetch.mjs +0 -5
  184. package/esm2022/adapter-ajax-httpclient/adapter-ajax-httpclient.mjs +0 -139
  185. package/esm2022/adapter-ajax-httpclient/adapter-core.mjs +0 -49
  186. package/esm2022/adapter-ajax-httpclient/breeze-client-adapter-ajax-httpclient.mjs +0 -5
  187. package/esm2022/adapter-ajax-jquery/adapter-ajax-jquery.mjs +0 -107
  188. package/esm2022/adapter-ajax-jquery/breeze-client-adapter-ajax-jquery.mjs +0 -5
  189. package/esm2022/adapter-ajax-post/adapter-ajax-post.mjs +0 -77
  190. package/esm2022/adapter-ajax-post/breeze-client-adapter-ajax-post.mjs +0 -5
  191. package/esm2022/adapter-data-service-odata/adapter-core.mjs +0 -49
  192. package/esm2022/adapter-data-service-odata/adapter-data-service-odata.mjs +0 -461
  193. package/esm2022/adapter-data-service-odata/breeze-client-adapter-data-service-odata.mjs +0 -5
  194. package/esm2022/adapter-data-service-webapi/adapter-data-service-webapi.mjs +0 -100
  195. package/esm2022/adapter-data-service-webapi/breeze-client-adapter-data-service-webapi.mjs +0 -5
  196. package/esm2022/adapter-model-library-backing-store/adapter-model-library-backing-store.mjs +0 -269
  197. package/esm2022/adapter-model-library-backing-store/breeze-client-adapter-model-library-backing-store.mjs +0 -5
  198. package/esm2022/adapter-model-library-ko/adapter-model-library-ko.mjs +0 -241
  199. package/esm2022/adapter-model-library-ko/breeze-client-adapter-model-library-ko.mjs +0 -5
  200. package/esm2022/adapter-uri-builder-json/adapter-core.mjs +0 -49
  201. package/esm2022/adapter-uri-builder-json/adapter-uri-builder-json.mjs +0 -37
  202. package/esm2022/adapter-uri-builder-json/breeze-client-adapter-uri-builder-json.mjs +0 -5
  203. package/esm2022/adapter-uri-builder-odata/adapter-core.mjs +0 -49
  204. package/esm2022/adapter-uri-builder-odata/adapter-uri-builder-odata.mjs +0 -191
  205. package/esm2022/adapter-uri-builder-odata/breeze-client-adapter-uri-builder-odata.mjs +0 -5
  206. package/esm2022/breeze-client.mjs +0 -5
  207. package/esm2022/index.mjs +0 -2
  208. package/esm2022/mixin-get-entity-graph/breeze-client-mixin-get-entity-graph.mjs +0 -5
  209. package/esm2022/mixin-get-entity-graph/mixin-get-entity-graph.mjs +0 -269
  210. package/esm2022/mixin-save-queuing/breeze-client-mixin-save-queuing.mjs +0 -5
  211. package/esm2022/mixin-save-queuing/mixin-save-queuing.mjs +0 -421
  212. package/esm2022/src/abstract-data-service-adapter.mjs +0 -325
  213. package/esm2022/src/array.mjs +0 -4
  214. package/esm2022/src/assert-param.mjs +0 -330
  215. package/esm2022/src/breeze.mjs +0 -85
  216. package/esm2022/src/complex-array.mjs +0 -117
  217. package/esm2022/src/config.mjs +0 -232
  218. package/esm2022/src/core.mjs +0 -712
  219. package/esm2022/src/csdl-metadata-parser.mjs +0 -385
  220. package/esm2022/src/data-service.mjs +0 -221
  221. package/esm2022/src/data-type.mjs +0 -510
  222. package/esm2022/src/default-property-interceptor.mjs +0 -460
  223. package/esm2022/src/entity-action.mjs +0 -45
  224. package/esm2022/src/entity-aspect.mjs +0 -897
  225. package/esm2022/src/entity-group.mjs +0 -192
  226. package/esm2022/src/entity-key.mjs +0 -125
  227. package/esm2022/src/entity-manager.mjs +0 -2163
  228. package/esm2022/src/entity-metadata.mjs +0 -2242
  229. package/esm2022/src/entity-query.mjs +0 -1024
  230. package/esm2022/src/entity-state.mjs +0 -107
  231. package/esm2022/src/enum.mjs +0 -143
  232. package/esm2022/src/event.mjs +0 -264
  233. package/esm2022/src/interface-registry.mjs +0 -39
  234. package/esm2022/src/key-generator.mjs +0 -110
  235. package/esm2022/src/local-query-comparison-options.mjs +0 -65
  236. package/esm2022/src/mapping-context.mjs +0 -411
  237. package/esm2022/src/naming-convention.mjs +0 -92
  238. package/esm2022/src/observable-array.mjs +0 -183
  239. package/esm2022/src/predicate.mjs +0 -1259
  240. package/esm2022/src/primitive-array.mjs +0 -85
  241. package/esm2022/src/query-options.mjs +0 -152
  242. package/esm2022/src/relation-array.mjs +0 -173
  243. package/esm2022/src/save-options.mjs +0 -41
  244. package/esm2022/src/unattached-children-map.mjs +0 -56
  245. package/esm2022/src/validate.mjs +0 -995
  246. package/esm2022/src/validation-options.mjs +0 -64
  247. package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs +0 -190
  248. package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs.map +0 -1
  249. package/fesm2022/breeze-client-adapter-ajax-fetch.mjs +0 -190
  250. package/fesm2022/breeze-client-adapter-ajax-fetch.mjs.map +0 -1
  251. package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs +0 -194
  252. package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs.map +0 -1
  253. package/fesm2022/breeze-client-adapter-ajax-jquery.mjs +0 -114
  254. package/fesm2022/breeze-client-adapter-ajax-jquery.mjs.map +0 -1
  255. package/fesm2022/breeze-client-adapter-ajax-post.mjs.map +0 -1
  256. package/fesm2022/breeze-client-adapter-data-service-odata.mjs +0 -516
  257. package/fesm2022/breeze-client-adapter-data-service-odata.mjs.map +0 -1
  258. package/fesm2022/breeze-client-adapter-data-service-webapi.mjs.map +0 -1
  259. package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs +0 -276
  260. package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs.map +0 -1
  261. package/fesm2022/breeze-client-adapter-model-library-ko.mjs +0 -248
  262. package/fesm2022/breeze-client-adapter-model-library-ko.mjs.map +0 -1
  263. package/fesm2022/breeze-client-adapter-uri-builder-json.mjs.map +0 -1
  264. package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs +0 -246
  265. package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs.map +0 -1
  266. package/fesm2022/breeze-client-mixin-get-entity-graph.mjs.map +0 -1
  267. package/fesm2022/breeze-client-mixin-save-queuing.mjs.map +0 -1
  268. package/fesm2022/breeze-client.mjs +0 -14144
  269. package/fesm2022/breeze-client.mjs.map +0 -1
  270. package/index.d.ts +0 -1
  271. package/mixin-get-entity-graph/index.d.ts +0 -5
  272. package/mixin-get-entity-graph/mixin-get-entity-graph.d.ts +0 -31
  273. package/mixin-save-queuing/index.d.ts +0 -5
  274. package/mixin-save-queuing/mixin-save-queuing.d.ts +0 -32
  275. package/src/abstract-data-service-adapter.d.ts +0 -84
  276. package/src/array.d.ts +0 -3
  277. package/src/breeze.d.ts +0 -139
  278. package/src/complex-array.d.ts +0 -13
  279. package/src/config.d.ts +0 -104
  280. package/src/core.d.ts +0 -164
  281. package/src/csdl-metadata-parser.d.ts +0 -7
  282. package/src/data-type.d.ts +0 -89
  283. package/src/default-property-interceptor.d.ts +0 -4
  284. package/src/entity-aspect.d.ts +0 -332
  285. package/src/entity-group.d.ts +0 -28
  286. package/src/entity-key.d.ts +0 -77
  287. package/src/entity-manager.d.ts +0 -680
  288. package/src/entity-metadata.d.ts +0 -988
  289. package/src/entity-query.d.ts +0 -444
  290. package/src/enum.d.ts +0 -100
  291. package/src/event.d.ts +0 -142
  292. package/src/interface-registry.d.ts +0 -150
  293. package/src/key-generator.d.ts +0 -12
  294. package/src/observable-array.d.ts +0 -52
  295. package/src/predicate.d.ts +0 -376
  296. package/src/primitive-array.d.ts +0 -7
  297. package/src/relation-array.d.ts +0 -18
  298. package/src/unattached-children-map.d.ts +0 -19
  299. package/src/validate.d.ts +0 -650
package/src/validate.d.ts DELETED
@@ -1,650 +0,0 @@
1
- import { NavigationProperty, DataProperty } from './entity-metadata';
2
- import { Entity } from './entity-aspect';
3
- export declare const INT16_MIN = -32768;
4
- export declare const INT16_MAX = 32767;
5
- export declare const INT32_MIN = -2147483648;
6
- export declare const INT32_MAX = 2147483647;
7
- export declare const BYTE_MIN = 0;
8
- export declare const BYTE_MAX = 255;
9
- /** Passed to ValidationFn */
10
- export interface ValidationContext {
11
- entity?: Entity;
12
- property?: DataProperty | NavigationProperty;
13
- propertyName?: string;
14
- value?: any;
15
- }
16
- /** Used by Validator to compose messages */
17
- export interface ValidationMessageContext extends ValidationContext {
18
- name?: string;
19
- displayName?: string;
20
- messageTemplate?: string;
21
- message?: string | ((vc: ValidationContext) => string);
22
- [key: string]: any;
23
- }
24
- /** Function called to validate an entity or property */
25
- export interface ValidationFn {
26
- (value: any, context?: ValidationContext): boolean;
27
- }
28
- /**
29
- Instances of the Validator class provide the logic to validate another object and provide a description of any errors
30
- encountered during the validation process. They are typically associated with a 'validators' property on the following types: [[EntityType]],
31
- [[DataProperty]] or [[NavigationProperty]].
32
-
33
- A number of property level validators are registered automatically, i.e added to each DataProperty.validators property
34
- based on [[DataProperty]] metadata. For example,
35
-
36
- - DataProperty.dataType -> one of the 'dataType' validator methods such as Validator.int64, Validator.date, Validator.bool etc.
37
- - DataProperty.maxLength -> Validator.maxLength
38
- - DataProperty.isNullable -> Validator.required (if not nullable)
39
-
40
- @class Validator
41
- **/
42
- /**
43
- Validator constructor - This method is used to create create custom validations. Several
44
- basic "Validator" construction methods are also provided as static methods to this class. These methods
45
- provide a simpler syntax for creating basic validations.
46
-
47
- Many of these stock validators are inspired by and implemented to conform to the validators defined at
48
- http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx
49
-
50
- Sometimes a custom validator will be required.
51
- @example
52
- Most validators will be 'property' level validators, like this.
53
- @example
54
- // v is this function is the value to be validated, in this case a "country" string.
55
- var valFn = function (v) {
56
- if (v == null) return true;
57
- return (core.stringStartsWith(v, "US"));
58
- };
59
- var countryValidator = new Validator("countryIsUS", valFn, {
60
- displayName: "Country",
61
- messageTemplate: "'%displayName%' must start with 'US'"
62
- });
63
-
64
- // Now plug it into Breeze.
65
- // Assume em1 is a preexisting EntityManager.
66
- var custType = metadataStore.getEntityType("Customer");
67
- var countryProp = custType.getProperty("Country");
68
- // Note that validator is added to a 'DataProperty' validators collection.
69
- prop.validators.push(countryValidator);
70
- Entity level validators are also possible
71
- @example
72
- function isValidZipCode(value) {
73
- var re = /^\d{5}([\-]\d{4})?$/;
74
- return (re.test(value));
75
- }
76
-
77
- // v in this case will be a Customer entity
78
- var valFn = function (v) {
79
- // This validator only validates US Zip Codes.
80
- if ( v.getProperty("Country") === "USA") {
81
- var postalCode = v.getProperty("PostalCode");
82
- return isValidZipCode(postalCode);
83
- }
84
- return true;
85
- };
86
- var zipCodeValidator = new Validator("zipCodeValidator", valFn,
87
- { messageTemplate: "For the US, this is not a valid PostalCode" });
88
-
89
- // Now plug it into Breeze.
90
- // Assume em1 is a preexisting EntityManager.
91
- var custType = em1.metadataStore.getEntityType("Customer");
92
- // Note that validator is added to an 'EntityType' validators collection.
93
- custType.validators.push(zipCodeValidator);
94
- What is commonly needed is a way of creating a parameterized function that will itself
95
- return a new Validator. This requires the use of a 'context' object.
96
- @example
97
- // create a function that will take in a config object
98
- // and will return a validator
99
- var numericRangeValidator = function(context) {
100
- var valFn = function(v, ctx) {
101
- if (v == null) return true;
102
- if (typeof(v) !== "number") return false;
103
- if (ctx.min != null && v < ctx.min) return false;
104
- if (ctx.max != null && v > ctx.max) return false;
105
- return true;
106
- };
107
- // The last parameter below is the 'context' object that will be passed into the 'ctx' parameter above
108
- // when this validator executes. Several other properties, such as displayName will get added to this object as well.
109
- return new Validator("numericRange", valFn, {
110
- messageTemplate: "'%displayName%' must be a number between the values of %min% and %max%",
111
- min: context.min,
112
- max: context.max
113
- });
114
- };
115
- // Assume that freightProperty is a DataEntityProperty that describes numeric values.
116
- // register the validator
117
- freightProperty.validators.push(numericRangeValidator({ min: 100, max: 500 }));
118
-
119
- Breeze substitutes context values and functions for the tokens in the messageTemplate when preparing the runtime error message;
120
- 'displayName' is a pre-defined context function that is always available.
121
-
122
- Please note that Breeze substitutes the empty string for falsey parameters. That usually works in your favor.
123
- Sometimes it doesn't as when the 'min' value is zero in which case the message text would have a hole
124
- where the 'min' value goes, saying: "... an integer between the values of and ...". That is not what you want.
125
-
126
- To avoid this effect, you may can bake certain of the context values into the 'messageTemplate' itself
127
- as shown in this revision to the pertinent part of the previous example:
128
- @example
129
- // ... as before
130
- // ... but bake the min/max values into the message template.
131
- var template = breeze.core.formatString(
132
- "'%displayName%' must be a number between the values of %1 and %2",
133
- context.min, context.max);
134
- return new Validator("numericRange", valFn, {
135
- messageTemplate: template,
136
- min: context.min,
137
- max: context.max
138
- });
139
-
140
- @method <ctor> Validator
141
- @param name {String} The name of this validator.
142
- @param validatorFn {Function} A function to perform validation.
143
-
144
- validatorFn(value, context)
145
- @param validatorFn.value {Object} Value to be validated
146
- @param validatorFn.context {Object} The same context object passed into the constructor with the following additional properties if not
147
- otherwise specified.
148
- @param validatorFn.context.value {Object} The value being validated.
149
- @param validatorFn.context.name {String} The name of the validator being executed.
150
- @param validatorFn.context.displayName {String} This will be either the value of the property's 'displayName' property or
151
- the value of its 'name' property or the string 'Value'
152
- @param validatorFn.context.messageTemplate {String} This will either be the value of Validator.messageTemplates[ {this validators name}] or null. Validator.messageTemplates
153
- is an object that is keyed by validator name and that can be added to in order to 'register' your own message for a given validator.
154
- The following property can also be specified for any validator to force a specific errorMessage string
155
- @param [validatorFn.context.message] {String} If this property is set it will be used instead of the 'messageTemplate' property when an
156
- error message is generated.
157
-
158
- @param [context] {Object} A free form object whose properties will made available during the validation and error message creation process.
159
- This object will be passed into the Validator's validation function whenever 'validate' is called. See above for a description
160
- of additional properties that will be automatically added to this object if not otherwise specified.
161
- @dynamic
162
- **/
163
- export declare class Validator {
164
- /** @hidden @internal */
165
- _$typeName: string;
166
- name: string;
167
- valFn: ValidationFn;
168
- context: ValidationMessageContext;
169
- currentContext: ValidationMessageContext;
170
- private _baseContext;
171
- constructor(name: string, valFn: ValidationFn, context?: ValidationMessageContext);
172
- /**
173
- The name of this validator.
174
-
175
- __readOnly__
176
- @property name {String}
177
- **/
178
- /**
179
- The context for this validator.
180
-
181
- This object will typically contain at a minimum the following properties. "name", "displayName", and "message" or "messageTemplate".
182
- __readOnly__
183
- @property context {Object}
184
- **/
185
- /**
186
- Run this validator against the specified value. This method will usually be called internally either
187
- automatically by an property change, entity attach, query or save operation, or manually as a result of
188
- a validateEntity call on the EntityAspect. The resulting ValidationResults are available via the
189
- EntityAspect.getValidationErrors method.
190
-
191
- However, you can also call a validator directly either for testing purposes or some other reason if needed.
192
- @example
193
- // using one of the predefined validators
194
- var validator = Validator.maxLength({ maxLength: 5, displayName: "City" });
195
- // should be ok because "asdf".length < 5
196
- var result = validator.validate("asdf");
197
- ok(result === null);
198
- result = validator.validate("adasdfasdf");
199
- // extract all of the properties of the 'result'
200
- var errMsg = result.errorMessage;
201
- var context = result.context;
202
- var sameValidator = result.validator;
203
- @method validate
204
- @param value {Object} Value to validate
205
- @param additionalContext {Object} Any additional contextual information that the Validator
206
- can make use of.
207
- @return {ValidationError|null} A ValidationError if validation fails, null otherwise
208
- **/
209
- validate(value: any, additionalContext?: ValidationMessageContext): ValidationError;
210
- /**
211
- Returns the message generated by the most recent execution of this Validator.
212
- @example
213
- var v0 = Validator.maxLength({ maxLength: 5, displayName: "City" });
214
- v0.validate("adasdfasdf");
215
- var errMessage = v0.getMessage());
216
- @method getMessage
217
- @return {String}
218
- **/
219
- getMessage(): string;
220
- toJSON(): ValidationMessageContext;
221
- /**
222
- Creates a validator instance from a JSON object or an array of instances from an array of JSON objects.
223
- @method fromJSON
224
- @static
225
- @param json {Object} JSON object that represents the serialized version of a validator.
226
- **/
227
- static fromJSON(json: any): any;
228
- /**
229
- Register a validator instance so that any deserialized metadata can reference it.
230
- @method register
231
- @static
232
- @param validator {Validator} Validator to register.
233
- **/
234
- static register(validator: Validator): void;
235
- /**
236
- Register a validator factory so that any deserialized metadata can reference it.
237
- @method registerFactory
238
- @static
239
- @param validatorFactory {Function} A function that optionally takes a context property and returns a Validator instance.
240
- @param name {String} The name of the validator.
241
- **/
242
- static registerFactory(validatorFactory: (options?: any) => Validator, name: string): void;
243
- /**
244
- Map of standard error message templates keyed by validator name.
245
- You can add to or modify this object to customize the template used for any validation error message.
246
- @example
247
- // v is this function is the value to be validated, in this case a "country" string.
248
- var valFn = function (v) {
249
- if (v == null) return true;
250
- return (core.stringStartsWith(v, "US"));
251
- };
252
- var countryValidator = new Validator("countryIsUS", valFn, { displayName: "Country" });
253
- Validator.messageTemplates.countryIsUS = "'%displayName%' must start with 'US'";
254
- // This will have a similar effect to this
255
- var countryValidator = new Validator("countryIsUS", valFn, {
256
- displayName: "Country",
257
- messageTemplate: "'%displayName%' must start with 'US'"
258
- });
259
- @property messageTemplates {Object}
260
- @static
261
- **/
262
- static messageTemplates: {
263
- bool: string;
264
- creditCard: string;
265
- date: string;
266
- duration: string;
267
- emailAddress: string;
268
- guid: string;
269
- integer: string;
270
- integerRange: string;
271
- maxLength: string;
272
- number: string;
273
- phone: string;
274
- regularExpression: string;
275
- required: string;
276
- string: string;
277
- stringLength: string;
278
- url: string;
279
- };
280
- /**
281
- Returns a standard 'required value' Validator
282
- @example
283
- // Assume em1 is a preexisting EntityManager.
284
- var custType = em1.metadataStore.getEntityType("Customer");
285
- var regionProperty - custType.getProperty("Region");
286
- // Makes "Region" on Customer a required property.
287
- regionProperty.validators.push(Validator.required());
288
- // or to allow empty strings
289
- regionProperty.validators.push(Validator.required({ allowEmptyStrings: true }););
290
- @method required
291
- @static
292
- @param context {Object}
293
- @param [context.allowEmptyStrings] {Boolean} If this parameter is omitted or false then empty strings do NOT pass validation.
294
- @return {Validator} A new Validator
295
- **/
296
- static required: (context?: any) => Validator;
297
- /**
298
- Returns a standard maximum string length Validator; the maximum length must be specified
299
- @example
300
- // Assume em1 is a preexisting EntityManager.
301
- var custType = em1.metadataStore.getEntityType("Customer");
302
- var regionProperty - custType.getProperty("Region");
303
- // Validates that the value of the Region property on Customer will be less than or equal to 5 characters.
304
- regionProperty.validators.push(Validator.maxLength( {maxLength: 5}));
305
- @method maxLength
306
- @static
307
- @param context {Object}
308
- @param context.maxLength {Integer}
309
- @return {Validator} A new Validator
310
- **/
311
- static maxLength: (context: any) => Validator;
312
- /**
313
- Returns a standard string length Validator; both minimum and maximum lengths must be specified.
314
- @example
315
- // Assume em1 is a preexisting EntityManager.
316
- var custType = em1.metadataStore.getEntityType("Customer");
317
- var regionProperty - custType.getProperty("Region");
318
- // Validates that the value of the Region property on Customer will be
319
- // between 2 and 5 characters
320
- regionProperty.validators.push(Validator.stringLength( {minLength: 2, maxLength: 5});
321
- @method stringLength
322
- @static
323
- @param context {Object}
324
- @param context.maxLength {Integer}
325
- @param context.minLength {Integer}
326
- @return {Validator} A new Validator
327
- **/
328
- static stringLength: (context: any) => Validator;
329
- /**
330
- Returns a standard string dataType Validator.
331
- @example
332
- // Assume em1 is a preexisting EntityManager.
333
- var custType = em1.metadataStore.getEntityType("Customer");
334
- var regionProperty - custType.getProperty("Region");
335
- // Validates that the value of the Region property on Customer is a string.
336
- regionProperty.validators.push(Validator.string());
337
- @method string
338
- @static
339
- @return {Validator} A new Validator
340
- **/
341
- static string: () => Validator;
342
- /**
343
- Returns a Guid data type Validator.
344
- @example
345
- // Assume em1 is a preexisting EntityManager.
346
- var custType = em1.metadataStore.getEntityType("Customer");
347
- var customerIdProperty - custType.getProperty("CustomerID");
348
- // Validates that the value of the CustomerID property on Customer is a Guid.
349
- customerIdProperty.validators.push(Validator.guid());
350
- @method guid
351
- @static
352
- @return {Validator} A new Validator
353
- **/
354
- static guid: () => Validator;
355
- /**
356
- Returns a ISO 8601 duration string Validator.
357
- @example
358
- // Assume em1 is a preexisting EntityManager.
359
- var eventType = em1.metadataStore.getEntityType("Event");
360
- var elapsedTimeProperty - eventType.getProperty("ElapsedTime");
361
- // Validates that the value of the ElapsedTime property on Customer is a duration.
362
- elapsedTimeProperty.validators.push(Validator.duration());
363
- @method duration
364
- @static
365
- @return {Validator} A new Validator
366
- **/
367
- static duration: () => Validator;
368
- /**
369
- Returns a standard numeric data type Validator.
370
- @example
371
- // Assume em1 is a preexisting EntityManager.
372
- var orderType = em1.metadataStore.getEntityType("Order");
373
- var freightProperty - orderType.getProperty("Freight");
374
- // Validates that the value of the Freight property on Order is a number.
375
- freightProperty.validators.push(Validator.number());
376
- @method number
377
- @static
378
- @return {Validator} A new Validator
379
- **/
380
- static number: (context?: any) => Validator;
381
- static double: (context?: any) => Validator;
382
- static single: (context?: any) => Validator;
383
- /**
384
- Returns a standard large integer data type - 64 bit - Validator.
385
- @example
386
- // Assume em1 is a preexisting EntityManager.
387
- var orderType = em1.metadataStore.getEntityType("Order");
388
- var freightProperty - orderType.getProperty("Freight");
389
- // Validates that the value of the Freight property on Order is within the range of a 64 bit integer.
390
- freightProperty.validators.push(Validator.int64());
391
- @method int64
392
- @static
393
- @return {Validator} A new Validator
394
- **/
395
- static integer: (context: any) => Validator;
396
- static int64: (context: any) => Validator;
397
- /**
398
- Returns a standard 32 bit integer data type Validator.
399
- @example
400
- // Assume em1 is a preexisting EntityManager.
401
- var orderType = em1.metadataStore.getEntityType("Order");
402
- var freightProperty - orderType.getProperty("Freight");
403
- freightProperty.validators.push(Validator.int32());
404
- @method int32
405
- @static
406
- @return {Validator} A new Validator
407
- **/
408
- static int32: (context: any) => Validator;
409
- /**
410
- Returns a standard 16 bit integer data type Validator.
411
- @example
412
- // Assume em1 is a preexisting EntityManager.
413
- var orderType = em1.metadataStore.getEntityType("Order");
414
- var freightProperty - orderType.getProperty("Freight");
415
- // Validates that the value of the Freight property on Order is within the range of a 16 bit integer.
416
- freightProperty.validators.push(Validator.int16());
417
- @method int16
418
- @static
419
- @return {Validator} A new Validator
420
- **/
421
- static int16: (context: any) => Validator;
422
- /**
423
- Returns a standard byte data type Validator. (This is a integer between 0 and 255 inclusive for js purposes).
424
- @example
425
- // Assume em1 is a preexisting EntityManager.
426
- var orderType = em1.metadataStore.getEntityType("Order");
427
- var freightProperty - orderType.getProperty("Freight");
428
- // Validates that the value of the Freight property on Order is within the range of a 16 bit integer.
429
- // Probably not a very good validation to place on the Freight property.
430
- regionProperty.validators.push(Validator.byte());
431
- @method byte
432
- @static
433
- @return {Validator} A new Validator
434
- **/
435
- static byte: (context: any) => Validator;
436
- /**
437
- Returns a standard boolean data type Validator.
438
- @example
439
- // Assume em1 is a preexisting EntityManager.
440
- var productType = em1.metadataStore.getEntityType("Product");
441
- var discontinuedProperty - productType.getProperty("Discontinued");
442
- // Validates that the value of the Discontinued property on Product is a boolean
443
- discontinuedProperty.validators.push(Validator.bool());
444
- @method bool
445
- @static
446
- @return {Validator} A new Validator
447
- **/
448
- static bool: () => Validator;
449
- static none: () => Validator;
450
- /**
451
- Returns a standard date data type Validator.
452
- @example
453
- // Assume em1 is a preexisting EntityManager.
454
- var orderType = em1.metadataStore.getEntityType("Order");
455
- var orderDateProperty - orderType.getProperty("OrderDate");
456
- // Validates that the value of the OrderDate property on Order is a date
457
- // Probably not a very good validation to place on the Freight property.
458
- orderDateProperty.validators.push(Validator.date());
459
- @method date
460
- @static
461
- @return {Validator} A new Validator
462
- **/
463
- static date: () => Validator;
464
- /**
465
- Returns a credit card number validator
466
- Performs a luhn algorithm checksum test for plausability
467
- catches simple mistakes; only service knows for sure
468
- @example
469
- // Assume em is a preexisting EntityManager.
470
- var personType = em.metadataStore.getEntityType("Person");
471
- var creditCardProperty = personType.getProperty("creditCard");
472
- // Validates that the value of the Person.creditCard property is credit card.
473
- creditCardProperty.validators.push(Validator.creditCard());
474
- @method creditCard
475
- @static
476
- @param [context] {Object} optional parameters to pass through to validation constructor
477
- @return {Validator} A new Validator
478
- **/
479
- static creditCard: (context?: any) => Validator;
480
- /**
481
- Returns a regular expression validator; the expression must be specified
482
- @example
483
- // Add validator to a property. Assume em is a preexisting EntityManager.
484
- var customerType = em.metadataStore.getEntityType("Customer");
485
- var regionProperty = customerType.getProperty("Region");
486
- // Validates that the value of Customer.Region is 2 char uppercase alpha.
487
- regionProperty.validators.push(Validator.regularExpression( {expression: '^[A-Z]{2}$'} );
488
- @method regularExpression
489
- @static
490
- @param context {Object}
491
- @param context.expression {String} String form of the regular expression to apply
492
- @return {Validator} A new Validator
493
- **/
494
- static regularExpression: (context?: any) => Validator;
495
- /**
496
- Returns the email address validator
497
- @example
498
- // Assume em is a preexisting EntityManager.
499
- var personType = em.metadataStore.getEntityType("Person");
500
- var emailProperty = personType.getProperty("email");
501
- // Validates that the value of the Person.email property is an email address.
502
- emailProperty.validators.push(Validator.emailAddress());
503
- @method emailAddress
504
- @static
505
- @param [context] {Object} optional parameters to pass through to validation constructor
506
- @return {Validator} A new Validator
507
- **/
508
- static emailAddress: (context?: any) => Validator;
509
- /**
510
- Returns the phone validator
511
- Provides basic assertions on the format and will help to eliminate most nonsense input
512
- Matches:
513
- International dialing prefix: {{}, +, 0, 0000} (with or without a trailing break character, if not '+': [-/. ])
514
- > ((\+)|(0(\d+)?[-/.\s]))
515
- Country code: {{}, 1, ..., 999} (with or without a trailing break character: [-/. ])
516
- > [1-9]\d{,2}[-/.\s]?
517
- Area code: {(0), ..., (000000), 0, ..., 000000} (with or without a trailing break character: [-/. ])
518
- > ((\(\d{1,6}\)|\d{1,6})[-/.\s]?)?
519
- Local: {0, ...}+ (with or without a trailing break character: [-/. ])
520
- > (\d+[-/.\s]?)+\d+
521
- @example
522
- // Assume em is a preexisting EntityManager.
523
- var customerType = em.metadataStore.getEntityType("Customer");
524
- var phoneProperty = customerType.getProperty("phone");
525
- // Validates that the value of the Customer.phone property is phone.
526
- phoneProperty.validators.push(Validator.phone());
527
- @method phone
528
- @static
529
- @param [context] {Object} optional parameters to pass through to validation constructor
530
- @return {Validator} A new Validator
531
- **/
532
- static phone: (context?: any) => Validator;
533
- /**
534
- Returns the URL (protocol required) validator
535
- @example
536
- // Assume em is a preexisting EntityManager.
537
- var personType = em.metadataStore.getEntityType("Person");
538
- var websiteProperty = personType.getProperty("website");
539
- // Validates that the value of the Person.website property is a URL.
540
- websiteProperty.validators.push(Validator.url());
541
- @method url
542
- @static
543
- @param [context] {Object} optional parameters to pass through to validation constructor
544
- @return {Validator} A new Validator
545
- **/
546
- static url: (context?: any) => Validator;
547
- /**
548
- Creates a regular expression validator with a fixed expression.
549
- Many of the stock validators are built with this factory method.
550
- Their expressions are often derived from
551
- https://github.com/srkirkland/DataAnnotationsExtensions/blob/master/DataAnnotationsExtensions
552
- You can try many of them at http://dataannotationsextensions.org/
553
- @example
554
- // Make a zipcode validator
555
- function zipValidator = Validator.makeRegExpValidator(
556
- "zipVal,
557
- /^\d{5}([\-]\d{4})?$/,
558
- "The %displayName% '%value%' is not a valid U.S. zipcode");
559
- // Register it.
560
- Validator.register(zipValidator);
561
- // Add it to a data property. Assume em is a preexisting EntityManager.
562
- var custType = em.metadataStore.getEntityType("Customer");
563
- var zipProperty = custType.getProperty("PostalCode");
564
- zipProperty.validators.push(zipValidator);
565
- @method makeRegExpValidator
566
- @static
567
- @param validatorName {String} name of this validator
568
- @param expression {String | RegExp} regular expression to apply
569
- @param [defaultMessage] {String} default message for failed validations
570
- @param [context] {Object} optional parameters to pass through to validation constructor
571
- @return {Validator} A new Validator
572
- **/
573
- static makeRegExpValidator: typeof makeRegExpValidator;
574
- }
575
- export declare function makeRegExpValidator(validatorName: string, expression: RegExp, defaultMessage?: string | null, context?: any): Validator;
576
- /**
577
- A ValidationError is used to describe a failed validation.
578
-
579
- @class ValidationError
580
- **/
581
- /**
582
- Constructs a new ValidationError
583
- @method <ctor> ValidationError
584
-
585
- @param validator {Validator || null} The Validator used to create this error, if any.
586
- @param context { ContextObject || null} The Context object used in conjunction with the Validator to create this error.
587
- @param errorMessage { String} The actual error message
588
- @param [key] {String} An optional key used to define a key for this error. One will be created automatically if not provided here.
589
- **/
590
- export declare class ValidationError {
591
- validator?: Validator;
592
- key: string;
593
- context: any;
594
- errorMessage: string;
595
- property: any;
596
- propertyName: string;
597
- isServerError: boolean;
598
- constructor(validator: Validator | null, context: ValidationContext, errorMessage: string, key?: string);
599
- /**
600
- The Validator associated with this ValidationError.
601
-
602
- __readOnly__
603
- @property validator {Validator}
604
- **/
605
- /**
606
- A 'context' object associated with this ValidationError.
607
-
608
- __readOnly__
609
- @property context {Object}
610
- **/
611
- /**
612
- The DataProperty or NavigationProperty associated with this ValidationError.
613
-
614
- __readOnly__
615
- @property property {DataProperty|NavigationProperty}
616
- **/
617
- /**
618
- The property name associated with this ValidationError. This will be a "property path" for any properties of a complex object.
619
-
620
- __readOnly__
621
- @property propertyName {String}
622
- **/
623
- /**
624
- The error message associated with the ValidationError.
625
-
626
- __readOnly__
627
- @property errorMessage {string}
628
- **/
629
- /**
630
- The key by which this validation error may be removed from a collection of ValidationErrors.
631
-
632
- __readOnly__
633
- @property key {string}
634
- **/
635
- /**
636
- Whether this is a server error.
637
-
638
- __readOnly__
639
- @property isServerError {bool}
640
- **/
641
- /**
642
- Composes a ValidationError 'key' given a validator or an errorName and an optional propertyName
643
- @method getKey
644
- @static
645
- @param validator {ValidatorOrErrorKey} A Validator or an "error name" if no validator is available.
646
- @param [propertyName] A property name
647
- @return {String} A ValidationError 'key'
648
- **/
649
- static getKey(validatorOrErrorName: Validator | string, propertyName?: string): string;
650
- }