@zintrust/core 0.1.22 → 0.1.23
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/bin/z.d.ts +1 -1
- package/bin/z.js +1 -1
- package/bin/zin.d.ts +1 -1
- package/bin/zin.js +1 -1
- package/bin/zintrust-main.d.ts +1 -1
- package/bin/zintrust-main.js +2 -2
- package/bin/zintrust-microservices.d.ts +1 -1
- package/bin/zintrust-microservices.js +1 -1
- package/bin/zintrust.d.ts +1 -1
- package/bin/zintrust.js +1 -1
- package/bin/zt.d.ts +1 -1
- package/bin/zt.js +1 -1
- package/package.json +2 -3
- package/public/index.html +3 -3
- package/routes/api.js +1 -1
- package/routes/health.d.ts +3 -4
- package/routes/health.d.ts.map +1 -1
- package/routes/health.js +3 -125
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +11 -22
- package/src/boot/bootstrap.d.ts +1 -1
- package/src/boot/bootstrap.js +48 -7
- package/src/builder/BundleOptimizer.d.ts +1 -1
- package/src/builder/BundleOptimizer.js +1 -1
- package/src/cache/drivers/KVRemoteDriver.d.ts +1 -1
- package/src/cache/drivers/KVRemoteDriver.js +1 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +15 -1
- package/src/cli/ErrorHandler.js +3 -3
- package/src/cli/commands/AddCommand.d.ts +1 -1
- package/src/cli/commands/AddCommand.d.ts.map +1 -1
- package/src/cli/commands/AddCommand.js +1 -1
- package/src/cli/commands/DbSeedCommand.js +1 -1
- package/src/cli/commands/MakeMailTemplateCommand.js +2 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.js +2 -1
- package/src/cli/commands/MigrateWorkerCommand.d.ts +9 -0
- package/src/cli/commands/MigrateWorkerCommand.d.ts.map +1 -0
- package/src/cli/commands/MigrateWorkerCommand.js +182 -0
- package/src/cli/commands/NewCommand.d.ts +1 -1
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +21 -7
- package/src/cli/commands/PublishCommand.d.ts +5 -0
- package/src/cli/commands/PublishCommand.d.ts.map +1 -0
- package/src/cli/commands/PublishCommand.js +54 -0
- package/src/cli/commands/QACommand.js +4 -4
- package/src/cli/commands/ResourceControlCommand.d.ts +6 -0
- package/src/cli/commands/ResourceControlCommand.d.ts.map +1 -0
- package/src/cli/commands/ResourceControlCommand.js +43 -0
- package/src/cli/commands/SimulateCommand.d.ts +1 -1
- package/src/cli/commands/SimulateCommand.js +4 -4
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +19 -7
- package/src/cli/commands/UpgradeCommand.d.ts +1 -1
- package/src/cli/commands/UpgradeCommand.js +2 -2
- package/src/cli/commands/WorkerCommands.d.ts +17 -0
- package/src/cli/commands/WorkerCommands.d.ts.map +1 -0
- package/src/cli/commands/WorkerCommands.js +264 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/config/ConfigSchema.d.ts +1 -1
- package/src/cli/config/ConfigSchema.d.ts.map +1 -1
- package/src/cli/config/ConfigSchema.js +4 -3
- package/src/cli/scaffolding/ProjectScaffolder.js +5 -5
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/RouteGenerator.js +21 -2
- package/src/cli/scaffolding/TemplateEngine.js +1 -1
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -1
- package/src/common/ExternalServiceUtils.d.ts +63 -0
- package/src/common/ExternalServiceUtils.d.ts.map +1 -0
- package/src/common/ExternalServiceUtils.js +116 -0
- package/src/common/HealthRoutes.d.ts +10 -0
- package/src/common/HealthRoutes.d.ts.map +1 -0
- package/src/common/HealthRoutes.js +114 -0
- package/src/config/SecretsManager.d.ts.map +1 -1
- package/src/config/SecretsManager.js +2 -1
- package/src/config/app.d.ts +2 -1
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +98 -52
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +1 -1
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +2 -2
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +24 -5
- package/src/config/env.d.ts +43 -1
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +68 -21
- package/src/config/index.d.ts +10 -1
- package/src/config/index.d.ts.map +1 -1
- package/src/config/index.js +1 -0
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +3 -3
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +1 -1
- package/src/config/notification.d.ts.map +1 -1
- package/src/config/notification.js +2 -2
- package/src/config/queue.d.ts +14 -0
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +61 -36
- package/src/config/security.js +2 -2
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +1 -1
- package/src/config/type.d.ts +111 -0
- package/src/config/type.d.ts.map +1 -1
- package/src/config/workers.d.ts +13 -0
- package/src/config/workers.d.ts.map +1 -0
- package/src/config/workers.js +173 -0
- package/src/database/Paginator.d.ts +37 -0
- package/src/database/Paginator.d.ts.map +1 -0
- package/src/database/Paginator.js +81 -0
- package/src/exceptions/ZintrustError.d.ts +5 -2
- package/src/exceptions/ZintrustError.d.ts.map +1 -1
- package/src/exceptions/ZintrustError.js +6 -2
- package/src/features/Auth.d.ts +1 -1
- package/src/features/Auth.d.ts.map +1 -1
- package/src/features/Auth.js +3 -2
- package/src/features/Queue.d.ts.map +1 -1
- package/src/features/Queue.js +0 -2
- package/src/index.d.ts +15 -5
- package/src/index.d.ts.map +1 -1
- package/src/index.js +24 -3
- package/src/microservices/MicroserviceBootstrap.d.ts.map +1 -1
- package/src/microservices/MicroserviceBootstrap.js +3 -1
- package/src/microservices/MicroserviceGenerator.js +4 -4
- package/src/microservices/MicroserviceManager.d.ts +1 -1
- package/src/microservices/MicroserviceManager.js +1 -1
- package/src/middleware/RateLimiter.d.ts.map +1 -1
- package/src/middleware/RateLimiter.js +4 -3
- package/src/node-singletons/crypto.d.ts +1 -1
- package/src/node-singletons/crypto.d.ts.map +1 -1
- package/src/node-singletons/crypto.js +1 -1
- package/src/node-singletons/os.d.ts +10 -1
- package/src/node-singletons/os.d.ts.map +1 -1
- package/src/node-singletons/os.js +10 -1
- package/src/openapi/OpenApiGenerator.js +2 -2
- package/src/orm/ConnectionManager.d.ts +1 -1
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +37 -19
- package/src/orm/Model.d.ts +8 -1
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +85 -24
- package/src/orm/QueryBuilder.d.ts +12 -2
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +438 -38
- package/src/orm/Relationships.d.ts +61 -1
- package/src/orm/Relationships.d.ts.map +1 -1
- package/src/orm/Relationships.js +190 -0
- package/src/orm/adapters/D1RemoteAdapter.d.ts +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +1 -1
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +2 -4
- package/src/routing/CoreRoutes.d.ts +1 -1
- package/src/routing/CoreRoutes.d.ts.map +1 -1
- package/src/routing/CoreRoutes.js +2 -116
- package/src/routing/error.d.ts.map +1 -1
- package/src/routing/error.js +3 -2
- package/src/routing/publicRoot.d.ts.map +1 -1
- package/src/routing/publicRoot.js +4 -2
- package/src/runtime/PluginAutoImports.d.ts.map +1 -1
- package/src/runtime/PluginAutoImports.js +20 -4
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +23 -6
- package/src/runtime/RuntimeAdapter.d.ts +3 -3
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts +2 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.js +2 -1
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/CloudflareAdapter.js +1 -1
- package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/DenoAdapter.js +1 -1
- package/src/runtime/adapters/FargateAdapter.d.ts +2 -2
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/FargateAdapter.js +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +6 -4
- package/src/runtime/adapters/NodeServerAdapter.js +1 -1
- package/src/scripts/GenerateEnvArtifacts.js +1 -1
- package/src/security/SignedRequest.js +1 -1
- package/src/security/StartupSecretValidation.d.ts.map +1 -1
- package/src/security/StartupSecretValidation.js +7 -1
- package/src/start.d.ts.map +1 -1
- package/src/start.js +0 -2
- package/src/templates/features/Auth.ts.tpl +4 -4
- package/src/templates/project/basic/README.md.tpl +1 -1
- package/src/templates/project/basic/app/Middleware/index.ts.tpl +1 -1
- package/src/templates/project/basic/config/notification.ts.tpl +1 -1
- package/src/templates/project/basic/routes/api.ts.tpl +1 -3
- package/src/templates/project/basic/src/index.ts.tpl +1 -1
- package/src/templates/project/basic/src/zintrust.plugins.ts.tpl +1 -1
- package/src/templates/project/basic/template.json +1 -1
- package/src/toolkit/Secrets/index.d.ts.map +1 -1
- package/src/toolkit/Secrets/index.js +13 -9
- package/src/toolkit/Secrets/providers/AwsSecretsManager.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/AwsSecretsManager.js +20 -7
- package/src/toolkit/Secrets/providers/CloudflareKv.d.ts.map +1 -1
- package/src/toolkit/Secrets/providers/CloudflareKv.js +19 -6
- package/src/tools/http/Http.js +1 -1
- package/src/tools/mail/drivers/Ses.d.ts.map +1 -1
- package/src/tools/mail/drivers/Ses.js +5 -4
- package/src/tools/mail/templates/index.js +2 -2
- package/src/tools/notification/drivers/Termii.d.ts.map +1 -1
- package/src/tools/notification/drivers/Termii.js +6 -17
- package/src/tools/notification/testingHelpers.d.ts.map +1 -1
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +3 -5
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
- package/src/tools/queue/drivers/Redis.js +7 -1
- package/src/tools/storage/drivers/S3.d.ts.map +1 -1
- package/src/tools/storage/drivers/S3.js +16 -3
- package/src/routes/health.d.ts +0 -2
- package/src/routes/health.d.ts.map +0 -1
- package/src/routes/health.js +0 -1
- package/src/runtime/RuntimeDetector.d.ts +0 -15
- package/src/runtime/RuntimeDetector.d.ts.map +0 -1
- package/src/runtime/RuntimeDetector.js +0 -271
- package/src/templates/project/basic/routes/health.ts.tpl +0 -143
- package/src/templates/project/basic/routes/metrics.ts.tpl +0 -22
- package/src/workers/BroadcastWorker.d.ts +0 -22
- package/src/workers/BroadcastWorker.d.ts.map +0 -1
- package/src/workers/BroadcastWorker.js +0 -24
- package/src/workers/NotificationWorker.d.ts +0 -22
- package/src/workers/NotificationWorker.d.ts.map +0 -1
- package/src/workers/NotificationWorker.js +0 -23
- package/src/workers/createQueueWorker.d.ts +0 -24
- package/src/workers/createQueueWorker.d.ts.map +0 -1
- package/src/workers/createQueueWorker.js +0 -114
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../config/logger.js';
|
|
2
|
-
import { Queue } from '../tools/queue/Queue.js';
|
|
3
|
-
const buildBaseLogFields = (message, getLogFields) => {
|
|
4
|
-
return {
|
|
5
|
-
messageId: message.id,
|
|
6
|
-
...getLogFields(message.payload),
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
const createProcessOne = (options) => {
|
|
10
|
-
return async (queueName = options.defaultQueueName, driverName) => {
|
|
11
|
-
const message = await Queue.dequeue(queueName, driverName);
|
|
12
|
-
if (!message)
|
|
13
|
-
return false;
|
|
14
|
-
const baseLogFields = buildBaseLogFields(message, options.getLogFields);
|
|
15
|
-
// Check for delayed execution
|
|
16
|
-
const payload = message.payload;
|
|
17
|
-
const rawTimestamp = 'timestamp' in payload ? payload['timestamp'] : 0;
|
|
18
|
-
const timestamp = typeof rawTimestamp === 'number' ? rawTimestamp : 0;
|
|
19
|
-
if (timestamp > Date.now()) {
|
|
20
|
-
Logger.info(`${options.kindLabel} not due yet, re-queueing`, {
|
|
21
|
-
...baseLogFields,
|
|
22
|
-
dueAt: new Date(timestamp).toISOString(),
|
|
23
|
-
});
|
|
24
|
-
// Re-queue original payload
|
|
25
|
-
await Queue.enqueue(queueName, message.payload, driverName);
|
|
26
|
-
await Queue.ack(queueName, message.id, driverName);
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
Logger.info(`Processing queued ${options.kindLabel}`, baseLogFields);
|
|
31
|
-
await options.handle(message.payload);
|
|
32
|
-
await Queue.ack(queueName, message.id, driverName);
|
|
33
|
-
Logger.info(`${options.kindLabel} processed successfully`, baseLogFields);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
const attempts = message.attempts ?? 0;
|
|
38
|
-
Logger.error(`Failed to process ${options.kindLabel}`, {
|
|
39
|
-
...baseLogFields,
|
|
40
|
-
error,
|
|
41
|
-
attempts,
|
|
42
|
-
});
|
|
43
|
-
if (attempts < options.maxAttempts) {
|
|
44
|
-
await Queue.enqueue(queueName, message.payload, driverName);
|
|
45
|
-
Logger.info(`${options.kindLabel} re-queued for retry`, {
|
|
46
|
-
...baseLogFields,
|
|
47
|
-
attempts: attempts + 1,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
await Queue.ack(queueName, message.id, driverName);
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
const createProcessAll = (defaultQueueName, processOne) => {
|
|
56
|
-
return async (queueName = defaultQueueName, driverName) => {
|
|
57
|
-
let processed = 0;
|
|
58
|
-
let hasMore = true;
|
|
59
|
-
while (hasMore) {
|
|
60
|
-
// eslint-disable-next-line no-await-in-loop
|
|
61
|
-
hasMore = await processOne(queueName, driverName);
|
|
62
|
-
if (hasMore)
|
|
63
|
-
processed++;
|
|
64
|
-
}
|
|
65
|
-
return processed;
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
const createRunOnce = (defaultQueueName, processOne) => {
|
|
69
|
-
return async (opts = {}) => {
|
|
70
|
-
const { queueName = defaultQueueName, driverName, maxItems } = opts;
|
|
71
|
-
let processed = 0;
|
|
72
|
-
if (maxItems === undefined) {
|
|
73
|
-
while (true) {
|
|
74
|
-
// eslint-disable-next-line no-await-in-loop
|
|
75
|
-
const didProcess = await processOne(queueName, driverName);
|
|
76
|
-
if (!didProcess)
|
|
77
|
-
break;
|
|
78
|
-
processed++;
|
|
79
|
-
}
|
|
80
|
-
return processed;
|
|
81
|
-
}
|
|
82
|
-
for (let i = 0; i < maxItems; i++) {
|
|
83
|
-
// eslint-disable-next-line no-await-in-loop
|
|
84
|
-
const didProcess = await processOne(queueName, driverName);
|
|
85
|
-
if (!didProcess)
|
|
86
|
-
break;
|
|
87
|
-
processed++;
|
|
88
|
-
}
|
|
89
|
-
return processed;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
const createStartWorker = (kindLabel, defaultQueueName, processOne) => {
|
|
93
|
-
return async (opts = {}) => {
|
|
94
|
-
const { queueName = defaultQueueName, driverName, signal } = opts;
|
|
95
|
-
Logger.info(`Starting ${kindLabel} worker (drain-until-empty)`, { queueName });
|
|
96
|
-
let processedCount = 0;
|
|
97
|
-
while (signal?.aborted !== true) {
|
|
98
|
-
// eslint-disable-next-line no-await-in-loop
|
|
99
|
-
const didProcess = await processOne(queueName, driverName);
|
|
100
|
-
if (!didProcess)
|
|
101
|
-
break;
|
|
102
|
-
processedCount++;
|
|
103
|
-
}
|
|
104
|
-
Logger.info(`${kindLabel} worker finished (queue drained)`, { queueName, processedCount });
|
|
105
|
-
return processedCount;
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
export function createQueueWorker(options) {
|
|
109
|
-
const processOne = createProcessOne(options);
|
|
110
|
-
const processAll = createProcessAll(options.defaultQueueName, processOne);
|
|
111
|
-
const runOnce = createRunOnce(options.defaultQueueName, processOne);
|
|
112
|
-
const startWorker = createStartWorker(options.kindLabel, options.defaultQueueName, processOne);
|
|
113
|
-
return Object.freeze({ processOne, processAll, runOnce, startWorker });
|
|
114
|
-
}
|