@creator.co/wapi 1.7.0 → 1.7.1-alpha1

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 (74) hide show
  1. package/.eslintignore +2 -1
  2. package/dist/package-lock.json +11786 -0
  3. package/dist/package.json +6 -4
  4. package/dist/src/Config/Configuration.js +2 -2
  5. package/dist/src/Config/Configuration.js.map +1 -1
  6. package/dist/src/Crypto/JWT.d.ts +1 -1
  7. package/dist/src/Crypto/JWT.js +1 -1
  8. package/dist/src/Crypto/JWT.js.map +1 -1
  9. package/dist/src/Database/DatabaseManager.js +1 -1
  10. package/dist/src/Database/DatabaseManager.js.map +1 -1
  11. package/dist/src/Database/integrations/knex/KnexDatabase.js +1 -1
  12. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
  13. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +2 -2
  14. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
  15. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +3 -3
  16. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +2 -2
  17. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
  18. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +9 -9
  19. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
  20. package/dist/src/Globals.js +1 -1
  21. package/dist/src/Globals.js.map +1 -1
  22. package/dist/src/Logger/Logger.js +3 -3
  23. package/dist/src/Logger/Logger.js.map +1 -1
  24. package/dist/src/Mailer/Mailer.d.ts +1 -1
  25. package/dist/src/Mailer/Mailer.js +2 -2
  26. package/dist/src/Mailer/Mailer.js.map +1 -1
  27. package/dist/src/Publisher/Publisher.js +1 -1
  28. package/dist/src/Publisher/Publisher.js.map +1 -1
  29. package/dist/src/Server/Router.d.ts +1 -1
  30. package/dist/src/Server/lib/container/GenericHandlerEvent.js +1 -1
  31. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  32. package/dist/src/Server/lib/container/Proxy.js +5 -3
  33. package/dist/src/Server/lib/container/Proxy.js.map +1 -1
  34. package/jest.config.ts +1 -0
  35. package/jest.smoke.config.ts +35 -0
  36. package/package.json +6 -4
  37. package/src/Config/Configuration.ts +2 -2
  38. package/src/Crypto/JWT.ts +1 -1
  39. package/src/Database/DatabaseManager.ts +1 -1
  40. package/src/Database/integrations/knex/KnexDatabase.ts +1 -1
  41. package/src/Database/integrations/kysely/KyselyDatabase.ts +2 -2
  42. package/src/Database/integrations/pgsql/PostgresDatabase.ts +4 -4
  43. package/src/Database/integrations/pgsql/PostgresTransaction.ts +8 -8
  44. package/src/Globals.ts +1 -1
  45. package/src/Logger/Logger.ts +3 -3
  46. package/src/Mailer/Mailer.ts +3 -3
  47. package/src/Publisher/Publisher.ts +1 -1
  48. package/src/Server/Router.ts +1 -1
  49. package/src/Server/lib/container/GenericHandlerEvent.ts +1 -1
  50. package/src/Server/lib/container/Proxy.ts +6 -3
  51. package/tests/API/Response.test.ts +1 -0
  52. package/tests/BaseEvent/Transaction.test.ts +1 -0
  53. package/tests/Cache/Redis-client.test.ts +2 -0
  54. package/tests/Cache/Redis-cluster.test.ts +2 -0
  55. package/tests/Database/DatabaseManager.test.ts +4 -3
  56. package/tests/Database/integrations/knex/KnexDatabase.test.ts +1 -0
  57. package/tests/Database/integrations/knex/KnexTransaction.test.ts +1 -0
  58. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +4 -3
  59. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +2 -1
  60. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +3 -2
  61. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +4 -3
  62. package/tests/Logger/Logger.test.ts +1 -0
  63. package/tests/Server/Router.test.ts +1 -0
  64. package/tests/Server/lib/ContainerServer.test.ts +2 -1
  65. package/tests/Server/lib/container/GenericHandler.test.ts +1 -0
  66. package/tests/Server/lib/container/HealthHandler.test.ts +1 -0
  67. package/tests/Server/lib/container/Proxy.test.ts +2 -1
  68. package/tests/Test.utils.ts +2 -1
  69. package/tsconfig.json +3 -1
  70. package/tsconfig.smoke.json +26 -0
  71. package/dist/jest.config.d.ts +0 -3
  72. package/dist/jest.config.js +0 -32
  73. package/dist/jest.config.js.map +0 -1
  74. package/tests/main.test.ts +0 -15
