forge-sql-orm 2.1.12 → 2.1.14

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.
Files changed (79) hide show
  1. package/README.md +922 -549
  2. package/dist/core/ForgeSQLAnalyseOperations.d.ts.map +1 -1
  3. package/dist/core/ForgeSQLAnalyseOperations.js +257 -0
  4. package/dist/core/ForgeSQLAnalyseOperations.js.map +1 -0
  5. package/dist/core/ForgeSQLCacheOperations.js +172 -0
  6. package/dist/core/ForgeSQLCacheOperations.js.map +1 -0
  7. package/dist/core/ForgeSQLCrudOperations.js +349 -0
  8. package/dist/core/ForgeSQLCrudOperations.js.map +1 -0
  9. package/dist/core/ForgeSQLORM.d.ts +29 -1
  10. package/dist/core/ForgeSQLORM.d.ts.map +1 -1
  11. package/dist/core/ForgeSQLORM.js +1252 -0
  12. package/dist/core/ForgeSQLORM.js.map +1 -0
  13. package/dist/core/ForgeSQLQueryBuilder.d.ts +179 -1
  14. package/dist/core/ForgeSQLQueryBuilder.d.ts.map +1 -1
  15. package/dist/core/ForgeSQLQueryBuilder.js +77 -0
  16. package/dist/core/ForgeSQLQueryBuilder.js.map +1 -0
  17. package/dist/core/ForgeSQLSelectOperations.js +81 -0
  18. package/dist/core/ForgeSQLSelectOperations.js.map +1 -0
  19. package/dist/core/Rovo.d.ts +116 -0
  20. package/dist/core/Rovo.d.ts.map +1 -0
  21. package/dist/core/Rovo.js +647 -0
  22. package/dist/core/Rovo.js.map +1 -0
  23. package/dist/core/SystemTables.js +258 -0
  24. package/dist/core/SystemTables.js.map +1 -0
  25. package/dist/index.js +30 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/lib/drizzle/extensions/additionalActions.d.ts.map +1 -1
  28. package/dist/lib/drizzle/extensions/additionalActions.js +527 -0
  29. package/dist/lib/drizzle/extensions/additionalActions.js.map +1 -0
  30. package/dist/utils/cacheContextUtils.d.ts.map +1 -1
  31. package/dist/utils/cacheContextUtils.js +198 -0
  32. package/dist/utils/cacheContextUtils.js.map +1 -0
  33. package/dist/utils/cacheUtils.d.ts.map +1 -1
  34. package/dist/utils/cacheUtils.js +383 -0
  35. package/dist/utils/cacheUtils.js.map +1 -0
  36. package/dist/utils/forgeDriver.d.ts.map +1 -1
  37. package/dist/utils/forgeDriver.js +139 -0
  38. package/dist/utils/forgeDriver.js.map +1 -0
  39. package/dist/utils/forgeDriverProxy.js +68 -0
  40. package/dist/utils/forgeDriverProxy.js.map +1 -0
  41. package/dist/utils/metadataContextUtils.d.ts.map +1 -1
  42. package/dist/utils/metadataContextUtils.js +26 -0
  43. package/dist/utils/metadataContextUtils.js.map +1 -0
  44. package/dist/utils/requestTypeContextUtils.js +10 -0
  45. package/dist/utils/requestTypeContextUtils.js.map +1 -0
  46. package/dist/utils/sqlHints.js +52 -0
  47. package/dist/utils/sqlHints.js.map +1 -0
  48. package/dist/utils/sqlUtils.d.ts.map +1 -1
  49. package/dist/utils/sqlUtils.js +590 -0
  50. package/dist/utils/sqlUtils.js.map +1 -0
  51. package/dist/webtriggers/applyMigrationsWebTrigger.js +77 -0
  52. package/dist/webtriggers/applyMigrationsWebTrigger.js.map +1 -0
  53. package/dist/webtriggers/clearCacheSchedulerTrigger.js +83 -0
  54. package/dist/webtriggers/clearCacheSchedulerTrigger.js.map +1 -0
  55. package/dist/webtriggers/dropMigrationWebTrigger.js +54 -0
  56. package/dist/webtriggers/dropMigrationWebTrigger.js.map +1 -0
  57. package/dist/webtriggers/dropTablesMigrationWebTrigger.js +54 -0
  58. package/dist/webtriggers/dropTablesMigrationWebTrigger.js.map +1 -0
  59. package/dist/webtriggers/fetchSchemaWebTrigger.js +82 -0
  60. package/dist/webtriggers/fetchSchemaWebTrigger.js.map +1 -0
  61. package/dist/webtriggers/index.js +40 -0
  62. package/dist/webtriggers/index.js.map +1 -0
  63. package/dist/webtriggers/slowQuerySchedulerTrigger.js +80 -0
  64. package/dist/webtriggers/slowQuerySchedulerTrigger.js.map +1 -0
  65. package/package.json +31 -25
  66. package/src/core/ForgeSQLAnalyseOperations.ts +3 -2
  67. package/src/core/ForgeSQLORM.ts +64 -0
  68. package/src/core/ForgeSQLQueryBuilder.ts +200 -1
  69. package/src/core/Rovo.ts +765 -0
  70. package/src/lib/drizzle/extensions/additionalActions.ts +11 -0
  71. package/src/utils/cacheContextUtils.ts +9 -6
  72. package/src/utils/cacheUtils.ts +6 -4
  73. package/src/utils/forgeDriver.ts +3 -7
  74. package/src/utils/metadataContextUtils.ts +1 -3
  75. package/src/utils/sqlUtils.ts +33 -34
  76. package/dist/ForgeSQLORM.js +0 -3922
  77. package/dist/ForgeSQLORM.js.map +0 -1
  78. package/dist/ForgeSQLORM.mjs +0 -3905
  79. package/dist/ForgeSQLORM.mjs.map +0 -1
