@breadstone-infrastructure/prisma-seeds 0.0.231
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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +284 -0
- package/ai/AISeedGenerator.d.ts +127 -0
- package/ai/AISeedGenerator.d.ts.map +1 -0
- package/ai/AISeedGenerator.js +438 -0
- package/ai/AISeedGenerator.js.map +1 -0
- package/ai/AISeedTypes.d.ts +138 -0
- package/ai/AISeedTypes.d.ts.map +1 -0
- package/ai/AISeedTypes.js +3 -0
- package/ai/AISeedTypes.js.map +1 -0
- package/ai/PrismaModelAnalyzer.d.ts +36 -0
- package/ai/PrismaModelAnalyzer.d.ts.map +1 -0
- package/ai/PrismaModelAnalyzer.js +110 -0
- package/ai/PrismaModelAnalyzer.js.map +1 -0
- package/ai/PrismaTypeSchemaGenerator.d.ts +38 -0
- package/ai/PrismaTypeSchemaGenerator.d.ts.map +1 -0
- package/ai/PrismaTypeSchemaGenerator.js +71 -0
- package/ai/PrismaTypeSchemaGenerator.js.map +1 -0
- package/ai/createAISeeder.d.ts +11 -0
- package/ai/createAISeeder.d.ts.map +1 -0
- package/ai/createAISeeder.js +72 -0
- package/ai/createAISeeder.js.map +1 -0
- package/ai/index.d.ts +6 -0
- package/ai/index.d.ts.map +1 -0
- package/ai/index.js +5 -0
- package/ai/index.js.map +1 -0
- package/assets/AssetManager.d.ts +213 -0
- package/assets/AssetManager.d.ts.map +1 -0
- package/assets/AssetManager.js +460 -0
- package/assets/AssetManager.js.map +1 -0
- package/assets/IImageTransformOptions.d.ts +42 -0
- package/assets/IImageTransformOptions.d.ts.map +1 -0
- package/assets/IImageTransformOptions.js +22 -0
- package/assets/IImageTransformOptions.js.map +1 -0
- package/assets/adapters/BlobAdapterFactory.d.ts +21 -0
- package/assets/adapters/BlobAdapterFactory.d.ts.map +1 -0
- package/assets/adapters/BlobAdapterFactory.js +3 -0
- package/assets/adapters/BlobAdapterFactory.js.map +1 -0
- package/assets/adapters/CloudflareR2BlobAdapter.d.ts +97 -0
- package/assets/adapters/CloudflareR2BlobAdapter.d.ts.map +1 -0
- package/assets/adapters/CloudflareR2BlobAdapter.js +265 -0
- package/assets/adapters/CloudflareR2BlobAdapter.js.map +1 -0
- package/assets/adapters/EmptyBlobAdapter.d.ts +42 -0
- package/assets/adapters/EmptyBlobAdapter.d.ts.map +1 -0
- package/assets/adapters/EmptyBlobAdapter.js +65 -0
- package/assets/adapters/EmptyBlobAdapter.js.map +1 -0
- package/assets/adapters/LocalFileAdapter.d.ts +34 -0
- package/assets/adapters/LocalFileAdapter.d.ts.map +1 -0
- package/assets/adapters/LocalFileAdapter.js +74 -0
- package/assets/adapters/LocalFileAdapter.js.map +1 -0
- package/assets/adapters/VercelBlobAdapter.d.ts +73 -0
- package/assets/adapters/VercelBlobAdapter.d.ts.map +1 -0
- package/assets/adapters/VercelBlobAdapter.js +168 -0
- package/assets/adapters/VercelBlobAdapter.js.map +1 -0
- package/assets/adapters/abstracts/BlobAdapterBase.d.ts +62 -0
- package/assets/adapters/abstracts/BlobAdapterBase.d.ts.map +1 -0
- package/assets/adapters/abstracts/BlobAdapterBase.js +58 -0
- package/assets/adapters/abstracts/BlobAdapterBase.js.map +1 -0
- package/assets/adapters/abstracts/HttpBlobAdapterBase.d.ts +43 -0
- package/assets/adapters/abstracts/HttpBlobAdapterBase.d.ts.map +1 -0
- package/assets/adapters/abstracts/HttpBlobAdapterBase.js +88 -0
- package/assets/adapters/abstracts/HttpBlobAdapterBase.js.map +1 -0
- package/assets/adapters/createBlobAdapter.d.ts +47 -0
- package/assets/adapters/createBlobAdapter.d.ts.map +1 -0
- package/assets/adapters/createBlobAdapter.js +63 -0
- package/assets/adapters/createBlobAdapter.js.map +1 -0
- package/assets/adapters/index.d.ts +11 -0
- package/assets/adapters/index.d.ts.map +1 -0
- package/assets/adapters/index.js +7 -0
- package/assets/adapters/index.js.map +1 -0
- package/assets/adapters/interfaces/IBlobAdapter.d.ts +41 -0
- package/assets/adapters/interfaces/IBlobAdapter.d.ts.map +1 -0
- package/assets/adapters/interfaces/IBlobAdapter.js +3 -0
- package/assets/adapters/interfaces/IBlobAdapter.js.map +1 -0
- package/assets/adapters/interfaces/IBlobAdapterConfig.d.ts +16 -0
- package/assets/adapters/interfaces/IBlobAdapterConfig.d.ts.map +1 -0
- package/assets/adapters/interfaces/IBlobAdapterConfig.js +2 -0
- package/assets/adapters/interfaces/IBlobAdapterConfig.js.map +1 -0
- package/assets/adapters/interfaces/IBlobUploadResult.d.ts +24 -0
- package/assets/adapters/interfaces/IBlobUploadResult.d.ts.map +1 -0
- package/assets/adapters/interfaces/IBlobUploadResult.js +2 -0
- package/assets/adapters/interfaces/IBlobUploadResult.js.map +1 -0
- package/base/BaseSeeder.d.ts +21 -0
- package/base/BaseSeeder.d.ts.map +1 -0
- package/base/BaseSeeder.js +45 -0
- package/base/BaseSeeder.js.map +1 -0
- package/base/functionalSeeder.d.ts +31 -0
- package/base/functionalSeeder.d.ts.map +1 -0
- package/base/functionalSeeder.js +33 -0
- package/base/functionalSeeder.js.map +1 -0
- package/cli/Cli.d.ts +2 -0
- package/cli/Cli.d.ts.map +1 -0
- package/cli/Cli.js +32 -0
- package/cli/Cli.js.map +1 -0
- package/cli/CliArgs.d.ts +2 -0
- package/cli/CliArgs.d.ts.map +1 -0
- package/cli/CliArgs.js +133 -0
- package/cli/CliArgs.js.map +1 -0
- package/cli/CliArgsConfig.d.ts +2 -0
- package/cli/CliArgsConfig.d.ts.map +1 -0
- package/cli/CliArgsConfig.js +15 -0
- package/cli/CliArgsConfig.js.map +1 -0
- package/cli/CliRun.d.ts +2 -0
- package/cli/CliRun.d.ts.map +1 -0
- package/cli/CliRun.js +34 -0
- package/cli/CliRun.js.map +1 -0
- package/cli/commands/SeedCommand.d.ts +2 -0
- package/cli/commands/SeedCommand.d.ts.map +1 -0
- package/cli/commands/SeedCommand.js +73 -0
- package/cli/commands/SeedCommand.js.map +1 -0
- package/cli/commands/SeedCommandArgsConfig.d.ts +2 -0
- package/cli/commands/SeedCommandArgsConfig.d.ts.map +1 -0
- package/cli/commands/SeedCommandArgsConfig.js +31 -0
- package/cli/commands/SeedCommandArgsConfig.js.map +1 -0
- package/cli/seed.d.ts +2 -0
- package/cli/seed.d.ts.map +1 -0
- package/cli/seed.js +42 -0
- package/cli/seed.js.map +1 -0
- package/config/IAssetConfig.d.ts +36 -0
- package/config/IAssetConfig.d.ts.map +1 -0
- package/config/IAssetConfig.js +3 -0
- package/config/IAssetConfig.js.map +1 -0
- package/config/IComposedSeedConfig.d.ts +32 -0
- package/config/IComposedSeedConfig.d.ts.map +1 -0
- package/config/IComposedSeedConfig.js +3 -0
- package/config/IComposedSeedConfig.js.map +1 -0
- package/config/ISeedConfig.d.ts +75 -0
- package/config/ISeedConfig.d.ts.map +1 -0
- package/config/ISeedConfig.js +3 -0
- package/config/ISeedConfig.js.map +1 -0
- package/config/ISeedContext.d.ts +92 -0
- package/config/ISeedContext.d.ts.map +1 -0
- package/config/ISeedContext.js +3 -0
- package/config/ISeedContext.js.map +1 -0
- package/config/ISeedDefinition.d.ts +38 -0
- package/config/ISeedDefinition.d.ts.map +1 -0
- package/config/ISeedDefinition.js +3 -0
- package/config/ISeedDefinition.js.map +1 -0
- package/config/ISeedFactory.d.ts +15 -0
- package/config/ISeedFactory.d.ts.map +1 -0
- package/config/ISeedFactory.js +3 -0
- package/config/ISeedFactory.js.map +1 -0
- package/config/ISeedOptions.d.ts +44 -0
- package/config/ISeedOptions.d.ts.map +1 -0
- package/config/ISeedOptions.js +2 -0
- package/config/ISeedOptions.js.map +1 -0
- package/config/ISeedResult.d.ts +44 -0
- package/config/ISeedResult.d.ts.map +1 -0
- package/config/ISeedResult.js +2 -0
- package/config/ISeedResult.js.map +1 -0
- package/config/ISeeder.d.ts +37 -0
- package/config/ISeeder.d.ts.map +1 -0
- package/config/ISeeder.js +3 -0
- package/config/ISeeder.js.map +1 -0
- package/config/createAdapter.d.ts +13 -0
- package/config/createAdapter.d.ts.map +1 -0
- package/config/createAdapter.js +16 -0
- package/config/createAdapter.js.map +1 -0
- package/config/createSeed.d.ts +6 -0
- package/config/createSeed.d.ts.map +1 -0
- package/config/createSeed.js +16 -0
- package/config/createSeed.js.map +1 -0
- package/config/defineConfig.d.ts +27 -0
- package/config/defineConfig.d.ts.map +1 -0
- package/config/defineConfig.js +35 -0
- package/config/defineConfig.js.map +1 -0
- package/discovery/SeedConfigDiscovery.d.ts +16 -0
- package/discovery/SeedConfigDiscovery.d.ts.map +1 -0
- package/discovery/SeedConfigDiscovery.js +137 -0
- package/discovery/SeedConfigDiscovery.js.map +1 -0
- package/index.d.ts +32 -0
- package/index.d.ts.map +1 -0
- package/index.js +32 -0
- package/index.js.map +1 -0
- package/json/JsonReferenceResolver.d.ts +23 -0
- package/json/JsonReferenceResolver.d.ts.map +1 -0
- package/json/JsonReferenceResolver.js +99 -0
- package/json/JsonReferenceResolver.js.map +1 -0
- package/json/JsonSchemaValidator.d.ts +23 -0
- package/json/JsonSchemaValidator.d.ts.map +1 -0
- package/json/JsonSchemaValidator.js +98 -0
- package/json/JsonSchemaValidator.js.map +1 -0
- package/json/JsonSeedLoader.d.ts +33 -0
- package/json/JsonSeedLoader.d.ts.map +1 -0
- package/json/JsonSeedLoader.js +176 -0
- package/json/JsonSeedLoader.js.map +1 -0
- package/json/JsonSeedTypes.d.ts +204 -0
- package/json/JsonSeedTypes.d.ts.map +1 -0
- package/json/JsonSeedTypes.js +3 -0
- package/json/JsonSeedTypes.js.map +1 -0
- package/json/createJsonSeeder.d.ts +13 -0
- package/json/createJsonSeeder.d.ts.map +1 -0
- package/json/createJsonSeeder.js +240 -0
- package/json/createJsonSeeder.js.map +1 -0
- package/json/index.d.ts +6 -0
- package/json/index.d.ts.map +1 -0
- package/json/index.js +7 -0
- package/json/index.js.map +1 -0
- package/logging/ISeedLogger.d.ts +55 -0
- package/logging/ISeedLogger.d.ts.map +1 -0
- package/logging/ISeedLogger.js +3 -0
- package/logging/ISeedLogger.js.map +1 -0
- package/logging/LogLevel.d.ts +30 -0
- package/logging/LogLevel.d.ts.map +1 -0
- package/logging/LogLevel.js +37 -0
- package/logging/LogLevel.js.map +1 -0
- package/logging/SeedLogger.d.ts +24 -0
- package/logging/SeedLogger.d.ts.map +1 -0
- package/logging/SeedLogger.js +94 -0
- package/logging/SeedLogger.js.map +1 -0
- package/orchestration/SeedOrchestrator.d.ts +30 -0
- package/orchestration/SeedOrchestrator.d.ts.map +1 -0
- package/orchestration/SeedOrchestrator.js +262 -0
- package/orchestration/SeedOrchestrator.js.map +1 -0
- package/package.json +27 -0
- package/resolvers/EntityResolver.d.ts +43 -0
- package/resolvers/EntityResolver.d.ts.map +1 -0
- package/resolvers/EntityResolver.js +95 -0
- package/resolvers/EntityResolver.js.map +1 -0
- package/utils/AssetReferenceResolver.d.ts +49 -0
- package/utils/AssetReferenceResolver.d.ts.map +1 -0
- package/utils/AssetReferenceResolver.js +62 -0
- package/utils/AssetReferenceResolver.js.map +1 -0
- package/utils/EntityLookupCache.d.ts +47 -0
- package/utils/EntityLookupCache.d.ts.map +1 -0
- package/utils/EntityLookupCache.js +64 -0
- package/utils/EntityLookupCache.js.map +1 -0
- package/utils/ISeedRandom.d.ts +70 -0
- package/utils/ISeedRandom.d.ts.map +1 -0
- package/utils/ISeedRandom.js +3 -0
- package/utils/ISeedRandom.js.map +1 -0
- package/utils/LocalizationToolkit.d.ts +125 -0
- package/utils/LocalizationToolkit.d.ts.map +1 -0
- package/utils/LocalizationToolkit.js +131 -0
- package/utils/LocalizationToolkit.js.map +1 -0
- package/utils/SeededRandom.d.ts +15 -0
- package/utils/SeededRandom.d.ts.map +1 -0
- package/utils/SeededRandom.js +56 -0
- package/utils/SeededRandom.js.map +1 -0
- package/utils/StringArrayToolkit.d.ts +25 -0
- package/utils/StringArrayToolkit.d.ts.map +1 -0
- package/utils/StringArrayToolkit.js +56 -0
- package/utils/StringArrayToolkit.js.map +1 -0
- package/utils/StringValueGuard.d.ts +24 -0
- package/utils/StringValueGuard.d.ts.map +1 -0
- package/utils/StringValueGuard.js +46 -0
- package/utils/StringValueGuard.js.map +1 -0
- package/utils/WarningCollector.d.ts +40 -0
- package/utils/WarningCollector.d.ts.map +1 -0
- package/utils/WarningCollector.js +83 -0
- package/utils/WarningCollector.js.map +1 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
/**
|
|
3
|
+
* Provides a caching layer for expensive lookup operations in JSON seed mappers.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class EntityLookupCache {
|
|
8
|
+
// #region Fields
|
|
9
|
+
cache;
|
|
10
|
+
resolver;
|
|
11
|
+
// #endregion
|
|
12
|
+
// #region Ctor
|
|
13
|
+
constructor(resolver) {
|
|
14
|
+
this.cache = new Map();
|
|
15
|
+
this.resolver = resolver;
|
|
16
|
+
}
|
|
17
|
+
// #endregion
|
|
18
|
+
// #region Methods
|
|
19
|
+
/**
|
|
20
|
+
* Resolves a value for the provided key, using the cache when available.
|
|
21
|
+
*
|
|
22
|
+
* @param key Lookup key
|
|
23
|
+
* @param context Seeder execution context
|
|
24
|
+
* @returns Resolved value
|
|
25
|
+
*/
|
|
26
|
+
async resolve(key, context) {
|
|
27
|
+
const normalizedKey = EntityLookupCache.normalizeKey(key);
|
|
28
|
+
const cachedValue = this.cache.get(normalizedKey);
|
|
29
|
+
if (cachedValue !== undefined) {
|
|
30
|
+
return cachedValue;
|
|
31
|
+
}
|
|
32
|
+
const resolvedValue = await this.resolver.resolve(normalizedKey, context);
|
|
33
|
+
this.cache.set(normalizedKey, resolvedValue);
|
|
34
|
+
return resolvedValue;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves multiple keys sequentially, preserving order.
|
|
38
|
+
*
|
|
39
|
+
* @param keys Lookup keys
|
|
40
|
+
* @param context Seeder execution context
|
|
41
|
+
* @returns Resolved values
|
|
42
|
+
*/
|
|
43
|
+
async resolveMany(keys, context) {
|
|
44
|
+
const results = [];
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
results.push(await this.resolve(key, context));
|
|
47
|
+
}
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Clears the internal cache.
|
|
52
|
+
*/
|
|
53
|
+
clear() {
|
|
54
|
+
this.cache.clear();
|
|
55
|
+
}
|
|
56
|
+
static normalizeKey(key) {
|
|
57
|
+
const normalized = key.trim();
|
|
58
|
+
if (normalized.length === 0) {
|
|
59
|
+
throw new Error('Entity key must not be empty.');
|
|
60
|
+
}
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=EntityLookupCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityLookupCache.js","sourceRoot":"","sources":["../../src/utils/EntityLookupCache.ts"],"names":[],"mappings":"AAAA,kBAAkB;AA2BlB;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAE1B,iBAAiB;IAEA,KAAK,CAAuB;IAC5B,QAAQ,CAAiC;IAE1D,aAAa;IAEb,eAAe;IAEf,YAAmB,QAAwC;QACvD,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;;OAMG;IACI,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,OAAqB;QACnD,MAAM,aAAa,GAAW,iBAAiB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAClE,MAAM,WAAW,GAAwB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACvE,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,WAAW,CAAC;QACvB,CAAC;QAED,MAAM,aAAa,GAAY,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACnF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QAC7C,OAAO,aAAa,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,IAAuB,EAAE,OAAqB;QACnE,MAAM,OAAO,GAAc,EAAE,CAAC;QAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IAED;;OAEG;IACI,KAAK;QACR,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,GAAW;QACnC,MAAM,UAAU,GAAW,GAAG,CAAC,IAAI,EAAE,CAAC;QACtC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;CAIJ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Random data generator for seeding operations.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ISeedRandom {
|
|
7
|
+
/**
|
|
8
|
+
* Generate a random number, optionally within a specified range.
|
|
9
|
+
*
|
|
10
|
+
* @param min The minimum value (inclusive).
|
|
11
|
+
* @param max The maximum value (exclusive).
|
|
12
|
+
* @returns A random number.
|
|
13
|
+
*/
|
|
14
|
+
number(min?: number, max?: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Generate a random integer, optionally within a specified range.
|
|
17
|
+
*
|
|
18
|
+
* @param min The minimum value (inclusive).
|
|
19
|
+
* @param max The maximum value (inclusive).
|
|
20
|
+
* @returns A random integer.
|
|
21
|
+
*/
|
|
22
|
+
int(min?: number, max?: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Generate a random boolean value, optionally with a specified probability.
|
|
25
|
+
*
|
|
26
|
+
* @param probability The probability of returning true (between 0 and 1).
|
|
27
|
+
* @returns A random boolean value.
|
|
28
|
+
*/
|
|
29
|
+
boolean(probability?: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Select one or more random items from an array.
|
|
32
|
+
*
|
|
33
|
+
* @template T The type of items in the array.
|
|
34
|
+
* @param items The array of items to choose from.
|
|
35
|
+
* @returns A single random item or an array of random items.
|
|
36
|
+
*/
|
|
37
|
+
choice<T>(items: T[]): T;
|
|
38
|
+
/**
|
|
39
|
+
* Select multiple random items from an array.
|
|
40
|
+
*
|
|
41
|
+
* @template T The type of items in the array.
|
|
42
|
+
* @param items The array of items to choose from.
|
|
43
|
+
* @param count The number of items to select.
|
|
44
|
+
* @returns An array of random items.
|
|
45
|
+
*/
|
|
46
|
+
choices<T>(items: T[], count: number): T[];
|
|
47
|
+
/**
|
|
48
|
+
* Shuffle the items in an array randomly.
|
|
49
|
+
*
|
|
50
|
+
* @template T The type of items in the array.
|
|
51
|
+
* @param items The array of items to shuffle.
|
|
52
|
+
* @returns A new array with the items shuffled.
|
|
53
|
+
*/
|
|
54
|
+
shuffle<T>(items: T[]): T[];
|
|
55
|
+
/**
|
|
56
|
+
* Generate a random UUID (version 4).
|
|
57
|
+
*
|
|
58
|
+
* @returns A random UUID string.
|
|
59
|
+
*/
|
|
60
|
+
uuid(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Generate a random CUID (collision-resistant unique identifier).
|
|
63
|
+
*
|
|
64
|
+
* @param prefix An optional prefix to prepend to the CUID.
|
|
65
|
+
* @param postfix An optional postfix to append to the CUID.
|
|
66
|
+
* @returns A random CUID string.
|
|
67
|
+
*/
|
|
68
|
+
cuid(prefix?: string, postfix?: string): string;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=ISeedRandom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ISeedRandom.d.ts","sourceRoot":"","sources":["../../src/utils/ISeedRandom.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAIxB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE3C;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAExC;;;;;OAKG;IACH,OAAO,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAEvC;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;IAEzB;;;;;;;OAOG;IACH,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;IAE3C;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IAE5B;;;;OAIG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;;;;;OAMG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAInD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ISeedRandom.js","sourceRoot":"","sources":["../../src/utils/ISeedRandom.ts"],"names":[],"mappings":"AAAA,mCAAmC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a dictionary of localized values keyed by locale identifier.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ITranslationMap {
|
|
7
|
+
[locale: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Normalized translation value containing locale and trimmed text.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface ITranslationValue {
|
|
15
|
+
/**
|
|
16
|
+
* Locale identifier (e.g. `en`, `de`).
|
|
17
|
+
*/
|
|
18
|
+
readonly locale: string;
|
|
19
|
+
/**
|
|
20
|
+
* Trimmed translation text.
|
|
21
|
+
*/
|
|
22
|
+
readonly value: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Options for validating translation maps.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export interface ITranslationValidationOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Human readable field name for error messaging.
|
|
32
|
+
*/
|
|
33
|
+
readonly fieldName: string;
|
|
34
|
+
/**
|
|
35
|
+
* Preferred locales when resolving primary translation values.
|
|
36
|
+
*/
|
|
37
|
+
readonly fallbackLocales?: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Prisma payload for creating translation group values.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export interface ITranslationGroupCreatePayload {
|
|
45
|
+
readonly create: {
|
|
46
|
+
readonly values: {
|
|
47
|
+
readonly createMany: {
|
|
48
|
+
readonly data: readonly ITranslationValue[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Prisma payload for updating translation group values.
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export interface ITranslationGroupUpdatePayload {
|
|
59
|
+
readonly update: {
|
|
60
|
+
readonly values: {
|
|
61
|
+
readonly deleteMany: Record<string, never>;
|
|
62
|
+
readonly createMany: {
|
|
63
|
+
readonly data: readonly ITranslationValue[];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Provides translation related utilities for JSON seed mappers.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
export declare class LocalizationToolkit {
|
|
74
|
+
private static readonly DEFAULT_FALLBACK_LOCALES;
|
|
75
|
+
private constructor();
|
|
76
|
+
/**
|
|
77
|
+
* Normalizes a translation map into Prisma compatible value objects.
|
|
78
|
+
*
|
|
79
|
+
* @param translations Translation dictionary
|
|
80
|
+
* @returns Normalized translation values
|
|
81
|
+
*/
|
|
82
|
+
static mapValues(translations: ITranslationMap | null | undefined): ITranslationValue[];
|
|
83
|
+
/**
|
|
84
|
+
* Ensures that the provided translations contain at least one valid entry.
|
|
85
|
+
*
|
|
86
|
+
* @param translations Translation dictionary
|
|
87
|
+
* @param options Validation options
|
|
88
|
+
* @returns Normalized translation values
|
|
89
|
+
*/
|
|
90
|
+
static ensureValues(translations: ITranslationMap | null | undefined, options: ITranslationValidationOptions): ITranslationValue[];
|
|
91
|
+
/**
|
|
92
|
+
* Creates a Prisma payload for translation group creation.
|
|
93
|
+
*
|
|
94
|
+
* @param translations Translation dictionary
|
|
95
|
+
* @param options Validation options
|
|
96
|
+
* @returns Prisma payload for create operation
|
|
97
|
+
*/
|
|
98
|
+
static createGroup(translations: ITranslationMap | null | undefined, options: ITranslationValidationOptions): ITranslationGroupCreatePayload;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a Prisma payload for translation group updates.
|
|
101
|
+
*
|
|
102
|
+
* @param translations Translation dictionary
|
|
103
|
+
* @param options Validation options
|
|
104
|
+
* @returns Prisma payload for update operation
|
|
105
|
+
*/
|
|
106
|
+
static updateGroup(translations: ITranslationMap | null | undefined, options: ITranslationValidationOptions): ITranslationGroupUpdatePayload;
|
|
107
|
+
/**
|
|
108
|
+
* Chooses between creating or updating a translation group based on existing data presence.
|
|
109
|
+
*
|
|
110
|
+
* @param translations Translation dictionary
|
|
111
|
+
* @param hasExistingGroup Whether a translation group already exists
|
|
112
|
+
* @param options Validation options
|
|
113
|
+
* @returns Prisma payload for create or update
|
|
114
|
+
*/
|
|
115
|
+
static createOrUpdateGroup(translations: ITranslationMap | null | undefined, hasExistingGroup: boolean, options: ITranslationValidationOptions): ITranslationGroupCreatePayload | ITranslationGroupUpdatePayload;
|
|
116
|
+
/**
|
|
117
|
+
* Resolves the primary textual representation from a translation map.
|
|
118
|
+
*
|
|
119
|
+
* @param translations Translation dictionary
|
|
120
|
+
* @param fallbackLocales Preferred locales used for selection (defaults to `['en']`)
|
|
121
|
+
* @returns Primary text or empty string when not available
|
|
122
|
+
*/
|
|
123
|
+
static resolvePrimary(translations: ITranslationMap | null | undefined, fallbackLocales?: readonly string[]): string;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=LocalizationToolkit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationToolkit.d.ts","sourceRoot":"","sources":["../../src/utils/LocalizationToolkit.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAI5B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CAI7B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAI9B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAI1B;AAED;;;;GAIG;AACH,MAAM,WAAW,6BAA6B;IAI1C;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAIhD;AAED;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAI3C,QAAQ,CAAC,MAAM,EAAE;QACb,QAAQ,CAAC,MAAM,EAAE;YACb,QA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AG,SAAS,EAAE,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;CAmB9H"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
/**
|
|
3
|
+
* Provides translation related utilities for JSON seed mappers.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class LocalizationToolkit {
|
|
8
|
+
// #region Fields
|
|
9
|
+
static DEFAULT_FALLBACK_LOCALES = ['en'];
|
|
10
|
+
// #endregion
|
|
11
|
+
// #region Ctor
|
|
12
|
+
constructor() {
|
|
13
|
+
// Utility class
|
|
14
|
+
}
|
|
15
|
+
// #endregion
|
|
16
|
+
// #region Methods
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes a translation map into Prisma compatible value objects.
|
|
19
|
+
*
|
|
20
|
+
* @param translations Translation dictionary
|
|
21
|
+
* @returns Normalized translation values
|
|
22
|
+
*/
|
|
23
|
+
static mapValues(translations) {
|
|
24
|
+
if (!translations) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const normalizedValues = [];
|
|
28
|
+
for (const [locale, rawValue] of Object.entries(translations)) {
|
|
29
|
+
if (typeof rawValue !== 'string') {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const trimmedValue = rawValue.trim();
|
|
33
|
+
if (trimmedValue.length === 0) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
normalizedValues.push({
|
|
37
|
+
locale,
|
|
38
|
+
value: trimmedValue
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return normalizedValues;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Ensures that the provided translations contain at least one valid entry.
|
|
45
|
+
*
|
|
46
|
+
* @param translations Translation dictionary
|
|
47
|
+
* @param options Validation options
|
|
48
|
+
* @returns Normalized translation values
|
|
49
|
+
*/
|
|
50
|
+
static ensureValues(translations, options) {
|
|
51
|
+
const normalizedValues = LocalizationToolkit.mapValues(translations);
|
|
52
|
+
if (normalizedValues.length === 0) {
|
|
53
|
+
throw new Error(`${options.fieldName} requires at least one translation.`);
|
|
54
|
+
}
|
|
55
|
+
return normalizedValues;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a Prisma payload for translation group creation.
|
|
59
|
+
*
|
|
60
|
+
* @param translations Translation dictionary
|
|
61
|
+
* @param options Validation options
|
|
62
|
+
* @returns Prisma payload for create operation
|
|
63
|
+
*/
|
|
64
|
+
static createGroup(translations, options) {
|
|
65
|
+
const normalizedValues = LocalizationToolkit.ensureValues(translations, options);
|
|
66
|
+
return {
|
|
67
|
+
create: {
|
|
68
|
+
values: {
|
|
69
|
+
createMany: {
|
|
70
|
+
data: normalizedValues
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates a Prisma payload for translation group updates.
|
|
78
|
+
*
|
|
79
|
+
* @param translations Translation dictionary
|
|
80
|
+
* @param options Validation options
|
|
81
|
+
* @returns Prisma payload for update operation
|
|
82
|
+
*/
|
|
83
|
+
static updateGroup(translations, options) {
|
|
84
|
+
const normalizedValues = LocalizationToolkit.ensureValues(translations, options);
|
|
85
|
+
return {
|
|
86
|
+
update: {
|
|
87
|
+
values: {
|
|
88
|
+
deleteMany: {},
|
|
89
|
+
createMany: {
|
|
90
|
+
data: normalizedValues
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Chooses between creating or updating a translation group based on existing data presence.
|
|
98
|
+
*
|
|
99
|
+
* @param translations Translation dictionary
|
|
100
|
+
* @param hasExistingGroup Whether a translation group already exists
|
|
101
|
+
* @param options Validation options
|
|
102
|
+
* @returns Prisma payload for create or update
|
|
103
|
+
*/
|
|
104
|
+
static createOrUpdateGroup(translations, hasExistingGroup, options) {
|
|
105
|
+
return hasExistingGroup
|
|
106
|
+
? LocalizationToolkit.updateGroup(translations, options)
|
|
107
|
+
: LocalizationToolkit.createGroup(translations, options);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Resolves the primary textual representation from a translation map.
|
|
111
|
+
*
|
|
112
|
+
* @param translations Translation dictionary
|
|
113
|
+
* @param fallbackLocales Preferred locales used for selection (defaults to `['en']`)
|
|
114
|
+
* @returns Primary text or empty string when not available
|
|
115
|
+
*/
|
|
116
|
+
static resolvePrimary(translations, fallbackLocales) {
|
|
117
|
+
const normalizedValues = LocalizationToolkit.mapValues(translations);
|
|
118
|
+
if (normalizedValues.length === 0) {
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
const preferredLocales = fallbackLocales ?? LocalizationToolkit.DEFAULT_FALLBACK_LOCALES;
|
|
122
|
+
for (const locale of preferredLocales) {
|
|
123
|
+
const match = normalizedValues.find((value) => value.locale === locale);
|
|
124
|
+
if (match) {
|
|
125
|
+
return match.value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return normalizedValues[0]?.value ?? '';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=LocalizationToolkit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationToolkit.js","sourceRoot":"","sources":["../../src/utils/LocalizationToolkit.ts"],"names":[],"mappings":"AAAA,kBAAkB;AA4GlB;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAE5B,iBAAiB;IAET,MAAM,CAAU,wBAAwB,GAAsB,CAAC,IAAI,CAAC,CAAC;IAE7E,aAAa;IAEb,eAAe;IAEf;QACI,gBAAgB;IACpB,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CAAC,YAAgD;QACpE,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;QACd,CAAC;QAED,MAAM,gBAAg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AAC;QACtG,OAAO;YACH,MAAM,EAAE;gBACJ,MAAM,EAAE;oBACJ,UAAU,EAAE,EAAE;oBACd,UAAU,EAAE;wBACR,IAAI,EAAE,gBAAgB;qBACzB;iBACJ;aACJ;SACJ,CAAC;IACN,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,mBAAmB,CAC7B,YAAgD,EAChD,gBAAyB,EACzB,OAAsC;QAEtC,OAAO,gBAAgB;YACnB,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC;YACxD,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,YAAgD,EAAE,eAAmC;QAC9G,MAAM,gBAAgB,GAAwB,mBAAmB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAC1F,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,EAAE,CAAC;QACd,CAAC;QAED,MAAM,gBAAgB,GAAsB,eAAe,IAAI,mBAAmB,CAAC,wBAAwB,CAAC;QAC5G,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;YACpC,MAAM,KAAK,GAAkC,gBAAgB,CAAC,IAAI,CAAC,CAAC,KAAwB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;YAC1H,IAAI,KAAK,EAAE,CAAC;gBACR,OAAO,KAAK,CAAC,KAAK,CAAC;YACvB,CAAC;QACL,CAAC;QAED,OAAO,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;IAC5C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ISeedRandom } from './ISeedRandom.js';
|
|
2
|
+
export declare class SeededRandom implements ISeedRandom {
|
|
3
|
+
private _seed;
|
|
4
|
+
private _cuidIncrement;
|
|
5
|
+
constructor(seed?: number);
|
|
6
|
+
number(min?: number, max?: number): number;
|
|
7
|
+
int(min?: number, max?: number): number;
|
|
8
|
+
boolean(probability?: number): boolean;
|
|
9
|
+
choice<T>(items: T[]): T;
|
|
10
|
+
choices<T>(items: T[], count: number): T[];
|
|
11
|
+
shuffle<T>(items: T[]): T[];
|
|
12
|
+
uuid(): string;
|
|
13
|
+
cuid(prefix?: string, postfix?: string): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=SeededRandom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SeededRandom.d.ts","sourceRoot":"","sources":["../../src/utils/SeededRandom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD,qBAAa,YAAa,YAAW,WAAW;IAE5C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,cAAc,CAAS;gBAEZ,IAAI,CAAC,EAAE,MAAM;IAKzB,MAAM,CAAC,GAAG,SAAI,EAAE,GAAG,SAAI,GAAG,MAAM;IAMhC,GAAG,CAAC,GAAG,SAAI,EAAE,GAAG,SAAM,GAAG,MAAM;IAI/B,OAAO,CAAC,WAAW,SAAM,GAAG,OAAO;IAInC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC;IAQxB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE;IAQ1C,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE;IAS3B,IAAI,IAAI,MAAM;IAId,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;CAUzD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
// #endregion
|
|
4
|
+
export class SeededRandom {
|
|
5
|
+
_seed;
|
|
6
|
+
_cuidIncrement;
|
|
7
|
+
constructor(seed) {
|
|
8
|
+
this._seed = seed ?? Date.now();
|
|
9
|
+
this._cuidIncrement = 0;
|
|
10
|
+
}
|
|
11
|
+
number(min = 0, max = 1) {
|
|
12
|
+
this._seed = ((this._seed * 9301) + 49297) % 233280;
|
|
13
|
+
const rnd = this._seed / 233280.0;
|
|
14
|
+
return min + (rnd * (max - min));
|
|
15
|
+
}
|
|
16
|
+
int(min = 0, max = 100) {
|
|
17
|
+
return Math.floor(this.number(min, max + 1));
|
|
18
|
+
}
|
|
19
|
+
boolean(probability = 0.5) {
|
|
20
|
+
return this.number() < probability;
|
|
21
|
+
}
|
|
22
|
+
choice(items) {
|
|
23
|
+
if (items.length === 0) {
|
|
24
|
+
throw new Error('Cannot choose from empty array');
|
|
25
|
+
}
|
|
26
|
+
const index = this.int(0, items.length - 1);
|
|
27
|
+
return items[index];
|
|
28
|
+
}
|
|
29
|
+
choices(items, count) {
|
|
30
|
+
const result = [];
|
|
31
|
+
for (let i = 0; i < count; i++) {
|
|
32
|
+
result.push(this.choice(items));
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
shuffle(items) {
|
|
37
|
+
const result = [...items];
|
|
38
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
39
|
+
const j = this.int(0, i);
|
|
40
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
uuid() {
|
|
45
|
+
return randomUUID();
|
|
46
|
+
}
|
|
47
|
+
cuid(prefix, postfix) {
|
|
48
|
+
const timestamp = Date.now().toString(36);
|
|
49
|
+
const randomBlock = Math.random().toString(36)
|
|
50
|
+
.substring(2, 10);
|
|
51
|
+
const counterBlock = (this._cuidIncrement++).toString(36).padStart(4, '0');
|
|
52
|
+
const cuid = `c${timestamp}${counterBlock}${randomBlock}`;
|
|
53
|
+
return `${prefix ?? ''}${cuid}${postfix ?? ''}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=SeededRandom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SeededRandom.js","sourceRoot":"","sources":["../../src/utils/SeededRandom.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAElB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,aAAa;AAEb,MAAM,OAAO,YAAY;IAEb,KAAK,CAAS;IACd,cAAc,CAAS;IAE/B,YAAmB,IAAa;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;QAClC,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;IACrC,CAAC;IAEM,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IAEM,OAAO,CAAC,WAAW,GAAG,GAAG;QAC5B,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,WAAW,CAAC;IACvC,CAAC;IAEM,MAAM,CAAI,KAAU;QACvB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IA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CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtB,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3E,MAAM,IAAI,GAAG,IAAI,SAAS,GAAG,YAAY,GAAG,WAAW,EAAE,CAAC;QAE1D,OAAO,GAAG,MAAM,IAAI,EAAE,GAAG,IAAI,GAAG,OAAO,IAAI,EAAE,EAAE,CAAC;IACpD,CAAC;CAEJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides utilities for working with arrays of string values in seed configurations.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class StringArrayToolkit {
|
|
7
|
+
private static readonly EMPTY_RESULT;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes an arbitrary array to a deduplicated list of trimmed strings.
|
|
11
|
+
*
|
|
12
|
+
* @param values Arbitrary values
|
|
13
|
+
* @returns Deduplicated and trimmed string list
|
|
14
|
+
*/
|
|
15
|
+
static unique(values: unknown[] | null | undefined): readonly string[];
|
|
16
|
+
/**
|
|
17
|
+
* Ensures that at least one valid string value is present.
|
|
18
|
+
*
|
|
19
|
+
* @param values Arbitrary values
|
|
20
|
+
* @param errorMessage Error to throw when no valid strings are found
|
|
21
|
+
* @returns Deduplicated and trimmed string list
|
|
22
|
+
*/
|
|
23
|
+
static ensureNonEmpty(values: unknown[] | null | undefined, errorMessage: string): readonly string[];
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=StringArrayToolkit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringArrayToolkit.d.ts","sourceRoot":"","sources":["../../src/utils/StringArrayToolkit.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,qBAAa,kBAAkB;IAI3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAM7D,OAAO;IAQP;;;;;OAKG;WACW,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE;IAsB7E;;;;;;OAMG;WACW,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE;CAW9G"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
// #endregion
|
|
3
|
+
/**
|
|
4
|
+
* Provides utilities for working with arrays of string values in seed configurations.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class StringArrayToolkit {
|
|
9
|
+
// #region Fields
|
|
10
|
+
static EMPTY_RESULT = [];
|
|
11
|
+
// #endregion
|
|
12
|
+
// #region Ctor
|
|
13
|
+
constructor() {
|
|
14
|
+
// Utility class
|
|
15
|
+
}
|
|
16
|
+
// #endregion
|
|
17
|
+
// #region Methods
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes an arbitrary array to a deduplicated list of trimmed strings.
|
|
20
|
+
*
|
|
21
|
+
* @param values Arbitrary values
|
|
22
|
+
* @returns Deduplicated and trimmed string list
|
|
23
|
+
*/
|
|
24
|
+
static unique(values) {
|
|
25
|
+
if (!values || values.length === 0) {
|
|
26
|
+
return StringArrayToolkit.EMPTY_RESULT;
|
|
27
|
+
}
|
|
28
|
+
const normalizedValues = new Set();
|
|
29
|
+
for (const value of values) {
|
|
30
|
+
if (typeof value !== 'string') {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const trimmedValue = value.trim();
|
|
34
|
+
if (trimmedValue.length === 0) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
normalizedValues.add(trimmedValue);
|
|
38
|
+
}
|
|
39
|
+
return Array.from(normalizedValues);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ensures that at least one valid string value is present.
|
|
43
|
+
*
|
|
44
|
+
* @param values Arbitrary values
|
|
45
|
+
* @param errorMessage Error to throw when no valid strings are found
|
|
46
|
+
* @returns Deduplicated and trimmed string list
|
|
47
|
+
*/
|
|
48
|
+
static ensureNonEmpty(values, errorMessage) {
|
|
49
|
+
const normalizedValues = StringArrayToolkit.unique(values);
|
|
50
|
+
if (normalizedValues.length === 0) {
|
|
51
|
+
throw new Error(errorMessage);
|
|
52
|
+
}
|
|
53
|
+
return normalizedValues;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=StringArrayToolkit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringArrayToolkit.js","sourceRoot":"","sources":["../../src/utils/StringArrayToolkit.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAElB,aAAa;AAEb;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAE3B,iBAAiB;IAET,MAAM,CAAU,YAAY,GAAsB,EAAE,CAAC;IAE7D,aAAa;IAEb,eAAe;IAEf;QACI,gBAAgB;IACpB,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,MAAoC;QACrD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,kBAAkB,CAAC,YAAY,CAAC;QAC3C,CAAC;QAED,MAAM,gBAAgB,GAAgB,IAAI,GAAG,EAAU,CAAC;QACxD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC5B,SAAS;YACb,CAAC;YAED,MAAM,YAAY,GAAW,KAAK,CAAC,IAAI,EAAE,CAAC;YAC1C,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC5B,SAAS;YACb,CAAC;YAED,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,cAAc,CAAC,MAAoC,EAAE,YAAoB;QACnF,MAAM,gBAAgB,GAAsB,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9E,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC5B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides validation utilities for working with string values inside seed mappers.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class StringValueGuard {
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Ensures that the provided value is a non-empty string.
|
|
10
|
+
*
|
|
11
|
+
* @param value Value to validate
|
|
12
|
+
* @param errorMessage Error message when validation fails
|
|
13
|
+
* @returns Trimmed string value
|
|
14
|
+
*/
|
|
15
|
+
static ensure(value: unknown, errorMessage: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Normalizes optional string inputs by trimming whitespace.
|
|
18
|
+
*
|
|
19
|
+
* @param value Value to normalize
|
|
20
|
+
* @returns Trimmed string or null when empty
|
|
21
|
+
*/
|
|
22
|
+
static normalize(value: unknown): string | null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=StringValueGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StringValueGuard.d.ts","sourceRoot":"","sources":["../../src/utils/StringValueGuard.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,qBAAa,gBAAgB;IAIzB,OAAO;IAQP;;;;;;OAMG;WACW,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAalE;;;;;OAKG;WACW,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;CAWzD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
// #endregion
|
|
3
|
+
/**
|
|
4
|
+
* Provides validation utilities for working with string values inside seed mappers.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class StringValueGuard {
|
|
9
|
+
// #region Ctor
|
|
10
|
+
constructor() {
|
|
11
|
+
// Static utility
|
|
12
|
+
}
|
|
13
|
+
// #endregion
|
|
14
|
+
// #region Methods
|
|
15
|
+
/**
|
|
16
|
+
* Ensures that the provided value is a non-empty string.
|
|
17
|
+
*
|
|
18
|
+
* @param value Value to validate
|
|
19
|
+
* @param errorMessage Error message when validation fails
|
|
20
|
+
* @returns Trimmed string value
|
|
21
|
+
*/
|
|
22
|
+
static ensure(value, errorMessage) {
|
|
23
|
+
if (typeof value !== 'string') {
|
|
24
|
+
throw new Error(errorMessage);
|
|
25
|
+
}
|
|
26
|
+
const trimmedValue = value.trim();
|
|
27
|
+
if (trimmedValue.length === 0) {
|
|
28
|
+
throw new Error(errorMessage);
|
|
29
|
+
}
|
|
30
|
+
return trimmedValue;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Normalizes optional string inputs by trimming whitespace.
|
|
34
|
+
*
|
|
35
|
+
* @param value Value to normalize
|
|
36
|
+
* @returns Trimmed string or null when empty
|
|
37
|
+
*/
|
|
38
|
+
static normalize(value) {
|
|
39
|
+
if (typeof value !== 'string') {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const trimmedValue = value.trim();
|
|
43
|
+
return trimmedValue.length > 0 ? trimmedValue : null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=StringValueGuard.js.map
|