@@ -1,4 +1,4 @@
1
- import { Pool, PoolClient } from 'pg'
1
+ import * as pg from 'pg'
2
2
 
3
3
  import { PostgresDatabase } from './PostgresDatabase'
4
4
  import { Database } from '../../Database'
@@ -8,7 +8,7 @@ import { DatabaseTransaction } from '../../DatabaseTransaction'
8
8
  * A type alias representing a Postgres transaction. It extends the `PostgresTransactionImpl`
9
9
  * interface and includes the `PoolClient` interface.
10
10
  */
11
- export type PostgresTransaction = PostgresTransactionImpl & PoolClient
11
+ export type PostgresTransaction = PostgresTransactionImpl & pg.PoolClient
12
12
 
13
13
  /**
14
14
  * Represents a transaction in a Postgres database.
@@ -18,16 +18,16 @@ export class PostgresTransactionImpl extends DatabaseTransaction {
18
18
  * A Pool object used for writing operations.
19
19
  * @readonly
20
20
  */
21
- public readonly writer: Pool
21
+ public readonly writer: pg.Pool
22
22
  /**
23
23
  * A readonly property representing a pool reader.
24
24
  */
25
- public readonly reader: Pool
25
+ public readonly reader: pg.Pool
26
26
  /**
27
27
  * Represents a database transaction using a PoolClient.
28
28
  * @type {PoolClient}
29
29
  */
30
- protected transaction: PoolClient
30
+ protected transaction: pg.PoolClient
31
31
  /**
32
32
  * A protected property representing a database of type Database<PostgresTransaction>.
33
33
  * This property is used to interact with a Postgres database using transactions.
@@ -39,7 +39,7 @@ export class PostgresTransactionImpl extends DatabaseTransaction {
39
39
  * @param {PostgresDatabase} database - The Postgres database instance.
40
40
  * @param {Pool} [reader] - The reader pool for database operations (optional).
41
41
  */
