ai-database 2.1.1 → 2.3.0
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 +47 -1
- package/README.md +1063 -186
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/ai-promise-db.d.ts +52 -23
- package/dist/ai-promise-db.d.ts.map +1 -1
- package/dist/ai-promise-db.js +185 -164
- package/dist/ai-promise-db.js.map +1 -1
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +38 -30
- package/dist/authorization.js.map +1 -1
- package/dist/cascade-orchestrator.d.ts +404 -0
- package/dist/cascade-orchestrator.d.ts.map +1 -0
- package/dist/cascade-orchestrator.js +828 -0
- package/dist/cascade-orchestrator.js.map +1 -0
- package/dist/cascade-write-strategy.d.ts +584 -0
- package/dist/cascade-write-strategy.d.ts.map +1 -0
- package/dist/cascade-write-strategy.js +590 -0
- package/dist/cascade-write-strategy.js.map +1 -0
- package/dist/ch-adapter.d.ts +358 -0
- package/dist/ch-adapter.d.ts.map +1 -0
- package/dist/ch-adapter.js +929 -0
- package/dist/ch-adapter.js.map +1 -0
- package/dist/client/index.d.ts +42 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +43 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client.d.ts +266 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +81 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +64 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +52 -2
- package/dist/constants.js.map +1 -1
- package/dist/dataloader.d.ts +99 -0
- package/dist/dataloader.d.ts.map +1 -0
- package/dist/dataloader.js +225 -0
- package/dist/dataloader.js.map +1 -0
- package/dist/db-provider-port.d.ts +501 -0
- package/dist/db-provider-port.d.ts.map +1 -0
- package/dist/db-provider-port.js +113 -0
- package/dist/db-provider-port.js.map +1 -0
- package/dist/digital-objects-provider.d.ts +49 -0
- package/dist/digital-objects-provider.d.ts.map +1 -0
- package/dist/digital-objects-provider.js +55 -0
- package/dist/digital-objects-provider.js.map +1 -0
- package/dist/do-sqlite-adapter.d.ts +402 -0
- package/dist/do-sqlite-adapter.d.ts.map +1 -0
- package/dist/do-sqlite-adapter.js +745 -0
- package/dist/do-sqlite-adapter.js.map +1 -0
- package/dist/docs-rels/custom-types.d.ts +134 -0
- package/dist/docs-rels/custom-types.d.ts.map +1 -0
- package/dist/docs-rels/custom-types.js +70 -0
- package/dist/docs-rels/custom-types.js.map +1 -0
- package/dist/docs-rels/index.d.ts +16 -0
- package/dist/docs-rels/index.d.ts.map +1 -0
- package/dist/docs-rels/index.js +16 -0
- package/dist/docs-rels/index.js.map +1 -0
- package/dist/docs-rels/migrations/index.d.ts +30 -0
- package/dist/docs-rels/migrations/index.d.ts.map +1 -0
- package/dist/docs-rels/migrations/index.js +128 -0
- package/dist/docs-rels/migrations/index.js.map +1 -0
- package/dist/docs-rels/schema.d.ts +2961 -0
- package/dist/docs-rels/schema.d.ts.map +1 -0
- package/dist/docs-rels/schema.js +244 -0
- package/dist/docs-rels/schema.js.map +1 -0
- package/dist/durable-clickhouse.d.ts.map +1 -1
- package/dist/durable-clickhouse.js +16 -13
- package/dist/durable-clickhouse.js.map +1 -1
- package/dist/durable-promise.d.ts.map +1 -1
- package/dist/durable-promise.js +34 -15
- package/dist/durable-promise.js.map +1 -1
- package/dist/errors.d.ts +127 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +210 -0
- package/dist/errors.js.map +1 -0
- package/dist/eventbridge.d.ts +117 -0
- package/dist/eventbridge.d.ts.map +1 -0
- package/dist/eventbridge.js +238 -0
- package/dist/eventbridge.js.map +1 -0
- package/dist/events.d.ts +2 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -1
- package/dist/events.js.map +1 -1
- package/dist/execution-queue.d.ts.map +1 -1
- package/dist/execution-queue.js +4 -5
- package/dist/execution-queue.js.map +1 -1
- package/dist/index.d.ts +37 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -6
- package/dist/index.js.map +1 -1
- package/dist/linguistic.d.ts +3 -108
- package/dist/linguistic.d.ts.map +1 -1
- package/dist/linguistic.js +3 -372
- package/dist/linguistic.js.map +1 -1
- package/dist/logger.d.ts +132 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +137 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory-provider.d.ts +129 -0
- package/dist/memory-provider.d.ts.map +1 -1
- package/dist/memory-provider.js +592 -257
- package/dist/memory-provider.js.map +1 -1
- package/dist/pg-adapter.d.ts +424 -0
- package/dist/pg-adapter.d.ts.map +1 -0
- package/dist/pg-adapter.js +921 -0
- package/dist/pg-adapter.js.map +1 -0
- package/dist/pipelines-iceberg-emitter.d.ts +327 -0
- package/dist/pipelines-iceberg-emitter.d.ts.map +1 -0
- package/dist/pipelines-iceberg-emitter.js +351 -0
- package/dist/pipelines-iceberg-emitter.js.map +1 -0
- package/dist/provider-capabilities.d.ts +146 -0
- package/dist/provider-capabilities.d.ts.map +1 -0
- package/dist/provider-capabilities.js +214 -0
- package/dist/provider-capabilities.js.map +1 -0
- package/dist/rdb-provider-adapter.d.ts +195 -0
- package/dist/rdb-provider-adapter.d.ts.map +1 -0
- package/dist/rdb-provider-adapter.js +291 -0
- package/dist/rdb-provider-adapter.js.map +1 -0
- package/dist/schema/cascade.d.ts +49 -10
- package/dist/schema/cascade.d.ts.map +1 -1
- package/dist/schema/cascade.js +491 -273
- package/dist/schema/cascade.js.map +1 -1
- package/dist/schema/definition-caches.d.ts +24 -0
- package/dist/schema/definition-caches.d.ts.map +1 -0
- package/dist/schema/definition-caches.js +26 -0
- package/dist/schema/definition-caches.js.map +1 -0
- package/dist/schema/dependency-graph.d.ts +45 -0
- package/dist/schema/dependency-graph.d.ts.map +1 -0
- package/dist/schema/dependency-graph.js +47 -0
- package/dist/schema/dependency-graph.js.map +1 -0
- package/dist/schema/diff.d.ts +103 -0
- package/dist/schema/diff.d.ts.map +1 -0
- package/dist/schema/diff.js +329 -0
- package/dist/schema/diff.js.map +1 -0
- package/dist/schema/entity-operations.d.ts +99 -0
- package/dist/schema/entity-operations.d.ts.map +1 -0
- package/dist/schema/entity-operations.js +818 -0
- package/dist/schema/entity-operations.js.map +1 -0
- package/dist/schema/generation-context.d.ts +202 -0
- package/dist/schema/generation-context.d.ts.map +1 -0
- package/dist/schema/generation-context.js +393 -0
- package/dist/schema/generation-context.js.map +1 -0
- package/dist/schema/index.d.ts +32 -34
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +462 -519
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/migration.d.ts +205 -0
- package/dist/schema/migration.d.ts.map +1 -0
- package/dist/schema/migration.js +327 -0
- package/dist/schema/migration.js.map +1 -0
- package/dist/schema/nl-query-generator.d.ts +68 -0
- package/dist/schema/nl-query-generator.d.ts.map +1 -0
- package/dist/schema/nl-query-generator.js +362 -0
- package/dist/schema/nl-query-generator.js.map +1 -0
- package/dist/schema/nl-query.d.ts +65 -0
- package/dist/schema/nl-query.d.ts.map +1 -0
- package/dist/schema/nl-query.js +178 -0
- package/dist/schema/nl-query.js.map +1 -0
- package/dist/schema/parse.d.ts.map +1 -1
- package/dist/schema/parse.js +152 -89
- package/dist/schema/parse.js.map +1 -1
- package/dist/schema/provider.d.ts +38 -0
- package/dist/schema/provider.d.ts.map +1 -1
- package/dist/schema/provider.js +15 -7
- package/dist/schema/provider.js.map +1 -1
- package/dist/schema/resolve.d.ts +46 -5
- package/dist/schema/resolve.d.ts.map +1 -1
- package/dist/schema/resolve.js +334 -117
- package/dist/schema/resolve.js.map +1 -1
- package/dist/schema/search-utils.d.ts +76 -0
- package/dist/schema/search-utils.d.ts.map +1 -0
- package/dist/schema/search-utils.js +86 -0
- package/dist/schema/search-utils.js.map +1 -0
- package/dist/schema/seed.d.ts +53 -0
- package/dist/schema/seed.d.ts.map +1 -0
- package/dist/schema/seed.js +94 -0
- package/dist/schema/seed.js.map +1 -0
- package/dist/schema/semantic.d.ts +11 -0
- package/dist/schema/semantic.d.ts.map +1 -1
- package/dist/schema/semantic.js +262 -68
- package/dist/schema/semantic.js.map +1 -1
- package/dist/schema/sub-apis.d.ts +52 -0
- package/dist/schema/sub-apis.d.ts.map +1 -0
- package/dist/schema/sub-apis.js +216 -0
- package/dist/schema/sub-apis.js.map +1 -0
- package/dist/schema/system-entities.d.ts +42 -0
- package/dist/schema/system-entities.d.ts.map +1 -0
- package/dist/schema/system-entities.js +101 -0
- package/dist/schema/system-entities.js.map +1 -0
- package/dist/schema/types.d.ts +91 -9
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/union-fallback.d.ts +219 -0
- package/dist/schema/union-fallback.d.ts.map +1 -0
- package/dist/schema/union-fallback.js +331 -0
- package/dist/schema/union-fallback.js.map +1 -0
- package/dist/schema/value-generators/ai.d.ts +54 -0
- package/dist/schema/value-generators/ai.d.ts.map +1 -0
- package/dist/schema/value-generators/ai.js +136 -0
- package/dist/schema/value-generators/ai.js.map +1 -0
- package/dist/schema/value-generators/index.d.ts +126 -0
- package/dist/schema/value-generators/index.d.ts.map +1 -0
- package/dist/schema/value-generators/index.js +219 -0
- package/dist/schema/value-generators/index.js.map +1 -0
- package/dist/schema/value-generators/placeholder.d.ts +52 -0
- package/dist/schema/value-generators/placeholder.d.ts.map +1 -0
- package/dist/schema/value-generators/placeholder.js +328 -0
- package/dist/schema/value-generators/placeholder.js.map +1 -0
- package/dist/schema/value-generators/types.d.ts +116 -0
- package/dist/schema/value-generators/types.d.ts.map +1 -0
- package/dist/schema/value-generators/types.js +11 -0
- package/dist/schema/value-generators/types.js.map +1 -0
- package/dist/schema/verb-derivation.d.ts +167 -0
- package/dist/schema/verb-derivation.d.ts.map +1 -0
- package/dist/schema/verb-derivation.js +281 -0
- package/dist/schema/verb-derivation.js.map +1 -0
- package/dist/schema/version.d.ts +111 -0
- package/dist/schema/version.d.ts.map +1 -0
- package/dist/schema/version.js +190 -0
- package/dist/schema/version.js.map +1 -0
- package/dist/schema.d.ts +1095 -23
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2854 -38
- package/dist/schema.js.map +1 -1
- package/dist/semantic-vectors.d.ts +39 -0
- package/dist/semantic-vectors.d.ts.map +1 -0
- package/dist/semantic-vectors.js +334 -0
- package/dist/semantic-vectors.js.map +1 -0
- package/dist/semantic.d.ts +29 -1
- package/dist/semantic.d.ts.map +1 -1
- package/dist/semantic.js +26 -16
- package/dist/semantic.js.map +1 -1
- package/dist/telemetry.d.ts +128 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +305 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/tests.d.ts.map +1 -1
- package/dist/tests.js +30 -22
- package/dist/tests.js.map +1 -1
- package/dist/type-guards.d.ts +212 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +318 -0
- package/dist/type-guards.js.map +1 -0
- package/dist/types.d.ts +33 -245
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +62 -72
- package/dist/types.js.map +1 -1
- package/dist/validation.d.ts +165 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +639 -0
- package/dist/validation.js.map +1 -0
- package/dist/worker/db-provider.d.ts +168 -0
- package/dist/worker/db-provider.d.ts.map +1 -0
- package/dist/worker/db-provider.js +277 -0
- package/dist/worker/db-provider.js.map +1 -0
- package/dist/worker/index.d.ts +35 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +37 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker.d.ts +779 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +2786 -0
- package/dist/worker.js.map +1 -0
- package/package.json +38 -8
- package/src/docs-rels/migrations/0001-init.sql +125 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AIValueGenerator Implementation
|
|
3
|
+
*
|
|
4
|
+
* Generates values using AI/LLM integration for production use.
|
|
5
|
+
* Supports context-aware generation with parent chain and array context.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { PlaceholderValueGenerator } from './placeholder.js';
|
|
10
|
+
/**
|
|
11
|
+
* AIValueGenerator
|
|
12
|
+
*
|
|
13
|
+
* Generates values using an AI function for production use.
|
|
14
|
+
* Builds rich context from parent chain, previous generations, and array context.
|
|
15
|
+
*/
|
|
16
|
+
export class AIValueGenerator {
|
|
17
|
+
aiFunction;
|
|
18
|
+
model;
|
|
19
|
+
maxTokens;
|
|
20
|
+
temperature;
|
|
21
|
+
fallbackToPlaceholder;
|
|
22
|
+
placeholderGenerator;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.aiFunction = config.aiFunction;
|
|
25
|
+
if (config.model !== undefined)
|
|
26
|
+
this.model = config.model;
|
|
27
|
+
if (config.maxTokens !== undefined)
|
|
28
|
+
this.maxTokens = config.maxTokens;
|
|
29
|
+
if (config.temperature !== undefined)
|
|
30
|
+
this.temperature = config.temperature;
|
|
31
|
+
this.fallbackToPlaceholder = config.fallbackToPlaceholder ?? false;
|
|
32
|
+
this.placeholderGenerator = new PlaceholderValueGenerator();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate a value using AI
|
|
36
|
+
*
|
|
37
|
+
* @param request - The generation request
|
|
38
|
+
* @returns Promise resolving to the generated value with metadata
|
|
39
|
+
*/
|
|
40
|
+
async generate(request) {
|
|
41
|
+
try {
|
|
42
|
+
const prompt = this.buildPrompt(request);
|
|
43
|
+
const response = await this.aiFunction(prompt);
|
|
44
|
+
const metadata = {
|
|
45
|
+
source: 'ai',
|
|
46
|
+
};
|
|
47
|
+
if (this.model !== undefined)
|
|
48
|
+
metadata.model = this.model;
|
|
49
|
+
if (response.usage?.tokens !== undefined)
|
|
50
|
+
metadata.tokens = response.usage.tokens;
|
|
51
|
+
return {
|
|
52
|
+
value: response.text,
|
|
53
|
+
metadata,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (this.fallbackToPlaceholder) {
|
|
58
|
+
const placeholderResult = await this.placeholderGenerator.generate(request);
|
|
59
|
+
return {
|
|
60
|
+
value: placeholderResult.value,
|
|
61
|
+
metadata: {
|
|
62
|
+
source: 'placeholder',
|
|
63
|
+
fallback: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a prompt from the generation request
|
|
72
|
+
*
|
|
73
|
+
* Combines field info, context, hints, and generation context
|
|
74
|
+
* into a comprehensive prompt for the AI.
|
|
75
|
+
*/
|
|
76
|
+
buildPrompt(request) {
|
|
77
|
+
const parts = [];
|
|
78
|
+
// Add field and type context
|
|
79
|
+
parts.push(`Generate a value for field "${request.fieldName}" on type "${request.type}".`);
|
|
80
|
+
// Add full context if available
|
|
81
|
+
if (request.fullContext) {
|
|
82
|
+
parts.push(`Context: ${request.fullContext}`);
|
|
83
|
+
}
|
|
84
|
+
// Add hint if available
|
|
85
|
+
if (request.hint) {
|
|
86
|
+
parts.push(`Hint: ${request.hint}`);
|
|
87
|
+
}
|
|
88
|
+
// Add parent data context
|
|
89
|
+
if (request.parentData && Object.keys(request.parentData).length > 0) {
|
|
90
|
+
const parentEntries = Object.entries(request.parentData)
|
|
91
|
+
.filter(([key, value]) => !key.startsWith('$') && !key.startsWith('_') && typeof value === 'string')
|
|
92
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
93
|
+
.join(', ');
|
|
94
|
+
if (parentEntries) {
|
|
95
|
+
parts.push(`Parent data: ${parentEntries}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Add generation context if available
|
|
99
|
+
const genCtx = request.generationContext;
|
|
100
|
+
if (genCtx) {
|
|
101
|
+
// Add parent chain context
|
|
102
|
+
if (genCtx.parentChain && genCtx.parentChain.length > 0) {
|
|
103
|
+
const chainInfo = genCtx.parentChain
|
|
104
|
+
.map((entity) => {
|
|
105
|
+
const name = entity['name'] || entity['title'] || entity.$id;
|
|
106
|
+
return `${entity.$type}: ${name}`;
|
|
107
|
+
})
|
|
108
|
+
.join(' > ');
|
|
109
|
+
parts.push(`Parent chain: ${chainInfo}`);
|
|
110
|
+
}
|
|
111
|
+
// Add previously generated entities
|
|
112
|
+
if (genCtx.previouslyGenerated && genCtx.previouslyGenerated.length > 0) {
|
|
113
|
+
const prevInfo = genCtx.previouslyGenerated
|
|
114
|
+
.map((entity) => {
|
|
115
|
+
const name = entity['name'] || entity['title'] || entity.$id;
|
|
116
|
+
return `${entity.$type}: ${name}`;
|
|
117
|
+
})
|
|
118
|
+
.join(', ');
|
|
119
|
+
parts.push(`Previously generated: ${prevInfo}`);
|
|
120
|
+
}
|
|
121
|
+
// Add array context
|
|
122
|
+
if (genCtx.arrayContext) {
|
|
123
|
+
const { fieldName, previousItems, index } = genCtx.arrayContext;
|
|
124
|
+
parts.push(`Array field: ${fieldName}, generating item ${index + 1}`);
|
|
125
|
+
if (previousItems.length > 0) {
|
|
126
|
+
const prevItemsInfo = previousItems
|
|
127
|
+
.map((item) => item['name'] || item['title'] || item.$id)
|
|
128
|
+
.join(', ');
|
|
129
|
+
parts.push(`Previous items: ${prevItemsInfo}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return parts.join('\n');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.js","sourceRoot":"","sources":["../../../src/schema/value-generators/ai.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAkB5D;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACnB,UA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,IAAI,CAAC,CAAA;gBACb,KAAK,CAAC,IAAI,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAA;YACjD,CAAC;YAED,oBAAoB;YACpB,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;gBACxB,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,YAAY,CAAA;gBAC/D,KAAK,CAAC,IAAI,CAAC,gBAAgB,SAAS,qBAAqB,KAAK,GAAG,CAAC,EAAE,CAAC,CAAA;gBACrE,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC7B,MAAM,aAAa,GAAG,aAAa;yBAChC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC;yBACxD,IAAI,CAAC,IAAI,CAAC,CAAA;oBACb,KAAK,CAAC,IAAI,CAAC,mBAAmB,aAAa,EAAE,CAAC,CAAA;gBAChD,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ValueGenerator Module
|
|
3
|
+
*
|
|
4
|
+
* Strategy pattern for value generation during entity creation.
|
|
5
|
+
* Supports both placeholder (deterministic test fixtures) and
|
|
6
|
+
* AI-powered (production) generation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Use placeholder generator for testing
|
|
11
|
+
* const generator = createValueGenerator({ type: 'placeholder' })
|
|
12
|
+
* const result = await generator.generate({
|
|
13
|
+
* fieldName: 'name',
|
|
14
|
+
* type: 'Person',
|
|
15
|
+
* fullContext: 'tech entrepreneur startup',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Configure global generator for AI in production
|
|
19
|
+
* configureValueGenerator({
|
|
20
|
+
* type: 'ai',
|
|
21
|
+
* aiFunction: async (prompt) => ({ text: await callAI(prompt) }),
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
export type { GenerationRequest, GenerationResult, GenerationMetadata, ValueGenerator, ValueGeneratorConfig, AIFunction, ArrayContext, GenerationContextData, } from './types.js';
|
|
28
|
+
export { PlaceholderValueGenerator } from './placeholder.js';
|
|
29
|
+
export { AIValueGenerator } from './ai.js';
|
|
30
|
+
export type { AIValueGeneratorConfig } from './ai.js';
|
|
31
|
+
import type { ValueGenerator, ValueGeneratorConfig } from './types.js';
|
|
32
|
+
/**
|
|
33
|
+
* Create a ValueGenerator based on configuration
|
|
34
|
+
*
|
|
35
|
+
* @param config - Generator configuration
|
|
36
|
+
* @returns A new ValueGenerator instance
|
|
37
|
+
* @throws Error if AI type is specified without aiFunction
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Create placeholder generator (default)
|
|
42
|
+
* const placeholderGen = createValueGenerator()
|
|
43
|
+
*
|
|
44
|
+
* // Create placeholder generator explicitly
|
|
45
|
+
* const placeholderGen = createValueGenerator({ type: 'placeholder' })
|
|
46
|
+
*
|
|
47
|
+
* // Create AI generator
|
|
48
|
+
* const aiGen = createValueGenerator({
|
|
49
|
+
* type: 'ai',
|
|
50
|
+
* aiFunction: async (prompt) => ({ text: 'AI response' }),
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function createValueGenerator(config?: ValueGeneratorConfig): ValueGenerator;
|
|
55
|
+
/**
|
|
56
|
+
* Configure the global default value generator
|
|
57
|
+
*
|
|
58
|
+
* Call this at application startup to set the default generator
|
|
59
|
+
* that will be used throughout the application.
|
|
60
|
+
*
|
|
61
|
+
* @param config - Generator configuration
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Use placeholder for testing
|
|
66
|
+
* configureValueGenerator({ type: 'placeholder' })
|
|
67
|
+
*
|
|
68
|
+
* // Use AI for production
|
|
69
|
+
* configureValueGenerator({
|
|
70
|
+
* type: 'ai',
|
|
71
|
+
* aiFunction: myAIFunction,
|
|
72
|
+
* model: 'claude-3',
|
|
73
|
+
* fallbackToPlaceholder: true,
|
|
74
|
+
* })
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function configureValueGenerator(config: ValueGeneratorConfig): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get the current global value generator
|
|
80
|
+
*
|
|
81
|
+
* Returns the configured generator instance, creating one if needed.
|
|
82
|
+
* Use this to get the generator configured via configureValueGenerator.
|
|
83
|
+
*
|
|
84
|
+
* @returns The current ValueGenerator instance
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const generator = getValueGenerator()
|
|
89
|
+
* const result = await generator.generate({
|
|
90
|
+
* fieldName: 'description',
|
|
91
|
+
* type: 'Product',
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function getValueGenerator(): ValueGenerator;
|
|
96
|
+
/**
|
|
97
|
+
* Generate a context-aware value for a field
|
|
98
|
+
*
|
|
99
|
+
* This is a convenience function that uses the global generator.
|
|
100
|
+
* Equivalent to calling `getValueGenerator().generate(request)`.
|
|
101
|
+
*
|
|
102
|
+
* @deprecated Use `getValueGenerator().generate()` instead
|
|
103
|
+
*
|
|
104
|
+
* @param fieldName - The name of the field being generated
|
|
105
|
+
* @param type - The entity type name
|
|
106
|
+
* @param fullContext - Combined context string
|
|
107
|
+
* @param hint - Optional hint text for guiding generation
|
|
108
|
+
* @param parentData - Parent entity data for context inheritance
|
|
109
|
+
* @returns A generated string value
|
|
110
|
+
*/
|
|
111
|
+
export declare function generateContextAwareValue(fieldName: string, type: string, fullContext: string, hint: string | undefined, parentData?: Record<string, unknown>): Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Synchronous wrapper for generateContextAwareValue
|
|
114
|
+
*
|
|
115
|
+
* Uses the PlaceholderValueGenerator directly for synchronous calls.
|
|
116
|
+
* This maintains backward compatibility with existing cascade.ts code.
|
|
117
|
+
*
|
|
118
|
+
* @param fieldName - The name of the field being generated
|
|
119
|
+
* @param type - The entity type name
|
|
120
|
+
* @param fullContext - Combined context string
|
|
121
|
+
* @param hint - Optional hint text for guiding generation
|
|
122
|
+
* @param parentData - Parent entity data for context inheritance
|
|
123
|
+
* @returns A generated string value
|
|
124
|
+
*/
|
|
125
|
+
export declare function generateContextAwareValueSync(fieldName: string, type: string, fullContext: string, hint: string | undefined, parentData?: Record<string, unknown>): string;
|
|
126
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/schema/value-generators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,qBAAqB,GACtB,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AActE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,oBAAyB,GAAG,cAAc,CAmBtF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAG1E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvC,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvC,MAAM,CA8CR"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ValueGenerator Module
|
|
3
|
+
*
|
|
4
|
+
* Strategy pattern for value generation during entity creation.
|
|
5
|
+
* Supports both placeholder (deterministic test fixtures) and
|
|
6
|
+
* AI-powered (production) generation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Use placeholder generator for testing
|
|
11
|
+
* const generator = createValueGenerator({ type: 'placeholder' })
|
|
12
|
+
* const result = await generator.generate({
|
|
13
|
+
* fieldName: 'name',
|
|
14
|
+
* type: 'Person',
|
|
15
|
+
* fullContext: 'tech entrepreneur startup',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Configure global generator for AI in production
|
|
19
|
+
* configureValueGenerator({
|
|
20
|
+
* type: 'ai',
|
|
21
|
+
* aiFunction: async (prompt) => ({ text: await callAI(prompt) }),
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
// Re-export implementations
|
|
28
|
+
export { PlaceholderValueGenerator } from './placeholder.js';
|
|
29
|
+
export { AIValueGenerator } from './ai.js';
|
|
30
|
+
import { PlaceholderValueGenerator } from './placeholder.js';
|
|
31
|
+
import { AIValueGenerator } from './ai.js';
|
|
32
|
+
// =============================================================================
|
|
33
|
+
// Global Generator Configuration
|
|
34
|
+
// =============================================================================
|
|
35
|
+
/** Current global generator instance */
|
|
36
|
+
let currentGenerator = null;
|
|
37
|
+
/** Current configuration */
|
|
38
|
+
let currentConfig = { type: 'placeholder' };
|
|
39
|
+
/**
|
|
40
|
+
* Create a ValueGenerator based on configuration
|
|
41
|
+
*
|
|
42
|
+
* @param config - Generator configuration
|
|
43
|
+
* @returns A new ValueGenerator instance
|
|
44
|
+
* @throws Error if AI type is specified without aiFunction
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Create placeholder generator (default)
|
|
49
|
+
* const placeholderGen = createValueGenerator()
|
|
50
|
+
*
|
|
51
|
+
* // Create placeholder generator explicitly
|
|
52
|
+
* const placeholderGen = createValueGenerator({ type: 'placeholder' })
|
|
53
|
+
*
|
|
54
|
+
* // Create AI generator
|
|
55
|
+
* const aiGen = createValueGenerator({
|
|
56
|
+
* type: 'ai',
|
|
57
|
+
* aiFunction: async (prompt) => ({ text: 'AI response' }),
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function createValueGenerator(config = {}) {
|
|
62
|
+
const type = config.type ?? 'placeholder';
|
|
63
|
+
if (type === 'ai') {
|
|
64
|
+
if (!config.aiFunction) {
|
|
65
|
+
throw new Error('aiFunction is required when creating an AI value generator');
|
|
66
|
+
}
|
|
67
|
+
const aiConfig = {
|
|
68
|
+
aiFunction: config.aiFunction,
|
|
69
|
+
};
|
|
70
|
+
if (config.model !== undefined)
|
|
71
|
+
aiConfig.model = config.model;
|
|
72
|
+
if (config.maxTokens !== undefined)
|
|
73
|
+
aiConfig.maxTokens = config.maxTokens;
|
|
74
|
+
if (config.temperature !== undefined)
|
|
75
|
+
aiConfig.temperature = config.temperature;
|
|
76
|
+
if (config.fallbackToPlaceholder !== undefined)
|
|
77
|
+
aiConfig.fallbackToPlaceholder = config.fallbackToPlaceholder;
|
|
78
|
+
return new AIValueGenerator(aiConfig);
|
|
79
|
+
}
|
|
80
|
+
return new PlaceholderValueGenerator();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Configure the global default value generator
|
|
84
|
+
*
|
|
85
|
+
* Call this at application startup to set the default generator
|
|
86
|
+
* that will be used throughout the application.
|
|
87
|
+
*
|
|
88
|
+
* @param config - Generator configuration
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Use placeholder for testing
|
|
93
|
+
* configureValueGenerator({ type: 'placeholder' })
|
|
94
|
+
*
|
|
95
|
+
* // Use AI for production
|
|
96
|
+
* configureValueGenerator({
|
|
97
|
+
* type: 'ai',
|
|
98
|
+
* aiFunction: myAIFunction,
|
|
99
|
+
* model: 'claude-3',
|
|
100
|
+
* fallbackToPlaceholder: true,
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export function configureValueGenerator(config) {
|
|
105
|
+
currentConfig = { ...config };
|
|
106
|
+
currentGenerator = null; // Reset so next getValueGenerator creates a new instance
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the current global value generator
|
|
110
|
+
*
|
|
111
|
+
* Returns the configured generator instance, creating one if needed.
|
|
112
|
+
* Use this to get the generator configured via configureValueGenerator.
|
|
113
|
+
*
|
|
114
|
+
* @returns The current ValueGenerator instance
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const generator = getValueGenerator()
|
|
119
|
+
* const result = await generator.generate({
|
|
120
|
+
* fieldName: 'description',
|
|
121
|
+
* type: 'Product',
|
|
122
|
+
* })
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export function getValueGenerator() {
|
|
126
|
+
if (!currentGenerator) {
|
|
127
|
+
currentGenerator = createValueGenerator(currentConfig);
|
|
128
|
+
}
|
|
129
|
+
return currentGenerator;
|
|
130
|
+
}
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Legacy Compatibility
|
|
133
|
+
// =============================================================================
|
|
134
|
+
/**
|
|
135
|
+
* Generate a context-aware value for a field
|
|
136
|
+
*
|
|
137
|
+
* This is a convenience function that uses the global generator.
|
|
138
|
+
* Equivalent to calling `getValueGenerator().generate(request)`.
|
|
139
|
+
*
|
|
140
|
+
* @deprecated Use `getValueGenerator().generate()` instead
|
|
141
|
+
*
|
|
142
|
+
* @param fieldName - The name of the field being generated
|
|
143
|
+
* @param type - The entity type name
|
|
144
|
+
* @param fullContext - Combined context string
|
|
145
|
+
* @param hint - Optional hint text for guiding generation
|
|
146
|
+
* @param parentData - Parent entity data for context inheritance
|
|
147
|
+
* @returns A generated string value
|
|
148
|
+
*/
|
|
149
|
+
export async function generateContextAwareValue(fieldName, type, fullContext, hint, parentData = {}) {
|
|
150
|
+
const generator = getValueGenerator();
|
|
151
|
+
const request = {
|
|
152
|
+
fieldName,
|
|
153
|
+
type,
|
|
154
|
+
fullContext,
|
|
155
|
+
parentData,
|
|
156
|
+
};
|
|
157
|
+
if (hint !== undefined)
|
|
158
|
+
request.hint = hint;
|
|
159
|
+
const result = await generator.generate(request);
|
|
160
|
+
return result.value;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Synchronous wrapper for generateContextAwareValue
|
|
164
|
+
*
|
|
165
|
+
* Uses the PlaceholderValueGenerator directly for synchronous calls.
|
|
166
|
+
* This maintains backward compatibility with existing cascade.ts code.
|
|
167
|
+
*
|
|
168
|
+
* @param fieldName - The name of the field being generated
|
|
169
|
+
* @param type - The entity type name
|
|
170
|
+
* @param fullContext - Combined context string
|
|
171
|
+
* @param hint - Optional hint text for guiding generation
|
|
172
|
+
* @param parentData - Parent entity data for context inheritance
|
|
173
|
+
* @returns A generated string value
|
|
174
|
+
*/
|
|
175
|
+
export function generateContextAwareValueSync(fieldName, type, fullContext, hint, parentData = {}) {
|
|
176
|
+
// Use placeholder generator directly for sync calls
|
|
177
|
+
const generator = new PlaceholderValueGenerator();
|
|
178
|
+
// Access the private generateValue method via the generate interface
|
|
179
|
+
// Since we know PlaceholderValueGenerator.generate is sync-compatible
|
|
180
|
+
const request = {
|
|
181
|
+
fieldName,
|
|
182
|
+
type,
|
|
183
|
+
fullContext,
|
|
184
|
+
parentData,
|
|
185
|
+
};
|
|
186
|
+
if (hint !== undefined)
|
|
187
|
+
request.hint = hint;
|
|
188
|
+
// We can safely synchronously return since PlaceholderValueGenerator
|
|
189
|
+
// doesn't actually do any async work in its current implementation
|
|
190
|
+
let result = '';
|
|
191
|
+
void generator.generate(request).then((r) => {
|
|
192
|
+
result = r.value;
|
|
193
|
+
});
|
|
194
|
+
// For true sync behavior, we need to inline the logic
|
|
195
|
+
// This duplicates the logic but maintains backward compatibility
|
|
196
|
+
const value = parentData[fieldName];
|
|
197
|
+
if (typeof value === 'string' && value) {
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
if (!fullContext || fullContext.trim() === '') {
|
|
201
|
+
return `Generated ${fieldName} for ${type}`;
|
|
202
|
+
}
|
|
203
|
+
const contextLower = fullContext.toLowerCase();
|
|
204
|
+
const hintLower = (hint || '').toLowerCase();
|
|
205
|
+
// Minimal subset of field handlers for common cases
|
|
206
|
+
// Full logic is in PlaceholderValueGenerator
|
|
207
|
+
if (fieldName === 'name') {
|
|
208
|
+
if (hintLower.includes('philosopher') || contextLower.includes('philosopher'))
|
|
209
|
+
return 'Aristotle';
|
|
210
|
+
if (hintLower.includes('tech entrepreneur') || hintLower.includes('startup'))
|
|
211
|
+
return 'Alex Chen';
|
|
212
|
+
if (hint && hint.trim())
|
|
213
|
+
return `${type}: ${hint}`;
|
|
214
|
+
return `Generated ${fieldName} for ${type}`;
|
|
215
|
+
}
|
|
216
|
+
// For all other fields, use a basic fallback
|
|
217
|
+
return `${fieldName}: ${fullContext}`;
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/schema/value-generators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAcH,4BAA4B;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,gFAAgF;AAChF,iCAAiC;AACjC,gFAAgF;AAEhF,wCAAwC;AACxC,IAAI,gBAAgB,GAA0B,IAAI,CAAA;AAElD,4BAA4B;AAC5B,IAAI,aAAa,GAAyB,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA+B,EAAE;IACpE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,aAAa,CAAA;IAEzC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAA;QAC/E,CAAC;QACD,MAAM,QAAQ,GAA6C;YACzD,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAA;QACD,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS;YAAE,QAAQ,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QAC7D,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;YAAE,QAAQ,CAAC,SAAS,GAAG,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,IAAI,SAAS,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC;YAAE,OAAO,WAAW,CAAA;QAChG,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;YAAE,OAAO,GAAG,IAAI,KAAK,IAAI,EAAE,CAAA;QAClD,OAAO,aAAa,SAAS,QAAQ,IAAI,EAAE,CAAA;IAC7C,CAAC;IAED,6CAA6C;IAC7C,OAAO,GAAG,SAAS,KAAK,WAAW,EAAE,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PlaceholderValueGenerator Implementation
|
|
3
|
+
*
|
|
4
|
+
* Provides deterministic, context-aware placeholder values for testing.
|
|
5
|
+
* This generator uses keyword matching on context and hints to produce
|
|
6
|
+
* appropriate values for common field names.
|
|
7
|
+
*
|
|
8
|
+
* **PURPOSE**: This is a test fixture generator that provides:
|
|
9
|
+
* - Deterministic, predictable outputs for testing
|
|
10
|
+
* - Expected behavior and API contract demonstration
|
|
11
|
+
* - Specific assertions about generated content
|
|
12
|
+
*
|
|
13
|
+
* In production, the AIValueGenerator would be used instead.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import type { ValueGenerator, GenerationRequest, GenerationResult } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* PlaceholderValueGenerator
|
|
20
|
+
*
|
|
21
|
+
* Generates deterministic values based on field name and context keywords.
|
|
22
|
+
* Used for testing and development when AI generation is not needed.
|
|
23
|
+
*/
|
|
24
|
+
export declare class PlaceholderValueGenerator implements ValueGenerator {
|
|
25
|
+
/**
|
|
26
|
+
* Generate a context-aware placeholder value
|
|
27
|
+
*
|
|
28
|
+
* Uses keyword matching on the context and hint to produce contextually
|
|
29
|
+
* relevant values for common field names.
|
|
30
|
+
*
|
|
31
|
+
* @param request - The generation request
|
|
32
|
+
* @returns Promise resolving to the generated value with metadata
|
|
33
|
+
*/
|
|
34
|
+
generate(request: GenerationRequest): Promise<GenerationResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Synchronous value generation
|
|
37
|
+
*
|
|
38
|
+
* This is the core generation logic, exposed for callers that need
|
|
39
|
+
* synchronous operation (e.g., backward-compatible cascade.ts).
|
|
40
|
+
*
|
|
41
|
+
* @param request - The generation request
|
|
42
|
+
* @returns The generated value string
|
|
43
|
+
*/
|
|
44
|
+
generateSync(request: GenerationRequest): string;
|
|
45
|
+
/**
|
|
46
|
+
* Core value generation logic
|
|
47
|
+
*
|
|
48
|
+
* Moved from cascade.ts generateContextAwareValue function.
|
|
49
|
+
*/
|
|
50
|
+
private generateValue;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=placeholder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.d.ts","sourceRoot":"","sources":["../../../src/schema/value-generators/placeholder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAErF;;;;;GAKG;AACH,qBAAa,yBAA0B,YAAW,cAAc;IAC9D;;;;;;;;OAQG;IACG,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAQrE;;;;;;;;OAQG;IACH,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM;IAIhD;;;;OAIG;IACH,OAAO,CAAC,aAAa;CAgTtB"}
|