@fgv/ts-utils 5.0.0-12 → 5.0.0-14
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/.vscode/launch.json +16 -0
- package/.vscode/settings.json +36 -0
- package/config/api-extractor.json +343 -0
- package/config/rig.json +16 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/test/helpers/jest/helpers/fsHelpers.d.ts +52 -0
- package/lib/test/helpers/jest/helpers/fsHelpers.js +180 -0
- package/lib/test/helpers/jest/helpers/index.d.ts +2 -0
- package/lib/test/helpers/jest/helpers/index.js +18 -0
- package/lib/test/helpers/jest/index.d.ts +3 -0
- package/lib/test/helpers/jest/index.js +27 -0
- package/lib/test/helpers/jest/matchers/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/index.js +19 -0
- package/lib/test/helpers/jest/matchers/toFail/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/toFail/index.js +25 -0
- package/lib/test/helpers/jest/matchers/toFail/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFail/predicate.js +9 -0
- package/lib/test/helpers/jest/matchers/toFailTest/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/toFailTest/index.js +30 -0
- package/lib/test/helpers/jest/matchers/toFailTest/predicate.d.ts +3 -0
- package/lib/test/helpers/jest/matchers/toFailTest/predicate.js +12 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.d.ts +17 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +26 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +15 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/index.js +31 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/predicate.js +30 -0
- package/lib/test/helpers/jest/matchers/toFailWith/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toFailWith/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toFailWith/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailWith/predicate.js +20 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/index.d.ts +19 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/predicate.js +26 -0
- package/lib/test/helpers/jest/matchers/toSucceed/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/toSucceed/index.js +25 -0
- package/lib/test/helpers/jest/matchers/toSucceed/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceed/predicate.js +9 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.d.ts +17 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +26 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.d.ts +17 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +26 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/index.d.ts +19 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +55 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +21 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/predicate.js +16 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +21 -0
- package/lib/test/helpers/jest/resolvers/cli.d.ts +5 -0
- package/lib/test/helpers/jest/resolvers/cli.js +48 -0
- package/lib/test/helpers/jest/resolvers/ide.d.ts +5 -0
- package/lib/test/helpers/jest/resolvers/ide.js +48 -0
- package/lib/test/helpers/jest/ts-utils.d.ts +2 -0
- package/lib/test/helpers/jest/ts-utils.js +18 -0
- package/lib/test/helpers/jest/types/index.d.ts +79 -0
- package/lib/test/helpers/jest/types/index.js +4 -0
- package/lib/test/helpers/jest/utils/matcherHelpers.d.ts +6 -0
- package/lib/test/helpers/jest/utils/matcherHelpers.js +53 -0
- package/lib/test/helpers/jest/utils/snapshotResolver.d.ts +4 -0
- package/lib/test/helpers/jest/utils/snapshotResolver.js +19 -0
- package/lib/test/unit/collections/collectible.test.d.ts +2 -0
- package/lib/test/unit/collections/collector.test.d.ts +2 -0
- package/lib/test/unit/collections/collectors.test.d.ts +2 -0
- package/lib/test/unit/collections/convertingCollector.test.d.ts +2 -0
- package/lib/test/unit/collections/helpers.d.ts +44 -0
- package/lib/test/unit/collections/helpers.js +115 -0
- package/lib/test/unit/collections/resultMap.test.d.ts +2 -0
- package/lib/test/unit/collections/validatingCollector.test.d.ts +2 -0
- package/lib/test/unit/collections/validatingConvertingCollector.test.d.ts +2 -0
- package/lib/test/unit/collections/validatingResultMap.test.d.ts +2 -0
- package/lib/test/unit/converter.test.d.ts +2 -0
- package/lib/test/unit/converters.test.d.ts +2 -0
- package/lib/test/unit/defaultingConverter.test.d.ts +2 -0
- package/lib/test/unit/file-tree/fileItem.test.d.ts +2 -0
- package/lib/test/unit/file-tree/fileTree.test.d.ts +2 -0
- package/lib/test/unit/file-tree/fsTree.test.d.ts +2 -0
- package/lib/test/unit/file-tree/inMemoryTree.test.d.ts +2 -0
- package/lib/test/unit/file-tree/sample/rootFile.json +1 -0
- package/lib/test/unit/file-tree/sample/some/other/path/file2.json +1 -0
- package/lib/test/unit/file-tree/sample/some/path/below/file4.json +1 -0
- package/lib/test/unit/file-tree/sample/some/path/file1.json +1 -0
- package/lib/test/unit/file-tree/sample/some/path/file3.json +1 -0
- package/lib/test/unit/hash.test.d.ts +2 -0
- package/lib/test/unit/logger.test.d.ts +2 -0
- package/lib/test/unit/mapResults.test.d.ts +3 -0
- package/lib/test/unit/messageAggregator.test.d.ts +3 -0
- package/lib/test/unit/normalize.test.d.ts +2 -0
- package/lib/test/unit/result.test.d.ts +3 -0
- package/lib/test/unit/utils.test.d.ts +3 -0
- package/lib/test/unit/validation/array.test.d.ts +2 -0
- package/lib/test/unit/validation/boolean.test.d.ts +2 -0
- package/lib/test/unit/validation/genericValidator.test.d.ts +2 -0
- package/lib/test/unit/validation/number.test.d.ts +2 -0
- package/lib/test/unit/validation/object.test.d.ts +2 -0
- package/lib/test/unit/validation/oneOf.test.d.ts +2 -0
- package/lib/test/unit/validation/recordOf.test.d.ts +2 -0
- package/lib/test/unit/validation/string.test.d.ts +2 -0
- package/lib/test/unit/validation/traits.test.d.ts +2 -0
- package/lib/test/unit/validation/typeGuard.test.d.ts +2 -0
- package/lib/test/unit/validation/validators.test.d.ts +2 -0
- package/package.json +9 -9
- package/src/index.ts +63 -0
- package/src/packlets/base/brand.ts +28 -0
- package/src/packlets/base/index.ts +31 -0
- package/src/packlets/base/logger.ts +156 -0
- package/src/packlets/base/mapResults.ts +302 -0
- package/src/packlets/base/messageAggregator.ts +120 -0
- package/src/packlets/base/normalize.ts +144 -0
- package/src/packlets/base/result.ts +961 -0
- package/src/packlets/base/utils.ts +236 -0
- package/src/packlets/collections/collectible.ts +238 -0
- package/src/packlets/collections/collector.ts +273 -0
- package/src/packlets/collections/collectorValidator.ts +178 -0
- package/src/packlets/collections/common.ts +27 -0
- package/src/packlets/collections/convertingCollector.ts +223 -0
- package/src/packlets/collections/convertingCollectorValidator.ts +164 -0
- package/src/packlets/collections/index.ts +39 -0
- package/src/packlets/collections/keyValueConverters.ts +142 -0
- package/src/packlets/collections/readonlyResultMap.ts +99 -0
- package/src/packlets/collections/resultMap.ts +322 -0
- package/src/packlets/collections/resultMapValidator.ts +188 -0
- package/src/packlets/collections/utils.ts +33 -0
- package/src/packlets/collections/validatingCollector.ts +123 -0
- package/src/packlets/collections/validatingConvertingCollector.ts +113 -0
- package/src/packlets/collections/validatingResultMap.ts +94 -0
- package/src/packlets/conversion/baseConverter.ts +330 -0
- package/src/packlets/conversion/converter.ts +260 -0
- package/src/packlets/conversion/converters.ts +1039 -0
- package/src/packlets/conversion/defaultingConverter.ts +188 -0
- package/src/packlets/conversion/index.ts +30 -0
- package/src/packlets/conversion/objectConverter.ts +259 -0
- package/src/packlets/conversion/stringConverter.ts +165 -0
- package/src/packlets/file-tree/directoryItem.ts +84 -0
- package/src/packlets/file-tree/fileItem.ts +119 -0
- package/src/packlets/file-tree/fileTree.ts +152 -0
- package/src/packlets/file-tree/fileTreeAccessors.ts +176 -0
- package/src/packlets/file-tree/fsTree.ts +118 -0
- package/src/packlets/file-tree/in-memory/inMemoryTree.ts +171 -0
- package/src/packlets/file-tree/in-memory/index.ts +23 -0
- package/src/packlets/file-tree/in-memory/treeBuilder.ts +203 -0
- package/src/packlets/file-tree/index.ts +31 -0
- package/src/packlets/hash/crcNormalizer.ts +81 -0
- package/src/packlets/hash/hashingNormalizer.ts +102 -0
- package/src/packlets/hash/index.ts +24 -0
- package/src/packlets/validation/array.ts +83 -0
- package/src/packlets/validation/boolean.ts +63 -0
- package/src/packlets/validation/classes.ts +38 -0
- package/src/packlets/validation/common.ts +38 -0
- package/src/packlets/validation/field.ts +99 -0
- package/src/packlets/validation/genericValidator.ts +205 -0
- package/src/packlets/validation/index.ts +31 -0
- package/src/packlets/validation/number.ts +66 -0
- package/src/packlets/validation/object.ts +208 -0
- package/src/packlets/validation/oneOf.ts +77 -0
- package/src/packlets/validation/string.ts +66 -0
- package/src/packlets/validation/traits.ts +113 -0
- package/src/packlets/validation/typeGuard.ts +82 -0
- package/src/packlets/validation/validator.ts +145 -0
- package/src/packlets/validation/validatorBase.ts +61 -0
- package/src/packlets/validation/validators.ts +246 -0
- package/CHANGELOG.md +0 -135
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/packlets/base/brand.d.ts.map +0 -1
- package/lib/packlets/base/brand.js.map +0 -1
- package/lib/packlets/base/index.d.ts.map +0 -1
- package/lib/packlets/base/index.js.map +0 -1
- package/lib/packlets/base/logger.d.ts.map +0 -1
- package/lib/packlets/base/logger.js.map +0 -1
- package/lib/packlets/base/mapResults.d.ts.map +0 -1
- package/lib/packlets/base/mapResults.js.map +0 -1
- package/lib/packlets/base/messageAggregator.d.ts.map +0 -1
- package/lib/packlets/base/messageAggregator.js.map +0 -1
- package/lib/packlets/base/normalize.d.ts.map +0 -1
- package/lib/packlets/base/normalize.js.map +0 -1
- package/lib/packlets/base/result.d.ts.map +0 -1
- package/lib/packlets/base/result.js.map +0 -1
- package/lib/packlets/base/utils.d.ts.map +0 -1
- package/lib/packlets/base/utils.js.map +0 -1
- package/lib/packlets/collections/collectible.d.ts.map +0 -1
- package/lib/packlets/collections/collectible.js.map +0 -1
- package/lib/packlets/collections/collector.d.ts.map +0 -1
- package/lib/packlets/collections/collector.js.map +0 -1
- package/lib/packlets/collections/collectorValidator.d.ts.map +0 -1
- package/lib/packlets/collections/collectorValidator.js.map +0 -1
- package/lib/packlets/collections/common.d.ts.map +0 -1
- package/lib/packlets/collections/common.js.map +0 -1
- package/lib/packlets/collections/convertingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/convertingCollector.js.map +0 -1
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +0 -1
- package/lib/packlets/collections/convertingCollectorValidator.js.map +0 -1
- package/lib/packlets/collections/index.d.ts.map +0 -1
- package/lib/packlets/collections/index.js.map +0 -1
- package/lib/packlets/collections/keyValueConverters.d.ts.map +0 -1
- package/lib/packlets/collections/keyValueConverters.js.map +0 -1
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/readonlyResultMap.js.map +0 -1
- package/lib/packlets/collections/resultMap.d.ts.map +0 -1
- package/lib/packlets/collections/resultMap.js.map +0 -1
- package/lib/packlets/collections/resultMapValidator.d.ts.map +0 -1
- package/lib/packlets/collections/resultMapValidator.js.map +0 -1
- package/lib/packlets/collections/utils.d.ts.map +0 -1
- package/lib/packlets/collections/utils.js.map +0 -1
- package/lib/packlets/collections/validatingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/validatingCollector.js.map +0 -1
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/validatingConvertingCollector.js.map +0 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/validatingResultMap.js.map +0 -1
- package/lib/packlets/conversion/baseConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/baseConverter.js.map +0 -1
- package/lib/packlets/conversion/converter.d.ts.map +0 -1
- package/lib/packlets/conversion/converter.js.map +0 -1
- package/lib/packlets/conversion/converters.d.ts.map +0 -1
- package/lib/packlets/conversion/converters.js.map +0 -1
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/defaultingConverter.js.map +0 -1
- package/lib/packlets/conversion/index.d.ts.map +0 -1
- package/lib/packlets/conversion/index.js.map +0 -1
- package/lib/packlets/conversion/objectConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/objectConverter.js.map +0 -1
- package/lib/packlets/conversion/stringConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/stringConverter.js.map +0 -1
- package/lib/packlets/file-tree/directoryItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/directoryItem.js.map +0 -1
- package/lib/packlets/file-tree/fileItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileItem.js.map +0 -1
- package/lib/packlets/file-tree/fileTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTree.js.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +0 -1
- package/lib/packlets/file-tree/fsTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fsTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/index.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/index.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +0 -1
- package/lib/packlets/file-tree/index.d.ts.map +0 -1
- package/lib/packlets/file-tree/index.js.map +0 -1
- package/lib/packlets/hash/crcNormalizer.d.ts.map +0 -1
- package/lib/packlets/hash/crcNormalizer.js.map +0 -1
- package/lib/packlets/hash/hashingNormalizer.d.ts.map +0 -1
- package/lib/packlets/hash/hashingNormalizer.js.map +0 -1
- package/lib/packlets/hash/index.d.ts.map +0 -1
- package/lib/packlets/hash/index.js.map +0 -1
- package/lib/packlets/validation/array.d.ts.map +0 -1
- package/lib/packlets/validation/array.js.map +0 -1
- package/lib/packlets/validation/boolean.d.ts.map +0 -1
- package/lib/packlets/validation/boolean.js.map +0 -1
- package/lib/packlets/validation/classes.d.ts.map +0 -1
- package/lib/packlets/validation/classes.js.map +0 -1
- package/lib/packlets/validation/common.d.ts.map +0 -1
- package/lib/packlets/validation/common.js.map +0 -1
- package/lib/packlets/validation/field.d.ts.map +0 -1
- package/lib/packlets/validation/field.js.map +0 -1
- package/lib/packlets/validation/genericValidator.d.ts.map +0 -1
- package/lib/packlets/validation/genericValidator.js.map +0 -1
- package/lib/packlets/validation/index.d.ts.map +0 -1
- package/lib/packlets/validation/index.js.map +0 -1
- package/lib/packlets/validation/number.d.ts.map +0 -1
- package/lib/packlets/validation/number.js.map +0 -1
- package/lib/packlets/validation/object.d.ts.map +0 -1
- package/lib/packlets/validation/object.js.map +0 -1
- package/lib/packlets/validation/oneOf.d.ts.map +0 -1
- package/lib/packlets/validation/oneOf.js.map +0 -1
- package/lib/packlets/validation/string.d.ts.map +0 -1
- package/lib/packlets/validation/string.js.map +0 -1
- package/lib/packlets/validation/traits.d.ts.map +0 -1
- package/lib/packlets/validation/traits.js.map +0 -1
- package/lib/packlets/validation/typeGuard.d.ts.map +0 -1
- package/lib/packlets/validation/typeGuard.js.map +0 -1
- package/lib/packlets/validation/validator.d.ts.map +0 -1
- package/lib/packlets/validation/validator.js.map +0 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +0 -1
- package/lib/packlets/validation/validatorBase.js.map +0 -1
- package/lib/packlets/validation/validators.d.ts.map +0 -1
- package/lib/packlets/validation/validators.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Brand, Result } from '../../../packlets/base';
|
|
2
|
+
import { Collectible, ConvertingCollector } from '../../../packlets/collections';
|
|
3
|
+
import { Converter } from '../../../packlets/conversion';
|
|
4
|
+
export type TestThingKey = Brand<string, 'TestThingKey'>;
|
|
5
|
+
export type TestThingIndex = Brand<number, 'TestThingIndex'>;
|
|
6
|
+
export declare const testThingKey: Converter<TestThingKey, unknown>;
|
|
7
|
+
export declare const testThingIndex: Converter<TestThingIndex, unknown>;
|
|
8
|
+
export interface ITestThing {
|
|
9
|
+
str?: string;
|
|
10
|
+
num?: number;
|
|
11
|
+
bool?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const testThing: Converter<ITestThing, unknown>;
|
|
14
|
+
export declare class BrandedCollectibleTestThing extends Collectible<TestThingKey, TestThingIndex> implements ITestThing {
|
|
15
|
+
str?: string;
|
|
16
|
+
num?: number;
|
|
17
|
+
bool?: boolean;
|
|
18
|
+
constructor(thing: ITestThing, key: TestThingKey, index?: TestThingIndex);
|
|
19
|
+
static create(thing: ITestThing, key: string, index?: number): Result<BrandedCollectibleTestThing>;
|
|
20
|
+
}
|
|
21
|
+
export declare class CollectibleTestThing extends Collectible<string, number> implements ITestThing {
|
|
22
|
+
str?: string;
|
|
23
|
+
num?: number;
|
|
24
|
+
bool?: boolean;
|
|
25
|
+
constructor(thing: ITestThing, key: string, index?: number);
|
|
26
|
+
static create(thing: ITestThing, key: string, index?: number): Result<CollectibleTestThing>;
|
|
27
|
+
}
|
|
28
|
+
export declare class BrokenCollectibleTestThing extends CollectibleTestThing {
|
|
29
|
+
constructor(thing: ITestThing, key: string, index?: number);
|
|
30
|
+
setIndex(index: number): Result<number>;
|
|
31
|
+
}
|
|
32
|
+
export declare class TestCollector extends ConvertingCollector<CollectibleTestThing, ITestThing> {
|
|
33
|
+
constructor(things?: ITestThing[]);
|
|
34
|
+
protected static _factory(key: string, index: number, item: ITestThing): Result<CollectibleTestThing>;
|
|
35
|
+
}
|
|
36
|
+
export declare function getTestThings(): {
|
|
37
|
+
things: ITestThing[];
|
|
38
|
+
collectibles: CollectibleTestThing[];
|
|
39
|
+
};
|
|
40
|
+
export declare function getBrandedTestThings(): {
|
|
41
|
+
things: ITestThing[];
|
|
42
|
+
collectibles: BrandedCollectibleTestThing[];
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TestCollector = exports.BrokenCollectibleTestThing = exports.CollectibleTestThing = exports.BrandedCollectibleTestThing = exports.testThing = exports.testThingIndex = exports.testThingKey = void 0;
|
|
25
|
+
exports.getTestThings = getTestThings;
|
|
26
|
+
exports.getBrandedTestThings = getBrandedTestThings;
|
|
27
|
+
const base_1 = require("../../../packlets/base");
|
|
28
|
+
const collections_1 = require("../../../packlets/collections");
|
|
29
|
+
const conversion_1 = require("../../../packlets/conversion");
|
|
30
|
+
exports.testThingKey = conversion_1.Converters.string
|
|
31
|
+
.withConstraint((s) => /^thing\d{1,4}$/.test(s))
|
|
32
|
+
.withFormattedError((val) => `${val} is not a valid TestThingKey`)
|
|
33
|
+
.withBrand('TestThingKey');
|
|
34
|
+
exports.testThingIndex = conversion_1.Converters.number
|
|
35
|
+
.withConstraint((n) => n >= 0)
|
|
36
|
+
.withBrand('TestThingIndex');
|
|
37
|
+
exports.testThing = conversion_1.Converters.strictObject({
|
|
38
|
+
str: conversion_1.Converters.string.optional(),
|
|
39
|
+
num: conversion_1.Converters.number.optional(),
|
|
40
|
+
bool: conversion_1.Converters.boolean.optional()
|
|
41
|
+
});
|
|
42
|
+
class BrandedCollectibleTestThing extends collections_1.Collectible {
|
|
43
|
+
constructor(thing, key, index) {
|
|
44
|
+
super({ key, index, indexConverter: exports.testThingIndex });
|
|
45
|
+
this.str = thing.str;
|
|
46
|
+
this.num = thing.num;
|
|
47
|
+
this.bool = thing.bool;
|
|
48
|
+
}
|
|
49
|
+
static create(thing, key, index) {
|
|
50
|
+
return exports.testThingKey.convert(key).onSuccess((convertedKey) => {
|
|
51
|
+
return exports.testThingIndex.convert(index).onSuccess((convertedIndex) => {
|
|
52
|
+
return (0, base_1.captureResult)(() => new BrandedCollectibleTestThing(thing, convertedKey, convertedIndex));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.BrandedCollectibleTestThing = BrandedCollectibleTestThing;
|
|
58
|
+
class CollectibleTestThing extends collections_1.Collectible {
|
|
59
|
+
constructor(thing, key, index) {
|
|
60
|
+
super({ key, index, indexConverter: conversion_1.Converters.number });
|
|
61
|
+
this.str = thing.str;
|
|
62
|
+
this.num = thing.num;
|
|
63
|
+
this.bool = thing.bool;
|
|
64
|
+
}
|
|
65
|
+
static create(thing, key, index) {
|
|
66
|
+
return (0, base_1.captureResult)(() => new CollectibleTestThing(thing, key, index));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.CollectibleTestThing = CollectibleTestThing;
|
|
70
|
+
class BrokenCollectibleTestThing extends CollectibleTestThing {
|
|
71
|
+
constructor(thing, key, index) {
|
|
72
|
+
super(thing, key, index ? (index + 1) : undefined);
|
|
73
|
+
}
|
|
74
|
+
setIndex(index) {
|
|
75
|
+
this._index = index + 1;
|
|
76
|
+
return (0, base_1.succeed)(this.index);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.BrokenCollectibleTestThing = BrokenCollectibleTestThing;
|
|
80
|
+
class TestCollector extends collections_1.ConvertingCollector {
|
|
81
|
+
constructor(things) {
|
|
82
|
+
const entries = things
|
|
83
|
+
? { entries: things.map((thing, index) => [`thing${index}`, thing]) }
|
|
84
|
+
: {};
|
|
85
|
+
const params = Object.assign({ factory: TestCollector._factory }, entries);
|
|
86
|
+
super(params);
|
|
87
|
+
}
|
|
88
|
+
static _factory(key, index, item) {
|
|
89
|
+
return (0, base_1.succeed)(new CollectibleTestThing(item, key, index));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.TestCollector = TestCollector;
|
|
93
|
+
function getTestThings() {
|
|
94
|
+
const things = [
|
|
95
|
+
{ str: 'thing0', num: 0, bool: false },
|
|
96
|
+
{ str: 'thing1', num: 1, bool: true },
|
|
97
|
+
{ str: 'thing2', num: 2, bool: false },
|
|
98
|
+
{ str: 'thing3', num: 3, bool: true },
|
|
99
|
+
{ str: 'thing4', num: 4, bool: false }
|
|
100
|
+
];
|
|
101
|
+
const collectibles = things.map((thing, index) => new CollectibleTestThing(thing, `thing${index}`, index));
|
|
102
|
+
return { things, collectibles };
|
|
103
|
+
}
|
|
104
|
+
function getBrandedTestThings() {
|
|
105
|
+
const things = [
|
|
106
|
+
{ str: 'thing0', num: 0, bool: false },
|
|
107
|
+
{ str: 'thing1', num: 1, bool: true },
|
|
108
|
+
{ str: 'thing2', num: 2, bool: false },
|
|
109
|
+
{ str: 'thing3', num: 3, bool: true },
|
|
110
|
+
{ str: 'thing4', num: 4, bool: false }
|
|
111
|
+
];
|
|
112
|
+
const collectibles = things.map((thing, index) => BrandedCollectibleTestThing.create(thing, `thing${index}`, index).orThrow());
|
|
113
|
+
return { things, collectibles };
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "myNameIs": "root" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "helloMyNameIs": "file2" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "helloMyNameIs": "file4" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "helloMyNameIs": "file1" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "helloMyNameIs": "file3" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-14",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-utils.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#readme",
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@jest/expect-utils": "^29.7.0",
|
|
20
|
-
"@microsoft/api-documenter": "^7.26.
|
|
21
|
-
"@microsoft/api-extractor": "^7.
|
|
20
|
+
"@microsoft/api-documenter": "^7.26.31",
|
|
21
|
+
"@microsoft/api-extractor": "^7.52.10",
|
|
22
22
|
"@types/jest": "^29.5.14",
|
|
23
|
-
"@types/luxon": "^3.
|
|
23
|
+
"@types/luxon": "^3.7.1",
|
|
24
24
|
"@types/mustache": "^4.2.5",
|
|
25
25
|
"@types/node": "^20.14.9",
|
|
26
26
|
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
"jest-extended": "^4.0.2",
|
|
34
34
|
"jest-matcher-utils": "^29.7.0",
|
|
35
35
|
"rimraf": "^5.0.7",
|
|
36
|
-
"ts-jest": "^29.4.
|
|
36
|
+
"ts-jest": "^29.4.1",
|
|
37
37
|
"ts-node": "^10.9.2",
|
|
38
|
-
"typescript": "^5.
|
|
38
|
+
"typescript": "^5.8.3",
|
|
39
39
|
"eslint-plugin-n": "^16.6.2",
|
|
40
40
|
"jest-snapshot": "~29.7.0",
|
|
41
|
-
"@rushstack/heft": "~0.74.
|
|
42
|
-
"@rushstack/heft-node-rig": "~2.9.
|
|
41
|
+
"@rushstack/heft": "~0.74.2",
|
|
42
|
+
"@rushstack/heft-node-rig": "~2.9.3",
|
|
43
43
|
"@rushstack/eslint-config": "~4.4.0",
|
|
44
44
|
"@types/heft-jest": "1.0.6",
|
|
45
|
-
"@rushstack/heft-jest-plugin": "~0.16.
|
|
45
|
+
"@rushstack/heft-jest-plugin": "~0.16.11",
|
|
46
46
|
"eslint-plugin-tsdoc": "~0.4.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import * as Collections from './packlets/collections';
|
|
24
|
+
import * as Conversion from './packlets/conversion';
|
|
25
|
+
import * as Hash from './packlets/hash';
|
|
26
|
+
import * as FileTree from './packlets/file-tree';
|
|
27
|
+
import * as Validation from './packlets/validation';
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
Collector,
|
|
31
|
+
ICollectible,
|
|
32
|
+
ConvertingCollector,
|
|
33
|
+
IReadOnlyResultMap,
|
|
34
|
+
ResultMap,
|
|
35
|
+
ValidatingCollector,
|
|
36
|
+
ValidatingConvertingCollector,
|
|
37
|
+
ValidatingResultMap
|
|
38
|
+
} from './packlets/collections';
|
|
39
|
+
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
40
|
+
import { Validator, Validators } from './packlets/validation';
|
|
41
|
+
|
|
42
|
+
export * from './packlets/base';
|
|
43
|
+
export {
|
|
44
|
+
Collections,
|
|
45
|
+
Collector,
|
|
46
|
+
ConvertingCollector,
|
|
47
|
+
Conversion,
|
|
48
|
+
Converter,
|
|
49
|
+
Converters,
|
|
50
|
+
FileTree,
|
|
51
|
+
Hash,
|
|
52
|
+
ICollectible,
|
|
53
|
+
IReadOnlyResultMap,
|
|
54
|
+
ObjectConverter,
|
|
55
|
+
ResultMap,
|
|
56
|
+
StringConverter,
|
|
57
|
+
ValidatingCollector,
|
|
58
|
+
ValidatingConvertingCollector,
|
|
59
|
+
ValidatingResultMap,
|
|
60
|
+
Validation,
|
|
61
|
+
Validator,
|
|
62
|
+
Validators
|
|
63
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Helper type to brand a simple type to prevent inappropriate use
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
+
export type Brand<T, B> = T & { __brand: B };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import * as Logging from './logger';
|
|
24
|
+
|
|
25
|
+
export * from './brand';
|
|
26
|
+
export * from './mapResults';
|
|
27
|
+
export * from './messageAggregator';
|
|
28
|
+
export { Normalizer } from './normalize';
|
|
29
|
+
export * from './result';
|
|
30
|
+
export * from './utils';
|
|
31
|
+
export { Logging };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { Failure, Success, fail, succeed } from './result';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
33
|
+
export interface Logger {
|
|
34
|
+
log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
35
|
+
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
36
|
+
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
37
|
+
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
38
|
+
warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
39
|
+
error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export abstract class LoggerBase {
|
|
46
|
+
public logLevel: LogLevel = 'info';
|
|
47
|
+
|
|
48
|
+
public constructor(logLevel?: LogLevel) {
|
|
49
|
+
this.logLevel = logLevel ?? 'info';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {
|
|
53
|
+
if (this.logLevel === 'detail') {
|
|
54
|
+
return this.log(message, parameters);
|
|
55
|
+
}
|
|
56
|
+
return succeed(undefined);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public info(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {
|
|
60
|
+
if (this.logLevel === 'detail' || this.logLevel === 'info') {
|
|
61
|
+
return this.log(message, parameters);
|
|
62
|
+
}
|
|
63
|
+
return succeed(undefined);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {
|
|
67
|
+
if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
|
|
68
|
+
return this.log(message, parameters);
|
|
69
|
+
}
|
|
70
|
+
return succeed(undefined);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T> {
|
|
74
|
+
const formatted = this._format(message, ...parameters);
|
|
75
|
+
if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
|
|
76
|
+
const result = this.log(formatted);
|
|
77
|
+
return fail(result.value ?? formatted);
|
|
78
|
+
}
|
|
79
|
+
return fail(formatted);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public error<T>(message?: unknown, ...parameters: unknown[]): Failure<T> {
|
|
83
|
+
const formatted = this._format(message, ...parameters);
|
|
84
|
+
if (this.logLevel !== 'silent') {
|
|
85
|
+
const result = this.log(formatted);
|
|
86
|
+
return fail(result.value ?? formatted);
|
|
87
|
+
}
|
|
88
|
+
return fail(formatted);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public log(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {
|
|
92
|
+
const messageString = this._format(message, ...parameters);
|
|
93
|
+
if (this.logLevel === 'silent') {
|
|
94
|
+
return this._innerSilent(messageString);
|
|
95
|
+
}
|
|
96
|
+
return this._innerLog(messageString);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected _format(message?: unknown, ...parameters: unknown[]): string {
|
|
100
|
+
const raw = [message, ...parameters];
|
|
101
|
+
const filtered = raw.filter((m): m is string => m !== undefined);
|
|
102
|
+
const strings = filtered.map((m) => m.toString());
|
|
103
|
+
const joined = strings.join('');
|
|
104
|
+
return joined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
protected _innerSilent(__message: string): Success<string | undefined> {
|
|
108
|
+
return succeed(undefined);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected abstract _innerLog(message: string): Success<string | undefined>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export class InMemoryLogger extends LoggerBase {
|
|
118
|
+
protected _messages: string[] = [];
|
|
119
|
+
protected _silent: string[] = [];
|
|
120
|
+
|
|
121
|
+
public constructor(logLevel?: LogLevel) {
|
|
122
|
+
super(logLevel);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public get messages(): string[] {
|
|
126
|
+
return this._messages;
|
|
127
|
+
}
|
|
128
|
+
public get silent(): string[] {
|
|
129
|
+
return this._silent;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public clear(): void {
|
|
133
|
+
this._messages = [];
|
|
134
|
+
this._silent = [];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
protected _innerLog(message: string): Success<string | undefined> {
|
|
138
|
+
this._messages.push(message);
|
|
139
|
+
return succeed(message);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
protected _innerSilent(message: string): Success<string | undefined> {
|
|
143
|
+
this._silent.push(message);
|
|
144
|
+
return succeed(undefined);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
export class NoOpLogger extends LoggerBase {
|
|
152
|
+
protected _innerLog(message: string): Success<string | undefined> {
|
|
153
|
+
// no-op
|
|
154
|
+
return succeed(message);
|
|
155
|
+
}
|
|
156
|
+
}
|