@travetto/model 2.2.1 → 2.2.4
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/bin/cli-model_export.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseModelCommand } from './lib/base-command';
|
|
2
2
|
import { ModelExportUtil } from './lib/export';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* CLI Entry point for exporting model schemas
|
|
6
6
|
*/
|
|
7
|
-
export class
|
|
7
|
+
export class ModelExportCommand extends BaseModelCommand {
|
|
8
8
|
name = 'model:export';
|
|
9
9
|
op = 'exportModel' as const;
|
|
10
10
|
|
package/bin/cli-model_install.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { color } from '@travetto/cli/src/color';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { BaseModelCommand } from './lib/base-command';
|
|
4
4
|
import { ModelInstallUtil } from './lib/install';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* CLI Entry point for installing models
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class ModelInstallCommand extends BaseModelCommand {
|
|
10
10
|
name = 'model:install';
|
|
11
11
|
op = 'createModel' as const;
|
|
12
12
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CliCommand, OptionConfig } from '@travetto/cli/src/command';
|
|
2
2
|
import { color } from '@travetto/cli/src/color';
|
|
3
3
|
import { EnvInit } from '@travetto/base/bin/init';
|
|
4
4
|
import type { ModelStorageSupport } from '@travetto/model/src/service/storage';
|
|
@@ -12,7 +12,7 @@ type Options = {
|
|
|
12
12
|
/**
|
|
13
13
|
* CLI Entry point for exporting model schemas
|
|
14
14
|
*/
|
|
15
|
-
export abstract class
|
|
15
|
+
export abstract class BaseModelCommand extends CliCommand<Options> {
|
|
16
16
|
|
|
17
17
|
restoreEnv?: (err: Error) => unknown;
|
|
18
18
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model",
|
|
3
3
|
"displayName": "Data Modeling Support",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.4",
|
|
5
5
|
"description": "Datastore abstraction for core operations.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"datastore",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"directory": "module/model"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/di": "^2.2.
|
|
32
|
-
"@travetto/config": "^2.2.
|
|
33
|
-
"@travetto/registry": "^2.2.
|
|
34
|
-
"@travetto/schema": "^2.2.
|
|
31
|
+
"@travetto/di": "^2.2.4",
|
|
32
|
+
"@travetto/config": "^2.2.4",
|
|
33
|
+
"@travetto/registry": "^2.2.4",
|
|
34
|
+
"@travetto/schema": "^2.2.4"
|
|
35
35
|
},
|
|
36
36
|
"optionalPeerDependencies": {
|
|
37
|
-
"@travetto/cli": "^2.2.
|
|
37
|
+
"@travetto/cli": "^2.2.4"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
package/test-support/base.ts
CHANGED
|
@@ -50,4 +50,12 @@ export abstract class BaseModelSuite<T> {
|
|
|
50
50
|
get service(): Promise<T> {
|
|
51
51
|
return DependencyRegistry.getInstance(this.serviceClass);
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
async toArray<U>(src: AsyncIterable<U> | AsyncGenerator<U>): Promise<U[]> {
|
|
55
|
+
const out: U[] = [];
|
|
56
|
+
for await (const el of src) {
|
|
57
|
+
out.push(el);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
53
61
|
}
|
package/test-support/crud.ts
CHANGED
|
@@ -217,7 +217,7 @@ export abstract class ModelCrudSuite extends BaseModelSuite<ModelCrudSupport> {
|
|
|
217
217
|
people.map(el => service.upsert(Person, el))
|
|
218
218
|
);
|
|
219
219
|
|
|
220
|
-
const found = (await service.list(Person)
|
|
220
|
+
const found = (await this.toArray(service.list(Person))).sort((a, b) => a.age - b.age);
|
|
221
221
|
|
|
222
222
|
assert(found[0].age === people[0].age);
|
|
223
223
|
assert(found[1].age === people[1].age);
|
package/test-support/indexed.ts
CHANGED
|
@@ -123,13 +123,13 @@ export abstract class ModelIndexedSuite extends BaseModelSuite<ModelIndexedSuppo
|
|
|
123
123
|
await service.create(User3, User3.from({ name: 'bob', age: 30, color: 'red' }));
|
|
124
124
|
await service.create(User3, User3.from({ name: 'bob', age: 50, color: 'green' }));
|
|
125
125
|
|
|
126
|
-
const arr = await service.listByIndex(User3, 'userAge', { name: 'bob' })
|
|
126
|
+
const arr = await this.toArray(service.listByIndex(User3, 'userAge', { name: 'bob' }));
|
|
127
127
|
|
|
128
128
|
assert(arr[0].color === 'red' && arr[0].name === 'bob');
|
|
129
129
|
assert(arr[1].color === 'blue' && arr[1].name === 'bob');
|
|
130
130
|
assert(arr[2].color === 'green' && arr[2].name === 'bob');
|
|
131
131
|
|
|
132
|
-
await assert.rejects(() => service.listByIndex(User3, 'userAge', {})
|
|
132
|
+
await assert.rejects(() => this.toArray(service.listByIndex(User3, 'userAge', {})), IndexNotSupported);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
@Test()
|
|
@@ -140,12 +140,12 @@ export abstract class ModelIndexedSuite extends BaseModelSuite<ModelIndexedSuppo
|
|
|
140
140
|
await service.create(User4, User4.from({ child: { name: 'bob', age: 30 }, color: 'red' }));
|
|
141
141
|
await service.create(User4, User4.from({ child: { name: 'bob', age: 50 }, color: 'green' }));
|
|
142
142
|
|
|
143
|
-
const arr = await service.listByIndex(User4, 'childAge', User4.from({ child: { name: 'bob' } }))
|
|
143
|
+
const arr = await this.toArray(service.listByIndex(User4, 'childAge', User4.from({ child: { name: 'bob' } })));
|
|
144
144
|
assert(arr[0].color === 'red' && arr[0].child.name === 'bob' && arr[0].child.age === 30);
|
|
145
145
|
assert(arr[1].color === 'blue' && arr[1].child.name === 'bob' && arr[1].child.age === 40);
|
|
146
146
|
assert(arr[2].color === 'green' && arr[2].child.name === 'bob' && arr[2].child.age === 50);
|
|
147
147
|
|
|
148
|
-
await assert.rejects(() => service.listByIndex(User4, 'childAge', {})
|
|
148
|
+
await assert.rejects(() => this.toArray(service.listByIndex(User4, 'childAge', {})), IndexNotSupported);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
@Test()
|
|
@@ -156,13 +156,13 @@ export abstract class ModelIndexedSuite extends BaseModelSuite<ModelIndexedSuppo
|
|
|
156
156
|
await service.create(User4, User4.from({ child: { name: 'bob', age: 30 }, createdDate: Util.timeFromNow('2d'), color: 'red' }));
|
|
157
157
|
await service.create(User4, User4.from({ child: { name: 'bob', age: 50 }, createdDate: Util.timeFromNow('-1d'), color: 'green' }));
|
|
158
158
|
|
|
159
|
-
const arr = await service.listByIndex(User4, 'nameCreated', User4.from({ child: { name: 'bob' } }))
|
|
159
|
+
const arr = await this.toArray(service.listByIndex(User4, 'nameCreated', User4.from({ child: { name: 'bob' } })));
|
|
160
160
|
|
|
161
161
|
assert(arr[0].color === 'green' && arr[0].child.name === 'bob' && arr[0].child.age === 50);
|
|
162
162
|
assert(arr[1].color === 'red' && arr[1].child.name === 'bob' && arr[1].child.age === 30);
|
|
163
163
|
assert(arr[2].color === 'blue' && arr[2].child.name === 'bob' && arr[2].child.age === 40);
|
|
164
164
|
|
|
165
|
-
await assert.rejects(() => service.listByIndex(User4, 'nameCreated', {})
|
|
165
|
+
await assert.rejects(() => this.toArray(service.listByIndex(User4, 'nameCreated', {})), IndexNotSupported);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
@Test()
|
|
@@ -173,7 +173,7 @@ export abstract class ModelIndexedSuite extends BaseModelSuite<ModelIndexedSuppo
|
|
|
173
173
|
const user2 = await service.upsertByIndex(User4, 'childAge', { child: { name: 'bob', age: 40 }, color: 'green' });
|
|
174
174
|
const user3 = await service.upsertByIndex(User4, 'childAge', { child: { name: 'bob', age: 40 }, color: 'red' });
|
|
175
175
|
|
|
176
|
-
const arr = await service.listByIndex(User4, 'childAge', { child: { name: 'bob' } })
|
|
176
|
+
const arr = await this.toArray(service.listByIndex(User4, 'childAge', { child: { name: 'bob' } }));
|
|
177
177
|
assert(arr.length === 1);
|
|
178
178
|
|
|
179
179
|
assert(user1.id === user2.id);
|
|
@@ -182,12 +182,12 @@ export abstract class ModelIndexedSuite extends BaseModelSuite<ModelIndexedSuppo
|
|
|
182
182
|
assert(user3.color === 'red');
|
|
183
183
|
|
|
184
184
|
const user4 = await service.upsertByIndex(User4, 'childAge', { child: { name: 'bob', age: 30 }, color: 'red' });
|
|
185
|
-
const arr2 = await service.listByIndex(User4, 'childAge', { child: { name: 'bob' } })
|
|
185
|
+
const arr2 = await this.toArray(service.listByIndex(User4, 'childAge', { child: { name: 'bob' } }));
|
|
186
186
|
assert(arr2.length === 2);
|
|
187
187
|
|
|
188
188
|
await service.deleteByIndex(User4, 'childAge', user1);
|
|
189
189
|
|
|
190
|
-
const arr3 = await service.listByIndex(User4, 'childAge', { child: { name: 'bob' } })
|
|
190
|
+
const arr3 = await this.toArray(service.listByIndex(User4, 'childAge', { child: { name: 'bob' } }));
|
|
191
191
|
assert(arr3.length === 1);
|
|
192
192
|
assert(arr3[0].id === user4.id);
|
|
193
193
|
}
|