@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,262 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
import { createAdapter } from '../config/createAdapter.js';
|
|
3
|
+
import { SeedConfigDiscovery } from '../discovery/SeedConfigDiscovery.js';
|
|
4
|
+
import { SeedLogger } from '../logging/SeedLogger.js';
|
|
5
|
+
import { SeededRandom } from '../utils/SeededRandom.js';
|
|
6
|
+
export class SeedOrchestrator {
|
|
7
|
+
// #region Fields
|
|
8
|
+
_discovery;
|
|
9
|
+
_logger;
|
|
10
|
+
// #endregion
|
|
11
|
+
// #region Ctor
|
|
12
|
+
constructor() {
|
|
13
|
+
this._discovery = new SeedConfigDiscovery();
|
|
14
|
+
// Logger will be created with proper logLevel in execute method
|
|
15
|
+
this._logger = new SeedLogger();
|
|
16
|
+
}
|
|
17
|
+
// #endregion
|
|
18
|
+
// #region Methods
|
|
19
|
+
/**
|
|
20
|
+
* @description Discovers seed configs and merges runtime options.
|
|
21
|
+
* Config file `options` are the defaults, NX executor overrides take priority.
|
|
22
|
+
* This follows the Vite pattern: config file is primary, executor options override.
|
|
23
|
+
*/
|
|
24
|
+
async executeWithOverrides(rootPath, overrides) {
|
|
25
|
+
const composedConfig = await this._discovery.discover({
|
|
26
|
+
rootPath,
|
|
27
|
+
searchPaths: ['libs/**', 'apps/**'],
|
|
28
|
+
});
|
|
29
|
+
const configOptions = composedConfig.rootConfig.options ?? {};
|
|
30
|
+
const merged = {
|
|
31
|
+
drop: overrides.drop ?? configOptions.drop,
|
|
32
|
+
count: overrides.count ?? configOptions.count,
|
|
33
|
+
force: overrides.force ?? configOptions.force,
|
|
34
|
+
dryRun: overrides.dryRun ?? configOptions.dryRun,
|
|
35
|
+
seed: overrides.seed ?? configOptions.seed,
|
|
36
|
+
environment: overrides.environment ?? configOptions.environment,
|
|
37
|
+
};
|
|
38
|
+
return this._executeWithComposedConfig(composedConfig, merged);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description Runs seeding with explicit options (no config file merging).
|
|
42
|
+
*/
|
|
43
|
+
async execute(rootPath, options) {
|
|
44
|
+
const composedConfig = await this._discovery.discover({
|
|
45
|
+
rootPath,
|
|
46
|
+
searchPaths: ['libs/**', 'apps/**'],
|
|
47
|
+
});
|
|
48
|
+
return this._executeWithComposedConfig(composedConfig, options);
|
|
49
|
+
}
|
|
50
|
+
async _executeWithComposedConfig(composedConfig, options) {
|
|
51
|
+
const startTime = Date.now();
|
|
52
|
+
try {
|
|
53
|
+
// Create logger with logLevel from composed config
|
|
54
|
+
const logLevel = composedConfig.resolved.logLevel;
|
|
55
|
+
this._logger = new SeedLogger(logLevel);
|
|
56
|
+
this._logger.info('🌱 Starting seed orchestration...');
|
|
57
|
+
this._logger.info(`Found ${composedConfig.featureConfigs.length} feature configs`);
|
|
58
|
+
this._logger.info(`Execution order: ${composedConfig.resolved.executionOrder.join(' → ')}`);
|
|
59
|
+
// Initialize shared context
|
|
60
|
+
const context = await this.createContext(composedConfig, options);
|
|
61
|
+
// Execute seeds in order
|
|
62
|
+
const seedResults = [];
|
|
63
|
+
let totalItemsCreated = 0;
|
|
64
|
+
for (const seedDef of composedConfig.resolved.seeds) {
|
|
65
|
+
if (seedDef.enabled === false) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// Clear warnings for each new seed
|
|
69
|
+
context.warnings?.clear();
|
|
70
|
+
this._logger.startGroup(`Executing: ${seedDef.name}`);
|
|
71
|
+
try {
|
|
72
|
+
const seeder = seedDef.factory.create();
|
|
73
|
+
const seedContext = {
|
|
74
|
+
...context,
|
|
75
|
+
seedConfigPath: seedDef.configPath ?? context.seedConfigPath
|
|
76
|
+
};
|
|
77
|
+
const result = await seeder.seed(seedContext);
|
|
78
|
+
seedResults.push({
|
|
79
|
+
name: seedDef.name,
|
|
80
|
+
result
|
|
81
|
+
});
|
|
82
|
+
totalItemsCreated += result.itemsCreated;
|
|
83
|
+
if (result.success) {
|
|
84
|
+
this._logger.success(`${result.itemsCreated} items in ${result.duration}ms`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this._logger.error(`Failed with ${result.errors.length} errors`);
|
|
88
|
+
for (const error of result.errors) {
|
|
89
|
+
this._logger.error(error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const warning of result.warnings) {
|
|
93
|
+
this._logger.warn(warning);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const errorMsg = `Seed threw exception: ${error}` + (error instanceof Error && error.stack ? `\n${error.stack}` : '');
|
|
98
|
+
this._logger.error(errorMsg);
|
|
99
|
+
seedResults.push({
|
|
100
|
+
name: seedDef.name,
|
|
101
|
+
result: {
|
|
102
|
+
success: false,
|
|
103
|
+
itemsCreated: 0,
|
|
104
|
+
duration: 0,
|
|
105
|
+
errors: [errorMsg],
|
|
106
|
+
warnings: []
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
this._logger.endGroup();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const totalDuration = Date.now() - startTime;
|
|
115
|
+
const allSuccessful = seedResults.every((sr) => sr.result.success);
|
|
116
|
+
const allErrors = seedResults.flatMap((sr) => sr.result.errors);
|
|
117
|
+
if (allSuccessful) {
|
|
118
|
+
this._logger.info('🎉 Seeding completed successfully!');
|
|
119
|
+
this._logger.info(`📈 Total items created: ${totalItemsCreated}`);
|
|
120
|
+
this._logger.info(`⏱️ Total duration: ${totalDuration}ms`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this._logger.error('💥 Seeding completed with errors!');
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
success: allSuccessful,
|
|
127
|
+
totalItemsCreated: totalItemsCreated,
|
|
128
|
+
totalDuration: totalDuration,
|
|
129
|
+
seedResults: seedResults,
|
|
130
|
+
errors: allErrors
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const errorMsg = `Fatal error during seeding: ${error}`;
|
|
135
|
+
this._logger.error(errorMsg);
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
totalItemsCreated: 0,
|
|
139
|
+
totalDuration: Date.now() - startTime,
|
|
140
|
+
seedResults: [],
|
|
141
|
+
errors: [errorMsg]
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async createContext(composedConfig, options) {
|
|
146
|
+
// Import PrismaClient dynamically to avoid compile-time dependency
|
|
147
|
+
const { PrismaClient } = await import('@prisma/client');
|
|
148
|
+
const prisma = new PrismaClient();
|
|
149
|
+
// Handle drop option
|
|
150
|
+
if (options.drop) {
|
|
151
|
+
this._logger.info('🗑️ Dropping existing data...');
|
|
152
|
+
// Note: Individual seeders should handle their own cleanup
|
|
153
|
+
}
|
|
154
|
+
// Import AssetManager for asset handling
|
|
155
|
+
const { AssetManager } = await import('../assets/AssetManager.js');
|
|
156
|
+
// Check if any seed configuration has asset configuration
|
|
157
|
+
const firstAssetConfig = composedConfig.featureConfigs.find((config) => config.assets)?.assets;
|
|
158
|
+
// Create a default blob adapter (will be overridden per feature if needed)
|
|
159
|
+
const defaultBlobAdapter = createAdapter('empty');
|
|
160
|
+
// Create AssetManager with default adapter (will be reconfigured per feature)
|
|
161
|
+
const assetManager = new AssetManager(this._logger, {
|
|
162
|
+
assetsDir: firstAssetConfig?.assetsDir || '.seed/assets',
|
|
163
|
+
uploadToBlob: firstAssetConfig?.uploadToBlob ?? !options.dryRun,
|
|
164
|
+
blobAdapter: defaultBlobAdapter,
|
|
165
|
+
imageTransforms: firstAssetConfig?.imageTransforms
|
|
166
|
+
});
|
|
167
|
+
// Import EntityResolver, LocalizationToolkit, and WarningCollector for factory methods
|
|
168
|
+
const { EntityResolver } = await import('../resolvers/EntityResolver.js');
|
|
169
|
+
const { LocalizationToolkit } = await import('../utils/LocalizationToolkit.js');
|
|
170
|
+
const { WarningCollector } = await import('../utils/WarningCollector.js');
|
|
171
|
+
// Create warning collector
|
|
172
|
+
const warningCollector = new WarningCollector(this._logger);
|
|
173
|
+
// Create complete context with factory methods
|
|
174
|
+
const context = {
|
|
175
|
+
prisma,
|
|
176
|
+
options,
|
|
177
|
+
logger: this._logger,
|
|
178
|
+
random: new SeededRandom(options.seed),
|
|
179
|
+
assets: assetManager,
|
|
180
|
+
seedConfigPath: undefined,
|
|
181
|
+
warnings: warningCollector,
|
|
182
|
+
// Factory method for creating cached entity resolvers
|
|
183
|
+
entity(modelName, uniqueField) {
|
|
184
|
+
return new EntityResolver(modelName, uniqueField, ['id'], // Default: only select 'id' field
|
|
185
|
+
context);
|
|
186
|
+
},
|
|
187
|
+
// Alias for batch resolution (same implementation)
|
|
188
|
+
manyEntity(modelName, uniqueField) {
|
|
189
|
+
return new EntityResolver(modelName, uniqueField, ['id'], context);
|
|
190
|
+
},
|
|
191
|
+
// Localization helpers namespace (direct passthrough to LocalizationToolkit)
|
|
192
|
+
localize: {
|
|
193
|
+
resolvePrimary: LocalizationToolkit.resolvePrimary.bind(LocalizationToolkit),
|
|
194
|
+
mapValues: LocalizationToolkit.mapValues.bind(LocalizationToolkit),
|
|
195
|
+
createGroup: LocalizationToolkit.createGroup.bind(LocalizationToolkit),
|
|
196
|
+
updateGroup: LocalizationToolkit.updateGroup.bind(LocalizationToolkit),
|
|
197
|
+
createOrUpdateGroup: LocalizationToolkit.createOrUpdateGroup.bind(LocalizationToolkit)
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
// Process assets for each feature that has them
|
|
201
|
+
const featuresWithAssets = composedConfig.featureConfigs.filter((config) => config.assets?.files && config.configPath);
|
|
202
|
+
if (featuresWithAssets.length > 0) {
|
|
203
|
+
this._logger.info('🖼️ Processing configured assets...');
|
|
204
|
+
for (const featureConfig of featuresWithAssets) {
|
|
205
|
+
if (!featureConfig.assets || !featureConfig.configPath || !featureConfig.assets.files) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const assetConfig = featureConfig.assets;
|
|
209
|
+
// Create blob adapter for this specific feature
|
|
210
|
+
let blobAdapter = createAdapter('empty');
|
|
211
|
+
if (assetConfig.blobAdapter) {
|
|
212
|
+
const adapterType = assetConfig.blobAdapter.type;
|
|
213
|
+
if (adapterType === 'empty') {
|
|
214
|
+
blobAdapter = createAdapter('empty');
|
|
215
|
+
}
|
|
216
|
+
else if (adapterType === 'local' && assetConfig.blobAdapter.config) {
|
|
217
|
+
blobAdapter = createAdapter('local', {
|
|
218
|
+
keyPrefix: assetConfig.blobAdapter.config.keyPrefix,
|
|
219
|
+
baseDirectory: assetConfig.blobAdapter.config.baseDirectory || './uploads',
|
|
220
|
+
baseUrl: assetConfig.blobAdapter.config.baseUrl || 'http://localhost:3000/uploads'
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
else if (adapterType === 'vercel' && assetConfig.blobAdapter.config) {
|
|
224
|
+
const token = assetConfig.blobAdapter.config.token;
|
|
225
|
+
if (token) {
|
|
226
|
+
blobAdapter = createAdapter('vercel', {
|
|
227
|
+
token: token,
|
|
228
|
+
keyPrefix: assetConfig.blobAdapter.config.keyPrefix,
|
|
229
|
+
baseUrl: assetConfig.blobAdapter.config.baseUrl
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this._logger.warn(`Vercel blob adapter configured for ${featureConfig.name} but missing token - using empty adapter`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else if (adapterType === 'cloudflare-r2' && assetConfig.blobAdapter.config) {
|
|
237
|
+
const { accessKeyId, secretAccessKey, bucketName, accountId } = assetConfig.blobAdapter.config;
|
|
238
|
+
if (accessKeyId && secretAccessKey && bucketName && accountId) {
|
|
239
|
+
blobAdapter = createAdapter('cloudflare-r2', {
|
|
240
|
+
accessKeyId: accessKeyId,
|
|
241
|
+
secretAccessKey: secretAccessKey,
|
|
242
|
+
bucketName: bucketName,
|
|
243
|
+
accountId: accountId,
|
|
244
|
+
keyPrefix: assetConfig.blobAdapter.config.keyPrefix,
|
|
245
|
+
baseUrl: assetConfig.blobAdapter.config.publicBaseUrl
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
this._logger.warn(`Cloudflare R2 blob adapter configured for ${featureConfig.name} but missing required credentials - using empty adapter`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Reconfigure AssetManager with feature-specific adapter
|
|
254
|
+
assetManager.reconfigureBlobAdapter(blobAdapter);
|
|
255
|
+
// Process assets for this feature
|
|
256
|
+
await assetManager.processAssets(featureConfig.configPath, assetConfig.files);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return context;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=SeedOrchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SeedOrchestrator.js","sourceRoot":"","sources":["../../src/orchestration/SeedOrchestrator.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAMlB,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAexD,MAAM,OAAO,gBAAgB;IAEzB,iBAAiB;IAEA,UAAU,CAAsB;IACzC,OAAO,CAAc;IAE7B,aAAa;IAEb,eAAe;IAEf;QACI,IAAI,CAAC,UAAU,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC5C,gEA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AU,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;YAClF,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CAIJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@breadstone-infrastructure/prisma-seeds",
|
|
3
|
+
"description": "Prisma seeds",
|
|
4
|
+
"version": "0.0.231",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "andre.wehlert <awehlert@breadstone.de> (https://www.breadstone.de)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"url": "git+ssh://git@github.com/RueDeRennes/mosaik.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./index.js",
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"bin": "./bin/prisma-seeds.js",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ai-sdk/openai": "3.0.45",
|
|
16
|
+
"@breadstone-infrastructure/utilities": "0.0.231",
|
|
17
|
+
"@nx/vite": "22.5.4",
|
|
18
|
+
"@prisma/client": "6.19.2",
|
|
19
|
+
"ai": "6.0.127",
|
|
20
|
+
"axios": "1.13.6",
|
|
21
|
+
"glob": "13.0.6",
|
|
22
|
+
"sharp": "0.34.5",
|
|
23
|
+
"tslib": "2.8.1",
|
|
24
|
+
"vitest": "4.1.0",
|
|
25
|
+
"zod": "4.3.6"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ISeedContext } from '../config/ISeedContext.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generic entity resolver with built-in caching.
|
|
4
|
+
* Resolves entity IDs or full entities from unique keys with automatic cache management.
|
|
5
|
+
*
|
|
6
|
+
* @template TKey - Type of the lookup key (usually string)
|
|
7
|
+
* @template TResult - Type of the resolved result (ID or full entity)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // In seed mapper:
|
|
12
|
+
* const categoryId = await ctx.entity('exerciseCategory', 'key').resolve(data.categoryKey);
|
|
13
|
+
* const muscleIds = await ctx.manyEntity('muscleGroup', 'name').resolve(data.muscles);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class EntityResolver<TKey = string, TResult = string> {
|
|
17
|
+
private readonly _cache;
|
|
18
|
+
private readonly _modelName;
|
|
19
|
+
private readonly _uniqueField;
|
|
20
|
+
private readonly _selectFields;
|
|
21
|
+
private readonly _context;
|
|
22
|
+
constructor(modelName: string, uniqueField: string, selectFields: string[], context: ISeedContext);
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a single entity by key (cached).
|
|
25
|
+
*
|
|
26
|
+
* @param key - Unique key to look up
|
|
27
|
+
* @returns Resolved entity data or throws if not found
|
|
28
|
+
*/
|
|
29
|
+
resolve(key: TKey): Promise<TResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve multiple entities by keys (batched, cached).
|
|
32
|
+
*
|
|
33
|
+
* @param keys - Array of unique keys
|
|
34
|
+
* @returns Array of resolved entity data in same order
|
|
35
|
+
*/
|
|
36
|
+
resolveMany(keys: TKey[]): Promise<TResult[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Clear the internal cache (useful for testing or re-seeding scenarios).
|
|
39
|
+
*/
|
|
40
|
+
clearCache(): void;
|
|
41
|
+
private _performLookup;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=EntityResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityResolver.d.ts","sourceRoot":"","sources":["../../src/resolvers/EntityResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D;;;;;;;;;;;;;GAaG;AACH,qBAAa,cAAc,CAAC,IAAI,GAAG,MAAM,EAAE,OAAO,GAAG,MAAM;IAIvD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAW;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAOpC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EAAE,EACtB,OAAO,EAAE,YAAY;IAYzB;;;;;OAKG;IACU,OAAO,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBjD;;;;;OAKG;IACU,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAQ1D;;OAEG;IACI,UAAU,IAAI,IAAI;YAIX,cAAc;CAqC/B"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic entity resolver with built-in caching.
|
|
3
|
+
* Resolves entity IDs or full entities from unique keys with automatic cache management.
|
|
4
|
+
*
|
|
5
|
+
* @template TKey - Type of the lookup key (usually string)
|
|
6
|
+
* @template TResult - Type of the resolved result (ID or full entity)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // In seed mapper:
|
|
11
|
+
* const categoryId = await ctx.entity('exerciseCategory', 'key').resolve(data.categoryKey);
|
|
12
|
+
* const muscleIds = await ctx.manyEntity('muscleGroup', 'name').resolve(data.muscles);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class EntityResolver {
|
|
16
|
+
// #region Fields
|
|
17
|
+
_cache = new Map();
|
|
18
|
+
_modelName;
|
|
19
|
+
_uniqueField;
|
|
20
|
+
_selectFields;
|
|
21
|
+
_context;
|
|
22
|
+
// #endregion
|
|
23
|
+
// #region Ctor
|
|
24
|
+
constructor(modelName, uniqueField, selectFields, context) {
|
|
25
|
+
this._modelName = modelName;
|
|
26
|
+
this._uniqueField = uniqueField;
|
|
27
|
+
this._selectFields = selectFields;
|
|
28
|
+
this._context = context;
|
|
29
|
+
}
|
|
30
|
+
// #endregion
|
|
31
|
+
// #region Methods
|
|
32
|
+
/**
|
|
33
|
+
* Resolve a single entity by key (cached).
|
|
34
|
+
*
|
|
35
|
+
* @param key - Unique key to look up
|
|
36
|
+
* @returns Resolved entity data or throws if not found
|
|
37
|
+
*/
|
|
38
|
+
async resolve(key) {
|
|
39
|
+
if (!key) {
|
|
40
|
+
throw new Error(`Cannot resolve ${this._modelName}: key is null or undefined`);
|
|
41
|
+
}
|
|
42
|
+
// Return cached promise if available
|
|
43
|
+
const cached = this._cache.get(key);
|
|
44
|
+
if (cached) {
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
// Create new lookup promise and cache it immediately (prevents duplicate queries)
|
|
48
|
+
const promise = this._performLookup(key);
|
|
49
|
+
this._cache.set(key, promise);
|
|
50
|
+
return promise;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve multiple entities by keys (batched, cached).
|
|
54
|
+
*
|
|
55
|
+
* @param keys - Array of unique keys
|
|
56
|
+
* @returns Array of resolved entity data in same order
|
|
57
|
+
*/
|
|
58
|
+
async resolveMany(keys) {
|
|
59
|
+
if (!Array.isArray(keys) || keys.length === 0) {
|
|
60
|
+
throw new Error(`Cannot resolve ${this._modelName}: keys must be a non-empty array`);
|
|
61
|
+
}
|
|
62
|
+
return Promise.all(keys.map((key) => this.resolve(key)));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clear the internal cache (useful for testing or re-seeding scenarios).
|
|
66
|
+
*/
|
|
67
|
+
clearCache() {
|
|
68
|
+
this._cache.clear();
|
|
69
|
+
}
|
|
70
|
+
async _performLookup(key) {
|
|
71
|
+
// Build select projection dynamically
|
|
72
|
+
const select = this._selectFields.reduce((acc, field) => {
|
|
73
|
+
acc[field] = true;
|
|
74
|
+
return acc;
|
|
75
|
+
}, {});
|
|
76
|
+
// Access Prisma model dynamically via bracket notation
|
|
77
|
+
const model = this._context.prisma[this._modelName];
|
|
78
|
+
if (!model || typeof model.findFirst !== 'function') {
|
|
79
|
+
throw new Error(`Invalid Prisma model: ${this._modelName}`);
|
|
80
|
+
}
|
|
81
|
+
const result = await model.findFirst({
|
|
82
|
+
where: { [this._uniqueField]: key },
|
|
83
|
+
select
|
|
84
|
+
});
|
|
85
|
+
if (!result) {
|
|
86
|
+
throw new Error(`${this._modelName} not found with ${this._uniqueField}="${String(key)}"`);
|
|
87
|
+
}
|
|
88
|
+
// If only one field selected and it's 'id', return scalar; otherwise return full object
|
|
89
|
+
if (this._selectFields.length === 1 && this._selectFields[0] === 'id') {
|
|
90
|
+
return result.id;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=EntityResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityResolver.js","sourceRoot":"","sources":["../../src/resolvers/EntityResolver.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,cAAc;IAEvB,iBAAiB;IAEA,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC3C,UAAU,CAAS;IACnB,YAAY,CAAS;IACrB,aAAa,CAAW;IACxB,QAAQ,CAAe;IAExC,aAAa;IAEb,eAAe;IAEf,YACI,SAAiB,EACjB,WAAmB,EACnB,YAAsB,EACtB,OAAqB;QAErB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACI,KAAK,CAAC,OAAO,CAAC,GAAS;QAC1B,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,MAAM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,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC;YACjC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE;YACnC,MAAM;SACT,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACX,GAAG,IAAI,CAAC,UAAU,mBAAmB,IAAI,CAAC,YAAY,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,CAC5E,CAAC;QACN,CAAC;QAED,wFAAwF;QACxF,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACpE,OAAO,MAAM,CAAC,EAAa,CAAC;QAChC,CAAC;QAED,OAAO,MAAiB,CAAC;IAC7B,CAAC;CAIJ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ISeedContext } from '../config/ISeedContext.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options controlling how asset references are resolved within JSON seeds.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface IAssetReferenceOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Prefix used to detect asset references.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue "@asset:"
|
|
12
|
+
*/
|
|
13
|
+
readonly prefix?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to trim surrounding whitespace from asset references prior to evaluation.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue true
|
|
18
|
+
*/
|
|
19
|
+
readonly trim?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves asset references inside JSON seed payloads.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare class AssetReferenceResolver {
|
|
27
|
+
/**
|
|
28
|
+
* Default prefix that indicates an asset reference.
|
|
29
|
+
*/
|
|
30
|
+
static readonly DEFAULT_PREFIX: string;
|
|
31
|
+
private constructor();
|
|
32
|
+
/**
|
|
33
|
+
* Resolves a potential asset reference to a concrete asset URL.
|
|
34
|
+
*
|
|
35
|
+
* @param value The JSON value that may contain an asset reference
|
|
36
|
+
* @param context Seeder execution context
|
|
37
|
+
* @param options Optional resolution configuration
|
|
38
|
+
* @returns The resolved asset URL or the normalized value when no prefix is present
|
|
39
|
+
*/
|
|
40
|
+
static resolve(value: unknown, context: ISeedContext, options?: IAssetReferenceOptions): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a reusable resolver function with the provided options.
|
|
43
|
+
*
|
|
44
|
+
* @param options Optional resolution options
|
|
45
|
+
* @returns A resolver function suitable for mapper usage
|
|
46
|
+
*/
|
|
47
|
+
static createResolver(options?: IAssetReferenceOptions): (value: unknown, context: ISeedContext) => string | null;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=AssetReferenceResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetReferenceResolver.d.ts","sourceRoot":"","sources":["../../src/utils/AssetReferenceResolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAI9D;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IAInC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;CAI3B;AAED;;;;GAIG;AACH,qBAAa,sBAAsB;IAI/B;;OAEG;IACH,gBAAuB,cAAc,EAAE,MAAM,CAAa;IAM1D,OAAO;IAQP;;;;;;;OAOG;WACW,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,GAAG,IAAI;IA4B7G;;;;;OAKG;WACW,cAAc,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,KAAK,MAAM,GAAG,IAAI;CAQ3H"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// #region Imports
|
|
2
|
+
/**
|
|
3
|
+
* Resolves asset references inside JSON seed payloads.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class AssetReferenceResolver {
|
|
8
|
+
// #region Fields
|
|
9
|
+
/**
|
|
10
|
+
* Default prefix that indicates an asset reference.
|
|
11
|
+
*/
|
|
12
|
+
static DEFAULT_PREFIX = '@asset:';
|
|
13
|
+
// #endregion
|
|
14
|
+
// #region Ctor
|
|
15
|
+
constructor() {
|
|
16
|
+
// Utility class
|
|
17
|
+
}
|
|
18
|
+
// #endregion
|
|
19
|
+
// #region Methods
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a potential asset reference to a concrete asset URL.
|
|
22
|
+
*
|
|
23
|
+
* @param value The JSON value that may contain an asset reference
|
|
24
|
+
* @param context Seeder execution context
|
|
25
|
+
* @param options Optional resolution configuration
|
|
26
|
+
* @returns The resolved asset URL or the normalized value when no prefix is present
|
|
27
|
+
*/
|
|
28
|
+
static resolve(value, context, options) {
|
|
29
|
+
if (typeof value !== 'string') {
|
|
30
|
+
return value === undefined || value === null ? null : String(value);
|
|
31
|
+
}
|
|
32
|
+
const prefix = options?.prefix ?? AssetReferenceResolver.DEFAULT_PREFIX;
|
|
33
|
+
const shouldTrim = options?.trim ?? true;
|
|
34
|
+
const normalizedValue = shouldTrim ? value.trim() : value;
|
|
35
|
+
if (!normalizedValue.startsWith(prefix)) {
|
|
36
|
+
return normalizedValue;
|
|
37
|
+
}
|
|
38
|
+
const assetKey = normalizedValue.slice(prefix.length);
|
|
39
|
+
if (assetKey.length === 0) {
|
|
40
|
+
context.logger.warn('Encountered empty asset reference.');
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const assetUrl = context.assets.getAsset(assetKey);
|
|
44
|
+
if (!assetUrl) {
|
|
45
|
+
context.logger.warn(`Asset not found for key: ${assetKey}`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return assetUrl;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a reusable resolver function with the provided options.
|
|
52
|
+
*
|
|
53
|
+
* @param options Optional resolution options
|
|
54
|
+
* @returns A resolver function suitable for mapper usage
|
|
55
|
+
*/
|
|
56
|
+
static createResolver(options) {
|
|
57
|
+
return (value, context) => {
|
|
58
|
+
return AssetReferenceResolver.resolve(value, context, options);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=AssetReferenceResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetReferenceResolver.js","sourceRoot":"","sources":["../../src/utils/AssetReferenceResolver.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAiClB;;;;GAIG;AACH,MAAM,OAAO,sBAAsB;IAE/B,iBAAiB;IAEjB;;OAEG;IACI,MAAM,CAAU,cAAc,GAAW,SAAS,CAAC;IAE1D,aAAa;IAEb,eAAe;IAEf;QACI,gBAAgB;IACpB,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;;;OAOG;IACI,MAAM,CAAC,OAAO,CAAC,KAAc,EAAE,OAAqB,EAAE,OAAgC;QACzF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,MAAM,GAAW,OAAO,EAAE,MAAM,IAAI,sBAAsB,CAAC,cAAc,CAAC;QAChF,MAAM,UAAU,GAAY,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC;QAClD,MAAM,eAAe,GAAW,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAElE,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,OAAO,eAAe,CAAC;QAC3B,CAAC;QAED,MAAM,QAAQ,GAAW,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC9D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,GAAuB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACvE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;YAC5D,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAC,OAAgC;QACzD,OAAO,CAAC,KAAc,EAAE,OAAqB,EAAiB,EAAE;YAC5D,OAAO,sBAAsB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACnE,CAAC,CAAC;IACN,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ISeedContext } from '../config/ISeedContext.js';
|
|
2
|
+
/**
|
|
3
|
+
* Describes a resolver capable of translating string keys to entity identifiers.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface IEntityLookupResolver<TResult> {
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the entity identifier for the provided key.
|
|
10
|
+
*
|
|
11
|
+
* @param key Key identifying the entity
|
|
12
|
+
* @param context Seeder execution context
|
|
13
|
+
*/
|
|
14
|
+
resolve(key: string, context: ISeedContext): Promise<TResult>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Provides a caching layer for expensive lookup operations in JSON seed mappers.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare class EntityLookupCache<TResult> {
|
|
22
|
+
private readonly cache;
|
|
23
|
+
private readonly resolver;
|
|
24
|
+
constructor(resolver: IEntityLookupResolver<TResult>);
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a value for the provided key, using the cache when available.
|
|
27
|
+
*
|
|
28
|
+
* @param key Lookup key
|
|
29
|
+
* @param context Seeder execution context
|
|
30
|
+
* @returns Resolved value
|
|
31
|
+
*/
|
|
32
|
+
resolve(key: string, context: ISeedContext): Promise<TResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves multiple keys sequentially, preserving order.
|
|
35
|
+
*
|
|
36
|
+
* @param keys Lookup keys
|
|
37
|
+
* @param context Seeder execution context
|
|
38
|
+
* @returns Resolved values
|
|
39
|
+
*/
|
|
40
|
+
resolveMany(keys: readonly string[], context: ISeedContext): Promise<readonly TResult[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Clears the internal cache.
|
|
43
|
+
*/
|
|
44
|
+
clear(): void;
|
|
45
|
+
private static normalizeKey;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=EntityLookupCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityLookupCache.d.ts","sourceRoot":"","sources":["../../src/utils/EntityLookupCache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAI9D;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CAAC,OAAO;IAI1C;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAIjE;AAED;;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,OAAO;IAIlC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;gBAMvC,QAAQ,EAAE,qBAAqB,CAAC,OAAO,CAAC;IAS3D;;;;;;OAMG;IACU,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAY1E;;;;;;OAMG;IACU,WAAW,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,OAAO,EAAE,CAAC;IASrG;;OAEG;IACI,KAAK,IAAI,IAAI;IAIpB,OAAO,CAAC,MAAM,CAAC,YAAY;CAW9B"}
|