@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.
- package/package.json +1 -1
- package/dist/fastify/cache.d.ts +0 -31
- package/dist/fastify/cache.js +0 -63
- package/dist/fastify/cache.js.map +0 -1
- package/dist/fastify/fastify.d.ts +0 -16
- package/dist/fastify/fastify.js +0 -46
- package/dist/fastify/fastify.js.map +0 -1
- package/dist/fastify/index.d.ts +0 -4
- package/dist/fastify/index.js +0 -21
- package/dist/fastify/index.js.map +0 -1
- package/dist/fastify/openapi.d.ts +0 -13
- package/dist/fastify/openapi.js +0 -23
- package/dist/fastify/openapi.js.map +0 -1
- package/dist/fastify/schemas.d.ts +0 -9
- package/dist/fastify/schemas.js +0 -16
- package/dist/fastify/schemas.js.map +0 -1
- package/dist/helpers/events.d.ts +0 -52
- package/dist/helpers/events.js +0 -93
- package/dist/helpers/events.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -7
- package/dist/helpers/index.js +0 -25
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/is-debugging.d.ts +0 -1
- package/dist/helpers/is-debugging.js +0 -15
- package/dist/helpers/is-debugging.js.map +0 -1
- package/dist/helpers/iterators.d.ts +0 -27
- package/dist/helpers/iterators.js +0 -74
- package/dist/helpers/iterators.js.map +0 -1
- package/dist/helpers/serialize-error.d.ts +0 -20
- package/dist/helpers/serialize-error.js +0 -135
- package/dist/helpers/serialize-error.js.map +0 -1
- package/dist/helpers/time.d.ts +0 -54
- package/dist/helpers/time.js +0 -121
- package/dist/helpers/time.js.map +0 -1
- package/dist/helpers/values.d.ts +0 -68
- package/dist/helpers/values.js +0 -165
- package/dist/helpers/values.js.map +0 -1
- package/dist/helpers/worker-thread-init.d.ts +0 -1
- package/dist/helpers/worker-thread-init.js +0 -67
- package/dist/helpers/worker-thread-init.js.map +0 -1
- package/dist/helpers/worker-thread-manager.d.ts +0 -53
- package/dist/helpers/worker-thread-manager.js +0 -148
- package/dist/helpers/worker-thread-manager.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/logger/index.d.ts +0 -20
- package/dist/logger/index.js +0 -14
- package/dist/logger/index.js.map +0 -1
- package/dist/postgres/base-pg-store.d.ts +0 -68
- package/dist/postgres/base-pg-store.js +0 -109
- package/dist/postgres/base-pg-store.js.map +0 -1
- package/dist/postgres/connection.d.ts +0 -62
- package/dist/postgres/connection.js +0 -126
- package/dist/postgres/connection.js.map +0 -1
- package/dist/postgres/errors.d.ts +0 -5
- package/dist/postgres/errors.js +0 -71
- package/dist/postgres/errors.js.map +0 -1
- package/dist/postgres/index.d.ts +0 -5
- package/dist/postgres/index.js +0 -22
- package/dist/postgres/index.js.map +0 -1
- package/dist/postgres/migrations.d.ts +0 -47
- package/dist/postgres/migrations.js +0 -134
- package/dist/postgres/migrations.js.map +0 -1
- package/dist/postgres/types.d.ts +0 -14
- package/dist/postgres/types.js +0 -48
- package/dist/postgres/types.js.map +0 -1
- package/dist/profiler/index.d.ts +0 -2
- package/dist/profiler/index.js +0 -19
- package/dist/profiler/index.js.map +0 -1
- package/dist/profiler/inspector-util.d.ts +0 -29
- package/dist/profiler/inspector-util.js +0 -268
- package/dist/profiler/inspector-util.js.map +0 -1
- package/dist/profiler/server.d.ts +0 -6
- package/dist/profiler/server.js +0 -186
- package/dist/profiler/server.js.map +0 -1
- package/dist/server-version/index.d.ts +0 -8
- package/dist/server-version/index.js +0 -33
- package/dist/server-version/index.js.map +0 -1
- package/dist/shutdown-handler/index.d.ts +0 -17
- package/dist/shutdown-handler/index.js +0 -82
- package/dist/shutdown-handler/index.js.map +0 -1
package/package.json
CHANGED
package/dist/fastify/cache.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FastifyReply } from 'fastify';
|
|
2
|
-
/**
|
|
3
|
-
* A `Cache-Control` header used for re-validation based caching.
|
|
4
|
-
* * `public` == allow proxies/CDNs to cache as opposed to only local browsers.
|
|
5
|
-
* * `no-cache` == clients can cache a resource but should revalidate each time before using it.
|
|
6
|
-
* * `must-revalidate` == somewhat redundant directive to assert that cache must be revalidated, required by some CDNs
|
|
7
|
-
*/
|
|
8
|
-
export declare const CACHE_CONTROL_MUST_REVALIDATE = "public, no-cache, must-revalidate";
|
|
9
|
-
export declare function setResponseNonCacheable(reply: FastifyReply): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Parses the etag values from a raw `If-None-Match` request header value.
|
|
12
|
-
* The wrapping double quotes (if any) and validation prefix (if any) are stripped.
|
|
13
|
-
* The parsing is permissive to account for commonly non-spec-compliant clients, proxies, CDNs, etc.
|
|
14
|
-
* E.g. the value:
|
|
15
|
-
* ```js
|
|
16
|
-
* `"a", W/"b", c,d, "e", "f"`
|
|
17
|
-
* ```
|
|
18
|
-
* Would be parsed and returned as:
|
|
19
|
-
* ```js
|
|
20
|
-
* ['a', 'b', 'c', 'd', 'e', 'f']
|
|
21
|
-
* ```
|
|
22
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match#syntax
|
|
23
|
-
* ```
|
|
24
|
-
* If-None-Match: "etag_value"
|
|
25
|
-
* If-None-Match: "etag_value", "etag_value", ...
|
|
26
|
-
* If-None-Match: *
|
|
27
|
-
* ```
|
|
28
|
-
* @param ifNoneMatchHeaderValue - raw header value
|
|
29
|
-
* @returns an array of etag values
|
|
30
|
-
*/
|
|
31
|
-
export declare function parseIfNoneMatchHeader(ifNoneMatchHeaderValue: string | undefined): string[] | undefined;
|
package/dist/fastify/cache.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CACHE_CONTROL_MUST_REVALIDATE = void 0;
|
|
4
|
-
exports.setResponseNonCacheable = setResponseNonCacheable;
|
|
5
|
-
exports.parseIfNoneMatchHeader = parseIfNoneMatchHeader;
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
/**
|
|
8
|
-
* A `Cache-Control` header used for re-validation based caching.
|
|
9
|
-
* * `public` == allow proxies/CDNs to cache as opposed to only local browsers.
|
|
10
|
-
* * `no-cache` == clients can cache a resource but should revalidate each time before using it.
|
|
11
|
-
* * `must-revalidate` == somewhat redundant directive to assert that cache must be revalidated, required by some CDNs
|
|
12
|
-
*/
|
|
13
|
-
exports.CACHE_CONTROL_MUST_REVALIDATE = 'public, no-cache, must-revalidate';
|
|
14
|
-
async function setResponseNonCacheable(reply) {
|
|
15
|
-
await reply.removeHeader('Cache-Control');
|
|
16
|
-
await reply.removeHeader('ETag');
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Parses the etag values from a raw `If-None-Match` request header value.
|
|
20
|
-
* The wrapping double quotes (if any) and validation prefix (if any) are stripped.
|
|
21
|
-
* The parsing is permissive to account for commonly non-spec-compliant clients, proxies, CDNs, etc.
|
|
22
|
-
* E.g. the value:
|
|
23
|
-
* ```js
|
|
24
|
-
* `"a", W/"b", c,d, "e", "f"`
|
|
25
|
-
* ```
|
|
26
|
-
* Would be parsed and returned as:
|
|
27
|
-
* ```js
|
|
28
|
-
* ['a', 'b', 'c', 'd', 'e', 'f']
|
|
29
|
-
* ```
|
|
30
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match#syntax
|
|
31
|
-
* ```
|
|
32
|
-
* If-None-Match: "etag_value"
|
|
33
|
-
* If-None-Match: "etag_value", "etag_value", ...
|
|
34
|
-
* If-None-Match: *
|
|
35
|
-
* ```
|
|
36
|
-
* @param ifNoneMatchHeaderValue - raw header value
|
|
37
|
-
* @returns an array of etag values
|
|
38
|
-
*/
|
|
39
|
-
function parseIfNoneMatchHeader(ifNoneMatchHeaderValue) {
|
|
40
|
-
if (!ifNoneMatchHeaderValue) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
// Strip wrapping double quotes like `"hello"` and the ETag validation-prefix like `W/"hello"`.
|
|
44
|
-
// The API returns compliant, strong-validation ETags (double quoted ASCII), but can't control what
|
|
45
|
-
// clients, proxies, CDNs, etc may provide.
|
|
46
|
-
const normalized = /^(?:"|W\/")?(.*?)"?$/gi.exec(ifNoneMatchHeaderValue.trim())?.[1];
|
|
47
|
-
if (!normalized) {
|
|
48
|
-
// This should never happen unless handling a buggy request with something like `If-None-Match: ""`,
|
|
49
|
-
// or if there's a flaw in the above code. Log warning for now.
|
|
50
|
-
logger_1.logger.warn(`Normalized If-None-Match header is falsy: ${ifNoneMatchHeaderValue}`);
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
else if (normalized.includes(',')) {
|
|
54
|
-
// Multiple etag values provided, likely irrelevant extra values added by a proxy/CDN.
|
|
55
|
-
// Split on comma, also stripping quotes, weak-validation prefixes, and extra whitespace.
|
|
56
|
-
return normalized.split(/(?:W\/"|")?(?:\s*),(?:\s*)(?:W\/"|")?/gi);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// Single value provided (the typical case)
|
|
60
|
-
return [normalized];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=cache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/fastify/cache.ts"],"names":[],"mappings":";;;AAWA,0DAGC;AAuBD,wDAuBC;AA3DD,sCAAmC;AAEnC;;;;;GAKG;AACU,QAAA,6BAA6B,GAAG,mCAAmC,CAAC;AAE1E,KAAK,UAAU,uBAAuB,CAAC,KAAmB;IAC/D,MAAM,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC1C,MAAM,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,sBAAsB,CACpC,sBAA0C;IAE1C,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,+FAA+F;IAC/F,mGAAmG;IACnG,2CAA2C;IAC3C,MAAM,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACrF,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,oGAAoG;QACpG,+DAA+D;QAC/D,eAAM,CAAC,IAAI,CAAC,6CAA6C,sBAAsB,EAAE,CAAC,CAAC;QACnF,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,sFAAsF;QACtF,yFAAyF;QACzF,OAAO,UAAU,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,2CAA2C;QAC3C,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FastifyInstance } from 'fastify';
|
|
2
|
-
import { IFastifyMetrics } from 'fastify-metrics';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a Fastify server that handles Prometheus metrics and CORS headers automatically.
|
|
5
|
-
* @returns Fastify instance
|
|
6
|
-
*/
|
|
7
|
-
export declare function buildFastifyApiServer(): Promise<FastifyInstance>;
|
|
8
|
-
/**
|
|
9
|
-
* Creates a Fastify server that serves a `/metrics` endpoint with metrics taken from
|
|
10
|
-
* `FastifyMetrics`.
|
|
11
|
-
* @param args - Fastify instance metrics decorator
|
|
12
|
-
* @returns Fastify instance
|
|
13
|
-
*/
|
|
14
|
-
export declare function buildPrometheusServer(args: {
|
|
15
|
-
metrics: IFastifyMetrics;
|
|
16
|
-
}): Promise<FastifyInstance>;
|
package/dist/fastify/fastify.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildFastifyApiServer = buildFastifyApiServer;
|
|
4
|
-
exports.buildPrometheusServer = buildPrometheusServer;
|
|
5
|
-
const cors_1 = require("@fastify/cors");
|
|
6
|
-
const fastify_1 = require("fastify");
|
|
7
|
-
const fastify_metrics_1 = require("fastify-metrics");
|
|
8
|
-
const logger_1 = require("../logger");
|
|
9
|
-
const values_1 = require("../helpers/values");
|
|
10
|
-
/**
|
|
11
|
-
* Creates a Fastify server that handles Prometheus metrics and CORS headers automatically.
|
|
12
|
-
* @returns Fastify instance
|
|
13
|
-
*/
|
|
14
|
-
async function buildFastifyApiServer() {
|
|
15
|
-
const fastify = (0, fastify_1.default)({
|
|
16
|
-
trustProxy: true,
|
|
17
|
-
logger: logger_1.PINO_LOGGER_CONFIG,
|
|
18
|
-
}).withTypeProvider();
|
|
19
|
-
if (values_1.isProdEnv) {
|
|
20
|
-
await fastify.register(fastify_metrics_1.default, { endpoint: null });
|
|
21
|
-
}
|
|
22
|
-
await fastify.register(cors_1.default);
|
|
23
|
-
return fastify;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Creates a Fastify server that serves a `/metrics` endpoint with metrics taken from
|
|
27
|
-
* `FastifyMetrics`.
|
|
28
|
-
* @param args - Fastify instance metrics decorator
|
|
29
|
-
* @returns Fastify instance
|
|
30
|
-
*/
|
|
31
|
-
async function buildPrometheusServer(args) {
|
|
32
|
-
const promServer = (0, fastify_1.default)({
|
|
33
|
-
trustProxy: true,
|
|
34
|
-
logger: logger_1.PINO_LOGGER_CONFIG,
|
|
35
|
-
});
|
|
36
|
-
promServer.route({
|
|
37
|
-
url: '/metrics',
|
|
38
|
-
method: 'GET',
|
|
39
|
-
logLevel: 'info',
|
|
40
|
-
handler: async (_, reply) => {
|
|
41
|
-
await reply.type('text/plain').send(await args.metrics.client.register.metrics());
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
return promServer;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=fastify.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/fastify/fastify.ts"],"names":[],"mappings":";;AAWA,sDAUC;AAQD,sDAgBC;AA7CD,wCAAwC;AACxC,qCAAmD;AACnD,qDAAkE;AAClE,sCAA+C;AAE/C,8CAA8C;AAE9C;;;GAGG;AACI,KAAK,UAAU,qBAAqB;IACzC,MAAM,OAAO,GAAG,IAAA,iBAAO,EAAC;QACtB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,2BAAkB;KAC3B,CAAC,CAAC,gBAAgB,EAAuB,CAAC;IAC3C,IAAI,kBAAS,EAAE,CAAC;QACd,MAAM,OAAO,CAAC,QAAQ,CAAC,yBAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,OAAO,CAAC,QAAQ,CAAC,cAAW,CAAC,CAAC;IACpC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CAAC,IAE3C;IACC,MAAM,UAAU,GAAG,IAAA,iBAAO,EAAC;QACzB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,2BAAkB;KAC3B,CAAC,CAAC;IACH,UAAU,CAAC,KAAK,CAAC;QACf,GAAG,EAAE,UAAU;QACf,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,MAAM;QAChB,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE;YAC1B,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpF,CAAC;KACF,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/fastify/index.d.ts
DELETED
package/dist/fastify/index.js
DELETED
|
@@ -1,21 +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("./cache"), exports);
|
|
18
|
-
__exportStar(require("./fastify"), exports);
|
|
19
|
-
__exportStar(require("./openapi"), exports);
|
|
20
|
-
__exportStar(require("./schemas"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fastify/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,4CAA0B;AAC1B,4CAA0B"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FastifyPluginAsync, FastifyPluginCallback } from 'fastify';
|
|
2
|
-
import { SwaggerOptions } from '@fastify/swagger';
|
|
3
|
-
export interface OpenApiGeneratorOptions {
|
|
4
|
-
apiDefinition: FastifyPluginAsync | FastifyPluginCallback;
|
|
5
|
-
swaggerOptions?: SwaggerOptions;
|
|
6
|
-
prefix?: string;
|
|
7
|
-
outputDirectory?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Generates OpenAPI JSON and YAML spec documents based on a given Fastify API plugin with optional
|
|
11
|
-
* Swagger definitions.
|
|
12
|
-
*/
|
|
13
|
-
export declare function generateOpenApiSpec(options: OpenApiGeneratorOptions): Promise<void>;
|
package/dist/fastify/openapi.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateOpenApiSpec = generateOpenApiSpec;
|
|
4
|
-
const fastify_1 = require("fastify");
|
|
5
|
-
const swagger_1 = require("@fastify/swagger");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
/**
|
|
8
|
-
* Generates OpenAPI JSON and YAML spec documents based on a given Fastify API plugin with optional
|
|
9
|
-
* Swagger definitions.
|
|
10
|
-
*/
|
|
11
|
-
async function generateOpenApiSpec(options) {
|
|
12
|
-
const fastify = (0, fastify_1.default)().withTypeProvider();
|
|
13
|
-
await fastify.register(swagger_1.default, options.swaggerOptions);
|
|
14
|
-
await fastify.register(options.apiDefinition, { prefix: options.prefix });
|
|
15
|
-
await fastify.ready();
|
|
16
|
-
const directory = options.outputDirectory ?? './tmp';
|
|
17
|
-
if (!(0, fs_1.existsSync)(directory))
|
|
18
|
-
(0, fs_1.mkdirSync)(directory);
|
|
19
|
-
(0, fs_1.writeFileSync)(`${directory}/openapi.yaml`, fastify.swagger({ yaml: true }));
|
|
20
|
-
(0, fs_1.writeFileSync)(`${directory}/openapi.json`, JSON.stringify(fastify.swagger(), null, 2));
|
|
21
|
-
await fastify.close();
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=openapi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/fastify/openapi.ts"],"names":[],"mappings":";;AAiBA,kDAYC;AA7BD,qCAA6E;AAG7E,8CAA8C;AAC9C,2BAA0D;AAS1D;;;GAGG;AACI,KAAK,UAAU,mBAAmB,CAAC,OAAgC;IACxE,MAAM,OAAO,GAAG,IAAA,iBAAO,GAAE,CAAC,gBAAgB,EAAuB,CAAC;IAClE,MAAM,OAAO,CAAC,QAAQ,CAAC,iBAAc,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/D,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1E,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IAEtB,MAAM,SAAS,GAAG,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC;IACrD,IAAI,CAAC,IAAA,eAAU,EAAC,SAAS,CAAC;QAAE,IAAA,cAAS,EAAC,SAAS,CAAC,CAAC;IACjD,IAAA,kBAAa,EAAC,GAAG,SAAS,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5E,IAAA,kBAAa,EAAC,GAAG,SAAS,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAEvF,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { TSchema } from '@sinclair/typebox';
|
|
2
|
-
export declare const Nullable: <T extends TSchema>(type: T) => import("@sinclair/typebox").TUnion<[T, import("@sinclair/typebox").TNull]>;
|
|
3
|
-
export declare const Optional: <T extends TSchema>(type: T) => import("@sinclair/typebox").TOptional<T>;
|
|
4
|
-
export declare const PaginatedResponse: <T extends TSchema>(type: T, title: string) => import("@sinclair/typebox").TObject<{
|
|
5
|
-
limit: import("@sinclair/typebox").TInteger;
|
|
6
|
-
offset: import("@sinclair/typebox").TInteger;
|
|
7
|
-
total: import("@sinclair/typebox").TInteger;
|
|
8
|
-
results: import("@sinclair/typebox").TArray<T>;
|
|
9
|
-
}>;
|
package/dist/fastify/schemas.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PaginatedResponse = exports.Optional = exports.Nullable = void 0;
|
|
4
|
-
const typebox_1 = require("@sinclair/typebox");
|
|
5
|
-
const Nullable = (type) => typebox_1.Type.Union([type, typebox_1.Type.Null()]);
|
|
6
|
-
exports.Nullable = Nullable;
|
|
7
|
-
const Optional = (type) => typebox_1.Type.Optional(type);
|
|
8
|
-
exports.Optional = Optional;
|
|
9
|
-
const PaginatedResponse = (type, title) => typebox_1.Type.Object({
|
|
10
|
-
limit: typebox_1.Type.Integer({ examples: [20] }),
|
|
11
|
-
offset: typebox_1.Type.Integer({ examples: [0] }),
|
|
12
|
-
total: typebox_1.Type.Integer({ examples: [1] }),
|
|
13
|
-
results: typebox_1.Type.Array(type),
|
|
14
|
-
}, { title });
|
|
15
|
-
exports.PaginatedResponse = PaginatedResponse;
|
|
16
|
-
//# sourceMappingURL=schemas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/fastify/schemas.ts"],"names":[],"mappings":";;;AAAA,+CAAkD;AAE3C,MAAM,QAAQ,GAAG,CAAoB,IAAO,EAAE,EAAE,CAAC,cAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,cAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAA3E,QAAA,QAAQ,YAAmE;AACjF,MAAM,QAAQ,GAAG,CAAoB,IAAO,EAAE,EAAE,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAA/D,QAAA,QAAQ,YAAuD;AAErE,MAAM,iBAAiB,GAAG,CAAoB,IAAO,EAAE,KAAa,EAAE,EAAE,CAC7E,cAAI,CAAC,MAAM,CACT;IACE,KAAK,EAAE,cAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACvC,MAAM,EAAE,cAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,KAAK,EAAE,cAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,OAAO,EAAE,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC;CAC1B,EACD,EAAE,KAAK,EAAE,CACV,CAAC;AATS,QAAA,iBAAiB,qBAS1B"}
|
package/dist/helpers/events.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a Promise that resolves when the specified `eventName` is emitted by the `EventEmitter`
|
|
4
|
-
* and the provided predicate returns `true` for the emitted arguments.
|
|
5
|
-
*
|
|
6
|
-
* Similar to [`events.once`](https://nodejs.org/api/events.html#eventsonceemitter-name-options),
|
|
7
|
-
* but includes support for a predicate function to filter events. Only events for which
|
|
8
|
-
* the predicate returns `true` will cause the Promise to resolve.
|
|
9
|
-
*
|
|
10
|
-
* The resolved value is an array of the arguments emitted with the event.
|
|
11
|
-
*
|
|
12
|
-
* Supports typed `EventEmitter`s and optional cancellation via `AbortSignal`.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { EventEmitter } from 'node:events';
|
|
17
|
-
*
|
|
18
|
-
* const emitter = new EventEmitter<{
|
|
19
|
-
* myEvent: [id: number, msg: string];
|
|
20
|
-
* }>();
|
|
21
|
-
*
|
|
22
|
-
* setTimeout(() => {
|
|
23
|
-
* for (let i = 0; i <= 5; i++) {
|
|
24
|
-
* emitter.emit('myEvent', i, `Message ${i}`);
|
|
25
|
-
* }
|
|
26
|
-
* }, 100);
|
|
27
|
-
*
|
|
28
|
-
* const [id, msg] = await onceWhen(emitter, 'myEvent', (id, msg) => id === 3);
|
|
29
|
-
*
|
|
30
|
-
* // outputs: "Received event with id: 3, message: Message 3"
|
|
31
|
-
* console.log(`Received event with id: ${id}, message: ${msg}`);
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* import { EventEmitter } from 'node:events';
|
|
37
|
-
*
|
|
38
|
-
* const emitter = new EventEmitter<{ myEvent: [id: number, msg: string] }>();
|
|
39
|
-
*
|
|
40
|
-
* const signal = AbortSignal.timeout(10);
|
|
41
|
-
*
|
|
42
|
-
* setTimeout(() => emitter.emit('myEvent', 1, 'Hello'), 1000);
|
|
43
|
-
*
|
|
44
|
-
* const whenPromise = onceWhen(emitter, 'myEvent', id => id === 1, { signal });
|
|
45
|
-
*
|
|
46
|
-
* // This rejects because the signal is aborted before the event is emitted
|
|
47
|
-
* await expect(whenPromise).rejects.toThrow(signal.reason);
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare function onceWhen<EventMap extends Record<string, any[]> = Record<string, any[]>, K extends Extract<keyof EventMap, string> = Extract<keyof EventMap, string>>(emitter: EventEmitter<EventMap>, eventName: K, predicate: (...args: EventMap[K]) => boolean, options?: {
|
|
51
|
-
signal?: AbortSignal;
|
|
52
|
-
}): Promise<EventMap[K]>;
|
package/dist/helpers/events.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onceWhen = onceWhen;
|
|
4
|
-
const node_events_1 = require("node:events");
|
|
5
|
-
// This is a workaround for Node.js versions that do not support Symbol.dispose
|
|
6
|
-
const DisposeSymbol = Symbol.dispose ?? Symbol.for('nodejs.dispose');
|
|
7
|
-
/**
|
|
8
|
-
* Creates a Promise that resolves when the specified `eventName` is emitted by the `EventEmitter`
|
|
9
|
-
* and the provided predicate returns `true` for the emitted arguments.
|
|
10
|
-
*
|
|
11
|
-
* Similar to [`events.once`](https://nodejs.org/api/events.html#eventsonceemitter-name-options),
|
|
12
|
-
* but includes support for a predicate function to filter events. Only events for which
|
|
13
|
-
* the predicate returns `true` will cause the Promise to resolve.
|
|
14
|
-
*
|
|
15
|
-
* The resolved value is an array of the arguments emitted with the event.
|
|
16
|
-
*
|
|
17
|
-
* Supports typed `EventEmitter`s and optional cancellation via `AbortSignal`.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { EventEmitter } from 'node:events';
|
|
22
|
-
*
|
|
23
|
-
* const emitter = new EventEmitter<{
|
|
24
|
-
* myEvent: [id: number, msg: string];
|
|
25
|
-
* }>();
|
|
26
|
-
*
|
|
27
|
-
* setTimeout(() => {
|
|
28
|
-
* for (let i = 0; i <= 5; i++) {
|
|
29
|
-
* emitter.emit('myEvent', i, `Message ${i}`);
|
|
30
|
-
* }
|
|
31
|
-
* }, 100);
|
|
32
|
-
*
|
|
33
|
-
* const [id, msg] = await onceWhen(emitter, 'myEvent', (id, msg) => id === 3);
|
|
34
|
-
*
|
|
35
|
-
* // outputs: "Received event with id: 3, message: Message 3"
|
|
36
|
-
* console.log(`Received event with id: ${id}, message: ${msg}`);
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* import { EventEmitter } from 'node:events';
|
|
42
|
-
*
|
|
43
|
-
* const emitter = new EventEmitter<{ myEvent: [id: number, msg: string] }>();
|
|
44
|
-
*
|
|
45
|
-
* const signal = AbortSignal.timeout(10);
|
|
46
|
-
*
|
|
47
|
-
* setTimeout(() => emitter.emit('myEvent', 1, 'Hello'), 1000);
|
|
48
|
-
*
|
|
49
|
-
* const whenPromise = onceWhen(emitter, 'myEvent', id => id === 1, { signal });
|
|
50
|
-
*
|
|
51
|
-
* // This rejects because the signal is aborted before the event is emitted
|
|
52
|
-
* await expect(whenPromise).rejects.toThrow(signal.reason);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
function onceWhen(emitter, eventName, predicate, options) {
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
// Immediate abort check
|
|
58
|
-
if (options?.signal?.aborted) {
|
|
59
|
-
reject(options.signal.reason ?? new Error('Aborted'));
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// Cleanup helper: remove both the event listener and the abort listener
|
|
63
|
-
const cleanup = () => {
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
65
|
-
emitter.off(eventName, listener);
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
67
|
-
disposable?.[DisposeSymbol]();
|
|
68
|
-
};
|
|
69
|
-
// Abort handler
|
|
70
|
-
const onAbort = () => {
|
|
71
|
-
cleanup();
|
|
72
|
-
reject(options?.signal?.reason ?? new Error('Aborted'));
|
|
73
|
-
};
|
|
74
|
-
// Our event listener that checks the predicate
|
|
75
|
-
const listener = (...args) => {
|
|
76
|
-
try {
|
|
77
|
-
if (predicate(...args)) {
|
|
78
|
-
cleanup();
|
|
79
|
-
resolve(args);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
cleanup();
|
|
84
|
-
reject(err);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
// Install the AbortSignal listener via Node’s helper
|
|
89
|
-
const disposable = options?.signal ? (0, node_events_1.addAbortListener)(options.signal, onAbort) : undefined;
|
|
90
|
-
emitter.on(eventName, listener);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=events.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/helpers/events.ts"],"names":[],"mappings":";;AAqDA,4BAiDC;AAtGD,6CAA6D;AAE7D,+EAA+E;AAC/E,MAAM,aAAa,GAA0B,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,SAAgB,QAAQ,CAItB,OAA+B,EAC/B,SAAY,EACZ,SAA4C,EAC5C,OAAkC;IAElC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,wBAAwB;QACxB,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC7B,MAAM,CAAE,OAAO,CAAC,MAAM,CAAC,MAAgB,IAAI,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QAED,wEAAwE;QACxE,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,mEAAmE;YAClE,OAAwB,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACnD,mEAAmE;YACnE,UAAU,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QAChC,CAAC,CAAC;QAEF,gBAAgB;QAChB,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,EAAE,CAAC;YACV,MAAM,CAAE,OAAO,EAAE,MAAM,EAAE,MAAgB,IAAI,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC;QAEF,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAiB,EAAE,EAAE;YACxC,IAAI,CAAC;gBACH,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;oBACvB,OAAO,EAAE,CAAC;oBACV,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,EAAE,CAAC;gBACV,MAAM,CAAC,GAAY,CAAC,CAAC;gBACrB,OAAO;YACT,CAAC;QACH,CAAC,CAAC;QAEF,qDAAqD;QACrD,MAAM,UAAU,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,8BAAgB,EAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE1F,OAAwB,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/helpers/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './iterators';
|
|
2
|
-
export * from './time';
|
|
3
|
-
export * from './values';
|
|
4
|
-
export * from './is-debugging';
|
|
5
|
-
export * from './events';
|
|
6
|
-
export { WorkerThreadManager } from './worker-thread-manager';
|
|
7
|
-
export type { WorkerPoolModuleInterface } from './worker-thread-manager';
|
package/dist/helpers/index.js
DELETED
|
@@ -1,25 +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
|
-
exports.WorkerThreadManager = void 0;
|
|
18
|
-
__exportStar(require("./iterators"), exports);
|
|
19
|
-
__exportStar(require("./time"), exports);
|
|
20
|
-
__exportStar(require("./values"), exports);
|
|
21
|
-
__exportStar(require("./is-debugging"), exports);
|
|
22
|
-
__exportStar(require("./events"), exports);
|
|
23
|
-
var worker_thread_manager_1 = require("./worker-thread-manager");
|
|
24
|
-
Object.defineProperty(exports, "WorkerThreadManager", { enumerable: true, get: function () { return worker_thread_manager_1.WorkerThreadManager; } });
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,yCAAuB;AACvB,2CAAyB;AACzB,iDAA+B;AAC/B,2CAAyB;AACzB,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDebugging(): boolean;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDebugging = isDebugging;
|
|
4
|
-
/*
|
|
5
|
-
* Reliable way to check if we are debugging. Supports ts-node and other tools unlike some other
|
|
6
|
-
* approaches that check argv or env vars. It also lazy-loads the `node:inspector` module to avoid
|
|
7
|
-
* unnecessary overhead in production environments where this function might not be called.
|
|
8
|
-
*/
|
|
9
|
-
function isDebugging() {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
11
|
-
const inspector = require('node:inspector');
|
|
12
|
-
const url = inspector.url();
|
|
13
|
-
return url !== undefined;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=is-debugging.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-debugging.js","sourceRoot":"","sources":["../../src/helpers/is-debugging.ts"],"names":[],"mappings":";;AAKA,kCAMC;AAXD;;;;GAIG;AACH,SAAgB,WAAW;IAEzB,8DAA8D;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAsB,CAAC;IACjE,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;IAC5B,OAAO,GAAG,KAAK,SAAS,CAAC;AAC3B,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Iterate over an array, yielding multiple items at a time. If the size of the given array
|
|
3
|
-
* is not divisible by the given batch size, then the length of the last items returned will
|
|
4
|
-
* be smaller than the given batch size, i.e.:
|
|
5
|
-
* ```typescript
|
|
6
|
-
* items.length % batchSize
|
|
7
|
-
* ```
|
|
8
|
-
* @param items - The array to iterate over.
|
|
9
|
-
* @param batchSize - Maximum number of items to return at a time.
|
|
10
|
-
* @param printBenchmark - If we should print benchmark of items per second
|
|
11
|
-
*/
|
|
12
|
-
export declare function batchIterate<T>(items: T[], batchSize: number, printBenchmark?: boolean): Generator<T[]>;
|
|
13
|
-
/**
|
|
14
|
-
* Iterate over an `AsyncIterable`, yielding multiple items at a time. If the size of the given
|
|
15
|
-
* array is not divisible by the given batch size, then the length of the last items returned will
|
|
16
|
-
* be smaller than the given batch size.
|
|
17
|
-
*
|
|
18
|
-
* @param items - AsyncIterable
|
|
19
|
-
* @param batchSize - Batch size
|
|
20
|
-
* @param printBenchmark - If we should print benchmark of items per second
|
|
21
|
-
*/
|
|
22
|
-
export declare function asyncBatchIterate<T>(items: AsyncIterable<T>, batchSize: number, printBenchmark?: boolean): AsyncGenerator<T[], void, unknown>;
|
|
23
|
-
/**
|
|
24
|
-
* Convert an `AsyncIterable` to a generator
|
|
25
|
-
* @param iter - AsyncIterable
|
|
26
|
-
*/
|
|
27
|
-
export declare function asyncIterableToGenerator<T>(iter: AsyncIterable<T>): AsyncGenerator<Awaited<T>, void, unknown>;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.batchIterate = batchIterate;
|
|
4
|
-
exports.asyncBatchIterate = asyncBatchIterate;
|
|
5
|
-
exports.asyncIterableToGenerator = asyncIterableToGenerator;
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
const values_1 = require("./values");
|
|
8
|
-
/**
|
|
9
|
-
* Iterate over an array, yielding multiple items at a time. If the size of the given array
|
|
10
|
-
* is not divisible by the given batch size, then the length of the last items returned will
|
|
11
|
-
* be smaller than the given batch size, i.e.:
|
|
12
|
-
* ```typescript
|
|
13
|
-
* items.length % batchSize
|
|
14
|
-
* ```
|
|
15
|
-
* @param items - The array to iterate over.
|
|
16
|
-
* @param batchSize - Maximum number of items to return at a time.
|
|
17
|
-
* @param printBenchmark - If we should print benchmark of items per second
|
|
18
|
-
*/
|
|
19
|
-
function* batchIterate(items, batchSize, printBenchmark = values_1.isDevEnv) {
|
|
20
|
-
if (items.length === 0)
|
|
21
|
-
return;
|
|
22
|
-
const startTime = Date.now();
|
|
23
|
-
for (let i = 0; i < items.length;) {
|
|
24
|
-
const itemsRemaining = items.length - i;
|
|
25
|
-
const sliceSize = Math.min(batchSize, itemsRemaining);
|
|
26
|
-
yield items.slice(i, i + sliceSize);
|
|
27
|
-
i += sliceSize;
|
|
28
|
-
}
|
|
29
|
-
if (printBenchmark) {
|
|
30
|
-
const itemsPerSecond = Math.round((items.length / (Date.now() - startTime)) * 1000);
|
|
31
|
-
const caller = new Error().stack?.split('at ')[3].trim();
|
|
32
|
-
logger_1.logger.debug(`Iterated ${itemsPerSecond} items/second at ${caller}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Iterate over an `AsyncIterable`, yielding multiple items at a time. If the size of the given
|
|
37
|
-
* array is not divisible by the given batch size, then the length of the last items returned will
|
|
38
|
-
* be smaller than the given batch size.
|
|
39
|
-
*
|
|
40
|
-
* @param items - AsyncIterable
|
|
41
|
-
* @param batchSize - Batch size
|
|
42
|
-
* @param printBenchmark - If we should print benchmark of items per second
|
|
43
|
-
*/
|
|
44
|
-
async function* asyncBatchIterate(items, batchSize, printBenchmark = values_1.isDevEnv) {
|
|
45
|
-
const startTime = Date.now();
|
|
46
|
-
let itemCount = 0;
|
|
47
|
-
let itemBatch = [];
|
|
48
|
-
for await (const item of items) {
|
|
49
|
-
itemBatch.push(item);
|
|
50
|
-
itemCount++;
|
|
51
|
-
if (itemBatch.length >= batchSize) {
|
|
52
|
-
yield itemBatch;
|
|
53
|
-
itemBatch = [];
|
|
54
|
-
if (printBenchmark) {
|
|
55
|
-
const itemsPerSecond = Math.round((itemCount / (Date.now() - startTime)) * 1000);
|
|
56
|
-
const caller = new Error().stack?.split('at ')[3].trim();
|
|
57
|
-
logger_1.logger.debug(`Iterated ${itemsPerSecond} items/second at ${caller}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (itemBatch.length > 0) {
|
|
62
|
-
yield itemBatch;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Convert an `AsyncIterable` to a generator
|
|
67
|
-
* @param iter - AsyncIterable
|
|
68
|
-
*/
|
|
69
|
-
async function* asyncIterableToGenerator(iter) {
|
|
70
|
-
for await (const entry of iter) {
|
|
71
|
-
yield entry;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=iterators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iterators.js","sourceRoot":"","sources":["../../src/helpers/iterators.ts"],"names":[],"mappings":";;AAcA,oCAkBC;AAWD,8CAwBC;AAMD,4DAIC;AA7ED,sCAAmC;AACnC,qCAAoC;AAEpC;;;;;;;;;;GAUG;AACH,QAAe,CAAC,CAAC,YAAY,CAC3B,KAAU,EACV,SAAiB,EACjB,cAAc,GAAG,iBAAQ;IAEzB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,GAAI,CAAC;QACnC,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACtD,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;QACpC,CAAC,IAAI,SAAS,CAAC;IACjB,CAAC;IACD,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACpF,MAAM,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACzD,eAAM,CAAC,KAAK,CAAC,YAAY,cAAc,oBAAoB,MAAM,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACI,KAAK,SAAS,CAAC,CAAC,iBAAiB,CACtC,KAAuB,EACvB,SAAiB,EACjB,cAAc,GAAG,iBAAQ;IAEzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,SAAS,GAAQ,EAAE,CAAC;IACxB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,SAAS,EAAE,CAAC;QACZ,IAAI,SAAS,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAClC,MAAM,SAAS,CAAC;YAChB,SAAS,GAAG,EAAE,CAAC;YACf,IAAI,cAAc,EAAE,CAAC;gBACnB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACjF,MAAM,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;gBACzD,eAAM,CAAC,KAAK,CAAC,YAAY,cAAc,oBAAoB,MAAM,EAAE,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,SAAS,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;GAGG;AACI,KAAK,SAAS,CAAC,CAAC,wBAAwB,CAAI,IAAsB;IACvE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QAC/B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom errors can only be deserialized correctly if they are registered here.
|
|
3
|
-
*/
|
|
4
|
-
export declare function addKnownErrorConstructor(constructor: new (message?: string, ..._arguments: unknown[]) => Error): void;
|
|
5
|
-
type SerializedError = {
|
|
6
|
-
constructorName: string;
|
|
7
|
-
name: string;
|
|
8
|
-
message: string;
|
|
9
|
-
stack: string;
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
};
|
|
12
|
-
export type ErrorLike = {
|
|
13
|
-
name: string;
|
|
14
|
-
message: string;
|
|
15
|
-
stack: string;
|
|
16
|
-
};
|
|
17
|
-
export declare function isErrorLike(value: unknown): value is ErrorLike;
|
|
18
|
-
export declare function serializeError(subject: Error): SerializedError;
|
|
19
|
-
export declare function deserializeError(subject: ErrorLike): Error;
|
|
20
|
-
export {};
|