integrate-sdk 0.9.55 → 0.9.58
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/dist/adapters/index.js +2440 -31
- package/dist/adapters/solid-start.js +2440 -31
- package/dist/adapters/svelte-kit.js +2440 -31
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +11 -2
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +11 -2
- package/dist/ai/index.js +16 -7
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +11 -2
- package/dist/ai/utils.d.ts +21 -0
- package/dist/ai/utils.d.ts.map +1 -1
- package/dist/ai/utils.js +10 -0
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +10 -1
- package/dist/database/adapters/drizzle.d.ts +23 -0
- package/dist/database/adapters/drizzle.d.ts.map +1 -0
- package/dist/database/adapters/drizzle.js +646 -0
- package/dist/database/adapters/mongodb.d.ts +17 -0
- package/dist/database/adapters/mongodb.d.ts.map +1 -0
- package/dist/database/adapters/mongodb.js +643 -0
- package/dist/database/adapters/prisma.d.ts +18 -0
- package/dist/database/adapters/prisma.d.ts.map +1 -0
- package/dist/database/adapters/prisma.js +679 -0
- package/dist/database/index.d.ts +9 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +1167 -0
- package/dist/index.js +77 -31
- package/dist/integrations.js +77 -31
- package/dist/server.js +3633 -42
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/utils.d.ts +21 -0
- package/dist/src/ai/utils.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/client.d.ts +4 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +44 -1
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/database/adapters/drizzle.d.ts +23 -0
- package/dist/src/database/adapters/drizzle.d.ts.map +1 -0
- package/dist/src/database/adapters/mongodb.d.ts +17 -0
- package/dist/src/database/adapters/mongodb.d.ts.map +1 -0
- package/dist/src/database/adapters/prisma.d.ts +18 -0
- package/dist/src/database/adapters/prisma.d.ts.map +1 -0
- package/dist/src/database/factory.d.ts +9 -0
- package/dist/src/database/factory.d.ts.map +1 -0
- package/dist/src/database/index.d.ts +9 -0
- package/dist/src/database/index.d.ts.map +1 -0
- package/dist/src/database/schemas/drizzle.d.ts +508 -0
- package/dist/src/database/schemas/drizzle.d.ts.map +1 -0
- package/dist/src/database/token-store.d.ts +28 -0
- package/dist/src/database/token-store.d.ts.map +1 -0
- package/dist/src/database/trigger-store.d.ts +23 -0
- package/dist/src/database/trigger-store.d.ts.map +1 -0
- package/dist/src/database/types.d.ts +132 -0
- package/dist/src/database/types.d.ts.map +1 -0
- package/dist/src/integrations/integration-docs-metadata.d.ts +40 -0
- package/dist/src/integrations/integration-docs-metadata.d.ts.map +1 -0
- package/dist/src/server.d.ts +4 -3
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +32 -5
package/dist/server.js
CHANGED
|
@@ -3449,6 +3449,169 @@ class HttpSessionTransport {
|
|
|
3449
3449
|
// src/client.ts
|
|
3450
3450
|
init_integration_summary();
|
|
3451
3451
|
init_library_metadata();
|
|
3452
|
+
|
|
3453
|
+
// src/database/token-store.ts
|
|
3454
|
+
var USABLE_ACCESS_TOKEN_BUFFER_MS = 30 * 1000;
|
|
3455
|
+
var MIN_MEANINGFUL_EXPIRY_MS = Date.UTC(2000, 0, 1);
|
|
3456
|
+
function getRowUpdatedAtMs(row) {
|
|
3457
|
+
return row.updatedAt instanceof Date ? row.updatedAt.getTime() : 0;
|
|
3458
|
+
}
|
|
3459
|
+
function normalizeAccountEmail(value) {
|
|
3460
|
+
if (!value)
|
|
3461
|
+
return null;
|
|
3462
|
+
const normalized = value.trim().toLowerCase();
|
|
3463
|
+
return normalized.length > 0 ? normalized : null;
|
|
3464
|
+
}
|
|
3465
|
+
function normalizeAccountEmailHint(value) {
|
|
3466
|
+
const normalized = normalizeAccountEmail(value);
|
|
3467
|
+
if (!normalized)
|
|
3468
|
+
return null;
|
|
3469
|
+
return normalized.includes("@") ? normalized : null;
|
|
3470
|
+
}
|
|
3471
|
+
function normalizeAccountIdentifier(value) {
|
|
3472
|
+
return normalizeAccountEmail(value);
|
|
3473
|
+
}
|
|
3474
|
+
function normalizeAccountIdHint(value) {
|
|
3475
|
+
if (!value)
|
|
3476
|
+
return null;
|
|
3477
|
+
const normalized = value.trim().toLowerCase();
|
|
3478
|
+
return normalized.length > 0 ? normalized : null;
|
|
3479
|
+
}
|
|
3480
|
+
function normalizeProviderTokenType(value) {
|
|
3481
|
+
const normalized = value?.trim();
|
|
3482
|
+
return normalized && normalized.length > 0 ? normalized : "Bearer";
|
|
3483
|
+
}
|
|
3484
|
+
function hasMeaningfulExpiresAt(value) {
|
|
3485
|
+
if (!value)
|
|
3486
|
+
return false;
|
|
3487
|
+
const ms = value.getTime();
|
|
3488
|
+
return Number.isFinite(ms) && ms >= MIN_MEANINGFUL_EXPIRY_MS;
|
|
3489
|
+
}
|
|
3490
|
+
function hasUsableAccessToken(row, now = Date.now(), bufferMs = USABLE_ACCESS_TOKEN_BUFFER_MS) {
|
|
3491
|
+
if (!row.accessToken)
|
|
3492
|
+
return false;
|
|
3493
|
+
const expiresAt = row.expiresAt;
|
|
3494
|
+
if (!hasMeaningfulExpiresAt(expiresAt))
|
|
3495
|
+
return true;
|
|
3496
|
+
return expiresAt.getTime() > now + bufferMs;
|
|
3497
|
+
}
|
|
3498
|
+
function isLikelyUsableToken(row, now = Date.now()) {
|
|
3499
|
+
return hasUsableAccessToken(row, now) || Boolean(row.refreshToken);
|
|
3500
|
+
}
|
|
3501
|
+
function parseScopes(scope) {
|
|
3502
|
+
if (!scope)
|
|
3503
|
+
return;
|
|
3504
|
+
const scopes = scope.split(" ").map((item) => item.trim()).filter((item) => item.length > 0);
|
|
3505
|
+
return scopes.length > 0 ? scopes : undefined;
|
|
3506
|
+
}
|
|
3507
|
+
function choosePreferredTokenRow(rows) {
|
|
3508
|
+
if (rows.length === 0)
|
|
3509
|
+
return;
|
|
3510
|
+
const sorted = [...rows].sort((left, right) => getRowUpdatedAtMs(right) - getRowUpdatedAtMs(left));
|
|
3511
|
+
return sorted.find((row) => hasUsableAccessToken(row)) ?? sorted.find((row) => Boolean(row.refreshToken)) ?? sorted[0];
|
|
3512
|
+
}
|
|
3513
|
+
function selectProviderTokenRow(rows, email, accountId) {
|
|
3514
|
+
if (rows.length === 0) {
|
|
3515
|
+
return;
|
|
3516
|
+
}
|
|
3517
|
+
const normalizedEmail = normalizeAccountEmailHint(email);
|
|
3518
|
+
const normalizedAccountId = normalizeAccountIdHint(accountId);
|
|
3519
|
+
if (normalizedAccountId && normalizedEmail) {
|
|
3520
|
+
const exactBoth = rows.filter((row) => normalizeAccountIdHint(row.accountId) === normalizedAccountId && normalizeAccountEmail(row.accountEmail) === normalizedEmail);
|
|
3521
|
+
if (exactBoth.length > 0) {
|
|
3522
|
+
return choosePreferredTokenRow(exactBoth);
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
if (normalizedAccountId) {
|
|
3526
|
+
const exactAccountId = rows.filter((row) => normalizeAccountIdHint(row.accountId) === normalizedAccountId);
|
|
3527
|
+
if (exactAccountId.length > 0) {
|
|
3528
|
+
return choosePreferredTokenRow(exactAccountId);
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
if (normalizedEmail) {
|
|
3532
|
+
const exactEmail = rows.filter((row) => normalizeAccountEmail(row.accountEmail) === normalizedEmail);
|
|
3533
|
+
if (exactEmail.length > 0) {
|
|
3534
|
+
return choosePreferredTokenRow(exactEmail);
|
|
3535
|
+
}
|
|
3536
|
+
} else if (email) {
|
|
3537
|
+
const normalizedIdentifier = normalizeAccountIdentifier(email);
|
|
3538
|
+
if (normalizedIdentifier) {
|
|
3539
|
+
const identifierMatches = rows.filter((row) => normalizeAccountIdHint(row.accountId) === normalizedIdentifier);
|
|
3540
|
+
if (identifierMatches.length > 0) {
|
|
3541
|
+
return choosePreferredTokenRow(identifierMatches);
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
if (normalizedAccountId || normalizedEmail) {
|
|
3546
|
+
const legacyRows = rows.filter((row) => !normalizeAccountIdHint(row.accountId) && !normalizeAccountEmail(row.accountEmail));
|
|
3547
|
+
if (legacyRows.length === 1) {
|
|
3548
|
+
return choosePreferredTokenRow(legacyRows);
|
|
3549
|
+
}
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
return choosePreferredTokenRow(rows);
|
|
3553
|
+
}
|
|
3554
|
+
function providerTokenRecordToData(row) {
|
|
3555
|
+
const expiresAt = hasMeaningfulExpiresAt(row.expiresAt) ? row.expiresAt : null;
|
|
3556
|
+
const expiresIn = expiresAt ? Math.max(0, Math.floor((expiresAt.getTime() - Date.now()) / 1000)) : 3600;
|
|
3557
|
+
return {
|
|
3558
|
+
accessToken: row.accessToken,
|
|
3559
|
+
refreshToken: row.refreshToken ?? undefined,
|
|
3560
|
+
tokenType: normalizeProviderTokenType(row.tokenType),
|
|
3561
|
+
expiresIn,
|
|
3562
|
+
expiresAt: expiresAt?.toISOString(),
|
|
3563
|
+
scopes: parseScopes(row.scope),
|
|
3564
|
+
email: row.accountEmail ?? undefined,
|
|
3565
|
+
accountId: row.accountId ?? undefined
|
|
3566
|
+
};
|
|
3567
|
+
}
|
|
3568
|
+
function listConnectedProvidersFromRows(rows, configuredIntegrationIds) {
|
|
3569
|
+
const allowed = configuredIntegrationIds ? new Set(configuredIntegrationIds) : undefined;
|
|
3570
|
+
const rowsByProvider = new Map;
|
|
3571
|
+
for (const row of rows) {
|
|
3572
|
+
if (allowed && !allowed.has(row.provider))
|
|
3573
|
+
continue;
|
|
3574
|
+
const existing = rowsByProvider.get(row.provider);
|
|
3575
|
+
if (existing) {
|
|
3576
|
+
existing.push(row);
|
|
3577
|
+
} else {
|
|
3578
|
+
rowsByProvider.set(row.provider, [row]);
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
const connected = [];
|
|
3582
|
+
for (const [provider, providerRows] of rowsByProvider.entries()) {
|
|
3583
|
+
const selected = selectProviderTokenRow(providerRows);
|
|
3584
|
+
if (selected && isLikelyUsableToken(selected)) {
|
|
3585
|
+
connected.push(provider);
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
return connected.sort();
|
|
3589
|
+
}
|
|
3590
|
+
async function listConnectedProviders(configuredIntegrationIds, getProviderToken, context) {
|
|
3591
|
+
if (!context.userId || configuredIntegrationIds.length === 0) {
|
|
3592
|
+
return [];
|
|
3593
|
+
}
|
|
3594
|
+
const connected = [];
|
|
3595
|
+
await Promise.all(configuredIntegrationIds.map(async (provider) => {
|
|
3596
|
+
try {
|
|
3597
|
+
const token = await getProviderToken(provider, undefined, context);
|
|
3598
|
+
if (token?.accessToken || typeof token?.refreshToken === "string" && token.refreshToken.length > 0) {
|
|
3599
|
+
connected.push(provider);
|
|
3600
|
+
}
|
|
3601
|
+
} catch {}
|
|
3602
|
+
}));
|
|
3603
|
+
return connected.sort();
|
|
3604
|
+
}
|
|
3605
|
+
function defaultResolveAccountIdentity(provider, tokenData, emailHint) {
|
|
3606
|
+
const accountEmail = normalizeAccountEmail(emailHint ?? tokenData.email ?? null);
|
|
3607
|
+
let accountId = normalizeAccountIdHint(tokenData.accountId ?? null);
|
|
3608
|
+
if (!accountId && accountEmail) {
|
|
3609
|
+
accountId = `${provider}:${accountEmail}`;
|
|
3610
|
+
}
|
|
3611
|
+
return { accountEmail, accountId };
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
// src/client.ts
|
|
3452
3615
|
init_errors();
|
|
3453
3616
|
init_logger();
|
|
3454
3617
|
|
|
@@ -5314,20 +5477,32 @@ class MCPClientBase {
|
|
|
5314
5477
|
getEnabledTools() {
|
|
5315
5478
|
return Array.from(this.availableTools.values()).filter((tool) => this.enabledToolNames.has(tool.name));
|
|
5316
5479
|
}
|
|
5317
|
-
async getEnabledToolsAsync() {
|
|
5318
|
-
|
|
5319
|
-
|
|
5480
|
+
async getEnabledToolsAsync(options) {
|
|
5481
|
+
const targetIntegrationIds = await this.resolveTargetIntegrationIds(options);
|
|
5482
|
+
if (targetIntegrationIds.size === 0) {
|
|
5483
|
+
return [];
|
|
5320
5484
|
}
|
|
5321
|
-
|
|
5322
|
-
|
|
5485
|
+
const filterToTargets = (tools2) => this.filterToolsToIntegrations(tools2, targetIntegrationIds);
|
|
5486
|
+
const hasCompleteCache = () => {
|
|
5487
|
+
for (const integration of this.integrations) {
|
|
5488
|
+
if (!targetIntegrationIds.has(integration.id))
|
|
5489
|
+
continue;
|
|
5490
|
+
for (const toolName of integration.tools) {
|
|
5491
|
+
if (!this.enabledToolNames.has(toolName))
|
|
5492
|
+
continue;
|
|
5493
|
+
if (!this.availableTools.has(toolName))
|
|
5494
|
+
return false;
|
|
5495
|
+
}
|
|
5496
|
+
}
|
|
5497
|
+
return this.availableTools.size > 0;
|
|
5498
|
+
};
|
|
5499
|
+
if (this.availableTools.size > 0 && hasCompleteCache()) {
|
|
5500
|
+
return filterToTargets(this.getEnabledTools());
|
|
5323
5501
|
}
|
|
5324
5502
|
const tools = [];
|
|
5325
|
-
const integrationIds = new Set;
|
|
5326
|
-
for (const integration of this.integrations) {
|
|
5327
|
-
integrationIds.add(integration.id);
|
|
5328
|
-
}
|
|
5329
5503
|
const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
|
|
5330
|
-
const
|
|
5504
|
+
const concurrency = options?.fetchConcurrency ?? 8;
|
|
5505
|
+
const integrationToolsResults = await parallelWithLimit2(Array.from(targetIntegrationIds), async (integrationId) => {
|
|
5331
5506
|
try {
|
|
5332
5507
|
const response = await this.callServerToolInternal("list_tools_by_integration", {
|
|
5333
5508
|
integration: integrationId
|
|
@@ -5338,25 +5513,14 @@ class MCPClientBase {
|
|
|
5338
5513
|
if (item.type === "text" && item.text) {
|
|
5339
5514
|
try {
|
|
5340
5515
|
const parsed = JSON.parse(item.text);
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
}
|
|
5350
|
-
}
|
|
5351
|
-
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
5352
|
-
for (const tool of parsed.tools) {
|
|
5353
|
-
if (tool.name && tool.inputSchema) {
|
|
5354
|
-
integrationTools.push({
|
|
5355
|
-
name: tool.name,
|
|
5356
|
-
description: tool.description,
|
|
5357
|
-
inputSchema: tool.inputSchema
|
|
5358
|
-
});
|
|
5359
|
-
}
|
|
5516
|
+
const parsedTools = Array.isArray(parsed) ? parsed : parsed.tools && Array.isArray(parsed.tools) ? parsed.tools : [];
|
|
5517
|
+
for (const tool of parsedTools) {
|
|
5518
|
+
if (tool.name && tool.inputSchema) {
|
|
5519
|
+
integrationTools.push({
|
|
5520
|
+
name: tool.name,
|
|
5521
|
+
description: tool.description,
|
|
5522
|
+
inputSchema: tool.inputSchema
|
|
5523
|
+
});
|
|
5360
5524
|
}
|
|
5361
5525
|
}
|
|
5362
5526
|
} catch {}
|
|
@@ -5368,14 +5532,40 @@ class MCPClientBase {
|
|
|
5368
5532
|
logger5.error(`Failed to fetch tools for integration ${integrationId}:`, error);
|
|
5369
5533
|
return [];
|
|
5370
5534
|
}
|
|
5371
|
-
},
|
|
5535
|
+
}, concurrency);
|
|
5372
5536
|
for (const integrationTools of integrationToolsResults) {
|
|
5373
5537
|
tools.push(...integrationTools);
|
|
5374
5538
|
}
|
|
5375
5539
|
for (const tool of tools) {
|
|
5376
5540
|
this.availableTools.set(tool.name, tool);
|
|
5377
5541
|
}
|
|
5378
|
-
return tools.filter((tool) => this.enabledToolNames.has(tool.name));
|
|
5542
|
+
return filterToTargets(tools.filter((tool) => this.enabledToolNames.has(tool.name)));
|
|
5543
|
+
}
|
|
5544
|
+
async resolveTargetIntegrationIds(options) {
|
|
5545
|
+
const configuredIds = this.integrations.map((integration) => integration.id);
|
|
5546
|
+
const configuredSet = new Set(configuredIds);
|
|
5547
|
+
if (options?.integrationIds && options.integrationIds.length > 0) {
|
|
5548
|
+
return new Set(options.integrationIds.filter((id) => configuredSet.has(id)));
|
|
5549
|
+
}
|
|
5550
|
+
if (options?.connectedOnly && options.context?.userId) {
|
|
5551
|
+
const connected = await listConnectedProviders(configuredIds, (provider, email, context) => this.oauthManager.getProviderToken(provider, email, context), options.context);
|
|
5552
|
+
return new Set(connected);
|
|
5553
|
+
}
|
|
5554
|
+
return configuredSet;
|
|
5555
|
+
}
|
|
5556
|
+
filterToolsToIntegrations(tools, integrationIds) {
|
|
5557
|
+
if (integrationIds.size === 0) {
|
|
5558
|
+
return [];
|
|
5559
|
+
}
|
|
5560
|
+
const allowedNames = new Set;
|
|
5561
|
+
for (const integration of this.integrations) {
|
|
5562
|
+
if (!integrationIds.has(integration.id))
|
|
5563
|
+
continue;
|
|
5564
|
+
for (const toolName of integration.tools) {
|
|
5565
|
+
allowedNames.add(toolName);
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
return tools.filter((tool) => this.enabledToolNames.has(tool.name) && allowedNames.has(tool.name));
|
|
5379
5569
|
}
|
|
5380
5570
|
getOAuthConfig(integrationId) {
|
|
5381
5571
|
const integration = this.integrations.find((p) => p.id === integrationId);
|
|
@@ -18330,6 +18520,15 @@ var coerce = {
|
|
|
18330
18520
|
};
|
|
18331
18521
|
var NEVER = INVALID;
|
|
18332
18522
|
// src/ai/utils.ts
|
|
18523
|
+
function toEnabledToolsAsyncOptions(options) {
|
|
18524
|
+
if (!options)
|
|
18525
|
+
return;
|
|
18526
|
+
const { integrationIds, connectedOnly, context, fetchConcurrency } = options;
|
|
18527
|
+
if (integrationIds === undefined && connectedOnly === undefined && context === undefined && fetchConcurrency === undefined) {
|
|
18528
|
+
return;
|
|
18529
|
+
}
|
|
18530
|
+
return { integrationIds, connectedOnly, context, fetchConcurrency };
|
|
18531
|
+
}
|
|
18333
18532
|
function getProviderForTool(client, toolName) {
|
|
18334
18533
|
return client.getProviderForTool?.(toolName);
|
|
18335
18534
|
}
|
|
@@ -18656,7 +18855,7 @@ async function getVercelAITools(client, options) {
|
|
|
18656
18855
|
}
|
|
18657
18856
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
18658
18857
|
await ensureClientConnected(client);
|
|
18659
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
18858
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
18660
18859
|
const vercelTools = {};
|
|
18661
18860
|
let effectiveMode;
|
|
18662
18861
|
if (options?.mode !== undefined) {
|
|
@@ -19962,7 +20161,7 @@ async function getOpenAITools(client, options) {
|
|
|
19962
20161
|
}
|
|
19963
20162
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
19964
20163
|
await ensureClientConnected(client);
|
|
19965
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20164
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
19966
20165
|
let effectiveMode;
|
|
19967
20166
|
if (options?.mode !== undefined) {
|
|
19968
20167
|
effectiveMode = options.mode;
|
|
@@ -20024,7 +20223,7 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
20024
20223
|
const getCodeModeTool = async () => {
|
|
20025
20224
|
if (cachedCodeModeTool)
|
|
20026
20225
|
return cachedCodeModeTool;
|
|
20027
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20226
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20028
20227
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
20029
20228
|
tools: mcpTools,
|
|
20030
20229
|
providerTokens: options?.providerTokens,
|
|
@@ -20108,7 +20307,7 @@ async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
|
20108
20307
|
const getCodeModeTool = async () => {
|
|
20109
20308
|
if (cachedCodeModeTool)
|
|
20110
20309
|
return cachedCodeModeTool;
|
|
20111
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20310
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20112
20311
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
20113
20312
|
tools: mcpTools,
|
|
20114
20313
|
providerTokens: options?.providerTokens,
|
|
@@ -20159,7 +20358,7 @@ async function getAnthropicTools(client, options) {
|
|
|
20159
20358
|
}
|
|
20160
20359
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
20161
20360
|
await ensureClientConnected(client);
|
|
20162
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20361
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20163
20362
|
let effectiveMode;
|
|
20164
20363
|
if (options?.mode !== undefined) {
|
|
20165
20364
|
effectiveMode = options.mode;
|
|
@@ -20325,7 +20524,7 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
20325
20524
|
const getCodeModeTool = async () => {
|
|
20326
20525
|
if (cachedCodeModeTool)
|
|
20327
20526
|
return cachedCodeModeTool;
|
|
20328
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20527
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20329
20528
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
20330
20529
|
tools: mcpTools,
|
|
20331
20530
|
providerTokens: finalOptions?.providerTokens,
|
|
@@ -20364,7 +20563,7 @@ async function getGoogleTools(client, options) {
|
|
|
20364
20563
|
}
|
|
20365
20564
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
20366
20565
|
await ensureClientConnected(client);
|
|
20367
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20566
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20368
20567
|
let effectiveMode;
|
|
20369
20568
|
if (options?.mode !== undefined) {
|
|
20370
20569
|
effectiveMode = options.mode;
|
|
@@ -21233,10 +21432,3372 @@ function zohoSprintsIntegration(config = {}) {
|
|
|
21233
21432
|
}
|
|
21234
21433
|
};
|
|
21235
21434
|
}
|
|
21435
|
+
// src/database/trigger-store.ts
|
|
21436
|
+
function toIsoString(value) {
|
|
21437
|
+
if (!value)
|
|
21438
|
+
return null;
|
|
21439
|
+
if (value instanceof Date) {
|
|
21440
|
+
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
21441
|
+
}
|
|
21442
|
+
const parsed = new Date(value);
|
|
21443
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed.toISOString();
|
|
21444
|
+
}
|
|
21445
|
+
function toDbSchedule(value) {
|
|
21446
|
+
if (value.scheduleType && value.scheduleValue) {
|
|
21447
|
+
return {
|
|
21448
|
+
scheduleType: value.scheduleType,
|
|
21449
|
+
scheduleValue: value.scheduleValue
|
|
21450
|
+
};
|
|
21451
|
+
}
|
|
21452
|
+
if (value.schedule.type === "once") {
|
|
21453
|
+
const runAt = toIsoString(value.schedule.runAt);
|
|
21454
|
+
if (!runAt) {
|
|
21455
|
+
throw new Error("Invalid trigger once schedule");
|
|
21456
|
+
}
|
|
21457
|
+
return {
|
|
21458
|
+
scheduleType: "once",
|
|
21459
|
+
scheduleValue: runAt
|
|
21460
|
+
};
|
|
21461
|
+
}
|
|
21462
|
+
return {
|
|
21463
|
+
scheduleType: "cron",
|
|
21464
|
+
scheduleValue: value.schedule.expression
|
|
21465
|
+
};
|
|
21466
|
+
}
|
|
21467
|
+
function toSdkSchedule(row) {
|
|
21468
|
+
if (row.scheduleType === "once") {
|
|
21469
|
+
return {
|
|
21470
|
+
type: "once",
|
|
21471
|
+
runAt: row.scheduleValue
|
|
21472
|
+
};
|
|
21473
|
+
}
|
|
21474
|
+
return {
|
|
21475
|
+
type: "cron",
|
|
21476
|
+
expression: row.scheduleValue
|
|
21477
|
+
};
|
|
21478
|
+
}
|
|
21479
|
+
function toSdkTrigger(row) {
|
|
21480
|
+
return {
|
|
21481
|
+
id: row.id,
|
|
21482
|
+
userId: row.userId ?? undefined,
|
|
21483
|
+
name: row.name ?? undefined,
|
|
21484
|
+
description: row.description ?? undefined,
|
|
21485
|
+
toolName: row.toolName,
|
|
21486
|
+
toolArguments: row.toolArguments ?? {},
|
|
21487
|
+
schedule: toSdkSchedule(row),
|
|
21488
|
+
status: row.status,
|
|
21489
|
+
provider: row.provider ?? undefined,
|
|
21490
|
+
createdAt: row.createdAt.toISOString(),
|
|
21491
|
+
updatedAt: row.updatedAt.toISOString(),
|
|
21492
|
+
lastRunAt: toIsoString(row.lastRunAt) ?? undefined,
|
|
21493
|
+
nextRunAt: toIsoString(row.nextRunAt) ?? undefined,
|
|
21494
|
+
runCount: row.runCount,
|
|
21495
|
+
lastError: row.lastError ?? undefined,
|
|
21496
|
+
lastResult: row.lastResult ?? undefined
|
|
21497
|
+
};
|
|
21498
|
+
}
|
|
21499
|
+
function toDbTriggerUpdates(updates) {
|
|
21500
|
+
const dbUpdates = {
|
|
21501
|
+
updatedAt: new Date
|
|
21502
|
+
};
|
|
21503
|
+
if (updates.name !== undefined)
|
|
21504
|
+
dbUpdates.name = updates.name ?? null;
|
|
21505
|
+
if (updates.description !== undefined) {
|
|
21506
|
+
dbUpdates.description = updates.description ?? null;
|
|
21507
|
+
}
|
|
21508
|
+
if (updates.toolArguments !== undefined) {
|
|
21509
|
+
dbUpdates.toolArguments = updates.toolArguments;
|
|
21510
|
+
}
|
|
21511
|
+
if (updates.status !== undefined)
|
|
21512
|
+
dbUpdates.status = updates.status;
|
|
21513
|
+
if (updates.provider !== undefined)
|
|
21514
|
+
dbUpdates.provider = updates.provider ?? null;
|
|
21515
|
+
if (updates.lastError !== undefined)
|
|
21516
|
+
dbUpdates.lastError = updates.lastError ?? null;
|
|
21517
|
+
if (updates.lastResult !== undefined) {
|
|
21518
|
+
dbUpdates.lastResult = updates.lastResult ?? null;
|
|
21519
|
+
}
|
|
21520
|
+
if (updates.lastRunAt !== undefined) {
|
|
21521
|
+
dbUpdates.lastRunAt = updates.lastRunAt ? new Date(updates.lastRunAt) : null;
|
|
21522
|
+
}
|
|
21523
|
+
if (updates.nextRunAt !== undefined) {
|
|
21524
|
+
dbUpdates.nextRunAt = updates.nextRunAt ? new Date(updates.nextRunAt) : null;
|
|
21525
|
+
}
|
|
21526
|
+
if (updates.runCount !== undefined)
|
|
21527
|
+
dbUpdates.runCount = updates.runCount;
|
|
21528
|
+
if (updates.schedule) {
|
|
21529
|
+
if (updates.schedule.type === "once") {
|
|
21530
|
+
dbUpdates.scheduleType = "once";
|
|
21531
|
+
dbUpdates.scheduleValue = new Date(updates.schedule.runAt).toISOString();
|
|
21532
|
+
} else {
|
|
21533
|
+
dbUpdates.scheduleType = "cron";
|
|
21534
|
+
dbUpdates.scheduleValue = updates.schedule.expression;
|
|
21535
|
+
}
|
|
21536
|
+
}
|
|
21537
|
+
return dbUpdates;
|
|
21538
|
+
}
|
|
21539
|
+
function flattenedTriggerToCreateInput(triggerData, contextUserId) {
|
|
21540
|
+
const schedule = toDbSchedule(triggerData);
|
|
21541
|
+
return {
|
|
21542
|
+
id: triggerData.id,
|
|
21543
|
+
userId: contextUserId ?? triggerData.userId ?? null,
|
|
21544
|
+
name: triggerData.name ?? null,
|
|
21545
|
+
description: triggerData.description ?? null,
|
|
21546
|
+
toolName: triggerData.toolName,
|
|
21547
|
+
toolArguments: triggerData.toolArguments ?? {},
|
|
21548
|
+
scheduleType: schedule.scheduleType,
|
|
21549
|
+
scheduleValue: schedule.scheduleValue,
|
|
21550
|
+
status: triggerData.status ?? "active",
|
|
21551
|
+
provider: triggerData.provider ?? null,
|
|
21552
|
+
nextRunAt: triggerData.nextRunAt ? new Date(triggerData.nextRunAt) : null
|
|
21553
|
+
};
|
|
21554
|
+
}
|
|
21236
21555
|
|
|
21237
|
-
// src/
|
|
21238
|
-
|
|
21239
|
-
|
|
21556
|
+
// src/database/factory.ts
|
|
21557
|
+
function log(debug, message, error) {
|
|
21558
|
+
if (!debug)
|
|
21559
|
+
return;
|
|
21560
|
+
if (error !== undefined) {
|
|
21561
|
+
console.error(`[Integrate SDK] ${message}`, error);
|
|
21562
|
+
return;
|
|
21563
|
+
}
|
|
21564
|
+
console.log(`[Integrate SDK] ${message}`);
|
|
21565
|
+
}
|
|
21566
|
+
async function authorizeTriggerRow(row, context, hooks) {
|
|
21567
|
+
if (!row)
|
|
21568
|
+
return null;
|
|
21569
|
+
const repaired = hooks?.authorizeTrigger ? await hooks.authorizeTrigger(row, context) : row;
|
|
21570
|
+
if (!repaired)
|
|
21571
|
+
return null;
|
|
21572
|
+
if (context?.userId && repaired.userId !== context.userId) {
|
|
21573
|
+
return null;
|
|
21574
|
+
}
|
|
21575
|
+
return repaired;
|
|
21576
|
+
}
|
|
21577
|
+
function createDatabaseAdapterCallbacks(options) {
|
|
21578
|
+
const { driver, hooks, debugLogs } = options;
|
|
21579
|
+
const getProviderToken = async (provider, email, context) => {
|
|
21580
|
+
const userId = context?.userId;
|
|
21581
|
+
if (!userId) {
|
|
21582
|
+
return;
|
|
21583
|
+
}
|
|
21584
|
+
const accountEmailHint = normalizeAccountEmailHint(email) ?? normalizeAccountEmailHint(typeof context?.accountEmail === "string" ? context.accountEmail : null);
|
|
21585
|
+
const accountIdHint = normalizeAccountIdHint(typeof context?.accountId === "string" ? context.accountId : null);
|
|
21586
|
+
try {
|
|
21587
|
+
const rows = await driver.tokens.listProviderTokens(userId, provider);
|
|
21588
|
+
const selectedRow = selectProviderTokenRow(rows, accountEmailHint ?? undefined, accountIdHint ?? undefined);
|
|
21589
|
+
if (!selectedRow) {
|
|
21590
|
+
return;
|
|
21591
|
+
}
|
|
21592
|
+
return providerTokenRecordToData(selectedRow);
|
|
21593
|
+
} catch (error) {
|
|
21594
|
+
log(debugLogs, "Error fetching provider token:", error);
|
|
21595
|
+
return;
|
|
21596
|
+
}
|
|
21597
|
+
};
|
|
21598
|
+
const setProviderToken = async (provider, tokenData, email, context) => {
|
|
21599
|
+
const userId = context?.userId;
|
|
21600
|
+
if (!userId) {
|
|
21601
|
+
console.error("[Integrate SDK] Cannot save token: No userId in context");
|
|
21602
|
+
return;
|
|
21603
|
+
}
|
|
21604
|
+
const accountEmail = normalizeAccountEmailHint(email) ?? normalizeAccountEmail(tokenData?.email ?? null);
|
|
21605
|
+
if (tokenData === null) {
|
|
21606
|
+
try {
|
|
21607
|
+
await driver.tokens.deleteProviderTokens({
|
|
21608
|
+
userId,
|
|
21609
|
+
provider,
|
|
21610
|
+
accountEmail,
|
|
21611
|
+
accountId: normalizeAccountIdHint(typeof context?.accountId === "string" ? context.accountId : null)
|
|
21612
|
+
});
|
|
21613
|
+
await hooks?.onTokenChange?.({ userId, provider, action: "remove" });
|
|
21614
|
+
} catch (error) {
|
|
21615
|
+
log(debugLogs, "Error deleting provider token:", error);
|
|
21616
|
+
throw error;
|
|
21617
|
+
}
|
|
21618
|
+
return;
|
|
21619
|
+
}
|
|
21620
|
+
try {
|
|
21621
|
+
const resolvedIdentity = hooks?.resolveAccountIdentity ? await hooks.resolveAccountIdentity(provider, tokenData, accountEmail, context) : defaultResolveAccountIdentity(provider, tokenData, accountEmail);
|
|
21622
|
+
const resolvedAccountEmail = resolvedIdentity.accountEmail;
|
|
21623
|
+
const resolvedAccountId = normalizeAccountIdHint(resolvedIdentity.accountId) ?? normalizeAccountIdHint(typeof context?.accountId === "string" ? context.accountId : null) ?? null;
|
|
21624
|
+
const rows = await driver.tokens.listProviderTokens(userId, provider);
|
|
21625
|
+
let existing = selectProviderTokenRow(rows, resolvedAccountEmail ?? accountEmail ?? undefined, resolvedAccountId ?? undefined) ?? rows.find((row) => {
|
|
21626
|
+
const sameEmail = resolvedAccountEmail && normalizeAccountEmail(row.accountEmail) === resolvedAccountEmail;
|
|
21627
|
+
const sameAccountId = resolvedAccountId && normalizeAccountIdHint(row.accountId) === resolvedAccountId;
|
|
21628
|
+
return Boolean(sameEmail || sameAccountId);
|
|
21629
|
+
}) ?? (rows.length === 1 ? rows[0] : undefined);
|
|
21630
|
+
const parsedExpiresAt = tokenData.expiresAt ? new Date(tokenData.expiresAt) : null;
|
|
21631
|
+
const expiresAt = hasMeaningfulExpiresAt(parsedExpiresAt) ? parsedExpiresAt : null;
|
|
21632
|
+
const scope = tokenData.scopes?.join(" ") ?? null;
|
|
21633
|
+
const saved = await driver.tokens.upsertProviderToken({
|
|
21634
|
+
existingId: existing?.id,
|
|
21635
|
+
id: existing?.id ?? `${userId}-${provider}-${resolvedAccountEmail ?? "default"}-${Date.now()}`,
|
|
21636
|
+
userId,
|
|
21637
|
+
provider,
|
|
21638
|
+
accountEmail: resolvedAccountEmail,
|
|
21639
|
+
accountId: resolvedAccountId,
|
|
21640
|
+
accessToken: tokenData.accessToken,
|
|
21641
|
+
refreshToken: tokenData.refreshToken ?? null,
|
|
21642
|
+
tokenType: normalizeProviderTokenType(tokenData.tokenType),
|
|
21643
|
+
expiresAt,
|
|
21644
|
+
scope
|
|
21645
|
+
});
|
|
21646
|
+
await driver.tokens.deleteDuplicateProviderTokens({
|
|
21647
|
+
keepId: saved.id,
|
|
21648
|
+
userId,
|
|
21649
|
+
provider,
|
|
21650
|
+
accountEmail: resolvedAccountEmail,
|
|
21651
|
+
accountId: resolvedAccountId
|
|
21652
|
+
});
|
|
21653
|
+
await hooks?.onTokenChange?.({ userId, provider, action: "set" });
|
|
21654
|
+
} catch (error) {
|
|
21655
|
+
log(debugLogs, "Error saving provider token:", error);
|
|
21656
|
+
throw error;
|
|
21657
|
+
}
|
|
21658
|
+
};
|
|
21659
|
+
const removeProviderToken = async (provider, email, context) => {
|
|
21660
|
+
const userId = context?.userId;
|
|
21661
|
+
if (!userId) {
|
|
21662
|
+
console.error("[Integrate SDK] Cannot delete token: No userId in context");
|
|
21663
|
+
return;
|
|
21664
|
+
}
|
|
21665
|
+
try {
|
|
21666
|
+
await driver.tokens.deleteProviderTokens({
|
|
21667
|
+
userId,
|
|
21668
|
+
provider,
|
|
21669
|
+
accountEmail: normalizeAccountEmail(email)
|
|
21670
|
+
});
|
|
21671
|
+
await hooks?.onTokenChange?.({ userId, provider, action: "remove" });
|
|
21672
|
+
} catch (error) {
|
|
21673
|
+
log(debugLogs, "Error deleting provider token:", error);
|
|
21674
|
+
throw error;
|
|
21675
|
+
}
|
|
21676
|
+
};
|
|
21677
|
+
const callbacks = {
|
|
21678
|
+
getProviderToken,
|
|
21679
|
+
setProviderToken,
|
|
21680
|
+
removeProviderToken
|
|
21681
|
+
};
|
|
21682
|
+
if (driver.triggers) {
|
|
21683
|
+
const triggerDriver = driver.triggers;
|
|
21684
|
+
const triggers = {
|
|
21685
|
+
create: async (triggerData, context) => {
|
|
21686
|
+
try {
|
|
21687
|
+
const created = await triggerDriver.createTrigger(flattenedTriggerToCreateInput(triggerData, context?.userId));
|
|
21688
|
+
return toSdkTrigger(created);
|
|
21689
|
+
} catch (error) {
|
|
21690
|
+
log(debugLogs, "Error creating trigger:", error);
|
|
21691
|
+
throw error;
|
|
21692
|
+
}
|
|
21693
|
+
},
|
|
21694
|
+
get: async (triggerId, context) => {
|
|
21695
|
+
try {
|
|
21696
|
+
const found = await triggerDriver.getTriggerById(triggerId);
|
|
21697
|
+
const authorized = await authorizeTriggerRow(found, context, hooks);
|
|
21698
|
+
return authorized ? toSdkTrigger(authorized) : null;
|
|
21699
|
+
} catch (error) {
|
|
21700
|
+
log(debugLogs, "Error getting trigger:", error);
|
|
21701
|
+
throw error;
|
|
21702
|
+
}
|
|
21703
|
+
},
|
|
21704
|
+
list: async (params, context) => {
|
|
21705
|
+
try {
|
|
21706
|
+
const { rows, total } = await triggerDriver.listTriggers({
|
|
21707
|
+
userId: context?.userId,
|
|
21708
|
+
status: params.status,
|
|
21709
|
+
toolName: params.toolName,
|
|
21710
|
+
limit: params.limit ?? 20,
|
|
21711
|
+
offset: params.offset ?? 0
|
|
21712
|
+
});
|
|
21713
|
+
const triggers2 = [];
|
|
21714
|
+
for (const row of rows) {
|
|
21715
|
+
const authorized = await authorizeTriggerRow(row, context, hooks);
|
|
21716
|
+
if (authorized) {
|
|
21717
|
+
triggers2.push(toSdkTrigger(authorized));
|
|
21718
|
+
}
|
|
21719
|
+
}
|
|
21720
|
+
return { triggers: triggers2, total };
|
|
21721
|
+
} catch (error) {
|
|
21722
|
+
log(debugLogs, "Error listing triggers:", error);
|
|
21723
|
+
throw error;
|
|
21724
|
+
}
|
|
21725
|
+
},
|
|
21726
|
+
update: async (triggerId, updates, context) => {
|
|
21727
|
+
try {
|
|
21728
|
+
const existing = await triggerDriver.getTriggerById(triggerId);
|
|
21729
|
+
const authorized = await authorizeTriggerRow(existing, context, hooks);
|
|
21730
|
+
if (!authorized) {
|
|
21731
|
+
throw new Error(`Trigger not found: ${triggerId}`);
|
|
21732
|
+
}
|
|
21733
|
+
const updated = await triggerDriver.updateTrigger(authorized.id, toDbTriggerUpdates(updates));
|
|
21734
|
+
if (!updated) {
|
|
21735
|
+
throw new Error(`Trigger not found: ${triggerId}`);
|
|
21736
|
+
}
|
|
21737
|
+
return toSdkTrigger(updated);
|
|
21738
|
+
} catch (error) {
|
|
21739
|
+
log(debugLogs, "Error updating trigger:", error);
|
|
21740
|
+
throw error;
|
|
21741
|
+
}
|
|
21742
|
+
},
|
|
21743
|
+
delete: async (triggerId, context) => {
|
|
21744
|
+
try {
|
|
21745
|
+
const existing = await triggerDriver.getTriggerById(triggerId);
|
|
21746
|
+
const authorized = await authorizeTriggerRow(existing, context, hooks);
|
|
21747
|
+
if (!authorized) {
|
|
21748
|
+
return;
|
|
21749
|
+
}
|
|
21750
|
+
await triggerDriver.deleteTrigger(authorized.id);
|
|
21751
|
+
} catch (error) {
|
|
21752
|
+
log(debugLogs, "Error deleting trigger:", error);
|
|
21753
|
+
throw error;
|
|
21754
|
+
}
|
|
21755
|
+
}
|
|
21756
|
+
};
|
|
21757
|
+
callbacks.triggers = triggers;
|
|
21758
|
+
}
|
|
21759
|
+
return callbacks;
|
|
21760
|
+
}
|
|
21761
|
+
function createDatabaseAdapterFactory(createDriver, options) {
|
|
21762
|
+
return () => createDatabaseAdapterCallbacks({
|
|
21763
|
+
driver: createDriver(),
|
|
21764
|
+
hooks: options?.hooks,
|
|
21765
|
+
debugLogs: options?.debugLogs
|
|
21766
|
+
});
|
|
21767
|
+
}
|
|
21768
|
+
// node_modules/drizzle-orm/entity.js
|
|
21769
|
+
var entityKind = Symbol.for("drizzle:entityKind");
|
|
21770
|
+
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
21771
|
+
function is(value, type) {
|
|
21772
|
+
if (!value || typeof value !== "object") {
|
|
21773
|
+
return false;
|
|
21774
|
+
}
|
|
21775
|
+
if (value instanceof type) {
|
|
21776
|
+
return true;
|
|
21777
|
+
}
|
|
21778
|
+
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) {
|
|
21779
|
+
throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
21780
|
+
}
|
|
21781
|
+
let cls = Object.getPrototypeOf(value).constructor;
|
|
21782
|
+
if (cls) {
|
|
21783
|
+
while (cls) {
|
|
21784
|
+
if (entityKind in cls && cls[entityKind] === type[entityKind]) {
|
|
21785
|
+
return true;
|
|
21786
|
+
}
|
|
21787
|
+
cls = Object.getPrototypeOf(cls);
|
|
21788
|
+
}
|
|
21789
|
+
}
|
|
21790
|
+
return false;
|
|
21791
|
+
}
|
|
21792
|
+
|
|
21793
|
+
// node_modules/drizzle-orm/column.js
|
|
21794
|
+
class Column {
|
|
21795
|
+
constructor(table, config) {
|
|
21796
|
+
this.table = table;
|
|
21797
|
+
this.config = config;
|
|
21798
|
+
this.name = config.name;
|
|
21799
|
+
this.keyAsName = config.keyAsName;
|
|
21800
|
+
this.notNull = config.notNull;
|
|
21801
|
+
this.default = config.default;
|
|
21802
|
+
this.defaultFn = config.defaultFn;
|
|
21803
|
+
this.onUpdateFn = config.onUpdateFn;
|
|
21804
|
+
this.hasDefault = config.hasDefault;
|
|
21805
|
+
this.primary = config.primaryKey;
|
|
21806
|
+
this.isUnique = config.isUnique;
|
|
21807
|
+
this.uniqueName = config.uniqueName;
|
|
21808
|
+
this.uniqueType = config.uniqueType;
|
|
21809
|
+
this.dataType = config.dataType;
|
|
21810
|
+
this.columnType = config.columnType;
|
|
21811
|
+
this.generated = config.generated;
|
|
21812
|
+
this.generatedIdentity = config.generatedIdentity;
|
|
21813
|
+
}
|
|
21814
|
+
static [entityKind] = "Column";
|
|
21815
|
+
name;
|
|
21816
|
+
keyAsName;
|
|
21817
|
+
primary;
|
|
21818
|
+
notNull;
|
|
21819
|
+
default;
|
|
21820
|
+
defaultFn;
|
|
21821
|
+
onUpdateFn;
|
|
21822
|
+
hasDefault;
|
|
21823
|
+
isUnique;
|
|
21824
|
+
uniqueName;
|
|
21825
|
+
uniqueType;
|
|
21826
|
+
dataType;
|
|
21827
|
+
columnType;
|
|
21828
|
+
enumValues = undefined;
|
|
21829
|
+
generated = undefined;
|
|
21830
|
+
generatedIdentity = undefined;
|
|
21831
|
+
config;
|
|
21832
|
+
mapFromDriverValue(value) {
|
|
21833
|
+
return value;
|
|
21834
|
+
}
|
|
21835
|
+
mapToDriverValue(value) {
|
|
21836
|
+
return value;
|
|
21837
|
+
}
|
|
21838
|
+
shouldDisableInsert() {
|
|
21839
|
+
return this.config.generated !== undefined && this.config.generated.type !== "byDefault";
|
|
21840
|
+
}
|
|
21841
|
+
}
|
|
21842
|
+
|
|
21843
|
+
// node_modules/drizzle-orm/column-builder.js
|
|
21844
|
+
class ColumnBuilder {
|
|
21845
|
+
static [entityKind] = "ColumnBuilder";
|
|
21846
|
+
config;
|
|
21847
|
+
constructor(name, dataType, columnType) {
|
|
21848
|
+
this.config = {
|
|
21849
|
+
name,
|
|
21850
|
+
keyAsName: name === "",
|
|
21851
|
+
notNull: false,
|
|
21852
|
+
default: undefined,
|
|
21853
|
+
hasDefault: false,
|
|
21854
|
+
primaryKey: false,
|
|
21855
|
+
isUnique: false,
|
|
21856
|
+
uniqueName: undefined,
|
|
21857
|
+
uniqueType: undefined,
|
|
21858
|
+
dataType,
|
|
21859
|
+
columnType,
|
|
21860
|
+
generated: undefined
|
|
21861
|
+
};
|
|
21862
|
+
}
|
|
21863
|
+
$type() {
|
|
21864
|
+
return this;
|
|
21865
|
+
}
|
|
21866
|
+
notNull() {
|
|
21867
|
+
this.config.notNull = true;
|
|
21868
|
+
return this;
|
|
21869
|
+
}
|
|
21870
|
+
default(value) {
|
|
21871
|
+
this.config.default = value;
|
|
21872
|
+
this.config.hasDefault = true;
|
|
21873
|
+
return this;
|
|
21874
|
+
}
|
|
21875
|
+
$defaultFn(fn) {
|
|
21876
|
+
this.config.defaultFn = fn;
|
|
21877
|
+
this.config.hasDefault = true;
|
|
21878
|
+
return this;
|
|
21879
|
+
}
|
|
21880
|
+
$default = this.$defaultFn;
|
|
21881
|
+
$onUpdateFn(fn) {
|
|
21882
|
+
this.config.onUpdateFn = fn;
|
|
21883
|
+
this.config.hasDefault = true;
|
|
21884
|
+
return this;
|
|
21885
|
+
}
|
|
21886
|
+
$onUpdate = this.$onUpdateFn;
|
|
21887
|
+
primaryKey() {
|
|
21888
|
+
this.config.primaryKey = true;
|
|
21889
|
+
this.config.notNull = true;
|
|
21890
|
+
return this;
|
|
21891
|
+
}
|
|
21892
|
+
setName(name) {
|
|
21893
|
+
if (this.config.name !== "")
|
|
21894
|
+
return;
|
|
21895
|
+
this.config.name = name;
|
|
21896
|
+
}
|
|
21897
|
+
}
|
|
21898
|
+
|
|
21899
|
+
// node_modules/drizzle-orm/table.utils.js
|
|
21900
|
+
var TableName = Symbol.for("drizzle:Name");
|
|
21901
|
+
|
|
21902
|
+
// node_modules/drizzle-orm/pg-core/foreign-keys.js
|
|
21903
|
+
class ForeignKeyBuilder {
|
|
21904
|
+
static [entityKind] = "PgForeignKeyBuilder";
|
|
21905
|
+
reference;
|
|
21906
|
+
_onUpdate = "no action";
|
|
21907
|
+
_onDelete = "no action";
|
|
21908
|
+
constructor(config, actions) {
|
|
21909
|
+
this.reference = () => {
|
|
21910
|
+
const { name, columns, foreignColumns } = config();
|
|
21911
|
+
return { name, columns, foreignTable: foreignColumns[0].table, foreignColumns };
|
|
21912
|
+
};
|
|
21913
|
+
if (actions) {
|
|
21914
|
+
this._onUpdate = actions.onUpdate;
|
|
21915
|
+
this._onDelete = actions.onDelete;
|
|
21916
|
+
}
|
|
21917
|
+
}
|
|
21918
|
+
onUpdate(action) {
|
|
21919
|
+
this._onUpdate = action === undefined ? "no action" : action;
|
|
21920
|
+
return this;
|
|
21921
|
+
}
|
|
21922
|
+
onDelete(action) {
|
|
21923
|
+
this._onDelete = action === undefined ? "no action" : action;
|
|
21924
|
+
return this;
|
|
21925
|
+
}
|
|
21926
|
+
build(table) {
|
|
21927
|
+
return new ForeignKey(table, this);
|
|
21928
|
+
}
|
|
21929
|
+
}
|
|
21930
|
+
|
|
21931
|
+
class ForeignKey {
|
|
21932
|
+
constructor(table, builder) {
|
|
21933
|
+
this.table = table;
|
|
21934
|
+
this.reference = builder.reference;
|
|
21935
|
+
this.onUpdate = builder._onUpdate;
|
|
21936
|
+
this.onDelete = builder._onDelete;
|
|
21937
|
+
}
|
|
21938
|
+
static [entityKind] = "PgForeignKey";
|
|
21939
|
+
reference;
|
|
21940
|
+
onUpdate;
|
|
21941
|
+
onDelete;
|
|
21942
|
+
getName() {
|
|
21943
|
+
const { name, columns, foreignColumns } = this.reference();
|
|
21944
|
+
const columnNames = columns.map((column) => column.name);
|
|
21945
|
+
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
21946
|
+
const chunks = [
|
|
21947
|
+
this.table[TableName],
|
|
21948
|
+
...columnNames,
|
|
21949
|
+
foreignColumns[0].table[TableName],
|
|
21950
|
+
...foreignColumnNames
|
|
21951
|
+
];
|
|
21952
|
+
return name ?? `${chunks.join("_")}_fk`;
|
|
21953
|
+
}
|
|
21954
|
+
}
|
|
21955
|
+
|
|
21956
|
+
// node_modules/drizzle-orm/tracing-utils.js
|
|
21957
|
+
function iife(fn, ...args) {
|
|
21958
|
+
return fn(...args);
|
|
21959
|
+
}
|
|
21960
|
+
|
|
21961
|
+
// node_modules/drizzle-orm/pg-core/unique-constraint.js
|
|
21962
|
+
function uniqueKeyName(table, columns) {
|
|
21963
|
+
return `${table[TableName]}_${columns.join("_")}_unique`;
|
|
21964
|
+
}
|
|
21965
|
+
|
|
21966
|
+
// node_modules/drizzle-orm/pg-core/utils/array.js
|
|
21967
|
+
function parsePgArrayValue(arrayString, startFrom, inQuotes) {
|
|
21968
|
+
for (let i = startFrom;i < arrayString.length; i++) {
|
|
21969
|
+
const char = arrayString[i];
|
|
21970
|
+
if (char === "\\") {
|
|
21971
|
+
i++;
|
|
21972
|
+
continue;
|
|
21973
|
+
}
|
|
21974
|
+
if (char === '"') {
|
|
21975
|
+
return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i + 1];
|
|
21976
|
+
}
|
|
21977
|
+
if (inQuotes) {
|
|
21978
|
+
continue;
|
|
21979
|
+
}
|
|
21980
|
+
if (char === "," || char === "}") {
|
|
21981
|
+
return [arrayString.slice(startFrom, i).replace(/\\/g, ""), i];
|
|
21982
|
+
}
|
|
21983
|
+
}
|
|
21984
|
+
return [arrayString.slice(startFrom).replace(/\\/g, ""), arrayString.length];
|
|
21985
|
+
}
|
|
21986
|
+
function parsePgNestedArray(arrayString, startFrom = 0) {
|
|
21987
|
+
const result = [];
|
|
21988
|
+
let i = startFrom;
|
|
21989
|
+
let lastCharIsComma = false;
|
|
21990
|
+
while (i < arrayString.length) {
|
|
21991
|
+
const char = arrayString[i];
|
|
21992
|
+
if (char === ",") {
|
|
21993
|
+
if (lastCharIsComma || i === startFrom) {
|
|
21994
|
+
result.push("");
|
|
21995
|
+
}
|
|
21996
|
+
lastCharIsComma = true;
|
|
21997
|
+
i++;
|
|
21998
|
+
continue;
|
|
21999
|
+
}
|
|
22000
|
+
lastCharIsComma = false;
|
|
22001
|
+
if (char === "\\") {
|
|
22002
|
+
i += 2;
|
|
22003
|
+
continue;
|
|
22004
|
+
}
|
|
22005
|
+
if (char === '"') {
|
|
22006
|
+
const [value2, startFrom2] = parsePgArrayValue(arrayString, i + 1, true);
|
|
22007
|
+
result.push(value2);
|
|
22008
|
+
i = startFrom2;
|
|
22009
|
+
continue;
|
|
22010
|
+
}
|
|
22011
|
+
if (char === "}") {
|
|
22012
|
+
return [result, i + 1];
|
|
22013
|
+
}
|
|
22014
|
+
if (char === "{") {
|
|
22015
|
+
const [value2, startFrom2] = parsePgNestedArray(arrayString, i + 1);
|
|
22016
|
+
result.push(value2);
|
|
22017
|
+
i = startFrom2;
|
|
22018
|
+
continue;
|
|
22019
|
+
}
|
|
22020
|
+
const [value, newStartFrom] = parsePgArrayValue(arrayString, i, false);
|
|
22021
|
+
result.push(value);
|
|
22022
|
+
i = newStartFrom;
|
|
22023
|
+
}
|
|
22024
|
+
return [result, i];
|
|
22025
|
+
}
|
|
22026
|
+
function parsePgArray(arrayString) {
|
|
22027
|
+
const [result] = parsePgNestedArray(arrayString, 1);
|
|
22028
|
+
return result;
|
|
22029
|
+
}
|
|
22030
|
+
function makePgArray(array2) {
|
|
22031
|
+
return `{${array2.map((item) => {
|
|
22032
|
+
if (Array.isArray(item)) {
|
|
22033
|
+
return makePgArray(item);
|
|
22034
|
+
}
|
|
22035
|
+
if (typeof item === "string") {
|
|
22036
|
+
return `"${item.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
22037
|
+
}
|
|
22038
|
+
return `${item}`;
|
|
22039
|
+
}).join(",")}}`;
|
|
22040
|
+
}
|
|
22041
|
+
|
|
22042
|
+
// node_modules/drizzle-orm/pg-core/columns/common.js
|
|
22043
|
+
class PgColumnBuilder extends ColumnBuilder {
|
|
22044
|
+
foreignKeyConfigs = [];
|
|
22045
|
+
static [entityKind] = "PgColumnBuilder";
|
|
22046
|
+
array(size) {
|
|
22047
|
+
return new PgArrayBuilder(this.config.name, this, size);
|
|
22048
|
+
}
|
|
22049
|
+
references(ref, actions = {}) {
|
|
22050
|
+
this.foreignKeyConfigs.push({ ref, actions });
|
|
22051
|
+
return this;
|
|
22052
|
+
}
|
|
22053
|
+
unique(name, config) {
|
|
22054
|
+
this.config.isUnique = true;
|
|
22055
|
+
this.config.uniqueName = name;
|
|
22056
|
+
this.config.uniqueType = config?.nulls;
|
|
22057
|
+
return this;
|
|
22058
|
+
}
|
|
22059
|
+
generatedAlwaysAs(as) {
|
|
22060
|
+
this.config.generated = {
|
|
22061
|
+
as,
|
|
22062
|
+
type: "always",
|
|
22063
|
+
mode: "stored"
|
|
22064
|
+
};
|
|
22065
|
+
return this;
|
|
22066
|
+
}
|
|
22067
|
+
buildForeignKeys(column, table) {
|
|
22068
|
+
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
22069
|
+
return iife((ref2, actions2) => {
|
|
22070
|
+
const builder = new ForeignKeyBuilder(() => {
|
|
22071
|
+
const foreignColumn = ref2();
|
|
22072
|
+
return { columns: [column], foreignColumns: [foreignColumn] };
|
|
22073
|
+
});
|
|
22074
|
+
if (actions2.onUpdate) {
|
|
22075
|
+
builder.onUpdate(actions2.onUpdate);
|
|
22076
|
+
}
|
|
22077
|
+
if (actions2.onDelete) {
|
|
22078
|
+
builder.onDelete(actions2.onDelete);
|
|
22079
|
+
}
|
|
22080
|
+
return builder.build(table);
|
|
22081
|
+
}, ref, actions);
|
|
22082
|
+
});
|
|
22083
|
+
}
|
|
22084
|
+
buildExtraConfigColumn(table) {
|
|
22085
|
+
return new ExtraConfigColumn(table, this.config);
|
|
22086
|
+
}
|
|
22087
|
+
}
|
|
22088
|
+
|
|
22089
|
+
class PgColumn extends Column {
|
|
22090
|
+
constructor(table, config) {
|
|
22091
|
+
if (!config.uniqueName) {
|
|
22092
|
+
config.uniqueName = uniqueKeyName(table, [config.name]);
|
|
22093
|
+
}
|
|
22094
|
+
super(table, config);
|
|
22095
|
+
this.table = table;
|
|
22096
|
+
}
|
|
22097
|
+
static [entityKind] = "PgColumn";
|
|
22098
|
+
}
|
|
22099
|
+
|
|
22100
|
+
class ExtraConfigColumn extends PgColumn {
|
|
22101
|
+
static [entityKind] = "ExtraConfigColumn";
|
|
22102
|
+
getSQLType() {
|
|
22103
|
+
return this.getSQLType();
|
|
22104
|
+
}
|
|
22105
|
+
indexConfig = {
|
|
22106
|
+
order: this.config.order ?? "asc",
|
|
22107
|
+
nulls: this.config.nulls ?? "last",
|
|
22108
|
+
opClass: this.config.opClass
|
|
22109
|
+
};
|
|
22110
|
+
defaultConfig = {
|
|
22111
|
+
order: "asc",
|
|
22112
|
+
nulls: "last",
|
|
22113
|
+
opClass: undefined
|
|
22114
|
+
};
|
|
22115
|
+
asc() {
|
|
22116
|
+
this.indexConfig.order = "asc";
|
|
22117
|
+
return this;
|
|
22118
|
+
}
|
|
22119
|
+
desc() {
|
|
22120
|
+
this.indexConfig.order = "desc";
|
|
22121
|
+
return this;
|
|
22122
|
+
}
|
|
22123
|
+
nullsFirst() {
|
|
22124
|
+
this.indexConfig.nulls = "first";
|
|
22125
|
+
return this;
|
|
22126
|
+
}
|
|
22127
|
+
nullsLast() {
|
|
22128
|
+
this.indexConfig.nulls = "last";
|
|
22129
|
+
return this;
|
|
22130
|
+
}
|
|
22131
|
+
op(opClass) {
|
|
22132
|
+
this.indexConfig.opClass = opClass;
|
|
22133
|
+
return this;
|
|
22134
|
+
}
|
|
22135
|
+
}
|
|
22136
|
+
|
|
22137
|
+
class IndexedColumn {
|
|
22138
|
+
static [entityKind] = "IndexedColumn";
|
|
22139
|
+
constructor(name, keyAsName, type, indexConfig) {
|
|
22140
|
+
this.name = name;
|
|
22141
|
+
this.keyAsName = keyAsName;
|
|
22142
|
+
this.type = type;
|
|
22143
|
+
this.indexConfig = indexConfig;
|
|
22144
|
+
}
|
|
22145
|
+
name;
|
|
22146
|
+
keyAsName;
|
|
22147
|
+
type;
|
|
22148
|
+
indexConfig;
|
|
22149
|
+
}
|
|
22150
|
+
|
|
22151
|
+
class PgArrayBuilder extends PgColumnBuilder {
|
|
22152
|
+
static [entityKind] = "PgArrayBuilder";
|
|
22153
|
+
constructor(name, baseBuilder, size) {
|
|
22154
|
+
super(name, "array", "PgArray");
|
|
22155
|
+
this.config.baseBuilder = baseBuilder;
|
|
22156
|
+
this.config.size = size;
|
|
22157
|
+
}
|
|
22158
|
+
build(table) {
|
|
22159
|
+
const baseColumn = this.config.baseBuilder.build(table);
|
|
22160
|
+
return new PgArray(table, this.config, baseColumn);
|
|
22161
|
+
}
|
|
22162
|
+
}
|
|
22163
|
+
|
|
22164
|
+
class PgArray extends PgColumn {
|
|
22165
|
+
constructor(table, config, baseColumn, range) {
|
|
22166
|
+
super(table, config);
|
|
22167
|
+
this.baseColumn = baseColumn;
|
|
22168
|
+
this.range = range;
|
|
22169
|
+
this.size = config.size;
|
|
22170
|
+
}
|
|
22171
|
+
size;
|
|
22172
|
+
static [entityKind] = "PgArray";
|
|
22173
|
+
getSQLType() {
|
|
22174
|
+
return `${this.baseColumn.getSQLType()}[${typeof this.size === "number" ? this.size : ""}]`;
|
|
22175
|
+
}
|
|
22176
|
+
mapFromDriverValue(value) {
|
|
22177
|
+
if (typeof value === "string") {
|
|
22178
|
+
value = parsePgArray(value);
|
|
22179
|
+
}
|
|
22180
|
+
return value.map((v) => this.baseColumn.mapFromDriverValue(v));
|
|
22181
|
+
}
|
|
22182
|
+
mapToDriverValue(value, isNestedArray = false) {
|
|
22183
|
+
const a = value.map((v) => v === null ? null : is(this.baseColumn, PgArray) ? this.baseColumn.mapToDriverValue(v, true) : this.baseColumn.mapToDriverValue(v));
|
|
22184
|
+
if (isNestedArray)
|
|
22185
|
+
return a;
|
|
22186
|
+
return makePgArray(a);
|
|
22187
|
+
}
|
|
22188
|
+
}
|
|
22189
|
+
|
|
22190
|
+
// node_modules/drizzle-orm/pg-core/columns/enum.js
|
|
22191
|
+
class PgEnumObjectColumn extends PgColumn {
|
|
22192
|
+
static [entityKind] = "PgEnumObjectColumn";
|
|
22193
|
+
enum;
|
|
22194
|
+
enumValues = this.config.enum.enumValues;
|
|
22195
|
+
constructor(table, config) {
|
|
22196
|
+
super(table, config);
|
|
22197
|
+
this.enum = config.enum;
|
|
22198
|
+
}
|
|
22199
|
+
getSQLType() {
|
|
22200
|
+
return this.enum.enumName;
|
|
22201
|
+
}
|
|
22202
|
+
}
|
|
22203
|
+
var isPgEnumSym = Symbol.for("drizzle:isPgEnum");
|
|
22204
|
+
function isPgEnum(obj) {
|
|
22205
|
+
return !!obj && typeof obj === "function" && isPgEnumSym in obj && obj[isPgEnumSym] === true;
|
|
22206
|
+
}
|
|
22207
|
+
class PgEnumColumn extends PgColumn {
|
|
22208
|
+
static [entityKind] = "PgEnumColumn";
|
|
22209
|
+
enum = this.config.enum;
|
|
22210
|
+
enumValues = this.config.enum.enumValues;
|
|
22211
|
+
constructor(table, config) {
|
|
22212
|
+
super(table, config);
|
|
22213
|
+
this.enum = config.enum;
|
|
22214
|
+
}
|
|
22215
|
+
getSQLType() {
|
|
22216
|
+
return this.enum.enumName;
|
|
22217
|
+
}
|
|
22218
|
+
}
|
|
22219
|
+
|
|
22220
|
+
// node_modules/drizzle-orm/subquery.js
|
|
22221
|
+
class Subquery {
|
|
22222
|
+
static [entityKind] = "Subquery";
|
|
22223
|
+
constructor(sql, fields, alias, isWith = false, usedTables = []) {
|
|
22224
|
+
this._ = {
|
|
22225
|
+
brand: "Subquery",
|
|
22226
|
+
sql,
|
|
22227
|
+
selectedFields: fields,
|
|
22228
|
+
alias,
|
|
22229
|
+
isWith,
|
|
22230
|
+
usedTables
|
|
22231
|
+
};
|
|
22232
|
+
}
|
|
22233
|
+
}
|
|
22234
|
+
|
|
22235
|
+
// node_modules/drizzle-orm/version.js
|
|
22236
|
+
var version = "0.44.7";
|
|
22237
|
+
|
|
22238
|
+
// node_modules/drizzle-orm/tracing.js
|
|
22239
|
+
var otel;
|
|
22240
|
+
var rawTracer;
|
|
22241
|
+
var tracer = {
|
|
22242
|
+
startActiveSpan(name, fn) {
|
|
22243
|
+
if (!otel) {
|
|
22244
|
+
return fn();
|
|
22245
|
+
}
|
|
22246
|
+
if (!rawTracer) {
|
|
22247
|
+
rawTracer = otel.trace.getTracer("drizzle-orm", version);
|
|
22248
|
+
}
|
|
22249
|
+
return iife((otel2, rawTracer2) => rawTracer2.startActiveSpan(name, (span) => {
|
|
22250
|
+
try {
|
|
22251
|
+
return fn(span);
|
|
22252
|
+
} catch (e) {
|
|
22253
|
+
span.setStatus({
|
|
22254
|
+
code: otel2.SpanStatusCode.ERROR,
|
|
22255
|
+
message: e instanceof Error ? e.message : "Unknown error"
|
|
22256
|
+
});
|
|
22257
|
+
throw e;
|
|
22258
|
+
} finally {
|
|
22259
|
+
span.end();
|
|
22260
|
+
}
|
|
22261
|
+
}), otel, rawTracer);
|
|
22262
|
+
}
|
|
22263
|
+
};
|
|
22264
|
+
|
|
22265
|
+
// node_modules/drizzle-orm/view-common.js
|
|
22266
|
+
var ViewBaseConfig = Symbol.for("drizzle:ViewBaseConfig");
|
|
22267
|
+
|
|
22268
|
+
// node_modules/drizzle-orm/table.js
|
|
22269
|
+
var Schema = Symbol.for("drizzle:Schema");
|
|
22270
|
+
var Columns = Symbol.for("drizzle:Columns");
|
|
22271
|
+
var ExtraConfigColumns = Symbol.for("drizzle:ExtraConfigColumns");
|
|
22272
|
+
var OriginalName = Symbol.for("drizzle:OriginalName");
|
|
22273
|
+
var BaseName = Symbol.for("drizzle:BaseName");
|
|
22274
|
+
var IsAlias = Symbol.for("drizzle:IsAlias");
|
|
22275
|
+
var ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
|
|
22276
|
+
var IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
|
|
22277
|
+
|
|
22278
|
+
class Table {
|
|
22279
|
+
static [entityKind] = "Table";
|
|
22280
|
+
static Symbol = {
|
|
22281
|
+
Name: TableName,
|
|
22282
|
+
Schema,
|
|
22283
|
+
OriginalName,
|
|
22284
|
+
Columns,
|
|
22285
|
+
ExtraConfigColumns,
|
|
22286
|
+
BaseName,
|
|
22287
|
+
IsAlias,
|
|
22288
|
+
ExtraConfigBuilder
|
|
22289
|
+
};
|
|
22290
|
+
[TableName];
|
|
22291
|
+
[OriginalName];
|
|
22292
|
+
[Schema];
|
|
22293
|
+
[Columns];
|
|
22294
|
+
[ExtraConfigColumns];
|
|
22295
|
+
[BaseName];
|
|
22296
|
+
[IsAlias] = false;
|
|
22297
|
+
[IsDrizzleTable] = true;
|
|
22298
|
+
[ExtraConfigBuilder] = undefined;
|
|
22299
|
+
constructor(name, schema, baseName) {
|
|
22300
|
+
this[TableName] = this[OriginalName] = name;
|
|
22301
|
+
this[Schema] = schema;
|
|
22302
|
+
this[BaseName] = baseName;
|
|
22303
|
+
}
|
|
22304
|
+
}
|
|
22305
|
+
|
|
22306
|
+
// node_modules/drizzle-orm/sql/sql.js
|
|
22307
|
+
function isSQLWrapper(value) {
|
|
22308
|
+
return value !== null && value !== undefined && typeof value.getSQL === "function";
|
|
22309
|
+
}
|
|
22310
|
+
function mergeQueries(queries) {
|
|
22311
|
+
const result = { sql: "", params: [] };
|
|
22312
|
+
for (const query of queries) {
|
|
22313
|
+
result.sql += query.sql;
|
|
22314
|
+
result.params.push(...query.params);
|
|
22315
|
+
if (query.typings?.length) {
|
|
22316
|
+
if (!result.typings) {
|
|
22317
|
+
result.typings = [];
|
|
22318
|
+
}
|
|
22319
|
+
result.typings.push(...query.typings);
|
|
22320
|
+
}
|
|
22321
|
+
}
|
|
22322
|
+
return result;
|
|
22323
|
+
}
|
|
22324
|
+
|
|
22325
|
+
class StringChunk {
|
|
22326
|
+
static [entityKind] = "StringChunk";
|
|
22327
|
+
value;
|
|
22328
|
+
constructor(value) {
|
|
22329
|
+
this.value = Array.isArray(value) ? value : [value];
|
|
22330
|
+
}
|
|
22331
|
+
getSQL() {
|
|
22332
|
+
return new SQL([this]);
|
|
22333
|
+
}
|
|
22334
|
+
}
|
|
22335
|
+
|
|
22336
|
+
class SQL {
|
|
22337
|
+
constructor(queryChunks) {
|
|
22338
|
+
this.queryChunks = queryChunks;
|
|
22339
|
+
for (const chunk of queryChunks) {
|
|
22340
|
+
if (is(chunk, Table)) {
|
|
22341
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
22342
|
+
this.usedTables.push(schemaName === undefined ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
22343
|
+
}
|
|
22344
|
+
}
|
|
22345
|
+
}
|
|
22346
|
+
static [entityKind] = "SQL";
|
|
22347
|
+
decoder = noopDecoder;
|
|
22348
|
+
shouldInlineParams = false;
|
|
22349
|
+
usedTables = [];
|
|
22350
|
+
append(query) {
|
|
22351
|
+
this.queryChunks.push(...query.queryChunks);
|
|
22352
|
+
return this;
|
|
22353
|
+
}
|
|
22354
|
+
toQuery(config) {
|
|
22355
|
+
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
22356
|
+
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
22357
|
+
span?.setAttributes({
|
|
22358
|
+
"drizzle.query.text": query.sql,
|
|
22359
|
+
"drizzle.query.params": JSON.stringify(query.params)
|
|
22360
|
+
});
|
|
22361
|
+
return query;
|
|
22362
|
+
});
|
|
22363
|
+
}
|
|
22364
|
+
buildQueryFromSourceParams(chunks, _config) {
|
|
22365
|
+
const config = Object.assign({}, _config, {
|
|
22366
|
+
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
22367
|
+
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
22368
|
+
});
|
|
22369
|
+
const {
|
|
22370
|
+
casing,
|
|
22371
|
+
escapeName,
|
|
22372
|
+
escapeParam,
|
|
22373
|
+
prepareTyping,
|
|
22374
|
+
inlineParams,
|
|
22375
|
+
paramStartIndex
|
|
22376
|
+
} = config;
|
|
22377
|
+
return mergeQueries(chunks.map((chunk) => {
|
|
22378
|
+
if (is(chunk, StringChunk)) {
|
|
22379
|
+
return { sql: chunk.value.join(""), params: [] };
|
|
22380
|
+
}
|
|
22381
|
+
if (is(chunk, Name)) {
|
|
22382
|
+
return { sql: escapeName(chunk.value), params: [] };
|
|
22383
|
+
}
|
|
22384
|
+
if (chunk === undefined) {
|
|
22385
|
+
return { sql: "", params: [] };
|
|
22386
|
+
}
|
|
22387
|
+
if (Array.isArray(chunk)) {
|
|
22388
|
+
const result = [new StringChunk("(")];
|
|
22389
|
+
for (const [i, p] of chunk.entries()) {
|
|
22390
|
+
result.push(p);
|
|
22391
|
+
if (i < chunk.length - 1) {
|
|
22392
|
+
result.push(new StringChunk(", "));
|
|
22393
|
+
}
|
|
22394
|
+
}
|
|
22395
|
+
result.push(new StringChunk(")"));
|
|
22396
|
+
return this.buildQueryFromSourceParams(result, config);
|
|
22397
|
+
}
|
|
22398
|
+
if (is(chunk, SQL)) {
|
|
22399
|
+
return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
22400
|
+
...config,
|
|
22401
|
+
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
22402
|
+
});
|
|
22403
|
+
}
|
|
22404
|
+
if (is(chunk, Table)) {
|
|
22405
|
+
const schemaName = chunk[Table.Symbol.Schema];
|
|
22406
|
+
const tableName = chunk[Table.Symbol.Name];
|
|
22407
|
+
return {
|
|
22408
|
+
sql: schemaName === undefined || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
22409
|
+
params: []
|
|
22410
|
+
};
|
|
22411
|
+
}
|
|
22412
|
+
if (is(chunk, Column)) {
|
|
22413
|
+
const columnName = casing.getColumnCasing(chunk);
|
|
22414
|
+
if (_config.invokeSource === "indexes") {
|
|
22415
|
+
return { sql: escapeName(columnName), params: [] };
|
|
22416
|
+
}
|
|
22417
|
+
const schemaName = chunk.table[Table.Symbol.Schema];
|
|
22418
|
+
return {
|
|
22419
|
+
sql: chunk.table[IsAlias] || schemaName === undefined ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
22420
|
+
params: []
|
|
22421
|
+
};
|
|
22422
|
+
}
|
|
22423
|
+
if (is(chunk, View)) {
|
|
22424
|
+
const schemaName = chunk[ViewBaseConfig].schema;
|
|
22425
|
+
const viewName = chunk[ViewBaseConfig].name;
|
|
22426
|
+
return {
|
|
22427
|
+
sql: schemaName === undefined || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
22428
|
+
params: []
|
|
22429
|
+
};
|
|
22430
|
+
}
|
|
22431
|
+
if (is(chunk, Param)) {
|
|
22432
|
+
if (is(chunk.value, Placeholder)) {
|
|
22433
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
22434
|
+
}
|
|
22435
|
+
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
22436
|
+
if (is(mappedValue, SQL)) {
|
|
22437
|
+
return this.buildQueryFromSourceParams([mappedValue], config);
|
|
22438
|
+
}
|
|
22439
|
+
if (inlineParams) {
|
|
22440
|
+
return { sql: this.mapInlineParam(mappedValue, config), params: [] };
|
|
22441
|
+
}
|
|
22442
|
+
let typings = ["none"];
|
|
22443
|
+
if (prepareTyping) {
|
|
22444
|
+
typings = [prepareTyping(chunk.encoder)];
|
|
22445
|
+
}
|
|
22446
|
+
return { sql: escapeParam(paramStartIndex.value++, mappedValue), params: [mappedValue], typings };
|
|
22447
|
+
}
|
|
22448
|
+
if (is(chunk, Placeholder)) {
|
|
22449
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
22450
|
+
}
|
|
22451
|
+
if (is(chunk, SQL.Aliased) && chunk.fieldAlias !== undefined) {
|
|
22452
|
+
return { sql: escapeName(chunk.fieldAlias), params: [] };
|
|
22453
|
+
}
|
|
22454
|
+
if (is(chunk, Subquery)) {
|
|
22455
|
+
if (chunk._.isWith) {
|
|
22456
|
+
return { sql: escapeName(chunk._.alias), params: [] };
|
|
22457
|
+
}
|
|
22458
|
+
return this.buildQueryFromSourceParams([
|
|
22459
|
+
new StringChunk("("),
|
|
22460
|
+
chunk._.sql,
|
|
22461
|
+
new StringChunk(") "),
|
|
22462
|
+
new Name(chunk._.alias)
|
|
22463
|
+
], config);
|
|
22464
|
+
}
|
|
22465
|
+
if (isPgEnum(chunk)) {
|
|
22466
|
+
if (chunk.schema) {
|
|
22467
|
+
return { sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName), params: [] };
|
|
22468
|
+
}
|
|
22469
|
+
return { sql: escapeName(chunk.enumName), params: [] };
|
|
22470
|
+
}
|
|
22471
|
+
if (isSQLWrapper(chunk)) {
|
|
22472
|
+
if (chunk.shouldOmitSQLParens?.()) {
|
|
22473
|
+
return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
22474
|
+
}
|
|
22475
|
+
return this.buildQueryFromSourceParams([
|
|
22476
|
+
new StringChunk("("),
|
|
22477
|
+
chunk.getSQL(),
|
|
22478
|
+
new StringChunk(")")
|
|
22479
|
+
], config);
|
|
22480
|
+
}
|
|
22481
|
+
if (inlineParams) {
|
|
22482
|
+
return { sql: this.mapInlineParam(chunk, config), params: [] };
|
|
22483
|
+
}
|
|
22484
|
+
return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
|
|
22485
|
+
}));
|
|
22486
|
+
}
|
|
22487
|
+
mapInlineParam(chunk, { escapeString }) {
|
|
22488
|
+
if (chunk === null) {
|
|
22489
|
+
return "null";
|
|
22490
|
+
}
|
|
22491
|
+
if (typeof chunk === "number" || typeof chunk === "boolean") {
|
|
22492
|
+
return chunk.toString();
|
|
22493
|
+
}
|
|
22494
|
+
if (typeof chunk === "string") {
|
|
22495
|
+
return escapeString(chunk);
|
|
22496
|
+
}
|
|
22497
|
+
if (typeof chunk === "object") {
|
|
22498
|
+
const mappedValueAsString = chunk.toString();
|
|
22499
|
+
if (mappedValueAsString === "[object Object]") {
|
|
22500
|
+
return escapeString(JSON.stringify(chunk));
|
|
22501
|
+
}
|
|
22502
|
+
return escapeString(mappedValueAsString);
|
|
22503
|
+
}
|
|
22504
|
+
throw new Error("Unexpected param value: " + chunk);
|
|
22505
|
+
}
|
|
22506
|
+
getSQL() {
|
|
22507
|
+
return this;
|
|
22508
|
+
}
|
|
22509
|
+
as(alias) {
|
|
22510
|
+
if (alias === undefined) {
|
|
22511
|
+
return this;
|
|
22512
|
+
}
|
|
22513
|
+
return new SQL.Aliased(this, alias);
|
|
22514
|
+
}
|
|
22515
|
+
mapWith(decoder) {
|
|
22516
|
+
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
22517
|
+
return this;
|
|
22518
|
+
}
|
|
22519
|
+
inlineParams() {
|
|
22520
|
+
this.shouldInlineParams = true;
|
|
22521
|
+
return this;
|
|
22522
|
+
}
|
|
22523
|
+
if(condition) {
|
|
22524
|
+
return condition ? this : undefined;
|
|
22525
|
+
}
|
|
22526
|
+
}
|
|
22527
|
+
|
|
22528
|
+
class Name {
|
|
22529
|
+
constructor(value) {
|
|
22530
|
+
this.value = value;
|
|
22531
|
+
}
|
|
22532
|
+
static [entityKind] = "Name";
|
|
22533
|
+
brand;
|
|
22534
|
+
getSQL() {
|
|
22535
|
+
return new SQL([this]);
|
|
22536
|
+
}
|
|
22537
|
+
}
|
|
22538
|
+
function isDriverValueEncoder(value) {
|
|
22539
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
22540
|
+
}
|
|
22541
|
+
var noopDecoder = {
|
|
22542
|
+
mapFromDriverValue: (value) => value
|
|
22543
|
+
};
|
|
22544
|
+
var noopEncoder = {
|
|
22545
|
+
mapToDriverValue: (value) => value
|
|
22546
|
+
};
|
|
22547
|
+
var noopMapper = {
|
|
22548
|
+
...noopDecoder,
|
|
22549
|
+
...noopEncoder
|
|
22550
|
+
};
|
|
22551
|
+
|
|
22552
|
+
class Param {
|
|
22553
|
+
constructor(value, encoder = noopEncoder) {
|
|
22554
|
+
this.value = value;
|
|
22555
|
+
this.encoder = encoder;
|
|
22556
|
+
}
|
|
22557
|
+
static [entityKind] = "Param";
|
|
22558
|
+
brand;
|
|
22559
|
+
getSQL() {
|
|
22560
|
+
return new SQL([this]);
|
|
22561
|
+
}
|
|
22562
|
+
}
|
|
22563
|
+
function sql(strings, ...params) {
|
|
22564
|
+
const queryChunks = [];
|
|
22565
|
+
if (params.length > 0 || strings.length > 0 && strings[0] !== "") {
|
|
22566
|
+
queryChunks.push(new StringChunk(strings[0]));
|
|
22567
|
+
}
|
|
22568
|
+
for (const [paramIndex, param2] of params.entries()) {
|
|
22569
|
+
queryChunks.push(param2, new StringChunk(strings[paramIndex + 1]));
|
|
22570
|
+
}
|
|
22571
|
+
return new SQL(queryChunks);
|
|
22572
|
+
}
|
|
22573
|
+
((sql2) => {
|
|
22574
|
+
function empty() {
|
|
22575
|
+
return new SQL([]);
|
|
22576
|
+
}
|
|
22577
|
+
sql2.empty = empty;
|
|
22578
|
+
function fromList(list) {
|
|
22579
|
+
return new SQL(list);
|
|
22580
|
+
}
|
|
22581
|
+
sql2.fromList = fromList;
|
|
22582
|
+
function raw(str) {
|
|
22583
|
+
return new SQL([new StringChunk(str)]);
|
|
22584
|
+
}
|
|
22585
|
+
sql2.raw = raw;
|
|
22586
|
+
function join(chunks, separator) {
|
|
22587
|
+
const result = [];
|
|
22588
|
+
for (const [i, chunk] of chunks.entries()) {
|
|
22589
|
+
if (i > 0 && separator !== undefined) {
|
|
22590
|
+
result.push(separator);
|
|
22591
|
+
}
|
|
22592
|
+
result.push(chunk);
|
|
22593
|
+
}
|
|
22594
|
+
return new SQL(result);
|
|
22595
|
+
}
|
|
22596
|
+
sql2.join = join;
|
|
22597
|
+
function identifier(value) {
|
|
22598
|
+
return new Name(value);
|
|
22599
|
+
}
|
|
22600
|
+
sql2.identifier = identifier;
|
|
22601
|
+
function placeholder2(name2) {
|
|
22602
|
+
return new Placeholder(name2);
|
|
22603
|
+
}
|
|
22604
|
+
sql2.placeholder = placeholder2;
|
|
22605
|
+
function param2(value, encoder) {
|
|
22606
|
+
return new Param(value, encoder);
|
|
22607
|
+
}
|
|
22608
|
+
sql2.param = param2;
|
|
22609
|
+
})(sql || (sql = {}));
|
|
22610
|
+
((SQL2) => {
|
|
22611
|
+
|
|
22612
|
+
class Aliased {
|
|
22613
|
+
constructor(sql2, fieldAlias) {
|
|
22614
|
+
this.sql = sql2;
|
|
22615
|
+
this.fieldAlias = fieldAlias;
|
|
22616
|
+
}
|
|
22617
|
+
static [entityKind] = "SQL.Aliased";
|
|
22618
|
+
isSelectionField = false;
|
|
22619
|
+
getSQL() {
|
|
22620
|
+
return this.sql;
|
|
22621
|
+
}
|
|
22622
|
+
clone() {
|
|
22623
|
+
return new Aliased(this.sql, this.fieldAlias);
|
|
22624
|
+
}
|
|
22625
|
+
}
|
|
22626
|
+
SQL2.Aliased = Aliased;
|
|
22627
|
+
})(SQL || (SQL = {}));
|
|
22628
|
+
|
|
22629
|
+
class Placeholder {
|
|
22630
|
+
constructor(name2) {
|
|
22631
|
+
this.name = name2;
|
|
22632
|
+
}
|
|
22633
|
+
static [entityKind] = "Placeholder";
|
|
22634
|
+
getSQL() {
|
|
22635
|
+
return new SQL([this]);
|
|
22636
|
+
}
|
|
22637
|
+
}
|
|
22638
|
+
var IsDrizzleView = Symbol.for("drizzle:IsDrizzleView");
|
|
22639
|
+
|
|
22640
|
+
class View {
|
|
22641
|
+
static [entityKind] = "View";
|
|
22642
|
+
[ViewBaseConfig];
|
|
22643
|
+
[IsDrizzleView] = true;
|
|
22644
|
+
constructor({ name: name2, schema, selectedFields, query }) {
|
|
22645
|
+
this[ViewBaseConfig] = {
|
|
22646
|
+
name: name2,
|
|
22647
|
+
originalName: name2,
|
|
22648
|
+
schema,
|
|
22649
|
+
selectedFields,
|
|
22650
|
+
query,
|
|
22651
|
+
isExisting: !query,
|
|
22652
|
+
isAlias: false
|
|
22653
|
+
};
|
|
22654
|
+
}
|
|
22655
|
+
getSQL() {
|
|
22656
|
+
return new SQL([this]);
|
|
22657
|
+
}
|
|
22658
|
+
}
|
|
22659
|
+
Column.prototype.getSQL = function() {
|
|
22660
|
+
return new SQL([this]);
|
|
22661
|
+
};
|
|
22662
|
+
Table.prototype.getSQL = function() {
|
|
22663
|
+
return new SQL([this]);
|
|
22664
|
+
};
|
|
22665
|
+
Subquery.prototype.getSQL = function() {
|
|
22666
|
+
return new SQL([this]);
|
|
22667
|
+
};
|
|
22668
|
+
|
|
22669
|
+
// node_modules/drizzle-orm/utils.js
|
|
22670
|
+
function getColumnNameAndConfig(a, b) {
|
|
22671
|
+
return {
|
|
22672
|
+
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
22673
|
+
config: typeof a === "object" ? a : b
|
|
22674
|
+
};
|
|
22675
|
+
}
|
|
22676
|
+
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder;
|
|
22677
|
+
|
|
22678
|
+
// node_modules/drizzle-orm/pg-core/columns/int.common.js
|
|
22679
|
+
class PgIntColumnBaseBuilder extends PgColumnBuilder {
|
|
22680
|
+
static [entityKind] = "PgIntColumnBaseBuilder";
|
|
22681
|
+
generatedAlwaysAsIdentity(sequence) {
|
|
22682
|
+
if (sequence) {
|
|
22683
|
+
const { name, ...options } = sequence;
|
|
22684
|
+
this.config.generatedIdentity = {
|
|
22685
|
+
type: "always",
|
|
22686
|
+
sequenceName: name,
|
|
22687
|
+
sequenceOptions: options
|
|
22688
|
+
};
|
|
22689
|
+
} else {
|
|
22690
|
+
this.config.generatedIdentity = {
|
|
22691
|
+
type: "always"
|
|
22692
|
+
};
|
|
22693
|
+
}
|
|
22694
|
+
this.config.hasDefault = true;
|
|
22695
|
+
this.config.notNull = true;
|
|
22696
|
+
return this;
|
|
22697
|
+
}
|
|
22698
|
+
generatedByDefaultAsIdentity(sequence) {
|
|
22699
|
+
if (sequence) {
|
|
22700
|
+
const { name, ...options } = sequence;
|
|
22701
|
+
this.config.generatedIdentity = {
|
|
22702
|
+
type: "byDefault",
|
|
22703
|
+
sequenceName: name,
|
|
22704
|
+
sequenceOptions: options
|
|
22705
|
+
};
|
|
22706
|
+
} else {
|
|
22707
|
+
this.config.generatedIdentity = {
|
|
22708
|
+
type: "byDefault"
|
|
22709
|
+
};
|
|
22710
|
+
}
|
|
22711
|
+
this.config.hasDefault = true;
|
|
22712
|
+
this.config.notNull = true;
|
|
22713
|
+
return this;
|
|
22714
|
+
}
|
|
22715
|
+
}
|
|
22716
|
+
|
|
22717
|
+
// node_modules/drizzle-orm/pg-core/columns/bigint.js
|
|
22718
|
+
class PgBigInt53Builder extends PgIntColumnBaseBuilder {
|
|
22719
|
+
static [entityKind] = "PgBigInt53Builder";
|
|
22720
|
+
constructor(name) {
|
|
22721
|
+
super(name, "number", "PgBigInt53");
|
|
22722
|
+
}
|
|
22723
|
+
build(table) {
|
|
22724
|
+
return new PgBigInt53(table, this.config);
|
|
22725
|
+
}
|
|
22726
|
+
}
|
|
22727
|
+
|
|
22728
|
+
class PgBigInt53 extends PgColumn {
|
|
22729
|
+
static [entityKind] = "PgBigInt53";
|
|
22730
|
+
getSQLType() {
|
|
22731
|
+
return "bigint";
|
|
22732
|
+
}
|
|
22733
|
+
mapFromDriverValue(value) {
|
|
22734
|
+
if (typeof value === "number") {
|
|
22735
|
+
return value;
|
|
22736
|
+
}
|
|
22737
|
+
return Number(value);
|
|
22738
|
+
}
|
|
22739
|
+
}
|
|
22740
|
+
|
|
22741
|
+
class PgBigInt64Builder extends PgIntColumnBaseBuilder {
|
|
22742
|
+
static [entityKind] = "PgBigInt64Builder";
|
|
22743
|
+
constructor(name) {
|
|
22744
|
+
super(name, "bigint", "PgBigInt64");
|
|
22745
|
+
}
|
|
22746
|
+
build(table) {
|
|
22747
|
+
return new PgBigInt64(table, this.config);
|
|
22748
|
+
}
|
|
22749
|
+
}
|
|
22750
|
+
|
|
22751
|
+
class PgBigInt64 extends PgColumn {
|
|
22752
|
+
static [entityKind] = "PgBigInt64";
|
|
22753
|
+
getSQLType() {
|
|
22754
|
+
return "bigint";
|
|
22755
|
+
}
|
|
22756
|
+
mapFromDriverValue(value) {
|
|
22757
|
+
return BigInt(value);
|
|
22758
|
+
}
|
|
22759
|
+
}
|
|
22760
|
+
function bigint2(a, b) {
|
|
22761
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
22762
|
+
if (config.mode === "number") {
|
|
22763
|
+
return new PgBigInt53Builder(name);
|
|
22764
|
+
}
|
|
22765
|
+
return new PgBigInt64Builder(name);
|
|
22766
|
+
}
|
|
22767
|
+
|
|
22768
|
+
// node_modules/drizzle-orm/pg-core/columns/bigserial.js
|
|
22769
|
+
class PgBigSerial53Builder extends PgColumnBuilder {
|
|
22770
|
+
static [entityKind] = "PgBigSerial53Builder";
|
|
22771
|
+
constructor(name) {
|
|
22772
|
+
super(name, "number", "PgBigSerial53");
|
|
22773
|
+
this.config.hasDefault = true;
|
|
22774
|
+
this.config.notNull = true;
|
|
22775
|
+
}
|
|
22776
|
+
build(table) {
|
|
22777
|
+
return new PgBigSerial53(table, this.config);
|
|
22778
|
+
}
|
|
22779
|
+
}
|
|
22780
|
+
|
|
22781
|
+
class PgBigSerial53 extends PgColumn {
|
|
22782
|
+
static [entityKind] = "PgBigSerial53";
|
|
22783
|
+
getSQLType() {
|
|
22784
|
+
return "bigserial";
|
|
22785
|
+
}
|
|
22786
|
+
mapFromDriverValue(value) {
|
|
22787
|
+
if (typeof value === "number") {
|
|
22788
|
+
return value;
|
|
22789
|
+
}
|
|
22790
|
+
return Number(value);
|
|
22791
|
+
}
|
|
22792
|
+
}
|
|
22793
|
+
|
|
22794
|
+
class PgBigSerial64Builder extends PgColumnBuilder {
|
|
22795
|
+
static [entityKind] = "PgBigSerial64Builder";
|
|
22796
|
+
constructor(name) {
|
|
22797
|
+
super(name, "bigint", "PgBigSerial64");
|
|
22798
|
+
this.config.hasDefault = true;
|
|
22799
|
+
}
|
|
22800
|
+
build(table) {
|
|
22801
|
+
return new PgBigSerial64(table, this.config);
|
|
22802
|
+
}
|
|
22803
|
+
}
|
|
22804
|
+
|
|
22805
|
+
class PgBigSerial64 extends PgColumn {
|
|
22806
|
+
static [entityKind] = "PgBigSerial64";
|
|
22807
|
+
getSQLType() {
|
|
22808
|
+
return "bigserial";
|
|
22809
|
+
}
|
|
22810
|
+
mapFromDriverValue(value) {
|
|
22811
|
+
return BigInt(value);
|
|
22812
|
+
}
|
|
22813
|
+
}
|
|
22814
|
+
function bigserial(a, b) {
|
|
22815
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
22816
|
+
if (config.mode === "number") {
|
|
22817
|
+
return new PgBigSerial53Builder(name);
|
|
22818
|
+
}
|
|
22819
|
+
return new PgBigSerial64Builder(name);
|
|
22820
|
+
}
|
|
22821
|
+
|
|
22822
|
+
// node_modules/drizzle-orm/pg-core/columns/boolean.js
|
|
22823
|
+
class PgBooleanBuilder extends PgColumnBuilder {
|
|
22824
|
+
static [entityKind] = "PgBooleanBuilder";
|
|
22825
|
+
constructor(name) {
|
|
22826
|
+
super(name, "boolean", "PgBoolean");
|
|
22827
|
+
}
|
|
22828
|
+
build(table) {
|
|
22829
|
+
return new PgBoolean(table, this.config);
|
|
22830
|
+
}
|
|
22831
|
+
}
|
|
22832
|
+
|
|
22833
|
+
class PgBoolean extends PgColumn {
|
|
22834
|
+
static [entityKind] = "PgBoolean";
|
|
22835
|
+
getSQLType() {
|
|
22836
|
+
return "boolean";
|
|
22837
|
+
}
|
|
22838
|
+
}
|
|
22839
|
+
function boolean2(name) {
|
|
22840
|
+
return new PgBooleanBuilder(name ?? "");
|
|
22841
|
+
}
|
|
22842
|
+
|
|
22843
|
+
// node_modules/drizzle-orm/pg-core/columns/char.js
|
|
22844
|
+
class PgCharBuilder extends PgColumnBuilder {
|
|
22845
|
+
static [entityKind] = "PgCharBuilder";
|
|
22846
|
+
constructor(name, config) {
|
|
22847
|
+
super(name, "string", "PgChar");
|
|
22848
|
+
this.config.length = config.length;
|
|
22849
|
+
this.config.enumValues = config.enum;
|
|
22850
|
+
}
|
|
22851
|
+
build(table) {
|
|
22852
|
+
return new PgChar(table, this.config);
|
|
22853
|
+
}
|
|
22854
|
+
}
|
|
22855
|
+
|
|
22856
|
+
class PgChar extends PgColumn {
|
|
22857
|
+
static [entityKind] = "PgChar";
|
|
22858
|
+
length = this.config.length;
|
|
22859
|
+
enumValues = this.config.enumValues;
|
|
22860
|
+
getSQLType() {
|
|
22861
|
+
return this.length === undefined ? `char` : `char(${this.length})`;
|
|
22862
|
+
}
|
|
22863
|
+
}
|
|
22864
|
+
function char(a, b = {}) {
|
|
22865
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
22866
|
+
return new PgCharBuilder(name, config);
|
|
22867
|
+
}
|
|
22868
|
+
|
|
22869
|
+
// node_modules/drizzle-orm/pg-core/columns/cidr.js
|
|
22870
|
+
class PgCidrBuilder extends PgColumnBuilder {
|
|
22871
|
+
static [entityKind] = "PgCidrBuilder";
|
|
22872
|
+
constructor(name) {
|
|
22873
|
+
super(name, "string", "PgCidr");
|
|
22874
|
+
}
|
|
22875
|
+
build(table) {
|
|
22876
|
+
return new PgCidr(table, this.config);
|
|
22877
|
+
}
|
|
22878
|
+
}
|
|
22879
|
+
|
|
22880
|
+
class PgCidr extends PgColumn {
|
|
22881
|
+
static [entityKind] = "PgCidr";
|
|
22882
|
+
getSQLType() {
|
|
22883
|
+
return "cidr";
|
|
22884
|
+
}
|
|
22885
|
+
}
|
|
22886
|
+
function cidr(name) {
|
|
22887
|
+
return new PgCidrBuilder(name ?? "");
|
|
22888
|
+
}
|
|
22889
|
+
|
|
22890
|
+
// node_modules/drizzle-orm/pg-core/columns/custom.js
|
|
22891
|
+
class PgCustomColumnBuilder extends PgColumnBuilder {
|
|
22892
|
+
static [entityKind] = "PgCustomColumnBuilder";
|
|
22893
|
+
constructor(name, fieldConfig, customTypeParams) {
|
|
22894
|
+
super(name, "custom", "PgCustomColumn");
|
|
22895
|
+
this.config.fieldConfig = fieldConfig;
|
|
22896
|
+
this.config.customTypeParams = customTypeParams;
|
|
22897
|
+
}
|
|
22898
|
+
build(table) {
|
|
22899
|
+
return new PgCustomColumn(table, this.config);
|
|
22900
|
+
}
|
|
22901
|
+
}
|
|
22902
|
+
|
|
22903
|
+
class PgCustomColumn extends PgColumn {
|
|
22904
|
+
static [entityKind] = "PgCustomColumn";
|
|
22905
|
+
sqlName;
|
|
22906
|
+
mapTo;
|
|
22907
|
+
mapFrom;
|
|
22908
|
+
constructor(table, config) {
|
|
22909
|
+
super(table, config);
|
|
22910
|
+
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
22911
|
+
this.mapTo = config.customTypeParams.toDriver;
|
|
22912
|
+
this.mapFrom = config.customTypeParams.fromDriver;
|
|
22913
|
+
}
|
|
22914
|
+
getSQLType() {
|
|
22915
|
+
return this.sqlName;
|
|
22916
|
+
}
|
|
22917
|
+
mapFromDriverValue(value) {
|
|
22918
|
+
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
22919
|
+
}
|
|
22920
|
+
mapToDriverValue(value) {
|
|
22921
|
+
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
22922
|
+
}
|
|
22923
|
+
}
|
|
22924
|
+
function customType(customTypeParams) {
|
|
22925
|
+
return (a, b) => {
|
|
22926
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
22927
|
+
return new PgCustomColumnBuilder(name, config, customTypeParams);
|
|
22928
|
+
};
|
|
22929
|
+
}
|
|
22930
|
+
|
|
22931
|
+
// node_modules/drizzle-orm/pg-core/columns/date.common.js
|
|
22932
|
+
class PgDateColumnBaseBuilder extends PgColumnBuilder {
|
|
22933
|
+
static [entityKind] = "PgDateColumnBaseBuilder";
|
|
22934
|
+
defaultNow() {
|
|
22935
|
+
return this.default(sql`now()`);
|
|
22936
|
+
}
|
|
22937
|
+
}
|
|
22938
|
+
|
|
22939
|
+
// node_modules/drizzle-orm/pg-core/columns/date.js
|
|
22940
|
+
class PgDateBuilder extends PgDateColumnBaseBuilder {
|
|
22941
|
+
static [entityKind] = "PgDateBuilder";
|
|
22942
|
+
constructor(name) {
|
|
22943
|
+
super(name, "date", "PgDate");
|
|
22944
|
+
}
|
|
22945
|
+
build(table) {
|
|
22946
|
+
return new PgDate(table, this.config);
|
|
22947
|
+
}
|
|
22948
|
+
}
|
|
22949
|
+
|
|
22950
|
+
class PgDate extends PgColumn {
|
|
22951
|
+
static [entityKind] = "PgDate";
|
|
22952
|
+
getSQLType() {
|
|
22953
|
+
return "date";
|
|
22954
|
+
}
|
|
22955
|
+
mapFromDriverValue(value) {
|
|
22956
|
+
return new Date(value);
|
|
22957
|
+
}
|
|
22958
|
+
mapToDriverValue(value) {
|
|
22959
|
+
return value.toISOString();
|
|
22960
|
+
}
|
|
22961
|
+
}
|
|
22962
|
+
|
|
22963
|
+
class PgDateStringBuilder extends PgDateColumnBaseBuilder {
|
|
22964
|
+
static [entityKind] = "PgDateStringBuilder";
|
|
22965
|
+
constructor(name) {
|
|
22966
|
+
super(name, "string", "PgDateString");
|
|
22967
|
+
}
|
|
22968
|
+
build(table) {
|
|
22969
|
+
return new PgDateString(table, this.config);
|
|
22970
|
+
}
|
|
22971
|
+
}
|
|
22972
|
+
|
|
22973
|
+
class PgDateString extends PgColumn {
|
|
22974
|
+
static [entityKind] = "PgDateString";
|
|
22975
|
+
getSQLType() {
|
|
22976
|
+
return "date";
|
|
22977
|
+
}
|
|
22978
|
+
}
|
|
22979
|
+
function date2(a, b) {
|
|
22980
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
22981
|
+
if (config?.mode === "date") {
|
|
22982
|
+
return new PgDateBuilder(name);
|
|
22983
|
+
}
|
|
22984
|
+
return new PgDateStringBuilder(name);
|
|
22985
|
+
}
|
|
22986
|
+
|
|
22987
|
+
// node_modules/drizzle-orm/pg-core/columns/double-precision.js
|
|
22988
|
+
class PgDoublePrecisionBuilder extends PgColumnBuilder {
|
|
22989
|
+
static [entityKind] = "PgDoublePrecisionBuilder";
|
|
22990
|
+
constructor(name) {
|
|
22991
|
+
super(name, "number", "PgDoublePrecision");
|
|
22992
|
+
}
|
|
22993
|
+
build(table) {
|
|
22994
|
+
return new PgDoublePrecision(table, this.config);
|
|
22995
|
+
}
|
|
22996
|
+
}
|
|
22997
|
+
|
|
22998
|
+
class PgDoublePrecision extends PgColumn {
|
|
22999
|
+
static [entityKind] = "PgDoublePrecision";
|
|
23000
|
+
getSQLType() {
|
|
23001
|
+
return "double precision";
|
|
23002
|
+
}
|
|
23003
|
+
mapFromDriverValue(value) {
|
|
23004
|
+
if (typeof value === "string") {
|
|
23005
|
+
return Number.parseFloat(value);
|
|
23006
|
+
}
|
|
23007
|
+
return value;
|
|
23008
|
+
}
|
|
23009
|
+
}
|
|
23010
|
+
function doublePrecision(name) {
|
|
23011
|
+
return new PgDoublePrecisionBuilder(name ?? "");
|
|
23012
|
+
}
|
|
23013
|
+
|
|
23014
|
+
// node_modules/drizzle-orm/pg-core/columns/inet.js
|
|
23015
|
+
class PgInetBuilder extends PgColumnBuilder {
|
|
23016
|
+
static [entityKind] = "PgInetBuilder";
|
|
23017
|
+
constructor(name) {
|
|
23018
|
+
super(name, "string", "PgInet");
|
|
23019
|
+
}
|
|
23020
|
+
build(table) {
|
|
23021
|
+
return new PgInet(table, this.config);
|
|
23022
|
+
}
|
|
23023
|
+
}
|
|
23024
|
+
|
|
23025
|
+
class PgInet extends PgColumn {
|
|
23026
|
+
static [entityKind] = "PgInet";
|
|
23027
|
+
getSQLType() {
|
|
23028
|
+
return "inet";
|
|
23029
|
+
}
|
|
23030
|
+
}
|
|
23031
|
+
function inet(name) {
|
|
23032
|
+
return new PgInetBuilder(name ?? "");
|
|
23033
|
+
}
|
|
23034
|
+
|
|
23035
|
+
// node_modules/drizzle-orm/pg-core/columns/integer.js
|
|
23036
|
+
class PgIntegerBuilder extends PgIntColumnBaseBuilder {
|
|
23037
|
+
static [entityKind] = "PgIntegerBuilder";
|
|
23038
|
+
constructor(name) {
|
|
23039
|
+
super(name, "number", "PgInteger");
|
|
23040
|
+
}
|
|
23041
|
+
build(table) {
|
|
23042
|
+
return new PgInteger(table, this.config);
|
|
23043
|
+
}
|
|
23044
|
+
}
|
|
23045
|
+
|
|
23046
|
+
class PgInteger extends PgColumn {
|
|
23047
|
+
static [entityKind] = "PgInteger";
|
|
23048
|
+
getSQLType() {
|
|
23049
|
+
return "integer";
|
|
23050
|
+
}
|
|
23051
|
+
mapFromDriverValue(value) {
|
|
23052
|
+
if (typeof value === "string") {
|
|
23053
|
+
return Number.parseInt(value);
|
|
23054
|
+
}
|
|
23055
|
+
return value;
|
|
23056
|
+
}
|
|
23057
|
+
}
|
|
23058
|
+
function integer(name) {
|
|
23059
|
+
return new PgIntegerBuilder(name ?? "");
|
|
23060
|
+
}
|
|
23061
|
+
|
|
23062
|
+
// node_modules/drizzle-orm/pg-core/columns/interval.js
|
|
23063
|
+
class PgIntervalBuilder extends PgColumnBuilder {
|
|
23064
|
+
static [entityKind] = "PgIntervalBuilder";
|
|
23065
|
+
constructor(name, intervalConfig) {
|
|
23066
|
+
super(name, "string", "PgInterval");
|
|
23067
|
+
this.config.intervalConfig = intervalConfig;
|
|
23068
|
+
}
|
|
23069
|
+
build(table) {
|
|
23070
|
+
return new PgInterval(table, this.config);
|
|
23071
|
+
}
|
|
23072
|
+
}
|
|
23073
|
+
|
|
23074
|
+
class PgInterval extends PgColumn {
|
|
23075
|
+
static [entityKind] = "PgInterval";
|
|
23076
|
+
fields = this.config.intervalConfig.fields;
|
|
23077
|
+
precision = this.config.intervalConfig.precision;
|
|
23078
|
+
getSQLType() {
|
|
23079
|
+
const fields = this.fields ? ` ${this.fields}` : "";
|
|
23080
|
+
const precision = this.precision ? `(${this.precision})` : "";
|
|
23081
|
+
return `interval${fields}${precision}`;
|
|
23082
|
+
}
|
|
23083
|
+
}
|
|
23084
|
+
function interval(a, b = {}) {
|
|
23085
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23086
|
+
return new PgIntervalBuilder(name, config);
|
|
23087
|
+
}
|
|
23088
|
+
|
|
23089
|
+
// node_modules/drizzle-orm/pg-core/columns/json.js
|
|
23090
|
+
class PgJsonBuilder extends PgColumnBuilder {
|
|
23091
|
+
static [entityKind] = "PgJsonBuilder";
|
|
23092
|
+
constructor(name) {
|
|
23093
|
+
super(name, "json", "PgJson");
|
|
23094
|
+
}
|
|
23095
|
+
build(table) {
|
|
23096
|
+
return new PgJson(table, this.config);
|
|
23097
|
+
}
|
|
23098
|
+
}
|
|
23099
|
+
|
|
23100
|
+
class PgJson extends PgColumn {
|
|
23101
|
+
static [entityKind] = "PgJson";
|
|
23102
|
+
constructor(table, config) {
|
|
23103
|
+
super(table, config);
|
|
23104
|
+
}
|
|
23105
|
+
getSQLType() {
|
|
23106
|
+
return "json";
|
|
23107
|
+
}
|
|
23108
|
+
mapToDriverValue(value) {
|
|
23109
|
+
return JSON.stringify(value);
|
|
23110
|
+
}
|
|
23111
|
+
mapFromDriverValue(value) {
|
|
23112
|
+
if (typeof value === "string") {
|
|
23113
|
+
try {
|
|
23114
|
+
return JSON.parse(value);
|
|
23115
|
+
} catch {
|
|
23116
|
+
return value;
|
|
23117
|
+
}
|
|
23118
|
+
}
|
|
23119
|
+
return value;
|
|
23120
|
+
}
|
|
23121
|
+
}
|
|
23122
|
+
function json(name) {
|
|
23123
|
+
return new PgJsonBuilder(name ?? "");
|
|
23124
|
+
}
|
|
23125
|
+
|
|
23126
|
+
// node_modules/drizzle-orm/pg-core/columns/jsonb.js
|
|
23127
|
+
class PgJsonbBuilder extends PgColumnBuilder {
|
|
23128
|
+
static [entityKind] = "PgJsonbBuilder";
|
|
23129
|
+
constructor(name) {
|
|
23130
|
+
super(name, "json", "PgJsonb");
|
|
23131
|
+
}
|
|
23132
|
+
build(table) {
|
|
23133
|
+
return new PgJsonb(table, this.config);
|
|
23134
|
+
}
|
|
23135
|
+
}
|
|
23136
|
+
|
|
23137
|
+
class PgJsonb extends PgColumn {
|
|
23138
|
+
static [entityKind] = "PgJsonb";
|
|
23139
|
+
constructor(table, config) {
|
|
23140
|
+
super(table, config);
|
|
23141
|
+
}
|
|
23142
|
+
getSQLType() {
|
|
23143
|
+
return "jsonb";
|
|
23144
|
+
}
|
|
23145
|
+
mapToDriverValue(value) {
|
|
23146
|
+
return JSON.stringify(value);
|
|
23147
|
+
}
|
|
23148
|
+
mapFromDriverValue(value) {
|
|
23149
|
+
if (typeof value === "string") {
|
|
23150
|
+
try {
|
|
23151
|
+
return JSON.parse(value);
|
|
23152
|
+
} catch {
|
|
23153
|
+
return value;
|
|
23154
|
+
}
|
|
23155
|
+
}
|
|
23156
|
+
return value;
|
|
23157
|
+
}
|
|
23158
|
+
}
|
|
23159
|
+
function jsonb(name) {
|
|
23160
|
+
return new PgJsonbBuilder(name ?? "");
|
|
23161
|
+
}
|
|
23162
|
+
|
|
23163
|
+
// node_modules/drizzle-orm/pg-core/columns/line.js
|
|
23164
|
+
class PgLineBuilder extends PgColumnBuilder {
|
|
23165
|
+
static [entityKind] = "PgLineBuilder";
|
|
23166
|
+
constructor(name) {
|
|
23167
|
+
super(name, "array", "PgLine");
|
|
23168
|
+
}
|
|
23169
|
+
build(table) {
|
|
23170
|
+
return new PgLineTuple(table, this.config);
|
|
23171
|
+
}
|
|
23172
|
+
}
|
|
23173
|
+
|
|
23174
|
+
class PgLineTuple extends PgColumn {
|
|
23175
|
+
static [entityKind] = "PgLine";
|
|
23176
|
+
getSQLType() {
|
|
23177
|
+
return "line";
|
|
23178
|
+
}
|
|
23179
|
+
mapFromDriverValue(value) {
|
|
23180
|
+
const [a, b, c] = value.slice(1, -1).split(",");
|
|
23181
|
+
return [Number.parseFloat(a), Number.parseFloat(b), Number.parseFloat(c)];
|
|
23182
|
+
}
|
|
23183
|
+
mapToDriverValue(value) {
|
|
23184
|
+
return `{${value[0]},${value[1]},${value[2]}}`;
|
|
23185
|
+
}
|
|
23186
|
+
}
|
|
23187
|
+
|
|
23188
|
+
class PgLineABCBuilder extends PgColumnBuilder {
|
|
23189
|
+
static [entityKind] = "PgLineABCBuilder";
|
|
23190
|
+
constructor(name) {
|
|
23191
|
+
super(name, "json", "PgLineABC");
|
|
23192
|
+
}
|
|
23193
|
+
build(table) {
|
|
23194
|
+
return new PgLineABC(table, this.config);
|
|
23195
|
+
}
|
|
23196
|
+
}
|
|
23197
|
+
|
|
23198
|
+
class PgLineABC extends PgColumn {
|
|
23199
|
+
static [entityKind] = "PgLineABC";
|
|
23200
|
+
getSQLType() {
|
|
23201
|
+
return "line";
|
|
23202
|
+
}
|
|
23203
|
+
mapFromDriverValue(value) {
|
|
23204
|
+
const [a, b, c] = value.slice(1, -1).split(",");
|
|
23205
|
+
return { a: Number.parseFloat(a), b: Number.parseFloat(b), c: Number.parseFloat(c) };
|
|
23206
|
+
}
|
|
23207
|
+
mapToDriverValue(value) {
|
|
23208
|
+
return `{${value.a},${value.b},${value.c}}`;
|
|
23209
|
+
}
|
|
23210
|
+
}
|
|
23211
|
+
function line(a, b) {
|
|
23212
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23213
|
+
if (!config?.mode || config.mode === "tuple") {
|
|
23214
|
+
return new PgLineBuilder(name);
|
|
23215
|
+
}
|
|
23216
|
+
return new PgLineABCBuilder(name);
|
|
23217
|
+
}
|
|
23218
|
+
|
|
23219
|
+
// node_modules/drizzle-orm/pg-core/columns/macaddr.js
|
|
23220
|
+
class PgMacaddrBuilder extends PgColumnBuilder {
|
|
23221
|
+
static [entityKind] = "PgMacaddrBuilder";
|
|
23222
|
+
constructor(name) {
|
|
23223
|
+
super(name, "string", "PgMacaddr");
|
|
23224
|
+
}
|
|
23225
|
+
build(table) {
|
|
23226
|
+
return new PgMacaddr(table, this.config);
|
|
23227
|
+
}
|
|
23228
|
+
}
|
|
23229
|
+
|
|
23230
|
+
class PgMacaddr extends PgColumn {
|
|
23231
|
+
static [entityKind] = "PgMacaddr";
|
|
23232
|
+
getSQLType() {
|
|
23233
|
+
return "macaddr";
|
|
23234
|
+
}
|
|
23235
|
+
}
|
|
23236
|
+
function macaddr(name) {
|
|
23237
|
+
return new PgMacaddrBuilder(name ?? "");
|
|
23238
|
+
}
|
|
23239
|
+
|
|
23240
|
+
// node_modules/drizzle-orm/pg-core/columns/macaddr8.js
|
|
23241
|
+
class PgMacaddr8Builder extends PgColumnBuilder {
|
|
23242
|
+
static [entityKind] = "PgMacaddr8Builder";
|
|
23243
|
+
constructor(name) {
|
|
23244
|
+
super(name, "string", "PgMacaddr8");
|
|
23245
|
+
}
|
|
23246
|
+
build(table) {
|
|
23247
|
+
return new PgMacaddr8(table, this.config);
|
|
23248
|
+
}
|
|
23249
|
+
}
|
|
23250
|
+
|
|
23251
|
+
class PgMacaddr8 extends PgColumn {
|
|
23252
|
+
static [entityKind] = "PgMacaddr8";
|
|
23253
|
+
getSQLType() {
|
|
23254
|
+
return "macaddr8";
|
|
23255
|
+
}
|
|
23256
|
+
}
|
|
23257
|
+
function macaddr8(name) {
|
|
23258
|
+
return new PgMacaddr8Builder(name ?? "");
|
|
23259
|
+
}
|
|
23260
|
+
|
|
23261
|
+
// node_modules/drizzle-orm/pg-core/columns/numeric.js
|
|
23262
|
+
class PgNumericBuilder extends PgColumnBuilder {
|
|
23263
|
+
static [entityKind] = "PgNumericBuilder";
|
|
23264
|
+
constructor(name, precision, scale) {
|
|
23265
|
+
super(name, "string", "PgNumeric");
|
|
23266
|
+
this.config.precision = precision;
|
|
23267
|
+
this.config.scale = scale;
|
|
23268
|
+
}
|
|
23269
|
+
build(table) {
|
|
23270
|
+
return new PgNumeric(table, this.config);
|
|
23271
|
+
}
|
|
23272
|
+
}
|
|
23273
|
+
|
|
23274
|
+
class PgNumeric extends PgColumn {
|
|
23275
|
+
static [entityKind] = "PgNumeric";
|
|
23276
|
+
precision;
|
|
23277
|
+
scale;
|
|
23278
|
+
constructor(table, config) {
|
|
23279
|
+
super(table, config);
|
|
23280
|
+
this.precision = config.precision;
|
|
23281
|
+
this.scale = config.scale;
|
|
23282
|
+
}
|
|
23283
|
+
mapFromDriverValue(value) {
|
|
23284
|
+
if (typeof value === "string")
|
|
23285
|
+
return value;
|
|
23286
|
+
return String(value);
|
|
23287
|
+
}
|
|
23288
|
+
getSQLType() {
|
|
23289
|
+
if (this.precision !== undefined && this.scale !== undefined) {
|
|
23290
|
+
return `numeric(${this.precision}, ${this.scale})`;
|
|
23291
|
+
} else if (this.precision === undefined) {
|
|
23292
|
+
return "numeric";
|
|
23293
|
+
} else {
|
|
23294
|
+
return `numeric(${this.precision})`;
|
|
23295
|
+
}
|
|
23296
|
+
}
|
|
23297
|
+
}
|
|
23298
|
+
|
|
23299
|
+
class PgNumericNumberBuilder extends PgColumnBuilder {
|
|
23300
|
+
static [entityKind] = "PgNumericNumberBuilder";
|
|
23301
|
+
constructor(name, precision, scale) {
|
|
23302
|
+
super(name, "number", "PgNumericNumber");
|
|
23303
|
+
this.config.precision = precision;
|
|
23304
|
+
this.config.scale = scale;
|
|
23305
|
+
}
|
|
23306
|
+
build(table) {
|
|
23307
|
+
return new PgNumericNumber(table, this.config);
|
|
23308
|
+
}
|
|
23309
|
+
}
|
|
23310
|
+
|
|
23311
|
+
class PgNumericNumber extends PgColumn {
|
|
23312
|
+
static [entityKind] = "PgNumericNumber";
|
|
23313
|
+
precision;
|
|
23314
|
+
scale;
|
|
23315
|
+
constructor(table, config) {
|
|
23316
|
+
super(table, config);
|
|
23317
|
+
this.precision = config.precision;
|
|
23318
|
+
this.scale = config.scale;
|
|
23319
|
+
}
|
|
23320
|
+
mapFromDriverValue(value) {
|
|
23321
|
+
if (typeof value === "number")
|
|
23322
|
+
return value;
|
|
23323
|
+
return Number(value);
|
|
23324
|
+
}
|
|
23325
|
+
mapToDriverValue = String;
|
|
23326
|
+
getSQLType() {
|
|
23327
|
+
if (this.precision !== undefined && this.scale !== undefined) {
|
|
23328
|
+
return `numeric(${this.precision}, ${this.scale})`;
|
|
23329
|
+
} else if (this.precision === undefined) {
|
|
23330
|
+
return "numeric";
|
|
23331
|
+
} else {
|
|
23332
|
+
return `numeric(${this.precision})`;
|
|
23333
|
+
}
|
|
23334
|
+
}
|
|
23335
|
+
}
|
|
23336
|
+
|
|
23337
|
+
class PgNumericBigIntBuilder extends PgColumnBuilder {
|
|
23338
|
+
static [entityKind] = "PgNumericBigIntBuilder";
|
|
23339
|
+
constructor(name, precision, scale) {
|
|
23340
|
+
super(name, "bigint", "PgNumericBigInt");
|
|
23341
|
+
this.config.precision = precision;
|
|
23342
|
+
this.config.scale = scale;
|
|
23343
|
+
}
|
|
23344
|
+
build(table) {
|
|
23345
|
+
return new PgNumericBigInt(table, this.config);
|
|
23346
|
+
}
|
|
23347
|
+
}
|
|
23348
|
+
|
|
23349
|
+
class PgNumericBigInt extends PgColumn {
|
|
23350
|
+
static [entityKind] = "PgNumericBigInt";
|
|
23351
|
+
precision;
|
|
23352
|
+
scale;
|
|
23353
|
+
constructor(table, config) {
|
|
23354
|
+
super(table, config);
|
|
23355
|
+
this.precision = config.precision;
|
|
23356
|
+
this.scale = config.scale;
|
|
23357
|
+
}
|
|
23358
|
+
mapFromDriverValue = BigInt;
|
|
23359
|
+
mapToDriverValue = String;
|
|
23360
|
+
getSQLType() {
|
|
23361
|
+
if (this.precision !== undefined && this.scale !== undefined) {
|
|
23362
|
+
return `numeric(${this.precision}, ${this.scale})`;
|
|
23363
|
+
} else if (this.precision === undefined) {
|
|
23364
|
+
return "numeric";
|
|
23365
|
+
} else {
|
|
23366
|
+
return `numeric(${this.precision})`;
|
|
23367
|
+
}
|
|
23368
|
+
}
|
|
23369
|
+
}
|
|
23370
|
+
function numeric(a, b) {
|
|
23371
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23372
|
+
const mode = config?.mode;
|
|
23373
|
+
return mode === "number" ? new PgNumericNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new PgNumericBigIntBuilder(name, config?.precision, config?.scale) : new PgNumericBuilder(name, config?.precision, config?.scale);
|
|
23374
|
+
}
|
|
23375
|
+
|
|
23376
|
+
// node_modules/drizzle-orm/pg-core/columns/point.js
|
|
23377
|
+
class PgPointTupleBuilder extends PgColumnBuilder {
|
|
23378
|
+
static [entityKind] = "PgPointTupleBuilder";
|
|
23379
|
+
constructor(name) {
|
|
23380
|
+
super(name, "array", "PgPointTuple");
|
|
23381
|
+
}
|
|
23382
|
+
build(table) {
|
|
23383
|
+
return new PgPointTuple(table, this.config);
|
|
23384
|
+
}
|
|
23385
|
+
}
|
|
23386
|
+
|
|
23387
|
+
class PgPointTuple extends PgColumn {
|
|
23388
|
+
static [entityKind] = "PgPointTuple";
|
|
23389
|
+
getSQLType() {
|
|
23390
|
+
return "point";
|
|
23391
|
+
}
|
|
23392
|
+
mapFromDriverValue(value) {
|
|
23393
|
+
if (typeof value === "string") {
|
|
23394
|
+
const [x, y] = value.slice(1, -1).split(",");
|
|
23395
|
+
return [Number.parseFloat(x), Number.parseFloat(y)];
|
|
23396
|
+
}
|
|
23397
|
+
return [value.x, value.y];
|
|
23398
|
+
}
|
|
23399
|
+
mapToDriverValue(value) {
|
|
23400
|
+
return `(${value[0]},${value[1]})`;
|
|
23401
|
+
}
|
|
23402
|
+
}
|
|
23403
|
+
|
|
23404
|
+
class PgPointObjectBuilder extends PgColumnBuilder {
|
|
23405
|
+
static [entityKind] = "PgPointObjectBuilder";
|
|
23406
|
+
constructor(name) {
|
|
23407
|
+
super(name, "json", "PgPointObject");
|
|
23408
|
+
}
|
|
23409
|
+
build(table) {
|
|
23410
|
+
return new PgPointObject(table, this.config);
|
|
23411
|
+
}
|
|
23412
|
+
}
|
|
23413
|
+
|
|
23414
|
+
class PgPointObject extends PgColumn {
|
|
23415
|
+
static [entityKind] = "PgPointObject";
|
|
23416
|
+
getSQLType() {
|
|
23417
|
+
return "point";
|
|
23418
|
+
}
|
|
23419
|
+
mapFromDriverValue(value) {
|
|
23420
|
+
if (typeof value === "string") {
|
|
23421
|
+
const [x, y] = value.slice(1, -1).split(",");
|
|
23422
|
+
return { x: Number.parseFloat(x), y: Number.parseFloat(y) };
|
|
23423
|
+
}
|
|
23424
|
+
return value;
|
|
23425
|
+
}
|
|
23426
|
+
mapToDriverValue(value) {
|
|
23427
|
+
return `(${value.x},${value.y})`;
|
|
23428
|
+
}
|
|
23429
|
+
}
|
|
23430
|
+
function point(a, b) {
|
|
23431
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23432
|
+
if (!config?.mode || config.mode === "tuple") {
|
|
23433
|
+
return new PgPointTupleBuilder(name);
|
|
23434
|
+
}
|
|
23435
|
+
return new PgPointObjectBuilder(name);
|
|
23436
|
+
}
|
|
23437
|
+
|
|
23438
|
+
// node_modules/drizzle-orm/pg-core/columns/postgis_extension/utils.js
|
|
23439
|
+
function hexToBytes(hex) {
|
|
23440
|
+
const bytes = [];
|
|
23441
|
+
for (let c = 0;c < hex.length; c += 2) {
|
|
23442
|
+
bytes.push(Number.parseInt(hex.slice(c, c + 2), 16));
|
|
23443
|
+
}
|
|
23444
|
+
return new Uint8Array(bytes);
|
|
23445
|
+
}
|
|
23446
|
+
function bytesToFloat64(bytes, offset) {
|
|
23447
|
+
const buffer = new ArrayBuffer(8);
|
|
23448
|
+
const view = new DataView(buffer);
|
|
23449
|
+
for (let i = 0;i < 8; i++) {
|
|
23450
|
+
view.setUint8(i, bytes[offset + i]);
|
|
23451
|
+
}
|
|
23452
|
+
return view.getFloat64(0, true);
|
|
23453
|
+
}
|
|
23454
|
+
function parseEWKB(hex) {
|
|
23455
|
+
const bytes = hexToBytes(hex);
|
|
23456
|
+
let offset = 0;
|
|
23457
|
+
const byteOrder = bytes[offset];
|
|
23458
|
+
offset += 1;
|
|
23459
|
+
const view = new DataView(bytes.buffer);
|
|
23460
|
+
const geomType = view.getUint32(offset, byteOrder === 1);
|
|
23461
|
+
offset += 4;
|
|
23462
|
+
let _srid;
|
|
23463
|
+
if (geomType & 536870912) {
|
|
23464
|
+
_srid = view.getUint32(offset, byteOrder === 1);
|
|
23465
|
+
offset += 4;
|
|
23466
|
+
}
|
|
23467
|
+
if ((geomType & 65535) === 1) {
|
|
23468
|
+
const x = bytesToFloat64(bytes, offset);
|
|
23469
|
+
offset += 8;
|
|
23470
|
+
const y = bytesToFloat64(bytes, offset);
|
|
23471
|
+
offset += 8;
|
|
23472
|
+
return [x, y];
|
|
23473
|
+
}
|
|
23474
|
+
throw new Error("Unsupported geometry type");
|
|
23475
|
+
}
|
|
23476
|
+
|
|
23477
|
+
// node_modules/drizzle-orm/pg-core/columns/postgis_extension/geometry.js
|
|
23478
|
+
class PgGeometryBuilder extends PgColumnBuilder {
|
|
23479
|
+
static [entityKind] = "PgGeometryBuilder";
|
|
23480
|
+
constructor(name) {
|
|
23481
|
+
super(name, "array", "PgGeometry");
|
|
23482
|
+
}
|
|
23483
|
+
build(table) {
|
|
23484
|
+
return new PgGeometry(table, this.config);
|
|
23485
|
+
}
|
|
23486
|
+
}
|
|
23487
|
+
|
|
23488
|
+
class PgGeometry extends PgColumn {
|
|
23489
|
+
static [entityKind] = "PgGeometry";
|
|
23490
|
+
getSQLType() {
|
|
23491
|
+
return "geometry(point)";
|
|
23492
|
+
}
|
|
23493
|
+
mapFromDriverValue(value) {
|
|
23494
|
+
return parseEWKB(value);
|
|
23495
|
+
}
|
|
23496
|
+
mapToDriverValue(value) {
|
|
23497
|
+
return `point(${value[0]} ${value[1]})`;
|
|
23498
|
+
}
|
|
23499
|
+
}
|
|
23500
|
+
|
|
23501
|
+
class PgGeometryObjectBuilder extends PgColumnBuilder {
|
|
23502
|
+
static [entityKind] = "PgGeometryObjectBuilder";
|
|
23503
|
+
constructor(name) {
|
|
23504
|
+
super(name, "json", "PgGeometryObject");
|
|
23505
|
+
}
|
|
23506
|
+
build(table) {
|
|
23507
|
+
return new PgGeometryObject(table, this.config);
|
|
23508
|
+
}
|
|
23509
|
+
}
|
|
23510
|
+
|
|
23511
|
+
class PgGeometryObject extends PgColumn {
|
|
23512
|
+
static [entityKind] = "PgGeometryObject";
|
|
23513
|
+
getSQLType() {
|
|
23514
|
+
return "geometry(point)";
|
|
23515
|
+
}
|
|
23516
|
+
mapFromDriverValue(value) {
|
|
23517
|
+
const parsed = parseEWKB(value);
|
|
23518
|
+
return { x: parsed[0], y: parsed[1] };
|
|
23519
|
+
}
|
|
23520
|
+
mapToDriverValue(value) {
|
|
23521
|
+
return `point(${value.x} ${value.y})`;
|
|
23522
|
+
}
|
|
23523
|
+
}
|
|
23524
|
+
function geometry(a, b) {
|
|
23525
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23526
|
+
if (!config?.mode || config.mode === "tuple") {
|
|
23527
|
+
return new PgGeometryBuilder(name);
|
|
23528
|
+
}
|
|
23529
|
+
return new PgGeometryObjectBuilder(name);
|
|
23530
|
+
}
|
|
23531
|
+
|
|
23532
|
+
// node_modules/drizzle-orm/pg-core/columns/real.js
|
|
23533
|
+
class PgRealBuilder extends PgColumnBuilder {
|
|
23534
|
+
static [entityKind] = "PgRealBuilder";
|
|
23535
|
+
constructor(name, length) {
|
|
23536
|
+
super(name, "number", "PgReal");
|
|
23537
|
+
this.config.length = length;
|
|
23538
|
+
}
|
|
23539
|
+
build(table) {
|
|
23540
|
+
return new PgReal(table, this.config);
|
|
23541
|
+
}
|
|
23542
|
+
}
|
|
23543
|
+
|
|
23544
|
+
class PgReal extends PgColumn {
|
|
23545
|
+
static [entityKind] = "PgReal";
|
|
23546
|
+
constructor(table, config) {
|
|
23547
|
+
super(table, config);
|
|
23548
|
+
}
|
|
23549
|
+
getSQLType() {
|
|
23550
|
+
return "real";
|
|
23551
|
+
}
|
|
23552
|
+
mapFromDriverValue = (value) => {
|
|
23553
|
+
if (typeof value === "string") {
|
|
23554
|
+
return Number.parseFloat(value);
|
|
23555
|
+
}
|
|
23556
|
+
return value;
|
|
23557
|
+
};
|
|
23558
|
+
}
|
|
23559
|
+
function real(name) {
|
|
23560
|
+
return new PgRealBuilder(name ?? "");
|
|
23561
|
+
}
|
|
23562
|
+
|
|
23563
|
+
// node_modules/drizzle-orm/pg-core/columns/serial.js
|
|
23564
|
+
class PgSerialBuilder extends PgColumnBuilder {
|
|
23565
|
+
static [entityKind] = "PgSerialBuilder";
|
|
23566
|
+
constructor(name) {
|
|
23567
|
+
super(name, "number", "PgSerial");
|
|
23568
|
+
this.config.hasDefault = true;
|
|
23569
|
+
this.config.notNull = true;
|
|
23570
|
+
}
|
|
23571
|
+
build(table) {
|
|
23572
|
+
return new PgSerial(table, this.config);
|
|
23573
|
+
}
|
|
23574
|
+
}
|
|
23575
|
+
|
|
23576
|
+
class PgSerial extends PgColumn {
|
|
23577
|
+
static [entityKind] = "PgSerial";
|
|
23578
|
+
getSQLType() {
|
|
23579
|
+
return "serial";
|
|
23580
|
+
}
|
|
23581
|
+
}
|
|
23582
|
+
function serial(name) {
|
|
23583
|
+
return new PgSerialBuilder(name ?? "");
|
|
23584
|
+
}
|
|
23585
|
+
|
|
23586
|
+
// node_modules/drizzle-orm/pg-core/columns/smallint.js
|
|
23587
|
+
class PgSmallIntBuilder extends PgIntColumnBaseBuilder {
|
|
23588
|
+
static [entityKind] = "PgSmallIntBuilder";
|
|
23589
|
+
constructor(name) {
|
|
23590
|
+
super(name, "number", "PgSmallInt");
|
|
23591
|
+
}
|
|
23592
|
+
build(table) {
|
|
23593
|
+
return new PgSmallInt(table, this.config);
|
|
23594
|
+
}
|
|
23595
|
+
}
|
|
23596
|
+
|
|
23597
|
+
class PgSmallInt extends PgColumn {
|
|
23598
|
+
static [entityKind] = "PgSmallInt";
|
|
23599
|
+
getSQLType() {
|
|
23600
|
+
return "smallint";
|
|
23601
|
+
}
|
|
23602
|
+
mapFromDriverValue = (value) => {
|
|
23603
|
+
if (typeof value === "string") {
|
|
23604
|
+
return Number(value);
|
|
23605
|
+
}
|
|
23606
|
+
return value;
|
|
23607
|
+
};
|
|
23608
|
+
}
|
|
23609
|
+
function smallint(name) {
|
|
23610
|
+
return new PgSmallIntBuilder(name ?? "");
|
|
23611
|
+
}
|
|
23612
|
+
|
|
23613
|
+
// node_modules/drizzle-orm/pg-core/columns/smallserial.js
|
|
23614
|
+
class PgSmallSerialBuilder extends PgColumnBuilder {
|
|
23615
|
+
static [entityKind] = "PgSmallSerialBuilder";
|
|
23616
|
+
constructor(name) {
|
|
23617
|
+
super(name, "number", "PgSmallSerial");
|
|
23618
|
+
this.config.hasDefault = true;
|
|
23619
|
+
this.config.notNull = true;
|
|
23620
|
+
}
|
|
23621
|
+
build(table) {
|
|
23622
|
+
return new PgSmallSerial(table, this.config);
|
|
23623
|
+
}
|
|
23624
|
+
}
|
|
23625
|
+
|
|
23626
|
+
class PgSmallSerial extends PgColumn {
|
|
23627
|
+
static [entityKind] = "PgSmallSerial";
|
|
23628
|
+
getSQLType() {
|
|
23629
|
+
return "smallserial";
|
|
23630
|
+
}
|
|
23631
|
+
}
|
|
23632
|
+
function smallserial(name) {
|
|
23633
|
+
return new PgSmallSerialBuilder(name ?? "");
|
|
23634
|
+
}
|
|
23635
|
+
|
|
23636
|
+
// node_modules/drizzle-orm/pg-core/columns/text.js
|
|
23637
|
+
class PgTextBuilder extends PgColumnBuilder {
|
|
23638
|
+
static [entityKind] = "PgTextBuilder";
|
|
23639
|
+
constructor(name, config) {
|
|
23640
|
+
super(name, "string", "PgText");
|
|
23641
|
+
this.config.enumValues = config.enum;
|
|
23642
|
+
}
|
|
23643
|
+
build(table) {
|
|
23644
|
+
return new PgText(table, this.config);
|
|
23645
|
+
}
|
|
23646
|
+
}
|
|
23647
|
+
|
|
23648
|
+
class PgText extends PgColumn {
|
|
23649
|
+
static [entityKind] = "PgText";
|
|
23650
|
+
enumValues = this.config.enumValues;
|
|
23651
|
+
getSQLType() {
|
|
23652
|
+
return "text";
|
|
23653
|
+
}
|
|
23654
|
+
}
|
|
23655
|
+
function text(a, b = {}) {
|
|
23656
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23657
|
+
return new PgTextBuilder(name, config);
|
|
23658
|
+
}
|
|
23659
|
+
|
|
23660
|
+
// node_modules/drizzle-orm/pg-core/columns/time.js
|
|
23661
|
+
class PgTimeBuilder extends PgDateColumnBaseBuilder {
|
|
23662
|
+
constructor(name, withTimezone, precision) {
|
|
23663
|
+
super(name, "string", "PgTime");
|
|
23664
|
+
this.withTimezone = withTimezone;
|
|
23665
|
+
this.precision = precision;
|
|
23666
|
+
this.config.withTimezone = withTimezone;
|
|
23667
|
+
this.config.precision = precision;
|
|
23668
|
+
}
|
|
23669
|
+
static [entityKind] = "PgTimeBuilder";
|
|
23670
|
+
build(table) {
|
|
23671
|
+
return new PgTime(table, this.config);
|
|
23672
|
+
}
|
|
23673
|
+
}
|
|
23674
|
+
|
|
23675
|
+
class PgTime extends PgColumn {
|
|
23676
|
+
static [entityKind] = "PgTime";
|
|
23677
|
+
withTimezone;
|
|
23678
|
+
precision;
|
|
23679
|
+
constructor(table, config) {
|
|
23680
|
+
super(table, config);
|
|
23681
|
+
this.withTimezone = config.withTimezone;
|
|
23682
|
+
this.precision = config.precision;
|
|
23683
|
+
}
|
|
23684
|
+
getSQLType() {
|
|
23685
|
+
const precision = this.precision === undefined ? "" : `(${this.precision})`;
|
|
23686
|
+
return `time${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
23687
|
+
}
|
|
23688
|
+
}
|
|
23689
|
+
function time(a, b = {}) {
|
|
23690
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23691
|
+
return new PgTimeBuilder(name, config.withTimezone ?? false, config.precision);
|
|
23692
|
+
}
|
|
23693
|
+
|
|
23694
|
+
// node_modules/drizzle-orm/pg-core/columns/timestamp.js
|
|
23695
|
+
class PgTimestampBuilder extends PgDateColumnBaseBuilder {
|
|
23696
|
+
static [entityKind] = "PgTimestampBuilder";
|
|
23697
|
+
constructor(name, withTimezone, precision) {
|
|
23698
|
+
super(name, "date", "PgTimestamp");
|
|
23699
|
+
this.config.withTimezone = withTimezone;
|
|
23700
|
+
this.config.precision = precision;
|
|
23701
|
+
}
|
|
23702
|
+
build(table) {
|
|
23703
|
+
return new PgTimestamp(table, this.config);
|
|
23704
|
+
}
|
|
23705
|
+
}
|
|
23706
|
+
|
|
23707
|
+
class PgTimestamp extends PgColumn {
|
|
23708
|
+
static [entityKind] = "PgTimestamp";
|
|
23709
|
+
withTimezone;
|
|
23710
|
+
precision;
|
|
23711
|
+
constructor(table, config) {
|
|
23712
|
+
super(table, config);
|
|
23713
|
+
this.withTimezone = config.withTimezone;
|
|
23714
|
+
this.precision = config.precision;
|
|
23715
|
+
}
|
|
23716
|
+
getSQLType() {
|
|
23717
|
+
const precision = this.precision === undefined ? "" : ` (${this.precision})`;
|
|
23718
|
+
return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
23719
|
+
}
|
|
23720
|
+
mapFromDriverValue = (value) => {
|
|
23721
|
+
return new Date(this.withTimezone ? value : value + "+0000");
|
|
23722
|
+
};
|
|
23723
|
+
mapToDriverValue = (value) => {
|
|
23724
|
+
return value.toISOString();
|
|
23725
|
+
};
|
|
23726
|
+
}
|
|
23727
|
+
|
|
23728
|
+
class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {
|
|
23729
|
+
static [entityKind] = "PgTimestampStringBuilder";
|
|
23730
|
+
constructor(name, withTimezone, precision) {
|
|
23731
|
+
super(name, "string", "PgTimestampString");
|
|
23732
|
+
this.config.withTimezone = withTimezone;
|
|
23733
|
+
this.config.precision = precision;
|
|
23734
|
+
}
|
|
23735
|
+
build(table) {
|
|
23736
|
+
return new PgTimestampString(table, this.config);
|
|
23737
|
+
}
|
|
23738
|
+
}
|
|
23739
|
+
|
|
23740
|
+
class PgTimestampString extends PgColumn {
|
|
23741
|
+
static [entityKind] = "PgTimestampString";
|
|
23742
|
+
withTimezone;
|
|
23743
|
+
precision;
|
|
23744
|
+
constructor(table, config) {
|
|
23745
|
+
super(table, config);
|
|
23746
|
+
this.withTimezone = config.withTimezone;
|
|
23747
|
+
this.precision = config.precision;
|
|
23748
|
+
}
|
|
23749
|
+
getSQLType() {
|
|
23750
|
+
const precision = this.precision === undefined ? "" : `(${this.precision})`;
|
|
23751
|
+
return `timestamp${precision}${this.withTimezone ? " with time zone" : ""}`;
|
|
23752
|
+
}
|
|
23753
|
+
}
|
|
23754
|
+
function timestamp(a, b = {}) {
|
|
23755
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23756
|
+
if (config?.mode === "string") {
|
|
23757
|
+
return new PgTimestampStringBuilder(name, config.withTimezone ?? false, config.precision);
|
|
23758
|
+
}
|
|
23759
|
+
return new PgTimestampBuilder(name, config?.withTimezone ?? false, config?.precision);
|
|
23760
|
+
}
|
|
23761
|
+
|
|
23762
|
+
// node_modules/drizzle-orm/pg-core/columns/uuid.js
|
|
23763
|
+
class PgUUIDBuilder extends PgColumnBuilder {
|
|
23764
|
+
static [entityKind] = "PgUUIDBuilder";
|
|
23765
|
+
constructor(name) {
|
|
23766
|
+
super(name, "string", "PgUUID");
|
|
23767
|
+
}
|
|
23768
|
+
defaultRandom() {
|
|
23769
|
+
return this.default(sql`gen_random_uuid()`);
|
|
23770
|
+
}
|
|
23771
|
+
build(table) {
|
|
23772
|
+
return new PgUUID(table, this.config);
|
|
23773
|
+
}
|
|
23774
|
+
}
|
|
23775
|
+
|
|
23776
|
+
class PgUUID extends PgColumn {
|
|
23777
|
+
static [entityKind] = "PgUUID";
|
|
23778
|
+
getSQLType() {
|
|
23779
|
+
return "uuid";
|
|
23780
|
+
}
|
|
23781
|
+
}
|
|
23782
|
+
function uuid(name) {
|
|
23783
|
+
return new PgUUIDBuilder(name ?? "");
|
|
23784
|
+
}
|
|
23785
|
+
|
|
23786
|
+
// node_modules/drizzle-orm/pg-core/columns/varchar.js
|
|
23787
|
+
class PgVarcharBuilder extends PgColumnBuilder {
|
|
23788
|
+
static [entityKind] = "PgVarcharBuilder";
|
|
23789
|
+
constructor(name, config) {
|
|
23790
|
+
super(name, "string", "PgVarchar");
|
|
23791
|
+
this.config.length = config.length;
|
|
23792
|
+
this.config.enumValues = config.enum;
|
|
23793
|
+
}
|
|
23794
|
+
build(table) {
|
|
23795
|
+
return new PgVarchar(table, this.config);
|
|
23796
|
+
}
|
|
23797
|
+
}
|
|
23798
|
+
|
|
23799
|
+
class PgVarchar extends PgColumn {
|
|
23800
|
+
static [entityKind] = "PgVarchar";
|
|
23801
|
+
length = this.config.length;
|
|
23802
|
+
enumValues = this.config.enumValues;
|
|
23803
|
+
getSQLType() {
|
|
23804
|
+
return this.length === undefined ? `varchar` : `varchar(${this.length})`;
|
|
23805
|
+
}
|
|
23806
|
+
}
|
|
23807
|
+
function varchar(a, b = {}) {
|
|
23808
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23809
|
+
return new PgVarcharBuilder(name, config);
|
|
23810
|
+
}
|
|
23811
|
+
|
|
23812
|
+
// node_modules/drizzle-orm/pg-core/columns/vector_extension/bit.js
|
|
23813
|
+
class PgBinaryVectorBuilder extends PgColumnBuilder {
|
|
23814
|
+
static [entityKind] = "PgBinaryVectorBuilder";
|
|
23815
|
+
constructor(name, config) {
|
|
23816
|
+
super(name, "string", "PgBinaryVector");
|
|
23817
|
+
this.config.dimensions = config.dimensions;
|
|
23818
|
+
}
|
|
23819
|
+
build(table) {
|
|
23820
|
+
return new PgBinaryVector(table, this.config);
|
|
23821
|
+
}
|
|
23822
|
+
}
|
|
23823
|
+
|
|
23824
|
+
class PgBinaryVector extends PgColumn {
|
|
23825
|
+
static [entityKind] = "PgBinaryVector";
|
|
23826
|
+
dimensions = this.config.dimensions;
|
|
23827
|
+
getSQLType() {
|
|
23828
|
+
return `bit(${this.dimensions})`;
|
|
23829
|
+
}
|
|
23830
|
+
}
|
|
23831
|
+
function bit(a, b) {
|
|
23832
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23833
|
+
return new PgBinaryVectorBuilder(name, config);
|
|
23834
|
+
}
|
|
23835
|
+
|
|
23836
|
+
// node_modules/drizzle-orm/pg-core/columns/vector_extension/halfvec.js
|
|
23837
|
+
class PgHalfVectorBuilder extends PgColumnBuilder {
|
|
23838
|
+
static [entityKind] = "PgHalfVectorBuilder";
|
|
23839
|
+
constructor(name, config) {
|
|
23840
|
+
super(name, "array", "PgHalfVector");
|
|
23841
|
+
this.config.dimensions = config.dimensions;
|
|
23842
|
+
}
|
|
23843
|
+
build(table) {
|
|
23844
|
+
return new PgHalfVector(table, this.config);
|
|
23845
|
+
}
|
|
23846
|
+
}
|
|
23847
|
+
|
|
23848
|
+
class PgHalfVector extends PgColumn {
|
|
23849
|
+
static [entityKind] = "PgHalfVector";
|
|
23850
|
+
dimensions = this.config.dimensions;
|
|
23851
|
+
getSQLType() {
|
|
23852
|
+
return `halfvec(${this.dimensions})`;
|
|
23853
|
+
}
|
|
23854
|
+
mapToDriverValue(value) {
|
|
23855
|
+
return JSON.stringify(value);
|
|
23856
|
+
}
|
|
23857
|
+
mapFromDriverValue(value) {
|
|
23858
|
+
return value.slice(1, -1).split(",").map((v) => Number.parseFloat(v));
|
|
23859
|
+
}
|
|
23860
|
+
}
|
|
23861
|
+
function halfvec(a, b) {
|
|
23862
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23863
|
+
return new PgHalfVectorBuilder(name, config);
|
|
23864
|
+
}
|
|
23865
|
+
|
|
23866
|
+
// node_modules/drizzle-orm/pg-core/columns/vector_extension/sparsevec.js
|
|
23867
|
+
class PgSparseVectorBuilder extends PgColumnBuilder {
|
|
23868
|
+
static [entityKind] = "PgSparseVectorBuilder";
|
|
23869
|
+
constructor(name, config) {
|
|
23870
|
+
super(name, "string", "PgSparseVector");
|
|
23871
|
+
this.config.dimensions = config.dimensions;
|
|
23872
|
+
}
|
|
23873
|
+
build(table) {
|
|
23874
|
+
return new PgSparseVector(table, this.config);
|
|
23875
|
+
}
|
|
23876
|
+
}
|
|
23877
|
+
|
|
23878
|
+
class PgSparseVector extends PgColumn {
|
|
23879
|
+
static [entityKind] = "PgSparseVector";
|
|
23880
|
+
dimensions = this.config.dimensions;
|
|
23881
|
+
getSQLType() {
|
|
23882
|
+
return `sparsevec(${this.dimensions})`;
|
|
23883
|
+
}
|
|
23884
|
+
}
|
|
23885
|
+
function sparsevec(a, b) {
|
|
23886
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23887
|
+
return new PgSparseVectorBuilder(name, config);
|
|
23888
|
+
}
|
|
23889
|
+
|
|
23890
|
+
// node_modules/drizzle-orm/pg-core/columns/vector_extension/vector.js
|
|
23891
|
+
class PgVectorBuilder extends PgColumnBuilder {
|
|
23892
|
+
static [entityKind] = "PgVectorBuilder";
|
|
23893
|
+
constructor(name, config) {
|
|
23894
|
+
super(name, "array", "PgVector");
|
|
23895
|
+
this.config.dimensions = config.dimensions;
|
|
23896
|
+
}
|
|
23897
|
+
build(table) {
|
|
23898
|
+
return new PgVector(table, this.config);
|
|
23899
|
+
}
|
|
23900
|
+
}
|
|
23901
|
+
|
|
23902
|
+
class PgVector extends PgColumn {
|
|
23903
|
+
static [entityKind] = "PgVector";
|
|
23904
|
+
dimensions = this.config.dimensions;
|
|
23905
|
+
getSQLType() {
|
|
23906
|
+
return `vector(${this.dimensions})`;
|
|
23907
|
+
}
|
|
23908
|
+
mapToDriverValue(value) {
|
|
23909
|
+
return JSON.stringify(value);
|
|
23910
|
+
}
|
|
23911
|
+
mapFromDriverValue(value) {
|
|
23912
|
+
return value.slice(1, -1).split(",").map((v) => Number.parseFloat(v));
|
|
23913
|
+
}
|
|
23914
|
+
}
|
|
23915
|
+
function vector(a, b) {
|
|
23916
|
+
const { name, config } = getColumnNameAndConfig(a, b);
|
|
23917
|
+
return new PgVectorBuilder(name, config);
|
|
23918
|
+
}
|
|
23919
|
+
|
|
23920
|
+
// node_modules/drizzle-orm/pg-core/columns/all.js
|
|
23921
|
+
function getPgColumnBuilders() {
|
|
23922
|
+
return {
|
|
23923
|
+
bigint: bigint2,
|
|
23924
|
+
bigserial,
|
|
23925
|
+
boolean: boolean2,
|
|
23926
|
+
char,
|
|
23927
|
+
cidr,
|
|
23928
|
+
customType,
|
|
23929
|
+
date: date2,
|
|
23930
|
+
doublePrecision,
|
|
23931
|
+
inet,
|
|
23932
|
+
integer,
|
|
23933
|
+
interval,
|
|
23934
|
+
json,
|
|
23935
|
+
jsonb,
|
|
23936
|
+
line,
|
|
23937
|
+
macaddr,
|
|
23938
|
+
macaddr8,
|
|
23939
|
+
numeric,
|
|
23940
|
+
point,
|
|
23941
|
+
geometry,
|
|
23942
|
+
real,
|
|
23943
|
+
serial,
|
|
23944
|
+
smallint,
|
|
23945
|
+
smallserial,
|
|
23946
|
+
text,
|
|
23947
|
+
time,
|
|
23948
|
+
timestamp,
|
|
23949
|
+
uuid,
|
|
23950
|
+
varchar,
|
|
23951
|
+
bit,
|
|
23952
|
+
halfvec,
|
|
23953
|
+
sparsevec,
|
|
23954
|
+
vector
|
|
23955
|
+
};
|
|
23956
|
+
}
|
|
23957
|
+
|
|
23958
|
+
// node_modules/drizzle-orm/pg-core/table.js
|
|
23959
|
+
var InlineForeignKeys = Symbol.for("drizzle:PgInlineForeignKeys");
|
|
23960
|
+
var EnableRLS = Symbol.for("drizzle:EnableRLS");
|
|
23961
|
+
|
|
23962
|
+
class PgTable extends Table {
|
|
23963
|
+
static [entityKind] = "PgTable";
|
|
23964
|
+
static Symbol = Object.assign({}, Table.Symbol, {
|
|
23965
|
+
InlineForeignKeys,
|
|
23966
|
+
EnableRLS
|
|
23967
|
+
});
|
|
23968
|
+
[InlineForeignKeys] = [];
|
|
23969
|
+
[EnableRLS] = false;
|
|
23970
|
+
[Table.Symbol.ExtraConfigBuilder] = undefined;
|
|
23971
|
+
[Table.Symbol.ExtraConfigColumns] = {};
|
|
23972
|
+
}
|
|
23973
|
+
function pgTableWithSchema(name, columns, extraConfig, schema, baseName = name) {
|
|
23974
|
+
const rawTable = new PgTable(name, schema, baseName);
|
|
23975
|
+
const parsedColumns = typeof columns === "function" ? columns(getPgColumnBuilders()) : columns;
|
|
23976
|
+
const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
|
|
23977
|
+
const colBuilder = colBuilderBase;
|
|
23978
|
+
colBuilder.setName(name2);
|
|
23979
|
+
const column = colBuilder.build(rawTable);
|
|
23980
|
+
rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
|
|
23981
|
+
return [name2, column];
|
|
23982
|
+
}));
|
|
23983
|
+
const builtColumnsForExtraConfig = Object.fromEntries(Object.entries(parsedColumns).map(([name2, colBuilderBase]) => {
|
|
23984
|
+
const colBuilder = colBuilderBase;
|
|
23985
|
+
colBuilder.setName(name2);
|
|
23986
|
+
const column = colBuilder.buildExtraConfigColumn(rawTable);
|
|
23987
|
+
return [name2, column];
|
|
23988
|
+
}));
|
|
23989
|
+
const table = Object.assign(rawTable, builtColumns);
|
|
23990
|
+
table[Table.Symbol.Columns] = builtColumns;
|
|
23991
|
+
table[Table.Symbol.ExtraConfigColumns] = builtColumnsForExtraConfig;
|
|
23992
|
+
if (extraConfig) {
|
|
23993
|
+
table[PgTable.Symbol.ExtraConfigBuilder] = extraConfig;
|
|
23994
|
+
}
|
|
23995
|
+
return Object.assign(table, {
|
|
23996
|
+
enableRLS: () => {
|
|
23997
|
+
table[PgTable.Symbol.EnableRLS] = true;
|
|
23998
|
+
return table;
|
|
23999
|
+
}
|
|
24000
|
+
});
|
|
24001
|
+
}
|
|
24002
|
+
var pgTable = (name, columns, extraConfig) => {
|
|
24003
|
+
return pgTableWithSchema(name, columns, extraConfig, undefined);
|
|
24004
|
+
};
|
|
24005
|
+
|
|
24006
|
+
// node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
24007
|
+
function bindIfParam(value, column) {
|
|
24008
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
24009
|
+
return new Param(value, column);
|
|
24010
|
+
}
|
|
24011
|
+
return value;
|
|
24012
|
+
}
|
|
24013
|
+
var eq = (left, right) => {
|
|
24014
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
24015
|
+
};
|
|
24016
|
+
var ne = (left, right) => {
|
|
24017
|
+
return sql`${left} <> ${bindIfParam(right, left)}`;
|
|
24018
|
+
};
|
|
24019
|
+
function and(...unfilteredConditions) {
|
|
24020
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
24021
|
+
if (conditions.length === 0) {
|
|
24022
|
+
return;
|
|
24023
|
+
}
|
|
24024
|
+
if (conditions.length === 1) {
|
|
24025
|
+
return new SQL(conditions);
|
|
24026
|
+
}
|
|
24027
|
+
return new SQL([
|
|
24028
|
+
new StringChunk("("),
|
|
24029
|
+
sql.join(conditions, new StringChunk(" and ")),
|
|
24030
|
+
new StringChunk(")")
|
|
24031
|
+
]);
|
|
24032
|
+
}
|
|
24033
|
+
function or(...unfilteredConditions) {
|
|
24034
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
24035
|
+
if (conditions.length === 0) {
|
|
24036
|
+
return;
|
|
24037
|
+
}
|
|
24038
|
+
if (conditions.length === 1) {
|
|
24039
|
+
return new SQL(conditions);
|
|
24040
|
+
}
|
|
24041
|
+
return new SQL([
|
|
24042
|
+
new StringChunk("("),
|
|
24043
|
+
sql.join(conditions, new StringChunk(" or ")),
|
|
24044
|
+
new StringChunk(")")
|
|
24045
|
+
]);
|
|
24046
|
+
}
|
|
24047
|
+
|
|
24048
|
+
// node_modules/drizzle-orm/sql/expressions/select.js
|
|
24049
|
+
function desc(column) {
|
|
24050
|
+
return sql`${column} desc`;
|
|
24051
|
+
}
|
|
24052
|
+
|
|
24053
|
+
// node_modules/drizzle-orm/sql/functions/aggregate.js
|
|
24054
|
+
function count(expression) {
|
|
24055
|
+
return sql`count(${expression || sql.raw("*")})`.mapWith(Number);
|
|
24056
|
+
}
|
|
24057
|
+
|
|
24058
|
+
// src/database/adapters/drizzle.ts
|
|
24059
|
+
function mapProviderTokenRow(row) {
|
|
24060
|
+
return {
|
|
24061
|
+
id: String(row.id),
|
|
24062
|
+
userId: String(row.userId),
|
|
24063
|
+
provider: String(row.provider),
|
|
24064
|
+
accountEmail: row.accountEmail ?? null,
|
|
24065
|
+
accountId: row.accountId ?? null,
|
|
24066
|
+
accessToken: String(row.accessToken),
|
|
24067
|
+
refreshToken: row.refreshToken ?? null,
|
|
24068
|
+
tokenType: String(row.tokenType ?? "Bearer"),
|
|
24069
|
+
expiresAt: row.expiresAt ?? null,
|
|
24070
|
+
scope: row.scope ?? null,
|
|
24071
|
+
createdAt: row.createdAt,
|
|
24072
|
+
updatedAt: row.updatedAt
|
|
24073
|
+
};
|
|
24074
|
+
}
|
|
24075
|
+
function mapTriggerRow(row) {
|
|
24076
|
+
return {
|
|
24077
|
+
id: String(row.id),
|
|
24078
|
+
userId: row.userId ?? null,
|
|
24079
|
+
name: row.name ?? null,
|
|
24080
|
+
description: row.description ?? null,
|
|
24081
|
+
toolName: String(row.toolName),
|
|
24082
|
+
toolArguments: row.toolArguments ?? {},
|
|
24083
|
+
scheduleType: row.scheduleType,
|
|
24084
|
+
scheduleValue: String(row.scheduleValue),
|
|
24085
|
+
status: String(row.status),
|
|
24086
|
+
provider: row.provider ?? null,
|
|
24087
|
+
lastRunAt: row.lastRunAt ?? null,
|
|
24088
|
+
nextRunAt: row.nextRunAt ?? null,
|
|
24089
|
+
runCount: Number(row.runCount ?? 0),
|
|
24090
|
+
lastError: row.lastError ?? null,
|
|
24091
|
+
lastResult: row.lastResult ?? null,
|
|
24092
|
+
createdAt: row.createdAt,
|
|
24093
|
+
updatedAt: row.updatedAt
|
|
24094
|
+
};
|
|
24095
|
+
}
|
|
24096
|
+
function createDrizzleTokenDriver(db, table) {
|
|
24097
|
+
const t = table;
|
|
24098
|
+
return {
|
|
24099
|
+
async listProviderTokens(userId, provider) {
|
|
24100
|
+
const rows = await db.select().from(table).where(and(eq(t.userId, userId), eq(t.provider, provider))).orderBy(desc(t.updatedAt)).limit(32);
|
|
24101
|
+
return rows.map((row) => mapProviderTokenRow(row));
|
|
24102
|
+
},
|
|
24103
|
+
async upsertProviderToken(input) {
|
|
24104
|
+
const now = new Date;
|
|
24105
|
+
const values = {
|
|
24106
|
+
id: input.existingId ?? input.id,
|
|
24107
|
+
userId: input.userId,
|
|
24108
|
+
provider: input.provider,
|
|
24109
|
+
accountEmail: input.accountEmail,
|
|
24110
|
+
accountId: input.accountId,
|
|
24111
|
+
accessToken: input.accessToken,
|
|
24112
|
+
refreshToken: input.refreshToken,
|
|
24113
|
+
tokenType: input.tokenType,
|
|
24114
|
+
expiresAt: input.expiresAt,
|
|
24115
|
+
scope: input.scope,
|
|
24116
|
+
updatedAt: now,
|
|
24117
|
+
...input.existingId ? {} : { createdAt: now }
|
|
24118
|
+
};
|
|
24119
|
+
if (input.existingId) {
|
|
24120
|
+
const [updated] = await db.update(table).set(values).where(eq(t.id, input.existingId)).returning();
|
|
24121
|
+
return mapProviderTokenRow(updated);
|
|
24122
|
+
}
|
|
24123
|
+
const [created] = await db.insert(table).values(values).returning();
|
|
24124
|
+
return mapProviderTokenRow(created);
|
|
24125
|
+
},
|
|
24126
|
+
async deleteProviderTokens(input) {
|
|
24127
|
+
const conditions = [
|
|
24128
|
+
eq(t.userId, input.userId),
|
|
24129
|
+
eq(t.provider, input.provider)
|
|
24130
|
+
];
|
|
24131
|
+
if (input.accountEmail) {
|
|
24132
|
+
conditions.push(eq(t.accountEmail, input.accountEmail));
|
|
24133
|
+
} else if (input.accountId) {
|
|
24134
|
+
conditions.push(eq(t.accountId, input.accountId));
|
|
24135
|
+
}
|
|
24136
|
+
await db.delete(table).where(and(...conditions));
|
|
24137
|
+
},
|
|
24138
|
+
async deleteDuplicateProviderTokens(input) {
|
|
24139
|
+
const normalizedEmail = normalizeAccountEmail(input.accountEmail);
|
|
24140
|
+
const normalizedAccountId = normalizeAccountIdHint(input.accountId);
|
|
24141
|
+
if (!normalizedEmail && !normalizedAccountId) {
|
|
24142
|
+
return;
|
|
24143
|
+
}
|
|
24144
|
+
const duplicateConditions = [
|
|
24145
|
+
eq(t.userId, input.userId),
|
|
24146
|
+
eq(t.provider, input.provider),
|
|
24147
|
+
ne(t.id, input.keepId)
|
|
24148
|
+
];
|
|
24149
|
+
const identityConditions = [];
|
|
24150
|
+
if (normalizedEmail) {
|
|
24151
|
+
identityConditions.push(eq(t.accountEmail, normalizedEmail));
|
|
24152
|
+
}
|
|
24153
|
+
if (normalizedAccountId) {
|
|
24154
|
+
identityConditions.push(eq(t.accountId, normalizedAccountId));
|
|
24155
|
+
}
|
|
24156
|
+
if (identityConditions.length === 0) {
|
|
24157
|
+
return;
|
|
24158
|
+
}
|
|
24159
|
+
await db.delete(table).where(and(...duplicateConditions, or(...identityConditions)));
|
|
24160
|
+
}
|
|
24161
|
+
};
|
|
24162
|
+
}
|
|
24163
|
+
function createDrizzleTriggerDriver(db, table) {
|
|
24164
|
+
const t = table;
|
|
24165
|
+
return {
|
|
24166
|
+
async createTrigger(input) {
|
|
24167
|
+
const now = new Date;
|
|
24168
|
+
const [created] = await db.insert(table).values({
|
|
24169
|
+
id: input.id,
|
|
24170
|
+
userId: input.userId,
|
|
24171
|
+
name: input.name ?? null,
|
|
24172
|
+
description: input.description ?? null,
|
|
24173
|
+
toolName: input.toolName,
|
|
24174
|
+
toolArguments: input.toolArguments,
|
|
24175
|
+
scheduleType: input.scheduleType,
|
|
24176
|
+
scheduleValue: input.scheduleValue,
|
|
24177
|
+
status: input.status,
|
|
24178
|
+
provider: input.provider ?? null,
|
|
24179
|
+
nextRunAt: input.nextRunAt ?? null,
|
|
24180
|
+
createdAt: now,
|
|
24181
|
+
updatedAt: now
|
|
24182
|
+
}).returning();
|
|
24183
|
+
return mapTriggerRow(created);
|
|
24184
|
+
},
|
|
24185
|
+
async getTriggerById(triggerId) {
|
|
24186
|
+
const [found] = await db.select().from(table).where(eq(t.id, triggerId)).limit(1);
|
|
24187
|
+
return found ? mapTriggerRow(found) : null;
|
|
24188
|
+
},
|
|
24189
|
+
async listTriggers(query) {
|
|
24190
|
+
const conditions = [];
|
|
24191
|
+
if (query.userId) {
|
|
24192
|
+
conditions.push(eq(t.userId, query.userId));
|
|
24193
|
+
}
|
|
24194
|
+
if (query.status) {
|
|
24195
|
+
conditions.push(eq(t.status, query.status));
|
|
24196
|
+
}
|
|
24197
|
+
if (query.toolName) {
|
|
24198
|
+
conditions.push(eq(t.toolName, query.toolName));
|
|
24199
|
+
}
|
|
24200
|
+
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
|
24201
|
+
const rows = await db.select().from(table).where(whereClause).limit(query.limit).offset(query.offset);
|
|
24202
|
+
const [totalResult] = await db.select({ count: count() }).from(table).where(whereClause);
|
|
24203
|
+
return {
|
|
24204
|
+
rows: rows.map((row) => mapTriggerRow(row)),
|
|
24205
|
+
total: Number(totalResult?.count ?? 0)
|
|
24206
|
+
};
|
|
24207
|
+
},
|
|
24208
|
+
async updateTrigger(triggerId, updates) {
|
|
24209
|
+
const [updated] = await db.update(table).set(updates).where(eq(t.id, triggerId)).returning();
|
|
24210
|
+
return updated ? mapTriggerRow(updated) : null;
|
|
24211
|
+
},
|
|
24212
|
+
async deleteTrigger(triggerId) {
|
|
24213
|
+
await db.delete(table).where(eq(t.id, triggerId));
|
|
24214
|
+
}
|
|
24215
|
+
};
|
|
24216
|
+
}
|
|
24217
|
+
function createDrizzleDatabaseDriver(db, schema) {
|
|
24218
|
+
const driver = {
|
|
24219
|
+
tokens: createDrizzleTokenDriver(db, schema.providerToken)
|
|
24220
|
+
};
|
|
24221
|
+
if (schema.trigger) {
|
|
24222
|
+
driver.triggers = createDrizzleTriggerDriver(db, schema.trigger);
|
|
24223
|
+
}
|
|
24224
|
+
return driver;
|
|
24225
|
+
}
|
|
24226
|
+
function drizzleAdapter(db, config) {
|
|
24227
|
+
config.provider;
|
|
24228
|
+
const driver = () => createDrizzleDatabaseDriver(db, config.schema);
|
|
24229
|
+
return createDatabaseAdapterFactory(driver, {
|
|
24230
|
+
hooks: config.hooks,
|
|
24231
|
+
debugLogs: config.debugLogs
|
|
24232
|
+
});
|
|
24233
|
+
}
|
|
24234
|
+
function drizzleAdapterCallbacks(db, config) {
|
|
24235
|
+
return createDatabaseAdapterCallbacks({
|
|
24236
|
+
driver: createDrizzleDatabaseDriver(db, config.schema),
|
|
24237
|
+
hooks: config.hooks,
|
|
24238
|
+
debugLogs: config.debugLogs
|
|
24239
|
+
});
|
|
24240
|
+
}
|
|
24241
|
+
// src/database/adapters/prisma.ts
|
|
24242
|
+
var DEFAULT_MODEL_NAMES = {
|
|
24243
|
+
providerToken: "providerToken",
|
|
24244
|
+
trigger: "trigger"
|
|
24245
|
+
};
|
|
24246
|
+
function getModel(client, name) {
|
|
24247
|
+
const model = client[name];
|
|
24248
|
+
if (!model) {
|
|
24249
|
+
throw new Error(`[Integrate SDK] Prisma model "${name}" was not found on the client`);
|
|
24250
|
+
}
|
|
24251
|
+
return model;
|
|
24252
|
+
}
|
|
24253
|
+
function mapProviderTokenRow2(row) {
|
|
24254
|
+
return {
|
|
24255
|
+
id: String(row.id),
|
|
24256
|
+
userId: String(row.userId),
|
|
24257
|
+
provider: String(row.provider),
|
|
24258
|
+
accountEmail: row.accountEmail ?? null,
|
|
24259
|
+
accountId: row.accountId ?? null,
|
|
24260
|
+
accessToken: String(row.accessToken),
|
|
24261
|
+
refreshToken: row.refreshToken ?? null,
|
|
24262
|
+
tokenType: String(row.tokenType ?? "Bearer"),
|
|
24263
|
+
expiresAt: row.expiresAt ?? null,
|
|
24264
|
+
scope: row.scope ?? null,
|
|
24265
|
+
createdAt: row.createdAt,
|
|
24266
|
+
updatedAt: row.updatedAt
|
|
24267
|
+
};
|
|
24268
|
+
}
|
|
24269
|
+
function mapTriggerRow2(row) {
|
|
24270
|
+
return {
|
|
24271
|
+
id: String(row.id),
|
|
24272
|
+
userId: row.userId ?? null,
|
|
24273
|
+
name: row.name ?? null,
|
|
24274
|
+
description: row.description ?? null,
|
|
24275
|
+
toolName: String(row.toolName),
|
|
24276
|
+
toolArguments: row.toolArguments ?? {},
|
|
24277
|
+
scheduleType: row.scheduleType,
|
|
24278
|
+
scheduleValue: String(row.scheduleValue),
|
|
24279
|
+
status: String(row.status),
|
|
24280
|
+
provider: row.provider ?? null,
|
|
24281
|
+
lastRunAt: row.lastRunAt ?? null,
|
|
24282
|
+
nextRunAt: row.nextRunAt ?? null,
|
|
24283
|
+
runCount: Number(row.runCount ?? 0),
|
|
24284
|
+
lastError: row.lastError ?? null,
|
|
24285
|
+
lastResult: row.lastResult ?? null,
|
|
24286
|
+
createdAt: row.createdAt,
|
|
24287
|
+
updatedAt: row.updatedAt
|
|
24288
|
+
};
|
|
24289
|
+
}
|
|
24290
|
+
function createPrismaTokenDriver(prisma, modelName) {
|
|
24291
|
+
const model = () => getModel(prisma, modelName);
|
|
24292
|
+
return {
|
|
24293
|
+
async listProviderTokens(userId, provider) {
|
|
24294
|
+
const rows = await model().findMany({
|
|
24295
|
+
where: { userId, provider },
|
|
24296
|
+
orderBy: { updatedAt: "desc" },
|
|
24297
|
+
take: 32
|
|
24298
|
+
});
|
|
24299
|
+
return rows.map((row) => mapProviderTokenRow2(row));
|
|
24300
|
+
},
|
|
24301
|
+
async upsertProviderToken(input) {
|
|
24302
|
+
const now = new Date;
|
|
24303
|
+
const data = {
|
|
24304
|
+
userId: input.userId,
|
|
24305
|
+
provider: input.provider,
|
|
24306
|
+
accountEmail: input.accountEmail,
|
|
24307
|
+
accountId: input.accountId,
|
|
24308
|
+
accessToken: input.accessToken,
|
|
24309
|
+
refreshToken: input.refreshToken,
|
|
24310
|
+
tokenType: input.tokenType,
|
|
24311
|
+
expiresAt: input.expiresAt,
|
|
24312
|
+
scope: input.scope,
|
|
24313
|
+
updatedAt: now
|
|
24314
|
+
};
|
|
24315
|
+
if (input.existingId) {
|
|
24316
|
+
const updated = await model().update({
|
|
24317
|
+
where: { id: input.existingId },
|
|
24318
|
+
data
|
|
24319
|
+
});
|
|
24320
|
+
return mapProviderTokenRow2(updated);
|
|
24321
|
+
}
|
|
24322
|
+
const created = await model().create({
|
|
24323
|
+
data: {
|
|
24324
|
+
id: input.id,
|
|
24325
|
+
...data,
|
|
24326
|
+
createdAt: now
|
|
24327
|
+
}
|
|
24328
|
+
});
|
|
24329
|
+
return mapProviderTokenRow2(created);
|
|
24330
|
+
},
|
|
24331
|
+
async deleteProviderTokens(input) {
|
|
24332
|
+
const where = {
|
|
24333
|
+
userId: input.userId,
|
|
24334
|
+
provider: input.provider
|
|
24335
|
+
};
|
|
24336
|
+
if (input.accountEmail) {
|
|
24337
|
+
where.accountEmail = input.accountEmail;
|
|
24338
|
+
} else if (input.accountId) {
|
|
24339
|
+
where.accountId = input.accountId;
|
|
24340
|
+
}
|
|
24341
|
+
await model().deleteMany({ where });
|
|
24342
|
+
},
|
|
24343
|
+
async deleteDuplicateProviderTokens(input) {
|
|
24344
|
+
const normalizedEmail = normalizeAccountEmail(input.accountEmail);
|
|
24345
|
+
const normalizedAccountId = normalizeAccountIdHint(input.accountId);
|
|
24346
|
+
if (!normalizedEmail && !normalizedAccountId) {
|
|
24347
|
+
return;
|
|
24348
|
+
}
|
|
24349
|
+
const orConditions = [];
|
|
24350
|
+
if (normalizedEmail) {
|
|
24351
|
+
orConditions.push({ accountEmail: normalizedEmail });
|
|
24352
|
+
}
|
|
24353
|
+
if (normalizedAccountId) {
|
|
24354
|
+
orConditions.push({ accountId: normalizedAccountId });
|
|
24355
|
+
}
|
|
24356
|
+
await model().deleteMany({
|
|
24357
|
+
where: {
|
|
24358
|
+
userId: input.userId,
|
|
24359
|
+
provider: input.provider,
|
|
24360
|
+
id: { not: input.keepId },
|
|
24361
|
+
OR: orConditions
|
|
24362
|
+
}
|
|
24363
|
+
});
|
|
24364
|
+
}
|
|
24365
|
+
};
|
|
24366
|
+
}
|
|
24367
|
+
function createPrismaTriggerDriver(prisma, modelName) {
|
|
24368
|
+
const model = () => getModel(prisma, modelName);
|
|
24369
|
+
return {
|
|
24370
|
+
async createTrigger(input) {
|
|
24371
|
+
const now = new Date;
|
|
24372
|
+
const created = await model().create({
|
|
24373
|
+
data: {
|
|
24374
|
+
id: input.id,
|
|
24375
|
+
userId: input.userId,
|
|
24376
|
+
name: input.name ?? null,
|
|
24377
|
+
description: input.description ?? null,
|
|
24378
|
+
toolName: input.toolName,
|
|
24379
|
+
toolArguments: input.toolArguments,
|
|
24380
|
+
scheduleType: input.scheduleType,
|
|
24381
|
+
scheduleValue: input.scheduleValue,
|
|
24382
|
+
status: input.status,
|
|
24383
|
+
provider: input.provider ?? null,
|
|
24384
|
+
nextRunAt: input.nextRunAt ?? null,
|
|
24385
|
+
createdAt: now,
|
|
24386
|
+
updatedAt: now
|
|
24387
|
+
}
|
|
24388
|
+
});
|
|
24389
|
+
return mapTriggerRow2(created);
|
|
24390
|
+
},
|
|
24391
|
+
async getTriggerById(triggerId) {
|
|
24392
|
+
const found = await model().findFirst({ where: { id: triggerId } });
|
|
24393
|
+
return found ? mapTriggerRow2(found) : null;
|
|
24394
|
+
},
|
|
24395
|
+
async listTriggers(query) {
|
|
24396
|
+
const where = {};
|
|
24397
|
+
if (query.userId)
|
|
24398
|
+
where.userId = query.userId;
|
|
24399
|
+
if (query.status)
|
|
24400
|
+
where.status = query.status;
|
|
24401
|
+
if (query.toolName)
|
|
24402
|
+
where.toolName = query.toolName;
|
|
24403
|
+
const [rows, total] = await Promise.all([
|
|
24404
|
+
model().findMany({
|
|
24405
|
+
where,
|
|
24406
|
+
take: query.limit,
|
|
24407
|
+
skip: query.offset,
|
|
24408
|
+
orderBy: { updatedAt: "desc" }
|
|
24409
|
+
}),
|
|
24410
|
+
model().count({ where })
|
|
24411
|
+
]);
|
|
24412
|
+
return {
|
|
24413
|
+
rows: rows.map((row) => mapTriggerRow2(row)),
|
|
24414
|
+
total
|
|
24415
|
+
};
|
|
24416
|
+
},
|
|
24417
|
+
async updateTrigger(triggerId, updates) {
|
|
24418
|
+
try {
|
|
24419
|
+
const updated = await model().update({
|
|
24420
|
+
where: { id: triggerId },
|
|
24421
|
+
data: updates
|
|
24422
|
+
});
|
|
24423
|
+
return mapTriggerRow2(updated);
|
|
24424
|
+
} catch {
|
|
24425
|
+
return null;
|
|
24426
|
+
}
|
|
24427
|
+
},
|
|
24428
|
+
async deleteTrigger(triggerId) {
|
|
24429
|
+
await model().delete({ where: { id: triggerId } });
|
|
24430
|
+
}
|
|
24431
|
+
};
|
|
24432
|
+
}
|
|
24433
|
+
function createPrismaDatabaseDriver(prisma, config) {
|
|
24434
|
+
const modelNames = {
|
|
24435
|
+
...DEFAULT_MODEL_NAMES,
|
|
24436
|
+
...config.modelNames
|
|
24437
|
+
};
|
|
24438
|
+
const driver = {
|
|
24439
|
+
tokens: createPrismaTokenDriver(prisma, modelNames.providerToken)
|
|
24440
|
+
};
|
|
24441
|
+
if (config.modelNames?.trigger !== null) {
|
|
24442
|
+
driver.triggers = createPrismaTriggerDriver(prisma, modelNames.trigger);
|
|
24443
|
+
}
|
|
24444
|
+
return driver;
|
|
24445
|
+
}
|
|
24446
|
+
function prismaAdapter(prisma, config) {
|
|
24447
|
+
config.provider;
|
|
24448
|
+
return createDatabaseAdapterFactory(() => createPrismaDatabaseDriver(prisma, config), {
|
|
24449
|
+
hooks: config.hooks,
|
|
24450
|
+
debugLogs: config.debugLogs
|
|
24451
|
+
});
|
|
24452
|
+
}
|
|
24453
|
+
function prismaAdapterCallbacks(prisma, config) {
|
|
24454
|
+
return createDatabaseAdapterCallbacks({
|
|
24455
|
+
driver: createPrismaDatabaseDriver(prisma, config),
|
|
24456
|
+
hooks: config.hooks,
|
|
24457
|
+
debugLogs: config.debugLogs
|
|
24458
|
+
});
|
|
24459
|
+
}
|
|
24460
|
+
// src/database/adapters/mongodb.ts
|
|
24461
|
+
var DEFAULT_COLLECTIONS = {
|
|
24462
|
+
providerTokens: "provider_tokens",
|
|
24463
|
+
triggers: "triggers"
|
|
24464
|
+
};
|
|
24465
|
+
function mapProviderTokenDoc(doc) {
|
|
24466
|
+
return {
|
|
24467
|
+
id: String(doc.id),
|
|
24468
|
+
userId: String(doc.userId),
|
|
24469
|
+
provider: String(doc.provider),
|
|
24470
|
+
accountEmail: doc.accountEmail ?? null,
|
|
24471
|
+
accountId: doc.accountId ?? null,
|
|
24472
|
+
accessToken: String(doc.accessToken),
|
|
24473
|
+
refreshToken: doc.refreshToken ?? null,
|
|
24474
|
+
tokenType: String(doc.tokenType ?? "Bearer"),
|
|
24475
|
+
expiresAt: doc.expiresAt ? new Date(doc.expiresAt) : null,
|
|
24476
|
+
scope: doc.scope ?? null,
|
|
24477
|
+
createdAt: new Date(doc.createdAt),
|
|
24478
|
+
updatedAt: new Date(doc.updatedAt)
|
|
24479
|
+
};
|
|
24480
|
+
}
|
|
24481
|
+
function mapTriggerDoc(doc) {
|
|
24482
|
+
return {
|
|
24483
|
+
id: String(doc.id),
|
|
24484
|
+
userId: doc.userId ?? null,
|
|
24485
|
+
name: doc.name ?? null,
|
|
24486
|
+
description: doc.description ?? null,
|
|
24487
|
+
toolName: String(doc.toolName),
|
|
24488
|
+
toolArguments: doc.toolArguments ?? {},
|
|
24489
|
+
scheduleType: doc.scheduleType,
|
|
24490
|
+
scheduleValue: String(doc.scheduleValue),
|
|
24491
|
+
status: String(doc.status),
|
|
24492
|
+
provider: doc.provider ?? null,
|
|
24493
|
+
lastRunAt: doc.lastRunAt ? new Date(doc.lastRunAt) : null,
|
|
24494
|
+
nextRunAt: doc.nextRunAt ? new Date(doc.nextRunAt) : null,
|
|
24495
|
+
runCount: Number(doc.runCount ?? 0),
|
|
24496
|
+
lastError: doc.lastError ?? null,
|
|
24497
|
+
lastResult: doc.lastResult ?? null,
|
|
24498
|
+
createdAt: new Date(doc.createdAt),
|
|
24499
|
+
updatedAt: new Date(doc.updatedAt)
|
|
24500
|
+
};
|
|
24501
|
+
}
|
|
24502
|
+
function createMongoTokenDriver(db, collectionName) {
|
|
24503
|
+
const collection = () => db.collection(collectionName);
|
|
24504
|
+
return {
|
|
24505
|
+
async listProviderTokens(userId, provider) {
|
|
24506
|
+
const docs = await collection().find({ userId, provider }).sort({ updatedAt: -1 }).limit(32).toArray();
|
|
24507
|
+
return docs.map((doc) => mapProviderTokenDoc(doc));
|
|
24508
|
+
},
|
|
24509
|
+
async upsertProviderToken(input) {
|
|
24510
|
+
const now = new Date;
|
|
24511
|
+
const id = input.existingId ?? input.id;
|
|
24512
|
+
const doc = {
|
|
24513
|
+
id,
|
|
24514
|
+
userId: input.userId,
|
|
24515
|
+
provider: input.provider,
|
|
24516
|
+
accountEmail: input.accountEmail,
|
|
24517
|
+
accountId: input.accountId,
|
|
24518
|
+
accessToken: input.accessToken,
|
|
24519
|
+
refreshToken: input.refreshToken,
|
|
24520
|
+
tokenType: input.tokenType,
|
|
24521
|
+
expiresAt: input.expiresAt,
|
|
24522
|
+
scope: input.scope,
|
|
24523
|
+
updatedAt: now,
|
|
24524
|
+
...input.existingId ? {} : { createdAt: now }
|
|
24525
|
+
};
|
|
24526
|
+
await collection().updateOne({ id }, { $set: doc }, { upsert: true });
|
|
24527
|
+
const saved = await collection().findOne({ id });
|
|
24528
|
+
return mapProviderTokenDoc(saved);
|
|
24529
|
+
},
|
|
24530
|
+
async deleteProviderTokens(input) {
|
|
24531
|
+
const filter = {
|
|
24532
|
+
userId: input.userId,
|
|
24533
|
+
provider: input.provider
|
|
24534
|
+
};
|
|
24535
|
+
if (input.accountEmail) {
|
|
24536
|
+
filter.accountEmail = input.accountEmail;
|
|
24537
|
+
} else if (input.accountId) {
|
|
24538
|
+
filter.accountId = input.accountId;
|
|
24539
|
+
}
|
|
24540
|
+
await collection().deleteMany(filter);
|
|
24541
|
+
},
|
|
24542
|
+
async deleteDuplicateProviderTokens(input) {
|
|
24543
|
+
const normalizedEmail = normalizeAccountEmail(input.accountEmail);
|
|
24544
|
+
const normalizedAccountId = normalizeAccountIdHint(input.accountId);
|
|
24545
|
+
if (!normalizedEmail && !normalizedAccountId) {
|
|
24546
|
+
return;
|
|
24547
|
+
}
|
|
24548
|
+
const orConditions = [];
|
|
24549
|
+
if (normalizedEmail) {
|
|
24550
|
+
orConditions.push({ accountEmail: normalizedEmail });
|
|
24551
|
+
}
|
|
24552
|
+
if (normalizedAccountId) {
|
|
24553
|
+
orConditions.push({ accountId: normalizedAccountId });
|
|
24554
|
+
}
|
|
24555
|
+
await collection().deleteMany({
|
|
24556
|
+
userId: input.userId,
|
|
24557
|
+
provider: input.provider,
|
|
24558
|
+
id: { $ne: input.keepId },
|
|
24559
|
+
$or: orConditions
|
|
24560
|
+
});
|
|
24561
|
+
}
|
|
24562
|
+
};
|
|
24563
|
+
}
|
|
24564
|
+
function createMongoTriggerDriver(db, collectionName) {
|
|
24565
|
+
const collection = () => db.collection(collectionName);
|
|
24566
|
+
return {
|
|
24567
|
+
async createTrigger(input) {
|
|
24568
|
+
const now = new Date;
|
|
24569
|
+
const doc = {
|
|
24570
|
+
id: input.id,
|
|
24571
|
+
userId: input.userId,
|
|
24572
|
+
name: input.name ?? null,
|
|
24573
|
+
description: input.description ?? null,
|
|
24574
|
+
toolName: input.toolName,
|
|
24575
|
+
toolArguments: input.toolArguments,
|
|
24576
|
+
scheduleType: input.scheduleType,
|
|
24577
|
+
scheduleValue: input.scheduleValue,
|
|
24578
|
+
status: input.status,
|
|
24579
|
+
provider: input.provider ?? null,
|
|
24580
|
+
nextRunAt: input.nextRunAt ?? null,
|
|
24581
|
+
createdAt: now,
|
|
24582
|
+
updatedAt: now
|
|
24583
|
+
};
|
|
24584
|
+
await collection().insertOne(doc);
|
|
24585
|
+
return mapTriggerDoc(doc);
|
|
24586
|
+
},
|
|
24587
|
+
async getTriggerById(triggerId) {
|
|
24588
|
+
const found = await collection().findOne({ id: triggerId });
|
|
24589
|
+
return found ? mapTriggerDoc(found) : null;
|
|
24590
|
+
},
|
|
24591
|
+
async listTriggers(query) {
|
|
24592
|
+
const filter = {};
|
|
24593
|
+
if (query.userId)
|
|
24594
|
+
filter.userId = query.userId;
|
|
24595
|
+
if (query.status)
|
|
24596
|
+
filter.status = query.status;
|
|
24597
|
+
if (query.toolName)
|
|
24598
|
+
filter.toolName = query.toolName;
|
|
24599
|
+
const [docs, total] = await Promise.all([
|
|
24600
|
+
collection().find(filter).sort({ updatedAt: -1 }).skip(query.offset).limit(query.limit).toArray(),
|
|
24601
|
+
collection().countDocuments(filter)
|
|
24602
|
+
]);
|
|
24603
|
+
return {
|
|
24604
|
+
rows: docs.map((doc) => mapTriggerDoc(doc)),
|
|
24605
|
+
total
|
|
24606
|
+
};
|
|
24607
|
+
},
|
|
24608
|
+
async updateTrigger(triggerId, updates) {
|
|
24609
|
+
const result = await collection().findOneAndUpdate({ id: triggerId }, { $set: updates }, { returnDocument: "after" });
|
|
24610
|
+
return result ? mapTriggerDoc(result) : null;
|
|
24611
|
+
},
|
|
24612
|
+
async deleteTrigger(triggerId) {
|
|
24613
|
+
await collection().deleteOne({ id: triggerId });
|
|
24614
|
+
}
|
|
24615
|
+
};
|
|
24616
|
+
}
|
|
24617
|
+
function createMongoDatabaseDriver(db, config) {
|
|
24618
|
+
const names = {
|
|
24619
|
+
...DEFAULT_COLLECTIONS,
|
|
24620
|
+
...config.collectionNames
|
|
24621
|
+
};
|
|
24622
|
+
const driver = {
|
|
24623
|
+
tokens: createMongoTokenDriver(db, names.providerTokens)
|
|
24624
|
+
};
|
|
24625
|
+
if (config.collectionNames?.triggers !== null) {
|
|
24626
|
+
driver.triggers = createMongoTriggerDriver(db, names.triggers);
|
|
24627
|
+
}
|
|
24628
|
+
return driver;
|
|
24629
|
+
}
|
|
24630
|
+
function mongodbAdapter(db, config = {}) {
|
|
24631
|
+
return createDatabaseAdapterFactory(() => createMongoDatabaseDriver(db, config), {
|
|
24632
|
+
hooks: config.hooks,
|
|
24633
|
+
debugLogs: config.debugLogs
|
|
24634
|
+
});
|
|
24635
|
+
}
|
|
24636
|
+
function mongodbAdapterCallbacks(db, config = {}) {
|
|
24637
|
+
return createDatabaseAdapterCallbacks({
|
|
24638
|
+
driver: createMongoDatabaseDriver(db, config),
|
|
24639
|
+
hooks: config.hooks,
|
|
24640
|
+
debugLogs: config.debugLogs
|
|
24641
|
+
});
|
|
24642
|
+
}
|
|
24643
|
+
// node_modules/drizzle-orm/pg-core/indexes.js
|
|
24644
|
+
class IndexBuilderOn {
|
|
24645
|
+
constructor(unique, name) {
|
|
24646
|
+
this.unique = unique;
|
|
24647
|
+
this.name = name;
|
|
24648
|
+
}
|
|
24649
|
+
static [entityKind] = "PgIndexBuilderOn";
|
|
24650
|
+
on(...columns) {
|
|
24651
|
+
return new IndexBuilder(columns.map((it) => {
|
|
24652
|
+
if (is(it, SQL)) {
|
|
24653
|
+
return it;
|
|
24654
|
+
}
|
|
24655
|
+
it = it;
|
|
24656
|
+
const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
|
|
24657
|
+
it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));
|
|
24658
|
+
return clonedIndexedColumn;
|
|
24659
|
+
}), this.unique, false, this.name);
|
|
24660
|
+
}
|
|
24661
|
+
onOnly(...columns) {
|
|
24662
|
+
return new IndexBuilder(columns.map((it) => {
|
|
24663
|
+
if (is(it, SQL)) {
|
|
24664
|
+
return it;
|
|
24665
|
+
}
|
|
24666
|
+
it = it;
|
|
24667
|
+
const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
|
|
24668
|
+
it.indexConfig = it.defaultConfig;
|
|
24669
|
+
return clonedIndexedColumn;
|
|
24670
|
+
}), this.unique, true, this.name);
|
|
24671
|
+
}
|
|
24672
|
+
using(method, ...columns) {
|
|
24673
|
+
return new IndexBuilder(columns.map((it) => {
|
|
24674
|
+
if (is(it, SQL)) {
|
|
24675
|
+
return it;
|
|
24676
|
+
}
|
|
24677
|
+
it = it;
|
|
24678
|
+
const clonedIndexedColumn = new IndexedColumn(it.name, !!it.keyAsName, it.columnType, it.indexConfig);
|
|
24679
|
+
it.indexConfig = JSON.parse(JSON.stringify(it.defaultConfig));
|
|
24680
|
+
return clonedIndexedColumn;
|
|
24681
|
+
}), this.unique, true, this.name, method);
|
|
24682
|
+
}
|
|
24683
|
+
}
|
|
24684
|
+
|
|
24685
|
+
class IndexBuilder {
|
|
24686
|
+
static [entityKind] = "PgIndexBuilder";
|
|
24687
|
+
config;
|
|
24688
|
+
constructor(columns, unique, only, name, method = "btree") {
|
|
24689
|
+
this.config = {
|
|
24690
|
+
name,
|
|
24691
|
+
columns,
|
|
24692
|
+
unique,
|
|
24693
|
+
only,
|
|
24694
|
+
method
|
|
24695
|
+
};
|
|
24696
|
+
}
|
|
24697
|
+
concurrently() {
|
|
24698
|
+
this.config.concurrently = true;
|
|
24699
|
+
return this;
|
|
24700
|
+
}
|
|
24701
|
+
with(obj) {
|
|
24702
|
+
this.config.with = obj;
|
|
24703
|
+
return this;
|
|
24704
|
+
}
|
|
24705
|
+
where(condition) {
|
|
24706
|
+
this.config.where = condition;
|
|
24707
|
+
return this;
|
|
24708
|
+
}
|
|
24709
|
+
build(table) {
|
|
24710
|
+
return new Index(this.config, table);
|
|
24711
|
+
}
|
|
24712
|
+
}
|
|
24713
|
+
|
|
24714
|
+
class Index {
|
|
24715
|
+
static [entityKind] = "PgIndex";
|
|
24716
|
+
config;
|
|
24717
|
+
constructor(config, table) {
|
|
24718
|
+
this.config = { ...config, table };
|
|
24719
|
+
}
|
|
24720
|
+
}
|
|
24721
|
+
function index(name) {
|
|
24722
|
+
return new IndexBuilderOn(false, name);
|
|
24723
|
+
}
|
|
24724
|
+
function uniqueIndex(name) {
|
|
24725
|
+
return new IndexBuilderOn(true, name);
|
|
24726
|
+
}
|
|
24727
|
+
|
|
24728
|
+
// src/database/schemas/drizzle.ts
|
|
24729
|
+
var integrateProviderToken = pgTable("provider_token", {
|
|
24730
|
+
id: text("id").primaryKey(),
|
|
24731
|
+
userId: text("user_id").notNull(),
|
|
24732
|
+
provider: text("provider").notNull(),
|
|
24733
|
+
accountEmail: text("account_email"),
|
|
24734
|
+
accountId: text("account_id"),
|
|
24735
|
+
accessToken: text("access_token").notNull(),
|
|
24736
|
+
refreshToken: text("refresh_token"),
|
|
24737
|
+
tokenType: text("token_type").notNull().default("Bearer"),
|
|
24738
|
+
expiresAt: timestamp("expires_at"),
|
|
24739
|
+
scope: text("scope"),
|
|
24740
|
+
createdAt: timestamp("created_at", { mode: "date", precision: 3 }).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
|
|
24741
|
+
updatedAt: timestamp("updated_at", { mode: "date", precision: 3 }).default(sql`CURRENT_TIMESTAMP(3)`).notNull()
|
|
24742
|
+
}, (table) => [
|
|
24743
|
+
index("provider_token_user_id_idx").on(table.userId),
|
|
24744
|
+
index("provider_token_provider_idx").on(table.provider),
|
|
24745
|
+
index("provider_token_user_provider_idx").on(table.userId, table.provider),
|
|
24746
|
+
uniqueIndex("provider_token_user_provider_account_email_uidx").on(table.userId, table.provider, table.accountEmail)
|
|
24747
|
+
]);
|
|
24748
|
+
var integrateTrigger = pgTable("trigger", {
|
|
24749
|
+
id: text("id").primaryKey(),
|
|
24750
|
+
userId: text("user_id"),
|
|
24751
|
+
name: text("name"),
|
|
24752
|
+
description: text("description"),
|
|
24753
|
+
toolName: text("tool_name").notNull(),
|
|
24754
|
+
toolArguments: jsonb("tool_arguments").notNull(),
|
|
24755
|
+
scheduleType: text("schedule_type").notNull(),
|
|
24756
|
+
scheduleValue: text("schedule_value").notNull(),
|
|
24757
|
+
status: text("status").notNull().default("active"),
|
|
24758
|
+
provider: text("provider"),
|
|
24759
|
+
lastRunAt: timestamp("last_run_at", { mode: "date", precision: 3 }),
|
|
24760
|
+
nextRunAt: timestamp("next_run_at", { mode: "date", precision: 3 }),
|
|
24761
|
+
runCount: integer("run_count").notNull().default(0),
|
|
24762
|
+
lastError: text("last_error"),
|
|
24763
|
+
lastResult: jsonb("last_result"),
|
|
24764
|
+
createdAt: timestamp("created_at", { mode: "date", precision: 3 }).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
|
|
24765
|
+
updatedAt: timestamp("updated_at", { mode: "date", precision: 3 }).default(sql`CURRENT_TIMESTAMP(3)`).notNull()
|
|
24766
|
+
}, (table) => [
|
|
24767
|
+
index("trigger_user_id_idx").on(table.userId),
|
|
24768
|
+
index("trigger_status_idx").on(table.status),
|
|
24769
|
+
index("trigger_next_run_at_idx").on(table.nextRunAt)
|
|
24770
|
+
]);
|
|
24771
|
+
// src/server.ts
|
|
24772
|
+
var SERVER_LOG_CONTEXT3 = "server";
|
|
24773
|
+
var logger203 = createLogger("MCPServer", SERVER_LOG_CONTEXT3);
|
|
24774
|
+
function mergeTriggerCallbacks(fromDatabase, explicit) {
|
|
24775
|
+
if (!fromDatabase && !explicit) {
|
|
24776
|
+
return;
|
|
24777
|
+
}
|
|
24778
|
+
return {
|
|
24779
|
+
create: explicit?.create ?? fromDatabase.create,
|
|
24780
|
+
get: explicit?.get ?? fromDatabase.get,
|
|
24781
|
+
list: explicit?.list ?? fromDatabase.list,
|
|
24782
|
+
update: explicit?.update ?? fromDatabase.update,
|
|
24783
|
+
delete: explicit?.delete ?? fromDatabase.delete,
|
|
24784
|
+
onComplete: explicit?.onComplete ?? fromDatabase?.onComplete,
|
|
24785
|
+
getCallbackUrl: explicit?.getCallbackUrl ?? fromDatabase?.getCallbackUrl
|
|
24786
|
+
};
|
|
24787
|
+
}
|
|
24788
|
+
function mergeDatabaseConfig(config) {
|
|
24789
|
+
if (!config.database) {
|
|
24790
|
+
return config;
|
|
24791
|
+
}
|
|
24792
|
+
const databaseCallbacks = config.database();
|
|
24793
|
+
return {
|
|
24794
|
+
...config,
|
|
24795
|
+
getProviderToken: config.getProviderToken ?? databaseCallbacks.getProviderToken,
|
|
24796
|
+
setProviderToken: config.setProviderToken ?? databaseCallbacks.setProviderToken,
|
|
24797
|
+
removeProviderToken: config.removeProviderToken ?? databaseCallbacks.removeProviderToken,
|
|
24798
|
+
triggers: mergeTriggerCallbacks(databaseCallbacks.triggers, config.triggers)
|
|
24799
|
+
};
|
|
24800
|
+
}
|
|
21240
24801
|
async function refreshTokenIfNeeded(provider, tokenData, providers, config, context) {
|
|
21241
24802
|
const credentials = providers[provider];
|
|
21242
24803
|
if (!credentials || !config.serverUrl) {
|
|
@@ -21360,7 +24921,8 @@ function getDefaultRedirectUri() {
|
|
|
21360
24921
|
}
|
|
21361
24922
|
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
21362
24923
|
}
|
|
21363
|
-
function createMCPServer(
|
|
24924
|
+
function createMCPServer(inputConfig) {
|
|
24925
|
+
const config = mergeDatabaseConfig(inputConfig);
|
|
21364
24926
|
setLogLevel(config.debug ? "debug" : "error", SERVER_LOG_CONTEXT3);
|
|
21365
24927
|
if (typeof window !== "undefined") {
|
|
21366
24928
|
throw new Error("createMCPServer() should only be called on the server-side. " + "Use createMCPClient() for client-side code.");
|
|
@@ -22313,7 +25875,11 @@ export {
|
|
|
22313
25875
|
toTanStackStartHandler,
|
|
22314
25876
|
toSvelteKitHandler,
|
|
22315
25877
|
toSolidStartHandler,
|
|
25878
|
+
toSdkTrigger,
|
|
25879
|
+
toSdkSchedule,
|
|
22316
25880
|
toNextJsHandler,
|
|
25881
|
+
toDbTriggerUpdates,
|
|
25882
|
+
toDbSchedule,
|
|
22317
25883
|
tldrawIntegration,
|
|
22318
25884
|
tinkIntegration,
|
|
22319
25885
|
tiktokIntegration,
|
|
@@ -22340,6 +25906,7 @@ export {
|
|
|
22340
25906
|
sharepointIntegration,
|
|
22341
25907
|
sentryIntegration,
|
|
22342
25908
|
sendWebResponse,
|
|
25909
|
+
selectProviderTokenRow,
|
|
22343
25910
|
salesforceIntegration,
|
|
22344
25911
|
sageIntegration,
|
|
22345
25912
|
ringIntegration,
|
|
@@ -22349,6 +25916,9 @@ export {
|
|
|
22349
25916
|
rampIntegration,
|
|
22350
25917
|
railwayIntegration,
|
|
22351
25918
|
quickbooksIntegration,
|
|
25919
|
+
providerTokenRecordToData,
|
|
25920
|
+
prismaAdapterCallbacks,
|
|
25921
|
+
prismaAdapter,
|
|
22352
25922
|
powerpointIntegration,
|
|
22353
25923
|
postmanIntegration,
|
|
22354
25924
|
posthogIntegration,
|
|
@@ -22361,6 +25931,7 @@ export {
|
|
|
22361
25931
|
philipsHueIntegration,
|
|
22362
25932
|
phantomIntegration,
|
|
22363
25933
|
paypalIntegration,
|
|
25934
|
+
parseScopes,
|
|
22364
25935
|
paperIntegration,
|
|
22365
25936
|
pandadocIntegration,
|
|
22366
25937
|
outlookIntegration,
|
|
@@ -22370,9 +25941,16 @@ export {
|
|
|
22370
25941
|
onedriveIntegration,
|
|
22371
25942
|
oktaIntegration,
|
|
22372
25943
|
notionIntegration,
|
|
25944
|
+
normalizeProviderTokenType,
|
|
25945
|
+
normalizeAccountIdentifier,
|
|
25946
|
+
normalizeAccountIdHint,
|
|
25947
|
+
normalizeAccountEmailHint,
|
|
25948
|
+
normalizeAccountEmail,
|
|
22373
25949
|
netlifyIntegration,
|
|
22374
25950
|
netatmoIntegration,
|
|
22375
25951
|
neonIntegration,
|
|
25952
|
+
mongodbAdapterCallbacks,
|
|
25953
|
+
mongodbAdapter,
|
|
22376
25954
|
moneybirdIntegration,
|
|
22377
25955
|
mondayIntegration,
|
|
22378
25956
|
miroIntegration,
|
|
@@ -22388,16 +25966,23 @@ export {
|
|
|
22388
25966
|
mapmyfitnessIntegration,
|
|
22389
25967
|
mailchimpIntegration,
|
|
22390
25968
|
lookerIntegration,
|
|
25969
|
+
listConnectedProvidersFromRows,
|
|
25970
|
+
listConnectedProviders,
|
|
22391
25971
|
linkedinIntegration,
|
|
22392
25972
|
linearIntegration,
|
|
22393
25973
|
leverIntegration,
|
|
22394
25974
|
klaviyoIntegration,
|
|
22395
25975
|
kickIntegration,
|
|
22396
25976
|
jiraIntegration,
|
|
25977
|
+
isLikelyUsableToken,
|
|
22397
25978
|
intercomIntegration,
|
|
25979
|
+
integrateTrigger,
|
|
25980
|
+
integrateProviderToken,
|
|
22398
25981
|
instagramIntegration,
|
|
22399
25982
|
hubspotIntegration,
|
|
22400
25983
|
homeConnectIntegration,
|
|
25984
|
+
hasUsableAccessToken,
|
|
25985
|
+
hasMeaningfulExpiresAt,
|
|
22401
25986
|
handleOpenAIResponse,
|
|
22402
25987
|
handleAnthropicMessage,
|
|
22403
25988
|
gtasksIntegration,
|
|
@@ -22434,6 +26019,7 @@ export {
|
|
|
22434
26019
|
freshserviceIntegration,
|
|
22435
26020
|
freeagentIntegration,
|
|
22436
26021
|
foursquareIntegration,
|
|
26022
|
+
flattenedTriggerToCreateInput,
|
|
22437
26023
|
fitbitIntegration,
|
|
22438
26024
|
firebaseIntegration,
|
|
22439
26025
|
figmaIntegration,
|
|
@@ -22451,9 +26037,12 @@ export {
|
|
|
22451
26037
|
ebayIntegration,
|
|
22452
26038
|
dropboxSignIntegration,
|
|
22453
26039
|
dropboxIntegration,
|
|
26040
|
+
drizzleAdapterCallbacks,
|
|
26041
|
+
drizzleAdapter,
|
|
22454
26042
|
docusignIntegration,
|
|
22455
26043
|
discordIntegration,
|
|
22456
26044
|
dhlIntegration,
|
|
26045
|
+
defaultResolveAccountIdentity,
|
|
22457
26046
|
deezerIntegration,
|
|
22458
26047
|
datadogIntegration,
|
|
22459
26048
|
databricksIntegration,
|
|
@@ -22463,6 +26052,8 @@ export {
|
|
|
22463
26052
|
createSimpleIntegration,
|
|
22464
26053
|
createNextOAuthHandler,
|
|
22465
26054
|
createMCPServer,
|
|
26055
|
+
createDatabaseAdapterFactory,
|
|
26056
|
+
createDatabaseAdapterCallbacks,
|
|
22466
26057
|
convexIntegration,
|
|
22467
26058
|
contentfulIntegration,
|
|
22468
26059
|
confluenceIntegration,
|