@stacks/api-toolkit 1.12.0 → 1.12.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.
Files changed (82) hide show
  1. package/package.json +1 -1
  2. package/dist/fastify/cache.d.ts +0 -31
  3. package/dist/fastify/cache.js +0 -63
  4. package/dist/fastify/cache.js.map +0 -1
  5. package/dist/fastify/fastify.d.ts +0 -16
  6. package/dist/fastify/fastify.js +0 -46
  7. package/dist/fastify/fastify.js.map +0 -1
  8. package/dist/fastify/index.d.ts +0 -4
  9. package/dist/fastify/index.js +0 -21
  10. package/dist/fastify/index.js.map +0 -1
  11. package/dist/fastify/openapi.d.ts +0 -13
  12. package/dist/fastify/openapi.js +0 -23
  13. package/dist/fastify/openapi.js.map +0 -1
  14. package/dist/fastify/schemas.d.ts +0 -9
  15. package/dist/fastify/schemas.js +0 -16
  16. package/dist/fastify/schemas.js.map +0 -1
  17. package/dist/helpers/events.d.ts +0 -52
  18. package/dist/helpers/events.js +0 -93
  19. package/dist/helpers/events.js.map +0 -1
  20. package/dist/helpers/index.d.ts +0 -7
  21. package/dist/helpers/index.js +0 -25
  22. package/dist/helpers/index.js.map +0 -1
  23. package/dist/helpers/is-debugging.d.ts +0 -1
  24. package/dist/helpers/is-debugging.js +0 -15
  25. package/dist/helpers/is-debugging.js.map +0 -1
  26. package/dist/helpers/iterators.d.ts +0 -27
  27. package/dist/helpers/iterators.js +0 -74
  28. package/dist/helpers/iterators.js.map +0 -1
  29. package/dist/helpers/serialize-error.d.ts +0 -20
  30. package/dist/helpers/serialize-error.js +0 -135
  31. package/dist/helpers/serialize-error.js.map +0 -1
  32. package/dist/helpers/time.d.ts +0 -54
  33. package/dist/helpers/time.js +0 -121
  34. package/dist/helpers/time.js.map +0 -1
  35. package/dist/helpers/values.d.ts +0 -68
  36. package/dist/helpers/values.js +0 -165
  37. package/dist/helpers/values.js.map +0 -1
  38. package/dist/helpers/worker-thread-init.d.ts +0 -1
  39. package/dist/helpers/worker-thread-init.js +0 -67
  40. package/dist/helpers/worker-thread-init.js.map +0 -1
  41. package/dist/helpers/worker-thread-manager.d.ts +0 -53
  42. package/dist/helpers/worker-thread-manager.js +0 -148
  43. package/dist/helpers/worker-thread-manager.js.map +0 -1
  44. package/dist/index.d.ts +0 -7
  45. package/dist/index.js +0 -24
  46. package/dist/index.js.map +0 -1
  47. package/dist/logger/index.d.ts +0 -20
  48. package/dist/logger/index.js +0 -14
  49. package/dist/logger/index.js.map +0 -1
  50. package/dist/postgres/base-pg-store.d.ts +0 -68
  51. package/dist/postgres/base-pg-store.js +0 -109
  52. package/dist/postgres/base-pg-store.js.map +0 -1
  53. package/dist/postgres/connection.d.ts +0 -62
  54. package/dist/postgres/connection.js +0 -126
  55. package/dist/postgres/connection.js.map +0 -1
  56. package/dist/postgres/errors.d.ts +0 -5
  57. package/dist/postgres/errors.js +0 -71
  58. package/dist/postgres/errors.js.map +0 -1
  59. package/dist/postgres/index.d.ts +0 -5
  60. package/dist/postgres/index.js +0 -22
  61. package/dist/postgres/index.js.map +0 -1
  62. package/dist/postgres/migrations.d.ts +0 -47
  63. package/dist/postgres/migrations.js +0 -134
  64. package/dist/postgres/migrations.js.map +0 -1
  65. package/dist/postgres/types.d.ts +0 -14
  66. package/dist/postgres/types.js +0 -48
  67. package/dist/postgres/types.js.map +0 -1
  68. package/dist/profiler/index.d.ts +0 -2
  69. package/dist/profiler/index.js +0 -19
  70. package/dist/profiler/index.js.map +0 -1
  71. package/dist/profiler/inspector-util.d.ts +0 -29
  72. package/dist/profiler/inspector-util.js +0 -268
  73. package/dist/profiler/inspector-util.js.map +0 -1
  74. package/dist/profiler/server.d.ts +0 -6
  75. package/dist/profiler/server.js +0 -186
  76. package/dist/profiler/server.js.map +0 -1
  77. package/dist/server-version/index.d.ts +0 -8
  78. package/dist/server-version/index.js +0 -33
  79. package/dist/server-version/index.js.map +0 -1
  80. package/dist/shutdown-handler/index.d.ts +0 -17
  81. package/dist/shutdown-handler/index.js +0 -82
  82. package/dist/shutdown-handler/index.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/postgres/connection.ts"],"names":[],"mappings":";;AA+CA,gEA0BC;AAQD,0CAkDC;AAOD,kCAmCC;AA7KD,qCAAqC;AACrC,sCAAmC;AACnC,qCAA+C;AAC/C,0CAAqD;AACrD,mCAA2C;AAmC3C;;;;;;;GAOG;AACH,SAAgB,0BAA0B,CACxC,IAAuB,EACvB,KAAc;IAEd,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,UAAU,CAAC;IACpF,MAAM,QAAQ,GAAG,KAAK,IAAI,OAAO,CAAC;IAClC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;YACL,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;YAChC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM;YACxB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;YAChC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM;YACxB,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC;YAC5C,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,SAAkC;YACnD,gBAAgB,EAAE,GAAG,OAAO,IAAI,QAAQ,EAAE;SAC3C,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1B,GAAG,CAAC,YAAY,CAAC,GAAG,CAClB,kBAAkB,EAClB,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,OAAO,IAAI,QAAQ,EAAE,CACrE,CAAC;QACF,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;I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AAC"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Checks if a given error from the pg lib is a connection error (i.e. the query is retryable).
