@zintrust/core 0.1.41 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -1
- package/src/boot/bootstrap.js +27 -11
- package/src/boot/registry/runtime.d.ts.map +1 -1
- package/src/boot/registry/runtime.js +11 -0
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +12 -0
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/ConfigCommand.js +3 -5
- package/src/cli/commands/D1LearnCommand.d.ts +9 -0
- package/src/cli/commands/D1LearnCommand.d.ts.map +1 -0
- package/src/cli/commands/D1LearnCommand.js +143 -0
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/D1MigrateCommand.js +55 -16
- package/src/cli/commands/InitContainerCommand.d.ts.map +1 -1
- package/src/cli/commands/InitContainerCommand.js +21 -6
- package/src/cli/commands/InitEcosystemCommand.d.ts +6 -0
- package/src/cli/commands/InitEcosystemCommand.d.ts.map +1 -0
- package/src/cli/commands/InitEcosystemCommand.js +51 -0
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +78 -36
- package/src/cli/commands/MigrateWorkerCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateWorkerCommand.js +36 -2
- package/src/cli/commands/PutCommand.d.ts +6 -0
- package/src/cli/commands/PutCommand.d.ts.map +1 -0
- package/src/cli/commands/PutCommand.js +173 -0
- package/src/cli/commands/QueueRecoveryCommand.d.ts.map +1 -1
- package/src/cli/commands/QueueRecoveryCommand.js +113 -14
- package/src/cli/commands/ScheduleListCommand.d.ts +6 -0
- package/src/cli/commands/ScheduleListCommand.d.ts.map +1 -0
- package/src/cli/commands/ScheduleListCommand.js +62 -0
- package/src/cli/commands/ScheduleRunCommand.d.ts +6 -0
- package/src/cli/commands/ScheduleRunCommand.d.ts.map +1 -0
- package/src/cli/commands/ScheduleRunCommand.js +32 -0
- package/src/cli/commands/ScheduleStartCommand.d.ts +6 -0
- package/src/cli/commands/ScheduleStartCommand.d.ts.map +1 -0
- package/src/cli/commands/ScheduleStartCommand.js +40 -0
- package/src/cli/commands/SecretsCommand.d.ts.map +1 -1
- package/src/cli/commands/SecretsCommand.js +2 -2
- package/src/cli/commands/schedule/ScheduleCliSupport.d.ts +6 -0
- package/src/cli/commands/schedule/ScheduleCliSupport.d.ts.map +1 -0
- package/src/cli/commands/schedule/ScheduleCliSupport.js +55 -0
- package/src/cli/config/ConfigManager.d.ts.map +1 -1
- package/src/cli/config/ConfigManager.js +8 -1
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -1
- package/src/cli/d1/D1SqlMigrations.js +11 -1
- package/src/cli/d1/WranglerConfig.d.ts.map +1 -1
- package/src/cli/d1/WranglerConfig.js +34 -2
- package/src/cli/services/VersionChecker.d.ts.map +1 -1
- package/src/cli/services/VersionChecker.js +5 -1
- package/src/cli/utils/DatabaseCliUtils.d.ts.map +1 -1
- package/src/cli/utils/DatabaseCliUtils.js +6 -1
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -1
- package/src/cli/utils/EnvFileLoader.js +33 -14
- package/src/cli.d.ts +5 -0
- package/src/cli.d.ts.map +1 -0
- package/src/cli.js +4 -0
- package/src/collections/index.d.ts +2 -2
- package/src/collections/index.d.ts.map +1 -1
- package/src/collections/index.js +1 -1
- package/src/common/RemoteSignedJson.d.ts.map +1 -1
- package/src/common/RemoteSignedJson.js +49 -23
- package/src/common/utility.d.ts.map +1 -1
- package/src/common/utility.js +2 -6
- package/src/config/cloudflare.d.ts.map +1 -1
- package/src/config/cloudflare.js +19 -8
- package/src/config/env.js +2 -2
- package/src/helper/index.d.ts +225 -0
- package/src/helper/index.d.ts.map +1 -0
- package/src/helper/index.js +347 -0
- package/src/index.d.ts +3 -6
- package/src/index.d.ts.map +1 -1
- package/src/index.js +7 -9
- package/src/migrations/MigrationDiscovery.d.ts.map +1 -1
- package/src/migrations/MigrationDiscovery.js +2 -1
- package/src/orm/DatabaseAdapter.d.ts +1 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/SchemaStatemenWriter.d.ts +15 -0
- package/src/orm/SchemaStatemenWriter.d.ts.map +1 -0
- package/src/orm/SchemaStatemenWriter.js +78 -0
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +52 -2
- package/src/orm/adapters/D1RemoteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +137 -89
- package/src/orm/adapters/MySQLProxyAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLProxyAdapter.js +100 -81
- package/src/orm/adapters/PostgreSQLProxyAdapter.d.ts.map +1 -1
- package/src/orm/adapters/PostgreSQLProxyAdapter.js +26 -10
- package/src/orm/adapters/SqlProxyAdapterUtils.d.ts.map +1 -1
- package/src/orm/adapters/SqlProxyAdapterUtils.js +2 -1
- package/src/orm/adapters/SqlProxyRegistryMode.d.ts +12 -0
- package/src/orm/adapters/SqlProxyRegistryMode.d.ts.map +1 -0
- package/src/orm/adapters/SqlProxyRegistryMode.js +24 -0
- package/src/orm/adapters/SqlServerProxyAdapter.d.ts +3 -0
- package/src/orm/adapters/SqlServerProxyAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SqlServerProxyAdapter.js +125 -117
- package/src/orm/migrations/MigrationStore.js +1 -1
- package/src/proxy/ProxyRequestParsing.d.ts +9 -0
- package/src/proxy/ProxyRequestParsing.d.ts.map +1 -0
- package/src/proxy/ProxyRequestParsing.js +16 -0
- package/src/proxy/RequestValidator.d.ts.map +1 -1
- package/src/proxy/RequestValidator.js +2 -1
- package/src/proxy/SigningService.js +2 -2
- package/src/proxy/SqlProxyDbOverrides.d.ts +17 -0
- package/src/proxy/SqlProxyDbOverrides.d.ts.map +1 -0
- package/src/proxy/SqlProxyDbOverrides.js +1 -0
- package/src/proxy/SqlProxyServerDeps.d.ts +12 -0
- package/src/proxy/SqlProxyServerDeps.d.ts.map +1 -0
- package/src/proxy/SqlProxyServerDeps.js +9 -0
- package/src/proxy/StatementPayloadValidator.d.ts +13 -0
- package/src/proxy/StatementPayloadValidator.d.ts.map +1 -0
- package/src/proxy/StatementPayloadValidator.js +18 -0
- package/src/proxy/StatementRegistryLoader.d.ts +2 -0
- package/src/proxy/StatementRegistryLoader.d.ts.map +1 -0
- package/src/proxy/StatementRegistryLoader.js +36 -0
- package/src/proxy/StatementRegistryResolver.d.ts +15 -0
- package/src/proxy/StatementRegistryResolver.d.ts.map +1 -0
- package/src/proxy/StatementRegistryResolver.js +34 -0
- package/src/proxy/d1/ZintrustD1Proxy.d.ts +2 -1
- package/src/proxy/d1/ZintrustD1Proxy.d.ts.map +1 -1
- package/src/proxy/d1/ZintrustD1Proxy.js +2 -1
- package/src/proxy/isMutatingSql.d.ts +2 -0
- package/src/proxy/isMutatingSql.d.ts.map +1 -0
- package/src/proxy/isMutatingSql.js +12 -0
- package/src/proxy/kv/ZintrustKvProxy.d.ts +2 -1
- package/src/proxy/kv/ZintrustKvProxy.d.ts.map +1 -1
- package/src/proxy/kv/ZintrustKvProxy.js +2 -1
- package/src/proxy/mysql/MySqlProxyServer.d.ts +2 -8
- package/src/proxy/mysql/MySqlProxyServer.d.ts.map +1 -1
- package/src/proxy/mysql/MySqlProxyServer.js +84 -51
- package/src/proxy/postgres/PostgresProxyServer.d.ts +2 -8
- package/src/proxy/postgres/PostgresProxyServer.d.ts.map +1 -1
- package/src/proxy/postgres/PostgresProxyServer.js +86 -48
- package/src/proxy/smtp/SmtpProxyServer.d.ts.map +1 -1
- package/src/proxy/smtp/SmtpProxyServer.js +6 -5
- package/src/proxy/sqlserver/SqlServerProxyServer.d.ts +2 -8
- package/src/proxy/sqlserver/SqlServerProxyServer.d.ts.map +1 -1
- package/src/proxy/sqlserver/SqlServerProxyServer.js +84 -49
- package/src/proxy.d.ts +4 -0
- package/src/proxy.d.ts.map +1 -0
- package/src/proxy.js +3 -0
- package/src/scheduler/Schedule.d.ts +36 -0
- package/src/scheduler/Schedule.d.ts.map +1 -0
- package/src/scheduler/Schedule.js +197 -0
- package/src/scheduler/ScheduleHttpGateway.d.ts +8 -0
- package/src/scheduler/ScheduleHttpGateway.d.ts.map +1 -0
- package/src/scheduler/ScheduleHttpGateway.js +196 -0
- package/src/scheduler/ScheduleRunner.d.ts +6 -0
- package/src/scheduler/ScheduleRunner.d.ts.map +1 -1
- package/src/scheduler/ScheduleRunner.js +166 -29
- package/src/scheduler/SchedulerRuntime.d.ts +15 -0
- package/src/scheduler/SchedulerRuntime.d.ts.map +1 -0
- package/src/scheduler/SchedulerRuntime.js +79 -0
- package/src/scheduler/cron/Cron.d.ts +19 -0
- package/src/scheduler/cron/Cron.d.ts.map +1 -0
- package/src/scheduler/cron/Cron.js +200 -0
- package/src/scheduler/leader/SchedulerLeader.d.ts +14 -0
- package/src/scheduler/leader/SchedulerLeader.d.ts.map +1 -0
- package/src/scheduler/leader/SchedulerLeader.js +187 -0
- package/src/scheduler/state/ScheduleStateStore.d.ts +27 -0
- package/src/scheduler/state/ScheduleStateStore.d.ts.map +1 -0
- package/src/scheduler/state/ScheduleStateStore.js +27 -0
- package/src/scheduler/types.d.ts +10 -0
- package/src/scheduler/types.d.ts.map +1 -1
- package/src/schedules/index.d.ts +1 -0
- package/src/schedules/index.d.ts.map +1 -1
- package/src/schedules/index.js +1 -0
- package/src/schedules/job-tracking-cleanup.d.ts +4 -0
- package/src/schedules/job-tracking-cleanup.d.ts.map +1 -0
- package/src/schedules/job-tracking-cleanup.js +116 -0
- package/src/schedules/log-cleanup.d.ts +1 -2
- package/src/schedules/log-cleanup.d.ts.map +1 -1
- package/src/schedules/log-cleanup.js +12 -15
- package/src/security/Sanitizer.d.ts.map +1 -1
- package/src/security/Sanitizer.js +1 -9
- package/src/security/SignedRequest.d.ts.map +1 -1
- package/src/security/SignedRequest.js +2 -2
- package/src/templates/docker/docker-compose.ecosystem.yml.tpl +301 -0
- package/src/templates/docker/docker-compose.schedules.yml.tpl +84 -0
- package/src/templates/project/basic/app/Schedules/index.ts.tpl +0 -0
- package/src/templates/project/basic/config/database.ts.tpl +1 -1
- package/src/toolkit/Secrets/Manifest.d.ts.map +1 -1
- package/src/toolkit/Secrets/Manifest.js +5 -7
- package/src/tools/mail/drivers/Smtp.d.ts.map +1 -1
- package/src/tools/mail/drivers/Smtp.js +7 -1
- package/src/tools/queue/JobReconciliationRunner.d.ts.map +1 -1
- package/src/tools/queue/JobReconciliationRunner.js +7 -39
- package/src/tools/queue/JobRecoveryDaemon.d.ts.map +1 -1
- package/src/tools/queue/JobRecoveryDaemon.js +116 -18
- package/src/tools/queue/JobStateTracker.d.ts +10 -1
- package/src/tools/queue/JobStateTracker.d.ts.map +1 -1
- package/src/tools/queue/JobStateTracker.js +24 -2
- package/src/tools/queue/JobStateTrackerDbPersistence.d.ts.map +1 -1
- package/src/tools/queue/JobStateTrackerDbPersistence.js +93 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RemoteSignedJson } from '../../common/RemoteSignedJson.js';
|
|
2
2
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
3
|
+
import { isObject } from '../../helper/index.js';
|
|
3
4
|
import { resolveSigningPrefix } from '../adapters/ProxySigningPath.js';
|
|
4
5
|
import { normalizeSigningCredentials } from '../../proxy/SigningService.js';
|
|
5
6
|
export const buildSignedSettings = (config) => {
|
|
@@ -32,4 +33,4 @@ export const requestSignedProxy = async (config, path, payload) => {
|
|
|
32
33
|
const signedSettings = ensureSignedSettings(config);
|
|
33
34
|
return RemoteSignedJson.request(signedSettings, path, payload);
|
|
34
35
|
};
|
|
35
|
-
export const isRecord = (value) =>
|
|
36
|
+
export const isRecord = (value) => isObject(value);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type SqlProxyMode = 'sql' | 'registry';
|
|
2
|
+
export declare const resolveSqlProxyMode: (envKey: string) => SqlProxyMode;
|
|
3
|
+
export declare const createStatementId: (sql: string) => Promise<string>;
|
|
4
|
+
export declare const createStatementPayload: (sql: string, parameters: unknown[]) => Promise<{
|
|
5
|
+
statementId: string;
|
|
6
|
+
params: unknown[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const getExecMetaWithLastRowId: (value: unknown) => {
|
|
9
|
+
changes: number;
|
|
10
|
+
lastRowId?: number | string | bigint;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=SqlProxyRegistryMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlProxyRegistryMode.d.ts","sourceRoot":"","sources":["../../../../src/orm/adapters/SqlProxyRegistryMode.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,UAAU,CAAC;AAE9C,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,KAAG,YAGpD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,CAEnE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,KAAK,MAAM,EACX,YAAY,OAAO,EAAE,KACpB,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAGpD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,OAAO,OAAO,KACb;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CAOzD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Env } from '../../config/env.js';
|
|
2
|
+
import { isRecord } from '../adapters/SqlProxyAdapterUtils.js';
|
|
3
|
+
import { SignedRequest } from '../../security/SignedRequest.js';
|
|
4
|
+
export const resolveSqlProxyMode = (envKey) => {
|
|
5
|
+
const raw = Env.get(envKey, 'sql').trim().toLowerCase();
|
|
6
|
+
return raw === 'registry' ? 'registry' : 'sql';
|
|
7
|
+
};
|
|
8
|
+
export const createStatementId = async (sql) => {
|
|
9
|
+
return SignedRequest.sha256Hex(sql);
|
|
10
|
+
};
|
|
11
|
+
export const createStatementPayload = async (sql, parameters) => {
|
|
12
|
+
const statementId = await createStatementId(sql);
|
|
13
|
+
return { statementId, params: parameters };
|
|
14
|
+
};
|
|
15
|
+
export const getExecMetaWithLastRowId = (value) => {
|
|
16
|
+
if (!isRecord(value) || typeof value['ok'] !== 'boolean')
|
|
17
|
+
return { changes: 0 };
|
|
18
|
+
const meta = value['meta'];
|
|
19
|
+
if (!isRecord(meta))
|
|
20
|
+
return { changes: 0 };
|
|
21
|
+
const changes = typeof meta['changes'] === 'number' ? meta['changes'] : 0;
|
|
22
|
+
const lastRowId = meta['lastRowId'];
|
|
23
|
+
return { changes, lastRowId: lastRowId };
|
|
24
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlServerProxyAdapter.d.ts","sourceRoot":"","sources":["../../../../src/orm/adapters/SqlServerProxyAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqlServerProxyAdapter.d.ts","sourceRoot":"","sources":["../../../../src/orm/adapters/SqlServerProxyAdapter.ts"],"names":[],"mappings":"AACA;;GAEG;AAKH,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAwO1E,wBAAgB,2BAA2B,IAAI,gBAAgB,CAI9D"}
|
|
@@ -1,146 +1,154 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/require-await */
|
|
2
|
+
/**
|
|
3
|
+
* SQL Server Proxy Adapter (HTTP)
|
|
4
|
+
*/
|
|
1
5
|
import { Env } from '../../config/env.js';
|
|
2
|
-
import { Logger } from '../../config/logger.js';
|
|
3
6
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { AdaptersEnum } from '../../migrations/enum/index.js';
|
|
8
|
+
import { QueryBuilder } from '../QueryBuilder.js';
|
|
9
|
+
import { ensureSignedSettings, isRecord, requestSignedProxy, } from '../adapters/SqlProxyAdapterUtils.js';
|
|
10
|
+
import { createStatementPayload, getExecMetaWithLastRowId, resolveSqlProxyMode, } from '../adapters/SqlProxyRegistryMode.js';
|
|
11
|
+
const resolveProxyMode = () => {
|
|
12
|
+
return resolveSqlProxyMode('SQLSERVER_PROXY_MODE');
|
|
9
13
|
};
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
14
|
-
if (Date.now() - entry.timestamp > CACHE_TTL_MS) {
|
|
15
|
-
cache.delete(key);
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return entry.data;
|
|
19
|
-
};
|
|
20
|
-
const setCachedResult = (key, data) => {
|
|
21
|
-
cache.set(key, { data, timestamp: Date.now() });
|
|
22
|
-
};
|
|
23
|
-
const resolveProxyUrl = () => {
|
|
24
|
-
const url = Env.get('SQLSERVER_PROXY_URL', '');
|
|
25
|
-
if (typeof url === 'string' && url.trim() !== '')
|
|
26
|
-
return url;
|
|
14
|
+
const resolveBaseUrl = () => {
|
|
15
|
+
const explicit = Env.get('SQLSERVER_PROXY_URL', '').trim();
|
|
16
|
+
if (explicit !== '')
|
|
17
|
+
return explicit;
|
|
27
18
|
const host = Env.get('SQLSERVER_PROXY_HOST', '127.0.0.1');
|
|
28
19
|
const port = Env.getInt('SQLSERVER_PROXY_PORT', 8793);
|
|
29
20
|
return `http://${host}:${port}`;
|
|
30
21
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
missingCredentialsMessage: 'SQL Server proxy signing credentials are missing (SQLSERVER_PROXY_KEY_ID / SQLSERVER_PROXY_SECRET)',
|
|
38
|
-
});
|
|
22
|
+
const buildProxySettings = () => {
|
|
23
|
+
const baseUrl = resolveBaseUrl();
|
|
24
|
+
const keyId = Env.get('SQLSERVER_PROXY_KEY_ID', '');
|
|
25
|
+
const secret = Env.get('SQLSERVER_PROXY_SECRET', '');
|
|
26
|
+
const timeoutMs = Env.getInt('SQLSERVER_PROXY_TIMEOUT_MS', Env.ZT_PROXY_TIMEOUT_MS ?? 30000);
|
|
27
|
+
return { baseUrl, keyId, secret, timeoutMs };
|
|
39
28
|
};
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
const buildSignedProxyConfig = (settings) => ({
|
|
30
|
+
settings,
|
|
31
|
+
missingUrlMessage: 'SQL Server proxy URL is missing (SQLSERVER_PROXY_URL)',
|
|
32
|
+
missingCredentialsMessage: 'SQL Server proxy signing credentials are missing (SQLSERVER_PROXY_KEY_ID / SQLSERVER_PROXY_SECRET)',
|
|
33
|
+
messages: {
|
|
34
|
+
unauthorized: 'SQL Server proxy unauthorized',
|
|
35
|
+
forbidden: 'SQL Server proxy forbidden',
|
|
36
|
+
rateLimited: 'SQL Server proxy rate limited',
|
|
37
|
+
rejected: 'SQL Server proxy rejected request',
|
|
38
|
+
error: 'SQL Server proxy error',
|
|
39
|
+
timedOut: 'SQL Server proxy request timed out',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const isQueryResponse = (value) => isRecord(value) && Array.isArray(value['rows']) && typeof value['rowCount'] === 'number';
|
|
43
|
+
const isQueryOneResponse = (value) => isRecord(value) && 'row' in value;
|
|
44
|
+
const requestProxy = async (settings, path, payload) => requestSignedProxy(buildSignedProxyConfig(settings), path, payload);
|
|
45
|
+
const requireConnected = (state) => {
|
|
46
|
+
if (!state.connected)
|
|
47
|
+
throw ErrorFactory.createConnectionError('Database not connected');
|
|
48
|
+
};
|
|
49
|
+
const toQueryResult = (out) => {
|
|
50
|
+
if (isQueryResponse(out)) {
|
|
51
|
+
return { rows: out.rows, rowCount: out.rowCount };
|
|
52
|
+
}
|
|
53
|
+
if (isQueryOneResponse(out)) {
|
|
54
|
+
const row = out.row ?? null;
|
|
55
|
+
return { rows: row ? [row] : [], rowCount: row ? 1 : 0 };
|
|
56
|
+
}
|
|
57
|
+
const meta = getExecMetaWithLastRowId(out);
|
|
58
|
+
return { rows: [], rowCount: meta.changes, lastInsertId: meta.lastRowId };
|
|
59
|
+
};
|
|
60
|
+
const createQuery = (state) => async (sql, parameters) => {
|
|
61
|
+
requireConnected(state);
|
|
62
|
+
const mode = resolveProxyMode();
|
|
63
|
+
const out = mode === 'registry'
|
|
64
|
+
? await requestProxy(state.settings, '/zin/sqlserver/statement', await createStatementPayload(sql, parameters))
|
|
65
|
+
: await requestProxy(state.settings, '/zin/sqlserver/query', {
|
|
66
|
+
sql,
|
|
67
|
+
params: parameters,
|
|
54
68
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
return toQueryResult(out);
|
|
70
|
+
};
|
|
71
|
+
const createQueryOne = (state) => async (sql, parameters) => {
|
|
72
|
+
requireConnected(state);
|
|
73
|
+
const mode = resolveProxyMode();
|
|
74
|
+
if (mode !== 'registry') {
|
|
75
|
+
const out = await requestProxy(state.settings, '/zin/sqlserver/queryOne', {
|
|
76
|
+
sql,
|
|
77
|
+
params: parameters,
|
|
78
|
+
});
|
|
79
|
+
return out.row ?? null;
|
|
80
|
+
}
|
|
81
|
+
const out = await requestProxy(state.settings, '/zin/sqlserver/statement', await createStatementPayload(sql, parameters));
|
|
82
|
+
if (isQueryOneResponse(out))
|
|
83
|
+
return out.row ?? null;
|
|
84
|
+
if (isQueryResponse(out))
|
|
85
|
+
return out.rows[0] ?? null;
|
|
86
|
+
return null;
|
|
87
|
+
};
|
|
88
|
+
const createPing = (query) => async () => {
|
|
89
|
+
await query(QueryBuilder.create('').select('1').toSQL(), []);
|
|
90
|
+
};
|
|
91
|
+
const createTransaction = (state, getAdapter) => async (callback) => {
|
|
92
|
+
if (state.inTransaction) {
|
|
93
|
+
throw ErrorFactory.createGeneralError('Transaction already in progress');
|
|
94
|
+
}
|
|
95
|
+
requireConnected(state);
|
|
96
|
+
state.inTransaction = true;
|
|
97
|
+
try {
|
|
98
|
+
const adapter = getAdapter();
|
|
99
|
+
await adapter.query('BEGIN TRANSACTION', []);
|
|
100
|
+
const result = await callback(adapter);
|
|
101
|
+
await adapter.query('COMMIT', []);
|
|
61
102
|
return result;
|
|
62
103
|
}
|
|
63
104
|
catch (error) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
105
|
+
try {
|
|
106
|
+
await getAdapter().query('ROLLBACK', []);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
void 0;
|
|
67
110
|
}
|
|
68
111
|
throw error;
|
|
69
112
|
}
|
|
113
|
+
finally {
|
|
114
|
+
state.inTransaction = false;
|
|
115
|
+
}
|
|
70
116
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
117
|
+
const createRawQuery = (query) => async (sql, parameters) => {
|
|
118
|
+
const result = await query(sql, parameters ?? []);
|
|
119
|
+
return result.rows;
|
|
120
|
+
};
|
|
121
|
+
const createAdapter = (state) => {
|
|
122
|
+
const query = createQuery(state);
|
|
123
|
+
const queryOne = createQueryOne(state);
|
|
124
|
+
const adapter = {
|
|
76
125
|
async connect() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
connected = true;
|
|
126
|
+
ensureSignedSettings(buildSignedProxyConfig(state.settings));
|
|
127
|
+
state.connected = true;
|
|
80
128
|
},
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
82
129
|
async disconnect() {
|
|
83
|
-
connected = false;
|
|
84
|
-
inTransaction = false;
|
|
85
|
-
cache.clear();
|
|
86
|
-
Logger.info('Disconnected from SQL Server proxy');
|
|
87
|
-
},
|
|
88
|
-
async query(sql, parameters) {
|
|
89
|
-
if (!connected) {
|
|
90
|
-
throw ErrorFactory.createConnectionError('Not connected to SQL Server proxy');
|
|
91
|
-
}
|
|
92
|
-
if (sql.trim().toUpperCase().startsWith('SELECT')) {
|
|
93
|
-
const cacheKey = getCacheKey(sql, parameters);
|
|
94
|
-
const cached = getCachedResult(cacheKey);
|
|
95
|
-
if (cached)
|
|
96
|
-
return cached;
|
|
97
|
-
const result = await sendQuery(sql, parameters);
|
|
98
|
-
setCachedResult(cacheKey, result);
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
return sendQuery(sql, parameters);
|
|
102
|
-
},
|
|
103
|
-
async queryOne(sql, parameters) {
|
|
104
|
-
const result = await this.query(sql, parameters);
|
|
105
|
-
return result.rows[0] ?? null;
|
|
106
|
-
},
|
|
107
|
-
async ping() {
|
|
108
|
-
if (!connected) {
|
|
109
|
-
throw ErrorFactory.createConnectionError('Not connected to SQL Server proxy');
|
|
110
|
-
}
|
|
111
|
-
await this.query('SELECT 1 AS ping', []);
|
|
112
|
-
},
|
|
113
|
-
async transaction(callback) {
|
|
114
|
-
if (inTransaction) {
|
|
115
|
-
throw ErrorFactory.createGeneralError('Transaction already in progress');
|
|
116
|
-
}
|
|
117
|
-
inTransaction = true;
|
|
118
|
-
try {
|
|
119
|
-
await this.query('BEGIN TRANSACTION', []);
|
|
120
|
-
const result = await callback(this);
|
|
121
|
-
await this.query('COMMIT', []);
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
await this.query('ROLLBACK', []);
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
finally {
|
|
129
|
-
inTransaction = false;
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
async rawQuery(sql, parameters) {
|
|
133
|
-
const result = await this.query(sql, parameters ?? []);
|
|
134
|
-
return result.rows;
|
|
130
|
+
state.connected = false;
|
|
131
|
+
state.inTransaction = false;
|
|
135
132
|
},
|
|
133
|
+
query,
|
|
134
|
+
queryOne,
|
|
135
|
+
ping: createPing(query),
|
|
136
|
+
transaction: createTransaction(state, () => adapter),
|
|
137
|
+
rawQuery: createRawQuery(query),
|
|
136
138
|
getType() {
|
|
137
|
-
return
|
|
139
|
+
return AdaptersEnum.sqlserver;
|
|
138
140
|
},
|
|
139
141
|
isConnected() {
|
|
140
|
-
return connected;
|
|
142
|
+
return state.connected;
|
|
141
143
|
},
|
|
142
144
|
getPlaceholder(index) {
|
|
143
145
|
return `@param${index}`;
|
|
144
146
|
},
|
|
145
147
|
};
|
|
148
|
+
return adapter;
|
|
149
|
+
};
|
|
150
|
+
export function createSqlServerProxyAdapter() {
|
|
151
|
+
const settings = buildProxySettings();
|
|
152
|
+
const state = { connected: false, inTransaction: false, settings };
|
|
153
|
+
return createAdapter(state);
|
|
146
154
|
}
|
|
@@ -12,7 +12,7 @@ const toSafeService = (service) => {
|
|
|
12
12
|
};
|
|
13
13
|
const assertDbSupportsMigrations = (db) => {
|
|
14
14
|
const t = db.getType();
|
|
15
|
-
if (t === 'd1'
|
|
15
|
+
if (t === 'd1') {
|
|
16
16
|
throw ErrorFactory.createCliError('This project is configured for D1. Use `zin d1:migrate --local|--remote` for now.');
|
|
17
17
|
}
|
|
18
18
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProxyResponse } from './ProxyBackend';
|
|
2
|
+
export declare const validateProxyRequest: (request: {
|
|
3
|
+
method: string;
|
|
4
|
+
}) => ProxyResponse | null;
|
|
5
|
+
export declare const parseJsonBody: (body: string) => {
|
|
6
|
+
ok: true;
|
|
7
|
+
value: Record<string, unknown>;
|
|
8
|
+
} | ProxyResponse;
|
|
9
|
+
//# sourceMappingURL=ProxyRequestParsing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyRequestParsing.d.ts","sourceRoot":"","sources":["../../../src/proxy/ProxyRequestParsing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,eAAO,MAAM,oBAAoB,GAAI,SAAS;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,KAAG,aAAa,GAAG,IAMlF,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,MAAM,MAAM,KACX;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,aAMjD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ErrorHandler } from './ErrorHandler.js';
|
|
2
|
+
import { RequestValidator } from './RequestValidator.js';
|
|
3
|
+
export const validateProxyRequest = (request) => {
|
|
4
|
+
const methodError = RequestValidator.requirePost(request.method);
|
|
5
|
+
if (methodError) {
|
|
6
|
+
return ErrorHandler.toProxyError(405, methodError.code, methodError.message);
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
};
|
|
10
|
+
export const parseJsonBody = (body) => {
|
|
11
|
+
const parsed = RequestValidator.parseJson(body);
|
|
12
|
+
if (!parsed.ok) {
|
|
13
|
+
return ErrorHandler.toProxyError(400, parsed.error.code, parsed.error.message);
|
|
14
|
+
}
|
|
15
|
+
return { ok: true, value: parsed.value };
|
|
16
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestValidator.d.ts","sourceRoot":"","sources":["../../../src/proxy/RequestValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RequestValidator.d.ts","sourceRoot":"","sources":["../../../src/proxy/RequestValidator.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AA2B1E,eAAO,MAAM,gBAAgB;sBAtBrB,MAAM,KACX;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,eAAe,CAAA;KAAE;0BAgB1D,MAAM,GAAG,SAAS,KAAG,eAAe,GAAG,IAAI;EAQtE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { isObject } from '../helper/index.js';
|
|
2
|
+
const isRecord = (value) => isObject(value);
|
|
2
3
|
const parseJson = (body) => {
|
|
3
4
|
if (body.trim() === '') {
|
|
4
5
|
return { ok: false, error: { code: 'VALIDATION_ERROR', message: 'Body is required' } };
|
|
@@ -16,7 +16,7 @@ const normalizeKeyId = (keyId) => {
|
|
|
16
16
|
const trimmed = keyId.trim();
|
|
17
17
|
if (trimmed !== '')
|
|
18
18
|
return trimmed.toLowerCase();
|
|
19
|
-
const appNameRaw = Env.APP_NAME
|
|
19
|
+
const appNameRaw = Env.get('APP_NAME', 'zintrust');
|
|
20
20
|
const normalized = (appNameRaw.trim() === '' ? 'zintrust' : appNameRaw)
|
|
21
21
|
.toLowerCase()
|
|
22
22
|
.replaceAll(/\s+/g, '_');
|
|
@@ -26,7 +26,7 @@ const normalizeSecret = (secret) => {
|
|
|
26
26
|
const trimmed = secret.trim();
|
|
27
27
|
if (trimmed !== '')
|
|
28
28
|
return trimmed;
|
|
29
|
-
return Env.APP_KEY
|
|
29
|
+
return Env.get('APP_KEY', '');
|
|
30
30
|
};
|
|
31
31
|
const normalizeConfig = (signing) => ({
|
|
32
32
|
...signing,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type SqlProxyDatabaseOverrides = Partial<{
|
|
2
|
+
dbHost: string;
|
|
3
|
+
dbPort: number;
|
|
4
|
+
dbName: string;
|
|
5
|
+
dbUser: string;
|
|
6
|
+
dbPass: string;
|
|
7
|
+
connectionLimit: number;
|
|
8
|
+
}>;
|
|
9
|
+
export type SqlProxyDatabaseConfig = Readonly<{
|
|
10
|
+
dbHost: string;
|
|
11
|
+
dbPort: number;
|
|
12
|
+
dbName: string;
|
|
13
|
+
dbUser: string;
|
|
14
|
+
dbPass: string;
|
|
15
|
+
connectionLimit: number;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=SqlProxyDbOverrides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlProxyDbOverrides.d.ts","sourceRoot":"","sources":["../../../src/proxy/SqlProxyDbOverrides.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Env } from '../config/env';
|
|
2
|
+
export { Logger } from '../config/logger';
|
|
3
|
+
export { ErrorHandler } from './ErrorHandler';
|
|
4
|
+
export type { ProxyBackend, ProxyResponse } from './ProxyBackend';
|
|
5
|
+
export type { ProxySigningConfig } from './ProxyConfig';
|
|
6
|
+
export { parseJsonBody, validateProxyRequest } from './ProxyRequestParsing';
|
|
7
|
+
export { createProxyServer } from './ProxyServer';
|
|
8
|
+
export { resolveBaseConfig, resolveBaseSigningConfig, verifyRequestSignature, type BaseProxyOverrides, } from './ProxyServerUtils';
|
|
9
|
+
export { validateSqlPayload } from './SqlPayloadValidator';
|
|
10
|
+
export { loadStatementRegistry } from './StatementRegistryLoader';
|
|
11
|
+
export { resolveStatementOrError } from './StatementRegistryResolver';
|
|
12
|
+
//# sourceMappingURL=SqlProxyServerDeps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SqlProxyServerDeps.d.ts","sourceRoot":"","sources":["../../../src/proxy/SqlProxyServerDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Env } from '../config/env.js';
|
|
2
|
+
export { Logger } from '../config/logger.js';
|
|
3
|
+
export { ErrorHandler } from './ErrorHandler.js';
|
|
4
|
+
export { parseJsonBody, validateProxyRequest } from './ProxyRequestParsing.js';
|
|
5
|
+
export { createProxyServer } from './ProxyServer.js';
|
|
6
|
+
export { resolveBaseConfig, resolveBaseSigningConfig, verifyRequestSignature, } from './ProxyServerUtils.js';
|
|
7
|
+
export { validateSqlPayload } from './SqlPayloadValidator.js';
|
|
8
|
+
export { loadStatementRegistry } from './StatementRegistryLoader.js';
|
|
9
|
+
export { resolveStatementOrError } from './StatementRegistryResolver.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type StatementPayloadValidation = {
|
|
2
|
+
valid: true;
|
|
3
|
+
statementId: string;
|
|
4
|
+
params: unknown[];
|
|
5
|
+
} | {
|
|
6
|
+
valid: false;
|
|
7
|
+
error: {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const validateStatementPayload: (payload: Record<string, unknown>) => StatementPayloadValidation;
|
|
13
|
+
//# sourceMappingURL=StatementPayloadValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatementPayloadValidator.d.ts","sourceRoot":"","sources":["../../../src/proxy/StatementPayloadValidator.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAClC;IACE,KAAK,EAAE,IAAI,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB,GACD;IACE,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C,CAAC;AAEN,eAAO,MAAM,wBAAwB,GACnC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,0BAoBF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const validateStatementPayload = (payload) => {
|
|
2
|
+
const statementId = payload['statementId'];
|
|
3
|
+
const params = Array.isArray(payload['params']) ? payload['params'] : [];
|
|
4
|
+
if (typeof statementId !== 'string') {
|
|
5
|
+
return {
|
|
6
|
+
valid: false,
|
|
7
|
+
error: { code: 'VALIDATION_ERROR', message: 'statementId must be a string' },
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const trimmed = statementId.trim();
|
|
11
|
+
if (trimmed === '') {
|
|
12
|
+
return {
|
|
13
|
+
valid: false,
|
|
14
|
+
error: { code: 'VALIDATION_ERROR', message: 'statementId is required' },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return { valid: true, statementId: trimmed, params };
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatementRegistryLoader.d.ts","sourceRoot":"","sources":["../../../src/proxy/StatementRegistryLoader.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,qBAAqB,GAChC,QAAQ,OAAO,GAAG,UAAU,GAAG,WAAW,KACzC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAqB3B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Env } from '../config/env.js';
|
|
2
|
+
import { isObject } from '../helper/index.js';
|
|
3
|
+
import fs from '../node-singletons/fs.js';
|
|
4
|
+
const isRecord = (value) => isObject(value);
|
|
5
|
+
const parseStatements = (input) => {
|
|
6
|
+
if (!isRecord(input))
|
|
7
|
+
return undefined;
|
|
8
|
+
const out = {};
|
|
9
|
+
for (const [key, value] of Object.entries(input)) {
|
|
10
|
+
if (typeof value === 'string')
|
|
11
|
+
out[key] = value;
|
|
12
|
+
}
|
|
13
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
14
|
+
};
|
|
15
|
+
export const loadStatementRegistry = (prefix) => {
|
|
16
|
+
const file = Env.get(`ZT_${prefix}_STATEMENTS_FILE`, '').trim();
|
|
17
|
+
if (file !== '') {
|
|
18
|
+
try {
|
|
19
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
20
|
+
return parseStatements(JSON.parse(text));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const json = Env.get(`ZT_${prefix}_STATEMENTS_JSON`, '').trim();
|
|
27
|
+
if (json !== '') {
|
|
28
|
+
try {
|
|
29
|
+
return parseStatements(JSON.parse(json));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProxyResponse } from './ProxyBackend';
|
|
2
|
+
export type ResolvedStatement = Readonly<{
|
|
3
|
+
statementId: string;
|
|
4
|
+
sql: string;
|
|
5
|
+
params: unknown[];
|
|
6
|
+
mutating: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const resolveStatementOrError: (statements: Record<string, string> | undefined, payload: Record<string, unknown>) => {
|
|
9
|
+
ok: true;
|
|
10
|
+
value: ResolvedStatement;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
response: ProxyResponse;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=StatementRegistryResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatementRegistryResolver.d.ts","sourceRoot":"","sources":["../../../src/proxy/StatementRegistryResolver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC,CAAC;AAEH,eAAO,MAAM,uBAAuB,GAClC,YAAY,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC9C,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAqC/E,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ErrorHandler } from './ErrorHandler.js';
|
|
2
|
+
import { validateStatementPayload } from './StatementPayloadValidator.js';
|
|
3
|
+
import { isMutatingSql } from './isMutatingSql.js';
|
|
4
|
+
export const resolveStatementOrError = (statements, payload) => {
|
|
5
|
+
if (!statements) {
|
|
6
|
+
return {
|
|
7
|
+
ok: false,
|
|
8
|
+
response: ErrorHandler.toProxyError(400, 'CONFIG_ERROR', 'Missing statement registry'),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const stmtValidation = validateStatementPayload(payload);
|
|
12
|
+
if (!stmtValidation.valid) {
|
|
13
|
+
return {
|
|
14
|
+
ok: false,
|
|
15
|
+
response: ErrorHandler.toProxyError(400, stmtValidation.error.code, stmtValidation.error.message),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const sql = statements[stmtValidation.statementId];
|
|
19
|
+
if (typeof sql !== 'string' || sql.trim() === '') {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
response: ErrorHandler.toProxyError(404, 'NOT_FOUND', 'Unknown statementId'),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
ok: true,
|
|
27
|
+
value: {
|
|
28
|
+
statementId: stmtValidation.statementId,
|
|
29
|
+
sql,
|
|
30
|
+
params: stmtValidation.params,
|
|
31
|
+
mutating: isMutatingSql(sql),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ZintrustD1Proxy } from '../../../packages/cloudflare-d1-proxy/src/index.js';
|
|
2
|
+
export { default } from '../../../packages/cloudflare-d1-proxy/src/index.js';
|
|
2
3
|
//# sourceMappingURL=ZintrustD1Proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZintrustD1Proxy.d.ts","sourceRoot":"","sources":["../../../../src/proxy/d1/ZintrustD1Proxy.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ZintrustD1Proxy.d.ts","sourceRoot":"","sources":["../../../../src/proxy/d1/ZintrustD1Proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ZintrustD1Proxy } from '../../../packages/cloudflare-d1-proxy/src/index.js';
|
|
2
|
+
export { default } from '../../../packages/cloudflare-d1-proxy/src/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMutatingSql.d.ts","sourceRoot":"","sources":["../../../src/proxy/isMutatingSql.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,OAa3C,CAAC"}
|