@travetto/model 3.1.4 → 3.1.6
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/README.md +5 -1
- package/package.json +4 -4
- package/src/service/crud.ts +5 -1
- package/support/test/crud.ts +28 -3
package/README.md
CHANGED
|
@@ -79,7 +79,11 @@ export interface ModelCrudSupport extends ModelBasicSupport {
|
|
|
79
79
|
upsert<T extends ModelType>(cls: Class<T>, item: OptionalId<T>): Promise<T>;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* Update
|
|
82
|
+
* Update partial, respecting only top level keys.
|
|
83
|
+
*
|
|
84
|
+
* When invoking this method, any top level keys that are null/undefined are treated as removals/deletes. Any properties
|
|
85
|
+
* that point to sub objects/arrays are treated as wholesale replacements.
|
|
86
|
+
*
|
|
83
87
|
* @param id The document identifier to update
|
|
84
88
|
* @param item The document to partially update.
|
|
85
89
|
* @param view The schema view to validate against
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "Datastore abstraction for core operations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datastore",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"directory": "module/model"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/config": "^3.1.
|
|
29
|
+
"@travetto/config": "^3.1.2",
|
|
30
30
|
"@travetto/di": "^3.1.1",
|
|
31
31
|
"@travetto/registry": "^3.1.1",
|
|
32
|
-
"@travetto/schema": "^3.1.
|
|
32
|
+
"@travetto/schema": "^3.1.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@travetto/cli": "^3.1.
|
|
35
|
+
"@travetto/cli": "^3.1.2",
|
|
36
36
|
"@travetto/test": "^3.1.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
package/src/service/crud.ts
CHANGED
|
@@ -30,7 +30,11 @@ export interface ModelCrudSupport extends ModelBasicSupport {
|
|
|
30
30
|
upsert<T extends ModelType>(cls: Class<T>, item: OptionalId<T>): Promise<T>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Update
|
|
33
|
+
* Update partial, respecting only top level keys.
|
|
34
|
+
*
|
|
35
|
+
* When invoking this method, any top level keys that are null/undefined are treated as removals/deletes. Any properties
|
|
36
|
+
* that point to sub objects/arrays are treated as wholesale replacements.
|
|
37
|
+
*
|
|
34
38
|
* @param id The document identifier to update
|
|
35
39
|
* @param item The document to partially update.
|
|
36
40
|
* @param view The schema view to validate against
|
package/support/test/crud.ts
CHANGED
|
@@ -127,7 +127,6 @@ export abstract class ModelCrudSuite extends BaseModelSuite<ModelCrudSupport> {
|
|
|
127
127
|
gender: 'f',
|
|
128
128
|
address: {
|
|
129
129
|
street1: 'changed\n',
|
|
130
|
-
street2: undefined
|
|
131
130
|
}
|
|
132
131
|
}));
|
|
133
132
|
|
|
@@ -172,7 +171,7 @@ export abstract class ModelCrudSuite extends BaseModelSuite<ModelCrudSupport> {
|
|
|
172
171
|
async testBlankPartialUpdate() {
|
|
173
172
|
const service = await this.service;
|
|
174
173
|
const o = await service.create(User2, User2.from({
|
|
175
|
-
name: 'bob'
|
|
174
|
+
name: 'bob',
|
|
176
175
|
}));
|
|
177
176
|
|
|
178
177
|
assert(o.address === undefined);
|
|
@@ -187,7 +186,8 @@ export abstract class ModelCrudSuite extends BaseModelSuite<ModelCrudSupport> {
|
|
|
187
186
|
const o3 = await service.get(User2, o.id);
|
|
188
187
|
|
|
189
188
|
assert(o3.address !== undefined);
|
|
190
|
-
assert(o3.address
|
|
189
|
+
assert(o3.address.street1 === 'blue');
|
|
190
|
+
assert(o3.address.street2 === undefined);
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
@Test('verify dates')
|
|
@@ -282,4 +282,29 @@ export abstract class ModelCrudSuite extends BaseModelSuite<ModelCrudSupport> {
|
|
|
282
282
|
assert(o2.age === 20);
|
|
283
283
|
assert(o2.address.street2 === 'roader');
|
|
284
284
|
}
|
|
285
|
+
|
|
286
|
+
@Test('Verify nested list in partial update')
|
|
287
|
+
async testPartialUpdateOnLists() {
|
|
288
|
+
const service = await this.service;
|
|
289
|
+
const o = await service.create(SimpleList, {
|
|
290
|
+
names: ['rob', 'tom'],
|
|
291
|
+
simples: [
|
|
292
|
+
{ name: 'roger' },
|
|
293
|
+
{ name: 'dodger' }
|
|
294
|
+
]
|
|
295
|
+
});
|
|
296
|
+
assert(o.names.length === 2);
|
|
297
|
+
assert(o.simples);
|
|
298
|
+
assert(o.simples.length === 2);
|
|
299
|
+
|
|
300
|
+
const o2 = await service.updatePartial(SimpleList, {
|
|
301
|
+
id: o.id,
|
|
302
|
+
names: ['dawn'],
|
|
303
|
+
simples: [{ name: 'jim' }]
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
assert(o2.names.length === 1);
|
|
307
|
+
assert(o2.simples);
|
|
308
|
+
assert(o2.simples.length === 1);
|
|
309
|
+
}
|
|
285
310
|
}
|