@workos/oagen-emitters 0.17.0 → 0.18.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +7 -0
- package/dist/index.mjs +1 -1
- package/dist/{plugin-BLnR-FMi.mjs → plugin-DAa-HsN5.mjs} +144 -39
- package/dist/plugin-DAa-HsN5.mjs.map +1 -0
- package/dist/plugin.mjs +1 -1
- package/package.json +6 -6
- package/src/node/discriminated-models.ts +197 -50
- package/src/node/resources.ts +34 -10
- package/test/node/discriminated-pure-oneof.test.ts +108 -0
- package/dist/plugin-BLnR-FMi.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.18.0](https://github.com/workos/oagen-emitters/compare/v0.17.0...v0.18.0) (2026-06-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **node:** emit discriminated unions for pure oneOf token response ([#150](https://github.com/workos/oagen-emitters/issues/150)) ([1433bcc](https://github.com/workos/oagen-emitters/commit/1433bcc2f61db52aeadd7b947b79bb90c184c0a1))
|
|
9
|
+
|
|
3
10
|
## [0.17.0](https://github.com/workos/oagen-emitters/compare/v0.16.1...v0.17.0) (2026-06-15)
|
|
4
11
|
|
|
5
12
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as fieldName$4, B as servicePropertyName, C as apiClassName, D as dotnetEmitter, E as propertyName, F as fieldName$3, H as fieldName$1, I as methodName, L as trimMountedResourceFromMethod, M as trimMountedResourceFromMethod$1, N as goEmitter, O as appendAsyncSuffix, P as className, R as phpEmitter, S as kotlinEmitter, T as packageSegment, U as safeParamName$1, V as pythonEmitter, W as nodeEmitter, _ as rubyEmitter, a as rustExtractor, b as resolveServiceTarget, c as pythonExtractor, d as rustEmitter, f as fieldName$5, g as typeName, h as resourceAccessorName, i as kotlinExtractor, j as methodName$1, k as className$1, l as rubyExtractor, m as moduleName, n as elixirExtractor, o as goExtractor, p as methodName$3, r as dotnetExtractor, s as phpExtractor, t as workosEmittersPlugin, u as nodeExtractor, v as buildExportedClassNameSet, w as methodName$2, x as safeParamName, y as fieldName, z as fieldName$2 } from "./plugin-
|
|
1
|
+
import { A as fieldName$4, B as servicePropertyName, C as apiClassName, D as dotnetEmitter, E as propertyName, F as fieldName$3, H as fieldName$1, I as methodName, L as trimMountedResourceFromMethod, M as trimMountedResourceFromMethod$1, N as goEmitter, O as appendAsyncSuffix, P as className, R as phpEmitter, S as kotlinEmitter, T as packageSegment, U as safeParamName$1, V as pythonEmitter, W as nodeEmitter, _ as rubyEmitter, a as rustExtractor, b as resolveServiceTarget, c as pythonExtractor, d as rustEmitter, f as fieldName$5, g as typeName, h as resourceAccessorName, i as kotlinExtractor, j as methodName$1, k as className$1, l as rubyExtractor, m as moduleName, n as elixirExtractor, o as goExtractor, p as methodName$3, r as dotnetExtractor, s as phpExtractor, t as workosEmittersPlugin, u as nodeExtractor, v as buildExportedClassNameSet, w as methodName$2, x as safeParamName, y as fieldName, z as fieldName$2 } from "./plugin-DAa-HsN5.mjs";
|
|
2
2
|
import { collectSnippetArgs, collectWrapperArgs, toSnakeCase } from "@workos/oagen";
|
|
3
3
|
//#region src/snippets/ruby.ts
|
|
4
4
|
const INDENT$6 = " ";
|
|
@@ -5603,6 +5603,17 @@ function renderOptionsParam(param) {
|
|
|
5603
5603
|
function isValidTypeIdentifier(name) {
|
|
5604
5604
|
return /^[A-Za-z_$][\w$]*$/.test(name);
|
|
5605
5605
|
}
|
|
5606
|
+
/**
|
|
5607
|
+
* Extract candidate named type references from a compound type expression such
|
|
5608
|
+
* as `GetAccessTokenOptions & { provider: string }`. PascalCase tokens are type
|
|
5609
|
+
* names worth importing; lowercase tokens are property keys or primitives and
|
|
5610
|
+
* are skipped. The caller only imports the ones that resolve to a known source
|
|
5611
|
+
* file, so unrecognized PascalCase tokens (e.g. `Date`, `Record`) are harmless.
|
|
5612
|
+
*/
|
|
5613
|
+
function extractNamedTypeRefs(typeExpr) {
|
|
5614
|
+
const matches = typeExpr.match(/\b[A-Z][A-Za-z0-9_$]*\b/g) ?? [];
|
|
5615
|
+
return [...new Set(matches)];
|
|
5616
|
+
}
|
|
5606
5617
|
function autoPaginatableItemType$1(returnType) {
|
|
5607
5618
|
return returnType?.match(/\b(?:AutoPaginatable|List)<\s*([A-Za-z_$][\w$]*)/)?.[1];
|
|
5608
5619
|
}
|
|
@@ -5937,12 +5948,21 @@ function generateResourceClass(service, ctx) {
|
|
|
5937
5948
|
if (hasIdempotentPost || hasCustomEncoding) lines.push("import type { PostOptions } from '../common/interfaces/post-options.interface';");
|
|
5938
5949
|
const importedTypeNames = /* @__PURE__ */ new Set();
|
|
5939
5950
|
for (const optionType of optionObjectTypes) {
|
|
5940
|
-
if (
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5951
|
+
if (isValidTypeIdentifier(optionType)) {
|
|
5952
|
+
if (importedTypeNames.has(optionType)) continue;
|
|
5953
|
+
importedTypeNames.add(optionType);
|
|
5954
|
+
const sourceFile = baselineTypeSourceFile(ctx, optionType);
|
|
5955
|
+
const relPath = sourceFile ? relativeImport(resourcePath, sourceFile) : `./interfaces/${fileName$3(optionType)}.interface`;
|
|
5956
|
+
lines.push(`import type { ${optionType} } from '${relPath}';`);
|
|
5957
|
+
continue;
|
|
5958
|
+
}
|
|
5959
|
+
for (const typeName of extractNamedTypeRefs(optionType)) {
|
|
5960
|
+
if (importedTypeNames.has(typeName)) continue;
|
|
5961
|
+
const sourceFile = baselineTypeSourceFile(ctx, typeName) ?? liveSurfaceInterfacePath(typeName);
|
|
5962
|
+
if (!sourceFile) continue;
|
|
5963
|
+
importedTypeNames.add(typeName);
|
|
5964
|
+
lines.push(`import type { ${typeName} } from '${relativeImport(resourcePath, sourceFile)}';`);
|
|
5965
|
+
}
|
|
5946
5966
|
}
|
|
5947
5967
|
for (const typeName of returnTypeImports) {
|
|
5948
5968
|
if (importedTypeNames.has(typeName)) continue;
|
|
@@ -9374,10 +9394,11 @@ function dedupeLiteralTypes(types) {
|
|
|
9374
9394
|
//#region src/node/discriminated-models.ts
|
|
9375
9395
|
function detectDiscriminatedShape(modelName, rawSchemas) {
|
|
9376
9396
|
const schema = rawSchemas[modelName];
|
|
9377
|
-
if (!schema
|
|
9397
|
+
if (!schema) return null;
|
|
9378
9398
|
let baseObject = null;
|
|
9379
9399
|
let oneOfVariants = null;
|
|
9380
|
-
|
|
9400
|
+
let inlineUnion = false;
|
|
9401
|
+
if (schema.allOf) for (const member of schema.allOf) {
|
|
9381
9402
|
const resolved = resolveRef(member, rawSchemas);
|
|
9382
9403
|
if (resolved.oneOf) {
|
|
9383
9404
|
if (oneOfVariants) return null;
|
|
@@ -9388,16 +9409,22 @@ function detectDiscriminatedShape(modelName, rawSchemas) {
|
|
|
9388
9409
|
baseObject = mergeBase(baseObject, nestedBase);
|
|
9389
9410
|
}
|
|
9390
9411
|
}
|
|
9412
|
+
else if (schema.oneOf && schema.oneOf.length >= 2) {
|
|
9413
|
+
if (!schema.oneOf.every((v) => v.properties && !v.$ref && (v.type === "object" || !v.type) && !v.allOf && !v.oneOf)) return null;
|
|
9414
|
+
oneOfVariants = schema.oneOf;
|
|
9415
|
+
inlineUnion = true;
|
|
9416
|
+
} else return null;
|
|
9391
9417
|
if (!oneOfVariants || oneOfVariants.length < 2) return null;
|
|
9392
9418
|
const flattenedVariants = oneOfVariants.map((v) => flattenVariant(v, rawSchemas));
|
|
9393
9419
|
const discProp = findSharedDiscriminator(flattenedVariants);
|
|
9394
9420
|
if (!discProp) return null;
|
|
9395
9421
|
const variants = flattenedVariants.map((fv) => {
|
|
9396
|
-
const discValue =
|
|
9397
|
-
if (
|
|
9422
|
+
const discValue = readConst(fv.alwaysProperties.get(discProp));
|
|
9423
|
+
if (discValue === null) return null;
|
|
9398
9424
|
return {
|
|
9399
|
-
nameSuffix: variantNameSuffix(discValue),
|
|
9400
|
-
discriminatorValue: discValue,
|
|
9425
|
+
nameSuffix: variantNameSuffix(String(discValue)),
|
|
9426
|
+
discriminatorValue: String(discValue),
|
|
9427
|
+
discriminatorIsBoolean: typeof discValue === "boolean",
|
|
9401
9428
|
fields: variantFields(fv, discProp, modelName)
|
|
9402
9429
|
};
|
|
9403
9430
|
}).filter((v) => v !== null);
|
|
@@ -9410,7 +9437,8 @@ function detectDiscriminatedShape(modelName, rawSchemas) {
|
|
|
9410
9437
|
discriminatorProperty: discProp,
|
|
9411
9438
|
discriminatorPropertyDomain: toCamelCase(discProp),
|
|
9412
9439
|
discriminatorDescription,
|
|
9413
|
-
variants
|
|
9440
|
+
variants,
|
|
9441
|
+
inlineUnion
|
|
9414
9442
|
};
|
|
9415
9443
|
}
|
|
9416
9444
|
function mergeBase(prev, next) {
|
|
@@ -9525,21 +9553,29 @@ function findSharedDiscriminator(variants) {
|
|
|
9525
9553
|
let allConst = true;
|
|
9526
9554
|
const values = [];
|
|
9527
9555
|
for (const v of variants) {
|
|
9528
|
-
const val =
|
|
9556
|
+
const val = readConst(v.alwaysProperties.get(propName));
|
|
9529
9557
|
if (val === null) {
|
|
9530
9558
|
allConst = false;
|
|
9531
9559
|
break;
|
|
9532
9560
|
}
|
|
9533
|
-
values.push(val);
|
|
9561
|
+
values.push(String(val));
|
|
9534
9562
|
}
|
|
9535
9563
|
if (allConst && new Set(values).size === values.length) return propName;
|
|
9536
9564
|
}
|
|
9537
9565
|
return null;
|
|
9538
9566
|
}
|
|
9539
|
-
|
|
9567
|
+
/**
|
|
9568
|
+
* Read a discriminator value pinned by `const` (or a single-value `enum`).
|
|
9569
|
+
* Supports string and boolean literals — the latter drives the
|
|
9570
|
+
* `active: true | false` style token response union.
|
|
9571
|
+
*/
|
|
9572
|
+
function readConst(schema) {
|
|
9540
9573
|
if (!schema) return null;
|
|
9541
|
-
if (typeof schema.const === "string") return schema.const;
|
|
9542
|
-
if (Array.isArray(schema.enum) && schema.enum.length === 1
|
|
9574
|
+
if (typeof schema.const === "string" || typeof schema.const === "boolean") return schema.const;
|
|
9575
|
+
if (Array.isArray(schema.enum) && schema.enum.length === 1) {
|
|
9576
|
+
const only = schema.enum[0];
|
|
9577
|
+
if (typeof only === "string" || typeof only === "boolean") return only;
|
|
9578
|
+
}
|
|
9543
9579
|
return null;
|
|
9544
9580
|
}
|
|
9545
9581
|
function variantNameSuffix(constValue) {
|
|
@@ -9568,6 +9604,7 @@ function buildField(rawName, schema, required, parentName) {
|
|
|
9568
9604
|
const modelDeps = /* @__PURE__ */ new Set();
|
|
9569
9605
|
const domainType = rawSchemaToTS(schema, parentName, rawName, false, modelDeps);
|
|
9570
9606
|
const wireType = rawSchemaToTS(schema, parentName, rawName, true, modelDeps);
|
|
9607
|
+
const enumValues = Array.isArray(schema.enum) && schema.enum.length > 0 && schema.enum.every((e) => typeof e === "string") ? schema.enum : void 0;
|
|
9571
9608
|
return {
|
|
9572
9609
|
name: rawName,
|
|
9573
9610
|
description: schema.description,
|
|
@@ -9575,7 +9612,8 @@ function buildField(rawName, schema, required, parentName) {
|
|
|
9575
9612
|
domainType,
|
|
9576
9613
|
wireType,
|
|
9577
9614
|
modelDeps,
|
|
9578
|
-
hasDateTime: schemaHasDateTime(schema)
|
|
9615
|
+
hasDateTime: schemaHasDateTime(schema),
|
|
9616
|
+
enumValues
|
|
9579
9617
|
};
|
|
9580
9618
|
}
|
|
9581
9619
|
function schemaHasDateTime(schema) {
|
|
@@ -9644,13 +9682,15 @@ function planDiscriminatedModels(models, ctx) {
|
|
|
9644
9682
|
const stripped = rawName.replace(/Dto/g, "").replace(/DTO/g, "").replace(/Json$/, "");
|
|
9645
9683
|
if (stripped !== rawName && irModelDir.has(stripped)) depDirMap.set(rawName, irModelDir.get(stripped));
|
|
9646
9684
|
}
|
|
9685
|
+
for (const [irName, dir] of irModelDir) if (!depDirMap.has(irName)) depDirMap.set(irName, dir);
|
|
9647
9686
|
for (const model of models) {
|
|
9648
9687
|
const shape = detectDiscriminatedShape(model.name, rawSchemas);
|
|
9649
9688
|
if (!shape) continue;
|
|
9650
9689
|
const allDeps = /* @__PURE__ */ new Set();
|
|
9651
9690
|
for (const field of shape.baseFields) for (const d of field.modelDeps) allDeps.add(d);
|
|
9652
9691
|
for (const variant of shape.variants) for (const field of variant.fields) for (const d of field.modelDeps) allDeps.add(d);
|
|
9653
|
-
|
|
9692
|
+
const resolvable = (dep) => depDirMap.has(dep) || irModelDir.has(dep) || depDirMap.has(toPascalCase(dep)) || irModelDir.has(toPascalCase(dep));
|
|
9693
|
+
if ([...allDeps].some((dep) => !resolvable(dep))) continue;
|
|
9654
9694
|
const modelDir = resolveDir(modelToService.get(model.name));
|
|
9655
9695
|
plans.set(model.name, {
|
|
9656
9696
|
shape,
|
|
@@ -9670,6 +9710,7 @@ function generateDiscriminatedFiles(plans, ctx) {
|
|
|
9670
9710
|
}
|
|
9671
9711
|
function buildInterfaceFile(plan, _ctx) {
|
|
9672
9712
|
const { shape, modelDir } = plan;
|
|
9713
|
+
if (shape.inlineUnion) return buildInlineUnionFile(plan);
|
|
9673
9714
|
const domain = toPascalCase(shape.modelName);
|
|
9674
9715
|
const wire = wireInterfaceName(domain);
|
|
9675
9716
|
const lines = [];
|
|
@@ -9697,6 +9738,45 @@ function buildInterfaceFile(plan, _ctx) {
|
|
|
9697
9738
|
overwriteExisting: true
|
|
9698
9739
|
};
|
|
9699
9740
|
}
|
|
9741
|
+
/**
|
|
9742
|
+
* Emit a pure-`oneOf` discriminated union as a single inline type alias
|
|
9743
|
+
* (`export type X = { … } | { … }`) for both the domain and wire shapes. Used
|
|
9744
|
+
* instead of named per-variant interfaces, which read poorly for small
|
|
9745
|
+
* (often two-variant, boolean-discriminated) unions like the token response.
|
|
9746
|
+
*/
|
|
9747
|
+
function buildInlineUnionFile(plan) {
|
|
9748
|
+
const { shape, modelDir } = plan;
|
|
9749
|
+
const domain = toPascalCase(shape.modelName);
|
|
9750
|
+
const wire = wireInterfaceName(domain);
|
|
9751
|
+
const lines = [];
|
|
9752
|
+
const imports = collectImports$2(plan);
|
|
9753
|
+
if (imports.length > 0) {
|
|
9754
|
+
for (const imp of imports) lines.push(`import type { ${imp.symbols.join(", ")} } from '${imp.path}';`);
|
|
9755
|
+
lines.push("");
|
|
9756
|
+
}
|
|
9757
|
+
lines.push(...buildInlineUnionAlias(domain, shape, false));
|
|
9758
|
+
lines.push("");
|
|
9759
|
+
lines.push(...buildInlineUnionAlias(wire, shape, true));
|
|
9760
|
+
return {
|
|
9761
|
+
path: `src/${modelDir}/interfaces/${fileName$3(shape.modelName)}.interface.ts`,
|
|
9762
|
+
content: lines.join("\n") + "\n",
|
|
9763
|
+
overwriteExisting: true
|
|
9764
|
+
};
|
|
9765
|
+
}
|
|
9766
|
+
function buildInlineUnionAlias(name, shape, isWire) {
|
|
9767
|
+
const lines = [`export type ${name} =`];
|
|
9768
|
+
shape.variants.forEach((variant, idx) => {
|
|
9769
|
+
const isLast = idx === shape.variants.length - 1;
|
|
9770
|
+
const members = [`${isWire ? shape.discriminatorProperty : shape.discriminatorPropertyDomain}: ${discLiteral(variant)}`];
|
|
9771
|
+
for (const field of variant.fields) {
|
|
9772
|
+
const key = isWire ? field.name : toCamelCase(field.name);
|
|
9773
|
+
const opt = field.required ? "" : "?";
|
|
9774
|
+
members.push(`${key}${opt}: ${inlineFieldType(field, isWire)}`);
|
|
9775
|
+
}
|
|
9776
|
+
lines.push(` | { ${members.join("; ")} }${isLast ? ";" : ""}`);
|
|
9777
|
+
});
|
|
9778
|
+
return lines;
|
|
9779
|
+
}
|
|
9700
9780
|
function buildInterfaceBody(name, shape, variant, isWire) {
|
|
9701
9781
|
const lines = [];
|
|
9702
9782
|
lines.push(`export interface ${name} {`);
|
|
@@ -9708,11 +9788,32 @@ function buildInterfaceBody(name, shape, variant, isWire) {
|
|
|
9708
9788
|
}
|
|
9709
9789
|
const discKey = isWire ? shape.discriminatorProperty : shape.discriminatorPropertyDomain;
|
|
9710
9790
|
if (shape.discriminatorDescription) lines.push(` /** ${shape.discriminatorDescription} */`);
|
|
9711
|
-
lines.push(` ${discKey}:
|
|
9791
|
+
lines.push(` ${discKey}: ${discLiteral(variant)};`);
|
|
9712
9792
|
for (const field of variant.fields) pushFieldLine(lines, field, isWire);
|
|
9713
9793
|
lines.push("}");
|
|
9714
9794
|
return lines;
|
|
9715
9795
|
}
|
|
9796
|
+
/**
|
|
9797
|
+
* The discriminator value as a TS literal: quoted for strings (`'oauth'`),
|
|
9798
|
+
* bare for booleans (`true`).
|
|
9799
|
+
*/
|
|
9800
|
+
function discLiteral(variant) {
|
|
9801
|
+
return variant.discriminatorIsBoolean ? variant.discriminatorValue : `'${variant.discriminatorValue}'`;
|
|
9802
|
+
}
|
|
9803
|
+
/**
|
|
9804
|
+
* Field type for an inline-union member: a literal union for inline string
|
|
9805
|
+
* enums, otherwise the resolved domain/wire type.
|
|
9806
|
+
*
|
|
9807
|
+
* The `enumValues` branch deliberately ignores `isWire`: `enumValues` is only
|
|
9808
|
+
* populated for string enums (see `buildField`), whose domain and wire
|
|
9809
|
+
* representations are identical literal unions. Any field whose domain/wire
|
|
9810
|
+
* types actually differ (model refs, dates, non-string enums) leaves
|
|
9811
|
+
* `enumValues` undefined and falls through to the type-specific branch.
|
|
9812
|
+
*/
|
|
9813
|
+
function inlineFieldType(field, isWire) {
|
|
9814
|
+
if (field.enumValues) return field.enumValues.map((v) => `'${v}'`).join(" | ");
|
|
9815
|
+
return isWire ? field.wireType : field.domainType;
|
|
9816
|
+
}
|
|
9716
9817
|
function pushFieldLine(lines, field, isWire) {
|
|
9717
9818
|
const key = isWire ? field.name : toCamelCase(field.name);
|
|
9718
9819
|
const opt = field.required ? "" : "?";
|
|
@@ -9729,7 +9830,7 @@ function collectImports$2(plan) {
|
|
|
9729
9830
|
const domain = toPascalCase(dep);
|
|
9730
9831
|
const wire = wireInterfaceName(domain);
|
|
9731
9832
|
const symbols = wire !== domain ? [domain, wire] : [domain];
|
|
9732
|
-
const depDir = plan.depDirMap.get(dep);
|
|
9833
|
+
const depDir = plan.depDirMap.get(dep) ?? plan.depDirMap.get(domain);
|
|
9733
9834
|
const baseName = fileName$3(toSnakeFromPascal(domain));
|
|
9734
9835
|
let importPath;
|
|
9735
9836
|
if (!depDir || depDir === plan.modelDir) importPath = `./${baseName}.interface`;
|
|
@@ -9756,39 +9857,43 @@ function buildSerializerFile(plan, _ctx) {
|
|
|
9756
9857
|
const allDeps = /* @__PURE__ */ new Set();
|
|
9757
9858
|
for (const field of shape.baseFields) for (const d of field.modelDeps) allDeps.add(d);
|
|
9758
9859
|
for (const variant of shape.variants) for (const field of variant.fields) for (const d of field.modelDeps) allDeps.add(d);
|
|
9860
|
+
const deserializeOnly = shape.inlineUnion === true;
|
|
9759
9861
|
for (const dep of [...allDeps].sort()) {
|
|
9760
9862
|
const depDomain = toPascalCase(dep);
|
|
9761
9863
|
const depFile = fileName$3(toSnakeFromPascal(depDomain));
|
|
9762
|
-
|
|
9864
|
+
const helpers = deserializeOnly ? `deserialize${depDomain}` : `deserialize${depDomain}, serialize${depDomain}`;
|
|
9865
|
+
lines.push(`import { ${helpers} } from './${depFile}.serializer';`);
|
|
9763
9866
|
}
|
|
9764
9867
|
lines.push("");
|
|
9765
9868
|
lines.push(`export const deserialize${domain} = (response: ${wire}): ${domain} => {`);
|
|
9766
9869
|
lines.push(` switch (response.${shape.discriminatorProperty}) {`);
|
|
9767
9870
|
for (const variant of shape.variants) {
|
|
9768
|
-
lines.push(` case
|
|
9871
|
+
lines.push(` case ${discLiteral(variant)}:`);
|
|
9769
9872
|
lines.push(` return {`);
|
|
9770
9873
|
for (const field of shape.baseFields) lines.push(` ${assignmentLine(field, false, allDeps)},`);
|
|
9771
|
-
lines.push(` ${shape.discriminatorPropertyDomain}:
|
|
9874
|
+
lines.push(` ${shape.discriminatorPropertyDomain}: ${discLiteral(variant)},`);
|
|
9772
9875
|
for (const field of variant.fields) lines.push(` ${assignmentLine(field, false, allDeps)},`);
|
|
9773
9876
|
lines.push(` };`);
|
|
9774
9877
|
}
|
|
9775
9878
|
lines.push(` default:`);
|
|
9776
|
-
lines.push(` throw new Error(\`Unknown ${shape.discriminatorProperty}: \${(response as
|
|
9879
|
+
lines.push(` throw new Error(\`Unknown ${shape.discriminatorProperty}: \${String((response as Record<string, unknown>).${shape.discriminatorProperty})}\`);`);
|
|
9777
9880
|
lines.push(` }`);
|
|
9778
9881
|
lines.push(`};`);
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9882
|
+
if (!deserializeOnly) {
|
|
9883
|
+
lines.push("");
|
|
9884
|
+
lines.push(`export const serialize${domain} = (model: ${domain}): ${wire} => {`);
|
|
9885
|
+
lines.push(` switch (model.${shape.discriminatorPropertyDomain}) {`);
|
|
9886
|
+
for (const variant of shape.variants) {
|
|
9887
|
+
lines.push(` case ${discLiteral(variant)}:`);
|
|
9888
|
+
lines.push(` return {`);
|
|
9889
|
+
for (const field of shape.baseFields) lines.push(` ${assignmentLine(field, true, allDeps)},`);
|
|
9890
|
+
lines.push(` ${shape.discriminatorProperty}: ${discLiteral(variant)},`);
|
|
9891
|
+
for (const field of variant.fields) lines.push(` ${assignmentLine(field, true, allDeps)},`);
|
|
9892
|
+
lines.push(` };`);
|
|
9893
|
+
}
|
|
9894
|
+
lines.push(` }`);
|
|
9895
|
+
lines.push(`};`);
|
|
9789
9896
|
}
|
|
9790
|
-
lines.push(` }`);
|
|
9791
|
-
lines.push(`};`);
|
|
9792
9897
|
return {
|
|
9793
9898
|
path: `src/${modelDir}/serializers/${fileName$3(shape.modelName)}.serializer.ts`,
|
|
9794
9899
|
content: lines.join("\n") + "\n",
|
|
@@ -29764,4 +29869,4 @@ const workosEmittersPlugin = {
|
|
|
29764
29869
|
//#endregion
|
|
29765
29870
|
export { fieldName$2 as A, servicePropertyName$2 as B, apiClassName as C, dotnetEmitter as D, propertyName as E, fieldName$3 as F, fieldName$5 as H, methodName$3 as I, trimMountedResourceFromMethod$2 as L, trimMountedResourceFromMethod$1 as M, goEmitter as N, appendAsyncSuffix as O, className$3 as P, phpEmitter as R, kotlinEmitter as S, packageSegment as T, safeParamName$1 as U, pythonEmitter as V, nodeEmitter as W, rubyEmitter as _, rustExtractor as a, resolveServiceTarget as b, pythonExtractor as c, rustEmitter as d, fieldName as f, typeName as g, resourceAccessorName as h, kotlinExtractor as i, methodName$2 as j, className$2 as k, rubyExtractor as l, moduleName as m, elixirExtractor as n, goExtractor as o, methodName as p, dotnetExtractor as r, phpExtractor as s, workosEmittersPlugin as t, nodeExtractor as u, buildExportedClassNameSet as v, methodName$1 as w, safeParamName as x, fieldName$1 as y, fieldName$4 as z };
|
|
29766
29871
|
|
|
29767
|
-
//# sourceMappingURL=plugin-
|
|
29872
|
+
//# sourceMappingURL=plugin-DAa-HsN5.mjs.map
|