@tailor-platform/sdk 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/application-CTQe2HSB.mjs.map +1 -1
- package/dist/cli/index.d.mts +0 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/lib.d.mts +7 -8
- package/dist/cli/lib.mjs +1 -1
- package/dist/cli/skills.d.mts +0 -1
- package/dist/configure/index.d.mts +3 -4
- package/dist/{index-DPN_P0w3.d.mts → index-BSXclved.d.mts} +2 -3
- package/dist/{index-Cwi86SUR.d.mts → index-CO-jsOMb.d.mts} +2 -3
- package/dist/{index-BiutQT7m.d.mts → index-CU2kZzKa.d.mts} +3 -4
- package/dist/{index-ClS0NClx.d.mts → index-DQlsfhpg.d.mts} +2 -3
- package/dist/{index-BGPX26_D.d.mts → index-lIALNMi_.d.mts} +2 -3
- package/dist/kysely/index.d.mts +0 -1
- package/dist/plugin/builtin/enum-constants/index.d.mts +2 -3
- package/dist/plugin/builtin/file-utils/index.d.mts +2 -3
- package/dist/plugin/builtin/kysely-type/index.d.mts +2 -3
- package/dist/plugin/builtin/seed/index.d.mts +2 -3
- package/dist/plugin/index.d.mts +1 -2
- package/dist/{query-Bz2oDGhw.mjs → query-BLQBOaAM.mjs} +330 -70
- package/dist/query-BLQBOaAM.mjs.map +1 -0
- package/dist/schema-Cjm-OvPF.mjs.map +1 -1
- package/dist/{types-bcuNRo1Y.d.mts → types--G4ilVmx.d.mts} +3 -4
- package/dist/{types-DVMQNdTs.d.mts → types-IR-hw0-y.d.mts} +2 -3
- package/dist/utils/test/index.d.mts +3 -4
- package/docs/services/auth.md +2 -2
- package/package.json +3 -3
- package/postinstall.mjs +4 -14
- package/dist/query-Bz2oDGhw.mjs.map +0 -1
- package/dist/user-defined.d.ts +0 -13
|
@@ -2,7 +2,6 @@ import { t as db } from "./schema-Cjm-OvPF.mjs";
|
|
|
2
2
|
import { $ as AuthSCIMAttribute_Mutability, A as platformBaseUrl, B as TailorDBType_Permission_Permit, C as readPlatformConfig, E as fetchMachineUserToken, F as WorkflowJobExecution_Status, H as PipelineResolver_OperationType, I as TailorDBGQLPermission_Action, J as ExecutorTriggerType, K as ExecutorJobStatus, L as TailorDBGQLPermission_Operator, M as userAgent, N as WorkspacePlatformUserRole, P as WorkflowExecution_Status, Q as AuthOAuth2Client_GrantType, R as TailorDBGQLPermission_Permit, S as loadWorkspaceId, T as fetchAll, U as IdPLang, V as TailorDBType_PermitAction, W as FunctionExecution_Status, X as AuthInvokerSchema, Y as AuthIDPConfig_AuthType, Z as AuthOAuth2Client_ClientType, _ as hashFile, a as loadConfig, at as UserProfileProviderConfig_UserProfileProviderType, b as loadFolderId, ct as Condition_Operator, d as TailorDBTypeSchema, dt as ApplicationSchemaUpdateAttemptStatus, et as AuthSCIMAttribute_Type, f as stringifyFunction, ft as Subgraph_ServiceType, g as getDistDir, h as createBundleCache, ht as symbols, it as TenantProviderConfig_TenantProviderType, j as resolveStaticWebsiteUrls, k as initOperatorClient, l as OAuth2ClientSchema, lt as FilterSchema, m as loadFilesWithIgnores, mt as styles, n as generatePluginFilesIfNeeded, nt as AuthSCIMConfig_AuthorizationType, ot as GetApplicationSchemaHealthResponse_ApplicationSchemaHealthStatus, p as tailorUserMap, pt as logger, q as ExecutorTargetType, r as loadApplication, s as createExecutorService, st as ConditionSchema, t as defineApplication, tt as AuthSCIMAttribute_Uniqueness, ut as PageDirection, w as writePlatformConfig, x as loadOrganizationId, y as loadAccessToken, z as TailorDBType_Permission_Operator } from "./application-CTQe2HSB.mjs";
|
|
3
3
|
import { t as readPackageJson } from "./package-json-iVBhE5Ef.mjs";
|
|
4
4
|
import { r as withSpan } from "./telemetry-C46fds1l.mjs";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
5
|
import { arg, defineCommand, runCommand } from "politty";
|
|
7
6
|
import { z } from "zod";
|
|
8
7
|
import * as fs$1 from "node:fs";
|
|
@@ -28,7 +27,9 @@ import { setTimeout as setTimeout$1 } from "timers/promises";
|
|
|
28
27
|
import { spawn } from "node:child_process";
|
|
29
28
|
import { watch } from "chokidar";
|
|
30
29
|
import * as madgeModule from "madge";
|
|
30
|
+
import { createInterface } from "node:readline/promises";
|
|
31
31
|
import { astVisitor, parse, toSql } from "pgsql-ast-parser";
|
|
32
|
+
import { parse as parse$1 } from "@0no-co/graphql.web";
|
|
32
33
|
|
|
33
34
|
//#region src/cli/shared/errors.ts
|
|
34
35
|
/**
|
|
@@ -519,7 +520,6 @@ export {};
|
|
|
519
520
|
|
|
520
521
|
`;
|
|
521
522
|
}
|
|
522
|
-
const require = createRequire(import.meta.url);
|
|
523
523
|
function collectAttributesFromConfig(config) {
|
|
524
524
|
const auth = config.auth;
|
|
525
525
|
if (!auth || typeof auth !== "object") return {};
|
|
@@ -562,12 +562,7 @@ function collectAttributesFromConfig(config) {
|
|
|
562
562
|
* @returns Absolute path to the type definition file
|
|
563
563
|
*/
|
|
564
564
|
function resolveTypeDefinitionPath(configPath) {
|
|
565
|
-
|
|
566
|
-
if (typePath) return path.resolve(process.cwd(), typePath);
|
|
567
|
-
const configDir = path.dirname(path.resolve(configPath));
|
|
568
|
-
const packageDir = resolvePackageDirectory(configDir);
|
|
569
|
-
if (!packageDir) return path.join(configDir, "node_modules", "@tailor-platform", "sdk", "dist", "user-defined.d.ts");
|
|
570
|
-
return path.join(packageDir, "dist", "user-defined.d.ts");
|
|
565
|
+
return path.join(path.dirname(path.resolve(configPath)), "tailor.d.ts");
|
|
571
566
|
}
|
|
572
567
|
/**
|
|
573
568
|
* Generate user type definitions from the app config and write them to disk.
|
|
@@ -595,23 +590,6 @@ async function generateUserTypes(options) {
|
|
|
595
590
|
logger.error(String(error));
|
|
596
591
|
}
|
|
597
592
|
}
|
|
598
|
-
function resolvePackageDirectory(startDir) {
|
|
599
|
-
let currentDir = startDir;
|
|
600
|
-
const root = path.parse(currentDir).root;
|
|
601
|
-
while (true) {
|
|
602
|
-
const candidate = path.join(currentDir, "node_modules", "@tailor-platform", "sdk");
|
|
603
|
-
const packageJsonPath = path.join(candidate, "package.json");
|
|
604
|
-
if (fs$1.existsSync(packageJsonPath)) return candidate;
|
|
605
|
-
if (currentDir === root) break;
|
|
606
|
-
currentDir = path.dirname(currentDir);
|
|
607
|
-
}
|
|
608
|
-
try {
|
|
609
|
-
const resolved = require.resolve("@tailor-platform/sdk/package.json", { paths: [startDir] });
|
|
610
|
-
return path.dirname(resolved);
|
|
611
|
-
} catch {
|
|
612
|
-
return null;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
593
|
|
|
616
594
|
//#endregion
|
|
617
595
|
//#region src/parser/plugin-config/generation-types.ts
|
|
@@ -11451,6 +11429,118 @@ function mapQueryExecutionError(args) {
|
|
|
11451
11429
|
return args.error instanceof Error ? args.error : new Error(message);
|
|
11452
11430
|
}
|
|
11453
11431
|
|
|
11432
|
+
//#endregion
|
|
11433
|
+
//#region src/cli/query/graphql-repl.ts
|
|
11434
|
+
/**
|
|
11435
|
+
* Return true when the buffered GraphQL input parses as a complete document.
|
|
11436
|
+
* @param input - Buffered GraphQL input
|
|
11437
|
+
* @returns True when the GraphQL document is complete and ready to execute
|
|
11438
|
+
*/
|
|
11439
|
+
function isGraphQLInputComplete(input) {
|
|
11440
|
+
if (input.trim().length === 0) return false;
|
|
11441
|
+
try {
|
|
11442
|
+
parse$1(input);
|
|
11443
|
+
return true;
|
|
11444
|
+
} catch {
|
|
11445
|
+
return false;
|
|
11446
|
+
}
|
|
11447
|
+
}
|
|
11448
|
+
|
|
11449
|
+
//#endregion
|
|
11450
|
+
//#region src/cli/query/sql-repl.ts
|
|
11451
|
+
/**
|
|
11452
|
+
* Return true when the buffered SQL input ends with a real statement terminator.
|
|
11453
|
+
* @param input - Buffered SQL input
|
|
11454
|
+
* @returns True when the SQL statement is complete and ready to execute
|
|
11455
|
+
*/
|
|
11456
|
+
function isSqlInputComplete(input) {
|
|
11457
|
+
let inSingleQuote = false;
|
|
11458
|
+
let inDoubleQuote = false;
|
|
11459
|
+
let inLineComment = false;
|
|
11460
|
+
let blockCommentDepth = 0;
|
|
11461
|
+
let dollarQuoteTag = null;
|
|
11462
|
+
let lastSignificantTokenWasSemicolon = false;
|
|
11463
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
11464
|
+
const char = input[i];
|
|
11465
|
+
const next = input[i + 1];
|
|
11466
|
+
if (inLineComment) {
|
|
11467
|
+
if (char === "\n") inLineComment = false;
|
|
11468
|
+
continue;
|
|
11469
|
+
}
|
|
11470
|
+
if (blockCommentDepth > 0) {
|
|
11471
|
+
if (char === "/" && next === "*") {
|
|
11472
|
+
blockCommentDepth += 1;
|
|
11473
|
+
i += 1;
|
|
11474
|
+
continue;
|
|
11475
|
+
}
|
|
11476
|
+
if (char === "*" && next === "/") {
|
|
11477
|
+
blockCommentDepth -= 1;
|
|
11478
|
+
i += 1;
|
|
11479
|
+
}
|
|
11480
|
+
continue;
|
|
11481
|
+
}
|
|
11482
|
+
if (dollarQuoteTag != null) {
|
|
11483
|
+
if (input.startsWith(dollarQuoteTag, i)) {
|
|
11484
|
+
i += dollarQuoteTag.length - 1;
|
|
11485
|
+
dollarQuoteTag = null;
|
|
11486
|
+
}
|
|
11487
|
+
continue;
|
|
11488
|
+
}
|
|
11489
|
+
if (inSingleQuote) {
|
|
11490
|
+
if (char === "'" && next === "'") {
|
|
11491
|
+
i += 1;
|
|
11492
|
+
continue;
|
|
11493
|
+
}
|
|
11494
|
+
if (char === "'") inSingleQuote = false;
|
|
11495
|
+
continue;
|
|
11496
|
+
}
|
|
11497
|
+
if (inDoubleQuote) {
|
|
11498
|
+
if (char === "\"" && next === "\"") {
|
|
11499
|
+
i += 1;
|
|
11500
|
+
continue;
|
|
11501
|
+
}
|
|
11502
|
+
if (char === "\"") inDoubleQuote = false;
|
|
11503
|
+
continue;
|
|
11504
|
+
}
|
|
11505
|
+
if (char === "-" && next === "-") {
|
|
11506
|
+
inLineComment = true;
|
|
11507
|
+
i += 1;
|
|
11508
|
+
continue;
|
|
11509
|
+
}
|
|
11510
|
+
if (char === "/" && next === "*") {
|
|
11511
|
+
blockCommentDepth = 1;
|
|
11512
|
+
i += 1;
|
|
11513
|
+
continue;
|
|
11514
|
+
}
|
|
11515
|
+
if (char === "'") {
|
|
11516
|
+
lastSignificantTokenWasSemicolon = false;
|
|
11517
|
+
inSingleQuote = true;
|
|
11518
|
+
continue;
|
|
11519
|
+
}
|
|
11520
|
+
if (char === "\"") {
|
|
11521
|
+
lastSignificantTokenWasSemicolon = false;
|
|
11522
|
+
inDoubleQuote = true;
|
|
11523
|
+
continue;
|
|
11524
|
+
}
|
|
11525
|
+
if (char === "$") {
|
|
11526
|
+
const rest = input.slice(i);
|
|
11527
|
+
const match = rest.match(/^\$[A-Za-z_][A-Za-z0-9_]*\$/) ?? rest.match(/^\$\$/);
|
|
11528
|
+
if (match != null) {
|
|
11529
|
+
lastSignificantTokenWasSemicolon = false;
|
|
11530
|
+
dollarQuoteTag = match[0];
|
|
11531
|
+
i += match[0].length - 1;
|
|
11532
|
+
continue;
|
|
11533
|
+
}
|
|
11534
|
+
}
|
|
11535
|
+
if (char === ";") {
|
|
11536
|
+
lastSignificantTokenWasSemicolon = true;
|
|
11537
|
+
continue;
|
|
11538
|
+
}
|
|
11539
|
+
if (!/\s/.test(char)) lastSignificantTokenWasSemicolon = false;
|
|
11540
|
+
}
|
|
11541
|
+
return lastSignificantTokenWasSemicolon && !inSingleQuote && !inDoubleQuote && blockCommentDepth === 0 && dollarQuoteTag == null;
|
|
11542
|
+
}
|
|
11543
|
+
|
|
11454
11544
|
//#endregion
|
|
11455
11545
|
//#region src/cli/query/sql-type-extractor.ts
|
|
11456
11546
|
/**
|
|
@@ -11560,14 +11650,14 @@ async function loadTypeFieldOrder(config, namespace) {
|
|
|
11560
11650
|
//#endregion
|
|
11561
11651
|
//#region src/cli/query/index.ts
|
|
11562
11652
|
const queryEngineSchema = z.enum(["sql", "gql"]);
|
|
11563
|
-
const
|
|
11653
|
+
const queryBaseOptionsSchema = z.object({
|
|
11564
11654
|
workspaceId: z.string().optional(),
|
|
11565
11655
|
profile: z.string().optional(),
|
|
11566
11656
|
configPath: z.string().optional(),
|
|
11567
11657
|
engine: queryEngineSchema,
|
|
11568
|
-
query: z.string(),
|
|
11569
11658
|
machineUser: z.string()
|
|
11570
11659
|
});
|
|
11660
|
+
const queryOptionsSchema = queryBaseOptionsSchema.extend({ query: z.string() });
|
|
11571
11661
|
async function getNamespaceFromSqlQuery(workspaceId, query$1, client, namespaces) {
|
|
11572
11662
|
if (namespaces.length === 0) throw new Error("No namespaces found in configuration.");
|
|
11573
11663
|
if (namespaces.length === 1) return namespaces[0];
|
|
@@ -11586,7 +11676,7 @@ async function getNamespaceFromSqlQuery(workspaceId, query$1, client, namespaces
|
|
|
11586
11676
|
throw new Error(`Query references types from multiple namespaces: ${[...namespacesFromTypes].join(", ")}.`);
|
|
11587
11677
|
}
|
|
11588
11678
|
async function loadOptions(options) {
|
|
11589
|
-
const result =
|
|
11679
|
+
const result = queryBaseOptionsSchema.safeParse(options);
|
|
11590
11680
|
if (!result.success) throw new Error(result.error.issues[0].message);
|
|
11591
11681
|
const client = await initOperatorClient(await loadAccessToken({
|
|
11592
11682
|
useProfile: true,
|
|
@@ -11609,23 +11699,14 @@ async function loadOptions(options) {
|
|
|
11609
11699
|
name: result.data.machineUser
|
|
11610
11700
|
});
|
|
11611
11701
|
if (!machineUserResource) throw new Error(`Machine user ${result.data.machineUser} not found.`);
|
|
11612
|
-
if (options.engine === "gql") return {
|
|
11613
|
-
engine: options.engine,
|
|
11614
|
-
client,
|
|
11615
|
-
workspaceId,
|
|
11616
|
-
config,
|
|
11617
|
-
application,
|
|
11618
|
-
machineUserResource
|
|
11619
|
-
};
|
|
11620
|
-
const namespace = await getNamespaceFromSqlQuery(workspaceId, result.data.query, client, namespaces);
|
|
11621
11702
|
return {
|
|
11622
|
-
engine:
|
|
11703
|
+
engine: result.data.engine,
|
|
11623
11704
|
client,
|
|
11624
11705
|
workspaceId,
|
|
11625
11706
|
config,
|
|
11626
11707
|
application,
|
|
11627
11708
|
machineUserResource,
|
|
11628
|
-
|
|
11709
|
+
namespaces
|
|
11629
11710
|
};
|
|
11630
11711
|
}
|
|
11631
11712
|
async function sqlQuery(client, invoker, args) {
|
|
@@ -11679,40 +11760,204 @@ function parseExecutionResult(result) {
|
|
|
11679
11760
|
}
|
|
11680
11761
|
}
|
|
11681
11762
|
/**
|
|
11763
|
+
* Resolve query input mode from CLI args.
|
|
11764
|
+
* @param args - Query input flags
|
|
11765
|
+
* @param args.query - Direct query string
|
|
11766
|
+
* @returns Normalized input mode
|
|
11767
|
+
*/
|
|
11768
|
+
function resolveQueryCommandInput(args) {
|
|
11769
|
+
if (args.query != null) return { query: args.query };
|
|
11770
|
+
return { query: void 0 };
|
|
11771
|
+
}
|
|
11772
|
+
/**
|
|
11682
11773
|
* Dispatch query execution.
|
|
11683
11774
|
* @param options - Query command options
|
|
11684
11775
|
* @returns Dispatch result
|
|
11685
11776
|
*/
|
|
11686
11777
|
async function query(options) {
|
|
11687
|
-
const
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11778
|
+
const result = queryOptionsSchema.safeParse(options);
|
|
11779
|
+
if (!result.success) throw new Error(result.error.issues[0].message);
|
|
11780
|
+
return await (await prepareQueryExecutor(result.data))(result.data.query);
|
|
11781
|
+
}
|
|
11782
|
+
async function prepareQueryExecutor(options) {
|
|
11783
|
+
const { client, workspaceId, config, application, machineUserResource, engine, namespaces } = await loadOptions(options);
|
|
11784
|
+
const bundledCode = await bundleQueryScript(engine);
|
|
11785
|
+
const invoker = create(AuthInvokerSchema, {
|
|
11786
|
+
namespace: application.authNamespace,
|
|
11787
|
+
machineUserName: machineUserResource.name
|
|
11788
|
+
});
|
|
11789
|
+
return async (queryString) => {
|
|
11790
|
+
let namespace;
|
|
11791
|
+
try {
|
|
11792
|
+
switch (engine) {
|
|
11793
|
+
case "sql":
|
|
11794
|
+
namespace = await getNamespaceFromSqlQuery(workspaceId, queryString, client, namespaces);
|
|
11795
|
+
return reorderSqlColumns(await sqlQuery(client, invoker, {
|
|
11796
|
+
workspaceId,
|
|
11797
|
+
namespace,
|
|
11798
|
+
bundledCode,
|
|
11799
|
+
query: queryString
|
|
11800
|
+
}), config, namespace, queryString);
|
|
11801
|
+
case "gql": return await gqlQuery(client, invoker, application, machineUserResource, {
|
|
11802
|
+
workspaceId,
|
|
11803
|
+
bundledCode,
|
|
11804
|
+
query: queryString
|
|
11805
|
+
});
|
|
11806
|
+
default: throw new Error(`Unsupported query engine: ${engine}`);
|
|
11807
|
+
}
|
|
11808
|
+
} catch (error) {
|
|
11809
|
+
throw mapQueryExecutionError({
|
|
11810
|
+
error,
|
|
11811
|
+
engine,
|
|
11697
11812
|
namespace,
|
|
11698
|
-
|
|
11699
|
-
query: options.query
|
|
11700
|
-
}), config, namespace, options.query);
|
|
11701
|
-
case "gql": return await gqlQuery(client, invoker, application, machineUserResource, {
|
|
11702
|
-
workspaceId,
|
|
11703
|
-
bundledCode,
|
|
11704
|
-
query: options.query
|
|
11813
|
+
machineUser: options.machineUser
|
|
11705
11814
|
});
|
|
11706
|
-
default: throw new Error(`Unsupported query engine: ${engine}`);
|
|
11707
11815
|
}
|
|
11708
|
-
}
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11714
|
-
|
|
11816
|
+
};
|
|
11817
|
+
}
|
|
11818
|
+
function isReadlineTerminationError(error) {
|
|
11819
|
+
if (!(error instanceof Error) || !("code" in error)) return false;
|
|
11820
|
+
return error.code === "ABORT_ERR" || error.code === "ERR_USE_AFTER_CLOSE";
|
|
11821
|
+
}
|
|
11822
|
+
/**
|
|
11823
|
+
* Resolve a backslash REPL command into its normalized action.
|
|
11824
|
+
* @param input - Raw user input
|
|
11825
|
+
* @returns Normalized REPL command, or null for non-command input
|
|
11826
|
+
*/
|
|
11827
|
+
function resolveReplCommand(input) {
|
|
11828
|
+
const trimmed = input.trim();
|
|
11829
|
+
if (!trimmed.startsWith("\\")) return null;
|
|
11830
|
+
if (trimmed === "\\q" || trimmed === "\\quit") return "quit";
|
|
11831
|
+
if (trimmed === "\\help" || trimmed === "\\h" || trimmed === "\\?") return "help";
|
|
11832
|
+
if (trimmed === "\\clear" || trimmed === "\\c") return "clear";
|
|
11833
|
+
return "unknown";
|
|
11834
|
+
}
|
|
11835
|
+
/**
|
|
11836
|
+
* Decide how REPL should react to Ctrl+C based on current buffered input.
|
|
11837
|
+
* @param bufferedLines - Previously accepted lines in the current statement buffer
|
|
11838
|
+
* @param currentLine - In-progress line currently being edited
|
|
11839
|
+
* @returns Whether to clear the buffer or exit the REPL
|
|
11840
|
+
*/
|
|
11841
|
+
function resolveReplInterruptAction(bufferedLines, currentLine) {
|
|
11842
|
+
if (bufferedLines.length === 0 && currentLine.length === 0) return "exit";
|
|
11843
|
+
return "clear";
|
|
11844
|
+
}
|
|
11845
|
+
/**
|
|
11846
|
+
* Clear the interactive terminal screen and move the cursor to the top-left.
|
|
11847
|
+
*/
|
|
11848
|
+
function clearReplScreen() {
|
|
11849
|
+
process.stdout.write("\x1Bc");
|
|
11850
|
+
}
|
|
11851
|
+
async function runRepl(options) {
|
|
11852
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error("Non-interactive terminals are not supported. Pass -q/--query to run a query.");
|
|
11853
|
+
const execute = await prepareQueryExecutor(options);
|
|
11854
|
+
const rl = createInterface({
|
|
11855
|
+
input: process.stdin,
|
|
11856
|
+
output: process.stdout
|
|
11857
|
+
});
|
|
11858
|
+
logger.info(`Entering ${options.engine.toUpperCase()} REPL mode.`);
|
|
11859
|
+
logger.info("Type \\help for usage, \\q to quit.");
|
|
11860
|
+
const lines = [];
|
|
11861
|
+
try {
|
|
11862
|
+
while (true) {
|
|
11863
|
+
const prompt = lines.length === 0 ? `${options.engine}> ` : " ";
|
|
11864
|
+
let line;
|
|
11865
|
+
let interruptAction = null;
|
|
11866
|
+
const controller = new AbortController();
|
|
11867
|
+
const handleSigint = () => {
|
|
11868
|
+
interruptAction = resolveReplInterruptAction(lines, rl.line);
|
|
11869
|
+
if (interruptAction === "clear") {
|
|
11870
|
+
lines.length = 0;
|
|
11871
|
+
rl.write(null, {
|
|
11872
|
+
ctrl: true,
|
|
11873
|
+
name: "u"
|
|
11874
|
+
});
|
|
11875
|
+
process.stdout.write("\n");
|
|
11876
|
+
} else rl.close();
|
|
11877
|
+
controller.abort();
|
|
11878
|
+
};
|
|
11879
|
+
rl.once("SIGINT", handleSigint);
|
|
11880
|
+
try {
|
|
11881
|
+
line = await rl.question(prompt, { signal: controller.signal });
|
|
11882
|
+
} catch (error) {
|
|
11883
|
+
rl.off("SIGINT", handleSigint);
|
|
11884
|
+
if (controller.signal.aborted) {
|
|
11885
|
+
if (interruptAction === "exit") return;
|
|
11886
|
+
continue;
|
|
11887
|
+
}
|
|
11888
|
+
if (isReadlineTerminationError(error)) return;
|
|
11889
|
+
throw error;
|
|
11890
|
+
} finally {
|
|
11891
|
+
rl.off("SIGINT", handleSigint);
|
|
11892
|
+
}
|
|
11893
|
+
const trimmed = line.trim();
|
|
11894
|
+
if (lines.length === 0 && trimmed === "") continue;
|
|
11895
|
+
if (lines.length === 0) {
|
|
11896
|
+
const command = resolveReplCommand(trimmed);
|
|
11897
|
+
if (command === "quit") return;
|
|
11898
|
+
if (command === "help") {
|
|
11899
|
+
printReplHelp(options.engine);
|
|
11900
|
+
continue;
|
|
11901
|
+
}
|
|
11902
|
+
if (command === "clear") {
|
|
11903
|
+
clearReplScreen();
|
|
11904
|
+
continue;
|
|
11905
|
+
}
|
|
11906
|
+
if (command === "unknown") {
|
|
11907
|
+
logger.warn(`Unknown command: ${trimmed}`);
|
|
11908
|
+
continue;
|
|
11909
|
+
}
|
|
11910
|
+
}
|
|
11911
|
+
lines.push(line);
|
|
11912
|
+
if (options.engine === "sql") {
|
|
11913
|
+
if (!isSqlInputComplete(lines.join("\n"))) continue;
|
|
11914
|
+
} else if (!isGraphQLInputComplete(lines.join("\n"))) continue;
|
|
11915
|
+
const statement = getReplStatement(lines, options.engine);
|
|
11916
|
+
lines.length = 0;
|
|
11917
|
+
if (statement.length === 0) continue;
|
|
11918
|
+
try {
|
|
11919
|
+
if (options.engine === "sql") {
|
|
11920
|
+
const result$1 = await execute(statement);
|
|
11921
|
+
if (result$1.engine !== "sql") throw new Error(`Expected sql engine result but got: ${result$1.engine}`);
|
|
11922
|
+
printSqlResult(result$1, { json: options.json });
|
|
11923
|
+
continue;
|
|
11924
|
+
}
|
|
11925
|
+
const result = await execute(statement);
|
|
11926
|
+
if (result.engine !== "gql") throw new Error(`Expected gql engine result but got: ${result.engine}`);
|
|
11927
|
+
printGqlResult(result, { json: options.json });
|
|
11928
|
+
} catch (error) {
|
|
11929
|
+
if (isCLIError(error)) {
|
|
11930
|
+
logger.log(error.format());
|
|
11931
|
+
continue;
|
|
11932
|
+
}
|
|
11933
|
+
if (error instanceof Error) {
|
|
11934
|
+
logger.error(error.message);
|
|
11935
|
+
continue;
|
|
11936
|
+
}
|
|
11937
|
+
logger.error(String(error));
|
|
11938
|
+
}
|
|
11939
|
+
}
|
|
11940
|
+
} finally {
|
|
11941
|
+
rl.close();
|
|
11942
|
+
}
|
|
11943
|
+
}
|
|
11944
|
+
function getReplStatement(lines, engine) {
|
|
11945
|
+
if (engine === "sql") return lines.join("\n").trim();
|
|
11946
|
+
let end = lines.length;
|
|
11947
|
+
while (end > 0 && lines[end - 1].trim() === "") end -= 1;
|
|
11948
|
+
return lines.slice(0, end).join("\n").trim();
|
|
11949
|
+
}
|
|
11950
|
+
function printReplHelp(engine) {
|
|
11951
|
+
logger.log("REPL commands:");
|
|
11952
|
+
logger.log(" \\help, \\h, \\? Show this help");
|
|
11953
|
+
logger.log(" Ctrl+C Clear current input");
|
|
11954
|
+
logger.log(" \\q, \\quit, Ctrl+D Exit REPL");
|
|
11955
|
+
logger.log(" \\clear, \\c Clear the screen");
|
|
11956
|
+
if (engine === "sql") {
|
|
11957
|
+
logger.log("SQL execution: statement ending with ';' runs immediately.");
|
|
11958
|
+
return;
|
|
11715
11959
|
}
|
|
11960
|
+
logger.log("GraphQL execution: a complete GraphQL document runs immediately.");
|
|
11716
11961
|
}
|
|
11717
11962
|
/**
|
|
11718
11963
|
* Execute SQL query directly.
|
|
@@ -11793,9 +12038,9 @@ const queryCommand = defineCommand({
|
|
|
11793
12038
|
...jsonArgs,
|
|
11794
12039
|
...deploymentArgs,
|
|
11795
12040
|
engine: arg(queryEngineSchema, { description: "Query engine (sql or gql)" }),
|
|
11796
|
-
query: arg(z.string(), {
|
|
12041
|
+
query: arg(z.string().optional(), {
|
|
11797
12042
|
alias: "q",
|
|
11798
|
-
description: "Query string to execute directly"
|
|
12043
|
+
description: "Query string to execute directly; omit to start REPL mode"
|
|
11799
12044
|
}),
|
|
11800
12045
|
machineuser: arg(z.string(), {
|
|
11801
12046
|
alias: "m",
|
|
@@ -11803,18 +12048,33 @@ const queryCommand = defineCommand({
|
|
|
11803
12048
|
})
|
|
11804
12049
|
}).strict(),
|
|
11805
12050
|
run: withCommonArgs(async (args) => {
|
|
12051
|
+
const mode = resolveQueryCommandInput({ query: args.query });
|
|
11806
12052
|
const sharedOptions = {
|
|
11807
12053
|
workspaceId: args["workspace-id"],
|
|
11808
12054
|
profile: args.profile,
|
|
11809
12055
|
configPath: args.config,
|
|
11810
|
-
|
|
12056
|
+
engine: args.engine,
|
|
11811
12057
|
machineUser: args.machineuser
|
|
11812
12058
|
};
|
|
12059
|
+
if (mode.query == null) {
|
|
12060
|
+
await runRepl({
|
|
12061
|
+
...sharedOptions,
|
|
12062
|
+
json: args.json
|
|
12063
|
+
});
|
|
12064
|
+
return;
|
|
12065
|
+
}
|
|
12066
|
+
const directQuery = mode.query;
|
|
11813
12067
|
if (args.engine === "sql") {
|
|
11814
|
-
printSqlResult(await querySql(
|
|
12068
|
+
printSqlResult(await querySql({
|
|
12069
|
+
...sharedOptions,
|
|
12070
|
+
query: directQuery
|
|
12071
|
+
}), { json: args.json });
|
|
11815
12072
|
return;
|
|
11816
12073
|
}
|
|
11817
|
-
printGqlResult(await queryGql(
|
|
12074
|
+
printGqlResult(await queryGql({
|
|
12075
|
+
...sharedOptions,
|
|
12076
|
+
query: directQuery
|
|
12077
|
+
}), { json: args.json });
|
|
11818
12078
|
})
|
|
11819
12079
|
});
|
|
11820
12080
|
function isSQLExecutionResult(value) {
|
|
@@ -11894,4 +12154,4 @@ function printGqlResult(result, options = {}) {
|
|
|
11894
12154
|
|
|
11895
12155
|
//#endregion
|
|
11896
12156
|
export { getExecutorJob as $, truncateCommand as A, getMigrationDirPath as At, getCommand$1 as B, getNamespacesWithMigrations as Bt, getAppHealth as C, MIGRATE_FILE_NAME as Ct, listCommand$3 as D, createSnapshotFromLocalTypes as Dt, resumeWorkflow as E, compareSnapshots as Et, showCommand as F, loadDiff as Ft, listMachineUsers as G, commonArgs as Gt, getMachineUserToken as H, generateUserTypes as Ht, remove as I, reconstructSnapshotFromMigrations as It, webhookCommand as J, jsonArgs as Jt, generate$1 as K, confirmationArgs as Kt, removeCommand$1 as L, formatDiffSummary as Lt, generateCommand as M, getMigrationFiles as Mt, logBetaWarning as N, getNextMigrationNumber as Nt, listWorkflows as O, formatMigrationNumber as Ot, show as P, isValidMigrationNumber as Pt, listExecutors as Q, listCommand$4 as R, formatMigrationDiff as Rt, listCommand$2 as S, INITIAL_SCHEMA_NUMBER as St, resumeCommand as T, compareLocalTypesWithSnapshot as Tt, tokenCommand as U, apiCall as Ut, getOAuth2Client as V, trnPrefix as Vt, listCommand$5 as W, apiCommand as Wt, triggerExecutor as X, workspaceArgs as Xt, triggerCommand as Y, withCommonArgs as Yt, listCommand$6 as Z, deleteCommand as _, MIGRATION_LABEL_KEY as _t, removeCommand as a, getCommand$2 as at, createWorkspace as b, DB_TYPES_FILE_NAME as bt, listUsers as c, getWorkflowExecution as ct, restoreCommand as d, formatKeyValueTable as dt, jobsCommand as et, restoreWorkspace as f, getCommand$3 as ft, getWorkspace as g, waitForExecution$1 as gt, getCommand as h, executeScript as ht, updateUser as i, startWorkflow as it, generate as j, getMigrationFilePath as jt, truncate as k, getLatestMigrationNumber as kt, inviteCommand as l, listWorkflowExecutions as lt, listWorkspaces as m, apply as mt, queryCommand as n, watchExecutorJob as nt, removeUser as o, getWorkflow as ot, listCommand$1 as p, getExecutor as pt, listWebhookExecutors as q, deploymentArgs as qt, updateCommand as r, startCommand as rt, listCommand as s, executionsCommand as st, query as t, listExecutorJobs as tt, inviteUser as u, functionExecutionStatusToString as ut, deleteWorkspace as v, parseMigrationLabelNumber as vt, healthCommand as w, SCHEMA_FILE_NAME as wt, listApps as x, DIFF_FILE_NAME as xt, createCommand as y, bundleMigrationScript as yt, listOAuth2Clients as z, hasChanges as zt };
|
|
11897
|
-
//# sourceMappingURL=query-
|
|
12157
|
+
//# sourceMappingURL=query-BLQBOaAM.mjs.map
|