@cap.core/ql 1.2.4 → 1.2.6

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/@types/exprs.d.ts CHANGED
@@ -1,8 +1,13 @@
1
1
  import * as cqn from './cqn'
2
+
3
+ export function subject (...args: any[]): cqn.ref;
2
4
  export function columns () : cqn.column[]
3
- export function orderBy () : cqn.order[]
4
- export function entity () : cqn.ref
5
+ export function values(...args: any[]): (string|number|boolean|null)[];
5
6
  export function where () : cqn.xo[]
7
+ export function having () : cqn.xo[]
8
+ export function groupBy () : cqn.column[]
9
+ export function orderBy () : cqn.order[]
10
+
6
11
 
7
12
  /**
8
13
  * This is the template string variant of `expr`. The argument is a template string,
package/@types/index.d.ts CHANGED
@@ -1 +1,29 @@
1
+ import { Query } from './ql/base-class.js';
2
+ import { SELECT as SELECT_ } from './ql/select.js';
3
+ import { INSERT as INSERT_ } from './ql/insert.js';
4
+ import { UPSERT as UPSERT_ } from './ql/insert.js';
5
+ import { UPDATE as UPDATE_ } from './ql/update.js';
6
+ import { DELETE as DELETE_ } from './ql/delete.js';
7
+
8
+ /**
9
+ * This is the central entry point for creating queries from various types of input:
10
+ * - If the input is a `Query` instance already, it's returned as-is.
11
+ * - If the input is a `string` or a template literal, it's parsed into a CQN object.
12
+ * - If the input is an `object` with a recognized query kind, it's cast into an instance of
13
+ * the corresponding query class.
14
+ * @param { Query | string | object } qso - The input, as described above, to be converted into an instance of a Query subclass.
15
+ * @param { ...any } args - Optional arguments for template literals or parameterized queries.
16
+ * @returns { SELECT & INSERT & UPSERT & UPDATE & DELETE }
17
+ */
18
+ export function cql (
19
+ qso: Query | string | object, ...args: any[]
20
+ ): SELECT_ & INSERT_ & UPSERT_ & UPDATE_ & DELETE_;
21
+
1
22
  export * from './exprs'
23
+ export { Query };
24
+ export const SELECT: (() => typeof SELECT_) & typeof SELECT_;
25
+ export const INSERT: (() => typeof INSERT_) & typeof INSERT_;
26
+ export const UPSERT: (() => typeof UPSERT_) & typeof UPSERT_;
27
+ export const UPDATE: (() => typeof UPDATE_) & typeof UPDATE_;
28
+ export const DELETE: (() => typeof DELETE_) & typeof DELETE_;
29
+ export default cql;
@@ -0,0 +1,18 @@
1
+ import * as cqn from '../cqn'
2
+
3
+ export class Query {
4
+ /**
5
+ * - Fills in any binding `{param}`s with corresponding `{val}`s from given `args`.
6
+ * - If no `args` are provided, the ones collected during parsing are used.
7
+ */
8
+ bind(...args: any[]): this;
9
+
10
+ /**
11
+ * Returns the main subject `{ref}` of the query, which refers to the entity being queried or modified.
12
+ * - For `SELECT` and `DELETE` queries, this is the `from` clause.
13
+ * - For `INSERT` and `UPSERT` queries, this is the `into` clause.
14
+ * - For `UPDATE` queries, this is the `entity` clause.
15
+ * @returns {ref:string[]} The main subject of the query.
16
+ */
17
+ get subject(): cqn.ref;
18
+ }
@@ -0,0 +1,8 @@
1
+ import { Query } from './base-class.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class DELETE extends Query {
5
+ static from(...args: any[]): DELETE;
6
+ DELETE: cqn.DELETE;
7
+ where(...args: any[]): this;
8
+ }
@@ -0,0 +1,20 @@
1
+ import { Query } from './base-class.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class XSERT extends Query {
5
+ static entries(...args: any[]): XSERT;
6
+ static into(x: any, ...tail: any[]): XSERT;
7
+ _entries(...tail: any[]): this;
8
+ into(...args: any[]): this;
9
+ entries(...args: any[]): this;
10
+ columns(...args: any[]): this;
11
+ values(...args: any[]): this;
12
+ rows(...args: any[]): this;
13
+ from(...args: any[]): this;
14
+ }
15
+ export class INSERT extends XSERT {
16
+ INSERT: cqn.INSERT;
17
+ }
18
+ export class UPSERT extends XSERT {
19
+ UPSERT: cqn.UPSERT;
20
+ }
@@ -0,0 +1,24 @@
1
+ import { Query } from './base-class.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class SELECT extends Query {
5
+ static from(...args: any[]): SELECT;
6
+ static columns(...args: any[]): SELECT;
7
+ static get localized(): SELECT;
8
+ static get distinct(): SELECT;
9
+ static get one(): SELECT;
10
+ SELECT: cqn.SELECT;
11
+ get localized(): this;
12
+ get distinct(): this;
13
+ get one(): this;
14
+ columns(...args: any[]): this;
15
+ from(...args: any[]): this;
16
+ where(...args: any[]): this;
17
+ having(...args: any[]): this;
18
+ groupBy(...args: any[]): this;
19
+ orderBy(...args: any[]): this;
20
+ limit(...args: any[]): this;
21
+ top(...args: any[]): this;
22
+ skip(...args: any[]): this;
23
+ offset(...args: any[]): this;
24
+ }
@@ -0,0 +1,10 @@
1
+ import { Query } from './base-class.js';
2
+ import * as cqn from '../cqn'
3
+
4
+ export class UPDATE extends Query {
5
+ static entity(...args: any[]): UPDATE;
6
+ UPDATE: cqn.UPDATE;
7
+ where(...args: any[]): this;
8
+ with(data: any, x: any): this;
9
+ set(data: any, x: any): this;
10
+ }
package/lib/index.js CHANGED
@@ -1,21 +1,21 @@
1
+ // Re-export all the helper functions and classes from the xl module
2
+ export * from './xl/ttl.js'
3
+ import * as peg from '../cql/parser.min.js'
4
+ import { Query } from './ql/base-class.js'
5
+ export { Query }
6
+
7
+ // Export the fluent interface variants of the query classes
1
8
  import { SELECT as SELECT_ } from './ql/select.js'