@@ -5,6 +5,7 @@ import {
5
5
  ForgeSqlOrmOptions,
6
6
  SchemaAnalyzeForgeSql,
7
7
  SchemaSqlForgeSql,
8
+ RovoIntegration,
8
9
  } from "./ForgeSQLQueryBuilder";
9
10
  import { ForgeSQLSelectOperations } from "./ForgeSQLSelectOperations";
10
11
  import {
@@ -41,6 +42,7 @@ import { WithSubquery } from "drizzle-orm/subquery";
41
42
  import { getLastestMetadata, metadataQueryContext } from "../utils/metadataContextUtils";
42
43
  import { operationTypeQueryContext } from "../utils/requestTypeContextUtils";
43
44
  import type { MySqlQueryResultKind } from "drizzle-orm/mysql-core/session";
45
+ import { Rovo } from "./Rovo";
44
46
 
45
47
  /**
46
48
  * Implementation of ForgeSQLORM that uses Drizzle ORM for query building.
@@ -827,6 +829,37 @@ class ForgeSQLORMImpl implements ForgeSqlOperation {
827
829
  with(...queries: WithSubquery[]) {
828
830
  return this.drizzle.with(...queries);
829
831
  }
832
+
833
+ /**
834
+ * Provides access to Rovo integration - a secure pattern for natural-language analytics.
835
+ *
836
+ * Rovo enables secure execution of dynamic SQL queries with comprehensive security validations:
837
+ * - Only SELECT queries are allowed
838
+ * - Queries are restricted to a single table
839
+ * - JOINs, subqueries, and window functions are blocked
840
+ * - Row-Level Security (RLS) support for data isolation
841
+ *
842
+ * @returns {RovoIntegration} Rovo integration instance for secure dynamic queries
843
+ *
844
+ * @example
845
+ * ```typescript
846
+ * const rovo = forgeSQL.rovo();
847
+ * const settings = await rovo.rovoSettingBuilder(usersTable, accountId)
848
+ * .useRLS()
849
+ * .addRlsColumn(usersTable.id)
850
+ * .addRlsWherePart((alias) => `${alias}.id = '${accountId}'`)
851
+ * .finish()
852
+ * .build();
853
+ *
854
+ * const result = await rovo.dynamicIsolatedQuery(
855
+ * "SELECT id, name FROM users WHERE status = 'active'",
856
+ * settings
857
+ * );
858
+ * ```
859
+ */
860
+ rovo(): RovoIntegration {
861
+ return new Rovo(this, this.options);
862
+ }
830
863
  }
