alepha 0.14.3 → 0.15.0
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 +2 -5
- package/dist/api/audits/index.d.ts +620 -811
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/files/index.d.ts +185 -377
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +0 -1
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.d.ts +245 -435
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/notifications/index.d.ts +238 -429
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/parameters/index.d.ts +236 -427
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/users/index.browser.js +1 -2
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +1010 -1196
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +178 -151
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.d.ts +17 -17
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/batch/index.d.ts +122 -122
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +1 -2
- package/dist/batch/index.js.map +1 -1
- package/dist/bucket/index.d.ts +163 -163
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/cache/core/index.d.ts +46 -46
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cli/index.d.ts +384 -285
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1113 -623
- package/dist/cli/index.js.map +1 -1
- package/dist/command/index.d.ts +299 -300
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +13 -9
- package/dist/command/index.js.map +1 -1
- package/dist/core/index.browser.js +445 -103
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +733 -625
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +446 -103
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +445 -103
- package/dist/core/index.native.js.map +1 -1
- package/dist/datetime/index.d.ts +44 -44
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js +4 -4
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/index.d.ts +97 -50
- package/dist/email/index.d.ts.map +1 -1
- package/dist/email/index.js +129 -33
- package/dist/email/index.js.map +1 -1
- package/dist/fake/index.d.ts +7981 -14
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/file/index.d.ts +523 -390
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +253 -1
- package/dist/file/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +208 -208
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/logger/index.d.ts +25 -26
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +12 -2
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +197 -197
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/chunk-DtkW-qnP.js +38 -0
- package/dist/orm/index.browser.js.map +1 -1
- package/dist/orm/index.bun.js +2814 -0
- package/dist/orm/index.bun.js.map +1 -0
- package/dist/orm/index.d.ts +1228 -1216
- package/dist/orm/index.d.ts.map +1 -1
- package/dist/orm/index.js +2041 -1967
- package/dist/orm/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +248 -248
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/redis/index.bun.js +285 -0
- package/dist/redis/index.bun.js.map +1 -0
- package/dist/redis/index.d.ts +118 -136
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +18 -38
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +69 -69
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/router/index.d.ts +6 -6
- package/dist/router/index.d.ts.map +1 -1
- package/dist/scheduler/index.d.ts +25 -25
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/security/index.browser.js +5 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +417 -254
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +386 -86
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +110 -110
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +20 -20
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cache/index.d.ts +62 -47
- package/dist/server/cache/index.d.ts.map +1 -1
- package/dist/server/cache/index.js +56 -3
- package/dist/server/cache/index.js.map +1 -1
- package/dist/server/compress/index.d.ts +6 -0
- package/dist/server/compress/index.d.ts.map +1 -1
- package/dist/server/compress/index.js +36 -1
- package/dist/server/compress/index.js.map +1 -1
- package/dist/server/cookies/index.d.ts +6 -6
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +3 -3
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.browser.js +2 -2
- package/dist/server/core/index.browser.js.map +1 -1
- package/dist/server/core/index.d.ts +242 -150
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +294 -125
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +11 -12
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/health/index.d.ts +0 -1
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/helmet/index.d.ts +2 -2
- package/dist/server/helmet/index.d.ts.map +1 -1
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +123 -124
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +1 -2
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/multipart/index.d.ts +6 -6
- package/dist/server/multipart/index.d.ts.map +1 -1
- package/dist/server/proxy/index.d.ts +102 -103
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.d.ts +16 -16
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/static/index.d.ts +44 -44
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/static/index.js +4 -0
- package/dist/server/static/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +48 -49
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js +3 -5
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +13 -11
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js +7 -7
- package/dist/sms/index.js.map +1 -1
- package/dist/thread/index.d.ts +71 -72
- package/dist/thread/index.d.ts.map +1 -1
- package/dist/topic/core/index.d.ts +318 -318
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/redis/index.d.ts +6 -6
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/vite/index.d.ts +5805 -249
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +599 -513
- package/dist/vite/index.js.map +1 -1
- package/dist/websocket/index.browser.js +6 -6
- package/dist/websocket/index.browser.js.map +1 -1
- package/dist/websocket/index.d.ts +247 -247
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +6 -6
- package/dist/websocket/index.js.map +1 -1
- package/package.json +9 -14
- package/src/api/files/controllers/AdminFileStatsController.ts +0 -1
- package/src/api/users/atoms/realmAuthSettingsAtom.ts +5 -0
- package/src/api/users/controllers/{UserRealmController.ts → RealmController.ts} +11 -11
- package/src/api/users/entities/users.ts +1 -1
- package/src/api/users/index.ts +8 -8
- package/src/api/users/primitives/{$userRealm.ts → $realm.ts} +17 -19
- package/src/api/users/providers/{UserRealmProvider.ts → RealmProvider.ts} +26 -30
- package/src/api/users/schemas/{userRealmConfigSchema.ts → realmConfigSchema.ts} +2 -2
- package/src/api/users/services/CredentialService.ts +7 -7
- package/src/api/users/services/IdentityService.ts +4 -4
- package/src/api/users/services/RegistrationService.spec.ts +25 -27
- package/src/api/users/services/RegistrationService.ts +38 -27
- package/src/api/users/services/SessionCrudService.ts +3 -3
- package/src/api/users/services/SessionService.spec.ts +3 -3
- package/src/api/users/services/SessionService.ts +28 -9
- package/src/api/users/services/UserService.ts +7 -7
- package/src/batch/providers/BatchProvider.ts +1 -2
- package/src/cli/apps/AlephaCli.ts +0 -2
- package/src/cli/apps/AlephaPackageBuilderCli.ts +38 -19
- package/src/cli/assets/apiHelloControllerTs.ts +18 -0
- package/src/cli/assets/apiIndexTs.ts +16 -0
- package/src/cli/assets/claudeMd.ts +303 -0
- package/src/cli/assets/mainBrowserTs.ts +2 -2
- package/src/cli/assets/mainServerTs.ts +24 -0
- package/src/cli/assets/webAppRouterTs.ts +15 -0
- package/src/cli/assets/webHelloComponentTsx.ts +16 -0
- package/src/cli/assets/webIndexTs.ts +16 -0
- package/src/cli/atoms/buildOptions.ts +88 -0
- package/src/cli/commands/build.ts +70 -87
- package/src/cli/commands/db.ts +21 -22
- package/src/cli/commands/deploy.ts +17 -5
- package/src/cli/commands/dev.ts +22 -14
- package/src/cli/commands/format.ts +8 -2
- package/src/cli/commands/gen/env.ts +53 -0
- package/src/cli/commands/gen/openapi.ts +1 -1
- package/src/cli/commands/gen/resource.ts +15 -0
- package/src/cli/commands/gen.ts +7 -1
- package/src/cli/commands/init.ts +74 -30
- package/src/cli/commands/lint.ts +8 -2
- package/src/cli/commands/test.ts +8 -3
- package/src/cli/commands/typecheck.ts +5 -1
- package/src/cli/commands/verify.ts +5 -3
- package/src/cli/defineConfig.ts +49 -7
- package/src/cli/index.ts +0 -1
- package/src/cli/services/AlephaCliUtils.ts +39 -589
- package/src/cli/services/PackageManagerUtils.ts +301 -0
- package/src/cli/services/ProjectScaffolder.ts +306 -0
- package/src/command/helpers/Runner.spec.ts +2 -2
- package/src/command/helpers/Runner.ts +16 -4
- package/src/command/primitives/$command.ts +0 -6
- package/src/command/providers/CliProvider.ts +1 -3
- package/src/core/Alepha.ts +42 -0
- package/src/core/__tests__/Alepha-graph.spec.ts +4 -0
- package/src/core/index.shared.ts +1 -0
- package/src/core/index.ts +2 -0
- package/src/core/primitives/$hook.ts +6 -2
- package/src/core/primitives/$module.spec.ts +4 -0
- package/src/core/providers/AlsProvider.ts +1 -1
- package/src/core/providers/CodecManager.spec.ts +12 -6
- package/src/core/providers/CodecManager.ts +26 -6
- package/src/core/providers/EventManager.ts +169 -13
- package/src/core/providers/KeylessJsonSchemaCodec.spec.ts +621 -0
- package/src/core/providers/KeylessJsonSchemaCodec.ts +407 -0
- package/src/core/providers/StateManager.spec.ts +27 -16
- package/src/email/providers/LocalEmailProvider.spec.ts +111 -87
- package/src/email/providers/LocalEmailProvider.ts +52 -15
- package/src/email/providers/NodemailerEmailProvider.ts +167 -56
- package/src/file/errors/FileError.ts +7 -0
- package/src/file/index.ts +9 -1
- package/src/file/providers/MemoryFileSystemProvider.ts +393 -0
- package/src/logger/index.ts +15 -3
- package/src/mcp/transports/StdioMcpTransport.ts +1 -1
- package/src/orm/index.browser.ts +1 -19
- package/src/orm/index.bun.ts +77 -0
- package/src/orm/index.shared-server.ts +22 -0
- package/src/orm/index.shared.ts +15 -0
- package/src/orm/index.ts +13 -39
- package/src/orm/providers/drivers/BunPostgresProvider.ts +3 -5
- package/src/orm/providers/drivers/BunSqliteProvider.ts +1 -1
- package/src/orm/providers/drivers/CloudflareD1Provider.ts +4 -0
- package/src/orm/providers/drivers/DatabaseProvider.ts +4 -0
- package/src/orm/providers/drivers/PglitePostgresProvider.ts +4 -0
- package/src/orm/services/Repository.ts +8 -0
- package/src/queue/core/providers/WorkerProvider.spec.ts +48 -32
- package/src/redis/index.bun.ts +35 -0
- package/src/redis/providers/BunRedisProvider.ts +12 -43
- package/src/redis/providers/BunRedisSubscriberProvider.ts +2 -3
- package/src/redis/providers/NodeRedisProvider.ts +16 -34
- package/src/{server/security → security}/__tests__/BasicAuth.spec.ts +11 -11
- package/src/{server/security → security}/__tests__/ServerSecurityProvider-realm.spec.ts +21 -16
- package/src/{server/security/providers → security/__tests__}/ServerSecurityProvider.spec.ts +5 -5
- package/src/security/index.browser.ts +5 -0
- package/src/security/index.ts +90 -7
- package/src/security/primitives/{$realm.spec.ts → $issuer.spec.ts} +11 -11
- package/src/security/primitives/{$realm.ts → $issuer.ts} +20 -17
- package/src/security/primitives/$role.ts +5 -5
- package/src/security/primitives/$serviceAccount.spec.ts +5 -5
- package/src/security/primitives/$serviceAccount.ts +3 -3
- package/src/{server/security → security}/providers/ServerSecurityProvider.ts +5 -7
- package/src/server/auth/primitives/$auth.ts +10 -10
- package/src/server/auth/primitives/$authCredentials.ts +3 -3
- package/src/server/auth/primitives/$authGithub.ts +3 -3
- package/src/server/auth/primitives/$authGoogle.ts +3 -3
- package/src/server/auth/providers/ServerAuthProvider.ts +13 -13
- package/src/server/cache/providers/ServerCacheProvider.spec.ts +183 -0
- package/src/server/cache/providers/ServerCacheProvider.ts +95 -10
- package/src/server/compress/providers/ServerCompressProvider.ts +61 -2
- package/src/server/cookies/providers/ServerCookiesProvider.ts +3 -3
- package/src/server/core/helpers/ServerReply.ts +2 -2
- package/src/server/core/providers/NodeHttpServerProvider.ts +25 -6
- package/src/server/core/providers/ServerBodyParserProvider.ts +19 -23
- package/src/server/core/providers/ServerLoggerProvider.ts +23 -19
- package/src/server/core/providers/ServerProvider.ts +155 -22
- package/src/server/core/providers/ServerRouterProvider.ts +259 -115
- package/src/server/core/providers/ServerTimingProvider.ts +2 -2
- package/src/server/links/index.ts +1 -1
- package/src/server/links/providers/LinkProvider.ts +1 -1
- package/src/server/static/providers/ServerStaticProvider.ts +10 -0
- package/src/server/swagger/index.ts +1 -1
- package/src/server/swagger/providers/ServerSwaggerProvider.ts +5 -8
- package/src/sms/providers/LocalSmsProvider.spec.ts +153 -111
- package/src/sms/providers/LocalSmsProvider.ts +8 -7
- package/src/vite/helpers/boot.ts +28 -17
- package/src/vite/helpers/importViteReact.ts +13 -0
- package/src/vite/index.ts +1 -21
- package/src/vite/plugins/viteAlephaDev.ts +16 -1
- package/src/vite/plugins/viteAlephaSsrPreload.ts +222 -0
- package/src/vite/tasks/buildClient.ts +11 -0
- package/src/vite/tasks/buildServer.ts +59 -4
- package/src/vite/tasks/devServer.ts +71 -0
- package/src/vite/tasks/generateCloudflare.ts +7 -0
- package/src/vite/tasks/index.ts +2 -1
- package/dist/server/security/index.browser.js +0 -13
- package/dist/server/security/index.browser.js.map +0 -1
- package/dist/server/security/index.d.ts +0 -173
- package/dist/server/security/index.d.ts.map +0 -1
- package/dist/server/security/index.js +0 -311
- package/dist/server/security/index.js.map +0 -1
- package/src/cli/assets/appRouterTs.ts +0 -9
- package/src/cli/assets/mainTs.ts +0 -13
- package/src/cli/assets/viteConfigTs.ts +0 -14
- package/src/cli/commands/run.ts +0 -24
- package/src/server/security/index.browser.ts +0 -10
- package/src/server/security/index.ts +0 -94
- package/src/vite/plugins/viteAlepha.ts +0 -37
- package/src/vite/plugins/viteAlephaBuild.ts +0 -281
- /package/src/{server/security → security}/primitives/$basicAuth.ts +0 -0
- /package/src/{server/security → security}/providers/ServerBasicAuthProvider.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Compile } from "typebox/compile";
|
|
2
1
|
import { Type } from "typebox";
|
|
3
2
|
import Format from "typebox/format";
|
|
4
3
|
import * as Value from "typebox/value";
|
|
4
|
+
import { Compile } from "typebox/compile";
|
|
5
5
|
|
|
6
6
|
//#region ../../src/core/constants/KIND.ts
|
|
7
7
|
/**
|
|
@@ -310,7 +310,7 @@ var AlsProvider = class AlsProvider {
|
|
|
310
310
|
if (!this.als) return callback();
|
|
311
311
|
data.registry ??= /* @__PURE__ */ new Map();
|
|
312
312
|
data.context ??= this.createContextId();
|
|
313
|
-
return this.als.run(data, callback);
|
|
313
|
+
return this.als.run({ ...data }, callback);
|
|
314
314
|
}
|
|
315
315
|
exists() {
|
|
316
316
|
return !!this.get("context");
|
|
@@ -395,84 +395,6 @@ var JsonSchemaCodec = class extends SchemaCodec {
|
|
|
395
395
|
}
|
|
396
396
|
};
|
|
397
397
|
|
|
398
|
-
//#endregion
|
|
399
|
-
//#region ../../src/core/errors/TypeBoxError.ts
|
|
400
|
-
var TypeBoxError = class extends AlephaError {
|
|
401
|
-
name = "TypeBoxError";
|
|
402
|
-
cause;
|
|
403
|
-
value;
|
|
404
|
-
constructor(error) {
|
|
405
|
-
super(`Invalid input: ${error.message}${error.instancePath ? ` at ${error.instancePath}` : ""}`, { cause: error });
|
|
406
|
-
const params = error.params;
|
|
407
|
-
if (params?.requiredProperties) this.value = {
|
|
408
|
-
path: `/${params.requiredProperties[0]}`,
|
|
409
|
-
message: "must be defined"
|
|
410
|
-
};
|
|
411
|
-
else this.value = {
|
|
412
|
-
path: error.instancePath,
|
|
413
|
-
message: error.message
|
|
414
|
-
};
|
|
415
|
-
this.cause = error;
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
//#endregion
|
|
420
|
-
//#region ../../src/core/primitives/$hook.ts
|
|
421
|
-
/**
|
|
422
|
-
* Registers a new hook.
|
|
423
|
-
*
|
|
424
|
-
* ```ts
|
|
425
|
-
* import { $hook } from "alepha";
|
|
426
|
-
*
|
|
427
|
-
* class MyProvider {
|
|
428
|
-
* onStart = $hook({
|
|
429
|
-
* name: "start", // or "configure", "ready", "stop", ...
|
|
430
|
-
* handler: async (app) => {
|
|
431
|
-
* // await db.connect(); ...
|
|
432
|
-
* }
|
|
433
|
-
* });
|
|
434
|
-
* }
|
|
435
|
-
* ```
|
|
436
|
-
*
|
|
437
|
-
* Hooks are used to run async functions from all registered providers/services.
|
|
438
|
-
*
|
|
439
|
-
* You can't register a hook after the App has started.
|
|
440
|
-
*
|
|
441
|
-
* It's used under the hood by the `configure`, `start`, and `stop` methods.
|
|
442
|
-
* Some modules also use hooks to run their own logic. (e.g. `alepha/server`).
|
|
443
|
-
*
|
|
444
|
-
* You can create your own hooks by using module augmentation:
|
|
445
|
-
*
|
|
446
|
-
* ```ts
|
|
447
|
-
* declare module "alepha" {
|
|
448
|
-
*
|
|
449
|
-
* interface Hooks {
|
|
450
|
-
* "my:custom:hook": {
|
|
451
|
-
* arg1: string;
|
|
452
|
-
* }
|
|
453
|
-
* }
|
|
454
|
-
* }
|
|
455
|
-
*
|
|
456
|
-
* await alepha.events.emit("my:custom:hook", { arg1: "value" });
|
|
457
|
-
* ```
|
|
458
|
-
*
|
|
459
|
-
*/
|
|
460
|
-
const $hook = (options) => createPrimitive(HookPrimitive, options);
|
|
461
|
-
var HookPrimitive = class extends Primitive {
|
|
462
|
-
called = 0;
|
|
463
|
-
onInit() {
|
|
464
|
-
this.alepha.events.on(this.options.on, {
|
|
465
|
-
caller: this.config.service,
|
|
466
|
-
priority: this.options.priority,
|
|
467
|
-
callback: async (args) => {
|
|
468
|
-
this.called += 1;
|
|
469
|
-
await this.options.handler(args);
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
$hook[KIND] = HookPrimitive;
|
|
475
|
-
|
|
476
398
|
//#endregion
|
|
477
399
|
//#region ../../src/core/helpers/FileLike.ts
|
|
478
400
|
const isTypeFile = (value) => {
|
|
@@ -907,6 +829,322 @@ var TypeProvider = class TypeProvider {
|
|
|
907
829
|
};
|
|
908
830
|
const t = new TypeProvider();
|
|
909
831
|
|
|
832
|
+
//#endregion
|
|
833
|
+
//#region ../../src/core/providers/KeylessJsonSchemaCodec.ts
|
|
834
|
+
/**
|
|
835
|
+
* KeylessJsonSchemaCodec provides schema-driven JSON encoding without keys.
|
|
836
|
+
*
|
|
837
|
+
* It uses the schema to determine field order, allowing the encoded output
|
|
838
|
+
* to be a simple JSON array instead of an object with keys.
|
|
839
|
+
*
|
|
840
|
+
* Performance characteristics:
|
|
841
|
+
* - Encode: 0.94-1.53x vs JSON.stringify (faster for complex objects)
|
|
842
|
+
* - Decode: 1.76-2.00x vs JSON.parse
|
|
843
|
+
* - Size: 50-56% smaller than JSON
|
|
844
|
+
*/
|
|
845
|
+
var KeylessJsonSchemaCodec = class extends SchemaCodec {
|
|
846
|
+
cache = /* @__PURE__ */ new Map();
|
|
847
|
+
encoder = new TextEncoder();
|
|
848
|
+
decoder = new TextDecoder();
|
|
849
|
+
varCounter = 0;
|
|
850
|
+
/**
|
|
851
|
+
* Encode value to a keyless JSON string.
|
|
852
|
+
*/
|
|
853
|
+
encodeToString(schema, value) {
|
|
854
|
+
return this.getCodec(schema).encode(value);
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Encode value to binary (UTF-8 encoded keyless JSON).
|
|
858
|
+
*/
|
|
859
|
+
encodeToBinary(schema, value) {
|
|
860
|
+
return this.encoder.encode(this.encodeToString(schema, value));
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Decode keyless JSON string or binary to value.
|
|
864
|
+
*/
|
|
865
|
+
decode(schema, value) {
|
|
866
|
+
if (value instanceof Uint8Array) {
|
|
867
|
+
const text = this.decoder.decode(value);
|
|
868
|
+
return this.getCodec(schema).decode(text);
|
|
869
|
+
}
|
|
870
|
+
if (typeof value === "string") return this.getCodec(schema).decode(value);
|
|
871
|
+
if (Array.isArray(value)) return this.reconstructObject(schema, value);
|
|
872
|
+
return value;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Get a compiled codec for the given schema.
|
|
876
|
+
* Codecs are cached for reuse.
|
|
877
|
+
*/
|
|
878
|
+
getCodec(schema) {
|
|
879
|
+
let c = this.cache.get(schema);
|
|
880
|
+
if (!c) {
|
|
881
|
+
c = this.compile(schema);
|
|
882
|
+
this.cache.set(schema, c);
|
|
883
|
+
}
|
|
884
|
+
return c;
|
|
885
|
+
}
|
|
886
|
+
nextVar() {
|
|
887
|
+
return `_${this.varCounter++}`;
|
|
888
|
+
}
|
|
889
|
+
compile(schema) {
|
|
890
|
+
this.varCounter = 0;
|
|
891
|
+
const encBody = this.genEnc(schema, "v");
|
|
892
|
+
this.varCounter = 0;
|
|
893
|
+
const decBody = this.genDec(schema);
|
|
894
|
+
return {
|
|
895
|
+
encode: new Function("v", `return JSON.stringify(${encBody});`),
|
|
896
|
+
decode: new Function("s", `const a=JSON.parse(s);let i=0;${decBody.code}return ${decBody.result};`)
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
genEnc(schema, ve) {
|
|
900
|
+
if (t.schema.isString(schema) || t.schema.isNumber(schema) || t.schema.isInteger(schema) || t.schema.isBoolean(schema) || this.isEnum(schema)) return ve;
|
|
901
|
+
if (t.schema.isBigInt(schema)) return `${ve}+'n'`;
|
|
902
|
+
if (t.schema.isArray(schema)) {
|
|
903
|
+
const arrSchema = schema;
|
|
904
|
+
const itemEnc = this.genEnc(arrSchema.items, "e");
|
|
905
|
+
if (t.schema.isString(arrSchema.items) || t.schema.isNumber(arrSchema.items) || t.schema.isInteger(arrSchema.items) || t.schema.isBoolean(arrSchema.items)) return ve;
|
|
906
|
+
return `${ve}.map(e=>${itemEnc})`;
|
|
907
|
+
}
|
|
908
|
+
if (t.schema.isObject(schema)) {
|
|
909
|
+
const objSchema = schema;
|
|
910
|
+
const props = objSchema.properties;
|
|
911
|
+
const keys = Object.keys(props);
|
|
912
|
+
const req = new Set(objSchema.required || []);
|
|
913
|
+
const parts = [];
|
|
914
|
+
for (const k of keys) {
|
|
915
|
+
const ps = props[k];
|
|
916
|
+
const isOpt = !req.has(k) || t.schema.isOptional(ps);
|
|
917
|
+
const isNullable = this.isNullable(ps);
|
|
918
|
+
const inner = this.unwrap(ps);
|
|
919
|
+
const innerEnc = this.genEnc(inner, `${ve}.${k}`);
|
|
920
|
+
if (isOpt) parts.push(`${ve}.${k}!==undefined?${innerEnc}:null`);
|
|
921
|
+
else if (isNullable) parts.push(`${ve}.${k}!==null?${innerEnc}:null`);
|
|
922
|
+
else parts.push(innerEnc);
|
|
923
|
+
}
|
|
924
|
+
return `[${parts.join(",")}]`;
|
|
925
|
+
}
|
|
926
|
+
if (t.schema.isOptional(schema) || t.schema.isUnion(schema)) {
|
|
927
|
+
const inner = this.unwrap(schema);
|
|
928
|
+
const innerEnc = this.genEnc(inner, ve);
|
|
929
|
+
if (this.isNullable(schema)) return `${ve}!==null?${innerEnc}:null`;
|
|
930
|
+
return `${ve}!==undefined?${innerEnc}:null`;
|
|
931
|
+
}
|
|
932
|
+
return ve;
|
|
933
|
+
}
|
|
934
|
+
genDec(schema) {
|
|
935
|
+
const v = this.nextVar();
|
|
936
|
+
if (t.schema.isString(schema) || t.schema.isNumber(schema) || t.schema.isInteger(schema) || t.schema.isBoolean(schema) || this.isEnum(schema)) return {
|
|
937
|
+
code: "",
|
|
938
|
+
result: "a[i++]"
|
|
939
|
+
};
|
|
940
|
+
if (t.schema.isBigInt(schema)) return {
|
|
941
|
+
code: "",
|
|
942
|
+
result: "BigInt(a[i++].slice(0,-1))"
|
|
943
|
+
};
|
|
944
|
+
if (t.schema.isArray(schema)) {
|
|
945
|
+
const arrSchema = schema;
|
|
946
|
+
if (t.schema.isObject(arrSchema.items)) return {
|
|
947
|
+
code: "",
|
|
948
|
+
result: `a[i++].map(e=>${this.genDecFromValue(arrSchema.items, "e")})`
|
|
949
|
+
};
|
|
950
|
+
return {
|
|
951
|
+
code: "",
|
|
952
|
+
result: "a[i++]"
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
if (t.schema.isObject(schema)) {
|
|
956
|
+
const objSchema = schema;
|
|
957
|
+
const props = objSchema.properties;
|
|
958
|
+
const keys = Object.keys(props);
|
|
959
|
+
const req = new Set(objSchema.required || []);
|
|
960
|
+
let simple = true;
|
|
961
|
+
for (const k of keys) {
|
|
962
|
+
const ps = props[k];
|
|
963
|
+
const isOpt = !req.has(k) || t.schema.isOptional(ps);
|
|
964
|
+
const isNullable = this.isNullable(ps);
|
|
965
|
+
const inner = this.unwrap(ps);
|
|
966
|
+
if (isOpt || isNullable || t.schema.isObject(inner) || t.schema.isArray(inner)) {
|
|
967
|
+
simple = false;
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (simple) return {
|
|
972
|
+
code: "",
|
|
973
|
+
result: `{${keys.map((k) => `${k}:a[i++]`).join(",")}}`
|
|
974
|
+
};
|
|
975
|
+
let code = `const ${v}={};`;
|
|
976
|
+
for (const k of keys) {
|
|
977
|
+
const ps = props[k];
|
|
978
|
+
const isOpt = !req.has(k) || t.schema.isOptional(ps);
|
|
979
|
+
const isNullable = this.isNullable(ps);
|
|
980
|
+
const inner = this.unwrap(ps);
|
|
981
|
+
if (isOpt) {
|
|
982
|
+
const nested = this.genDecFromValue(inner, "t");
|
|
983
|
+
code += `{const t=a[i++];if(t!==null){${v}.${k}=${nested};}}`;
|
|
984
|
+
} else if (isNullable) {
|
|
985
|
+
const nested = this.genDecFromValue(inner, "t");
|
|
986
|
+
code += `{const t=a[i++];if(t===null){${v}.${k}=null;}else{${v}.${k}=${nested};}}`;
|
|
987
|
+
} else if (t.schema.isObject(inner)) {
|
|
988
|
+
const nested = this.genDecFromValue(inner, "a[i++]");
|
|
989
|
+
code += `${v}.${k}=${nested};`;
|
|
990
|
+
} else if (t.schema.isArray(inner)) {
|
|
991
|
+
const arrSchema = inner;
|
|
992
|
+
if (t.schema.isObject(arrSchema.items)) {
|
|
993
|
+
const itemTransform = this.genDecFromValue(arrSchema.items, "e");
|
|
994
|
+
code += `${v}.${k}=a[i++].map(e=>${itemTransform});`;
|
|
995
|
+
} else code += `${v}.${k}=a[i++];`;
|
|
996
|
+
} else code += `${v}.${k}=a[i++];`;
|
|
997
|
+
}
|
|
998
|
+
return {
|
|
999
|
+
code,
|
|
1000
|
+
result: v
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
if (t.schema.isOptional(schema) || t.schema.isUnion(schema)) {
|
|
1004
|
+
const inner = this.unwrap(schema);
|
|
1005
|
+
const innerDec = this.genDec(inner);
|
|
1006
|
+
return {
|
|
1007
|
+
code: `const ${v}t=a[i++];let ${v};if(${v}t===null){${v}=${this.isNullable(schema) ? "null" : "undefined"};}else{${innerDec.code.replace(/a\[i\+\+\]/g, `${v}t`)}${v}=${innerDec.result.replace(/a\[i\+\+\]/g, `${v}t`)};}`,
|
|
1008
|
+
result: v
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
return {
|
|
1012
|
+
code: "",
|
|
1013
|
+
result: "a[i++]"
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
genDecFromValue(schema, expr) {
|
|
1017
|
+
if (t.schema.isString(schema) || t.schema.isNumber(schema) || t.schema.isInteger(schema) || t.schema.isBoolean(schema) || this.isEnum(schema)) return expr;
|
|
1018
|
+
if (t.schema.isBigInt(schema)) return `BigInt(${expr}.slice(0,-1))`;
|
|
1019
|
+
if (t.schema.isArray(schema)) return expr;
|
|
1020
|
+
if (t.schema.isObject(schema)) {
|
|
1021
|
+
const props = schema.properties;
|
|
1022
|
+
const keys = Object.keys(props);
|
|
1023
|
+
const v = this.nextVar();
|
|
1024
|
+
return `((${v}=${expr})=>({${keys.map((k, idx) => {
|
|
1025
|
+
const inner = this.unwrap(props[k]);
|
|
1026
|
+
const innerExpr = `${v}[${idx}]`;
|
|
1027
|
+
if (t.schema.isObject(inner)) return `${k}:${this.genDecFromValue(inner, innerExpr)}`;
|
|
1028
|
+
if (t.schema.isBigInt(inner)) return `${k}:BigInt(${innerExpr}.slice(0,-1))`;
|
|
1029
|
+
return `${k}:${innerExpr}`;
|
|
1030
|
+
}).join(",")}}))()`;
|
|
1031
|
+
}
|
|
1032
|
+
return expr;
|
|
1033
|
+
}
|
|
1034
|
+
isEnum(schema) {
|
|
1035
|
+
return "enum" in schema && Array.isArray(schema.enum) && (schema.enum?.length ?? 0) > 0;
|
|
1036
|
+
}
|
|
1037
|
+
isNullable(schema) {
|
|
1038
|
+
if (!t.schema.isUnion(schema)) return false;
|
|
1039
|
+
return schema.anyOf?.some((s) => t.schema.isNull(s)) ?? false;
|
|
1040
|
+
}
|
|
1041
|
+
unwrap(schema) {
|
|
1042
|
+
if ("anyOf" in schema && Array.isArray(schema.anyOf)) return schema.anyOf.find((s) => !t.schema.isNull(s)) || schema;
|
|
1043
|
+
return schema;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Reconstruct an object from a parsed array (for when input is already parsed).
|
|
1047
|
+
*/
|
|
1048
|
+
reconstructObject(schema, arr) {
|
|
1049
|
+
if (!t.schema.isObject(schema)) return arr;
|
|
1050
|
+
const props = schema.properties;
|
|
1051
|
+
const keys = Object.keys(props);
|
|
1052
|
+
const result = {};
|
|
1053
|
+
let i = 0;
|
|
1054
|
+
for (const k of keys) {
|
|
1055
|
+
const ps = props[k];
|
|
1056
|
+
const isOpt = t.schema.isOptional(ps);
|
|
1057
|
+
const isNullable = this.isNullable(ps);
|
|
1058
|
+
const inner = this.unwrap(ps);
|
|
1059
|
+
const val = arr[i++];
|
|
1060
|
+
if (isOpt) {
|
|
1061
|
+
if (val !== null) result[k] = t.schema.isObject(inner) ? this.reconstructObject(inner, val) : val;
|
|
1062
|
+
} else if (isNullable) result[k] = val === null ? null : t.schema.isObject(inner) ? this.reconstructObject(inner, val) : val;
|
|
1063
|
+
else result[k] = t.schema.isObject(inner) ? this.reconstructObject(inner, val) : val;
|
|
1064
|
+
}
|
|
1065
|
+
return result;
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region ../../src/core/errors/TypeBoxError.ts
|
|
1071
|
+
var TypeBoxError = class extends AlephaError {
|
|
1072
|
+
name = "TypeBoxError";
|
|
1073
|
+
cause;
|
|
1074
|
+
value;
|
|
1075
|
+
constructor(error) {
|
|
1076
|
+
super(`Invalid input: ${error.message}${error.instancePath ? ` at ${error.instancePath}` : ""}`, { cause: error });
|
|
1077
|
+
const params = error.params;
|
|
1078
|
+
if (params?.requiredProperties) this.value = {
|
|
1079
|
+
path: `/${params.requiredProperties[0]}`,
|
|
1080
|
+
message: "must be defined"
|
|
1081
|
+
};
|
|
1082
|
+
else this.value = {
|
|
1083
|
+
path: error.instancePath,
|
|
1084
|
+
message: error.message
|
|
1085
|
+
};
|
|
1086
|
+
this.cause = error;
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
//#endregion
|
|
1091
|
+
//#region ../../src/core/primitives/$hook.ts
|
|
1092
|
+
/**
|
|
1093
|
+
* Registers a new hook.
|
|
1094
|
+
*
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* import { $hook } from "alepha";
|
|
1097
|
+
*
|
|
1098
|
+
* class MyProvider {
|
|
1099
|
+
* onStart = $hook({
|
|
1100
|
+
* name: "start", // or "configure", "ready", "stop", ...
|
|
1101
|
+
* handler: async (app) => {
|
|
1102
|
+
* // await db.connect(); ...
|
|
1103
|
+
* }
|
|
1104
|
+
* });
|
|
1105
|
+
* }
|
|
1106
|
+
* ```
|
|
1107
|
+
*
|
|
1108
|
+
* Hooks are used to run async functions from all registered providers/services.
|
|
1109
|
+
*
|
|
1110
|
+
* You can't register a hook after the App has started.
|
|
1111
|
+
*
|
|
1112
|
+
* It's used under the hood by the `configure`, `start`, and `stop` methods.
|
|
1113
|
+
* Some modules also use hooks to run their own logic. (e.g. `alepha/server`).
|
|
1114
|
+
*
|
|
1115
|
+
* You can create your own hooks by using module augmentation:
|
|
1116
|
+
*
|
|
1117
|
+
* ```ts
|
|
1118
|
+
* declare module "alepha" {
|
|
1119
|
+
*
|
|
1120
|
+
* interface Hooks {
|
|
1121
|
+
* "my:custom:hook": {
|
|
1122
|
+
* arg1: string;
|
|
1123
|
+
* }
|
|
1124
|
+
* }
|
|
1125
|
+
* }
|
|
1126
|
+
*
|
|
1127
|
+
* await alepha.events.emit("my:custom:hook", { arg1: "value" });
|
|
1128
|
+
* ```
|
|
1129
|
+
*
|
|
1130
|
+
*/
|
|
1131
|
+
const $hook = (options) => createPrimitive(HookPrimitive, options);
|
|
1132
|
+
var HookPrimitive = class extends Primitive {
|
|
1133
|
+
called = 0;
|
|
1134
|
+
onInit() {
|
|
1135
|
+
const handler = this.options.handler;
|
|
1136
|
+
this.alepha.events.on(this.options.on, {
|
|
1137
|
+
caller: this.config.service,
|
|
1138
|
+
priority: this.options.priority,
|
|
1139
|
+
callback: (args) => {
|
|
1140
|
+
this.called += 1;
|
|
1141
|
+
return handler(args);
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
$hook[KIND] = HookPrimitive;
|
|
1147
|
+
|
|
910
1148
|
//#endregion
|
|
911
1149
|
//#region ../../src/core/providers/SchemaValidator.ts
|
|
912
1150
|
var SchemaValidator = class {
|
|
@@ -1001,19 +1239,26 @@ var SchemaValidator = class {
|
|
|
1001
1239
|
var CodecManager = class {
|
|
1002
1240
|
codecs = /* @__PURE__ */ new Map();
|
|
1003
1241
|
jsonCodec = $inject(JsonSchemaCodec);
|
|
1242
|
+
keylessCodec = $inject(KeylessJsonSchemaCodec);
|
|
1004
1243
|
schemaValidator = $inject(SchemaValidator);
|
|
1005
1244
|
default = "json";
|
|
1006
1245
|
constructor() {
|
|
1007
|
-
this.register(
|
|
1246
|
+
this.register({
|
|
1247
|
+
name: "json",
|
|
1248
|
+
codec: this.jsonCodec,
|
|
1249
|
+
default: true
|
|
1250
|
+
});
|
|
1251
|
+
this.register({
|
|
1252
|
+
name: "keyless",
|
|
1253
|
+
codec: this.keylessCodec
|
|
1254
|
+
});
|
|
1008
1255
|
}
|
|
1009
1256
|
/**
|
|
1010
1257
|
* Register a new codec format.
|
|
1011
|
-
*
|
|
1012
|
-
* @param name - The name of the codec (e.g., 'json', 'protobuf')
|
|
1013
|
-
* @param codec - The codec implementation
|
|
1014
1258
|
*/
|
|
1015
|
-
register(
|
|
1016
|
-
this.codecs.set(name, codec);
|
|
1259
|
+
register(opts) {
|
|
1260
|
+
this.codecs.set(opts.name, opts.codec);
|
|
1261
|
+
if (opts.default) this.default = opts.name;
|
|
1017
1262
|
}
|
|
1018
1263
|
/**
|
|
1019
1264
|
* Get a specific codec by name.
|
|
@@ -1092,35 +1337,110 @@ var EventManager = class {
|
|
|
1092
1337
|
};
|
|
1093
1338
|
}
|
|
1094
1339
|
/**
|
|
1340
|
+
* Compiles an event into an optimized executor function.
|
|
1341
|
+
*
|
|
1342
|
+
* Call this after all hooks are registered (e.g., after Alepha.start()).
|
|
1343
|
+
* The returned function checks each hook's return value and awaits promises.
|
|
1344
|
+
* Returns undefined if all hooks are sync, or a Promise if any hook returns one.
|
|
1345
|
+
*
|
|
1346
|
+
* @example
|
|
1347
|
+
* ```ts
|
|
1348
|
+
* // At startup (after hooks are registered)
|
|
1349
|
+
* const onRequest = alepha.events.compile("server:onRequest", { catch: true });
|
|
1350
|
+
*
|
|
1351
|
+
* // In hot path - only await if promise returned
|
|
1352
|
+
* const result = onRequest({ request, route });
|
|
1353
|
+
* if (result) await result;
|
|
1354
|
+
* ```
|
|
1355
|
+
*/
|
|
1356
|
+
compile(event, options = {}) {
|
|
1357
|
+
const hooks = this.events[event];
|
|
1358
|
+
if (!hooks || hooks.length === 0) return () => {};
|
|
1359
|
+
const catchErrors = options.catch ?? false;
|
|
1360
|
+
const log = this.log;
|
|
1361
|
+
const runRemainingAsync = async (startIndex, payload) => {
|
|
1362
|
+
for (let i = startIndex; i < hooks.length; i++) {
|
|
1363
|
+
const hook = hooks[i];
|
|
1364
|
+
try {
|
|
1365
|
+
const result = hook.callback(payload);
|
|
1366
|
+
if (result && typeof result === "object" && "then" in result) if (catchErrors) await result.catch((error) => {
|
|
1367
|
+
log?.error(`${String(event)}(${hook.caller?.name ?? "unknown"}) ERROR`, error);
|
|
1368
|
+
});
|
|
1369
|
+
else await result;
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
if (catchErrors) log?.error(`${String(event)}(${hook.caller?.name ?? "unknown"}) ERROR`, error);
|
|
1372
|
+
else throw error;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
return (payload) => {
|
|
1377
|
+
for (let i = 0; i < hooks.length; i++) {
|
|
1378
|
+
const hook = hooks[i];
|
|
1379
|
+
try {
|
|
1380
|
+
const result = hook.callback(payload);
|
|
1381
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
1382
|
+
if (catchErrors) return result.catch((error) => {
|
|
1383
|
+
log?.error(`${String(event)}(${hook.caller?.name ?? "unknown"}) ERROR`, error);
|
|
1384
|
+
}).then(() => runRemainingAsync(i + 1, payload));
|
|
1385
|
+
return result.then(() => runRemainingAsync(i + 1, payload));
|
|
1386
|
+
}
|
|
1387
|
+
} catch (error) {
|
|
1388
|
+
if (catchErrors) log?.error(`${String(event)}(${hook.caller?.name ?? "unknown"}) ERROR`, error);
|
|
1389
|
+
else throw error;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1095
1395
|
* Emits the specified event with the given payload.
|
|
1396
|
+
*
|
|
1397
|
+
* For hot paths (like HTTP request handling), use compile() instead
|
|
1398
|
+
* to get an optimized executor.
|
|
1096
1399
|
*/
|
|
1097
1400
|
async emit(func, payload, options = {}) {
|
|
1401
|
+
const events = this.events[func];
|
|
1402
|
+
if (!events || events.length === 0) return;
|
|
1403
|
+
if (events.length === 1 && !options.log && !options.reverse) {
|
|
1404
|
+
const hook = events[0];
|
|
1405
|
+
try {
|
|
1406
|
+
const result = hook.callback(payload);
|
|
1407
|
+
if (result && typeof result === "object" && "then" in result) await result;
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
if (options.catch) {
|
|
1410
|
+
this.log?.error(`${String(func)}(${hook.caller?.name ?? "unknown"}) ERROR`, error);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
throw error;
|
|
1414
|
+
}
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1098
1417
|
const ctx = {};
|
|
1099
1418
|
if (options.log) {
|
|
1100
|
-
ctx.now =
|
|
1101
|
-
this.log?.trace(`${func} ...`);
|
|
1419
|
+
ctx.now = performance.now();
|
|
1420
|
+
this.log?.trace(`${String(func)} ...`);
|
|
1102
1421
|
}
|
|
1103
|
-
let
|
|
1104
|
-
if (options.reverse)
|
|
1105
|
-
for (const hook of
|
|
1422
|
+
let eventList = events;
|
|
1423
|
+
if (options.reverse) eventList = events.toReversed();
|
|
1424
|
+
for (const hook of eventList) {
|
|
1106
1425
|
const name = hook.caller?.name ?? "unknown";
|
|
1107
1426
|
if (options.log) {
|
|
1108
|
-
ctx.now2 =
|
|
1109
|
-
this.log?.trace(`${func}(${name}) ...`);
|
|
1427
|
+
ctx.now2 = performance.now();
|
|
1428
|
+
this.log?.trace(`${String(func)}(${name}) ...`);
|
|
1110
1429
|
}
|
|
1111
1430
|
try {
|
|
1112
|
-
|
|
1431
|
+
const result = hook.callback(payload);
|
|
1432
|
+
if (result && typeof result === "object" && "then" in result) await result;
|
|
1113
1433
|
} catch (error) {
|
|
1114
1434
|
if (options.catch) {
|
|
1115
|
-
this.log?.error(`${func}(${name}) ERROR`, error);
|
|
1435
|
+
this.log?.error(`${String(func)}(${name}) ERROR`, error);
|
|
1116
1436
|
continue;
|
|
1117
1437
|
}
|
|
1118
|
-
if (options.log) throw new AlephaError(`Failed during '${func}()' hook for service: ${name}`, { cause: error });
|
|
1438
|
+
if (options.log) throw new AlephaError(`Failed during '${String(func)}()' hook for service: ${name}`, { cause: error });
|
|
1119
1439
|
throw error;
|
|
1120
1440
|
}
|
|
1121
|
-
if (options.log) this.log?.debug(`${func}(${name}) OK [${
|
|
1441
|
+
if (options.log) this.log?.debug(`${String(func)}(${name}) OK [${(performance.now() - ctx.now2).toFixed(1)}ms]`);
|
|
1122
1442
|
}
|
|
1123
|
-
if (options.log) this.log?.debug(`${func} OK [${
|
|
1443
|
+
if (options.log) this.log?.debug(`${String(func)} OK [${(performance.now() - ctx.now).toFixed(1)}ms]`);
|
|
1124
1444
|
}
|
|
1125
1445
|
};
|
|
1126
1446
|
|
|
@@ -1404,10 +1724,13 @@ var Alepha = class Alepha {
|
|
|
1404
1724
|
* If you are not interested about these helpers, you can use the constructor directly.
|
|
1405
1725
|
*/
|
|
1406
1726
|
static create(state = {}) {
|
|
1407
|
-
if (typeof process === "object" && typeof process.env === "object")
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1727
|
+
if (typeof process === "object" && typeof process.env === "object") {
|
|
1728
|
+
state.env = {
|
|
1729
|
+
...state.env,
|
|
1730
|
+
...process.env
|
|
1731
|
+
};
|
|
1732
|
+
for (const key in state.env) if (state.env[key] === "") delete state.env[key];
|
|
1733
|
+
}
|
|
1411
1734
|
const alepha = new Alepha(state);
|
|
1412
1735
|
if (alepha.isTest()) {
|
|
1413
1736
|
const g = globalThis;
|
|
@@ -1835,6 +2158,25 @@ var Alepha = class Alepha {
|
|
|
1835
2158
|
}
|
|
1836
2159
|
return graph;
|
|
1837
2160
|
}
|
|
2161
|
+
dump() {
|
|
2162
|
+
const env = {};
|
|
2163
|
+
for (const [schema] of this.cacheEnv.entries()) {
|
|
2164
|
+
const ref = schema;
|
|
2165
|
+
for (const [key, value] of Object.entries(ref.properties)) {
|
|
2166
|
+
const prop = value;
|
|
2167
|
+
env[key] = {
|
|
2168
|
+
description: prop.description,
|
|
2169
|
+
default: prop.default,
|
|
2170
|
+
required: ref.required?.includes(key) ?? void 0,
|
|
2171
|
+
enum: prop.enum ? [...prop.enum] : void 0
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
return {
|
|
2176
|
+
env,
|
|
2177
|
+
providers: this.graph()
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
1838
2180
|
services(base) {
|
|
1839
2181
|
const list = [];
|
|
1840
2182
|
for (const [key, value] of this.registry.entries()) if (value.instance instanceof base) list.push(value.instance);
|
|
@@ -2306,5 +2648,5 @@ const run = (entry, opts) => {
|
|
|
2306
2648
|
};
|
|
2307
2649
|
|
|
2308
2650
|
//#endregion
|
|
2309
|
-
export { $atom, $context, $env, $hook, $inject, $module, $use, Alepha, AlephaError, AlsProvider, AppNotStartedError, Atom, CircularDependencyError, CodecManager, ContainerLockedError, EventManager, Format, HookPrimitive, InjectPrimitive, JsonSchemaCodec, KIND, Module, OPTIONS, Primitive, SchemaCodec, StateManager, TooLateSubstitutionError, Type, TypeBoxError, TypeGuard, TypeProvider, Value, createPagination, createPrimitive, isClass, isFileLike, isTypeFile, isUUID, jsonSchemaToTypeBox, pageMetadataSchema, pageQuerySchema, pageSchema, run, t };
|
|
2651
|
+
export { $atom, $context, $env, $hook, $inject, $module, $use, Alepha, AlephaError, AlsProvider, AppNotStartedError, Atom, CircularDependencyError, CodecManager, ContainerLockedError, EventManager, Format, HookPrimitive, InjectPrimitive, JsonSchemaCodec, KIND, KeylessJsonSchemaCodec, Module, OPTIONS, Primitive, SchemaCodec, StateManager, TooLateSubstitutionError, Type, TypeBoxError, TypeGuard, TypeProvider, Value, createPagination, createPrimitive, isClass, isFileLike, isTypeFile, isUUID, jsonSchemaToTypeBox, pageMetadataSchema, pageQuerySchema, pageSchema, run, t };
|
|
2310
2652
|
//# sourceMappingURL=index.browser.js.map
|