@workos/oagen-emitters 0.0.1 → 0.2.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.
Files changed (41) 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/.prettierignore +1 -0
  6. package/.release-please-manifest.json +3 -0
  7. package/.vscode/settings.json +3 -0
  8. package/CHANGELOG.md +54 -0
  9. package/README.md +2 -2
  10. package/dist/index.d.mts +7 -0
  11. package/dist/index.d.mts.map +1 -0
  12. package/dist/index.mjs +3522 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/package.json +14 -18
  15. package/release-please-config.json +11 -0
  16. package/src/node/client.ts +437 -204
  17. package/src/node/common.ts +74 -4
  18. package/src/node/config.ts +1 -0
  19. package/src/node/enums.ts +50 -6
  20. package/src/node/errors.ts +78 -3
  21. package/src/node/fixtures.ts +84 -15
  22. package/src/node/index.ts +2 -2
  23. package/src/node/manifest.ts +4 -2
  24. package/src/node/models.ts +195 -79
  25. package/src/node/naming.ts +16 -1
  26. package/src/node/resources.ts +721 -106
  27. package/src/node/serializers.ts +510 -52
  28. package/src/node/tests.ts +621 -105
  29. package/src/node/type-map.ts +89 -11
  30. package/src/node/utils.ts +377 -114
  31. package/test/node/client.test.ts +979 -15
  32. package/test/node/enums.test.ts +0 -1
  33. package/test/node/errors.test.ts +4 -21
  34. package/test/node/models.test.ts +409 -2
  35. package/test/node/naming.test.ts +0 -3
  36. package/test/node/resources.test.ts +964 -7
  37. package/test/node/serializers.test.ts +212 -3
  38. package/tsconfig.json +2 -3
  39. package/{tsup.config.ts → tsdown.config.ts} +1 -1
  40. package/dist/index.d.ts +0 -5
  41. 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', () => {
@@ -78,8 +77,8 @@ describe('generateSerializers', () => {
78
77
 
79
78
  const content = files[0].content;
80
79
  expect(content).toContain('export const deserializeOrganization');
81
- expect(content).toContain(" id: response.id ?? '',");
82
- expect(content).toContain(" createdAt: response.created_at ?? '',");
80
+ expect(content).toContain(' id: response.id,');
81
+ expect(content).toContain(' createdAt: new Date(response.created_at),');
83
82
  expect(content).toContain(' externalId: response.external_id ?? null,');
84
83
  });
85
84
 
@@ -144,6 +143,77 @@ describe('generateSerializers', () => {
144
143
  expect(orgSerializer.content).toContain('import { deserializeOrganizationDomain, serializeOrganizationDomain }');
145
144
  });
146
145
 
