@workos/oagen-emitters 0.0.1 → 0.2.1
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/.github/workflows/release-please.yml +9 -1
- package/.husky/commit-msg +0 -0
- package/.husky/pre-commit +1 -0
- package/.husky/pre-push +1 -0
- package/.oxfmtrc.json +8 -1
- package/.prettierignore +1 -0
- package/.release-please-manifest.json +3 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +61 -0
- package/README.md +2 -2
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4070 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -18
- package/release-please-config.json +11 -0
- package/smoke/sdk-dotnet.ts +17 -3
- package/smoke/sdk-elixir.ts +17 -3
- package/smoke/sdk-go.ts +21 -4
- package/smoke/sdk-kotlin.ts +23 -4
- package/smoke/sdk-node.ts +15 -3
- package/smoke/sdk-ruby.ts +17 -3
- package/smoke/sdk-rust.ts +16 -3
- package/src/node/client.ts +521 -206
- package/src/node/common.ts +74 -4
- package/src/node/config.ts +1 -0
- package/src/node/enums.ts +53 -9
- package/src/node/errors.ts +82 -3
- package/src/node/fixtures.ts +87 -16
- package/src/node/index.ts +66 -10
- package/src/node/manifest.ts +4 -2
- package/src/node/models.ts +251 -124
- package/src/node/naming.ts +107 -3
- package/src/node/resources.ts +1162 -108
- package/src/node/serializers.ts +512 -52
- package/src/node/tests.ts +650 -110
- package/src/node/type-map.ts +89 -11
- package/src/node/utils.ts +426 -113
- package/test/node/client.test.ts +1083 -20
- package/test/node/enums.test.ts +73 -4
- package/test/node/errors.test.ts +4 -21
- package/test/node/models.test.ts +499 -5
- package/test/node/naming.test.ts +14 -7
- package/test/node/resources.test.ts +1568 -9
- package/test/node/serializers.test.ts +241 -5
- package/tsconfig.json +2 -3
- package/{tsup.config.ts → tsdown.config.ts} +1 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -2158
package/src/node/type-map.ts
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import type { TypeRef, PrimitiveType } from '@workos/oagen';
|
|
1
|
+
import type { TypeRef, PrimitiveType, UnionType } from '@workos/oagen';
|
|
2
2
|
import { mapTypeRef as irMapTypeRef } from '@workos/oagen';
|
|
3
3
|
import { wireInterfaceName } from './naming.js';
|
|
4
4
|
|
|
5
|
+
export interface MapTypeRefOpts {
|
|
6
|
+
stringDates?: boolean;
|
|
7
|
+
/** Map from model name → default type args (e.g., `'<Record<string, unknown>>'`).
|
|
8
|
+
* When present, model refs for generic models get their defaults appended. */
|
|
9
|
+
genericDefaults?: Map<string, string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
/**
|
|
6
13
|
* Map an IR TypeRef to a TypeScript domain type string.
|
|
7
14
|
* Domain types use PascalCase model names (e.g., `Organization`).
|
|
15
|
+
*
|
|
16
|
+
* @param opts.stringDates - When true, map `date-time` to `string` instead of `Date`.
|
|
17
|
+
* Use this when integrating into an existing SDK that represents timestamps as
|
|
18
|
+
* ISO 8601 strings rather than Date objects.
|
|
19
|
+
* @param opts.genericDefaults - When present, appends default type args to generic model refs.
|
|
8
20
|
*/
|
|
9
|
-
export function mapTypeRef(ref: TypeRef): string {
|
|
21
|
+
export function mapTypeRef(ref: TypeRef, opts?: MapTypeRefOpts): string {
|
|
22
|
+
const primMapper = opts?.stringDates ? mapPrimitiveStringDates : mapPrimitive;
|
|
23
|
+
const genericDefaults = opts?.genericDefaults;
|
|
10
24
|
return irMapTypeRef<string>(ref, {
|
|
11
|
-
primitive:
|
|
25
|
+
primitive: primMapper,
|
|
12
26
|
array: (_r, items) => `${parenthesizeUnion(items)}[]`,
|
|
13
|
-
model: (r) => r.name,
|
|
27
|
+
model: (r) => r.name + (genericDefaults?.get(r.name) ?? ''),
|
|
14
28
|
enum: (r) => r.name,
|
|
15
|
-
union: (
|
|
29
|
+
union: (r, variants) => joinUnionVariants(r, variants),
|
|
16
30
|
nullable: (_r, inner) => `${inner} | null`,
|
|
17
31
|
literal: (r) => (typeof r.value === 'string' ? `'${r.value}'` : String(r.value)),
|
|
18
32
|
map: (_r, value) => `Record<string, ${value}>`,
|
|
@@ -22,14 +36,16 @@ export function mapTypeRef(ref: TypeRef): string {
|
|
|
22
36
|
/**
|
|
23
37
|
* Map an IR TypeRef to a TypeScript wire/response type string.
|
|
24
38
|
* Model references get the `Response` suffix (e.g., `OrganizationResponse`).
|
|
39
|
+
* Wire types use JSON-native types (string for date-time, number/string for int64).
|
|
25
40
|
*/
|
|
26
|
-
export function mapWireTypeRef(ref: TypeRef): string {
|
|
41
|
+
export function mapWireTypeRef(ref: TypeRef, opts?: { genericDefaults?: Map<string, string> }): string {
|
|
42
|
+
const genericDefaults = opts?.genericDefaults;
|
|
27
43
|
return irMapTypeRef<string>(ref, {
|
|
28
|
-
primitive:
|
|
44
|
+
primitive: mapWirePrimitive,
|
|
29
45
|
array: (_r, items) => `${parenthesizeUnion(items)}[]`,
|
|
30
|
-
model: (r) => wireInterfaceName(r.name),
|
|
46
|
+
model: (r) => wireInterfaceName(r.name) + (genericDefaults?.get(r.name) ?? ''),
|
|
31
47
|
enum: (r) => r.name,
|
|
32
|
-
union: (
|
|
48
|
+
union: (r, variants) => joinUnionVariants(r, variants),
|
|
33
49
|
nullable: (_r, inner) => `${inner} | null`,
|
|
34
50
|
literal: (r) => (typeof r.value === 'string' ? `'${r.value}'` : String(r.value)),
|
|
35
51
|
map: (_r, value) => `Record<string, ${value}>`,
|
|
@@ -37,6 +53,39 @@ export function mapWireTypeRef(ref: TypeRef): string {
|
|
|
37
53
|
}
|
|
38
54
|
|
|
39
55
|
function mapPrimitive(ref: PrimitiveType): string {
|
|
56
|
+
if (ref.format) {
|
|
57
|
+
switch (ref.format) {
|
|
58
|
+
case 'date-time':
|
|
59
|
+
return 'Date';
|
|
60
|
+
case 'int64':
|
|
61
|
+
return 'bigint';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
switch (ref.type) {
|
|
65
|
+
case 'string':
|
|
66
|
+
return 'string';
|
|
67
|
+
case 'integer':
|
|
68
|
+
case 'number':
|
|
69
|
+
return 'number';
|
|
70
|
+
case 'boolean':
|
|
71
|
+
return 'boolean';
|
|
72
|
+
case 'unknown':
|
|
73
|
+
return 'any';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Map a primitive type using string representation for dates.
|
|
79
|
+
* Used when the existing SDK represents timestamps as ISO 8601 strings.
|
|
80
|
+
*/
|
|
81
|
+
function mapPrimitiveStringDates(ref: PrimitiveType): string {
|
|
82
|
+
if (ref.format) {
|
|
83
|
+
switch (ref.format) {
|
|
84
|
+
case 'int64':
|
|
85
|
+
return 'bigint';
|
|
86
|
+
// date-time intentionally falls through to the string case
|
|
87
|
+
}
|
|
88
|
+
}
|
|
40
89
|
switch (ref.type) {
|
|
41
90
|
case 'string':
|
|
42
91
|
return 'string';
|
|
@@ -50,7 +99,36 @@ function mapPrimitive(ref: PrimitiveType): string {
|
|
|
50
99
|
}
|
|
51
100
|
}
|
|
52
101
|
|
|
53
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Map an IR PrimitiveType to a TypeScript wire/JSON type string.
|
|
104
|
+
* Wire types match JSON encoding: date-time stays string, int64 stays string/number.
|
|
105
|
+
*/
|
|
106
|
+
function mapWirePrimitive(ref: PrimitiveType): string {
|
|
107
|
+
switch (ref.type) {
|
|
108
|
+
case 'string':
|
|
109
|
+
return 'string';
|
|
110
|
+
case 'integer':
|
|
111
|
+
case 'number':
|
|
112
|
+
return 'number';
|
|
113
|
+
case 'boolean':
|
|
114
|
+
return 'boolean';
|
|
115
|
+
case 'unknown':
|
|
116
|
+
return 'any';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Join union variant type strings using the appropriate operator.
|
|
122
|
+
* allOf unions use `&` (intersection), oneOf/anyOf/unspecified use `|` (union).
|
|
123
|
+
*/
|
|
124
|
+
function joinUnionVariants(ref: UnionType, variants: string[]): string {
|
|
125
|
+
if (ref.compositionKind === 'allOf') {
|
|
126
|
+
return variants.join(' & ');
|
|
127
|
+
}
|
|
128
|
+
return variants.join(' | ');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Wrap union/intersection types in parentheses when used as array item type. */
|
|
54
132
|
function parenthesizeUnion(type: string): string {
|
|
55
|
-
return type.includes(' | ') ? `(${type})` : type;
|
|
133
|
+
return type.includes(' | ') || type.includes(' & ') ? `(${type})` : type;
|
|
56
134
|
}
|