831
864
 
832
865
  /**
@@ -1390,6 +1423,37 @@ class ForgeSQLORM implements ForgeSqlOperation {
1390
1423
  with(...queries: WithSubquery[]) {
1391
1424
  return this.ormInstance.getDrizzleQueryBuilder().with(...queries);
1392
1425
  }
1426
+
1427
+ /**
1428
+ * Provides access to Rovo integration - a secure pattern for natural-language analytics.
1429
+ *
1430
+ * Rovo enables secure execution of dynamic SQL queries with comprehensive security validations:
1431
+ * - Only SELECT queries are allowed
1432
+ * - Queries are restricted to a single table
1433
+ * - JOINs, subqueries, and window functions are blocked
1434
+ * - Row-Level Security (RLS) support for data isolation
1435
+ *
1436
+ * @returns {RovoIntegration} Rovo integration instance for secure dynamic queries
1437
+ *
1438
+ * @example
1439
+ * ```typescript
1440
+ * const rovo = forgeSQL.rovo();
1441
+ * const settings = await rovo.rovoSettingBuilder(usersTable, accountId)
1442
+ * .useRLS()
1443
+ * .addRlsColumn(usersTable.id)
1444
+ * .addRlsWherePart((alias) => `${alias}.id = '${accountId}'`)
1445
+ * .finish()
1446
+ * .build();
1447
+ *
1448
+ * const result = await rovo.dynamicIsolatedQuery(
1449
+ * "SELECT id, name FROM users WHERE status = 'active'",
1450
+ * settings
1451
+ * );
1452
+ * ```
1453
+ */
1454
+ rovo(): RovoIntegration {
1455
+ return this.ormInstance.rovo();
1456
+ }
1393
1457
  }
1394
1458
 
1395
1459
  export default ForgeSQLORM;
@@ -1,4 +1,4 @@
1
- import { UpdateQueryResponse } from "@forge/sql";
1
+ import { Result, UpdateQueryResponse } from "@forge/sql";
2
2
  import { SqlParameters } from "@forge/sql/out/sql-statement";
3
3
  import {
4
4
  AnyMySqlSelectQueryBuilder,
@@ -56,6 +56,7 @@ import { SQLWrapper } from "drizzle-orm/sql/sql";
56
56
  import type { MySqlQueryResultKind } from "drizzle-orm/mysql-core/session";
57
57
  import type { WithBuilder } from "drizzle-orm/mysql-core/subquery";
58
58
  import { WithSubquery } from "drizzle-orm/subquery";
59
+ import { MySqlColumn } from "drizzle-orm/mysql-core";
59
60
 
60
61
  /**
61
62
  * Core interface for ForgeSQL operations.
@@ -120,6 +121,35 @@ export interface ForgeSqlOperation extends QueryBuilderForgeSql {
120
121
  * @returns {ForgeSQLCacheOperations} Interface for executing versioned SQL operations with cache management
121
122
  */
122
123
  modifyWithVersioningAndEvictCache(): ForgeSQLCacheOperations;
124
+
125
+ /**
126
+ * Provides access to Rovo integration - a secure pattern for natural-language analytics.
127
+ *
128
+ * Rovo enables secure execution of dynamic SQL queries with comprehensive security validations:
129
+ * - Only SELECT queries are allowed
130
+ * - Queries are restricted to a single table
131
+ * - JOINs, subqueries, and window functions are blocked
132
+ * - Row-Level Security (RLS) support for data isolation
133
+ *
134
+ * @returns {RovoIntegration} Rovo integration instance for secure dynamic queries
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const rovo = forgeSQL.rovo();
139
+ * const settings = await rovo.rovoSettingBuilder(usersTable, accountId)
140
+ * .useRLS()
141
+ * .addRlsColumn(usersTable.id)
142
+ * .addRlsWherePart((alias) => `${alias}.id = '${accountId}'`)
143
+ * .finish()
144
+ * .build();
145
+ *
146
+ * const result = await rovo.dynamicIsolatedQuery(
147
+ * "SELECT id, name FROM users WHERE status = 'active'",
148
+ * settings
149
+ * );
150
+ * ```
151
+ */
152
+ rovo(): RovoIntegration;
123
153
  }
