@platformatic/sql-mapper 0.26.1 → 0.28.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.
package/mapper.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { FastifyPluginAsync } from 'fastify'
1
+ import { FastifyPluginAsync, FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
2
+ import type { PlatformaticApp } from '@platformatic/types'
2
3
  import { SQL, SQLQuery } from '@databases/sql'
3
4
 
4
5
  interface ILogger {
@@ -306,9 +307,37 @@ export interface SQLMapperPluginInterface {
306
307
  addEntityHooks(entityName: string, hooks: EntityHooks): any
307
308
  }
308
309
 
310
+ // Extend the PlatformaticApp interface,
311
+ // Unfortunately we neeed to copy over all the types from SQLMapperPluginInterface
312
+ declare module '@platformatic/types' {
313
+ interface PlatformaticApp {
314
+ /**
315
+ * A Database abstraction layer from [@Databases](https://www.atdatabases.org/)
316
+ */
317
+ db: Database,
318
+ /**
319
+ * The SQL builder from [@Databases](https://www.atdatabases.org/)
320
+ */
321
+ sql: SQL,
322
+ /**
323
+ * An object containing a key for each table found in the schema, with basic CRUD operations. See [entity.md](./entity.md) for details.
324
+ */
325
+ entities: Entities,
326
+ /**
327
+ * Adds hooks to the entity.
328
+ */
329
+ addEntityHooks(entityName: string, hooks: EntityHooks): any
330
+ }
331
+ }
332
+
333
+ export interface PlatformaticContext {
334
+ app: FastifyInstance,
335
+ reply: FastifyReply
336
+ }
337
+
309
338
  declare module 'fastify' {
310
- interface FastifyInstance {
311
- platformatic: SQLMapperPluginInterface
339
+ interface FastifyRequest {
340
+ platformaticContext: PlatformaticContext
312
341
  }
313
342
  }
314
343
 
@@ -328,3 +357,4 @@ export default plugin
328
357
  export module utils {
329
358
  export function toSingular(str: string): string
330
359
  }
360
+
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@platformatic/sql-mapper",
3
- "version": "0.26.1",
3
+ "version": "0.28.1",
4
4
  "description": "A data mapper utility for SQL databases",
5
5
  "main": "mapper.js",
6
+ "types": "mapper.d.ts",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/platformatic/platformatic.git"
@@ -14,10 +15,10 @@
14
15
  },
15
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
16
17
  "devDependencies": {
17
- "fastify": "^4.17.0",
18
+ "fastify": "^4.18.0",
18
19
  "snazzy": "^9.0.0",
19
- "standard": "^17.0.0",
20
- "tap": "^16.3.4",
20
+ "standard": "^17.1.0",
21
+ "tap": "^16.3.6",
21
22
  "tsd": "^0.28.1"
22
23
  },
23
24
  "dependencies": {
@@ -27,7 +28,8 @@
27
28
  "@databases/sqlite": "^4.0.2",
28
29
  "camelcase": "^6.3.0",
29
30
  "fastify-plugin": "^4.5.0",
30
- "inflected": "^2.1.0"
31
+ "inflected": "^2.1.0",
32
+ "@platformatic/types": "0.28.1"
31
33
  },
32
34
  "tsd": {
33
35
  "directory": "test/types"
@@ -1,3 +1,4 @@
1
+ 'use strict'
1
2
 
2
3
  const { test } = require('tap')
3
4
  const { connect, plugin } = require('..')
@@ -1,6 +1,6 @@
1
1
  import { expectType } from 'tsd'
2
2
  import { SQL, SQLQuery } from '@databases/sql'
3
- import { fastify, FastifyInstance } from 'fastify'
3
+ import { fastify, FastifyInstance, FastifyReply } from 'fastify'
4
4
  import {
5
5
  connect,
6
6
  plugin,
@@ -72,6 +72,13 @@ expectType<SQLMapperPluginInterface>(await connect({
72
72
 
73
73
  const instance: FastifyInstance = fastify()
74
74
  instance.register(plugin, { connectionString: '', autoTimestamp: true })
75
- instance.register((instance) => { expectType<SQLMapperPluginInterface>(instance.platformatic) })
75
+ instance.register((instance) => {
76
+ expectType<SQLMapperPluginInterface>(instance.platformatic)
77
+ instance.get('/', async (request, reply) => {
78
+ const ctx = request.platformaticContext
79
+ expectType<FastifyInstance>(ctx.app)
80
+ expectType<FastifyReply>(ctx.reply)
81
+ })
82
+ })
76
83
 
77
84
  expectType<(str: string) => string>(utils.toSingular)