@aidc-toolkit/utility 1.0.24-beta → 1.0.26-beta
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/dist/character-set.d.ts +308 -0
- package/dist/character-set.d.ts.map +1 -0
- package/dist/character-set.js +564 -0
- package/dist/character-set.js.map +1 -0
- package/dist/exclusion.d.ts +26 -0
- package/dist/exclusion.d.ts.map +1 -0
- package/dist/exclusion.js +18 -0
- package/dist/exclusion.js.map +1 -0
- package/dist/index.d.ts +26 -947
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -3504
- package/dist/index.js.map +1 -1
- package/dist/iterable-utility.d.ts +39 -0
- package/dist/iterable-utility.d.ts.map +1 -0
- package/dist/iterable-utility.js +35 -0
- package/dist/iterable-utility.js.map +1 -0
- package/dist/locale/en/locale-resources.d.ts +33 -0
- package/dist/locale/en/locale-resources.d.ts.map +1 -0
- package/dist/locale/en/locale-resources.js +32 -0
- package/dist/locale/en/locale-resources.js.map +1 -0
- package/dist/locale/fr/locale-resources.d.ts +33 -0
- package/dist/locale/fr/locale-resources.d.ts.map +1 -0
- package/dist/locale/fr/locale-resources.js +32 -0
- package/dist/locale/fr/locale-resources.js.map +1 -0
- package/dist/locale/i18n.d.ts +27 -0
- package/dist/locale/i18n.d.ts.map +1 -0
- package/dist/locale/i18n.js +34 -0
- package/dist/locale/i18n.js.map +1 -0
- package/dist/record.d.ts +44 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +58 -0
- package/dist/record.js.map +1 -0
- package/dist/reg-exp.d.ts +43 -0
- package/dist/reg-exp.d.ts.map +1 -0
- package/dist/reg-exp.js +55 -0
- package/dist/reg-exp.js.map +1 -0
- package/dist/sequence.d.ts +68 -0
- package/dist/sequence.d.ts.map +1 -0
- package/dist/sequence.js +96 -0
- package/dist/sequence.js.map +1 -0
- package/dist/string.d.ts +25 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +2 -0
- package/dist/string.js.map +1 -0
- package/dist/transformer.d.ts +347 -0
- package/dist/transformer.d.ts.map +1 -0
- package/dist/transformer.js +457 -0
- package/dist/transformer.js.map +1 -0
- package/package.json +11 -7
- package/src/character-set.ts +20 -19
- package/src/exclusion.ts +6 -1
- package/src/index.ts +9 -9
- package/src/locale/i18n.ts +3 -3
- package/src/locale/i18next.d.ts +1 -1
- package/src/record.ts +2 -2
- package/src/reg-exp.ts +7 -7
- package/src/string.ts +3 -3
- package/src/transformer.ts +19 -18
- package/test/character-set.test.ts +1 -1
- package/test/record.test.ts +4 -2
- package/test/reg-exp.test.ts +1 -1
- package/test/sequence.test.ts +1 -1
- package/test/setup.ts +1 -1
- package/test/transformer.test.ts +1 -1
- package/tsconfig-config.json +4 -0
- package/tsconfig-src.json +8 -0
- package/tsconfig-test.json +9 -0
- package/tsconfig.json +12 -1
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -3569
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -947
package/src/index.ts
CHANGED
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
export * from "./locale/i18n";
|
|
18
|
-
export * from "./sequence";
|
|
19
|
-
export * from "./iterable-utility";
|
|
20
|
-
export * from "./transformer";
|
|
21
|
-
export type * from "./string";
|
|
22
|
-
export * from "./reg-exp";
|
|
23
|
-
export * from "./record";
|
|
24
|
-
export * from "./exclusion";
|
|
25
|
-
export * from "./character-set";
|
|
17
|
+
export * from "./locale/i18n.js";
|
|
18
|
+
export * from "./sequence.js";
|
|
19
|
+
export * from "./iterable-utility.js";
|
|
20
|
+
export * from "./transformer.js";
|
|
21
|
+
export type * from "./string.js";
|
|
22
|
+
export * from "./reg-exp.js";
|
|
23
|
+
export * from "./record.js";
|
|
24
|
+
export * from "./exclusion.js";
|
|
25
|
+
export * from "./character-set.js";
|
package/src/locale/i18n.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i18nCoreInit, type I18nEnvironment } from "@aidc-toolkit/core";
|
|
2
2
|
import i18next, { type i18n, type Resource } from "i18next";
|
|
3
|
-
import enLocaleResources from "./en/locale-resources";
|
|
4
|
-
import frLocaleResources from "./fr/locale-resources";
|
|
3
|
+
import enLocaleResources from "./en/locale-resources.js";
|
|
4
|
+
import frLocaleResources from "./fr/locale-resources.js";
|
|
5
5
|
|
|
6
6
|
export const utilityNS = "aidct_utility";
|
|
7
7
|
|
|
@@ -22,7 +22,7 @@ export const utilityResources: Resource = {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
// Explicit type is necessary
|
|
25
|
+
// Explicit type is necessary because type can't be inferred without additional references.
|
|
26
26
|
export const i18nextUtility: i18n = i18next.createInstance();
|
|
27
27
|
|
|
28
28
|
/**
|
package/src/locale/i18next.d.ts
CHANGED
package/src/record.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i18nextUtility } from "./locale/i18n";
|
|
2
|
-
import type { StringValidator } from "./string";
|
|
1
|
+
import { i18nextUtility } from "./locale/i18n.js";
|
|
2
|
+
import type { StringValidator } from "./string.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Record validator. Validation is performed against a record with a string key type and throws an error if the key is
|
package/src/reg-exp.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { i18nextUtility } from "./locale/i18n";
|
|
2
|
-
import type { StringValidator } from "./string";
|
|
1
|
+
import { i18nextUtility } from "./locale/i18n.js";
|
|
2
|
+
import type { StringValidator } from "./string.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Regular expression validator. The regular expression applies to the full string only if constructed as such. For
|
|
6
|
-
* example, <code>/\d*/</code> (0 or more digits) matches every string, <code>/\d+/</code>
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* example, <code>/\d*/</code> (0 or more digits) matches every string, <code>/\d+/</code> (1
|
|
7
|
+
* or more digits) matches strings with at least one digit, <code>/^\d*$/</code> matches strings that are
|
|
8
|
+
* all digits or empty, and <code>/^\d+$/</code> matches strings that are all digits and not empty.
|
|
9
9
|
*
|
|
10
|
-
* Clients of this class are recommended to override the {@
|
|
11
|
-
* message for their use case.
|
|
10
|
+
* Clients of this class are recommended to override the {@linkcode createErrorMessage | createErrorMessage()} method
|
|
11
|
+
* to create a more suitable error message for their use case.
|
|
12
12
|
*/
|
|
13
13
|
export class RegExpValidator implements StringValidator {
|
|
14
14
|
/**
|
package/src/string.ts
CHANGED
|
@@ -8,10 +8,10 @@ export interface StringValidation {
|
|
|
8
8
|
/**
|
|
9
9
|
* String validator interface.
|
|
10
10
|
*
|
|
11
|
-
* @template
|
|
11
|
+
* @template TStringValidation
|
|
12
12
|
* String validation type.
|
|
13
13
|
*/
|
|
14
|
-
export interface StringValidator<
|
|
14
|
+
export interface StringValidator<TStringValidation extends StringValidation = StringValidation> {
|
|
15
15
|
/**
|
|
16
16
|
* Validate a string and throw an error if validation fails.
|
|
17
17
|
*
|
|
@@ -21,5 +21,5 @@ export interface StringValidator<V extends StringValidation = StringValidation>
|
|
|
21
21
|
* @param validation
|
|
22
22
|
* String validation parameters.
|
|
23
23
|
*/
|
|
24
|
-
validate: (s: string, validation?:
|
|
24
|
+
validate: (s: string, validation?: TStringValidation) => void;
|
|
25
25
|
}
|
package/src/transformer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type IndexedCallback, mapIterable } from "./iterable-utility";
|
|
2
|
-
import { i18nextUtility } from "./locale/i18n";
|
|
3
|
-
import { Sequence } from "./sequence";
|
|
1
|
+
import { type IndexedCallback, mapIterable } from "./iterable-utility.js";
|
|
2
|
+
import { i18nextUtility } from "./locale/i18n.js";
|
|
3
|
+
import { Sequence } from "./sequence.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Transformer primitive type.
|
|
@@ -43,11 +43,12 @@ export type TransformerOutput<TTransformerInput extends TransformerInput<Transfo
|
|
|
43
43
|
* into values in the same domain, typically for storage in a database where the data type and length are already fixed
|
|
44
44
|
* and exfiltration of the data can have significant repercussions.
|
|
45
45
|
*
|
|
46
|
-
* Two subclasses are supported directly by this class: {@
|
|
47
|
-
* only) and {@
|
|
48
|
-
* to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the
|
|
49
|
-
* object, an in-memory cache is available via the {@
|
|
50
|
-
* {@
|
|
46
|
+
* Two subclasses are supported directly by this class: {@linkcode IdentityTransformer} (which operates based on a
|
|
47
|
+
* domain only) and {@linkcode EncryptionTransformer} (which operates based on a domain and a tweak). If an application
|
|
48
|
+
* is expected to make repeated use of a transformer with the same domain and (optional) tweak and can't manage the
|
|
49
|
+
* transformer object, an in-memory cache is available via the {@linkcode get | get()} method. Properties in {@linkcode
|
|
50
|
+
* IdentityTransformer} and {@linkcode EncryptionTransformer} are read-only once constructed, so there is no issue with
|
|
51
|
+
* their shared use.
|
|
51
52
|
*/
|
|
52
53
|
export abstract class Transformer {
|
|
53
54
|
/**
|
|
@@ -77,10 +78,10 @@ export abstract class Transformer {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
/**
|
|
80
|
-
* Get a transformer, constructing it if necessary. The type returned is {@
|
|
81
|
-
* undefined, {@
|
|
82
|
-
* with a zero tweak operates as an {@
|
|
83
|
-
* returned if a zero tweak is explicitly specified.
|
|
81
|
+
* Get a transformer, constructing it if necessary. The type returned is {@linkcode IdentityTransformer} if tweak is
|
|
82
|
+
* undefined, {@linkcode EncryptionTransformer} if tweak is defined. Note that although an {@linkcode
|
|
83
|
+
* EncryptionTransformer} with a zero tweak operates as an {@linkcode IdentityTransformer}, {@linkcode
|
|
84
|
+
* EncryptionTransformer} is still the type returned if a zero tweak is explicitly specified.
|
|
84
85
|
*
|
|
85
86
|
* @param domain
|
|
86
87
|
* Domain.
|
|
@@ -89,7 +90,7 @@ export abstract class Transformer {
|
|
|
89
90
|
* Tweak.
|
|
90
91
|
*
|
|
91
92
|
* @returns
|
|
92
|
-
* {@
|
|
93
|
+
* {@linkcode IdentityTransformer} if tweak is undefined, {@linkcode EncryptionTransformer} if tweak is defined.
|
|
93
94
|
*/
|
|
94
95
|
static get(domain: number | bigint, tweak?: number | bigint): Transformer {
|
|
95
96
|
const domainN = BigInt(domain);
|
|
@@ -195,7 +196,7 @@ export abstract class Transformer {
|
|
|
195
196
|
* Value(s) input type.
|
|
196
197
|
*
|
|
197
198
|
* @param valueOrValues
|
|
198
|
-
* Value(s). If this is an instance of {@
|
|
199
|
+
* Value(s). If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
|
|
199
200
|
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
200
201
|
*
|
|
201
202
|
* @returns
|
|
@@ -213,7 +214,7 @@ export abstract class Transformer {
|
|
|
213
214
|
* Transformation callback output type.
|
|
214
215
|
*
|
|
215
216
|
* @param valueOrValues
|
|
216
|
-
* Value(s). If this is an instance of {@
|
|
217
|
+
* Value(s). If this is an instance of {@linkcode Sequence}, the minimum and maximum values are validated prior to
|
|
217
218
|
* transformation. Otherwise, the individual value(s) is/are validated at the time of transformation.
|
|
218
219
|
*
|
|
219
220
|
* @param transformerCallback
|
|
@@ -305,9 +306,9 @@ export class IdentityTransformer extends Transformer {
|
|
|
305
306
|
/**
|
|
306
307
|
* Encryption transformer. Values are transformed using repeated shuffle and xor operations, similar to those found in
|
|
307
308
|
* many cryptography algorithms, particularly AES. While sufficient for obfuscation of numeric sequences (e.g., serial
|
|
308
|
-
* number generation, below), if true format-preserving encryption is required, a more robust algorithm such as
|
|
309
|
-
*
|
|
310
|
-
*
|
|
309
|
+
* number generation, below), if true format-preserving encryption is required, a more robust algorithm such as {@link
|
|
310
|
+
* https://doi.org/10.6028/NIST.SP.800-38Gr1.2pd | FF1} is recommended. Furthermore, no work has been done to mitigate
|
|
311
|
+
* {@link https://timing.attacks.cr.yp.to/index.html | timing attacks} for key detection.
|
|
311
312
|
*
|
|
312
313
|
* The purpose of the encryption transformer is to generate pseudo-random values in a deterministic manner to obscure
|
|
313
314
|
* the sequence of values generated over time. A typical example is for serial number generation, where knowledge of the
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
NUMERIC_CREATOR,
|
|
14
14
|
NUMERIC_VALIDATOR,
|
|
15
15
|
Sequence
|
|
16
|
-
} from "../src";
|
|
16
|
+
} from "../src/index.js";
|
|
17
17
|
|
|
18
18
|
// Type is used to ensure that testCharacterSet() is not called with creator twice.
|
|
19
19
|
type ValidatorNotCreator<T extends CharacterSetValidator> = T extends CharacterSetCreator ? never : T;
|
package/test/record.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { RecordValidator } from "../src";
|
|
2
|
+
import { RecordValidator } from "../src/index.js";
|
|
3
3
|
|
|
4
4
|
describe("Record validator", () => {
|
|
5
5
|
const StringIndexes = {
|
|
@@ -9,7 +9,9 @@ describe("Record validator", () => {
|
|
|
9
9
|
ValueD: "D"
|
|
10
10
|
} as const;
|
|
11
11
|
|
|
12
|
-
type
|
|
12
|
+
type StringIndexKey = keyof typeof StringIndexes;
|
|
13
|
+
|
|
14
|
+
type StringIndex = typeof StringIndexes[StringIndexKey];
|
|
13
15
|
|
|
14
16
|
const stringRecord: Record<StringIndex, string> = {
|
|
15
17
|
[StringIndexes.ValueA]: "This is for Value A",
|
package/test/reg-exp.test.ts
CHANGED
package/test/sequence.test.ts
CHANGED
package/test/setup.ts
CHANGED
package/test/transformer.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
-
import { EncryptionTransformer, IdentityTransformer, Sequence, Transformer } from "../src";
|
|
2
|
+
import { EncryptionTransformer, IdentityTransformer, Sequence, Transformer } from "../src/index.js";
|
|
3
3
|
|
|
4
4
|
function testTransformer(domain: number, tweak?: number, callback?: (value: bigint, forwardValue: bigint) => void): void {
|
|
5
5
|
const transformer = Transformer.get(domain, tweak);
|
package/tsconfig.json
CHANGED
package/tsup.config.ts
CHANGED