124
154
 
125
155
  /**
@@ -998,6 +1028,175 @@ export interface SchemaSqlForgeSql {
998
1028
  executeRawUpdateSQL(query: string, params?: unknown[]): Promise<UpdateQueryResponse>;
999
1029
  }
1000
1030
 
1031
+ /**
1032
+ * Interface for Rovo integration settings.
1033
+ * Defines configuration for secure dynamic SQL query execution.
1034
+ *
1035
+ * @interface RovoIntegrationSetting
1036
+ */
1037
+ export interface RovoIntegrationSetting {
1038
+ /**
1039
+ * Gets the account ID of the active user.
1040
+ *
1041
+ * @returns {string} The account ID of the active user
1042
+ */
1043
+ getActiveUser(): string;
1044
+
1045
+ /**
1046
+ * Gets the context parameters for query substitution.
1047
+ *
1048
+ * @returns {Record<string, string>} Map of parameter names to their values
1049
+ */
1050
+ getParameters(): Record<string, string>;
1051
+
1052
+ /**
1053
+ * Gets the name of the table to query.
1054
+ *
1055
+ * @returns {string} The table name
1056
+ */
1057
+ getTableName(): string;
1058
+
1059
+ /**
1060
+ * Checks if Row-Level Security is enabled.
1061
+ *
1062
+ * @returns {boolean} True if RLS is enabled, false otherwise
1063
+ */
1064
+ isUseRLS(): boolean;
1065
+
1066
+ /**
1067
+ * Generates the WHERE clause for Row-Level Security filtering.
1068
+ *
1069
+ * @param {string} alias - The table alias to use in the WHERE clause
1070
+ * @returns {string} SQL WHERE clause condition for RLS filtering
1071
+ */
1072
+ userScopeWhere(alias: string): string;
1073
+
1074
+ /**
1075
+ * Gets the list of field names required for RLS validation.
1076
+ *
1077
+ * @returns {string[]} Array of field names that must be present in SELECT clause for RLS
1078
+ */
1079
+ userScopeFields(): string[];
1080
+ }
1081
+
1082
+ /**
1083
+ * Interface for configuring Row-Level Security (RLS) settings.
1084
+ * Provides a fluent API for setting up RLS conditions, required columns, and WHERE clauses.
1085
+ *
1086
+ * @interface RlsSettings
1087
+ */
1088
+ export interface RlsSettings {
1089
+ /**
1090
+ * Sets a conditional function to determine if RLS should be applied.
1091
+ *
1092
+ * @param {() => Promise<boolean>} condition - Async function that returns true if RLS should be enabled
1093
+ * @returns {RlsSettings} This builder instance for method chaining
1094
+ */
1095
+ addRlsCondition(condition: () => Promise<boolean>): RlsSettings;
1096
+
1097
+ /**
1098
+ * Adds a column name that must be present in the SELECT clause for RLS validation.
1099
+ *
1100
+ * @param {string} columnName - The name of the column to require
1101
+ * @returns {RlsSettings} This builder instance for method chaining
1102
+ */
1103
+ addRlsColumnName(columnName: string): RlsSettings;
1104
+
1105
+ /**
1106
+ * Adds a Drizzle column that must be present in the SELECT clause for RLS validation.
1107
+ *
1108
+ * @param {MySqlColumn} column - The Drizzle column object
1109
+ * @returns {RlsSettings} This builder instance for method chaining
1110
+ */
1111
+ addRlsColumn(columnName: MySqlColumn): RlsSettings;
1112
+
1113
+ /**
1114
+ * Sets the WHERE clause function for RLS filtering.
1115
+ *
1116
+ * @param {(alias: string) => string} wherePart - Function that generates WHERE clause
1117
+ * @returns {RlsSettings} This builder instance for method chaining
1118
+ */
1119
+ addRlsWherePart(wherePart: (alias: string) => string): RlsSettings;
1120
+
1121
+ /**
1122
+ * Finishes RLS configuration and returns to the settings builder.
1123
+ *
1124
+ * @returns {RovoIntegrationSettingCreator} The parent settings builder
1125
+ */
1126
+ finish(): RovoIntegrationSettingCreator;
1127
+ }
1128
+
1129
+ /**
1130
+ * Interface for building Rovo integration settings.
1131
+ * Provides a fluent API for configuring query settings including context parameters and RLS.
1132
+ *
1133
+ * @interface RovoIntegrationSettingCreator
1134
+ */
1135
+ export interface RovoIntegrationSettingCreator {
1136
+ /**
1137
+ * Adds a context parameter for query substitution.
1138
+ *
1139
+ * @param {string} parameterName - The parameter name to replace in the query
1140
+ * @param {string} value - The value to substitute for the parameter
1141
+ * @returns {RovoIntegrationSettingCreator} This builder instance for method chaining
1142
+ */
1143
+ addContextParameter(parameterName: string, value: string): RovoIntegrationSettingCreator;
1144
+
1145
+ /**
1146
+ * Enables Row-Level Security (RLS) for the query.
1147
+ *
1148
+ * @returns {RlsSettings} RLS settings builder for configuring security options
1149
+ */
1150
+ useRLS(): RlsSettings;
1151
+
1152
+ /**
1153
+ * Builds and returns the RovoIntegrationSetting instance.
1154
+ *
1155
+ * @returns {Promise<RovoIntegrationSetting>} The configured RovoIntegrationSetting instance
1156
+ */
1157
+ build(): Promise<RovoIntegrationSetting>;
1158
+ }
1159
+
1160
+ /**
1161
+ * Interface for Rovo integration - a secure pattern for natural-language analytics.
1162
+ *
1163
+ * Rovo provides secure execution of dynamic SQL queries with comprehensive security validations.
1164
+ *
1165
+ * @interface RovoIntegration
1166
+ */
1167
+ export interface RovoIntegration {
1168
+ /**
1169
+ * Creates a settings builder for Rovo queries using a raw table name.
1170
+ *
1171
+ * @param {string} tableName - The name of the table to query
1172
+ * @param {string} accountId - The account ID of the active user
1173
+ * @returns {RovoIntegrationSettingCreator} Builder for configuring Rovo query settings
1174
+ */
1175
+ rovoRawSettingBuilder(tableName: string, accountId: string): RovoIntegrationSettingCreator;
1176
+
1177
+ /**
1178
+ * Creates a settings builder for Rovo queries using a Drizzle table object.
1179
+ *
1180
+ * @param {AnyMySqlTable} table - The Drizzle table object
1181
+ * @param {string} accountId - The account ID of the active user
1182
+ * @returns {RovoIntegrationSettingCreator} Builder for configuring Rovo query settings
1183
+ */
1184
+ rovoSettingBuilder(table: AnyMySqlTable, accountId: string): RovoIntegrationSettingCreator;
1185
+
1186
+ /**
1187
+ * Executes a dynamic SQL query with comprehensive security validations.
1188
+ *
1189
+ * @param {string} dynamicSql - The SQL query to execute (must be a SELECT statement)
1190
+ * @param {RovoIntegrationSetting} settings - Configuration settings for the query
1191
+ * @returns {Promise<Result<unknown>>} Query execution result with metadata
1192
+ * @throws {Error} If the query violates security restrictions
1193
+ */
1194
+ dynamicIsolatedQuery(
1195
+ dynamicSql: string,
1196
+ settings: RovoIntegrationSetting,
1197
+ ): Promise<Result<unknown>>;
1198
+ }
1199
+
1001
1200
  /**
1002
1201
  * Interface for version field metadata.
1003
1202
  * Defines the configuration for optimistic locking version fields.