2
9
  import { INSERT as INSERT_ } from './ql/insert.js'
3
10
  import { UPSERT as UPSERT_ } from './ql/insert.js'
4
11
  import { UPDATE as UPDATE_ } from './ql/update.js'
5
12
  import { DELETE as DELETE_ } from './ql/delete.js'
6
13
 
7
- // Re-export the query classes with fluent interfaces
8
- export const SELECT = SELECT_.chimera (SELECT_.columns)
9
- export const INSERT = INSERT_.chimera (INSERT_.entries)
10
- export const UPSERT = UPSERT_.chimera (UPSERT_.entries)
11
- export const UPDATE = UPDATE_.chimera (UPDATE_.entity)
12
- export const DELETE = DELETE_.chimera (DELETE_.from)
13
-
14
- // Re-export all the helper functions and classes from the xl module
15
- export * from './xl/ttl.js'
16
- import * as peg from '../cql/parser.min.js'
17
- import { Query } from './ql/base-class.js'
18
- export { Query }
14
+ export const SELECT = global.SELECT = SELECT_.chimera (SELECT_.columns)
15
+ export const INSERT = global.INSERT = INSERT_.chimera (INSERT_.entries)
16
+ export const UPSERT = global.UPSERT = UPSERT_.chimera (UPSERT_.entries)
17
+ export const UPDATE = global.UPDATE = UPDATE_.chimera (UPDATE_.entity)
18
+ export const DELETE = global.DELETE = DELETE_.chimera (DELETE_.from)
19
19
 
20
20
 
21
21
  /**
@@ -84,9 +84,6 @@ export class Query {
84
84
 
85
85
  /**
86
86
  * Returns the main subject `{ref}` of the query, which refers to the entity being queried or modified.
87
- * - For `SELECT` and `DELETE` queries, this is the `from` clause.
88
- * - For `INSERT` and `UPSERT` queries, this is the `into` clause.
89
- * - For `UPDATE` queries, this is the `entity` clause.
90
87
  * @returns {ref:string[]} The main subject of the query.
91
88
  */
92
89
  get subject() { return this._.from }
@@ -95,4 +92,9 @@ export class Query {
95
92
  /** @private */ set source (cql) { Object.defineProperty (this, 'source', { value: cql, writable: true }) }
96
93
  /** @private */ set params (arr) { Object.defineProperty (this, 'params', { value: arr, writable: true }) }
97
94
  /** @private */ set args (arr) { Object.defineProperty (this, 'args', { value: arr, writable: true }) }
95
+
96
+ // Custom inspect method to improve the output, e.g. in repl, console.log,
97
+ [Symbol.for('nodejs.util.inspect.custom')] = function (depth, options, inspect) {
98
+ return `${this.kind} ${inspect(this[this.kind], options)}`
99
+ }
98
100
  }
package/lib/ql/insert.js CHANGED
@@ -2,7 +2,7 @@ import { subject, columns, values, fluent, unwrapped } from '../xl/ttl.js'
2
2
  import { Query } from './base-class.js'
3
3
  import { cql } from '../index.js'
4
4
 
5
- export class XSERT extends Query { INSERT = {}
5
+ export class XSERT extends Query {
6
6
  static entries (...args) { return (new this).entries(...args) }
7
7
  static into (x,...tail) {
8
8
  if (x.raw) return (new this)._set ('into', subject(x,...tail)) //> INSERT.into`Foo`
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@cap.core/ql",
3
- "version": "1.2.4",
4
- "description": "Minimalistic implementation of `cds.ql`, carved out from CAP.",
3
+ "version": "1.2.6",
4
+ "description": "Minimalistic implementation of cds.ql, carved out from CAP.",
5
+ "repository": "https://github.com/cap-js/ql.git",
5
6
  "author": "daniel.hutzel@sap.com",
6
7
  "type": "module",
7
8
  "main": "lib/index.js",