@aintela/chat 0.4.1 → 0.4.2
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/package.json +1 -1
- package/scripts/gen-uitools.mjs +26 -1
package/package.json
CHANGED
package/scripts/gen-uitools.mjs
CHANGED
|
@@ -212,6 +212,31 @@ function hoistNamedTypes(schema, rootName, from) {
|
|
|
212
212
|
return hoisted;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
// A C# `Dictionary<string, V>` reaches the schema as `additionalProperties`, which the schema builder
|
|
216
|
+
// writes as a TypeScript index signature — three lines of `{ [k: string]: V }` for what a TS reader
|
|
217
|
+
// spells `Record<string, V>`. Identical type, so this is only how it READS, but a payload carrying a
|
|
218
|
+
// dozen of them reads very differently for it.
|
|
219
|
+
//
|
|
220
|
+
// Done on the emitted TEXT, not by handing the builder a `tsType` override for the dictionary node:
|
|
221
|
+
// `tsType` replaces the node outright and the builder stops walking INTO it, so a named value type
|
|
222
|
+
// reached only through a dictionary (`faresByAgeGroup: Dictionary<string, Money>`) stops being emitted
|
|
223
|
+
// and the file references an interface it no longer declares.
|
|
224
|
+
//
|
|
225
|
+
// The leading `:` / `(` / `=` is what keeps an interface's OWN opening brace out of it — `export
|
|
226
|
+
// interface Foo {` must stay an interface with an index signature, not become `export interface
|
|
227
|
+
// FooRecord<…>`. A value spanning more than one line (a dictionary OF inline objects) doesn't match and
|
|
228
|
+
// keeps the index signature, which is correct if verbose; the loop is for a dictionary of dictionaries,
|
|
229
|
+
// where the inner rewrite is what makes the outer one match.
|
|
230
|
+
const INDEX_SIGNATURE = /([:(|&,=]\s*)\{\n\[k: string]: ([^\n{}]+)\n\}/g;
|
|
231
|
+
|
|
232
|
+
function asRecords(ts) {
|
|
233
|
+
for (let previous = null; previous !== ts;) {
|
|
234
|
+
previous = ts;
|
|
235
|
+
ts = ts.replace(INDEX_SIGNATURE, (_, lead, value) => `${lead}Record<string, ${value}>`);
|
|
236
|
+
}
|
|
237
|
+
return ts;
|
|
238
|
+
}
|
|
239
|
+
|
|
215
240
|
// One compile() output holds the requested type PLUS every named sub-schema hoisted into its own
|
|
216
241
|
// declaration. Split it so the same type reached through two different tools (deep contracts share
|
|
217
242
|
// sub-types) dedupes instead of colliding as duplicate identifiers in the generated file.
|
|
@@ -230,7 +255,7 @@ async function register(typeName, schema, fallback = 'void', from = typeName) {
|
|
|
230
255
|
if (!typeName || !schema) return fallback;
|
|
231
256
|
const prim = primitiveOf(schema);
|
|
232
257
|
if (prim) return prim;
|
|
233
|
-
const ts = await compile(hoistNamedTypes(schema, typeName, from), typeName, opts);
|
|
258
|
+
const ts = asRecords(await compile(hoistNamedTypes(schema, typeName, from), typeName, opts));
|
|
234
259
|
// Compiled every time, not just the first: a second tool declaring the SAME name with a different
|
|
235
260
|
// shape is exactly the mistake worth catching, and skipping the compile is what used to hide it.
|
|
236
261
|
for (const block of splitDeclarations(ts)) {
|