@deepagents/text2sql 7.13.1 → 7.14.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.
Files changed (30) hide show
  1. package/README.md +106 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/lib/adapters/bigquery/index.js +24 -5
  4. package/dist/lib/adapters/bigquery/index.js.map +2 -2
  5. package/dist/lib/adapters/clickhouse/index.js.map +1 -1
  6. package/dist/lib/adapters/duckdb/index.js.map +1 -1
  7. package/dist/lib/adapters/mysql/index.js +24 -5
  8. package/dist/lib/adapters/mysql/index.js.map +2 -2
  9. package/dist/lib/adapters/policy/in-scope.d.ts.map +1 -1
  10. package/dist/lib/adapters/policy/index.js +24 -5
  11. package/dist/lib/adapters/policy/index.js.map +2 -2
  12. package/dist/lib/adapters/policy/source-policy.d.ts +6 -0
  13. package/dist/lib/adapters/policy/source-policy.d.ts.map +1 -1
  14. package/dist/lib/adapters/postgres/index.js +24 -5
  15. package/dist/lib/adapters/postgres/index.js.map +2 -2
  16. package/dist/lib/adapters/posthog/index.js.map +1 -1
  17. package/dist/lib/adapters/spreadsheet/index.js +24 -5
  18. package/dist/lib/adapters/spreadsheet/index.js.map +2 -2
  19. package/dist/lib/adapters/sqlite/index.js +24 -5
  20. package/dist/lib/adapters/sqlite/index.js.map +2 -2
  21. package/dist/lib/adapters/sqlserver/index.d.ts +1 -0
  22. package/dist/lib/adapters/sqlserver/index.d.ts.map +1 -1
  23. package/dist/lib/adapters/sqlserver/index.js +130 -5
  24. package/dist/lib/adapters/sqlserver/index.js.map +4 -4
  25. package/dist/lib/adapters/sqlserver/sqlserver-plan.d.ts +66 -0
  26. package/dist/lib/adapters/sqlserver/sqlserver-plan.d.ts.map +1 -0
  27. package/dist/lib/sql-scope-error.d.ts +12 -1
  28. package/dist/lib/sql-scope-error.d.ts.map +1 -1
  29. package/dist/lib/synthesis/index.js.map +1 -1
  30. package/package.json +4 -4
