This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usecase.ts
60 lines (54 loc) · 1.66 KB
/
usecase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (c) TIKI Inc.
* MIT license. See LICENSE file in root directory.
*/
import { CommonUsecases } from './common-usecases';
/**
* Describes how and optionally where a data asset may be used.
*/
export class Usecase {
/**
* The raw value of the use case.
*/
readonly value: string;
/**
* Constructs a new Usecase with the provided value. This constructor is
* private. To create a Usecase instance, use the static factory methods.
*
* @private
* @param {string} usecase - The use case value.
*/
private constructor(usecase: string) {
this.value = usecase;
}
/**
* Creates a Usecase from a provided use case value. If the use case value
* matches a common use case, a pre-defined Usecase is returned. Otherwise,
* a custom Usecase is created.
*
* @static
* @param {string} usecase - The use case value.
* @returns {Usecase} A Usecase instance.
*/
static from(usecase: string): Usecase {
if ((Object as any).values(CommonUsecases).includes(usecase)) {
return new Usecase(usecase);
} else return new Usecase(`custom:${usecase}`);
}
/**
* Creates a custom Usecase with the provided use case value.
*
* @static
* @param {string} usecase - The custom use case value.
* @returns {Usecase} A Usecase instance.
*/
static custom = (usecase: string): Usecase => new Usecase(`custom:${usecase}`);
/**
* Creates a Usecase from one of the {@link CommonUsecases}
*
* @static
* @param {CommonUsecases} usecase - The common use case to use.
* @returns {Usecase} A Usecase instance.
*/
static common = (usecase: CommonUsecases): Usecase => new Usecase(usecase.valueOf());
}