@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.
Files changed (49) hide show
  1. package/.github/workflows/release-please.yml +9 -1
  2. package/.husky/commit-msg +0 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.husky/pre-push +1 -0
  5. package/.oxfmtrc.json +8 -1
  6. package/.prettierignore +1 -0
  7. package/.release-please-manifest.json +3 -0
  8. package/.vscode/settings.json +3 -0
  9. package/CHANGELOG.md +61 -0
  10. package/README.md +2 -2
  11. package/dist/index.d.mts +7 -0
  12. package/dist/index.d.mts.map +1 -0
  13. package/dist/index.mjs +4070 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/package.json +14 -18
  16. package/release-please-config.json +11 -0
  17. package/smoke/sdk-dotnet.ts +17 -3
  18. package/smoke/sdk-elixir.ts +17 -3
  19. package/smoke/sdk-go.ts +21 -4
  20. package/smoke/sdk-kotlin.ts +23 -4
  21. package/smoke/sdk-node.ts +15 -3
  22. package/smoke/sdk-ruby.ts +17 -3
  23. package/smoke/sdk-rust.ts +16 -3
  24. package/src/node/client.ts +521 -206
  25. package/src/node/common.ts +74 -4
  26. package/src/node/config.ts +1 -0
  27. package/src/node/enums.ts +53 -9
  28. package/src/node/errors.ts +82 -3
  29. package/src/node/fixtures.ts +87 -16
  30. package/src/node/index.ts +66 -10
  31. package/src/node/manifest.ts +4 -2
  32. package/src/node/models.ts +251 -124
  33. package/src/node/naming.ts +107 -3
  34. package/src/node/resources.ts +1162 -108
  35. package/src/node/serializers.ts +512 -52
  36. package/src/node/tests.ts +650 -110
  37. package/src/node/type-map.ts +89 -11
  38. package/src/node/utils.ts +426 -113
  39. package/test/node/client.test.ts +1083 -20
  40. package/test/node/enums.test.ts +73 -4
  41. package/test/node/errors.test.ts +4 -21
  42. package/test/node/models.test.ts +499 -5
  43. package/test/node/naming.test.ts +14 -7
  44. package/test/node/resources.test.ts +1568 -9
  45. package/test/node/serializers.test.ts +241 -5
  46. package/tsconfig.json +2 -3
  47. package/{tsup.config.ts → tsdown.config.ts} +1 -1
  48. package/dist/index.d.ts +0 -5
  49. package/dist/index.js +0 -2158
@@ -15,7 +15,6 @@ const ctx: EmitterContext = {
15
15
  namespace: 'workos',
16
16
  namespacePascal: 'WorkOS',
17
17
  spec: emptySpec,
18
- irVersion: 6,
19
18
  };
20
19
 
