@e22m4u/js-repository 0.8.8 → 0.8.9
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.
- package/dist/cjs/index.cjs +98 -111
- package/package.json +5 -5
- package/src/definition/definition-registry.d.ts +10 -0
- package/src/definition/definition-registry.js +25 -13
- package/src/definition/definition-registry.spec.js +60 -111
- package/src/repository/repository-registry.js +2 -4
- package/src/repository/repository-registry.spec.js +0 -19
- package/src/utils/index.d.ts +0 -1
- package/src/utils/index.js +0 -1
- package/src/utils/model-name-to-model-key.d.ts +0 -6
- package/src/utils/model-name-to-model-key.js +0 -18
- package/src/utils/model-name-to-model-key.spec.js +0 -94
package/dist/cjs/index.cjs
CHANGED
|
@@ -419,24 +419,6 @@ var init_exclude_object_keys = __esm({
|
|
|
419
419
|
}
|
|
420
420
|
});
|
|
421
421
|
|
|
422
|
-
// src/utils/model-name-to-model-key.js
|
|
423
|
-
function modelNameToModelKey(modelName) {
|
|
424
|
-
if (!modelName || typeof modelName !== "string" || /\s/.test(modelName)) {
|
|
425
|
-
throw new InvalidArgumentError(
|
|
426
|
-
"Model name must be a non-empty String without spaces, but %v was given.",
|
|
427
|
-
modelName
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
return modelName.toLowerCase().replace(/[-_]/g, "");
|
|
431
|
-
}
|
|
432
|
-
var init_model_name_to_model_key = __esm({
|
|
433
|
-
"src/utils/model-name-to-model-key.js"() {
|
|
434
|
-
"use strict";
|
|
435
|
-
init_errors();
|
|
436
|
-
__name(modelNameToModelKey, "modelNameToModelKey");
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
|
|
440
422
|
// src/utils/index.js
|
|
441
423
|
var init_utils = __esm({
|
|
442
424
|
"src/utils/index.js"() {
|
|
@@ -452,7 +434,6 @@ var init_utils = __esm({
|
|
|
452
434
|
init_get_value_by_path();
|
|
453
435
|
init_select_object_keys();
|
|
454
436
|
init_exclude_object_keys();
|
|
455
|
-
init_model_name_to_model_key();
|
|
456
437
|
}
|
|
457
438
|
});
|
|
458
439
|
|
|
@@ -1833,17 +1814,65 @@ var init_property_uniqueness = __esm({
|
|
|
1833
1814
|
}
|
|
1834
1815
|
});
|
|
1835
1816
|
|
|
1817
|
+
// src/definition/datasource/datasource-definition-validator.js
|
|
1818
|
+
var import_js_service6, DatasourceDefinitionValidator;
|
|
1819
|
+
var init_datasource_definition_validator = __esm({
|
|
1820
|
+
"src/definition/datasource/datasource-definition-validator.js"() {
|
|
1821
|
+
"use strict";
|
|
1822
|
+
import_js_service6 = require("@e22m4u/js-service");
|
|
1823
|
+
init_errors();
|
|
1824
|
+
DatasourceDefinitionValidator = class extends import_js_service6.Service {
|
|
1825
|
+
static {
|
|
1826
|
+
__name(this, "DatasourceDefinitionValidator");
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Validate.
|
|
1830
|
+
*
|
|
1831
|
+
* @param {object} datasourceDef
|
|
1832
|
+
*/
|
|
1833
|
+
validate(datasourceDef) {
|
|
1834
|
+
if (!datasourceDef || typeof datasourceDef !== "object") {
|
|
1835
|
+
throw new InvalidArgumentError(
|
|
1836
|
+
"Datasource definition must be an Object, but %v was given.",
|
|
1837
|
+
datasourceDef
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
if (!datasourceDef.name || typeof datasourceDef.name !== "string") {
|
|
1841
|
+
throw new InvalidArgumentError(
|
|
1842
|
+
'Datasource definition requires the option "name" as a non-empty String, but %v was given.',
|
|
1843
|
+
datasourceDef.name
|
|
1844
|
+
);
|
|
1845
|
+
}
|
|
1846
|
+
if (!datasourceDef.adapter || typeof datasourceDef.adapter !== "string") {
|
|
1847
|
+
throw new InvalidArgumentError(
|
|
1848
|
+
'Datasource %v requires the option "adapter" as a non-empty String, but %v was given.',
|
|
1849
|
+
datasourceDef.name,
|
|
1850
|
+
datasourceDef.adapter
|
|
1851
|
+
);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
});
|
|
1857
|
+
|
|
1858
|
+
// src/definition/datasource/index.js
|
|
1859
|
+
var init_datasource = __esm({
|
|
1860
|
+
"src/definition/datasource/index.js"() {
|
|
1861
|
+
"use strict";
|
|
1862
|
+
init_datasource_definition_validator();
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
|
|
1836
1866
|
// src/definition/definition-registry.js
|
|
1837
|
-
var
|
|
1867
|
+
var import_js_service7, DefinitionRegistry;
|
|
1838
1868
|
var init_definition_registry = __esm({
|
|
1839
1869
|
"src/definition/definition-registry.js"() {
|
|
1840
1870
|
"use strict";
|
|
1841
|
-
|
|
1842
|
-
init_utils();
|
|
1871
|
+
import_js_service7 = require("@e22m4u/js-service");
|
|
1843
1872
|
init_errors();
|
|
1844
1873
|
init_model();
|
|
1845
|
-
|
|
1846
|
-
DefinitionRegistry = class extends
|
|
1874
|
+
init_datasource();
|
|
1875
|
+
DefinitionRegistry = class extends import_js_service7.Service {
|
|
1847
1876
|
static {
|
|
1848
1877
|
__name(this, "DefinitionRegistry");
|
|
1849
1878
|
}
|
|
@@ -1894,6 +1923,14 @@ var init_definition_registry = __esm({
|
|
|
1894
1923
|
}
|
|
1895
1924
|
return datasourceDef;
|
|
1896
1925
|
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Get datasource names.
|
|
1928
|
+
*
|
|
1929
|
+
* @returns {string[]}
|
|
1930
|
+
*/
|
|
1931
|
+
getDatasourceNames() {
|
|
1932
|
+
return Object.keys(this._datasources);
|
|
1933
|
+
}
|
|
1897
1934
|
/**
|
|
1898
1935
|
* Add model.
|
|
1899
1936
|
*
|
|
@@ -1901,14 +1938,11 @@ var init_definition_registry = __esm({
|
|
|
1901
1938
|
*/
|
|
1902
1939
|
addModel(modelDef) {
|
|
1903
1940
|
this.getService(ModelDefinitionValidator).validate(modelDef);
|
|
1904
|
-
const
|
|
1905
|
-
if (
|
|
1906
|
-
throw new InvalidArgumentError(
|
|
1907
|
-
"Model %v is already defined.",
|
|
1908
|
-
modelDef.name
|
|
1909
|
-
);
|
|
1941
|
+
const name = modelDef.name;
|
|
1942
|
+
if (name in this._models) {
|
|
1943
|
+
throw new InvalidArgumentError("Model %v is already defined.", name);
|
|
1910
1944
|
}
|
|
1911
|
-
this._models[
|
|
1945
|
+
this._models[name] = modelDef;
|
|
1912
1946
|
}
|
|
1913
1947
|
/**
|
|
1914
1948
|
* Has model.
|
|
@@ -1917,8 +1951,7 @@ var init_definition_registry = __esm({
|
|
|
1917
1951
|
* @returns {boolean}
|
|
1918
1952
|
*/
|
|
1919
1953
|
hasModel(name) {
|
|
1920
|
-
|
|
1921
|
-
return Boolean(this._models[modelKey]);
|
|
1954
|
+
return Boolean(this._models[name]);
|
|
1922
1955
|
}
|
|
1923
1956
|
/**
|
|
1924
1957
|
* Get model.
|
|
@@ -1927,29 +1960,36 @@ var init_definition_registry = __esm({
|
|
|
1927
1960
|
* @returns {object}
|
|
1928
1961
|
*/
|
|
1929
1962
|
getModel(name) {
|
|
1930
|
-
const
|
|
1931
|
-
const modelDef = this._models[modelKey];
|
|
1963
|
+
const modelDef = this._models[name];
|
|
1932
1964
|
if (!modelDef) {
|
|
1933
1965
|
throw new InvalidArgumentError("Model %v is not defined.", name);
|
|
1934
1966
|
}
|
|
1935
1967
|
return modelDef;
|
|
1936
1968
|
}
|
|
1969
|
+
/**
|
|
1970
|
+
* Get model names.
|
|
1971
|
+
*
|
|
1972
|
+
* @returns {string[]}
|
|
1973
|
+
*/
|
|
1974
|
+
getModelNames() {
|
|
1975
|
+
return Object.keys(this._models);
|
|
1976
|
+
}
|
|
1937
1977
|
};
|
|
1938
1978
|
}
|
|
1939
1979
|
});
|
|
1940
1980
|
|
|
1941
1981
|
// src/definition/model/model-definition-utils.js
|
|
1942
|
-
var
|
|
1982
|
+
var import_js_service8, DEFAULT_PRIMARY_KEY_PROPERTY_NAME, ModelDefinitionUtils;
|
|
1943
1983
|
var init_model_definition_utils = __esm({
|
|
1944
1984
|
"src/definition/model/model-definition-utils.js"() {
|
|
1945
1985
|
"use strict";
|
|
1946
|
-
|
|
1986
|
+
import_js_service8 = require("@e22m4u/js-service");
|
|
1947
1987
|
init_properties();
|
|
1948
1988
|
init_errors();
|
|
1949
1989
|
init_definition_registry();
|
|
1950
1990
|
init_utils();
|
|
1951
1991
|
DEFAULT_PRIMARY_KEY_PROPERTY_NAME = "id";
|
|
1952
|
-
ModelDefinitionUtils = class extends
|
|
1992
|
+
ModelDefinitionUtils = class extends import_js_service8.Service {
|
|
1953
1993
|
static {
|
|
1954
1994
|
__name(this, "ModelDefinitionUtils");
|
|
1955
1995
|
}
|
|
@@ -2383,15 +2423,15 @@ var init_model_definition_utils = __esm({
|
|
|
2383
2423
|
});
|
|
2384
2424
|
|
|
2385
2425
|
// src/definition/model/properties/required-property-validator.js
|
|
2386
|
-
var
|
|
2426
|
+
var import_js_service9, RequiredPropertyValidator;
|
|
2387
2427
|
var init_required_property_validator = __esm({
|
|
2388
2428
|
"src/definition/model/properties/required-property-validator.js"() {
|
|
2389
2429
|
"use strict";
|
|
2390
2430
|
init_data_type();
|
|
2391
|
-
|
|
2431
|
+
import_js_service9 = require("@e22m4u/js-service");
|
|
2392
2432
|
init_errors();
|
|
2393
2433
|
init_model_definition_utils();
|
|
2394
|
-
RequiredPropertyValidator = class extends
|
|
2434
|
+
RequiredPropertyValidator = class extends import_js_service9.Service {
|
|
2395
2435
|
static {
|
|
2396
2436
|
__name(this, "RequiredPropertyValidator");
|
|
2397
2437
|
}
|
|
@@ -2456,16 +2496,16 @@ var init_required_property_validator = __esm({
|
|
|
2456
2496
|
});
|
|
2457
2497
|
|
|
2458
2498
|
// src/definition/model/properties/property-uniqueness-validator.js
|
|
2459
|
-
var
|
|
2499
|
+
var import_js_service10, PropertyUniquenessValidator;
|
|
2460
2500
|
var init_property_uniqueness_validator = __esm({
|
|
2461
2501
|
"src/definition/model/properties/property-uniqueness-validator.js"() {
|
|
2462
2502
|
"use strict";
|
|
2463
|
-
|
|
2503
|
+
import_js_service10 = require("@e22m4u/js-service");
|
|
2464
2504
|
init_utils();
|
|
2465
2505
|
init_property_uniqueness();
|
|
2466
2506
|
init_errors();
|
|
2467
2507
|
init_model_definition_utils();
|
|
2468
|
-
PropertyUniquenessValidator = class extends
|
|
2508
|
+
PropertyUniquenessValidator = class extends import_js_service10.Service {
|
|
2469
2509
|
static {
|
|
2470
2510
|
__name(this, "PropertyUniquenessValidator");
|
|
2471
2511
|
}
|
|
@@ -2588,14 +2628,14 @@ var init_property_uniqueness_validator = __esm({
|
|
|
2588
2628
|
});
|
|
2589
2629
|
|
|
2590
2630
|
// src/definition/model/properties/primary-keys-definition-validator.js
|
|
2591
|
-
var
|
|
2631
|
+
var import_js_service11, PrimaryKeysDefinitionValidator;
|
|
2592
2632
|
var init_primary_keys_definition_validator = __esm({
|
|
2593
2633
|
"src/definition/model/properties/primary-keys-definition-validator.js"() {
|
|
2594
2634
|
"use strict";
|
|
2595
|
-
|
|
2635
|
+
import_js_service11 = require("@e22m4u/js-service");
|
|
2596
2636
|
init_errors();
|
|
2597
2637
|
init_model_definition_utils();
|
|
2598
|
-
PrimaryKeysDefinitionValidator = class extends
|
|
2638
|
+
PrimaryKeysDefinitionValidator = class extends import_js_service11.Service {
|
|
2599
2639
|
static {
|
|
2600
2640
|
__name(this, "PrimaryKeysDefinitionValidator");
|
|
2601
2641
|
}
|
|
@@ -2643,17 +2683,17 @@ var init_primary_keys_definition_validator = __esm({
|
|
|
2643
2683
|
});
|
|
2644
2684
|
|
|
2645
2685
|
// src/definition/model/properties/properties-definition-validator.js
|
|
2646
|
-
var
|
|
2686
|
+
var import_js_service12, PropertiesDefinitionValidator;
|
|
2647
2687
|
var init_properties_definition_validator = __esm({
|
|
2648
2688
|
"src/definition/model/properties/properties-definition-validator.js"() {
|
|
2649
2689
|
"use strict";
|
|
2650
|
-
|
|
2690
|
+
import_js_service12 = require("@e22m4u/js-service");
|
|
2651
2691
|
init_data_type();
|
|
2652
2692
|
init_utils();
|
|
2653
2693
|
init_property_uniqueness();
|
|
2654
2694
|
init_errors();
|
|
2655
2695
|
init_primary_keys_definition_validator();
|
|
2656
|
-
PropertiesDefinitionValidator = class extends
|
|
2696
|
+
PropertiesDefinitionValidator = class extends import_js_service12.Service {
|
|
2657
2697
|
static {
|
|
2658
2698
|
__name(this, "PropertiesDefinitionValidator");
|
|
2659
2699
|
}
|
|
@@ -2908,14 +2948,14 @@ var init_model_definition = __esm({
|
|
|
2908
2948
|
});
|
|
2909
2949
|
|
|
2910
2950
|
// src/definition/model/model-data-sanitizer.js
|
|
2911
|
-
var
|
|
2951
|
+
var import_js_service13, ModelDataSanitizer;
|
|
2912
2952
|
var init_model_data_sanitizer = __esm({
|
|
2913
2953
|
"src/definition/model/model-data-sanitizer.js"() {
|
|
2914
2954
|
"use strict";
|
|
2915
|
-
|
|
2955
|
+
import_js_service13 = require("@e22m4u/js-service");
|
|
2916
2956
|
init_errors();
|
|
2917
2957
|
init_model_definition_utils();
|
|
2918
|
-
ModelDataSanitizer = class extends
|
|
2958
|
+
ModelDataSanitizer = class extends import_js_service13.Service {
|
|
2919
2959
|
static {
|
|
2920
2960
|
__name(this, "ModelDataSanitizer");
|
|
2921
2961
|
}
|
|
@@ -2948,15 +2988,15 @@ var init_model_data_sanitizer = __esm({
|
|
|
2948
2988
|
});
|
|
2949
2989
|
|
|
2950
2990
|
// src/definition/model/model-definition-validator.js
|
|
2951
|
-
var
|
|
2991
|
+
var import_js_service14, ModelDefinitionValidator;
|
|
2952
2992
|
var init_model_definition_validator = __esm({
|
|
2953
2993
|
"src/definition/model/model-definition-validator.js"() {
|
|
2954
2994
|
"use strict";
|
|
2955
|
-
|
|
2995
|
+
import_js_service14 = require("@e22m4u/js-service");
|
|
2956
2996
|
init_errors();
|
|
2957
2997
|
init_relations();
|
|
2958
2998
|
init_properties();
|
|
2959
|
-
ModelDefinitionValidator = class extends
|
|
2999
|
+
ModelDefinitionValidator = class extends import_js_service14.Service {
|
|
2960
3000
|
static {
|
|
2961
3001
|
__name(this, "ModelDefinitionValidator");
|
|
2962
3002
|
}
|
|
@@ -3043,55 +3083,6 @@ var init_model = __esm({
|
|
|
3043
3083
|
}
|
|
3044
3084
|
});
|
|
3045
3085
|
|
|
3046
|
-
// src/definition/datasource/datasource-definition-validator.js
|
|
3047
|
-
var import_js_service14, DatasourceDefinitionValidator;
|
|
3048
|
-
var init_datasource_definition_validator = __esm({
|
|
3049
|
-
"src/definition/datasource/datasource-definition-validator.js"() {
|
|
3050
|
-
"use strict";
|
|
3051
|
-
import_js_service14 = require("@e22m4u/js-service");
|
|
3052
|
-
init_errors();
|
|
3053
|
-
DatasourceDefinitionValidator = class extends import_js_service14.Service {
|
|
3054
|
-
static {
|
|
3055
|
-
__name(this, "DatasourceDefinitionValidator");
|
|
3056
|
-
}
|
|
3057
|
-
/**
|
|
3058
|
-
* Validate.
|
|
3059
|
-
*
|
|
3060
|
-
* @param {object} datasourceDef
|
|
3061
|
-
*/
|
|
3062
|
-
validate(datasourceDef) {
|
|
3063
|
-
if (!datasourceDef || typeof datasourceDef !== "object") {
|
|
3064
|
-
throw new InvalidArgumentError(
|
|
3065
|
-
"Datasource definition must be an Object, but %v was given.",
|
|
3066
|
-
datasourceDef
|
|
3067
|
-
);
|
|
3068
|
-
}
|
|
3069
|
-
if (!datasourceDef.name || typeof datasourceDef.name !== "string") {
|
|
3070
|
-
throw new InvalidArgumentError(
|
|
3071
|
-
'Datasource definition requires the option "name" as a non-empty String, but %v was given.',
|
|
3072
|
-
datasourceDef.name
|
|
3073
|
-
);
|
|
3074
|
-
}
|
|
3075
|
-
if (!datasourceDef.adapter || typeof datasourceDef.adapter !== "string") {
|
|
3076
|
-
throw new InvalidArgumentError(
|
|
3077
|
-
'Datasource %v requires the option "adapter" as a non-empty String, but %v was given.',
|
|
3078
|
-
datasourceDef.name,
|
|
3079
|
-
datasourceDef.adapter
|
|
3080
|
-
);
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
};
|
|
3084
|
-
}
|
|
3085
|
-
});
|
|
3086
|
-
|
|
3087
|
-
// src/definition/datasource/index.js
|
|
3088
|
-
var init_datasource = __esm({
|
|
3089
|
-
"src/definition/datasource/index.js"() {
|
|
3090
|
-
"use strict";
|
|
3091
|
-
init_datasource_definition_validator();
|
|
3092
|
-
}
|
|
3093
|
-
});
|
|
3094
|
-
|
|
3095
3086
|
// src/definition/index.js
|
|
3096
3087
|
var init_definition = __esm({
|
|
3097
3088
|
"src/definition/index.js"() {
|
|
@@ -4664,7 +4655,6 @@ var init_repository_registry = __esm({
|
|
|
4664
4655
|
"use strict";
|
|
4665
4656
|
import_js_service26 = require("@e22m4u/js-service");
|
|
4666
4657
|
init_repository();
|
|
4667
|
-
init_utils();
|
|
4668
4658
|
init_errors();
|
|
4669
4659
|
RepositoryRegistry = class extends import_js_service26.Service {
|
|
4670
4660
|
static {
|
|
@@ -4704,13 +4694,12 @@ var init_repository_registry = __esm({
|
|
|
4704
4694
|
* @returns {Repository}
|
|
4705
4695
|
*/
|
|
4706
4696
|
getRepository(modelName) {
|
|
4707
|
-
|
|
4708
|
-
let repository = this._repositories[modelKey];
|
|
4697
|
+
let repository = this._repositories[modelName];
|
|
4709
4698
|
if (repository) {
|
|
4710
4699
|
return repository;
|
|
4711
4700
|
}
|
|
4712
4701
|
repository = new this._repositoryCtor(this.container, modelName);
|
|
4713
|
-
this._repositories[
|
|
4702
|
+
this._repositories[modelName] = repository;
|
|
4714
4703
|
return repository;
|
|
4715
4704
|
}
|
|
4716
4705
|
};
|
|
@@ -6073,7 +6062,6 @@ __export(index_exports, {
|
|
|
6073
6062
|
isPlainObject: () => isPlainObject,
|
|
6074
6063
|
isPromise: () => isPromise,
|
|
6075
6064
|
likeToRegexp: () => likeToRegexp,
|
|
6076
|
-
modelNameToModelKey: () => modelNameToModelKey,
|
|
6077
6065
|
selectObjectKeys: () => selectObjectKeys,
|
|
6078
6066
|
singularize: () => singularize,
|
|
6079
6067
|
stringToRegexp: () => stringToRegexp
|
|
@@ -6171,7 +6159,6 @@ init_repository2();
|
|
|
6171
6159
|
isPlainObject,
|
|
6172
6160
|
isPromise,
|
|
6173
6161
|
likeToRegexp,
|
|
6174
|
-
modelNameToModelKey,
|
|
6175
6162
|
selectObjectKeys,
|
|
6176
6163
|
singularize,
|
|
6177
6164
|
stringToRegexp
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e22m4u/js-repository",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "Реализация репозитория для работы с базами данных",
|
|
5
5
|
"author": "Mikhail Evstropov <e22m4u@yandex.ru>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
8
|
-
"Repository",
|
|
9
8
|
"ORM",
|
|
10
9
|
"ODM",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
10
|
+
"database",
|
|
11
|
+
"datasource",
|
|
12
|
+
"repository",
|
|
13
|
+
"relations"
|
|
14
14
|
],
|
|
15
15
|
"homepage": "https://gitverse.ru/e22m4u/js-repository",
|
|
16
16
|
"repository": {
|
|
@@ -27,6 +27,11 @@ export declare class DefinitionRegistry extends Service {
|
|
|
27
27
|
*/
|
|
28
28
|
getDatasource(name: string): DatasourceDefinition;
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Get datasource names.
|
|
32
|
+
*/
|
|
33
|
+
getDatasourceNames(): string[];
|
|
34
|
+
|
|
30
35
|
/**
|
|
31
36
|
* Add model.
|
|
32
37
|
*
|
|
@@ -47,4 +52,9 @@ export declare class DefinitionRegistry extends Service {
|
|
|
47
52
|
* @param name
|
|
48
53
|
*/
|
|
49
54
|
getModel(name: string): ModelDefinition;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get model names.
|
|
58
|
+
*/
|
|
59
|
+
getModelNames(): string[];
|
|
50
60
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {Service} from '@e22m4u/js-service';
|
|
2
|
-
import {modelNameToModelKey} from '../utils/index.js';
|
|
3
2
|
import {InvalidArgumentError} from '../errors/index.js';
|
|
4
3
|
import {ModelDefinitionValidator} from './model/index.js';
|
|
5
|
-
import {DatasourceDefinitionValidator} from '
|
|
4
|
+
import {DatasourceDefinitionValidator} from './datasource/index.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Definition registry.
|
|
@@ -60,6 +59,15 @@ export class DefinitionRegistry extends Service {
|
|
|
60
59
|
return datasourceDef;
|
|
61
60
|
}
|
|
62
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Get datasource names.
|
|
64
|
+
*
|
|
65
|
+
* @returns {string[]}
|
|
66
|
+
*/
|
|
67
|
+
getDatasourceNames() {
|
|
68
|
+
return Object.keys(this._datasources);
|
|
69
|
+
}
|
|
70
|
+
|
|
63
71
|
/**
|
|
64
72
|
* Add model.
|
|
65
73
|
*
|
|
@@ -67,14 +75,11 @@ export class DefinitionRegistry extends Service {
|
|
|
67
75
|
*/
|
|
68
76
|
addModel(modelDef) {
|
|
69
77
|
this.getService(ModelDefinitionValidator).validate(modelDef);
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
throw new InvalidArgumentError(
|
|
73
|
-
'Model %v is already defined.',
|
|
74
|
-
modelDef.name,
|
|
75
|
-
);
|
|
78
|
+
const name = modelDef.name;
|
|
79
|
+
if (name in this._models) {
|
|
80
|
+
throw new InvalidArgumentError('Model %v is already defined.', name);
|
|
76
81
|
}
|
|
77
|
-
this._models[
|
|
82
|
+
this._models[name] = modelDef;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/**
|
|
@@ -84,8 +89,7 @@ export class DefinitionRegistry extends Service {
|
|
|
84
89
|
* @returns {boolean}
|
|
85
90
|
*/
|
|
86
91
|
hasModel(name) {
|
|
87
|
-
|
|
88
|
-
return Boolean(this._models[modelKey]);
|
|
92
|
+
return Boolean(this._models[name]);
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
/**
|
|
@@ -95,11 +99,19 @@ export class DefinitionRegistry extends Service {
|
|
|
95
99
|
* @returns {object}
|
|
96
100
|
*/
|
|
97
101
|
getModel(name) {
|
|
98
|
-
const
|
|
99
|
-
const modelDef = this._models[modelKey];
|
|
102
|
+
const modelDef = this._models[name];
|
|
100
103
|
if (!modelDef) {
|
|
101
104
|
throw new InvalidArgumentError('Model %v is not defined.', name);
|
|
102
105
|
}
|
|
103
106
|
return modelDef;
|
|
104
107
|
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get model names.
|
|
111
|
+
*
|
|
112
|
+
* @returns {string[]}
|
|
113
|
+
*/
|
|
114
|
+
getModelNames() {
|
|
115
|
+
return Object.keys(this._models);
|
|
116
|
+
}
|
|
105
117
|
}
|
|
@@ -1,42 +1,33 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
|
-
import {
|
|
2
|
+
import {createSpy} from '@e22m4u/js-spy';
|
|
3
3
|
import {ModelDefinitionValidator} from './model/index.js';
|
|
4
4
|
import {DefinitionRegistry} from './definition-registry.js';
|
|
5
5
|
import {DatasourceDefinitionValidator} from '../definition/index.js';
|
|
6
6
|
|
|
7
|
-
const sandbox = createSandbox();
|
|
8
|
-
|
|
9
7
|
describe('DefinitionRegistry', function () {
|
|
10
|
-
let S;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
S = new DefinitionRegistry();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(function () {
|
|
17
|
-
sandbox.restore();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
8
|
describe('addDatasource', function () {
|
|
21
|
-
it('
|
|
9
|
+
it('should add the given datasource to the registry', function () {
|
|
22
10
|
const datasource = {name: 'datasource', adapter: 'adapter'};
|
|
11
|
+
const S = new DefinitionRegistry();
|
|
23
12
|
S.addDatasource(datasource);
|
|
24
13
|
const result = S.getDatasource('datasource');
|
|
25
14
|
expect(result).to.be.eql(datasource);
|
|
26
15
|
});
|
|
27
16
|
|
|
28
|
-
it('
|
|
17
|
+
it('should use DatasourceDefinitionValidator to validate the given datasource', function () {
|
|
18
|
+
const S = new DefinitionRegistry();
|
|
29
19
|
const V = S.getService(DatasourceDefinitionValidator);
|
|
30
|
-
|
|
20
|
+
createSpy(V, 'validate');
|
|
31
21
|
const datasource = {name: 'datasource', adapter: 'adapter'};
|
|
32
22
|
S.addDatasource(datasource);
|
|
33
23
|
expect(V.validate).to.have.been.called.once;
|
|
34
24
|
expect(V.validate).to.have.been.called.with(datasource);
|
|
35
25
|
});
|
|
36
26
|
|
|
37
|
-
it('
|
|
27
|
+
it('should throw an error when the given datasource is already defined', function () {
|
|
38
28
|
const datasource1 = {name: 'datasource', adapter: 'adapter'};
|
|
39
29
|
const datasource2 = {name: 'datasource', adapter: 'adapter'};
|
|
30
|
+
const S = new DefinitionRegistry();
|
|
40
31
|
S.addDatasource(datasource1);
|
|
41
32
|
const throwable = () => S.addDatasource(datasource2);
|
|
42
33
|
expect(throwable).to.throw('Datasource "datasource" is already defined.');
|
|
@@ -44,8 +35,9 @@ describe('DefinitionRegistry', function () {
|
|
|
44
35
|
});
|
|
45
36
|
|
|
46
37
|
describe('hasDatasource', function () {
|
|
47
|
-
it('should
|
|
38
|
+
it('should return true when the datasource name is registered', function () {
|
|
48
39
|
const datasource = {name: 'datasource', adapter: 'adapter'};
|
|
40
|
+
const S = new DefinitionRegistry();
|
|
49
41
|
expect(S.hasDatasource(datasource.name)).to.be.false;
|
|
50
42
|
S.addDatasource(datasource);
|
|
51
43
|
expect(S.hasDatasource(datasource.name)).to.be.true;
|
|
@@ -53,39 +45,62 @@ describe('DefinitionRegistry', function () {
|
|
|
53
45
|
});
|
|
54
46
|
|
|
55
47
|
describe('getDatasource', function () {
|
|
56
|
-
it('
|
|
48
|
+
it('should return the registered datasource for its name', function () {
|
|
57
49
|
const datasource = {name: 'datasource', adapter: 'adapter'};
|
|
50
|
+
const S = new DefinitionRegistry();
|
|
58
51
|
S.addDatasource(datasource);
|
|
59
52
|
const result = S.getDatasource('datasource');
|
|
60
53
|
expect(result).to.be.eql(datasource);
|
|
61
54
|
});
|
|
62
55
|
|
|
63
|
-
it('
|
|
56
|
+
it('should throw an error when the datasource name is not registered', function () {
|
|
57
|
+
const S = new DefinitionRegistry();
|
|
64
58
|
const throwable = () => S.getDatasource('undefined');
|
|
65
59
|
expect(throwable).to.throw('Datasource "undefined" is not defined.');
|
|
66
60
|
});
|
|
67
61
|
});
|
|
68
62
|
|
|
63
|
+
describe('getDatasourceNames', function () {
|
|
64
|
+
it('should return an array of datasource names in the definition order', function () {
|
|
65
|
+
const datasource1 = {name: 'datasource1', adapter: 'adapter'};
|
|
66
|
+
const datasource2 = {name: 'datasource2', adapter: 'adapter'};
|
|
67
|
+
const datasource3 = {name: 'datasource3', adapter: 'adapter'};
|
|
68
|
+
const S = new DefinitionRegistry();
|
|
69
|
+
expect(S.getDatasourceNames()).to.be.eql([]);
|
|
70
|
+
S.addDatasource(datasource1);
|
|
71
|
+
S.addDatasource(datasource2);
|
|
72
|
+
S.addDatasource(datasource3);
|
|
73
|
+
expect(S.getDatasourceNames()).to.be.eql([
|
|
74
|
+
datasource1.name,
|
|
75
|
+
datasource2.name,
|
|
76
|
+
datasource3.name,
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
69
81
|
describe('addModel', function () {
|
|
70
|
-
it('
|
|
82
|
+
it('should add the given model to the registry', function () {
|
|
71
83
|
const model = {name: 'model'};
|
|
84
|
+
const S = new DefinitionRegistry();
|
|
72
85
|
S.addModel(model);
|
|
73
86
|
const result = S.getModel('model');
|
|
74
87
|
expect(result).to.be.eql(model);
|
|
75
88
|
});
|
|
76
89
|
|
|
77
|
-
it('
|
|
90
|
+
it('should use ModelDefinitionValidator to validate the given model', function () {
|
|
91
|
+
const S = new DefinitionRegistry();
|
|
78
92
|
const V = S.getService(ModelDefinitionValidator);
|
|
79
|
-
|
|
93
|
+
createSpy(V, 'validate');
|
|
80
94
|
const model = {name: 'model'};
|
|
81
95
|
S.addModel(model);
|
|
82
96
|
expect(V.validate).to.have.been.called.once;
|
|
83
97
|
expect(V.validate).to.have.been.called.with(model);
|
|
84
98
|
});
|
|
85
99
|
|
|
86
|
-
it('
|
|
100
|
+
it('should throw an error when the model name is already registered', function () {
|
|
87
101
|
const model1 = {name: 'TestModel'};
|
|
88
102
|
const model2 = {name: 'TestModel'};
|
|
103
|
+
const S = new DefinitionRegistry();
|
|
89
104
|
S.addModel(model1);
|
|
90
105
|
const throwable = () => S.addModel(model2);
|
|
91
106
|
expect(throwable).to.throw('Model "TestModel" is already defined.');
|
|
@@ -93,112 +108,46 @@ describe('DefinitionRegistry', function () {
|
|
|
93
108
|
});
|
|
94
109
|
|
|
95
110
|
describe('hasModel', function () {
|
|
96
|
-
it('should
|
|
111
|
+
it('should return true when the model name is registered', function () {
|
|
97
112
|
const model = {name: 'model'};
|
|
113
|
+
const S = new DefinitionRegistry();
|
|
98
114
|
expect(S.hasModel(model.name)).to.be.false;
|
|
99
115
|
S.addModel(model);
|
|
100
116
|
expect(S.hasModel(model.name)).to.be.true;
|
|
101
117
|
});
|
|
102
|
-
|
|
103
|
-
it('should ignore naming convention of the model name', function () {
|
|
104
|
-
const model = {name: 'UserProfileDetails'};
|
|
105
|
-
const modelNames = [
|
|
106
|
-
'userProfileDetails',
|
|
107
|
-
'UserProfileDetails',
|
|
108
|
-
'user-profile-details',
|
|
109
|
-
'user_profile_details',
|
|
110
|
-
'USER-PROFILE-DETAILS',
|
|
111
|
-
'USER_PROFILE_DETAILS',
|
|
112
|
-
'USERPROFILEDETAILS',
|
|
113
|
-
'userprofiledetails',
|
|
114
|
-
];
|
|
115
|
-
modelNames.forEach(v => expect(S.hasModel(v)).to.be.false);
|
|
116
|
-
S.addModel(model);
|
|
117
|
-
modelNames.forEach(v => expect(S.hasModel(v)).to.be.true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should respect numbers in the model name', function () {
|
|
121
|
-
const model1 = {name: 'UserProfileDetails1'};
|
|
122
|
-
const modelNames1 = [
|
|
123
|
-
'userProfileDetails1',
|
|
124
|
-
'UserProfileDetails1',
|
|
125
|
-
'user-profile-details-1',
|
|
126
|
-
'user_profile_details_1',
|
|
127
|
-
'USER-PROFILE-DETAILS-1',
|
|
128
|
-
'USER_PROFILE_DETAILS_1',
|
|
129
|
-
'USERPROFILEDETAILS1',
|
|
130
|
-
'userprofiledetails1',
|
|
131
|
-
];
|
|
132
|
-
const modelNames2 = [
|
|
133
|
-
'userProfileDetails2',
|
|
134
|
-
'UserProfileDetails2',
|
|
135
|
-
'user-profile-details-2',
|
|
136
|
-
'user_profile_details_2',
|
|
137
|
-
'USER-PROFILE-DETAILS-2',
|
|
138
|
-
'USER_PROFILE_DETAILS_2',
|
|
139
|
-
'USERPROFILEDETAILS2',
|
|
140
|
-
'userprofiledetails2',
|
|
141
|
-
];
|
|
142
|
-
S.addModel(model1);
|
|
143
|
-
modelNames1.forEach(v => expect(S.hasModel(v)).to.be.true);
|
|
144
|
-
modelNames2.forEach(v => expect(S.hasModel(v)).to.be.false);
|
|
145
|
-
});
|
|
146
118
|
});
|
|
147
119
|
|
|
148
120
|
describe('getModel', function () {
|
|
149
|
-
it('
|
|
121
|
+
it('should return the model definition for the model name', function () {
|
|
150
122
|
const model = {name: 'model'};
|
|
123
|
+
const S = new DefinitionRegistry();
|
|
151
124
|
S.addModel(model);
|
|
152
125
|
const result = S.getModel('model');
|
|
153
126
|
expect(result).to.be.eql(model);
|
|
154
127
|
});
|
|
155
128
|
|
|
156
|
-
it('
|
|
129
|
+
it('should throw an error when the model name is not registered', function () {
|
|
130
|
+
const S = new DefinitionRegistry();
|
|
157
131
|
const throwable = () => S.getModel('undefined');
|
|
158
132
|
expect(throwable).to.throw('Model "undefined" is not defined.');
|
|
159
133
|
});
|
|
134
|
+
});
|
|
160
135
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
'USER-PROFILE-DETAILS',
|
|
169
|
-
'USER_PROFILE_DETAILS',
|
|
170
|
-
'USERPROFILEDETAILS',
|
|
171
|
-
'userprofiledetails',
|
|
172
|
-
];
|
|
173
|
-
S.addModel(model);
|
|
174
|
-
modelNames.forEach(v => expect(S.getModel(v)).to.be.eq(model));
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('should respect numbers in the model name', function () {
|
|
178
|
-
const model1 = {name: 'userProfileDetails1'};
|
|
179
|
-
const modelNames1 = [
|
|
180
|
-
'userProfileDetails1',
|
|
181
|
-
'UserProfileDetails1',
|
|
182
|
-
'user-profile-details-1',
|
|
183
|
-
'user_profile_details_1',
|
|
184
|
-
'USER-PROFILE-DETAILS-1',
|
|
185
|
-
'USER_PROFILE_DETAILS_1',
|
|
186
|
-
'USERPROFILEDETAILS1',
|
|
187
|
-
'userprofiledetails1',
|
|
188
|
-
];
|
|
189
|
-
const modelNames2 = [
|
|
190
|
-
'userProfileDetails2',
|
|
191
|
-
'UserProfileDetails2',
|
|
192
|
-
'user-profile-details-2',
|
|
193
|
-
'user_profile_details_2',
|
|
194
|
-
'USER-PROFILE-DETAILS-2',
|
|
195
|
-
'USER_PROFILE_DETAILS_2',
|
|
196
|
-
'USERPROFILEDETAILS2',
|
|
197
|
-
'userprofiledetails2',
|
|
198
|
-
];
|
|
136
|
+
describe('getModelNames', function () {
|
|
137
|
+
it('should return an array of model names in the definition order', function () {
|
|
138
|
+
const model1 = {name: 'model1'};
|
|
139
|
+
const model2 = {name: 'model2'};
|
|
140
|
+
const model3 = {name: 'model3'};
|
|
141
|
+
const S = new DefinitionRegistry();
|
|
142
|
+
expect(S.getModelNames()).to.be.eql([]);
|
|
199
143
|
S.addModel(model1);
|
|
200
|
-
|
|
201
|
-
|
|
144
|
+
S.addModel(model2);
|
|
145
|
+
S.addModel(model3);
|
|
146
|
+
expect(S.getModelNames()).to.be.eql([
|
|
147
|
+
model1.name,
|
|
148
|
+
model2.name,
|
|
149
|
+
model3.name,
|
|
150
|
+
]);
|
|
202
151
|
});
|
|
203
152
|
});
|
|
204
153
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {Service} from '@e22m4u/js-service';
|
|
2
2
|
import {Repository} from './repository.js';
|
|
3
|
-
import {modelNameToModelKey} from '../utils/index.js';
|
|
4
3
|
import {InvalidArgumentError} from '../errors/index.js';
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -49,13 +48,12 @@ export class RepositoryRegistry extends Service {
|
|
|
49
48
|
* @returns {Repository}
|
|
50
49
|
*/
|
|
51
50
|
getRepository(modelName) {
|
|
52
|
-
|
|
53
|
-
let repository = this._repositories[modelKey];
|
|
51
|
+
let repository = this._repositories[modelName];
|
|
54
52
|
if (repository) {
|
|
55
53
|
return repository;
|
|
56
54
|
}
|
|
57
55
|
repository = new this._repositoryCtor(this.container, modelName);
|
|
58
|
-
this._repositories[
|
|
56
|
+
this._repositories[modelName] = repository;
|
|
59
57
|
return repository;
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -35,25 +35,6 @@ describe('RepositoryRegistry', function () {
|
|
|
35
35
|
expect(repA2).to.be.not.eq(repB2);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
it('should ignore naming convention of the model name', function () {
|
|
39
|
-
const dbs = new DatabaseSchema();
|
|
40
|
-
const modelName = 'userProfileDetails';
|
|
41
|
-
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
42
|
-
dbs.defineModel({name: modelName, datasource: 'datasource'});
|
|
43
|
-
const reg = dbs.getService(RepositoryRegistry);
|
|
44
|
-
const rep = reg.getRepository(modelName);
|
|
45
|
-
const modelNames = [
|
|
46
|
-
'UserProfileDetails',
|
|
47
|
-
'user-profile-details',
|
|
48
|
-
'user_profile_details',
|
|
49
|
-
'USER-PROFILE-DETAILS',
|
|
50
|
-
'USER_PROFILE_DETAILS',
|
|
51
|
-
'USERPROFILEDETAILS',
|
|
52
|
-
'userprofiledetails',
|
|
53
|
-
];
|
|
54
|
-
modelNames.forEach(v => expect(reg.getRepository(v)).to.be.eq(rep));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
38
|
it('should respect numbers in the model name', function () {
|
|
58
39
|
const dbs = new DatabaseSchema();
|
|
59
40
|
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
package/src/utils/index.d.ts
CHANGED
package/src/utils/index.js
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {InvalidArgumentError} from '../errors/index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Model name to model key.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} modelName
|
|
7
|
-
* @returns {string}
|
|
8
|
-
*/
|
|
9
|
-
export function modelNameToModelKey(modelName) {
|
|
10
|
-
if (!modelName || typeof modelName !== 'string' || /\s/.test(modelName)) {
|
|
11
|
-
throw new InvalidArgumentError(
|
|
12
|
-
'Model name must be a non-empty String ' +
|
|
13
|
-
'without spaces, but %v was given.',
|
|
14
|
-
modelName,
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
return modelName.toLowerCase().replace(/[-_]/g, '');
|
|
18
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {expect} from 'chai';
|
|
2
|
-
import {modelNameToModelKey} from './model-name-to-model-key.js';
|
|
3
|
-
|
|
4
|
-
describe('modelNameToModelKey', function () {
|
|
5
|
-
it('should return a simple lowercase string as is', function () {
|
|
6
|
-
expect(modelNameToModelKey('user')).to.be.eq('user');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('should convert to lowercase and remove hyphens and underscores', function () {
|
|
10
|
-
const modelNames = [
|
|
11
|
-
'userProfileDetails',
|
|
12
|
-
'UserProfileDetails',
|
|
13
|
-
'user-profile-details',
|
|
14
|
-
'user_profile_details',
|
|
15
|
-
'User-Profile-Details',
|
|
16
|
-
'User_Profile_Details',
|
|
17
|
-
'USER-PROFILE-DETAILS',
|
|
18
|
-
'USER_PROFILE_DETAILS',
|
|
19
|
-
'USERPROFILEDETAILS',
|
|
20
|
-
'userprofiledetails',
|
|
21
|
-
];
|
|
22
|
-
modelNames.forEach(v =>
|
|
23
|
-
expect(modelNameToModelKey(v)).to.be.eq('userprofiledetails'),
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should handle a mixed string with uppercase, hyphens and underscores', function () {
|
|
28
|
-
const modelName = 'User_Profile-Details';
|
|
29
|
-
const expected = 'userprofiledetails';
|
|
30
|
-
expect(modelNameToModelKey(modelName)).to.be.eq(expected);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should not remove numbers from the string', function () {
|
|
34
|
-
const modelName = 'Type1-Model_2';
|
|
35
|
-
const expected = 'type1model2';
|
|
36
|
-
expect(modelNameToModelKey(modelName)).to.be.eq(expected);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should throw an error for an empty string', function () {
|
|
40
|
-
const throwable = () => modelNameToModelKey('');
|
|
41
|
-
expect(throwable).to.throw(
|
|
42
|
-
'Model name must be a non-empty String ' +
|
|
43
|
-
'without spaces, but "" was given.',
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should throw an error for a string with spaces', function () {
|
|
48
|
-
const throwable = () => modelNameToModelKey('user profile');
|
|
49
|
-
expect(throwable).to.throw(
|
|
50
|
-
'Model name must be a non-empty String ' +
|
|
51
|
-
'without spaces, but "user profile" was given.',
|
|
52
|
-
);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should throw an error for null', function () {
|
|
56
|
-
const throwable = () => modelNameToModelKey(null);
|
|
57
|
-
expect(throwable).to.throw(
|
|
58
|
-
'Model name must be a non-empty String ' +
|
|
59
|
-
'without spaces, but null was given.',
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should throw an error for undefined', function () {
|
|
64
|
-
const throwable = () => modelNameToModelKey(undefined);
|
|
65
|
-
expect(throwable).to.throw(
|
|
66
|
-
'Model name must be a non-empty String ' +
|
|
67
|
-
'without spaces, but undefined was given.',
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should throw an error for a number', function () {
|
|
72
|
-
const throwable = () => modelNameToModelKey(123);
|
|
73
|
-
expect(throwable).to.throw(
|
|
74
|
-
'Model name must be a non-empty String ' +
|
|
75
|
-
'without spaces, but 123 was given.',
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should throw an error for an object', function () {
|
|
80
|
-
const throwable = () => modelNameToModelKey({name: 'test'});
|
|
81
|
-
expect(throwable).to.throw(
|
|
82
|
-
'Model name must be a non-empty String ' +
|
|
83
|
-
'without spaces, but Object was given.',
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should throw an error for an array', function () {
|
|
88
|
-
const throwable = () => modelNameToModelKey(['test']);
|
|
89
|
-
expect(throwable).to.throw(
|
|
90
|
-
'Model name must be a non-empty String ' +
|
|
91
|
-
'without spaces, but Array was given.',
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
});
|