146
+ it('preserves null fallback for optional nullable model fields', () => {
147
+ const service: Service = {
148
+ name: 'Organizations',
149
+ operations: [
150
+ {
151
+ name: 'getOrganization',
152
+ httpMethod: 'get',
153
+ path: '/organizations/{id}',
154
+ pathParams: [{ name: 'id', type: { kind: 'primitive', type: 'string' }, required: true }],
155
+ queryParams: [],
156
+ headerParams: [],
157
+ response: { kind: 'model', name: 'Organization' },
158
+ errors: [],
159
+ injectIdempotencyKey: false,
160
+ },
161
+ ],
162
+ };
163
+
164
+ const models: Model[] = [
165
+ {
166
+ name: 'Organization',
167
+ fields: [
168
+ {
169
+ name: 'id',
170
+ type: { kind: 'primitive', type: 'string' },
171
+ required: true,
172
+ },
173
+ {
174
+ name: 'parent',
175
+ type: {
176
+ kind: 'nullable',
177
+ inner: { kind: 'model', name: 'ParentOrg' },
178
+ },
179
+ required: false,
180
+ },
181
+ ],
182
+ },
183
+ {
184
+ name: 'ParentOrg',
185
+ fields: [
186
+ {
187
+ name: 'id',
188
+ type: { kind: 'primitive', type: 'string' },
189
+ required: true,
190
+ },
191
+ ],
192
+ },
193
+ ];
194
+
195
+ const ctxWithServices: EmitterContext = {
196
+ ...ctx,
197
+ spec: { ...emptySpec, services: [service], models },
198
+ };
199
+
200
+ const files = generateSerializers(models, ctxWithServices);
201
+ const orgSerializer = files.find((f) => f.path.includes('organization.serializer.ts'))!;
202
+ const content = orgSerializer.content;
203
+
204
+ // Deserialize: optional nullable model field should fall back to null, not undefined
205
+ expect(content).toContain('parent: response.parent != null ?');
206
+ expect(content).toContain(': null,');
207
+ expect(content).not.toMatch(/parent:.*: undefined,/);
208
+
209
+ // Serialize: optional nullable model field should fall back to null, not undefined
210
+ expect(content).toContain('parent: model.parent != null ?');
211
+ // Ensure the serialize side also uses null fallback
212
+ const serializeSection = content.split('serializeOrganization')[1];
213
+ expect(serializeSection).toContain(': null,');
214
+ expect(serializeSection).not.toMatch(/parent:.*: undefined/);
215
+ });
216
+
147
217
  it('generates serialize function for request body models', () => {
148
218
  const service: Service = {
149
219
  name: 'Organizations',
@@ -203,4 +273,143 @@ describe('generateSerializers', () => {
203
273
  expect(inputSerializer.content).toContain('export const deserializeCreateOrganizationInput');
204
274
  expect(inputSerializer.content).toContain('export const serializeCreateOrganizationInput');
205
275
  });
276
+
277
+ it('skips per-domain ListMetadata serializers (Fix #5)', () => {
278
+ const service: Service = {
279
+ name: 'Connections',
280
+ operations: [
281
+ {
282
+ name: 'listConnections',
283
+ httpMethod: 'get',
284
+ path: '/connections',
285
+ pathParams: [],
286
+ queryParams: [],
287
+ headerParams: [],
288
+ response: { kind: 'model', name: 'ConnectionList' },
289
+ errors: [],
290
+ injectIdempotencyKey: false,
291
+ pagination: {
292
+ strategy: 'cursor',
293
+ param: 'after',
294
+ itemType: { kind: 'model', name: 'Connection' },
295
+ },
296
+ },
297
+ ],
298
+ };
299
+
300
+ const models: Model[] = [
301
+ {
302
+ name: 'ConnectionListListMetadata',
303
+ fields: [
304
+ {
305
+ name: 'before',
306
+ type: { kind: 'nullable', inner: { kind: 'primitive', type: 'string' } },
307
+ required: false,
308
+ },
309
+ {
310
+ name: 'after',
311
+ type: { kind: 'nullable', inner: { kind: 'primitive', type: 'string' } },
312
+ required: false,
313
+ },
314
+ ],
315
+ },
316
+ {
317
+ name: 'Connection',
318
+ fields: [
319
+ {
320
+ name: 'id',
321
+ type: { kind: 'primitive', type: 'string' },
322
+ required: true,
323
+ },
324
+ ],
325
+ },
326
+ ];
327
+
328
+ const ctxWithServices: EmitterContext = {
329
+ ...ctx,
330
+ spec: { ...emptySpec, services: [service], models },
331
+ };
332
+
333
+ const files = generateSerializers(models, ctxWithServices);
334
+
335
+ // The ListMetadata serializer should be skipped
336
+ const listMetadataSerializer = files.find((f) => f.path.includes('list-metadata'));
337
+ expect(listMetadataSerializer).toBeUndefined();
338
+
339
+ // The Connection serializer should still be generated
340
+ const connectionSerializer = files.find((f) => f.path.includes('connection.serializer.ts'));
341
+ expect(connectionSerializer).toBeDefined();
342
+ });
343
+
344
+ it('skips per-domain list wrapper serializers (Fix #7)', () => {
345
+ const service: Service = {
346
+ name: 'Connections',
347
+ operations: [
348
+ {
349
+ name: 'listConnections',
350
+ httpMethod: 'get',
351
+ path: '/connections',
352
+ pathParams: [],
353
+ queryParams: [],
354
+ headerParams: [],
355
+ response: { kind: 'model', name: 'ConnectionList' },
356
+ errors: [],
357
+ injectIdempotencyKey: false,
358
+ pagination: {
359
+ strategy: 'cursor',
360
+ param: 'after',
361
+ itemType: { kind: 'model', name: 'Connection' },
362
+ },
363
+ },
364
+ ],
365
+ };
366
+
367
+ const models: Model[] = [
368
+ {
369
+ name: 'ConnectionList',
370
+ fields: [
371
+ {
372
+ name: 'object',
373
+ type: { kind: 'literal', value: 'list' },
374
+ required: true,
375
+ },
376
+ {
377
+ name: 'data',
378
+ type: { kind: 'array', items: { kind: 'model', name: 'Connection' } },
379
+ required: true,
380
+ },
381
+ {
382
+ name: 'list_metadata',
383
+ type: { kind: 'model', name: 'ConnectionListListMetadata' },
384
+ required: true,
385
+ },
386
+ ],
387
+ },
388
+ {
389
+ name: 'Connection',
390
+ fields: [
391
+ {
392
+ name: 'id',
393
+ type: { kind: 'primitive', type: 'string' },
394
+ required: true,
395
+ },
396
+ ],
397
+ },
398
+ ];
399
+
400
+ const ctxWithServices: EmitterContext = {
401
+ ...ctx,
402
+ spec: { ...emptySpec, services: [service], models },
403
+ };
404
+
405
+ const files = generateSerializers(models, ctxWithServices);
406
+
407
+ // The list wrapper serializer should be skipped
408
+ const listSerializer = files.find((f) => f.path.includes('connection-list.serializer.ts'));
409
+ expect(listSerializer).toBeUndefined();
410
+
411
+ // The Connection serializer should still be generated
412
+ const connectionSerializer = files.find((f) => f.path.includes('connection.serializer.ts'));
413
+ expect(connectionSerializer).toBeDefined();
414
+ });
206
415
  });
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 };