21
20
  describe('generateSerializers', () => {
@@ -31,7 +30,13 @@ describe('generateSerializers', () => {
31
30
  name: 'getOrganization',
32
31
  httpMethod: 'get',
33
32
  path: '/organizations/{id}',
34
- pathParams: [{ name: 'id', type: { kind: 'primitive', type: 'string' }, required: true }],
33
+ pathParams: [
34
+ {
35
+ name: 'id',
36
+ type: { kind: 'primitive', type: 'string' },
37
+ required: true,
38
+ },
39
+ ],
35
40
  queryParams: [],
36
41
  headerParams: [],
37
42
  response: { kind: 'model', name: 'Organization' },
@@ -78,8 +83,8 @@ describe('generateSerializers', () => {
78
83
 
79
84
  const content = files[0].content;
80
85
  expect(content).toContain('export const deserializeOrganization');
81
- expect(content).toContain(" id: response.id ?? '',");
82
- expect(content).toContain(" createdAt: response.created_at ?? '',");
86
+ expect(content).toContain(' id: response.id,');
87
+ expect(content).toContain(' createdAt: new Date(response.created_at),');
83
88
  expect(content).toContain(' externalId: response.external_id ?? null,');
84
89
  });
85
90
 
@@ -91,7 +96,13 @@ describe('generateSerializers', () => {
91
96
  name: 'getOrganization',
92
97
  httpMethod: 'get',
93
98
  path: '/organizations/{id}',
94
- pathParams: [{ name: 'id', type: { kind: 'primitive', type: 'string' }, required: true }],
99
+ pathParams: [
100
+ {
101
+ name: 'id',
102
+ type: { kind: 'primitive', type: 'string' },
103
+ required: true,
104
+ },
105
+ ],
95
106
  queryParams: [],
96
107
  headerParams: [],
97
108
  response: { kind: 'model', name: 'Organization' },
@@ -144,6 +155,83 @@ describe('generateSerializers', () => {
144
155
  expect(orgSerializer.content).toContain('import { deserializeOrganizationDomain, serializeOrganizationDomain }');
145
156
  });
146
157
 
158
+ it('preserves null fallback for optional nullable model fields', () => {
159
+ const service: Service = {
160
+ name: 'Organizations',
161
+ operations: [
162
+ {
163
+ name: 'getOrganization',
164
+ httpMethod: 'get',
165
+ path: '/organizations/{id}',
166
+ pathParams: [
167
+ {
168
+ name: 'id',
169
+ type: { kind: 'primitive', type: 'string' },
170
+ required: true,
171
+ },
172
+ ],
173
+ queryParams: [],
174
+ headerParams: [],
175
+ response: { kind: 'model', name: 'Organization' },
176
+ errors: [],
177
+ injectIdempotencyKey: false,
178
+ },
179
+ ],
180
+ };
181
+
182
+ const models: Model[] = [
183
+ {
184
+ name: 'Organization',
185
+ fields: [
186
+ {
187
+ name: 'id',
188
+ type: { kind: 'primitive', type: 'string' },
189
+ required: true,
190
+ },
191
+ {
192
+ name: 'parent',
193
+ type: {
194
+ kind: 'nullable',
195
+ inner: { kind: 'model', name: 'ParentOrg' },
196
+ },
197
+ required: false,
198
+ },
199
+ ],
200
+ },
201
+ {
202
+ name: 'ParentOrg',
203
+ fields: [
204
+ {
205
+ name: 'id',
206
+ type: { kind: 'primitive', type: 'string' },
207
+ required: true,
208
+ },
209
+ ],
210
+ },
211
+ ];
212
+
213
+ const ctxWithServices: EmitterContext = {
214
+ ...ctx,
215
+ spec: { ...emptySpec, services: [service], models },
216
+ };
217
+
218
+ const files = generateSerializers(models, ctxWithServices);
219
+ const orgSerializer = files.find((f) => f.path.includes('organization.serializer.ts'))!;
220
+ const content = orgSerializer.content;
221
+
222
+ // Deserialize: optional nullable model field should fall back to null, not undefined
223
+ expect(content).toContain('parent: response.parent != null ?');
224
+ expect(content).toContain(': null,');
225
+ expect(content).not.toMatch(/parent:.*: undefined,/);
226
+
227
+ // Serialize: optional nullable model field should fall back to null, not undefined
228
+ expect(content).toContain('parent: model.parent != null ?');
229
+ // Ensure the serialize side also uses null fallback
230
+ const serializeSection = content.split('serializeOrganization')[1];
231
+ expect(serializeSection).toContain(': null,');
232
+ expect(serializeSection).not.toMatch(/parent:.*: undefined/);
233
+ });
234
+
147
235
  it('generates serialize function for request body models', () => {
148
236
  const service: Service = {
149
237
  name: 'Organizations',
@@ -203,4 +291,152 @@ describe('generateSerializers', () => {
203
291
  expect(inputSerializer.content).toContain('export const deserializeCreateOrganizationInput');
204
292
  expect(inputSerializer.content).toContain('export const serializeCreateOrganizationInput');
205
293
  });
294
+
295
+ it('skips per-domain ListMetadata serializers (Fix #5)', () => {
296
+ const service: Service = {
297
+ name: 'Connections',
298
+ operations: [
299
+ {
300
+ name: 'listConnections',
301
+ httpMethod: 'get',
302
+ path: '/connections',
303
+ pathParams: [],
304
+ queryParams: [],
305
+ headerParams: [],
306
+ response: { kind: 'model', name: 'ConnectionList' },
307
+ errors: [],
308
+ injectIdempotencyKey: false,
309
+ pagination: {
310
+ strategy: 'cursor',
311
+ param: 'after',
312
+ itemType: { kind: 'model', name: 'Connection' },
313
+ },
314
+ },
315
+ ],
316
+ };
317
+
318
+ const models: Model[] = [
319
+ {
320
+ name: 'ConnectionListListMetadata',
321
+ fields: [
322
+ {
323
+ name: 'before',
324
+ type: {
325
+ kind: 'nullable',
326
+ inner: { kind: 'primitive', type: 'string' },
327
+ },
328
+ required: false,
329
+ },
330
+ {
331
+ name: 'after',
332
+ type: {
333
+ kind: 'nullable',
334
+ inner: { kind: 'primitive', type: 'string' },
335
+ },
336
+ required: false,
337
+ },
338
+ ],
339
+ },
340
+ {
341
+ name: 'Connection',
342
+ fields: [
343
+ {
344
+ name: 'id',
345
+ type: { kind: 'primitive', type: 'string' },
346
+ required: true,
347
+ },
348
+ ],
349
+ },
350
+ ];
351
+
352
+ const ctxWithServices: EmitterContext = {
353
+ ...ctx,
354
+ spec: { ...emptySpec, services: [service], models },
355
+ };
356
+
357
+ const files = generateSerializers(models, ctxWithServices);
358
+
359
+ // The ListMetadata serializer should be skipped
360
+ const listMetadataSerializer = files.find((f) => f.path.includes('list-metadata'));
361
+ expect(listMetadataSerializer).toBeUndefined();
362
+
363
+ // The Connection serializer should still be generated
364
+ const connectionSerializer = files.find((f) => f.path.includes('connection.serializer.ts'));
365
+ expect(connectionSerializer).toBeDefined();
366
+ });
367
+
368
+ it('skips per-domain list wrapper serializers (Fix #7)', () => {
369
+ const service: Service = {
370
+ name: 'Connections',
371
+ operations: [
372
+ {
373
+ name: 'listConnections',
374
+ httpMethod: 'get',
375
+ path: '/connections',
376
+ pathParams: [],
377
+ queryParams: [],
378
+ headerParams: [],
379
+ response: { kind: 'model', name: 'ConnectionList' },
380
+ errors: [],
381
+ injectIdempotencyKey: false,
382
+ pagination: {
383
+ strategy: 'cursor',
384
+ param: 'after',
385
+ itemType: { kind: 'model', name: 'Connection' },
386
+ },
387
+ },
388
+ ],
389
+ };
390
+
391
+ const models: Model[] = [
392
+ {
393
+ name: 'ConnectionList',
394
+ fields: [
395
+ {
396
+ name: 'object',
397
+ type: { kind: 'literal', value: 'list' },
398
+ required: true,
399
+ },
400
+ {
401
+ name: 'data',
402
+ type: {
403
+ kind: 'array',
404
+ items: { kind: 'model', name: 'Connection' },
405
+ },
406
+ required: true,
407
+ },
408
+ {
409
+ name: 'list_metadata',
410
+ type: { kind: 'model', name: 'ConnectionListListMetadata' },
411
+ required: true,
412
+ },
413
+ ],
414
+ },
415
+ {
416
+ name: 'Connection',
417
+ fields: [
418
+ {
419
+ name: 'id',
420
+ type: { kind: 'primitive', type: 'string' },
421
+ required: true,
422
+ },
423
+ ],
424
+ },
425
+ ];
426
+
427
+ const ctxWithServices: EmitterContext = {
428
+ ...ctx,
429
+ spec: { ...emptySpec, services: [service], models },
430
+ };
431
+
432
+ const files = generateSerializers(models, ctxWithServices);
433
+
434
+ // The list wrapper serializer should be skipped
435
+ const listSerializer = files.find((f) => f.path.includes('connection-list.serializer.ts'));
436
+ expect(listSerializer).toBeUndefined();
437
+
438
+ // The Connection serializer should still be generated
439
+ const connectionSerializer = files.find((f) => f.path.includes('connection.serializer.ts'));
440
+ expect(connectionSerializer).toBeDefined();
441
+ });
206
442
  });
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2022",
3
+ "target": "ES2024",
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "bundler",
6
6
  "strict": true,
@@ -12,8 +12,7 @@
12
12
  "esModuleInterop": true,
13
13
  "skipLibCheck": true,
14
14
  "forceConsistentCasingInFileNames": true,
15
- "resolveJsonModule": true,
16
- "isolatedModules": true
15
+ "resolveJsonModule": true
17
16
  },
18
17
  "include": ["src", "test"],
19
18
  "exclude": ["node_modules", "dist"]
@@ -1,4 +1,4 @@
1
- import { defineConfig } from 'tsup';
1
+ import { defineConfig } from 'tsdown';
2
2
  export default defineConfig({
3
3
  entry: { index: 'src/index.ts' },
4
4
  format: ['esm'],
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Emitter } from '@workos/oagen';
2
-
3
- declare const nodeEmitter: Emitter;
4
-
5
- export { nodeEmitter };