@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.
- 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/.prettierignore +1 -0
- package/.release-please-manifest.json +3 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +54 -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 +3522 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -18
- package/release-please-config.json +11 -0
- package/src/node/client.ts +437 -204
- package/src/node/common.ts +74 -4
- package/src/node/config.ts +1 -0
- package/src/node/enums.ts +50 -6
- package/src/node/errors.ts +78 -3
- package/src/node/fixtures.ts +84 -15
- package/src/node/index.ts +2 -2
- package/src/node/manifest.ts +4 -2
- package/src/node/models.ts +195 -79
- package/src/node/naming.ts +16 -1
- package/src/node/resources.ts +721 -106
- package/src/node/serializers.ts +510 -52
- package/src/node/tests.ts +621 -105
- package/src/node/type-map.ts +89 -11
- package/src/node/utils.ts +377 -114
- package/test/node/client.test.ts +979 -15
- package/test/node/enums.test.ts +0 -1
- package/test/node/errors.test.ts +4 -21
- package/test/node/models.test.ts +409 -2
- package/test/node/naming.test.ts +0 -3
- package/test/node/resources.test.ts +964 -7
- package/test/node/serializers.test.ts +212 -3
- 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
|
@@ -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(
|
|
82
|
-
expect(content).toContain(
|
|
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": "
|
|
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"]
|