Skip to content

Commit 3f06ac9

Browse files
committed
feat(node): add entity property to adapters
1 parent a733f9b commit 3f06ac9

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

examples/with-fastify/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fastify.register(FastifySteno, {
1212
entities: [User, Post]
1313
})
1414

15-
fastify.post('/', { schema: { body: fastify.getSchema('User') } }, (req) => {
15+
fastify.post('/', { schema: { body: { $ref: 'User' } } }, (req) => {
1616
return {
1717
body: req.body,
1818
schema: req.routeSchema
@@ -21,6 +21,5 @@ fastify.post('/', { schema: { body: fastify.getSchema('User') } }, (req) => {
2121

2222
fastify.listen({ host: '0.0.0.0', port: 3000 }, async (err, address) => {
2323
if (err) throw err
24-
console.log(fastify.getSchemas())
2524
console.log(address)
2625
})

packages/fastify/src/plugin.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,23 @@ export class StenoPlugin {
1313
#options: StenoOptions
1414
#provider: NodeProvider
1515

16-
constructor(
17-
fastify: FastifyInstance,
18-
options: StenoOptions,
19-
next: () => void
20-
) {
16+
constructor(fastify: FastifyInstance, options: StenoOptions, done: () => void) {
2117
this.#fastify = fastify
2218
this.#options = options
2319
this.#provider = new NodeProvider(options)
2420

2521
this.#fastify.decorate('steno', {})
2622
this.registerSchemas()
2723

28-
next()
24+
done()
2925
}
3026

31-
static createInstance(
27+
static async createInstance(
3228
fastify: FastifyInstance,
3329
options: StenoOptions,
34-
next: () => void
35-
): StenoPlugin {
36-
return new StenoPlugin(fastify, options, next)
30+
done: () => void
31+
): Promise<StenoPlugin> {
32+
return new StenoPlugin(fastify, options, done)
3733
}
3834

3935
private registerSchemas(options?: IOptions): void {

packages/node/src/adapter/BaseAdapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class BaseAdapter<T> {
99
fileName: string
1010
filePath: string
1111

12+
entity: Steno.Entity<T>
1213
entityTransformer: EntityTransformer<T>
1314
dataTransformer: DataTransformer<T>
1415

@@ -21,6 +22,7 @@ export class BaseAdapter<T> {
2122

2223
constructor(fileName: string, entity: Steno.Entity<T>, initialData?: T) {
2324
this.fileName = fileName
25+
this.entity = entity
2426
this.entityTransformer = entityTransformer(entity)
2527
this.dataTransformer = dataTransformer(this.entityTransformer)
2628

0 commit comments

Comments
 (0)