@@ -0,0 +1,66 @@
1
+ import type { Statements } from '../policy/facts.ts';
2
+ import { type FactSource, type PolicyCheck, type Rule, SourcePolicy } from '../policy/source-policy.ts';
3
+ import type { SqlPolicyViolation } from '../sql-policy.ts';
4
+ /** A connection of its own to the database, closed when it is disposed. */
5
+ export interface SqlServerSession extends AsyncDisposable {
6
+ /**
7
+ * Runs one batch and gives the rows of every result set it returns. It
8
+ * rejects with the driver's error, whose `number` is SQL Server's error
9
+ * number.
10
+ */
11
+ batch(sql: string): Promise<readonly Record<string, unknown>[]>;
12
+ }
13
+ /**
14
+ * The database user that compiles the SQL. The host's execute runs the SQL as
15
+ * this user too, so the check and the run resolve a name such as `users` in
16
+ * the same default schema.
17
+ */
18
+ export interface SqlServerPrincipal {
19
+ readonly name: string;
20
+ session(): Promise<SqlServerSession>;
21
+ }
22
+ /** The refusals of the database for the principal, in SQL Server's words. */
23
+ export interface Grants {
24
+ denials(): Promise<readonly string[]>;
25
+ }
26
+ /** The physical operators of the plans, such as `Clustered Index Scan`. */
27
+ export interface PlanOperators {
28
+ operators(): Promise<ReadonlySet<string>>;
29
+ }
30
+ export type PlanFacts = Statements & Grants & PlanOperators;
31
+ /**
32
+ * Reads SQL by SQL Server's own compile: the principal compiles the SQL under
33
+ * `SET SHOWPLAN_XML ON`, which plans each statement and runs none. A plan
34
+ * names the base tables after views, synonyms and functions are expanded, so
35
+ * it gives no `Relations`, and a lock hint leaves the plan the same, so it
36
+ * gives no `Constructs`.
37
+ *
38
+ * A compile that SQL Server refuses with a permission error on an object
39
+ * (229) gives that error as a denial, and it has no statements and no
40
+ * operators: those facts throw, so a policy without `GrantedScope` rejects
41
+ * the check. A compile that fails with any other error is unreadable, such as
42
+ * 102 for `LIMIT`, 208 for an unknown table and 262 for a principal without
43
+ * SHOWPLAN. SQL Server checks SHOWPLAN only for a plan that reads an object
44
+ * of the database, so no compile of the policy's own can test it first.
45
+ */
46
+ export declare class SqlServerPlan implements FactSource<PlanFacts> {
47
+ #private;
48
+ readonly dialect = "transactsql";
49
+ constructor(principal: SqlServerPrincipal);
50
+ read(sql: string): PlanFacts;
51
+ }
52
+ /** The principal may compile the SQL: SQL Server refused no permission. */
53
+ export declare class GrantedScope implements Rule<Grants> {
54
+ readonly check: (facts: Grants, check: PolicyCheck) => Promise<SqlPolicyViolation | null>;
55
+ }
56
+ /** The plans use no linked server: no operator is a `Remote` one. */
57
+ export declare class NoRemoteOperators implements Rule<PlanOperators> {
58
+ readonly check: (facts: PlanOperators) => Promise<SqlPolicyViolation | null>;
59
+ }
60
+ /**
61
+ * The policy that SQL Server's own compile decides: the principal's grants
62
+ * decide the scope, the plan decides that the SQL is one SELECT, and no plan
63
+ * reads a linked server.
64
+ */
65
+ export declare function planPolicy(principal: SqlServerPrincipal): SourcePolicy<PlanFacts>;
66
+ //# sourceMappingURL=sqlserver-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlserver-plan.d.ts","sources":["../../../../src/lib/adapters/sqlserver/sqlserver-plan.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhE,OAAO,EACL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,YAAY,EAEb,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,2EAA2E;AAC3E,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;CACjE;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACtC;AAED,6EAA6E;AAC7E,MAAM,WAAW,MAAM;IACrB,OAAO,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;CACvC;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,SAAS,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,aAAa,CAAC;AAsB5D;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAc,YAAW,UAAU,CAAC,SAAS,CAAC;;IACzD,QAAQ,CAAC,OAAO,iBAAiB;IAGjC,YAAY,SAAS,EAAE,kBAAkB,EAExC;IAED,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAsB3B;CA+BF;AAkBD,2EAA2E;AAC3E,qBAAa,YAAa,YAAW,IAAI,CAAC,MAAM,CAAC;IAC/C,QAAQ,CAAC,KAAK,UACL,MAAM,SACN,WAAW,KACjB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAUnC;CACH;AAED,qEAAqE;AACrE,qBAAa,iBAAkB,YAAW,IAAI,CAAC,aAAa,CAAC;IAC3D,QAAQ,CAAC,KAAK,UAAiB,aAAa,wCAK1C;CACH;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,kBAAkB,2BAMvD"}
@@ -1,4 +1,15 @@
1
1
  import type { SQLScopeErrorPayload } from './agents/exceptions.ts';
2
2
  export declare function buildScopeParseErrorPayload(sql: string, parserDialect: string, error: unknown): SQLScopeErrorPayload;
3
- export declare function buildOutOfScopePayload(sql: string, referencedEntities: string[], allowedEntities: string[]): SQLScopeErrorPayload;
3
+ /**
4
+ * Why SQL is out of scope: it reads entities outside the grounded scope, or
5
+ * the database refused it for the principal that compiled it, in the
6
+ * database's own words.
7
+ */
8
+ export type OutOfScope = {
9
+ readonly referenced: string[];
10
+ readonly allowed: string[];
11
+ } | {
12
+ readonly denial: string;
13
+ };
14
+ export declare function buildOutOfScopePayload(sql: string, scope: OutOfScope): SQLScopeErrorPayload;
4
15
  //# sourceMappingURL=sql-scope-error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sql-scope-error.d.ts","sources":["../../src/lib/sql-scope-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,OAAO,GACb,oBAAoB,CActB;AAED,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,kBAAkB,EAAE,MAAM,EAAE,EAC5B,eAAe,EAAE,MAAM,EAAE,GACxB,oBAAoB,CAUtB"}
1
+ {"version":3,"file":"sql-scope-error.d.ts","sources":["../../src/lib/sql-scope-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,OAAO,GACb,oBAAoB,CActB;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAC7D;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhC,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,GAChB,oBAAoB,CAmBtB"}