@dolittle/sdk.artifacts
Version:
Dolittle is a decentralized, distributed, event-driven microservice platform built to harness the power of events.
48 lines (40 loc) • 1.74 kB
text/typescript
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
import { ConceptAs, createIsConceptAsNumber } from '@dolittle/concepts';
import { GenerationMustBePositiveInteger } from './GenerationMustBePositiveInteger';
/**
* Defines the types that can be converted into a {@link Generation}.
*/
export type GenerationLike = Generation | number;
/**
* Represents the generation of an Artifact.
*/
export class Generation extends ConceptAs<number, '@dolittle/sdk.artifacts.Generation'>{
/**
* Initialises a new instance of the {@link Generation} class.
* @param {number} generation - The generation.
*/
constructor(generation: number) {
if (!Number.isSafeInteger(generation) || generation < 0) throw new GenerationMustBePositiveInteger();
super(generation, '@dolittle/sdk.artifacts.Generation');
}
/**.
* Represents the first {@link Generation}
*/
static first: Generation = Generation.from(1);
/**
* Creates a {@link Generation} from a {@link GenerationLike}.
* @param {GenerationLike} generation - The generation.
* @returns {Generation} The created generation concept.
*/
static from(generation: GenerationLike): Generation {
if (generation instanceof Generation) return generation;
return new Generation(generation);
}
}
/**
* Checks whether or not an object is an instance of {@link Generation}.
* @param {any} object - The object to check.
* @returns {boolean} True if the object is an {@link Generation}, false if not.
*/
export const isGeneration = createIsConceptAsNumber(Generation, '@dolittle/sdk.artifacts.Generation');