42
- private constructor(writer: Pool, database: PostgresDatabase, reader?: Pool) {
42
+ private constructor(writer: pg.Pool, database: PostgresDatabase, reader?: pg.Pool) {
43
43
  super(writer, database, reader)
44
44
  }
45
45
 
@@ -51,9 +51,9 @@ export class PostgresTransactionImpl extends DatabaseTransaction {
51
51
  * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction instance.
52
52
  */
53
53
  public static async newTransaction(
54
- writer: Pool,
54
+ writer: pg.Pool,
55
55
  database: PostgresDatabase,
56
- reader?: Pool
56
+ reader?: pg.Pool
57
57
  ): Promise<PostgresTransaction> {
58
58
  const tx = new PostgresTransactionImpl(writer, database, reader)
59
59
  await tx.begin() // defaults to opened
package/src/Globals.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as dotenv from 'dotenv'
1
+ import dotenv from 'dotenv'
2
2
 
3
3
  import Utils from './Util/Utils'
4
4
 
@@ -1,6 +1,6 @@
1
- import * as abind from 'abind'
2
- import * as stringify from 'json-stringify-safe'
3
- import * as stackTrace from 'stack-trace'
1
+ import abind from 'abind'
2
+ import stringify from 'json-stringify-safe'
3
+ import stackTrace from 'stack-trace'
4
4
 
5
5
  import Utils from '../Util/Utils'
6
6
 
@@ -1,8 +1,8 @@
1
1
  import * as SES from '@aws-sdk/client-ses'
2
2
  import { defaultProvider } from '@aws-sdk/credential-provider-node'
3
- import * as Email from 'email-templates'
4
- import * as nodemailer from 'nodemailer'
5
- import type * as SESTransport from 'nodemailer/lib/ses-transport'
3
+ import Email from 'email-templates'
4
+ import nodemailer from 'nodemailer'
5
+ import type SESTransport from 'nodemailer/lib/ses-transport'
6
6
 
7
7
  export default class Mailer {
8
8
  /**
@@ -4,7 +4,7 @@ import {
4
4
  PublishCommandOutput,
5
5
  PublishCommandInput,
6
6
  } from '@aws-sdk/client-sns'
7
- import * as sha1 from 'sha1'
7
+ import sha1 from 'sha1'
8
8
  //reusable client
9
9
  /**
10
10
  * A variable that holds the connection to the SNS client for publishing messages.
@@ -1,6 +1,6 @@
1
1
  import { Server as HTTPServer } from 'http'
2
2
 
3
- import * as express from 'express'
3
+ import express from 'express'
4
4
  import { z } from 'zod'
5
5
 
6
6
  import ContainerServer from './lib/ContainerServer'
@@ -1,5 +1,5 @@
1
1
  import type { APIGatewayProxyEvent, Context } from 'aws-lambda'
2
- import * as cuid from 'cuid'
2
+ import cuid from 'cuid'
3
3
  import { Request } from 'express'
4
4
 
5
5
  import { parseMultiValueQueryStringParameters, parseQueryStringParameters } from './Utils'
@@ -1,16 +1,19 @@
1
+ import fs from 'fs'
1
2
  import { Server as HTTPServer, createServer } from 'http'
2
3
 
3
- import * as cors from 'cors'
4
- import * as express from 'express'
4
+ import cors from 'cors'
5
+ import express from 'express'
5
6
 
6
7
  import Server from './../Server'
7
8
  import GenericHandler from './GenericHandler'
8
9
  import HealthHandler from './HealthHandler'
9
- import { version as appVersion } from '../../../../package.json'
10
10
  import Globals from '../../../Globals'
11
11
  import Utils from '../../../Util/Utils'
12
12
  import { RouterConfig } from '../../Router'
13
13
 
14
+ /* Get package.json version from Wapi on ESM */
15
+ const { version: appVersion } = JSON.parse(fs.readFileSync('package.json').toString())
16
+
14
17
  /**
15
18
  * Represents a Proxy class that handles routing and server functionality.
16
19
  */
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { APIGatewayEvent, Context } from 'aws-lambda'
2
3
  import { expect as c_expect } from 'chai'
3
4
 
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { expect as c_expect } from 'chai'
2
3
 
3
4
  import Response from '../../src/API/Response'
@@ -1,3 +1,5 @@
1
+ import { jest } from '@jest/globals'
2
+
1
3
  import Redis from '../../src/Cache/Redis'
2
4
 
3
5
  let _connectionId = 1
@@ -1,3 +1,5 @@
1
+ import { jest } from '@jest/globals'
2
+
1
3
  import Redis from '../../src/Cache/Redis'
2
4
 
3
5
  let _connectionId = 1
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { expect } from 'chai'
2
3
 
3
4
  import { DatabaseManager } from '../../src/Database'
@@ -17,13 +18,13 @@ describe('Database Manager', () => {
17
18
  const underTest = new DatabaseManager()
18
19
 
19
20
  underTest['databases'] = {
20
- knex: jest.fn(config => {
21
+ knex: jest.fn((config: any) => {
21
22
  return { host: config.host, type: 'knex' } as any
22
23
  }) as any,
23
- pg: jest.fn(config => {
24
+ pg: jest.fn((config: any) => {
24
25
  return { host: config.host, type: 'pg' } as any
25
26
  }) as any,
26
- kysely: jest.fn(config => {
27
+ kysely: jest.fn((config: any) => {
27
28
  return { host: config.host, type: 'kysely' } as any
28
29
  }) as any,
29
30
  }
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { Knex } from 'knex'
2
3
 
3
4
  import type { DbConfig } from '../../../../src/Database'
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { Knex } from 'knex'
2
3
 
3
4
  import { DbConfig } from '../../../../src/Database'
@@ -1,5 +1,6 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { PostgresDialect } from 'kysely'
2
- import { PoolClient } from 'pg'
3
+ import * as pg from 'pg'
3
4
 
4
5
  import type { DbConfig } from '../../../../src/Database'
5
6
  import { KyselyDatabase } from '../../../../src/Database/integrations/kysely/KyselyDatabase'
@@ -38,7 +39,7 @@ describe('KyselyDatabase', () => {
38
39
  let mockPgClient
39
40
  beforeEach(() => {
40
41
  mockTrans = {
41
- execute: jest.fn(async cb => {
42
+ execute: jest.fn(async (cb: any) => {
42
43
  cb(mockTrans)
43
44
  }),
44
45
  } as any
@@ -68,7 +69,7 @@ describe('KyselyDatabase', () => {
68
69
  () =>
69
70
  ({
70
71
  connect: async () => mockPgTrans,
71
- }) as PoolClient
72
+ }) as pg.PoolClient
72
73
  )
73
74
  KyselyDatabase['pgProvider'] = mockPgClient as any
74
75
  })
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { Kysely, Transaction } from 'kysely'
2
3
 
3
4
  import type { DbConfig } from '../../../../src/Database'
@@ -23,7 +24,7 @@ const testResources = async (config: Partial<DbConfig<'kysely'>>) => {
23
24
 
24
25
  const transaction = jest.fn().mockImplementation(() => {
25
26
  return {
26
- execute: jest.fn(async cb => {
27
+ execute: jest.fn(async (cb: any) => {
27
28
  try {
28
29
  await cb(transaction)
29
30
  } catch (e) {
@@ -1,4 +1,5 @@
1
- import { PoolClient } from 'pg'
1
+ import { jest } from '@jest/globals'
2
+ import * as pg from 'pg'
2
3
 
3
4
  import type { DbConfig } from '../../../../src/Database'
4
5
  import { PostgresDatabase } from '../../../../src/Database/integrations/pgsql/PostgresDatabase'
@@ -39,7 +40,7 @@ describe('PostgresDatabase', () => {
39
40
  () =>
40
41
  ({
41
42
  connect: async () => mockTrans,
42
- }) as PoolClient
43
+ }) as pg.PoolClient
43
44
  )
44
45
  PostgresDatabase['pgProvider'] = mockClient as any
45
46
  })
@@ -1,4 +1,5 @@
1
- import { Pool, PoolClient } from 'pg'
1
+ import { jest } from '@jest/globals'
2
+ import * as pg from 'pg'
2
3
 
3
4
  import type { DbConfig } from '../../../../src/Database'
4
5
  import { PostgresDatabase } from '../../../../src/Database/integrations/pgsql/PostgresDatabase'
@@ -18,13 +19,13 @@ const testResources = async (config: Partial<DbConfig<'pg'>>) => {
18
19
  rollback: jest.fn(),
19
20
  query: jest.fn(),
20
21
  }
21
- })() as any as PoolClient
22
+ })() as any as pg.PoolClient
22
23
 
23
24
  const writer = jest.fn().mockImplementation(() => {
24
25
  return {
25
26
  connect: jest.fn(() => transaction),
26
27
  }
27
- })() as any as Pool
28
+ })() as any as pg.Pool
28
29
 
29
30
  return {
30
31
  transaction,
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { expect as c_expect } from 'chai'
2
3
 
3
4
  // get console ref and mock before logger import
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { expect } from 'chai'
2
3
 
3
4
  import ContainerServer from '../../src/Server/lib/ContainerServer'
@@ -1,5 +1,6 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { expect as c_expect } from 'chai'
2
- import * as request from 'supertest'
3
+ import request from 'supertest'
3
4
  import { z } from 'zod'
4
5
 
5
6
  import { HttpMethod } from '../../../src/API/Request'
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { APIGatewayProxyEvent, Context } from 'aws-lambda'
2
3
  import { expect as c_expect } from 'chai'
3
4
  import { Request, Response } from 'express'
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { expect as c_expect } from 'chai'
2
3
  import { Request, Response } from 'express'
3
4
 
@@ -1,6 +1,7 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { APIGatewayProxyEvent, Context } from 'aws-lambda'
2
3
  import { expect as c_expect } from 'chai'
3
- import * as request from 'supertest'
4
+ import request from 'supertest'
4
5
 
5
6
  import Globals from '../../../../src/Globals'
6
7
  import Proxy from '../../../../src/Server/lib/container/Proxy'
@@ -1,3 +1,4 @@
1
+ import { jest } from '@jest/globals'
1
2
  import { APIGatewayEvent, Context, SQSEvent } from 'aws-lambda'
2
3
  import { z } from 'zod'
3
4
 
@@ -68,6 +69,6 @@ export function emptyQueueEvent(data?: any) {
68
69
 
69
70
  export function observableTransaction() {
70
71
  const t = new Transaction(emptyEvent(), observableContext())
71
- t.responseProxy = jest.fn()
72
+ t.responseProxy = jest.fn() as any
72
73
  return t
73
74
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
- "exclude": ["**/*.test.*", "**/__mocks__/*", "**/__tests__/*", "**/tests/*", "./dist/**/*"],
2
+ "exclude": ["**/*.test.*", "**/__mocks__/*", "**/__tests__/*", "**/tests/*", "./dist/**/*", "./smoke-tests/**/*", "./jest*", "./node_modules"],
3
+ "include": ["./**/*", "./package.json", "./package-lock.json"],
3
4
  "compilerOptions": {
4
5
  "lib": [
5
6
  "es5",
@@ -9,6 +10,7 @@
9
10
  "module": "esnext",
10
11
  "target": "es6",
11
12
  "moduleResolution": "node",
13
+ "esModuleInterop": true,
12
14
  "noImplicitAny": false,
13
15
  "noEmitOnError": true,
14
16
  "removeComments": false,
@@ -0,0 +1,26 @@
1
+ {
2
+ "exclude": ["./dist/**/*", "./smoke-tests/**/*", "./node_modules", "./**/Logger.test.*"],
3
+ "include": ["./**/*", "./package.json", "./package-lock.json"],
4
+ "compilerOptions": {
5
+ "lib": [
6
+ "es5",
7
+ "es6",
8
+ "dom"
9
+ ],
10
+ "module": "esnext",
11
+ "target": "es6",
12
+ "moduleResolution": "node",
13
+ "noImplicitAny": false,
14
+ "noEmitOnError": true,
15
+ "removeComments": false,
16
+ "downlevelIteration": true,
17
+ "resolveJsonModule": true,
18
+ "sourceMap": true,
19
+ "esModuleInterop": true,
20
+ "outDir": "smoke-tests",
21
+ "declaration": true,
22
+ "skipLibCheck": true,
23
+ "strictNullChecks": true,
24
+ "noErrorTruncation": true
25
+ }
26
+ }
@@ -1,3 +0,0 @@
1
- import type { Config } from '@jest/types';
2
- declare const config: Config.InitialOptions;
3
- export default config;
@@ -1,32 +0,0 @@
1
- /* eslint-env node */
2
- const config = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- reporters: [
6
- 'default',
7
- [
8
- 'jest-junit',
9
- {
10
- outputDirectory: 'coverage',
11
- outputName: 'jest-junit.xml',
12
- ancestorSeparator: ' › ',
13
- uniqueOutputName: 'false',
14
- suiteNameTemplate: '{filepath}',
15
- classNameTemplate: '{classname}',
16
- titleTemplate: '{title}',
17
- },
18
- ],
19
- ],
20
- coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
21
- collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
22
- coverageThreshold: {
23
- global: {
24
- branches: 80,
25
- functions: 80,
26
- lines: 80,
27
- statements: 80,
28
- },
29
- },
30
- };
31
- export default config;
32
- //# sourceMappingURL=jest.config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":"AACA,qBAAqB;AACrB,MAAM,MAAM,GAA0B;IACpC,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,SAAS,EAAE;QACT,SAAS;QACT;YACE,YAAY;YACZ;gBACE,eAAe,EAAE,UAAU;gBAC3B,UAAU,EAAE,gBAAgB;gBAC5B,iBAAiB,EAAE,KAAK;gBACxB,gBAAgB,EAAE,OAAO;gBACzB,iBAAiB,EAAE,YAAY;gBAC/B,iBAAiB,EAAE,aAAa;gBAChC,aAAa,EAAE,SAAS;aACzB;SACF;KACF;IACD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,CAAC;IACjG,mBAAmB,EAAE,CAAC,iBAAiB,EAAE,oBAAoB,CAAC;IAC9D,iBAAiB,EAAE;QACjB,MAAM,EAAE;YACN,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;YACb,KAAK,EAAE,EAAE;YACT,UAAU,EAAE,EAAE;SACf;KACF;CACF,CAAA;AACD,eAAe,MAAM,CAAA"}
@@ -1,15 +0,0 @@
1
- // requireActual ensures you get the real file
2
- // instead of an automock
3
- // we use import type and <typeof ...> to still get types
4
- // import type * as Silly from "../silly"
5
- // const { sillyFunction } = jest.requireActual<typeof Silly>("../silly")
6
-
7
- describe('silly function', () => {
8
- test('guaranteed random', () => {
9
- expect(4).toBe(4)
10
- })
11
- })
12
-
13
- // required with this small example
14
- // to make the isolatedModules config happy
15
- export {}