@e22m4u/js-repository 0.0.41 → 0.1.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.
- package/.eslintignore +1 -0
- package/.husky/pre-commit +1 -0
- package/README.md +516 -526
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +99 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1394 -0
- package/docs/classes/Adapter.html +38 -0
- package/docs/classes/AdapterLoader.html +16 -0
- package/docs/classes/AdapterRegistry.html +16 -0
- package/docs/classes/BelongsToResolver.html +18 -0
- package/docs/classes/DatasourceDefinitionValidator.html +16 -0
- package/docs/classes/DefinitionRegistry.html +26 -0
- package/docs/classes/FieldsClauseTool.html +20 -0
- package/docs/classes/HasManyResolver.html +20 -0
- package/docs/classes/HasOneResolver.html +20 -0
- package/docs/classes/IncludeClauseTool.html +24 -0
- package/docs/classes/InvalidArgumentError.html +14 -0
- package/docs/classes/InvalidOperatorValueError.html +14 -0
- package/docs/classes/ModelDataSanitizer.html +16 -0
- package/docs/classes/ModelDataValidator.html +18 -0
- package/docs/classes/ModelDefinitionUtils.html +46 -0
- package/docs/classes/ModelDefinitionValidator.html +16 -0
- package/docs/classes/NotImplementedError.html +14 -0
- package/docs/classes/OperatorClauseTool.html +72 -0
- package/docs/classes/OrderClauseTool.html +20 -0
- package/docs/classes/PrimaryKeysDefinitionValidator.html +16 -0
- package/docs/classes/PropertiesDefinitionValidator.html +16 -0
- package/docs/classes/ReferencesManyResolver.html +16 -0
- package/docs/classes/RelationsDefinitionValidator.html +16 -0
- package/docs/classes/Repository.html +44 -0
- package/docs/classes/RepositoryRegistry.html +18 -0
- package/docs/classes/Schema.html +20 -0
- package/docs/classes/SliceClauseTool.html +20 -0
- package/docs/classes/WhereClauseTool.html +18 -0
- package/docs/enums/DataType.html +8 -0
- package/docs/enums/RelationType.html +6 -0
- package/docs/functions/capitalize.html +2 -0
- package/docs/functions/cloneDeep.html +2 -0
- package/docs/functions/excludeObjectKeys.html +2 -0
- package/docs/functions/getCtorName.html +2 -0
- package/docs/functions/getValueByPath.html +2 -0
- package/docs/functions/isCtor.html +2 -0
- package/docs/functions/isPureObject.html +2 -0
- package/docs/functions/selectObjectKeys.html +2 -0
- package/docs/functions/singularize.html +2 -0
- package/docs/functions/stringToRegexp.html +2 -0
- package/docs/index.html +284 -0
- package/docs/interfaces/AndClause.html +5 -0
- package/docs/interfaces/OrClause.html +5 -0
- package/docs/modules.html +80 -0
- package/docs/types/AnyObject.html +2 -0
- package/docs/types/BelongsToDefinition.html +6 -0
- package/docs/types/DEFAULT_PRIMARY_KEY_PROPERTY_NAME.html +2 -0
- package/docs/types/DatasourceDefinition.html +2 -0
- package/docs/types/FieldsClause.html +4 -0
- package/docs/types/FilterClause.html +2 -0
- package/docs/types/Flatten.html +1 -0
- package/docs/types/FullPropertyDefinition.html +2 -0
- package/docs/types/HasManyDefinition.html +4 -0
- package/docs/types/HasOneDefinition.html +4 -0
- package/docs/types/Identity.html +2 -0
- package/docs/types/IncludeClause.html +14 -0
- package/docs/types/ItemFilterClause.html +2 -0
- package/docs/types/ModelData.html +2 -0
- package/docs/types/ModelDefinition.html +2 -0
- package/docs/types/ModelId.html +2 -0
- package/docs/types/NestedIncludeClause.html +10 -0
- package/docs/types/NormalizedFieldsClause.html +4 -0
- package/docs/types/NormalizedIncludeClause.html +6 -0
- package/docs/types/OperatorClause.html +4 -0
- package/docs/types/OptionalUnlessRequiredId.html +2 -0
- package/docs/types/OrderClause.html +4 -0
- package/docs/types/PartialBy.html +2 -0
- package/docs/types/PartialWithoutId.html +2 -0
- package/docs/types/PolyBelongsToDefinition.html +6 -0
- package/docs/types/PolyHasManyDefinitionWithTargetKeys.html +4 -0
- package/docs/types/PolyHasManyDefinitionWithTargetRelationName.html +4 -0
- package/docs/types/PolyHasOneDefinitionWithTargetKeys.html +4 -0
- package/docs/types/PolyHasOneDefinitionWithTargetRelationName.html +4 -0
- package/docs/types/PropertiesClause.html +4 -0
- package/docs/types/PropertyDefinition.html +2 -0
- package/docs/types/PropertyDefinitionMap.html +2 -0
- package/docs/types/ReferencesManyDefinition.html +6 -0
- package/docs/types/RelationDefinition.html +4 -0
- package/docs/types/RelationDefinitionMap.html +2 -0
- package/docs/types/WhereClause.html +4 -0
- package/docs/types/WithoutId.html +2 -0
- package/package.json +14 -12
- package/src/adapter/adapter.d.ts +13 -0
- package/src/adapter/adapter.js +15 -0
- package/src/adapter/adapter.spec.js +8 -0
- package/src/adapter/builtin/memory-adapter.d.ts +13 -0
- package/src/adapter/builtin/memory-adapter.js +30 -0
- package/src/adapter/builtin/memory-adapter.spec.js +660 -8
- package/src/adapter/decorator/data-sanitizing-decorator.js +6 -0
- package/src/adapter/decorator/data-sanitizing-decorator.spec.js +13 -0
- package/src/adapter/decorator/data-validation-decorator.js +6 -0
- package/src/adapter/decorator/data-validation-decorator.spec.js +13 -0
- package/src/adapter/decorator/default-values-decorator.js +6 -0
- package/src/adapter/decorator/default-values-decorator.spec.js +16 -0
- package/src/adapter/decorator/fields-filtering-decorator.js +13 -0
- package/src/adapter/decorator/fields-filtering-decorator.spec.js +17 -0
- package/src/adapter/decorator/inclusion-decorator.js +13 -0
- package/src/adapter/decorator/inclusion-decorator.spec.js +17 -0
- package/src/definition/model/relations/relation-definition.d.ts +11 -29
- package/src/definition/model/relations/relations-definition-validator.js +4 -4
- package/src/definition/model/relations/relations-definition-validator.spec.js +18 -18
- package/src/filter/filter-clause.d.ts +5 -4
- package/src/repository/repository.js +2 -6
- package/typedoc.json +4 -0
|
@@ -18,6 +18,11 @@ class TestAdapter extends Adapter {
|
|
|
18
18
|
return Promise.resolve({});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
replaceOrCreate(modelName, modelData, filter = undefined) {
|
|
23
|
+
return Promise.resolve({});
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
// eslint-disable-next-line no-unused-vars
|
|
22
27
|
patch(modelName, modelData, where = undefined) {
|
|
23
28
|
return Promise.resolve(1);
|
|
@@ -54,6 +59,14 @@ describe('DataSanitizingDecorator', function () {
|
|
|
54
59
|
expect(V.sanitize).to.be.called.with.exactly('model', data);
|
|
55
60
|
});
|
|
56
61
|
|
|
62
|
+
it('overrides the "replaceOrCreate" method and sanitizes a given data', async function () {
|
|
63
|
+
sandbox.on(V, 'sanitize');
|
|
64
|
+
const data = {};
|
|
65
|
+
await A.replaceOrCreate('model', data);
|
|
66
|
+
expect(V.sanitize).to.be.called.once;
|
|
67
|
+
expect(V.sanitize).to.be.called.with.exactly('model', data);
|
|
68
|
+
});
|
|
69
|
+
|
|
57
70
|
it('overrides the "patch" method and sanitizes a given data', async function () {
|
|
58
71
|
sandbox.on(V, 'sanitize');
|
|
59
72
|
const data = {};
|
|
@@ -32,6 +32,12 @@ export class DataValidationDecorator extends Service {
|
|
|
32
32
|
return replaceById.call(this, modelName, id, modelData, filter);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
const replaceOrCreate = adapter.replaceOrCreate;
|
|
36
|
+
adapter.replaceOrCreate = function (modelName, modelData, filter) {
|
|
37
|
+
this.getService(ModelDataValidator).validate(modelName, modelData);
|
|
38
|
+
return replaceOrCreate.call(this, modelName, modelData, filter);
|
|
39
|
+
};
|
|
40
|
+
|
|
35
41
|
const patch = adapter.patch;
|
|
36
42
|
adapter.patch = function (modelName, modelData, where) {
|
|
37
43
|
this.getService(ModelDataValidator).validate(modelName, modelData, true);
|
|
@@ -18,6 +18,11 @@ class TestAdapter extends Adapter {
|
|
|
18
18
|
return Promise.resolve({});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
replaceOrCreate(modelName, modelData, filter = undefined) {
|
|
23
|
+
return Promise.resolve({});
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
// eslint-disable-next-line no-unused-vars
|
|
22
27
|
patch(modelName, modelData, where = undefined) {
|
|
23
28
|
return Promise.resolve(1);
|
|
@@ -54,6 +59,14 @@ describe('DataValidationDecorator', function () {
|
|
|
54
59
|
expect(V.validate).to.be.called.with.exactly('model', data);
|
|
55
60
|
});
|
|
56
61
|
|
|
62
|
+
it('overrides the "replaceOrCreate" method and validates a given data', async function () {
|
|
63
|
+
sandbox.on(V, 'validate');
|
|
64
|
+
const data = {};
|
|
65
|
+
await A.replaceOrCreate('model', data);
|
|
66
|
+
expect(V.validate).to.be.called.once;
|
|
67
|
+
expect(V.validate).to.be.called.with.exactly('model', data);
|
|
68
|
+
});
|
|
69
|
+
|
|
57
70
|
it('overrides the "patchById" method and validates a given data', async function () {
|
|
58
71
|
sandbox.on(V, 'validate');
|
|
59
72
|
const data = {};
|
|
@@ -36,6 +36,12 @@ export class DefaultValuesDecorator extends Service {
|
|
|
36
36
|
return replaceById.call(this, modelName, id, modelData, filter);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const replaceOrCreate = adapter.replaceOrCreate;
|
|
40
|
+
adapter.replaceOrCreate = function (modelName, modelData, filter) {
|
|
41
|
+
modelData = setDefaults(modelName, modelData);
|
|
42
|
+
return replaceOrCreate.call(this, modelName, modelData, filter);
|
|
43
|
+
};
|
|
44
|
+
|
|
39
45
|
const patch = adapter.patch;
|
|
40
46
|
adapter.patch = function (modelName, modelData, where) {
|
|
41
47
|
modelData = setDefaults(modelName, modelData, true);
|
|
@@ -29,6 +29,11 @@ class TestAdapter extends Adapter {
|
|
|
29
29
|
return modelData;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// eslint-disable-next-line no-unused-vars
|
|
33
|
+
async replaceOrCreate(modelName, modelData, filter = undefined) {
|
|
34
|
+
return modelData;
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
// eslint-disable-next-line no-unused-vars
|
|
33
38
|
patch(modelName, modelData, where = undefined) {
|
|
34
39
|
return Promise.resolve(modelData);
|
|
@@ -81,6 +86,17 @@ describe('DefaultValuesDecorator', function () {
|
|
|
81
86
|
);
|
|
82
87
|
});
|
|
83
88
|
|
|
89
|
+
it('overrides the "replaceOrCreate" method and sets default values to input data', async function () {
|
|
90
|
+
sandbox.on(U, 'setDefaultValuesToEmptyProperties');
|
|
91
|
+
const retval = await A.replaceOrCreate('model', INPUT_DATA);
|
|
92
|
+
expect(retval).to.be.eql({prop: 'value'});
|
|
93
|
+
expect(U.setDefaultValuesToEmptyProperties).to.be.called.once;
|
|
94
|
+
expect(U.setDefaultValuesToEmptyProperties).to.be.called.with.exactly(
|
|
95
|
+
'model',
|
|
96
|
+
INPUT_DATA,
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
84
100
|
describe('overrides the "patch" method and sets default values to input data', function () {
|
|
85
101
|
it('does not set default values to not existing properties of input data', async function () {
|
|
86
102
|
sandbox.on(U, 'setDefaultValuesToEmptyProperties');
|
|
@@ -45,6 +45,19 @@ export class FieldsFilteringDecorator extends Service {
|
|
|
45
45
|
return result;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
const replaceOrCreate = adapter.replaceOrCreate;
|
|
49
|
+
adapter.replaceOrCreate = async function (modelName, modelData, filter) {
|
|
50
|
+
let result = await replaceOrCreate.call(
|
|
51
|
+
this,
|
|
52
|
+
modelName,
|
|
53
|
+
modelData,
|
|
54
|
+
filter,
|
|
55
|
+
);
|
|
56
|
+
if (filter && typeof filter === 'object' && filter.fields)
|
|
57
|
+
result = selectFields(result, modelName, filter.fields);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
|
|
48
61
|
const patchById = adapter.patchById;
|
|
49
62
|
adapter.patchById = async function (modelName, id, modelData, filter) {
|
|
50
63
|
let result = await patchById.call(this, modelName, id, modelData, filter);
|
|
@@ -32,6 +32,11 @@ class TestAdapter extends Adapter {
|
|
|
32
32
|
return MODEL_DATA;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// eslint-disable-next-line no-unused-vars
|
|
36
|
+
async replaceOrCreate(modelName, modelData, filter = undefined) {
|
|
37
|
+
return MODEL_DATA;
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
// eslint-disable-next-line no-unused-vars
|
|
36
41
|
async patchById(modelName, id, modelData, filter = undefined) {
|
|
37
42
|
return MODEL_DATA;
|
|
@@ -81,6 +86,18 @@ describe('FieldsFilteringDecorator', function () {
|
|
|
81
86
|
);
|
|
82
87
|
});
|
|
83
88
|
|
|
89
|
+
it('overrides the "replaceOrCreate" method and filtering output fields', async function () {
|
|
90
|
+
sandbox.on(T, 'filter');
|
|
91
|
+
const retval = await A.replaceOrCreate(MODEL_NAME, {}, FILTER);
|
|
92
|
+
expect(retval).to.be.eql(RETVAL_DATA);
|
|
93
|
+
expect(T.filter).to.be.called.once;
|
|
94
|
+
expect(T.filter).to.be.called.with.exactly(
|
|
95
|
+
MODEL_DATA,
|
|
96
|
+
MODEL_NAME,
|
|
97
|
+
FILTER.fields,
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
84
101
|
it('overrides the "patchById" method and filtering output fields', async function () {
|
|
85
102
|
sandbox.on(T, 'filter');
|
|
86
103
|
const retval = await A.patchById(MODEL_NAME, 1, {}, FILTER);
|
|
@@ -45,6 +45,19 @@ export class InclusionDecorator extends Service {
|
|
|
45
45
|
return retvalData;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
const replaceOrCreate = adapter.replaceOrCreate;
|
|
49
|
+
adapter.replaceOrCreate = async function (modelName, modelData, filter) {
|
|
50
|
+
const retvalData = await replaceOrCreate.call(
|
|
51
|
+
this,
|
|
52
|
+
modelName,
|
|
53
|
+
modelData,
|
|
54
|
+
filter,
|
|
55
|
+
);
|
|
56
|
+
if (filter && typeof filter === 'object' && filter.include)
|
|
57
|
+
await includeTo([retvalData], modelName, filter.include);
|
|
58
|
+
return retvalData;
|
|
59
|
+
};
|
|
60
|
+
|
|
48
61
|
const patchById = adapter.patchById;
|
|
49
62
|
adapter.patchById = async function (modelName, id, modelData, filter) {
|
|
50
63
|
const retvalData = await patchById.call(
|
|
@@ -30,6 +30,11 @@ class TestAdapter extends Adapter {
|
|
|
30
30
|
return Object.assign({}, MODEL_DATA);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// eslint-disable-next-line no-unused-vars
|
|
34
|
+
async replaceOrCreate(modelName, modelData, filter = undefined) {
|
|
35
|
+
return Object.assign({}, MODEL_DATA);
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
// eslint-disable-next-line no-unused-vars
|
|
34
39
|
async patchById(modelName, id, modelData, filter = undefined) {
|
|
35
40
|
return Object.assign({}, MODEL_DATA);
|
|
@@ -79,6 +84,18 @@ describe('InclusionDecorator', function () {
|
|
|
79
84
|
expect(T.includeTo).to.be.called.once;
|
|
80
85
|
});
|
|
81
86
|
|
|
87
|
+
it('overrides the "replaceOrCreate" method and applies clause inclusion', async function () {
|
|
88
|
+
sandbox.on(T, 'includeTo', function (entities, modelName, clause) {
|
|
89
|
+
expect(entities).to.be.eql([MODEL_DATA]);
|
|
90
|
+
expect(modelName).to.be.eql('model');
|
|
91
|
+
expect(clause).to.be.eql(FILTER.include);
|
|
92
|
+
Object.assign(entities[0], RETVAL_DATA);
|
|
93
|
+
});
|
|
94
|
+
const retval = await A.replaceOrCreate('model', {}, FILTER);
|
|
95
|
+
expect(retval).to.be.eql(RETVAL_DATA);
|
|
96
|
+
expect(T.includeTo).to.be.called.once;
|
|
97
|
+
});
|
|
98
|
+
|
|
82
99
|
it('overrides the "patchById" method and applies clause inclusion', async function () {
|
|
83
100
|
sandbox.on(T, 'includeTo', function (entities, modelName, clause) {
|
|
84
101
|
expect(entities).to.be.eql([MODEL_DATA]);
|
|
@@ -73,7 +73,7 @@ export declare type BelongsToDefinition = {
|
|
|
73
73
|
* type: RelationType.BELONGS_TO,
|
|
74
74
|
* polymorphic: true,
|
|
75
75
|
* foreignKey: 'referenceId',
|
|
76
|
-
* discriminator: 'referenceType,
|
|
76
|
+
* discriminator: 'referenceType',
|
|
77
77
|
* }
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
@@ -99,8 +99,8 @@ export declare type PolyBelongsToDefinition = {
|
|
|
99
99
|
export declare type HasOneDefinition = {
|
|
100
100
|
type: RelationType.HAS_ONE;
|
|
101
101
|
model: string;
|
|
102
|
+
foreignKey: string;
|
|
102
103
|
polymorphic?: false;
|
|
103
|
-
foreignKey?: string;
|
|
104
104
|
discriminator?: undefined;
|
|
105
105
|
};
|
|
106
106
|
|
|
@@ -127,23 +127,14 @@ export declare type PolyHasOneDefinitionWithTargetRelationName = {
|
|
|
127
127
|
/**
|
|
128
128
|
* The polymorphic "hasOne" relation with target relation keys.
|
|
129
129
|
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```
|
|
132
|
-
* {
|
|
133
|
-
* type: RelationType.HAS_ONE,
|
|
134
|
-
* model: 'model',
|
|
135
|
-
* polymorphic: true,
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*
|
|
139
|
-
* @example Verbose definition.
|
|
130
|
+
* @example
|
|
140
131
|
* ```
|
|
141
132
|
* {
|
|
142
133
|
* type: RelationType.HAS_ONE,
|
|
143
134
|
* model: 'model',
|
|
144
135
|
* polymorphic: true,
|
|
145
136
|
* foreignKey: 'referenceId',
|
|
146
|
-
* discriminator: 'referenceType,
|
|
137
|
+
* discriminator: 'referenceType',
|
|
147
138
|
* }
|
|
148
139
|
* ```
|
|
149
140
|
*/
|
|
@@ -151,8 +142,8 @@ export declare type PolyHasOneDefinitionWithTargetKeys = {
|
|
|
151
142
|
type: RelationType.HAS_ONE;
|
|
152
143
|
model: string;
|
|
153
144
|
polymorphic: true;
|
|
154
|
-
foreignKey
|
|
155
|
-
discriminator
|
|
145
|
+
foreignKey: string;
|
|
146
|
+
discriminator: string;
|
|
156
147
|
};
|
|
157
148
|
|
|
158
149
|
/**
|
|
@@ -170,8 +161,8 @@ export declare type PolyHasOneDefinitionWithTargetKeys = {
|
|
|
170
161
|
export declare type HasManyDefinition = {
|
|
171
162
|
type: RelationType.HAS_MANY;
|
|
172
163
|
model: string;
|
|
164
|
+
foreignKey: string;
|
|
173
165
|
polymorphic?: false;
|
|
174
|
-
foreignKey?: string;
|
|
175
166
|
discriminator?: undefined;
|
|
176
167
|
};
|
|
177
168
|
|
|
@@ -198,23 +189,14 @@ export declare type PolyHasManyDefinitionWithTargetRelationName = {
|
|
|
198
189
|
/**
|
|
199
190
|
* The polymorphic "hasMany" relation with target relation keys.
|
|
200
191
|
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```
|
|
203
|
-
* {
|
|
204
|
-
* type: RelationType.HAS_MANY,
|
|
205
|
-
* model: 'model',
|
|
206
|
-
* polymorphic: true,
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* @example Verbose definition.
|
|
192
|
+
* @example
|
|
211
193
|
* ```
|
|
212
194
|
* {
|
|
213
195
|
* type: RelationType.HAS_MANY,
|
|
214
196
|
* model: 'model',
|
|
215
197
|
* polymorphic: true,
|
|
216
198
|
* foreignKey: 'referenceId',
|
|
217
|
-
* discriminator: 'referenceType,
|
|
199
|
+
* discriminator: 'referenceType',
|
|
218
200
|
* }
|
|
219
201
|
* ```
|
|
220
202
|
*/
|
|
@@ -222,8 +204,8 @@ export declare type PolyHasManyDefinitionWithTargetKeys = {
|
|
|
222
204
|
type: RelationType.HAS_MANY;
|
|
223
205
|
model: string;
|
|
224
206
|
polymorphic: true;
|
|
225
|
-
foreignKey
|
|
226
|
-
discriminator
|
|
207
|
+
foreignKey: string;
|
|
208
|
+
discriminator: string;
|
|
227
209
|
};
|
|
228
210
|
|
|
229
211
|
/**
|
|
@@ -94,8 +94,8 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
94
94
|
* {
|
|
95
95
|
* type: RelationType.BELONGS_TO,
|
|
96
96
|
* polymorphic: true,
|
|
97
|
-
* foreignKey: 'referenceId',
|
|
98
|
-
* discriminator: 'referenceType, // optional
|
|
97
|
+
* foreignKey: 'referenceId', // optional
|
|
98
|
+
* discriminator: 'referenceType', // optional
|
|
99
99
|
* }
|
|
100
100
|
* ```
|
|
101
101
|
*
|
|
@@ -193,7 +193,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
193
193
|
* model: 'model',
|
|
194
194
|
* polymorphic: true,
|
|
195
195
|
* foreignKey: 'referenceId',
|
|
196
|
-
* discriminator: 'referenceType,
|
|
196
|
+
* discriminator: 'referenceType',
|
|
197
197
|
* }
|
|
198
198
|
* ```
|
|
199
199
|
*
|
|
@@ -311,7 +311,7 @@ export class RelationsDefinitionValidator extends Service {
|
|
|
311
311
|
* model: 'model',
|
|
312
312
|
* polymorphic: true,
|
|
313
313
|
* foreignKey: 'referenceId',
|
|
314
|
-
* discriminator: 'referenceType,
|
|
314
|
+
* discriminator: 'referenceType',
|
|
315
315
|
* }
|
|
316
316
|
* ```
|
|
317
317
|
*
|
|
@@ -253,15 +253,15 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
253
253
|
const validate = v => {
|
|
254
254
|
const foo = {
|
|
255
255
|
type: RelationType.HAS_ONE,
|
|
256
|
-
model:
|
|
257
|
-
foreignKey:
|
|
256
|
+
model: v,
|
|
257
|
+
foreignKey: 'modelId',
|
|
258
258
|
};
|
|
259
259
|
return () => S.validate('model', {foo});
|
|
260
260
|
};
|
|
261
261
|
const error = v =>
|
|
262
262
|
format(
|
|
263
263
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
264
|
-
'so it requires the option "
|
|
264
|
+
'so it requires the option "model" to be a non-empty String, ' +
|
|
265
265
|
'but %s given.',
|
|
266
266
|
v,
|
|
267
267
|
);
|
|
@@ -273,22 +273,22 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
273
273
|
expect(validate([])).to.throw(error('Array'));
|
|
274
274
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
275
275
|
expect(validate(null)).to.throw(error('null'));
|
|
276
|
-
validate('
|
|
276
|
+
validate('model')();
|
|
277
277
|
});
|
|
278
278
|
|
|
279
|
-
it('requires the option "foreignKey" to be a string', function () {
|
|
279
|
+
it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
280
280
|
const validate = v => {
|
|
281
281
|
const foo = {
|
|
282
282
|
type: RelationType.HAS_ONE,
|
|
283
|
-
model:
|
|
284
|
-
foreignKey:
|
|
283
|
+
model: 'model',
|
|
284
|
+
foreignKey: v,
|
|
285
285
|
};
|
|
286
286
|
return () => S.validate('model', {foo});
|
|
287
287
|
};
|
|
288
288
|
const error = v =>
|
|
289
289
|
format(
|
|
290
290
|
'The relation "foo" of the model "model" has the type "hasOne", ' +
|
|
291
|
-
'so it requires the option "
|
|
291
|
+
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
292
292
|
'but %s given.',
|
|
293
293
|
v,
|
|
294
294
|
);
|
|
@@ -300,7 +300,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
300
300
|
expect(validate([])).to.throw(error('Array'));
|
|
301
301
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
302
302
|
expect(validate(null)).to.throw(error('null'));
|
|
303
|
-
validate('
|
|
303
|
+
validate('modelId')();
|
|
304
304
|
});
|
|
305
305
|
|
|
306
306
|
it('throws an error if the option "discriminator" is provided', function () {
|
|
@@ -479,15 +479,15 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
479
479
|
const validate = v => {
|
|
480
480
|
const foo = {
|
|
481
481
|
type: RelationType.HAS_MANY,
|
|
482
|
-
model:
|
|
483
|
-
foreignKey:
|
|
482
|
+
model: v,
|
|
483
|
+
foreignKey: 'modelId',
|
|
484
484
|
};
|
|
485
485
|
return () => S.validate('model', {foo});
|
|
486
486
|
};
|
|
487
487
|
const error = v =>
|
|
488
488
|
format(
|
|
489
489
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
490
|
-
'so it requires the option "
|
|
490
|
+
'so it requires the option "model" to be a non-empty String, ' +
|
|
491
491
|
'but %s given.',
|
|
492
492
|
v,
|
|
493
493
|
);
|
|
@@ -499,22 +499,22 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
499
499
|
expect(validate([])).to.throw(error('Array'));
|
|
500
500
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
501
501
|
expect(validate(null)).to.throw(error('null'));
|
|
502
|
-
validate('
|
|
502
|
+
validate('model')();
|
|
503
503
|
});
|
|
504
504
|
|
|
505
|
-
it('requires the option "foreignKey" to be a string', function () {
|
|
505
|
+
it('requires the option "foreignKey" to be a non-empty string', function () {
|
|
506
506
|
const validate = v => {
|
|
507
507
|
const foo = {
|
|
508
508
|
type: RelationType.HAS_MANY,
|
|
509
|
-
model:
|
|
510
|
-
foreignKey:
|
|
509
|
+
model: 'model',
|
|
510
|
+
foreignKey: v,
|
|
511
511
|
};
|
|
512
512
|
return () => S.validate('model', {foo});
|
|
513
513
|
};
|
|
514
514
|
const error = v =>
|
|
515
515
|
format(
|
|
516
516
|
'The relation "foo" of the model "model" has the type "hasMany", ' +
|
|
517
|
-
'so it requires the option "
|
|
517
|
+
'so it requires the option "foreignKey" to be a non-empty String, ' +
|
|
518
518
|
'but %s given.',
|
|
519
519
|
v,
|
|
520
520
|
);
|
|
@@ -526,7 +526,7 @@ describe('RelationsDefinitionValidator', function () {
|
|
|
526
526
|
expect(validate([])).to.throw(error('Array'));
|
|
527
527
|
expect(validate(undefined)).to.throw(error('undefined'));
|
|
528
528
|
expect(validate(null)).to.throw(error('null'));
|
|
529
|
-
validate('
|
|
529
|
+
validate('modelId')();
|
|
530
530
|
});
|
|
531
531
|
|
|
532
532
|
it('throws an error if the option "discriminator" is provided', function () {
|
|
@@ -43,9 +43,9 @@ export declare type ItemFilterClause = Pick<FilterClause, 'fields' | 'include'>;
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
export declare type WhereClause =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
& AndClause
|
|
47
|
+
& OrClause
|
|
48
|
+
& PropertiesClause;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Properties clause.
|
|
@@ -67,7 +67,8 @@ export type PropertiesClause = {
|
|
|
67
67
|
| boolean
|
|
68
68
|
| RegExp
|
|
69
69
|
| null
|
|
70
|
-
| undefined
|
|
70
|
+
| undefined
|
|
71
|
+
| object;
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
/**
|
|
@@ -103,12 +103,8 @@ export class Repository extends Service {
|
|
|
103
103
|
* @returns {Promise<object>}
|
|
104
104
|
*/
|
|
105
105
|
async replaceOrCreate(data, filter = undefined) {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
).getPrimaryKeyAsPropertyName(this.modelName);
|
|
109
|
-
const pkValue = data[pkPropName];
|
|
110
|
-
if (pkValue == null) return this.create(data, filter);
|
|
111
|
-
return this.replaceById(pkValue, data, filter);
|
|
106
|
+
const adapter = await this.getAdapter();
|
|
107
|
+
return adapter.replaceOrCreate(this.modelName, data, filter);
|
|
112
108
|
}
|
|
113
109
|
|
|
114
110
|
/**
|
package/typedoc.json
ADDED