3
- * If true then returns a normalized error message, otherwise returns false.
4
- */
5
- export declare function isPgConnectionError(error: any): string | false;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPgConnectionError = isPgConnectionError;
4
- /**
5
- * Checks if a given error from the pg lib is a connection error (i.e. the query is retryable).
6
- * If true then returns a normalized error message, otherwise returns false.
7
- */
8
- function isPgConnectionError(error) {
9
- if (error.code === 'ECONNREFUSED') {
10
- return 'Postgres connection ECONNREFUSED';
11
- }
12
- else if (error.code === 'ETIMEDOUT') {
13
- return 'Postgres connection ETIMEDOUT';
14
- }
15
- else if (error.code === 'ENOTFOUND') {
16
- return 'Postgres connection ENOTFOUND';
17
- }
18
- else if (error.code === 'ECONNRESET') {
19
- return 'Postgres connection ECONNRESET';
20
- }
21
- else if (error.code === 'CONNECTION_CLOSED') {
22
- return 'Postgres connection CONNECTION_CLOSED';
23
- }
24
- else if (error.code === 'CONNECTION_ENDED') {
25
- return 'Postgres connection CONNECTION_ENDED';
26
- }
27
- else if (error.code === 'CONNECTION_DESTROYED') {
28
- return 'Postgres connection CONNECTION_DESTROYED';
29
- }
30
- else if (error.code === 'CONNECTION_CONNECT_TIMEOUT') {
31
- return 'Postgres connection CONNECTION_CONNECT_TIMEOUT';
32
- }
33
- else if (error.code === 'CONNECT_TIMEOUT') {
34
- return 'Postgres connection CONNECT_TIMEOUT';
35
- }
36
- else if (error.message) {
37
- const msg = error.message.toLowerCase();
38
- if (msg.includes('database system is starting up')) {
39
- return 'Postgres connection failed while database system is starting up';
40
- }
41
- else if (msg.includes('database system is shutting down')) {
42
- return 'Postgres connection failed while database system is shutting down';
43
- }
44
- else if (msg.includes('connection terminated unexpectedly')) {
45
- return 'Postgres connection terminated unexpectedly';
46
- }
47
- else if (msg.includes('connection terminated')) {
48
- return 'Postgres connection terminated';
49
- }
50
- else if (msg.includes('connection error')) {
51
- return 'Postgres client has encountered a connection error and is not queryable';
52
- }
53
- else if (msg.includes('terminating connection due to unexpected postmaster exit')) {
54
- return 'Postgres connection terminating due to unexpected postmaster exit';
55
- }
56
- else if (msg.includes('getaddrinfo eai_again')) {
57
- return 'Postgres connection failed due to a DNS lookup error';
58
- }
59
- else if (msg.includes('terminating connection due to administrator command')) {
60
- return 'Postgres connection closed due to administrator command';
61
- }
62
- else if (msg.includes('password authentication failed')) {
63
- return 'Postgres authentication failed';
64
- }
65
- else if (msg.includes('database system is not yet accepting connections')) {
66
- return 'Postgres not yet accepting connections';
67
- }
68
- }
69
- return false;
70
- }
71
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/postgres/errors.ts"],"names":[],"mappings":";;AAIA,kDA4CC;AAhDD;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,KAAU;IAC5C,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QAClC,OAAO,kCAAkC,CAAC;IAC5C,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACtC,OAAO,+BAA+B,CAAC;IACzC,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACtC,OAAO,+BAA+B,CAAC;IACzC,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACvC,OAAO,gCAAgC,CAAC;IAC1C,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QAC9C,OAAO,uCAAuC,CAAC;IACjD,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;QAC7C,OAAO,sCAAsC,CAAC;IAChD,CAAC;SAAM,IAAI,KAAK,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QACjD,OAAO,0CAA0C,CAA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AC;QAC1C,CAAC;aAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,kDAAkD,CAAC,EAAE,CAAC;YAC5E,OAAO,wCAAwC,CAAC;QAClD,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from './base-pg-store';
2
- export * from './connection';
3
- export * from './errors';
4
- export * from './migrations';
5
- export * from './types';
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./base-pg-store"), exports);
18
- __exportStar(require("./connection"), exports);
19
- __exportStar(require("./errors"), exports);
20
- __exportStar(require("./migrations"), exports);
21
- __exportStar(require("./types"), exports);
22
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/postgres/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B;AAC7B,2CAAyB;AACzB,+CAA6B;AAC7B,0CAAwB"}
@@ -1,47 +0,0 @@
1
- import { Logger as PgMigrateLogger, MigrationDirection } from 'node-pg-migrate/dist/types';
2
- import { PgConnectionArgs } from './connection';
3
- export interface MigrationOptions {
4
- /** Bypass the NODE_ENV check when performing a "down" migration which irreversibly drops data. */
5
- dangerousAllowDataLoss?: boolean;
6
- /** Log all applied migrations */
7
- logMigrations?: boolean;
8
- /** Name of the table used for migrations. Defaults to `pgmigrations`. */
9
- migrationsTable?: string;
10
- /** Custom logging configuration */
11
- logger?: PgMigrateLogger;
12
- }
13
- /**
14
- * Run migrations in one direction.
15
- * @param dir - Migrations directory
16
- * @param direction - Migration direction (`'down'` or `'up'`)
17
- * @param connectionArgs - Postgres connection args
18
- * @param opts - Migration options
19
- */
20
- export declare function runMigrations(dir: string, direction: MigrationDirection, connectionArgs?: PgConnectionArgs, opts?: MigrationOptions): Promise<void>;
21
- /**
22
- * Cycle migrations down and up.
23
- * @param dir - Migrations directory
24
- * @param connectionArgs - Postgres connection args
25
- * @param opts - Migration options
26
- */
27
- export declare function cycleMigrations(dir: string, connectionArgs?: PgConnectionArgs, opts?: MigrationOptions & {
28
- /** Validates if the database was cleared completely after all `down` migrations are done */
29
- checkForEmptyData?: boolean;
30
- }): Promise<void>;
31
- /**
32
- * Check the `pg_class` table for any data structures contained in the database. We will consider
33
- * any and all results here as "data" contained in the DB, since anything that is not a completely
34
- * empty DB could lead to strange errors when running the API. See:
35
- * https://www.postgresql.org/docs/current/catalog-pg-class.html
36
- * @returns `boolean` if the DB has data
37
- */
38
- export declare function databaseHasData(connectionArgs?: PgConnectionArgs, opts?: {
39
- ignoreMigrationTables?: boolean;
40
- migrationsTable?: string;
41
- }): Promise<boolean>;
42
- /**
43
- * Drops all tables from the Postgres DB. DANGEROUS!!!
44
- */
45
- export declare function dangerousDropAllTables(connectionArgs?: PgConnectionArgs, opts?: {
46
- acknowledgePotentialCatastrophicConsequences?: 'yes';
47
- }): Promise<void>;
@@ -1,134 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runMigrations = runMigrations;
4
- exports.cycleMigrations = cycleMigrations;
5
- exports.databaseHasData = databaseHasData;
6
- exports.dangerousDropAllTables = dangerousDropAllTables;
7
- const node_pg_migrate_1 = require("node-pg-migrate");
8
- const logger_1 = require("../logger");
9
- const connection_1 = require("./connection");
10
- const values_1 = require("../helpers/values");
11
- /**
12
- * Run migrations in one direction.
13
- * @param dir - Migrations directory
14
- * @param direction - Migration direction (`'down'` or `'up'`)
15
- * @param connectionArgs - Postgres connection args
16
- * @param opts - Migration options
17
- */
18
- async function runMigrations(dir, direction, connectionArgs, opts) {
19
- if (!opts?.dangerousAllowDataLoss && direction !== 'up' && !values_1.isTestEnv && !values_1.isDevEnv) {
20
- throw new Error('Whoa there! This is a testing function that will drop all data from PG. ' +
21
- 'Set NODE_ENV to "test" or "development" to enable migration testing.');
22
- }
23
- const args = (0, connection_1.standardizedConnectionArgs)(connectionArgs, 'migrations');
24
- await (0, node_pg_migrate_1.default)({
25
- dir,
26
- direction,
27
- count: Infinity,
28
- ignorePattern: '.*(\\.map|\\.d\\.ts)',
29
- databaseUrl: typeof args === 'string'
30
- ? args
31
- : {
32
- host: args.host,
33
- port: args.port,
34
- user: args.user,
35
- password: args.password,
36
- database: args.database,
37
- },
38
- migrationsTable: opts?.migrationsTable ?? 'pgmigrations',
39
- schema: typeof args === 'string' ? 'public' : args.schema,
40
- logger: opts?.logger ?? {
41
- info: msg => (opts?.logMigrations === true ? logger_1.logger.info(msg) : {}),
42
- warn: msg => logger_1.logger.warn(msg),
43
- error: msg => logger_1.logger.error(msg),
44
- },
45
- });
46
- }
47
- /**
48
- * Cycle migrations down and up.
49
- * @param dir - Migrations directory
50
- * @param connectionArgs - Postgres connection args
51
- * @param opts - Migration options
52
- */
53
- async function cycleMigrations(dir, connectionArgs, opts) {
54
- await runMigrations(dir, 'down', connectionArgs, opts);
55
- if (opts?.checkForEmptyData &&
56
- (await databaseHasData(connectionArgs, {
57
- ignoreMigrationTables: true,
58
- migrationsTable: opts.migrationsTable,
59
- }))) {
60
- throw new Error('Migration down process did not completely remove DB tables');
61
- }
62
- await runMigrations(dir, 'up', connectionArgs, opts);
63
- }
64
- /**
65
- * Check the `pg_class` table for any data structures contained in the database. We will consider
66
- * any and all results here as "data" contained in the DB, since anything that is not a completely
67
- * empty DB could lead to strange errors when running the API. See:
68
- * https://www.postgresql.org/docs/current/catalog-pg-class.html
69
- * @returns `boolean` if the DB has data
70
- */
71
- async function databaseHasData(connectionArgs, opts) {
72
- const sql = await (0, connection_1.connectPostgres)({
73
- usageName: 'contains-data-check',
74
- connectionArgs: (0, connection_1.standardizedConnectionArgs)(connectionArgs, 'contains-data-check'),
75
- });
76
- try {
77
- const ignoreMigrationTables = opts?.ignoreMigrationTables ?? false;
78
- const tableName = opts?.migrationsTable ?? 'pgmigrations';
79
- const result = await sql `
80
- SELECT COUNT(*)
81
- FROM pg_class c
82
- JOIN pg_namespace s ON s.oid = c.relnamespace
83
- WHERE s.nspname = ${sql.options.connection.search_path}
84
- ${ignoreMigrationTables ? sql `AND c.relname NOT LIKE ${tableName}::text || '%'` : sql ``}
85
- `;
86
- return result.count > 0 && result[0].count > 0;
87
- }
88
- catch (error) {
89
- if (error.message?.includes('does not exist')) {
90
- return false;
91
- }
92
- throw error;
93
- }
94
- finally {
95
- await sql.end();
96
- }
97
- }
98
- /**
99
- * Drops all tables from the Postgres DB. DANGEROUS!!!
100
- */
101
- async function dangerousDropAllTables(connectionArgs, opts) {
102
- if (opts?.acknowledgePotentialCatastrophicConsequences !== 'yes') {
103
- throw new Error('Dangerous usage error.');
104
- }
105
- const sql = await (0, connection_1.connectPostgres)({
106
- usageName: 'dangerous-drop-all-tables',
107
- connectionArgs: (0, connection_1.standardizedConnectionArgs)(connectionArgs, 'dangerous-drop-all-tables'),
108
- });
109
- const schema = sql.options.connection.search_path;
110
- try {
111
- await sql.begin(async (sql) => {
112
- const relNamesQuery = async (kind) => sql `
113
- SELECT relname
114
- FROM pg_class c
115
- JOIN pg_namespace s ON s.oid = c.relnamespace
116
- WHERE s.nspname = ${schema} AND c.relkind = ${kind}
117
- `;
118
- // Remove materialized views first and tables second.
119
- // Using CASCADE in these DROP statements also removes associated indexes and constraints.
120
- const views = await relNamesQuery('m');
121
- for (const view of views) {
122
- await sql `DROP MATERIALIZED VIEW IF EXISTS ${sql(view.relname)} CASCADE`;
123
- }
124
- const tables = await relNamesQuery('r');
125
- for (const table of tables) {
126
- await sql `DROP TABLE IF EXISTS ${sql(table.relname)} CASCADE`;
127
- }
128
- });
129
- }
130
- finally {
131
- await sql.end();
132
- }
133
- }
134
- //# sourceMappingURL=migrations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/postgres/migrations.ts"],"names":[],"mappings":";;AAwBA,sCAoCC;AAQD,0CAmBC;AASD,0CA8BC;AAKD,wDAoCC;AAvKD,qDAAwC;AAExC,sCAAmC;AACnC,6CAA6F;AAC7F,8CAAwD;AAaxD;;;;;;GAMG;AACI,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,SAA6B,EAC7B,cAAiC,EACjC,IAAuB;IAEvB,IAAI,CAAC,IAAI,EAAE,sBAAsB,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC,kBAAS,IAAI,CAAC,iBAAQ,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CACb,0EAA0E;YACxE,sEAAsE,CACzE,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,IAAA,uCAA0B,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACtE,MAAM,IAAA,yBAAS,EAAC;QACd,GAAG;QACH,SAAS;QACT,KAAK,EAAE,QAAQ;QACf,aAAa,EAAE,sBAAsB;QACrC,WAAW,EACT,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC;gBACE,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;QACP,eAAe,EAAE,IAAI,EAAE,eAAe,IAAI,cAAc;Q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AAG,CAAuB;;;;4BAIlD,MAAM,oBAAoB,IAAI;OACnD,CAAC;YACF,qDAAqD;YACrD,0FAA0F;YAC1F,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YACvC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,GAAG,CAAA,oCAAoC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YAC3E,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAC;YACxC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,MAAM,GAAG,CAAA,wBAAwB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;YAChE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -1,14 +0,0 @@
1
- export declare const PG_TYPE_MAPPINGS: {
2
- bytea: {
3
- to: number;
4
- from: number[];
5
- serialize: (x: any) => string;
6
- parse: (x: any) => string;
7
- };
8
- };
9
- /** Values will be automatically converted into a `bytea` compatible string before sending to pg. */
10
- export type PgBytea = string | Buffer;
11
- /** The `string` type guarantees the value will fit into the `numeric` pg type. */
12
- export type PgNumeric = string;
13
- /** JSON objects will be automatically stringified before insertion. */
14
- export type PgJsonb = any;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PG_TYPE_MAPPINGS = void 0;
4
- exports.PG_TYPE_MAPPINGS = {
5
- // Make both `string` and `Buffer` be compatible with a `bytea` columns.
6
- // * Buffers and strings with `0x` prefixes will be transformed to hex format (`\x`).
7
- // * Other strings will be passed as-is.
8
- // From postgres, all values will be returned as strings with `0x` prefix.
9
- bytea: {
10
- to: 17,
11
- from: [17],
12
- serialize: (x) => {
13
- if (typeof x === 'string') {
14
- if (/^(0x|0X)[a-fA-F0-9]*$/.test(x)) {
15
- // hex string with "0x" prefix
16
- if (x.length % 2 !== 0) {
17
- throw new Error(`Hex string is an odd number of digits`);
18
- }
19
- return '\\x' + x.slice(2);
20
- }
21
- else if (x.length === 0) {
22
- return '\\x';
23
- }
24
- else if (/^\\x[a-fA-F0-9]*$/.test(x)) {
25
- // hex string with "\x" prefix (already encoded for postgres)
26
- if (x.length % 2 !== 0) {
27
- throw new Error(`Hex string is an odd number of digits`);
28
- }
29
- return x;
30
- }
31
- else {
32
- throw new Error(`String value for bytea column does not have 0x prefix`);
33
- }
34
- }
35
- else if (Buffer.isBuffer(x)) {
36
- return '\\x' + x.toString('hex');
37
- }
38
- else if (ArrayBuffer.isView(x)) {
39
- return '\\x' + Buffer.from(x.buffer, x.byteOffset, x.byteLength).toString('hex');
40
- }
41
- else {
42
- throw new Error(`Cannot serialize unexpected type "${x.constructor.name}" to bytea hex string`);
43
- }
44
- },
45
- parse: (x) => `0x${x.slice(2)}`,
46
- },
47
- };
48
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/postgres/types.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG;IAC9B,wEAAwE;IACxE,qFAAqF;IACrF,wCAAwC;IACxC,0EAA0E;IAC1E,KAAK,EAAE;QACL,EAAE,EAAE,EAAE;QACN,IAAI,EAAE,CAAC,EAAE,CAAC;QACV,SAAS,EAAE,CAAC,CAAM,EAAE,EAAE;YACpB,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC1B,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;oBACpC,8BAA8B;oBAC9B,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;wBACvB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;oBAC3D,CAAC;oBACD,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC5B,CAAC;qBAAM,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC1B,OAAO,KAAK,CAAC;gBACf,CAAC;qBAAM,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;oBACvC,6DAA6D;oBAC7D,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;wBACvB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;oBAC3D,CAAC;oBACD,OAAO,CAAC,CAAC;gBACX,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;gBAC3E,CAAC;YACH,CAAC;iBAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9B,OAAO,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC;iBAAM,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjC,OAAO,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACnF,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,qCAAqC,CAAC,CAAC,WAAW,CAAC,IAAI,uBAAuB,CAC/E,CAAC;YACJ,CAAC;QACH,CAAC;QACD,KAAK,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;KACrC;CACF,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './inspector-util';
2
- export * from './server';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./inspector-util"), exports);
18
- __exportStar(require("./server"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/profiler/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,2CAAyB"}
@@ -1,29 +0,0 @@
1
- import * as inspector from 'inspector';
2
- import * as stream from 'stream';
3
- import { Stopwatch } from '../helpers';
4
- export type CpuProfileResult = inspector.Profiler.Profile;
5
- export interface ProfilerInstance<TStopResult = void> {
6
- start: () => Promise<void>;
7
- stop: () => Promise<TStopResult>;
8
- dispose: () => Promise<void>;
9
- session: inspector.Session;
10
- sessionType: 'cpu' | 'memory';
11
- stopwatch: Stopwatch;
12
- }
13
- /**
14
- * Connects and enables a new `inspector` session, then starts an internal v8 CPU profiling process.
15
- * @returns A function to stop the profiling, and return the CPU profile result object.
16
- * The result object can be used to create a `.cpuprofile` file using JSON.stringify.
17
- * Use VSCode or Chrome's 'DevTools for Node' (under chrome://inspect) to visualize the `.cpuprofile` file.
18
- * @param samplingInterval - Optionally set sampling interval in microseconds, default is 1000 microseconds.
19
- */
20
- export declare function initCpuProfiling(samplingInterval?: number): ProfilerInstance<CpuProfileResult>;
21
- /**
22
- * Connects and enables a new `inspector` session, then creates an internal v8 Heap profiler snapshot.
23
- * @param outputStream - An output stream that heap snapshot chunks are written to.
24
- * The result stream can be used to create a `.heapsnapshot` file.
25
- * Use Chrome's 'DevTools for Node' (under chrome://inspect) to visualize the `.heapsnapshot` file.
26
- */
27
- export declare function initHeapSnapshot(outputStream: stream.Writable): ProfilerInstance<{
28
- totalSnapshotByteSize: number;
29
- }>;