@workos/oagen-emitters 0.12.3 → 0.12.4

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/dist/plugin.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as workosEmittersPlugin } from "./plugin-D2N2ZT5W.mjs";
1
+ import { t as workosEmittersPlugin } from "./plugin-nmiHN7Ko.mjs";
2
2
  export { workosEmittersPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workos/oagen-emitters",
3
- "version": "0.12.3",
3
+ "version": "0.12.4",
4
4
  "description": "WorkOS' oagen emitters",
5
5
  "license": "MIT",
6
6
  "author": "WorkOS",
@@ -813,6 +813,41 @@ export function generateSerializers(
813
813
 
814
814
  (ctx as any)._skippedSerializeModels = skippedSerializeModels;
815
815
 
816
+ // Emit a `serializers/index.ts` barrel per directory that received serializer
817
+ // files in this pass. Mirrors the per-service `interfaces/index.ts` barrel so
818
+ // consumers can `import { ... } from './serializers'` rather than reaching
819
+ // into individual `.serializer.ts` files. Also includes any pre-existing
820
+ // `*.serializer.ts` files in the same directory (e.g. hand-written option
821
+ // serializers in an owned service) so we don't strand them from the barrel.
822
+ const serializersByDir = new Map<string, Set<string>>();
823
+ for (const f of files) {
824
+ const match = f.path.match(/^src\/([^/]+)\/serializers\/(.+)\.serializer\.ts$/);
825
+ if (!match) continue;
826
+ const [, dir, stem] = match;
827
+ if (!serializersByDir.has(dir)) serializersByDir.set(dir, new Set());
828
+ serializersByDir.get(dir)!.add(stem);
829
+ }
830
+ const liveRootForBarrel = ctx.outputDir ?? ctx.targetDir;
831
+ for (const [dir, stems] of serializersByDir) {
832
+ if (liveRootForBarrel) {
833
+ const serializersDir = path.join(liveRootForBarrel, 'src', dir, 'serializers');
834
+ try {
835
+ for (const entry of fs.readdirSync(serializersDir)) {
836
+ if (!entry.endsWith('.serializer.ts')) continue;
837
+ stems.add(entry.replace(/\.serializer\.ts$/, ''));
838
+ }
839
+ } catch {
840
+ // Directory doesn't exist yet — only this-pass serializers will appear.
841
+ }
842
+ }
843
+ const lines = [...stems].sort().map((stem) => `export * from './${stem}.serializer';`);
844
+ files.push({
845
+ path: `src/${dir}/serializers/index.ts`,
846
+ content: lines.join('\n') + '\n',
847
+ overwriteExisting: true,
848
+ });
849
+ }
850
+
816
851
  return files;
817
852
  }
818
853
 
@@ -558,4 +558,36 @@ describe('generateSerializers', () => {
558
558
  fs.rmSync(tmpRoot, { recursive: true, force: true });
559
559
  }
560
560
  });
561
+
562
+ it('emits a serializers/index.ts barrel listing every emitted serializer', () => {
563
+ const models: Model[] = [
564
+ {
565
+ name: 'Organization',
566
+ fields: [{ name: 'id', type: { kind: 'primitive', type: 'string' }, required: true }],
567
+ },
568
+ {
569
+ name: 'OrganizationMember',
570
+ fields: [{ name: 'id', type: { kind: 'primitive', type: 'string' }, required: true }],
571
+ },
572
+ ];
573
+
574
+ const spec = makeSpec(models);
575
+ const ctxWithModels: EmitterContext = { ...ctx, spec };
576
+ const result = generateSerializers(models, ctxWithModels);
577
+
578
+ const serializerFiles = result.filter((f) => f.path.endsWith('.serializer.ts'));
579
+ expect(serializerFiles.length).toBeGreaterThan(0);
580
+
581
+ // Every emitted serializer file should appear in a barrel at the same
582
+ // directory's `serializers/index.ts`.
583
+ for (const sf of serializerFiles) {
584
+ const match = sf.path.match(/^src\/([^/]+)\/serializers\/(.+)\.serializer\.ts$/);
585
+ expect(match).not.toBeNull();
586
+ const [, dir, stem] = match!;
587
+ const barrel = result.find((f) => f.path === `src/${dir}/serializers/index.ts`);
588
+ expect(barrel, `expected barrel for ${dir}`).toBeDefined();
589
+ expect(barrel!.content).toContain(`export * from './${stem}.serializer';`);
590
+ expect(barrel!.overwriteExisting).toBe(true);
591
+ }
592
+ });
561
593
  });