@scpxl/nodejs-framework 1.0.49 → 1.0.56
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/README.md +12 -7
- package/dist/api-requester/api-requester.js +1 -1
- package/dist/api-requester/api-requester.js.map +2 -2
- package/dist/api-requester/index.d.ts +1 -1
- package/dist/api-requester/index.d.ts.map +1 -1
- package/dist/api-requester/index.js.map +2 -2
- package/dist/application/base-application.d.ts +6 -5
- package/dist/application/base-application.d.ts.map +1 -1
- package/dist/application/base-application.interface.d.ts +2 -4
- package/dist/application/base-application.interface.d.ts.map +1 -1
- package/dist/application/base-application.js +23 -14
- package/dist/application/base-application.js.map +2 -2
- package/dist/application/command-application.d.ts.map +1 -1
- package/dist/application/command-application.js +2 -2
- package/dist/application/command-application.js.map +2 -2
- package/dist/application/index.d.ts +3 -3
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +4 -4
- package/dist/application/index.js.map +2 -2
- package/dist/application/web-application.d.ts +5 -5
- package/dist/application/web-application.d.ts.map +1 -1
- package/dist/application/web-application.js +6 -7
- package/dist/application/web-application.js.map +2 -2
- package/dist/application/worker-application.d.ts +2 -2
- package/dist/application/worker-application.d.ts.map +1 -1
- package/dist/application/worker-application.js +2 -2
- package/dist/application/worker-application.js.map +2 -2
- package/dist/auth/jwt.d.ts.map +1 -1
- package/dist/auth/jwt.js +2 -2
- package/dist/auth/jwt.js.map +2 -2
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js.map +2 -2
- package/dist/cli/index.js +192 -7029
- package/dist/cli/index.js.map +4 -4
- package/dist/cluster/cluster-manager.d.ts.map +1 -1
- package/dist/cluster/cluster-manager.js +1 -1
- package/dist/cluster/cluster-manager.js.map +2 -2
- package/dist/command/command.d.ts +1 -1
- package/dist/command/command.d.ts.map +1 -1
- package/dist/command/command.js.map +2 -2
- package/dist/config/env.d.ts +1 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +2 -2
- package/dist/database/dynamic-entity.js +9 -9
- package/dist/database/dynamic-entity.js.map +2 -2
- package/dist/database/index.d.ts +3 -3
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +5 -5
- package/dist/database/index.js.map +2 -2
- package/dist/database/instance.d.ts +3 -3
- package/dist/database/instance.js +3 -3
- package/dist/database/instance.js.map +1 -1
- package/dist/database/manager.d.ts +1 -0
- package/dist/database/manager.d.ts.map +1 -1
- package/dist/database/manager.js +16 -3
- package/dist/database/manager.js.map +2 -2
- package/dist/error/error-reporter.js +1 -1
- package/dist/error/error-reporter.js.map +2 -2
- package/dist/error/index.d.ts +2 -3
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +8 -9
- package/dist/error/index.js.map +2 -2
- package/dist/event/controller/base.d.ts +2 -2
- package/dist/event/controller/base.d.ts.map +1 -1
- package/dist/event/controller/base.js +2 -2
- package/dist/event/controller/base.js.map +2 -2
- package/dist/event/index.d.ts +3 -3
- package/dist/event/index.d.ts.map +1 -1
- package/dist/event/index.js +5 -5
- package/dist/event/index.js.map +2 -2
- package/dist/event/manager.d.ts.map +1 -1
- package/dist/event/manager.interface.d.ts +2 -3
- package/dist/event/manager.interface.d.ts.map +1 -1
- package/dist/event/manager.js.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.d.ts.map +1 -1
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle/index.js.map +2 -2
- package/dist/lifecycle/lifecycle-manager.d.ts +6 -0
- package/dist/lifecycle/lifecycle-manager.d.ts.map +1 -1
- package/dist/lifecycle/lifecycle-manager.js +28 -0
- package/dist/lifecycle/lifecycle-manager.js.map +2 -2
- package/dist/logger/logger.d.ts +20 -1
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +68 -96
- package/dist/logger/logger.js.map +2 -2
- package/dist/performance/cache-performance.d.ts.map +1 -1
- package/dist/performance/cache-performance.js +1 -1
- package/dist/performance/cache-performance.js.map +2 -2
- package/dist/performance/database-performance.d.ts.map +1 -1
- package/dist/performance/database-performance.js +1 -1
- package/dist/performance/database-performance.js.map +2 -2
- package/dist/performance/index.d.ts +3 -3
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/performance/index.js.map +1 -1
- package/dist/performance/performance-monitor.js +2 -2
- package/dist/performance/performance-monitor.js.map +2 -2
- package/dist/performance/performance-monitor.plugin.d.ts.map +1 -1
- package/dist/performance/performance-monitor.plugin.js +1 -1
- package/dist/performance/performance-monitor.plugin.js.map +2 -2
- package/dist/performance/queue-performance.d.ts.map +1 -1
- package/dist/performance/queue-performance.js +1 -1
- package/dist/performance/queue-performance.js.map +2 -2
- package/dist/performance/webserver-performance.d.ts.map +1 -1
- package/dist/performance/webserver-performance.js +1 -1
- package/dist/performance/webserver-performance.js.map +2 -2
- package/dist/performance/websocket-performance.d.ts.map +1 -1
- package/dist/performance/websocket-performance.js +1 -1
- package/dist/performance/websocket-performance.js.map +2 -2
- package/dist/queue/index.d.ts +2 -2
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.interface.d.ts +1 -1
- package/dist/queue/index.interface.d.ts.map +1 -1
- package/dist/queue/index.js.map +2 -2
- package/dist/queue/manager.d.ts +9 -2
- package/dist/queue/manager.d.ts.map +1 -1
- package/dist/queue/manager.js +44 -6
- package/dist/queue/manager.js.map +2 -2
- package/dist/queue/processor/base.d.ts +5 -5
- package/dist/queue/processor/base.d.ts.map +1 -1
- package/dist/queue/processor/base.js +2 -2
- package/dist/queue/processor/base.js.map +2 -2
- package/dist/queue/processor/processor.interface.d.ts +3 -3
- package/dist/queue/processor/processor.interface.d.ts.map +1 -1
- package/dist/queue/worker.d.ts +5 -0
- package/dist/queue/worker.d.ts.map +1 -1
- package/dist/queue/worker.interface.d.ts +1 -1
- package/dist/queue/worker.interface.d.ts.map +1 -1
- package/dist/queue/worker.js +9 -1
- package/dist/queue/worker.js.map +2 -2
- package/dist/redis/index.d.ts +1 -1
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +5 -4
- package/dist/redis/index.js.map +2 -2
- package/dist/redis/instance.js +1 -1
- package/dist/redis/instance.js.map +2 -2
- package/dist/redis/manager.d.ts +7 -1
- package/dist/redis/manager.d.ts.map +1 -1
- package/dist/redis/manager.js +20 -4
- package/dist/redis/manager.js.map +2 -2
- package/dist/request-context/index.d.ts +1 -1
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +5 -5
- package/dist/request-context/index.js.map +1 -1
- package/dist/schemas/entity-builder.d.ts +3 -3
- package/dist/schemas/entity-builder.d.ts.map +1 -1
- package/dist/schemas/entity-builder.js.map +1 -1
- package/dist/services/aws/s3.d.ts.map +1 -1
- package/dist/services/aws/s3.js +7 -10
- package/dist/services/aws/s3.js.map +2 -2
- package/dist/util/file.d.ts +13 -8
- package/dist/util/file.d.ts.map +1 -1
- package/dist/util/file.js +6 -28
- package/dist/util/file.js.map +2 -2
- package/dist/util/helper.js +2 -2
- package/dist/util/helper.js.map +2 -2
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +18 -18
- package/dist/util/index.js.map +2 -2
- package/dist/util/loader.js +3 -3
- package/dist/util/loader.js.map +2 -2
- package/dist/util/os.js +2 -2
- package/dist/util/os.js.map +2 -2
- package/dist/webserver/controller/auth-middleware.d.ts +1 -1
- package/dist/webserver/controller/auth-middleware.d.ts.map +1 -1
- package/dist/webserver/controller/auth-middleware.js +1 -1
- package/dist/webserver/controller/auth-middleware.js.map +2 -2
- package/dist/webserver/controller/base.d.ts +6 -6
- package/dist/webserver/controller/base.d.ts.map +1 -1
- package/dist/webserver/controller/base.interface.d.ts +1 -1
- package/dist/webserver/controller/base.interface.d.ts.map +1 -1
- package/dist/webserver/controller/base.js +4 -4
- package/dist/webserver/controller/base.js.map +2 -2
- package/dist/webserver/controller/entity.d.ts +4 -3
- package/dist/webserver/controller/entity.d.ts.map +1 -1
- package/dist/webserver/controller/entity.js +26 -17
- package/dist/webserver/controller/entity.js.map +2 -2
- package/dist/webserver/controller/example-auth.d.ts.map +1 -1
- package/dist/webserver/controller/example-auth.js +1 -1
- package/dist/webserver/controller/example-auth.js.map +2 -2
- package/dist/webserver/controller/health.d.ts.map +1 -1
- package/dist/webserver/controller/health.js +1 -1
- package/dist/webserver/controller/health.js.map +2 -2
- package/dist/webserver/define-action.d.ts +1 -1
- package/dist/webserver/define-action.d.ts.map +1 -1
- package/dist/webserver/define-action.js.map +1 -1
- package/dist/webserver/define-route.d.ts +1 -1
- package/dist/webserver/define-route.d.ts.map +1 -1
- package/dist/webserver/define-route.js.map +2 -2
- package/dist/webserver/index.d.ts +9 -9
- package/dist/webserver/index.d.ts.map +1 -1
- package/dist/webserver/index.js +14 -14
- package/dist/webserver/index.js.map +2 -2
- package/dist/webserver/webserver.d.ts +3 -3
- package/dist/webserver/webserver.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.d.ts +5 -5
- package/dist/webserver/webserver.interface.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.js.map +1 -1
- package/dist/webserver/webserver.js +9 -9
- package/dist/webserver/webserver.js.map +2 -2
- package/dist/websocket/controller/server/base.d.ts +2 -2
- package/dist/websocket/controller/server/base.js.map +1 -1
- package/dist/websocket/controllers/server/system.d.ts.map +1 -1
- package/dist/websocket/controllers/server/system.js +1 -1
- package/dist/websocket/controllers/server/system.js.map +2 -2
- package/dist/websocket/index.d.ts +9 -11
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +22 -22
- package/dist/websocket/index.js.map +2 -2
- package/dist/websocket/subscriber-middleware.d.ts.map +1 -1
- package/dist/websocket/subscriber-middleware.js.map +2 -2
- package/dist/websocket/subscriber-utils.d.ts.map +1 -1
- package/dist/websocket/subscriber-utils.js.map +2 -2
- package/dist/websocket/utils.d.ts.map +1 -1
- package/dist/websocket/utils.js +4 -2
- package/dist/websocket/utils.js.map +2 -2
- package/dist/websocket/websocket-auth.d.ts.map +1 -1
- package/dist/websocket/websocket-auth.js +3 -3
- package/dist/websocket/websocket-auth.js.map +2 -2
- package/dist/websocket/websocket-base.d.ts +2 -2
- package/dist/websocket/websocket-base.d.ts.map +1 -1
- package/dist/websocket/websocket-base.js +1 -1
- package/dist/websocket/websocket-base.js.map +2 -2
- package/dist/websocket/websocket-client-manager.d.ts +2 -0
- package/dist/websocket/websocket-client-manager.d.ts.map +1 -1
- package/dist/websocket/websocket-client-manager.js +11 -4
- package/dist/websocket/websocket-client-manager.js.map +2 -2
- package/dist/websocket/websocket-client.d.ts +10 -5
- package/dist/websocket/websocket-client.d.ts.map +1 -1
- package/dist/websocket/websocket-client.js +27 -5
- package/dist/websocket/websocket-client.js.map +2 -2
- package/dist/websocket/websocket-room-manager.js +1 -1
- package/dist/websocket/websocket-room-manager.js.map +1 -1
- package/dist/websocket/websocket-server.d.ts +7 -7
- package/dist/websocket/websocket-server.d.ts.map +1 -1
- package/dist/websocket/websocket-server.js +25 -20
- package/dist/websocket/websocket-server.js.map +2 -2
- package/dist/websocket/websocket-service.d.ts +2 -2
- package/dist/websocket/websocket-service.d.ts.map +1 -1
- package/dist/websocket/websocket-service.js +1 -1
- package/dist/websocket/websocket-service.js.map +2 -2
- package/dist/websocket/websocket.interface.d.ts +3 -5
- package/dist/websocket/websocket.interface.d.ts.map +1 -1
- package/dist/websocket/websocket.interface.js.map +2 -2
- package/package.json +68 -64
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/request-context/index.ts"],
|
|
4
|
-
"sourcesContent": ["export type { RequestContext, RunWithContextOptions } from './request-context.interface.js';\nexport {\n
|
|
4
|
+
"sourcesContent": ["export type { RequestContext, RunWithContextOptions } from './request-context.interface.js';\nexport {\n enterRequestContext,\n getContextMetadata,\n getRequestContext,\n getRequestId,\n getUserId,\n requestContextStorage,\n runWithContext,\n runWithContextAsync,\n setContextMetadata,\n setUserId,\n} from './request-context.js';\n"],
|
|
5
5
|
"mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
* - readAugment: additional fields present on the persisted/read model (e.g. id, timestamps)
|
|
7
7
|
* - strict: apply .strict() to objects (defaults true)
|
|
8
8
|
*/
|
|
9
|
-
export interface BuildEntitySchemasOptions<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape =
|
|
9
|
+
export interface BuildEntitySchemasOptions<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape = Record<string, never>> {
|
|
10
10
|
shape: Shape;
|
|
11
11
|
updatableFields?: readonly Updatable[];
|
|
12
12
|
readAugment?: ReadAugment;
|
|
@@ -21,7 +21,7 @@ export interface BuiltEntitySchemas<Shape extends z.ZodRawShape, Updatable exten
|
|
|
21
21
|
keys: (keyof Shape)[];
|
|
22
22
|
updatableKeys: Updatable[];
|
|
23
23
|
}
|
|
24
|
-
export declare function buildEntitySchemas<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape =
|
|
24
|
+
export declare function buildEntitySchemas<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape = Record<string, never>>(options: BuildEntitySchemasOptions<Shape, Updatable, ReadAugment>): BuiltEntitySchemas<Shape, Updatable, ReadAugment>;
|
|
25
25
|
export declare const HttpMethodSchema: z.ZodEnum<{
|
|
26
26
|
GET: "GET";
|
|
27
27
|
POST: "POST";
|
|
@@ -31,5 +31,5 @@ export declare const HttpMethodSchema: z.ZodEnum<{
|
|
|
31
31
|
PATCH: "PATCH";
|
|
32
32
|
OPTIONS: "OPTIONS";
|
|
33
33
|
}>;
|
|
34
|
-
export declare const HttpStatusCodeSchema: z.core.$ZodBranded<z.ZodNumber, "HttpStatusCode">;
|
|
34
|
+
export declare const HttpStatusCodeSchema: z.core.$ZodBranded<z.ZodNumber, "HttpStatusCode", "out">;
|
|
35
35
|
//# sourceMappingURL=entity-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-builder.d.ts","sourceRoot":"","sources":["../../src/schemas/entity-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB,CACxC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,KAAK,EAC3C,WAAW,SAAS,CAAC,CAAC,WAAW,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"entity-builder.d.ts","sourceRoot":"","sources":["../../src/schemas/entity-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB,CACxC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,KAAK,EAC3C,WAAW,SAAS,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAEzD,KAAK,EAAE,KAAK,CAAC;IACb,eAAe,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACvC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,kBAAkB,CACjC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,EAC7B,WAAW,SAAS,CAAC,CAAC,WAAW;IAEjC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC3B,+DAA+D;IAC/D,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,GAAG,WAAW,CAAC,CAAC;IACvC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACtB,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,KAAK,EAC3C,WAAW,SAAS,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzD,OAAO,EAAE,yBAAyB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,GAChE,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,CAoCnD;AAGD,eAAO,MAAM,gBAAgB;;;;;;;;EAAuE,CAAC;AACrG,eAAO,MAAM,oBAAoB,0DAA+D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/schemas/entity-builder.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from 'zod';\n\n/**\n * Options for building standardized entity schemas.\n * - shape: base create shape (required fields for creation)\n * - updatableFields: subset of keys allowed in updates (defaults to all keys of shape)\n * - readAugment: additional fields present on the persisted/read model (e.g. id, timestamps)\n * - strict: apply .strict() to objects (defaults true)\n */\nexport interface BuildEntitySchemasOptions<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape = keyof Shape,\n ReadAugment extends z.ZodRawShape =
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod';\n\n/**\n * Options for building standardized entity schemas.\n * - shape: base create shape (required fields for creation)\n * - updatableFields: subset of keys allowed in updates (defaults to all keys of shape)\n * - readAugment: additional fields present on the persisted/read model (e.g. id, timestamps)\n * - strict: apply .strict() to objects (defaults true)\n */\nexport interface BuildEntitySchemasOptions<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape = keyof Shape,\n ReadAugment extends z.ZodRawShape = Record<string, never>,\n> {\n shape: Shape;\n updatableFields?: readonly Updatable[];\n readAugment?: ReadAugment; // fields that exist after persistence (e.g. id, createdAt)\n strict?: boolean;\n requireAtLeastOneOnUpdate?: boolean; // default true\n}\n\nexport interface BuiltEntitySchemas<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape,\n ReadAugment extends z.ZodRawShape,\n> {\n create: z.ZodObject<Shape>;\n /** Update schema is a partial over selected updatable keys. */\n update: z.ZodTypeAny;\n read: z.ZodObject<Shape & ReadAugment>;\n keys: (keyof Shape)[];\n updatableKeys: Updatable[];\n}\n\nexport function buildEntitySchemas<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape = keyof Shape,\n ReadAugment extends z.ZodRawShape = Record<string, never>,\n>(\n options: BuildEntitySchemasOptions<Shape, Updatable, ReadAugment>,\n): BuiltEntitySchemas<Shape, Updatable, ReadAugment> {\n const { shape, updatableFields, readAugment, strict = true, requireAtLeastOneOnUpdate = true } = options;\n\n // Freeze to avoid accidental mutation\n Object.freeze(shape);\n\n const create = strict ? z.object(shape).strict() : z.object(shape);\n\n const updatableKeys = updatableFields ? [...updatableFields] : (Object.keys(shape) as Updatable[]);\n // Build pick mask for updatable keys\n const pickMask = updatableKeys.reduce<Record<string, true>>((acc, key) => {\n acc[String(key)] = true;\n return acc;\n }, {});\n\n const updateBase = updatableFields ? (create as z.ZodObject<any>).pick(pickMask) : (create as z.ZodObject<any>);\n let updateObject: z.ZodTypeAny = updateBase.partial();\n\n if (requireAtLeastOneOnUpdate) {\n updateObject = updateObject.refine(\n (value: unknown) =>\n !!value && typeof value === 'object' && Object.keys(value as Record<string, unknown>).length > 0,\n 'At least one field must be provided for update',\n );\n }\n\n const readShape = { ...shape, ...(readAugment ?? {}) } as Shape & ReadAugment;\n const read = strict ? z.object(readShape).strict() : z.object(readShape);\n\n return {\n create,\n update: updateObject,\n read: read as z.ZodObject<Shape & ReadAugment>,\n keys: Object.keys(shape) as (keyof Shape)[],\n updatableKeys,\n };\n}\n\n// Common atoms for reuse in entity schemas\nexport const HttpMethodSchema = z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']);\nexport const HttpStatusCodeSchema = z.number().int().min(100).max(599).brand<'HttpStatusCode'>();\n"],
|
|
5
5
|
"mappings": ";;AAAA,SAAS,SAAS;AAkCX,SAAS,mBAKd,SACmD;AACnD,QAAM,EAAE,OAAO,iBAAiB,aAAa,SAAS,MAAM,4BAA4B,KAAK,IAAI;AAGjG,SAAO,OAAO,KAAK;AAEnB,QAAM,SAAS,SAAS,EAAE,OAAO,KAAK,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAEjE,QAAM,gBAAgB,kBAAkB,CAAC,GAAG,eAAe,IAAK,OAAO,KAAK,KAAK;AAEjF,QAAM,WAAW,cAAc,OAA6B,CAAC,KAAK,QAAQ;AACxE,QAAI,OAAO,GAAG,CAAC,IAAI;AACnB,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,kBAAmB,OAA4B,KAAK,QAAQ,IAAK;AACpF,MAAI,eAA6B,WAAW,QAAQ;AAEpD,MAAI,2BAA2B;AAC7B,mBAAe,aAAa;AAAA,MAC1B,CAAC,UACC,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,OAAO,KAAK,KAAgC,EAAE,SAAS;AAAA,MACjG;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,EAAE,GAAG,OAAO,GAAI,eAAe,CAAC,EAAG;AACrD,QAAM,OAAO,SAAS,EAAE,OAAO,SAAS,EAAE,OAAO,IAAI,EAAE,OAAO,SAAS;AAEvE,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,MAAM,OAAO,KAAK,KAAK;AAAA,IACvB;AAAA,EACF;AACF;AA1CgB;AA6CT,MAAM,mBAAmB,EAAE,KAAK,CAAC,OAAO,QAAQ,OAAO,UAAU,SAAS,QAAQ,SAAS,CAAC;AAC5F,MAAM,uBAAuB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,IAAI,GAAG,EAAE,MAAwB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../src/services/aws/s3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../src/services/aws/s3.ts"],"names":[],"mappings":"AAIA,OAAO,EAML,QAAQ,EAGT,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAIjE,UAAU,mBAAmB;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,CAAC,OAAO,OAAO,KAAK;IACjB,MAAM,EAAE,QAAQ,CAAC;IAExB,OAAO,CAAC,OAAO,CAA0B;gBAE7B,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC;IA4CrD,OAAO,CAAC,YAAY;IAQP,UAAU,CAAC,EACtB,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,GACX,EAAE;QACD,UAAU,EAAE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AAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC,GAAG,OAAO,CAAC,IAAI,CAAC;IA+EJ,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CA2BlG"}
|
package/dist/services/aws/s3.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { createWriteStream } from "node:fs";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
import { pipeline, Readable } from "node:stream";
|
|
6
|
+
import { promisify } from "node:util";
|
|
3
7
|
import {
|
|
4
8
|
CompleteMultipartUploadCommand,
|
|
5
9
|
CreateMultipartUploadCommand,
|
|
@@ -9,12 +13,8 @@ import {
|
|
|
9
13
|
UploadPartCommand
|
|
10
14
|
} from "@aws-sdk/client-s3";
|
|
11
15
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
12
|
-
import { File, Helper } from "../../util/index.js";
|
|
13
|
-
import { createWriteStream } from "fs";
|
|
14
|
-
import { Readable, pipeline } from "stream";
|
|
15
|
-
import { promisify } from "node:util";
|
|
16
16
|
import { Logger } from "../../logger/index.js";
|
|
17
|
-
import {
|
|
17
|
+
import { File, Helper } from "../../util/index.js";
|
|
18
18
|
const asyncPipeline = promisify(pipeline);
|
|
19
19
|
class AwsS3 {
|
|
20
20
|
static {
|
|
@@ -55,13 +55,10 @@ class AwsS3 {
|
|
|
55
55
|
this.client = new S3Client(s3ClientConfig);
|
|
56
56
|
}
|
|
57
57
|
getBucketUrl({ bucketName, path }) {
|
|
58
|
-
let url;
|
|
59
58
|
if (this.options.localstack.enabled) {
|
|
60
|
-
|
|
61
|
-
} else {
|
|
62
|
-
url = `https://${bucketName}.s3.amazonaws.com/${path}`;
|
|
59
|
+
return `http://localhost:${this.options.localstack.port}/${bucketName}/${path}`;
|
|
63
60
|
}
|
|
64
|
-
return
|
|
61
|
+
return `https://${bucketName}.s3.amazonaws.com/${path}`;
|
|
65
62
|
}
|
|
66
63
|
async uploadFile({
|
|
67
64
|
bucketName,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/services/aws/s3.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n CompleteMultipartUploadCommand,\n CreateMultipartUploadCommand,\n GetObjectCommand,\n PutObjectCommand,\n type PutObjectCommandInput,\n S3Client,\n type S3ClientConfig,\n UploadPartCommand,\n} from '@aws-sdk/client-s3';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport {
|
|
5
|
-
"mappings": ";;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { createWriteStream } from 'node:fs';\nimport { dirname } from 'node:path';\nimport { pipeline, Readable } from 'node:stream';\nimport { promisify } from 'node:util';\nimport {\n CompleteMultipartUploadCommand,\n CreateMultipartUploadCommand,\n GetObjectCommand,\n PutObjectCommand,\n type PutObjectCommandInput,\n S3Client,\n type S3ClientConfig,\n UploadPartCommand,\n} from '@aws-sdk/client-s3';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport { Logger } from '../../logger/index.js';\nimport { File, Helper } from '../../util/index.js';\nimport type { AwsS3ConstructorOptions } from './s3.interface.js';\n\nconst asyncPipeline = promisify(pipeline);\n\ninterface DownloadFileOptions {\n bucketName: string;\n key: string;\n destinationFilePath: string;\n}\n\nexport default class AwsS3 {\n public client: S3Client;\n\n private options: AwsS3ConstructorOptions;\n\n constructor(options: Partial<AwsS3ConstructorOptions>) {\n // Define default options\n const defaultOptions: AwsS3ConstructorOptions = {\n region: 'us-east-1',\n localstack: {\n enabled: false,\n port: 4566,\n },\n };\n\n this.options = Helper.defaultsDeep(options, defaultOptions) as AwsS3ConstructorOptions;\n\n const s3ClientConfig: S3ClientConfig = {\n region: this.options.region,\n };\n\n if (this.options.localstack.enabled) {\n s3ClientConfig.forcePathStyle = true;\n\n if (!this.options.endpoint) {\n throw new Error('Endpoint is required when using LocalStack');\n }\n\n // s3ClientConfig.endpoint = `http://s3.localhost.localstack.cloud:${this.options.localstack.port}`; // Works when the Node.js API is calling from within the Docker container\n // s3ClientConfig.endpoint = `http://localhost:${this.options.localstack.port}`; // works out side of the container (media generator example)\n\n s3ClientConfig.endpoint = this.options.endpoint;\n\n s3ClientConfig.credentials = {\n accessKeyId: 'test',\n secretAccessKey: 'test',\n };\n } else {\n if (this.options.credentials?.accessKeyId && this.options.credentials?.secretAccessKey) {\n s3ClientConfig.credentials = {\n accessKeyId: this.options.credentials.accessKeyId,\n secretAccessKey: this.options.credentials.secretAccessKey,\n };\n }\n }\n\n this.client = new S3Client(s3ClientConfig);\n }\n\n private getBucketUrl({ bucketName, path }: { bucketName: string; path: string }) {\n if (this.options.localstack.enabled) {\n return `http://localhost:${this.options.localstack.port}/${bucketName}/${path}`;\n }\n\n return `https://${bucketName}.s3.amazonaws.com/${path}`;\n }\n\n public async uploadFile({\n bucketName,\n path,\n body,\n contentType,\n forceDownload,\n publicRead,\n }: {\n bucketName: string;\n path: string;\n body: Buffer;\n contentType?: string;\n forceDownload?: boolean;\n publicRead?: boolean;\n }): Promise<string> {\n let contentDisposition = forceDownload ? 'attachment' : 'inline';\n contentDisposition += `; filename=\"${path.split('/').pop()}\"`;\n\n const putObjectOptions: PutObjectCommandInput = {\n Bucket: bucketName,\n Key: path,\n Body: body,\n ContentDisposition: contentDisposition,\n ACL: publicRead ? 'public-read' : 'private',\n };\n\n if (contentType) {\n putObjectOptions.ContentType = contentType;\n }\n\n const command = new PutObjectCommand(putObjectOptions);\n\n await this.client.send(command);\n\n return this.getBucketUrl({ bucketName, path });\n }\n\n public async startMultipartUpload({\n bucketName,\n path,\n publicRead,\n }: {\n bucketName: string;\n path: string;\n publicRead?: boolean;\n }) {\n const command = new CreateMultipartUploadCommand({\n Bucket: bucketName,\n Key: path,\n ACL: publicRead ? 'public-read' : 'private',\n });\n\n const response = await this.client.send(command);\n\n return response.UploadId;\n }\n\n public async uploadPart({\n bucketName,\n path,\n partNumber,\n uploadId,\n body,\n }: {\n bucketName: string;\n path: string;\n partNumber: number;\n uploadId: string;\n body: any;\n }): Promise<string | undefined> {\n const command = new UploadPartCommand({\n Bucket: bucketName,\n Key: path,\n PartNumber: partNumber,\n UploadId: uploadId,\n Body: body,\n });\n\n const response = await this.client.send(command);\n\n return response.ETag;\n }\n\n public async completeMultipartUpload({\n bucketName,\n path,\n uploadId,\n parts,\n }: {\n bucketName: string;\n path: string;\n uploadId: string;\n parts: { PartNumber: number; ETag: string }[];\n }) {\n // Sort parts by PartNumber\n parts.sort((a, b) => a.PartNumber - b.PartNumber);\n\n const command = new CompleteMultipartUploadCommand({\n Bucket: bucketName,\n Key: path,\n UploadId: uploadId,\n MultipartUpload: {\n Parts: parts,\n },\n });\n\n const response = await this.client.send(command);\n\n if (!response.Location) {\n throw new Error('Failed to complete multipart upload');\n }\n\n // return response.Location;\n return this.getBucketUrl({\n bucketName,\n path,\n });\n }\n\n async downloadFile({\n bucketName,\n key,\n destinationFilePath,\n onStart,\n onProgress,\n onComplete,\n onError,\n }: DownloadFileOptions & {\n onStart?: () => void;\n onProgress?: (progress: number) => void;\n onComplete?: () => void;\n onError?: (error: Error) => void;\n }): Promise<void> {\n const decodedKey = decodeURIComponent(key);\n const bucketKey = decodedKey;\n\n Logger.info({\n message: 'Downloading file from S3',\n meta: {\n bucketName,\n Key: bucketKey,\n },\n });\n\n const getObjectParams = {\n Bucket: bucketName,\n Key: bucketKey,\n };\n\n try {\n const command = new GetObjectCommand(getObjectParams);\n\n const response = await this.client.send(command);\n\n if (!response.Body || !(response.Body instanceof Readable)) {\n throw new Error('Expected Body to be a readable stream!');\n }\n\n if (onStart) {\n onStart();\n }\n\n const directoryPath = dirname(destinationFilePath);\n\n // Ensure directory exists\n await File.ensureDir(directoryPath);\n\n const fileStream = createWriteStream(destinationFilePath);\n const totalSize = parseInt(response.ContentLength?.toString() ?? '0', 10);\n\n let bytesRead = 0;\n\n response.Body.on('data', (chunk: Buffer) => {\n bytesRead += chunk.length;\n\n if (onProgress && totalSize > 0) {\n const progress = Math.min((bytesRead / totalSize) * 100, 100);\n const formattedProgress = parseFloat(progress.toFixed(1));\n\n onProgress(formattedProgress);\n }\n });\n\n await asyncPipeline(response.Body, fileStream);\n\n // Verify file was written\n if (!(await File.pathExists(destinationFilePath))) {\n throw new Error(`Could not find downloaded file at ${destinationFilePath}`);\n }\n\n Logger.info({\n message: 'File successfully downloaded',\n meta: {\n Path: destinationFilePath,\n },\n });\n\n if (onComplete) {\n onComplete();\n }\n } catch (error) {\n Logger.error({ error });\n\n if (onError) {\n onError(error as Error);\n }\n\n throw error as Error;\n }\n }\n\n public async generateSignedUrl({ bucket, key }: { bucket: string; key: string }): Promise<string> {\n try {\n const command = new GetObjectCommand({\n Bucket: bucket,\n Key: key,\n });\n\n // Set the expiration for the signed URL to 1 hour\n const signedUrl = await getSignedUrl(this.client, command, {\n expiresIn: 3600,\n });\n\n // Log the signed URL\n Logger.info({\n message: 'Generated signed URL',\n meta: {\n URL: signedUrl,\n },\n });\n\n return signedUrl;\n } catch (error) {\n Logger.error({ error });\n\n throw error;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAS,yBAAyB;AAClC,SAAS,eAAe;AACxB,SAAS,UAAU,gBAAgB;AACnC,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,MAAM,cAAc;AAG7B,MAAM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B;AAAA,MACF,CAAC;AAED,YAAM,cAAc,SAAS,MAAM,UAAU;AAG7C,UAAI,CAAE,MAAM,KAAK,WAAW,mBAAmB,GAAI;AACjD,cAAM,IAAI,MAAM,qCAAqC,mBAAmB,EAAE;AAAA,MAC5E;AAEA,aAAO,KAAK;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,MAAM;AAAA,QACR;AAAA,MACF,CAAC;AAED,UAAI,YAAY;AACd,mBAAW;AAAA,MACb;AAAA,IACF,SAAS,OAAO;AACd,aAAO,MAAM,EAAE,MAAM,CAAC;AAEtB,UAAI,SAAS;AACX,gBAAQ,KAAc;AAAA,MACxB;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,MAAa,kBAAkB,EAAE,QAAQ,IAAI,GAAqD;AAChG,QAAI;AACF,YAAM,UAAU,IAAI,iBAAiB;AAAA,QACnC,QAAQ;AAAA,QACR,KAAK;AAAA,MACP,CAAC;AAGD,YAAM,YAAY,MAAM,aAAa,KAAK,QAAQ,SAAS;AAAA,QACzD,WAAW;AAAA,MACb,CAAC;AAGD,aAAO,KAAK;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,KAAK;AAAA,QACP;AAAA,MACF,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,aAAO,MAAM,EAAE,MAAM,CAAC;AAEtB,YAAM;AAAA,IACR;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/file.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ declare function pathExists(pathToCheck: string): Promise<boolean>;
|
|
|
9
9
|
* @param dirPath - Directory path to ensure
|
|
10
10
|
*/
|
|
11
11
|
declare function ensureDir(dirPath: string): Promise<void>;
|
|
12
|
-
declare function convertFile({ inputFilePath, outputFilePath, format, }: {
|
|
13
|
-
inputFilePath: string;
|
|
14
|
-
outputFilePath: string;
|
|
15
|
-
format: string;
|
|
16
|
-
}): Promise<void>;
|
|
17
12
|
/**
|
|
18
|
-
* Copy a file or directory synchronously
|
|
13
|
+
* Copy a file or directory synchronously.
|
|
14
|
+
*
|
|
15
|
+
* **Note**: This function uses synchronous file system operations which block
|
|
16
|
+
* the event loop. It is intended for use during application initialization,
|
|
17
|
+
* build scripts, or CLI tools where blocking is acceptable.
|
|
18
|
+
* For production runtime code with high concurrency, consider using async alternatives.
|
|
19
19
|
*
|
|
20
20
|
* @param src The source path
|
|
21
21
|
* @param dest The destination path
|
|
@@ -40,13 +40,18 @@ declare function formatFileSize({ bytes }: {
|
|
|
40
40
|
bytes: number;
|
|
41
41
|
}): string;
|
|
42
42
|
/**
|
|
43
|
-
* Remove a file or directory synchronously
|
|
43
|
+
* Remove a file or directory synchronously.
|
|
44
|
+
*
|
|
45
|
+
* **Note**: This function uses synchronous file system operations which block
|
|
46
|
+
* the event loop. It is intended for use during application cleanup, build scripts,
|
|
47
|
+
* or CLI tools where blocking is acceptable.
|
|
48
|
+
* For production runtime code with high concurrency, consider using async alternatives
|
|
49
|
+
* like `fs.promises.rm(target, { recursive: true, force: true })`.
|
|
44
50
|
*
|
|
45
51
|
* @param target The path to the file or directory to remove
|
|
46
52
|
*/
|
|
47
53
|
declare function removeSync(target: string): void;
|
|
48
54
|
declare const _default: {
|
|
49
|
-
convertFile: typeof convertFile;
|
|
50
55
|
copySync: typeof copySync;
|
|
51
56
|
downloadFile: typeof downloadFile;
|
|
52
57
|
formatFileSize: typeof formatFileSize;
|
package/dist/util/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,iBAAe,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO/D;AAED;;;GAGG;AACH,iBAAe,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvD;AAED;;;;;;;;;;GAUG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAmBjD;AAED;;;;;GAKG;AACH,iBAAe,YAAY,CAAC,EAAE,GAAG,EAAE,eAAe,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA4B7G;AAED;;;;GAIG;AACH,iBAAS,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAyB5D;AAED;;;;;;;;;;GAUG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAoBxC;;;;;;;;;AAED,wBAOE"}
|
package/dist/util/file.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { access, mkdir } from "fs/promises";
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
import { pipeline } from "stream";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import { access, mkdir } from "node:fs/promises";
|
|
5
|
+
import * as https from "node:https";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { pipeline } from "node:stream";
|
|
8
8
|
import { promisify } from "node:util";
|
|
9
|
-
import ffmpeg from "fluent-ffmpeg";
|
|
10
9
|
const pipelineAsync = promisify(pipeline);
|
|
11
10
|
async function pathExists(pathToCheck) {
|
|
12
11
|
try {
|
|
@@ -25,26 +24,6 @@ async function ensureDir(dirPath) {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
__name(ensureDir, "ensureDir");
|
|
28
|
-
async function convertFile({
|
|
29
|
-
inputFilePath,
|
|
30
|
-
outputFilePath,
|
|
31
|
-
format
|
|
32
|
-
}) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
console.log(`Starting conversion: ${inputFilePath} -> ${outputFilePath} (format: ${format})`);
|
|
35
|
-
const command = ffmpeg(inputFilePath).output(outputFilePath).outputFormat(format === "jpg" ? "mjpeg" : format).on("progress", (progress) => {
|
|
36
|
-
console.log(`Processing: ${Math.round(progress.percent)}% done`);
|
|
37
|
-
}).on("end", () => {
|
|
38
|
-
console.log("Conversion finished successfully");
|
|
39
|
-
resolve();
|
|
40
|
-
}).on("error", (err) => {
|
|
41
|
-
console.error("Error during conversion:", err);
|
|
42
|
-
reject(err);
|
|
43
|
-
});
|
|
44
|
-
command.run();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
__name(convertFile, "convertFile");
|
|
48
27
|
function copySync(src, dest) {
|
|
49
28
|
const stats = fs.statSync(src);
|
|
50
29
|
if (stats.isDirectory()) {
|
|
@@ -89,7 +68,7 @@ function formatFileSize({ bytes }) {
|
|
|
89
68
|
let idx = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
90
69
|
if (idx < 0) idx = 0;
|
|
91
70
|
if (idx >= units.length) idx = units.length - 1;
|
|
92
|
-
const fileSize = (bytes /
|
|
71
|
+
const fileSize = (bytes / 1024 ** idx).toFixed(1);
|
|
93
72
|
let unit;
|
|
94
73
|
switch (idx) {
|
|
95
74
|
case 0:
|
|
@@ -128,7 +107,6 @@ function removeSync(target) {
|
|
|
128
107
|
}
|
|
129
108
|
__name(removeSync, "removeSync");
|
|
130
109
|
var file_default = {
|
|
131
|
-
convertFile,
|
|
132
110
|
copySync,
|
|
133
111
|
downloadFile,
|
|
134
112
|
formatFileSize,
|
package/dist/util/file.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/file.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from 'fs';\nimport { access, mkdir } from 'fs/promises';\nimport * as
|
|
5
|
-
"mappings": ";;AAAA,YAAY,QAAQ;AACpB,SAAS,QAAQ,aAAa;AAC9B,YAAY,
|
|
4
|
+
"sourcesContent": ["import * as fs from 'node:fs';\nimport { access, mkdir } from 'node:fs/promises';\nimport * as https from 'node:https';\nimport * as path from 'node:path';\nimport { pipeline } from 'node:stream';\nimport { promisify } from 'node:util';\n\nconst pipelineAsync = promisify(pipeline);\n\n/**\n * Check if a file or directory exists asynchronously\n * @param pathToCheck - Path to check\n * @returns Promise<boolean> - true if exists, false otherwise\n */\nasync function pathExists(pathToCheck: string): Promise<boolean> {\n try {\n await access(pathToCheck);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure directory exists, create if it doesn't\n * @param dirPath - Directory path to ensure\n */\nasync function ensureDir(dirPath: string): Promise<void> {\n try {\n await access(dirPath);\n } catch {\n await mkdir(dirPath, { recursive: true });\n }\n}\n\n/**\n * Copy a file or directory synchronously.\n *\n * **Note**: This function uses synchronous file system operations which block\n * the event loop. It is intended for use during application initialization,\n * build scripts, or CLI tools where blocking is acceptable.\n * For production runtime code with high concurrency, consider using async alternatives.\n *\n * @param src The source path\n * @param dest The destination path\n */\nfunction copySync(src: string, dest: string): void {\n const stats = fs.statSync(src);\n\n if (stats.isDirectory()) {\n // Create destination directory if it doesn't exist\n if (!fs.existsSync(dest)) {\n fs.mkdirSync(dest);\n }\n\n // Read directory contents\n for (const entry of fs.readdirSync(src)) {\n const srcPath = path.join(src, entry);\n const destPath = path.join(dest, entry);\n copySync(srcPath, destPath);\n }\n } else {\n // Copy file\n fs.copyFileSync(src, dest);\n }\n}\n\n/**\n * Download file from URL\n *\n * @param url The URL to download the file from\n * @param destinationPath The path to save the downloaded file\n */\nasync function downloadFile({ url, destinationPath }: { url: string; destinationPath: string }): Promise<void> {\n return new Promise((resolve, reject) => {\n const file = fs.createWriteStream(destinationPath);\n\n https\n .get(url, response => {\n // Check if response status is OK (200\u2013299)\n if (response.statusCode && response.statusCode >= 200 && response.statusCode < 300) {\n pipelineAsync(response, file)\n .then(() => resolve())\n .catch(err => {\n fs.unlink(destinationPath, () => reject(err)); // Clean up partially written file on error\n });\n } else {\n fs.unlink(destinationPath, () => {\n reject(new Error(`Failed to download file, status code: ${response.statusCode}`));\n });\n }\n })\n .on('error', err => {\n fs.unlink(destinationPath, () => reject(err)); // Handle request errors\n });\n\n // Handle file stream errors\n file.on('error', err => {\n fs.unlink(destinationPath, () => reject(err));\n });\n });\n}\n\n/**\n * Format file size.\n *\n * @param bytes The file size in bytes\n */\nfunction formatFileSize({ bytes }: { bytes: number }): string {\n if (bytes === 0) return '0 bytes';\n const units = ['bytes', 'kB', 'MB', 'GB', 'TB'] as const;\n let idx = Math.floor(Math.log(bytes) / Math.log(1024));\n if (idx < 0) idx = 0;\n if (idx >= units.length) idx = units.length - 1;\n const fileSize = (bytes / 1024 ** idx).toFixed(1);\n let unit: string;\n switch (idx) {\n case 0:\n unit = 'bytes';\n break;\n case 1:\n unit = 'kB';\n break;\n case 2:\n unit = 'MB';\n break;\n case 3:\n unit = 'GB';\n break;\n default:\n unit = 'TB';\n }\n return `${fileSize} ${unit}`;\n}\n\n/**\n * Remove a file or directory synchronously.\n *\n * **Note**: This function uses synchronous file system operations which block\n * the event loop. It is intended for use during application cleanup, build scripts,\n * or CLI tools where blocking is acceptable.\n * For production runtime code with high concurrency, consider using async alternatives\n * like `fs.promises.rm(target, { recursive: true, force: true })`.\n *\n * @param target The path to the file or directory to remove\n */\nfunction removeSync(target: string): void {\n if (fs.existsSync(target)) {\n const stats = fs.statSync(target);\n\n if (stats.isDirectory()) {\n // Read the directory contents\n for (const entry of fs.readdirSync(target)) {\n const entryPath = path.join(target, entry);\n removeSync(entryPath);\n }\n\n // Remove the directory itself\n fs.rmdirSync(target);\n } else {\n // Remove the file\n fs.unlinkSync(target);\n }\n } else {\n console.warn(`Path ${target} does not exist.`);\n }\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AAK,KAAK,QAAQ,KAAK;AACzC,mBAAW,SAAS;AAAA,MACtB;AAGA,SAAG,UAAU,MAAM;AAAA,IACrB,OAAO;AAEL,SAAG,WAAW,MAAM;AAAA,IACtB;AAAA,EACF,OAAO;AACL,YAAQ,KAAK,QAAQ,MAAM,kBAAkB;AAAA,EAC/C;AACF;AApBS;AAsBT,IAAO,eAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/helper.js
CHANGED
|
@@ -45,7 +45,7 @@ function mergeObjects(target, source) {
|
|
|
45
45
|
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
|
-
if (!Object.
|
|
48
|
+
if (!Object.hasOwn(source, key)) {
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
51
51
|
const sourceValue = source[key];
|
|
@@ -84,7 +84,7 @@ function getValueFromObject(obj, path) {
|
|
|
84
84
|
let current = obj;
|
|
85
85
|
for (const part of parts) {
|
|
86
86
|
if (part === "__proto__" || part === "constructor" || part === "prototype") return void 0;
|
|
87
|
-
if (!current || !Object.
|
|
87
|
+
if (!current || !Object.hasOwn(current, part)) return void 0;
|
|
88
88
|
current = current[part];
|
|
89
89
|
}
|
|
90
90
|
return current;
|
package/dist/util/helper.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/helper.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Deep merge objects with defaults, preventing prototype pollution.\n *\n * This function:\n * - Recursively merges source objects into the target\n * - Preserves existing values in target (acts like defaults)\n * - Sanitizes sources to remove dangerous keys (__proto__, constructor, prototype)\n * - Prevents prototype pollution attacks\n *\n * @param target - The target object to merge into\n * @param sources - Source objects providing default values\n * @returns The merged target object (mutated)\n *\n * @example\n * const userConfig = { host: 'localhost' };\n * const defaults = { host: '0.0.0.0', port: 3001 };\n * const merged = defaultsDeep(userConfig, defaults);\n * // merged = { host: 'localhost', port: 3001 }\n */\nfunction defaultsDeep<T extends object>(target: T, ...sources: Array<Partial<T>>): T {\n // Handle null/undefined target by converting to empty object\n let result = target;\n if (target === null || target === undefined) {\n result = {} as T;\n }\n\n // Process each source\n for (const source of sources) {\n if (!isObject(source) && !Array.isArray(source)) continue;\n\n // Recursively merge source into target\n mergeObjects(result, source);\n }\n\n return result;\n}\n\n/**\n * Recursively merge source into target, preserving target values.\n * This acts like defaultsDeep - only fills in missing values from source.\n */\nfunction mergeObjects(target: any, source: any): void {\n // Handle arrays specially - merge by index\n if (Array.isArray(source)) {\n // If target is not an array but source is, treat target as object with numeric keys\n if (!Array.isArray(target)) {\n // Merge array into object-like target\n for (let i = 0; i < source.length; i++) {\n const key = String(i);\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;\n\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[key];\n\n // Check if key exists in target\n const keyExists = key in target;\n\n if (keyExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n } else if (!keyExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[key] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n }\n return;\n }\n\n // Both are arrays - merge by index\n for (let i = 0; i < source.length; i++) {\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[i];\n\n // Check if index exists in target (not just if value is undefined)\n const indexExists = i in target;\n\n // If index exists and both values are objects, merge them\n if (indexExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If index doesn't exist or value is undefined, fill from source\n else if (!indexExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[i] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n // Otherwise, keep target's existing value\n }\n return;\n }\n\n // Regular object merging\n for (const key of Object.keys(source)) {\n // Block dangerous keys to prevent prototype pollution\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only use hasOwnProperty for safer property access\n if (!Object.
|
|
5
|
-
"mappings": ";;AAmBA,SAAS,aAA+B,WAAc,SAA+B;AAEnF,MAAI,SAAS;AACb,MAAI,WAAW,QAAQ,WAAW,QAAW;AAC3C,aAAS,CAAC;AAAA,EACZ;AAGA,aAAW,UAAU,SAAS;AAC5B,QAAI,CAAC,SAAS,MAAM,KAAK,CAAC,MAAM,QAAQ,MAAM,EAAG;AAGjD,iBAAa,QAAQ,MAAM;AAAA,EAC7B;AAEA,SAAO;AACT;AAhBS;AAsBT,SAAS,aAAa,QAAa,QAAmB;AAEpD,MAAI,MAAM,QAAQ,MAAM,GAAG;AAEzB,QAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAE1B,eAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,cAAM,MAAM,OAAO,CAAC;AACpB,YAAI,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ,YAAa;AAGzE,cAAM,cAAc,OAAO,CAAC;AAE5B,cAAM,cAAc,OAAO,GAAG;AAG9B,cAAM,YAAY,OAAO;AAEzB,YAAI,aAAa,SAAS,WAAW,KAAK,SAAS,WAAW,GAAG;AAC/D,uBAAa,aAAa,WAAW;AAAA,QACvC,WAAW,CAAC,aAAa,gBAAgB,QAAW;AAElD,iBAAO,GAAG,IAAI,SAAS,WAAW,IAAI,UAAU,WAAW,IAAI;AAAA,QACjE;AAAA,MACF;AACA;AAAA,IACF;AAGA,aAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAEtC,YAAM,cAAc,OAAO,CAAC;AAE5B,YAAM,cAAc,OAAO,CAAC;AAG5B,YAAM,cAAc,KAAK;AAGzB,UAAI,eAAe,SAAS,WAAW,KAAK,SAAS,WAAW,GAAG;AACjE,qBAAa,aAAa,WAAW;AAAA,MACvC,WAES,CAAC,eAAe,gBAAgB,QAAW;AAElD,eAAO,CAAC,IAAI,SAAS,WAAW,IAAI,UAAU,WAAW,IAAI;AAAA,MAC/D;AAAA,IAEF;AACA;AAAA,EACF;AAGA,aAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AAErC,QAAI,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ,aAAa;AACvE;AAAA,IACF;AAGA,QAAI,CAAC,OAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * Deep merge objects with defaults, preventing prototype pollution.\n *\n * This function:\n * - Recursively merges source objects into the target\n * - Preserves existing values in target (acts like defaults)\n * - Sanitizes sources to remove dangerous keys (__proto__, constructor, prototype)\n * - Prevents prototype pollution attacks\n *\n * @param target - The target object to merge into\n * @param sources - Source objects providing default values\n * @returns The merged target object (mutated)\n *\n * @example\n * const userConfig = { host: 'localhost' };\n * const defaults = { host: '0.0.0.0', port: 3001 };\n * const merged = defaultsDeep(userConfig, defaults);\n * // merged = { host: 'localhost', port: 3001 }\n */\nfunction defaultsDeep<T extends object>(target: T, ...sources: Array<Partial<T>>): T {\n // Handle null/undefined target by converting to empty object\n let result = target;\n if (target === null || target === undefined) {\n result = {} as T;\n }\n\n // Process each source\n for (const source of sources) {\n if (!isObject(source) && !Array.isArray(source)) continue;\n\n // Recursively merge source into target\n mergeObjects(result, source);\n }\n\n return result;\n}\n\n/**\n * Recursively merge source into target, preserving target values.\n * This acts like defaultsDeep - only fills in missing values from source.\n */\nfunction mergeObjects(target: any, source: any): void {\n // Handle arrays specially - merge by index\n if (Array.isArray(source)) {\n // If target is not an array but source is, treat target as object with numeric keys\n if (!Array.isArray(target)) {\n // Merge array into object-like target\n for (let i = 0; i < source.length; i++) {\n const key = String(i);\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;\n\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[key];\n\n // Check if key exists in target\n const keyExists = key in target;\n\n if (keyExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n } else if (!keyExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[key] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n }\n return;\n }\n\n // Both are arrays - merge by index\n for (let i = 0; i < source.length; i++) {\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[i];\n\n // Check if index exists in target (not just if value is undefined)\n const indexExists = i in target;\n\n // If index exists and both values are objects, merge them\n if (indexExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If index doesn't exist or value is undefined, fill from source\n else if (!indexExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[i] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n // Otherwise, keep target's existing value\n }\n return;\n }\n\n // Regular object merging\n for (const key of Object.keys(source)) {\n // Block dangerous keys to prevent prototype pollution\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only use hasOwnProperty for safer property access\n if (!Object.hasOwn(source, key)) {\n continue;\n }\n\n // Access guarded by ownProperty check and blocked prototype keys\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[key];\n\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[key];\n\n // If both are arrays, merge them by index\n if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If target is object and source is array, merge array into object by numeric keys\n else if (isObject(targetValue) && Array.isArray(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If target value exists and both are objects (not arrays), recurse\n else if (targetValue !== undefined && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If target doesn't have this key, set it from source\n else if (targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[key] = isObject(sourceValue) || Array.isArray(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n // Otherwise, keep target's existing value (defaultsDeep behavior)\n }\n}\n\n/**\n * Deep clone an object to avoid reference sharing.\n */\nfunction deepClone<T>(obj: T): T {\n if (!isObject(obj)) return obj;\n\n const cloned: any = Array.isArray(obj) ? [] : {};\n\n for (const key of Object.keys(obj)) {\n // Block dangerous keys\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // eslint-disable-next-line security/detect-object-injection\n const value = (obj as any)[key];\n\n // eslint-disable-next-line security/detect-object-injection\n cloned[key] = isObject(value) ? deepClone(value) : value;\n }\n\n return cloned;\n}\n\n/**\n * Check if a value is an object.\n */\nfunction isObject(item: unknown): item is Record<string, unknown> {\n return item !== null && typeof item === 'object' && !Array.isArray(item);\n}\n\ntype AnyObject = Record<string, unknown>;\n\n/**\n * Retrieves the value from an object using a dotted key path safely.\n *\n * @param obj - The object to retrieve the value from.\n * @param path - The dotted key path (e.g., 'user.email').\n * @returns The value at the specified key path or undefined if not found.\n */\nfunction getValueFromObject(obj: AnyObject, path: string): unknown {\n const parts = path.split('.');\n let current: any = obj;\n for (const part of parts) {\n if (part === '__proto__' || part === 'constructor' || part === 'prototype') return undefined;\n if (!current || !Object.hasOwn(current, part)) return undefined;\n // Access guarded by ownProperty check and blocked prototype keys\n // eslint-disable-next-line security/detect-object-injection\n current = (current as Record<string, any>)[part];\n }\n return current;\n}\n\n/**\n * Retrieves the value from an array of objects using a dotted key path.\n *\n * @param arr - The array of objects.\n * @param path - The dotted key path (e.g., 'user.email').\n * @returns An array of values at the specified key path from each object.\n */\nfunction getValueFromArray(arr: AnyObject[], path: string): unknown[] {\n return arr.map(obj => getValueFromObject(obj, path));\n}\n\nfunction getScriptFileExtension(): string {\n return process.env.NODE_ENV === 'development' ? 'ts' : 'js';\n}\n\nexport default {\n defaultsDeep,\n isObject,\n getVal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AQ,KAAK,MAAM,GAAG;AAC5B,MAAI,UAAe;AACnB,aAAW,QAAQ,OAAO;AACxB,QAAI,SAAS,eAAe,SAAS,iBAAiB,SAAS,YAAa,QAAO;AACnF,QAAI,CAAC,WAAW,CAAC,OAAO,OAAO,SAAS,IAAI,EAAG,QAAO;AAGtD,cAAW,QAAgC,IAAI;AAAA,EACjD;AACA,SAAO;AACT;AAXS;AAoBT,SAAS,kBAAkB,KAAkB,MAAyB;AACpE,SAAO,IAAI,IAAI,SAAO,mBAAmB,KAAK,IAAI,CAAC;AACrD;AAFS;AAIT,SAAS,yBAAiC;AACxC,SAAO,QAAQ,IAAI,aAAa,gBAAgB,OAAO;AACzD;AAFS;AAIT,IAAO,iBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { default as Time } from './time.js';
|
|
2
|
-
export { default as Timing } from './timing.js';
|
|
3
1
|
export { default as File } from './file.js';
|
|
4
2
|
export { default as Helper } from './helper.js';
|
|
5
3
|
export { default as Image } from './image.js';
|
|
@@ -7,5 +5,7 @@ export { default as Loader } from './loader.js';
|
|
|
7
5
|
export { default as Num } from './num.js';
|
|
8
6
|
export { default as OS } from './os.js';
|
|
9
7
|
export { default as Str } from './str.js';
|
|
8
|
+
export { default as Time } from './time.js';
|
|
9
|
+
export { default as Timing } from './timing.js';
|
|
10
10
|
export { default as URL } from './url.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/util/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { default as default2 } from "./
|
|
2
|
-
import { default as default3 } from "./
|
|
3
|
-
import { default as default4 } from "./
|
|
4
|
-
import { default as default5 } from "./
|
|
5
|
-
import { default as default6 } from "./
|
|
6
|
-
import { default as default7 } from "./
|
|
7
|
-
import { default as default8 } from "./
|
|
8
|
-
import { default as default9 } from "./
|
|
9
|
-
import { default as default10 } from "./
|
|
1
|
+
import { default as default2 } from "./file.js";
|
|
2
|
+
import { default as default3 } from "./helper.js";
|
|
3
|
+
import { default as default4 } from "./image.js";
|
|
4
|
+
import { default as default5 } from "./loader.js";
|
|
5
|
+
import { default as default6 } from "./num.js";
|
|
6
|
+
import { default as default7 } from "./os.js";
|
|
7
|
+
import { default as default8 } from "./str.js";
|
|
8
|
+
import { default as default9 } from "./time.js";
|
|
9
|
+
import { default as default10 } from "./timing.js";
|
|
10
10
|
import { default as default11 } from "./url.js";
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
default2 as File,
|
|
13
|
+
default3 as Helper,
|
|
14
|
+
default4 as Image,
|
|
15
|
+
default5 as Loader,
|
|
16
|
+
default6 as Num,
|
|
17
|
+
default7 as OS,
|
|
18
|
+
default8 as Str,
|
|
19
|
+
default9 as Time,
|
|
20
|
+
default10 as Timing,
|
|
21
21
|
default11 as URL
|
|
22
22
|
};
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
package/dist/util/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,
|
|
4
|
+
"sourcesContent": ["export { default as File } from './file.js';\nexport { default as Helper } from './helper.js';\nexport { default as Image } from './image.js';\nexport { default as Loader } from './loader.js';\nexport { default as Num } from './num.js';\nexport { default as OS } from './os.js';\nexport { default as Str } from './str.js';\nexport { default as Time } from './time.js';\nexport { default as Timing } from './timing.js';\nexport { default as URL } from './url.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAAwB;AACjC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAAsB;AAC/B,SAAoB,WAAXA,gBAAqB;AAC9B,SAAoB,WAAXA,gBAAsB;AAC/B,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,iBAAyB;AAClC,SAAoB,WAAXA,iBAAsB;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/dist/util/loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
import { LRUCache } from "lru-cache";
|
|
6
6
|
import { Helper } from "./index.js";
|
|
7
7
|
const moduleCache = new LRUCache({
|
|
@@ -69,7 +69,7 @@ const loadEntityModule = /* @__PURE__ */ __name(async ({
|
|
|
69
69
|
if (entityName === "__proto__" || entityName === "constructor" || entityName === "prototype") {
|
|
70
70
|
throw new Error(`Invalid entity name (Entity: ${entityName})`);
|
|
71
71
|
}
|
|
72
|
-
if (!entityModule || !Object.
|
|
72
|
+
if (!entityModule || !Object.hasOwn(entityModule, entityName)) {
|
|
73
73
|
throw new Error(`Entity not found (Entity: ${entityName})`);
|
|
74
74
|
}
|
|
75
75
|
const EntityClass = Reflect.get(entityModule, entityName);
|
package/dist/util/loader.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/loader.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'fs';\nimport path from 'path';\nimport { LRUCache } from 'lru-cache';\nimport { Helper } from './index.js';\n\n// Type for a map of loaded modules\nexport interface ModuleMap<T = unknown> {\n [key: string]: T;\n}\n\n// Cache for loaded modules to avoid repeated imports\n// Using LRU cache to prevent unbounded memory growth in long-running processes\nconst moduleCache = new LRUCache<string, ModuleMap>({\n max: 100, // Max 100 directories cached\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst entityCache = new LRUCache<string, EntityClass>({\n max: 500, // Max 500 entities cached (accessed more frequently than modules)\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst loadModulesInDirectory = async <T = unknown>({\n directory,\n extensions,\n}: {\n directory: string;\n extensions?: string[];\n}): Promise<ModuleMap<T>> => {\n // Create cache key based on directory and extensions\n const cacheKey = `${directory}:${extensions?.join(',') ?? 'all'}`;\n\n // Check cache first\n if (moduleCache.has(cacheKey)) {\n const cachedModule = moduleCache.get(cacheKey);\n if (cachedModule) {\n return cachedModule as ModuleMap<T>;\n }\n }\n\n const loadedModules: ModuleMap<T> = {};\n\n // Use readdir with withFileTypes option to avoid separate stat calls\n const dirents = await fs.promises.readdir(directory, { withFileTypes: true });\n\n for (const dirent of dirents) {\n // Skip directories without needing stat call\n if (dirent.isDirectory()) {\n continue;\n }\n\n const file = dirent.name;\n const ext = path.extname(file);\n const isDeclarationFile = file.endsWith('.d.ts');\n\n // Skip files that are not in the specified extensions or are .d.ts files\n if ((extensions && extensions.length > 0 && !extensions.includes(ext)) || isDeclarationFile) {\n continue;\n }\n\n const moduleName = path.basename(file, ext);\n const filePath = path.join(directory, file);\n // Convert to absolute path for ESM import\n const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);\n // Use file:// URL for Windows compatibility\n const fileUrl = `file://${absolutePath.replace(/\\\\/g, '/')}`;\n\n try {\n const importedModule = await import(fileUrl);\n\n // Use safe property assignment to prevent prototype pollution\n if (moduleName !== '__proto__' && moduleName !== 'constructor' && moduleName !== 'prototype') {\n // Prefer default export, but fall back to the entire module if no default\n const moduleExport = importedModule.default ?? importedModule;\n Reflect.set(loadedModules, moduleName, moduleExport);\n }\n } catch (error) {\n // Note: console.error used here as Logger may not be initialized during early bootstrap\n console.error(`Failed to import module ${filePath}:`, error);\n }\n }\n\n // Cache the results for future use\n moduleCache.set(cacheKey, loadedModules);\n\n return loadedModules;\n};\n\n// Type constraint for entity classes (must be constructable)\nexport type EntityClass<T = unknown> = new (...args: unknown[]) => T;\n\nconst loadEntityModule = async <T = unknown>({\n entitiesDirectory,\n entityName,\n}: {\n entitiesDirectory: string;\n entityName: string;\n}): Promise<EntityClass<T>> => {\n // Create cache key based on directory and entity name\n const cacheKey = `${entitiesDirectory}:${entityName}`;\n\n // Check cache first\n if (entityCache.has(cacheKey)) {\n return entityCache.get(cacheKey) as EntityClass<T>;\n }\n\n // Define entity module path\n const entityModulePath = path.join(entitiesDirectory, `${entityName}.${Helper.getScriptFileExtension()}`);\n\n // Import entity module\n const entityModule = await import(entityModulePath);\n\n // Safe property access to prevent prototype pollution\n if (entityName === '__proto__' || entityName === 'constructor' || entityName === 'prototype') {\n throw new Error(`Invalid entity name (Entity: ${entityName})`);\n }\n\n if (!entityModule || !Object.
|
|
5
|
-
"mappings": ";;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AASvB,MAAM,cAAc,IAAI,SAA4B;AAAA,EAClD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAAA;AACnB,CAAC;AAED,MAAM,cAAc,IAAI,SAA8B;AAAA,EACpD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAAA;AACnB,CAAC;AAED,MAAM,yBAAyB,8BAAoB;AAAA,EACjD;AAAA,EACA;AACF,MAG6B;AAE3B,QAAM,WAAW,GAAG,SAAS,IAAI,YAAY,KAAK,GAAG,KAAK,KAAK;AAG/D,MAAI,YAAY,IAAI,QAAQ,GAAG;AAC7B,UAAM,eAAe,YAAY,IAAI,QAAQ;AAC7C,QAAI,cAAc;AAChB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,gBAA8B,CAAC;AAGrC,QAAM,UAAU,MAAM,GAAG,SAAS,QAAQ,WAAW,EAAE,eAAe,KAAK,CAAC;AAE5E,aAAW,UAAU,SAAS;AAE5B,QAAI,OAAO,YAAY,GAAG;AACxB;AAAA,IACF;AAEA,UAAM,OAAO,OAAO;AACpB,UAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,UAAM,oBAAoB,KAAK,SAAS,OAAO;AAG/C,QAAK,cAAc,WAAW,SAAS,KAAK,CAAC,WAAW,SAAS,GAAG,KAAM,mBAAmB;AAC3F;AAAA,IACF;AAEA,UAAM,aAAa,KAAK,SAAS,MAAM,GAAG;AAC1C,UAAM,WAAW,KAAK,KAAK,WAAW,IAAI;AAE1C,UAAM,eAAe,KAAK,WAAW,QAAQ,IAAI,WAAW,KAAK,QAAQ,QAAQ;AAEjF,UAAM,UAAU,UAAU,aAAa,QAAQ,OAAO,GAAG,CAAC;AAE1D,QAAI;AACF,YAAM,iBAAiB,MAAM,OAAO;AAGpC,UAAI,eAAe,eAAe,eAAe,iBAAiB,eAAe,aAAa;AAE5F,cAAM,eAAe,eAAe,WAAW;AAC/C,gBAAQ,IAAI,eAAe,YAAY,YAAY;AAAA,MACrD;AAAA,IACF,SAAS,OAAO;AAEd,cAAQ,MAAM,2BAA2B,QAAQ,KAAK,KAAK;AAAA,IAC7D;AAAA,EACF;AAGA,cAAY,IAAI,UAAU,aAAa;AAEvC,SAAO;AACT,GAhE+B;AAqE/B,MAAM,mBAAmB,8BAAoB;AAAA,EAC3C;AAAA,EACA;AACF,MAG+B;AAE7B,QAAM,WAAW,GAAG,iBAAiB,IAAI,UAAU;AAGnD,MAAI,YAAY,IAAI,QAAQ,GAAG;AAC7B,WAAO,YAAY,IAAI,QAAQ;AAAA,EACjC;AAGA,QAAM,mBAAmB,KAAK,KAAK,mBAAmB,GAAG,UAAU,IAAI,OAAO,uBAAuB,CAAC,EAAE;AAGxG,QAAM,eAAe,MAAM,OAAO;AAGlC,MAAI,eAAe,eAAe,eAAe,iBAAiB,eAAe,aAAa;AAC5F,UAAM,IAAI,MAAM,gCAAgC,UAAU,GAAG;AAAA,EAC/D;AAEA,MAAI,CAAC,gBAAgB,CAAC,OAAO,
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs';\nimport path from 'node:path';\nimport { LRUCache } from 'lru-cache';\nimport { Helper } from './index.js';\n\n// Type for a map of loaded modules\nexport interface ModuleMap<T = unknown> {\n [key: string]: T;\n}\n\n// Cache for loaded modules to avoid repeated imports\n// Using LRU cache to prevent unbounded memory growth in long-running processes\nconst moduleCache = new LRUCache<string, ModuleMap>({\n max: 100, // Max 100 directories cached\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst entityCache = new LRUCache<string, EntityClass>({\n max: 500, // Max 500 entities cached (accessed more frequently than modules)\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst loadModulesInDirectory = async <T = unknown>({\n directory,\n extensions,\n}: {\n directory: string;\n extensions?: string[];\n}): Promise<ModuleMap<T>> => {\n // Create cache key based on directory and extensions\n const cacheKey = `${directory}:${extensions?.join(',') ?? 'all'}`;\n\n // Check cache first\n if (moduleCache.has(cacheKey)) {\n const cachedModule = moduleCache.get(cacheKey);\n if (cachedModule) {\n return cachedModule as ModuleMap<T>;\n }\n }\n\n const loadedModules: ModuleMap<T> = {};\n\n // Use readdir with withFileTypes option to avoid separate stat calls\n const dirents = await fs.promises.readdir(directory, { withFileTypes: true });\n\n for (const dirent of dirents) {\n // Skip directories without needing stat call\n if (dirent.isDirectory()) {\n continue;\n }\n\n const file = dirent.name;\n const ext = path.extname(file);\n const isDeclarationFile = file.endsWith('.d.ts');\n\n // Skip files that are not in the specified extensions or are .d.ts files\n if ((extensions && extensions.length > 0 && !extensions.includes(ext)) || isDeclarationFile) {\n continue;\n }\n\n const moduleName = path.basename(file, ext);\n const filePath = path.join(directory, file);\n // Convert to absolute path for ESM import\n const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);\n // Use file:// URL for Windows compatibility\n const fileUrl = `file://${absolutePath.replace(/\\\\/g, '/')}`;\n\n try {\n const importedModule = await import(fileUrl);\n\n // Use safe property assignment to prevent prototype pollution\n if (moduleName !== '__proto__' && moduleName !== 'constructor' && moduleName !== 'prototype') {\n // Prefer default export, but fall back to the entire module if no default\n const moduleExport = importedModule.default ?? importedModule;\n Reflect.set(loadedModules, moduleName, moduleExport);\n }\n } catch (error) {\n // Note: console.error used here as Logger may not be initialized during early bootstrap\n console.error(`Failed to import module ${filePath}:`, error);\n }\n }\n\n // Cache the results for future use\n moduleCache.set(cacheKey, loadedModules);\n\n return loadedModules;\n};\n\n// Type constraint for entity classes (must be constructable)\nexport type EntityClass<T = unknown> = new (...args: unknown[]) => T;\n\nconst loadEntityModule = async <T = unknown>({\n entitiesDirectory,\n entityName,\n}: {\n entitiesDirectory: string;\n entityName: string;\n}): Promise<EntityClass<T>> => {\n // Create cache key based on directory and entity name\n const cacheKey = `${entitiesDirectory}:${entityName}`;\n\n // Check cache first\n if (entityCache.has(cacheKey)) {\n return entityCache.get(cacheKey) as EntityClass<T>;\n }\n\n // Define entity module path\n const entityModulePath = path.join(entitiesDirectory, `${entityName}.${Helper.getScriptFileExtension()}`);\n\n // Import entity module\n const entityModule = await import(entityModulePath);\n\n // Safe property access to prevent prototype pollution\n if (entityName === '__proto__' || entityName === 'constructor' || entityName === 'prototype') {\n throw new Error(`Invalid entity name (Entity: ${entityName})`);\n }\n\n if (!entityModule || !Object.hasOwn(entityModule, entityName)) {\n throw new Error(`Entity not found (Entity: ${entityName})`);\n }\n\n // Get entity class\n const EntityClass = Reflect.get(entityModule, entityName);\n\n // Cache the entity for future use\n entityCache.set(cacheKey, EntityClass);\n\n return EntityClass;\n};\n\n// Cache management functions for development/testing\nconst clearModuleCache = (): void => {\n moduleCache.clear();\n entityCache.clear();\n};\n\nconst getCacheStats = (): { modulesCached: number; entitiesCached: number } => {\n return {\n modulesCached: moduleCache.size,\n entitiesCached: entityCache.size,\n };\n};\n\nexport default {\n loadModulesInDirectory,\n loadEntityModule,\n clearModuleCache,\n getCacheStats,\n};\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AASvB,MAAM,cAAc,IAAI,SAA4B;AAAA,EAClD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAA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AGA,cAAY,IAAI,UAAU,aAAa;AAEvC,SAAO;AACT,GAhE+B;AAqE/B,MAAM,mBAAmB,8BAAoB;AAAA,EAC3C;AAAA,EACA;AACF,MAG+B;AAE7B,QAAM,WAAW,GAAG,iBAAiB,IAAI,UAAU;AAGnD,MAAI,YAAY,IAAI,QAAQ,GAAG;AAC7B,WAAO,YAAY,IAAI,QAAQ;AAAA,EACjC;AAGA,QAAM,mBAAmB,KAAK,KAAK,mBAAmB,GAAG,UAAU,IAAI,OAAO,uBAAuB,CAAC,EAAE;AAGxG,QAAM,eAAe,MAAM,OAAO;AAGlC,MAAI,eAAe,eAAe,eAAe,iBAAiB,eAAe,aAAa;AAC5F,UAAM,IAAI,MAAM,gCAAgC,UAAU,GAAG;AAAA,EAC/D;AAEA,MAAI,CAAC,gBAAgB,CAAC,OAAO,OAAO,cAAc,UAAU,GAAG;AAC7D,UAAM,IAAI,MAAM,6BAA6B,UAAU,GAAG;AAAA,EAC5D;AAGA,QAAM,cAAc,QAAQ,IAAI,cAAc,UAAU;AAGxD,cAAY,IAAI,UAAU,WAAW;AAErC,SAAO;AACT,GArCyB;AAwCzB,MAAM,mBAAmB,6BAAY;AACnC,cAAY,MAAM;AAClB,cAAY,MAAM;AACpB,GAHyB;AAKzB,MAAM,gBAAgB,6BAAyD;AAC7E,SAAO;AAAA,IACL,eAAe,YAAY;AAAA,IAC3B,gBAAgB,YAAY;AAAA,EAC9B;AACF,GALsB;AAOtB,IAAO,iBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/os.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
import os from "node:os";
|
|
5
5
|
function getUniqueComputerId() {
|
|
6
6
|
const interfaces = Object.values(os.networkInterfaces()).filter(Boolean);
|
|
7
7
|
let macAddress = "";
|
package/dist/util/os.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/os.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;AAAA,OAAO,
|
|
4
|
+
"sourcesContent": ["import crypto from 'node:crypto';\nimport os from 'node:os';\n\nfunction getUniqueComputerId(): string {\n const interfaces = Object.values(os.networkInterfaces()).filter(Boolean) as os.NetworkInterfaceInfo[][];\n let macAddress = '';\n for (const ifaceList of interfaces) {\n for (const details of ifaceList) {\n if (details.mac) {\n macAddress = details.mac;\n break;\n }\n }\n if (macAddress) break;\n }\n return crypto.createHash('sha256').update(macAddress).digest('hex');\n}\n\nexport default {\n getUniqueComputerId,\n};\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO,YAAY;AACnB,OAAO,QAAQ;AAEf,SAAS,sBAA8B;AACrC,QAAM,aAAa,OAAO,OAAO,GAAG,kBAAkB,CAAC,EAAE,OAAO,OAAO;AACvE,MAAI,aAAa;AACjB,aAAW,aAAa,YAAY;AAClC,eAAW,WAAW,WAAW;AAC/B,UAAI,QAAQ,KAAK;AACf,qBAAa,QAAQ;AACrB;AAAA,MACF;AAAA,IACF;AACA,QAAI,WAAY;AAAA,EAClB;AACA,SAAO,OAAO,WAAW,QAAQ,EAAE,OAAO,UAAU,EAAE,OAAO,KAAK;AACpE;AAbS;AAeT,IAAO,aAAQ;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,5 +17,5 @@ export declare function withAuth(handler: AuthenticatedRouteHandler, authenticat
|
|
|
17
17
|
* Method decorator for class-based controllers
|
|
18
18
|
* Usage: @requiresAuth()
|
|
19
19
|
*/
|
|
20
|
-
export declare function requiresAuth(): (
|
|
20
|
+
export declare function requiresAuth(): (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
21
21
|
//# sourceMappingURL=auth-middleware.d.ts.map
|