@travetto/model 8.0.0-alpha.0 → 8.0.0-alpha.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Datastore abstraction for core operations.",
|
|
6
6
|
"keywords": [
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"directory": "module/model"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/config": "^8.0.0-alpha.
|
|
31
|
-
"@travetto/di": "^8.0.0-alpha.
|
|
32
|
-
"@travetto/registry": "^8.0.0-alpha.
|
|
33
|
-
"@travetto/schema": "^8.0.0-alpha.
|
|
30
|
+
"@travetto/config": "^8.0.0-alpha.1",
|
|
31
|
+
"@travetto/di": "^8.0.0-alpha.1",
|
|
32
|
+
"@travetto/registry": "^8.0.0-alpha.1",
|
|
33
|
+
"@travetto/schema": "^8.0.0-alpha.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
37
|
-
"@travetto/test": "^8.0.0-alpha.
|
|
36
|
+
"@travetto/cli": "^8.0.0-alpha.1",
|
|
37
|
+
"@travetto/test": "^8.0.0-alpha.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/cli": {
|
package/src/util/blob.ts
CHANGED
|
@@ -10,4 +10,9 @@ export class ModelBlobUtil {
|
|
|
10
10
|
* Type guard for determining if service supports blob operations
|
|
11
11
|
*/
|
|
12
12
|
static isSupported = hasFunction<ModelBlobSupport>('getBlob');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type guard for determining if service supports blob write urls
|
|
16
|
+
*/
|
|
17
|
+
static isWriteUrlSupported = hasFunction<ModelBlobSupport>('getBlobWriteUrl');
|
|
13
18
|
}
|
package/support/base-command.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Env } from '@travetto/runtime';
|
|
2
|
-
import { type
|
|
2
|
+
import { type CliCommandShape, cliTpl, CliModuleFlag, CliProfilesFlag } from '@travetto/cli';
|
|
3
3
|
import { Registry } from '@travetto/registry';
|
|
4
|
-
import { Schema } from '@travetto/schema';
|
|
4
|
+
import { Schema, type ValidationError } from '@travetto/schema';
|
|
5
5
|
|
|
6
6
|
import type { ModelStorageSupport } from '../src/types/storage.ts';
|
|
7
7
|
|
|
@@ -13,9 +13,26 @@ import { ModelCandidateUtil } from './bin/candidate.ts';
|
|
|
13
13
|
@Schema()
|
|
14
14
|
export abstract class BaseModelCommand implements CliCommandShape {
|
|
15
15
|
|
|
16
|
+
static async validate(operation: keyof ModelStorageSupport, provider: string, models: string[]): Promise<ValidationError | undefined> {
|
|
17
|
+
const candidates = await ModelCandidateUtil.export(operation);
|
|
18
|
+
if (provider && !candidates.providers.includes(provider)) {
|
|
19
|
+
return { message: `provider: ${provider} is not a valid provider`, source: 'arg', kind: 'invalid', path: 'provider' };
|
|
20
|
+
}
|
|
21
|
+
const badModel = models.find(model => model !== '*' && !candidates.models.includes(model));
|
|
22
|
+
if (badModel) {
|
|
23
|
+
return { message: `model: ${badModel} is not a valid model`, source: 'arg', kind: 'invalid', path: 'models' };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@CliProfilesFlag()
|
|
28
|
+
profile: string[];
|
|
29
|
+
|
|
30
|
+
@CliModuleFlag({ short: 'm' })
|
|
31
|
+
module: string;
|
|
32
|
+
|
|
16
33
|
abstract getOperation(): keyof ModelStorageSupport;
|
|
17
34
|
|
|
18
|
-
|
|
35
|
+
finalize(): void {
|
|
19
36
|
Env.DEBUG.set(false);
|
|
20
37
|
}
|
|
21
38
|
|
|
@@ -34,18 +51,5 @@ export abstract class BaseModelCommand implements CliCommandShape {
|
|
|
34
51
|
];
|
|
35
52
|
}
|
|
36
53
|
|
|
37
|
-
async validate(provider: string, models: string[]): Promise<CliValidationError | undefined> {
|
|
38
|
-
await Registry.init();
|
|
39
|
-
|
|
40
|
-
const candidates = await ModelCandidateUtil.export(this.getOperation());
|
|
41
|
-
if (provider && !candidates.providers.includes(provider)) {
|
|
42
|
-
return { message: `provider: ${provider} is not a valid provider`, source: 'arg' };
|
|
43
|
-
}
|
|
44
|
-
const badModel = models.find(model => model !== '*' && !candidates.models.includes(model));
|
|
45
|
-
if (badModel) {
|
|
46
|
-
return { message: `model: ${badModel} is not a valid model`, source: 'arg' };
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
54
|
abstract main(...args: unknown[]): ReturnType<CliCommandShape['main']>;
|
|
51
55
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliCommand } from '@travetto/cli';
|
|
2
|
+
import { MethodValidator } from '@travetto/schema';
|
|
2
3
|
|
|
3
4
|
import { BaseModelCommand } from './base-command.ts';
|
|
4
5
|
import { ModelExportUtil } from './bin/export.ts';
|
|
@@ -7,11 +8,12 @@ import { ModelCandidateUtil } from './bin/candidate.ts';
|
|
|
7
8
|
/**
|
|
8
9
|
* Exports model schemas
|
|
9
10
|
*/
|
|
10
|
-
@CliCommand(
|
|
11
|
+
@CliCommand()
|
|
11
12
|
export class ModelExportCommand extends BaseModelCommand {
|
|
12
13
|
|
|
13
14
|
getOperation(): 'exportModel' { return 'exportModel'; }
|
|
14
15
|
|
|
16
|
+
@MethodValidator(BaseModelCommand.validate.bind(null, 'exportModel'))
|
|
15
17
|
async main(provider: string, models: string[]): Promise<void> {
|
|
16
18
|
const resolved = await ModelCandidateUtil.resolve(provider, models);
|
|
17
19
|
await ModelExportUtil.run(resolved.provider, resolved.models);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliCommand, cliTpl } from '@travetto/cli';
|
|
2
|
+
import { MethodValidator } from '@travetto/schema';
|
|
2
3
|
|
|
3
4
|
import { BaseModelCommand } from './base-command.ts';
|
|
4
5
|
import { ModelInstallUtil } from './bin/install.ts';
|
|
@@ -7,11 +8,12 @@ import { ModelCandidateUtil } from './bin/candidate.ts';
|
|
|
7
8
|
/**
|
|
8
9
|
* Installing models
|
|
9
10
|
*/
|
|
10
|
-
@CliCommand(
|
|
11
|
+
@CliCommand()
|
|
11
12
|
export class ModelInstallCommand extends BaseModelCommand {
|
|
12
13
|
|
|
13
14
|
getOperation(): 'upsertModel' { return 'upsertModel'; }
|
|
14
15
|
|
|
16
|
+
@MethodValidator(BaseModelCommand.validate.bind(null, 'upsertModel'))
|
|
15
17
|
async main(provider: string, models: string[]): Promise<void> {
|
|
16
18
|
const resolved = await ModelCandidateUtil.resolve(provider, models);
|
|
17
19
|
await ModelInstallUtil.run(resolved.provider, resolved.models);
|
package/support/test/blob.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { BinaryMetadataUtil, BinaryUtil, Util } from '@travetto/runtime';
|
|
|
6
6
|
import { BaseModelSuite } from '@travetto/model/support/test/base.ts';
|
|
7
7
|
|
|
8
8
|
import type { ModelBlobSupport } from '../../src/types/blob.ts';
|
|
9
|
+
import { ModelBlobUtil } from '../../src/util/blob.ts';
|
|
9
10
|
|
|
10
11
|
@Suite()
|
|
11
12
|
export abstract class ModelBlobSuite extends BaseModelSuite<ModelBlobSupport> {
|
|
@@ -150,8 +151,7 @@ export abstract class ModelBlobSuite extends BaseModelSuite<ModelBlobSupport> {
|
|
|
150
151
|
assert(savedMeta.hash === undefined);
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
|
|
154
|
-
@Test({ skip: (x: unknown) => !(x as ModelBlobSuite).serviceClass.prototype.getBlobWriteUrl })
|
|
154
|
+
@Test({ skip: ModelBlobSuite.ifNot(ModelBlobUtil.isWriteUrlSupported) })
|
|
155
155
|
async signedUrl() {
|
|
156
156
|
const service = await this.service;
|
|
157
157
|
|
package/support/test/suite.ts
CHANGED
|
@@ -45,16 +45,17 @@ class ModelSuiteHandler<T extends { configClass: Class<ConfigType>, serviceClass
|
|
|
45
45
|
async afterEach(instance: T) {
|
|
46
46
|
const service = await DependencyRegistryIndex.getInstance<T>(instance.serviceClass, this.qualifier);
|
|
47
47
|
if (ModelStorageUtil.isSupported(service)) {
|
|
48
|
-
const models = ModelRegistryIndex.getClasses()
|
|
48
|
+
const models = ModelRegistryIndex.getClasses()
|
|
49
|
+
.filter(model => model === SchemaRegistryIndex.getBaseClass(model));
|
|
49
50
|
|
|
50
51
|
if (ModelBlobUtil.isSupported(service) && service.truncateBlob) {
|
|
51
52
|
await service.truncateBlob();
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
if (service.truncateModel) {
|
|
55
|
-
await Promise.all(models.map(
|
|
56
|
+
await Promise.all(models.map(model => service.truncateModel!(model)));
|
|
56
57
|
} else if (service.deleteModel) {
|
|
57
|
-
await Promise.all(models.map(
|
|
58
|
+
await Promise.all(models.map(model => service.deleteModel!(model)));
|
|
58
59
|
} else {
|
|
59
60
|
await service.deleteStorage(); // Purge it all
|
|
60
61
|
}
|