@workos/oagen-emitters 0.12.0 → 0.12.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/.github/workflows/ci.yml +1 -1
- package/.github/workflows/lint-pr-title.yml +1 -1
- package/.github/workflows/lint.yml +1 -1
- package/.github/workflows/release-please.yml +2 -2
- package/.github/workflows/release.yml +1 -1
- package/.node-version +1 -1
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{plugin-C408Wh-o.mjs → plugin-eCuvoL1T.mjs} +3914 -2121
- package/dist/plugin-eCuvoL1T.mjs.map +1 -0
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +1 -1
- package/package.json +10 -10
- package/renovate.json +46 -6
- package/src/node/client.ts +19 -32
- package/src/node/enums.ts +67 -30
- package/src/node/errors.ts +2 -8
- package/src/node/field-plan.ts +188 -52
- package/src/node/fixtures.ts +11 -33
- package/src/node/index.ts +345 -20
- package/src/node/live-surface.ts +378 -0
- package/src/node/models.ts +540 -351
- package/src/node/naming.ts +119 -25
- package/src/node/node-overrides.ts +77 -0
- package/src/node/options.ts +41 -0
- package/src/node/resources.ts +455 -46
- package/src/node/sdk-errors.ts +0 -16
- package/src/node/tests.ts +108 -83
- package/src/node/type-map.ts +40 -18
- package/src/node/utils.ts +89 -102
- package/src/node/wrappers.ts +0 -20
- package/src/rust/fixtures.ts +87 -1
- package/src/rust/models.ts +17 -2
- package/src/rust/resources.ts +697 -62
- package/src/rust/tests.ts +540 -20
- package/test/node/client.test.ts +106 -1201
- package/test/node/enums.test.ts +59 -130
- package/test/node/errors.test.ts +2 -3
- package/test/node/live-surface.test.ts +240 -0
- package/test/node/models.test.ts +396 -765
- package/test/node/naming.test.ts +69 -234
- package/test/node/resources.test.ts +376 -2036
- package/test/node/tests.test.ts +119 -0
- package/test/node/type-map.test.ts +49 -54
- package/test/node/utils.test.ts +29 -80
- package/test/rust/fixtures.test.ts +227 -0
- package/test/rust/models.test.ts +38 -0
- package/test/rust/resources.test.ts +505 -2
- package/test/rust/tests.test.ts +504 -0
- package/dist/plugin-C408Wh-o.mjs.map +0 -1
- package/test/node/serializers.test.ts +0 -444
|
@@ -1,444 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateSerializers } from '../../src/node/models.js';
|
|
3
|
-
import type { EmitterContext, ApiSpec, Model, Service } from '@workos/oagen';
|
|
4
|
-
import { defaultSdkBehavior } from '@workos/oagen';
|
|
5
|
-
|
|
6
|
-
const emptySpec: ApiSpec = {
|
|
7
|
-
name: 'Test',
|
|
8
|
-
version: '1.0.0',
|
|
9
|
-
baseUrl: '',
|
|
10
|
-
services: [],
|
|
11
|
-
models: [],
|
|
12
|
-
enums: [],
|
|
13
|
-
sdk: defaultSdkBehavior(),
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const ctx: EmitterContext = {
|
|
17
|
-
namespace: 'workos',
|
|
18
|
-
namespacePascal: 'WorkOS',
|
|
19
|
-
spec: emptySpec,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe('generateSerializers', () => {
|
|
23
|
-
it('returns empty for no models', () => {
|
|
24
|
-
expect(generateSerializers([], ctx)).toEqual([]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('generates deserializer with camelCase→snake_case mapping', () => {
|
|
28
|
-
const service: Service = {
|
|
29
|
-
name: 'Organizations',
|
|
30
|
-
operations: [
|
|
31
|
-
{
|
|
32
|
-
name: 'getOrganization',
|
|
33
|
-
httpMethod: 'get',
|
|
34
|
-
path: '/organizations/{id}',
|
|
35
|
-
pathParams: [
|
|
36
|
-
{
|
|
37
|
-
name: 'id',
|
|
38
|
-
type: { kind: 'primitive', type: 'string' },
|
|
39
|
-
required: true,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
queryParams: [],
|
|
43
|
-
headerParams: [],
|
|
44
|
-
response: { kind: 'model', name: 'Organization' },
|
|
45
|
-
errors: [],
|
|
46
|
-
injectIdempotencyKey: false,
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const models: Model[] = [
|
|
52
|
-
{
|
|
53
|
-
name: 'Organization',
|
|
54
|
-
fields: [
|
|
55
|
-
{
|
|
56
|
-
name: 'id',
|
|
57
|
-
type: { kind: 'primitive', type: 'string' },
|
|
58
|
-
required: true,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: 'created_at',
|
|
62
|
-
type: { kind: 'primitive', type: 'string', format: 'date-time' },
|
|
63
|
-
required: true,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'external_id',
|
|
67
|
-
type: {
|
|
68
|
-
kind: 'nullable',
|
|
69
|
-
inner: { kind: 'primitive', type: 'string' },
|
|
70
|
-
},
|
|
71
|
-
required: false,
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
const ctxWithServices: EmitterContext = {
|
|
78
|
-
...ctx,
|
|
79
|
-
spec: { ...emptySpec, services: [service], models },
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const files = generateSerializers(models, ctxWithServices);
|
|
83
|
-
expect(files.length).toBe(1);
|
|
84
|
-
expect(files[0].path).toBe('src/organizations/serializers/organization.serializer.ts');
|
|
85
|
-
|
|
86
|
-
const content = files[0].content;
|
|
87
|
-
expect(content).toContain('export const deserializeOrganization');
|
|
88
|
-
expect(content).toContain(' id: response.id,');
|
|
89
|
-
expect(content).toContain(' createdAt: new Date(response.created_at),');
|
|
90
|
-
expect(content).toContain(' externalId: response.external_id ?? null,');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('generates nested model deserialization', () => {
|
|
94
|
-
const service: Service = {
|
|
95
|
-
name: 'Organizations',
|
|
96
|
-
operations: [
|
|
97
|
-
{
|
|
98
|
-
name: 'getOrganization',
|
|
99
|
-
httpMethod: 'get',
|
|
100
|
-
path: '/organizations/{id}',
|
|
101
|
-
pathParams: [
|
|
102
|
-
{
|
|
103
|
-
name: 'id',
|
|
104
|
-
type: { kind: 'primitive', type: 'string' },
|
|
105
|
-
required: true,
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
queryParams: [],
|
|
109
|
-
headerParams: [],
|
|
110
|
-
response: { kind: 'model', name: 'Organization' },
|
|
111
|
-
errors: [],
|
|
112
|
-
injectIdempotencyKey: false,
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const models: Model[] = [
|
|
118
|
-
{
|
|
119
|
-
name: 'Organization',
|
|
120
|
-
fields: [
|
|
121
|
-
{
|
|
122
|
-
name: 'id',
|
|
123
|
-
type: { kind: 'primitive', type: 'string' },
|
|
124
|
-
required: true,
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
name: 'domains',
|
|
128
|
-
type: {
|
|
129
|
-
kind: 'array',
|
|
130
|
-
items: { kind: 'model', name: 'OrganizationDomain' },
|
|
131
|
-
},
|
|
132
|
-
required: true,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
name: 'OrganizationDomain',
|
|
138
|
-
fields: [
|
|
139
|
-
{
|
|
140
|
-
name: 'id',
|
|
141
|
-
type: { kind: 'primitive', type: 'string' },
|
|
142
|
-
required: true,
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
},
|
|
146
|
-
];
|
|
147
|
-
|
|
148
|
-
const ctxWithServices: EmitterContext = {
|
|
149
|
-
...ctx,
|
|
150
|
-
spec: { ...emptySpec, services: [service], models },
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const files = generateSerializers(models, ctxWithServices);
|
|
154
|
-
const orgSerializer = files.find((f) => f.path.includes('organization.serializer.ts'))!;
|
|
155
|
-
|
|
156
|
-
expect(orgSerializer.content).toContain('domains: response.domains.map(deserializeOrganizationDomain),');
|
|
157
|
-
expect(orgSerializer.content).toContain('import { deserializeOrganizationDomain, serializeOrganizationDomain }');
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('preserves null fallback for optional nullable model fields', () => {
|
|
161
|
-
const service: Service = {
|
|
162
|
-
name: 'Organizations',
|
|
163
|
-
operations: [
|
|
164
|
-
{
|
|
165
|
-
name: 'getOrganization',
|
|
166
|
-
httpMethod: 'get',
|
|
167
|
-
path: '/organizations/{id}',
|
|
168
|
-
pathParams: [
|
|
169
|
-
{
|
|
170
|
-
name: 'id',
|
|
171
|
-
type: { kind: 'primitive', type: 'string' },
|
|
172
|
-
required: true,
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
queryParams: [],
|
|
176
|
-
headerParams: [],
|
|
177
|
-
response: { kind: 'model', name: 'Organization' },
|
|
178
|
-
errors: [],
|
|
179
|
-
injectIdempotencyKey: false,
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const models: Model[] = [
|
|
185
|
-
{
|
|
186
|
-
name: 'Organization',
|
|
187
|
-
fields: [
|
|
188
|
-
{
|
|
189
|
-
name: 'id',
|
|
190
|
-
type: { kind: 'primitive', type: 'string' },
|
|
191
|
-
required: true,
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: 'parent',
|
|
195
|
-
type: {
|
|
196
|
-
kind: 'nullable',
|
|
197
|
-
inner: { kind: 'model', name: 'ParentOrg' },
|
|
198
|
-
},
|
|
199
|
-
required: false,
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
name: 'ParentOrg',
|
|
205
|
-
fields: [
|
|
206
|
-
{
|
|
207
|
-
name: 'id',
|
|
208
|
-
type: { kind: 'primitive', type: 'string' },
|
|
209
|
-
required: true,
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
},
|
|
213
|
-
];
|
|
214
|
-
|
|
215
|
-
const ctxWithServices: EmitterContext = {
|
|
216
|
-
...ctx,
|
|
217
|
-
spec: { ...emptySpec, services: [service], models },
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const files = generateSerializers(models, ctxWithServices);
|
|
221
|
-
const orgSerializer = files.find((f) => f.path.includes('organization.serializer.ts'))!;
|
|
222
|
-
const content = orgSerializer.content;
|
|
223
|
-
|
|
224
|
-
// Deserialize: optional nullable model field should fall back to null, not undefined
|
|
225
|
-
expect(content).toContain('parent: response.parent != null ?');
|
|
226
|
-
expect(content).toContain(': null,');
|
|
227
|
-
expect(content).not.toMatch(/parent:.*: undefined,/);
|
|
228
|
-
|
|
229
|
-
// Serialize: optional nullable model field should fall back to null, not undefined
|
|
230
|
-
expect(content).toContain('parent: model.parent != null ?');
|
|
231
|
-
// Ensure the serialize side also uses null fallback
|
|
232
|
-
const serializeSection = content.split('serializeOrganization')[1];
|
|
233
|
-
expect(serializeSection).toContain(': null,');
|
|
234
|
-
expect(serializeSection).not.toMatch(/parent:.*: undefined/);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('generates serialize function for request body models', () => {
|
|
238
|
-
const service: Service = {
|
|
239
|
-
name: 'Organizations',
|
|
240
|
-
operations: [
|
|
241
|
-
{
|
|
242
|
-
name: 'createOrganization',
|
|
243
|
-
httpMethod: 'post',
|
|
244
|
-
path: '/organizations',
|
|
245
|
-
pathParams: [],
|
|
246
|
-
queryParams: [],
|
|
247
|
-
headerParams: [],
|
|
248
|
-
requestBody: { kind: 'model', name: 'CreateOrganizationInput' },
|
|
249
|
-
response: { kind: 'model', name: 'Organization' },
|
|
250
|
-
errors: [],
|
|
251
|
-
injectIdempotencyKey: false,
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const models: Model[] = [
|
|
257
|
-
{
|
|
258
|
-
name: 'Organization',
|
|
259
|
-
fields: [
|
|
260
|
-
{
|
|
261
|
-
name: 'id',
|
|
262
|
-
type: { kind: 'primitive', type: 'string' },
|
|
263
|
-
required: true,
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
name: 'CreateOrganizationInput',
|
|
269
|
-
fields: [
|
|
270
|
-
{
|
|
271
|
-
name: 'name',
|
|
272
|
-
type: { kind: 'primitive', type: 'string' },
|
|
273
|
-
required: true,
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
name: 'external_id',
|
|
277
|
-
type: { kind: 'primitive', type: 'string' },
|
|
278
|
-
required: false,
|
|
279
|
-
},
|
|
280
|
-
],
|
|
281
|
-
},
|
|
282
|
-
];
|
|
283
|
-
|
|
284
|
-
const ctxWithServices: EmitterContext = {
|
|
285
|
-
...ctx,
|
|
286
|
-
spec: { ...emptySpec, services: [service], models },
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
const files = generateSerializers(models, ctxWithServices);
|
|
290
|
-
const inputSerializer = files.find((f) => f.path.includes('create-organization-input.serializer.ts'))!;
|
|
291
|
-
|
|
292
|
-
// Should have both deserialize AND serialize
|
|
293
|
-
expect(inputSerializer.content).toContain('export const deserializeCreateOrganizationInput');
|
|
294
|
-
expect(inputSerializer.content).toContain('export const serializeCreateOrganizationInput');
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('skips per-domain ListMetadata serializers (Fix #5)', () => {
|
|
298
|
-
const service: Service = {
|
|
299
|
-
name: 'Connections',
|
|
300
|
-
operations: [
|
|
301
|
-
{
|
|
302
|
-
name: 'listConnections',
|
|
303
|
-
httpMethod: 'get',
|
|
304
|
-
path: '/connections',
|
|
305
|
-
pathParams: [],
|
|
306
|
-
queryParams: [],
|
|
307
|
-
headerParams: [],
|
|
308
|
-
response: { kind: 'model', name: 'ConnectionList' },
|
|
309
|
-
errors: [],
|
|
310
|
-
injectIdempotencyKey: false,
|
|
311
|
-
pagination: {
|
|
312
|
-
strategy: 'cursor',
|
|
313
|
-
param: 'after',
|
|
314
|
-
itemType: { kind: 'model', name: 'Connection' },
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
],
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
const models: Model[] = [
|
|
321
|
-
{
|
|
322
|
-
name: 'ConnectionListListMetadata',
|
|
323
|
-
fields: [
|
|
324
|
-
{
|
|
325
|
-
name: 'before',
|
|
326
|
-
type: {
|
|
327
|
-
kind: 'nullable',
|
|
328
|
-
inner: { kind: 'primitive', type: 'string' },
|
|
329
|
-
},
|
|
330
|
-
required: false,
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
name: 'after',
|
|
334
|
-
type: {
|
|
335
|
-
kind: 'nullable',
|
|
336
|
-
inner: { kind: 'primitive', type: 'string' },
|
|
337
|
-
},
|
|
338
|
-
required: false,
|
|
339
|
-
},
|
|
340
|
-
],
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
name: 'Connection',
|
|
344
|
-
fields: [
|
|
345
|
-
{
|
|
346
|
-
name: 'id',
|
|
347
|
-
type: { kind: 'primitive', type: 'string' },
|
|
348
|
-
required: true,
|
|
349
|
-
},
|
|
350
|
-
],
|
|
351
|
-
},
|
|
352
|
-
];
|
|
353
|
-
|
|
354
|
-
const ctxWithServices: EmitterContext = {
|
|
355
|
-
...ctx,
|
|
356
|
-
spec: { ...emptySpec, services: [service], models },
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const files = generateSerializers(models, ctxWithServices);
|
|
360
|
-
|
|
361
|
-
// The ListMetadata serializer should be skipped
|
|
362
|
-
const listMetadataSerializer = files.find((f) => f.path.includes('list-metadata'));
|
|
363
|
-
expect(listMetadataSerializer).toBeUndefined();
|
|
364
|
-
|
|
365
|
-
// The Connection serializer should still be generated
|
|
366
|
-
const connectionSerializer = files.find((f) => f.path.includes('connection.serializer.ts'));
|
|
367
|
-
expect(connectionSerializer).toBeDefined();
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
it('skips per-domain list wrapper serializers (Fix #7)', () => {
|
|
371
|
-
const service: Service = {
|
|
372
|
-
name: 'Connections',
|
|
373
|
-
operations: [
|
|
374
|
-
{
|
|
375
|
-
name: 'listConnections',
|
|
376
|
-
httpMethod: 'get',
|
|
377
|
-
path: '/connections',
|
|
378
|
-
pathParams: [],
|
|
379
|
-
queryParams: [],
|
|
380
|
-
headerParams: [],
|
|
381
|
-
response: { kind: 'model', name: 'ConnectionList' },
|
|
382
|
-
errors: [],
|
|
383
|
-
injectIdempotencyKey: false,
|
|
384
|
-
pagination: {
|
|
385
|
-
strategy: 'cursor',
|
|
386
|
-
param: 'after',
|
|
387
|
-
itemType: { kind: 'model', name: 'Connection' },
|
|
388
|
-
},
|
|
389
|
-
},
|
|
390
|
-
],
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
const models: Model[] = [
|
|
394
|
-
{
|
|
395
|
-
name: 'ConnectionList',
|
|
396
|
-
fields: [
|
|
397
|
-
{
|
|
398
|
-
name: 'object',
|
|
399
|
-
type: { kind: 'literal', value: 'list' },
|
|
400
|
-
required: true,
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
name: 'data',
|
|
404
|
-
type: {
|
|
405
|
-
kind: 'array',
|
|
406
|
-
items: { kind: 'model', name: 'Connection' },
|
|
407
|
-
},
|
|
408
|
-
required: true,
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
name: 'list_metadata',
|
|
412
|
-
type: { kind: 'model', name: 'ConnectionListListMetadata' },
|
|
413
|
-
required: true,
|
|
414
|
-
},
|
|
415
|
-
],
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
name: 'Connection',
|
|
419
|
-
fields: [
|
|
420
|
-
{
|
|
421
|
-
name: 'id',
|
|
422
|
-
type: { kind: 'primitive', type: 'string' },
|
|
423
|
-
required: true,
|
|
424
|
-
},
|
|
425
|
-
],
|
|
426
|
-
},
|
|
427
|
-
];
|
|
428
|
-
|
|
429
|
-
const ctxWithServices: EmitterContext = {
|
|
430
|
-
...ctx,
|
|
431
|
-
spec: { ...emptySpec, services: [service], models },
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
const files = generateSerializers(models, ctxWithServices);
|
|
435
|
-
|
|
436
|
-
// The list wrapper serializer should be skipped
|
|
437
|
-
const listSerializer = files.find((f) => f.path.includes('connection-list.serializer.ts'));
|
|
438
|
-
expect(listSerializer).toBeUndefined();
|
|
439
|
-
|
|
440
|
-
// The Connection serializer should still be generated
|
|
441
|
-
const connectionSerializer = files.find((f) => f.path.includes('connection.serializer.ts'));
|
|
442
|
-
expect(connectionSerializer).toBeDefined();
|
|
443
|
-
});
|
|
444
|
-
});
|