@cubicweb/client
Advanced tools
Comparing version 3.0.0-alpha.14 to 3.0.0-alpha.15
import { ValidationError } from "../errors.js"; | ||
import { getBinariesFromTransaction, serializeQueryParams } from "../utils.js"; | ||
import { ResultSet } from "./ResultSet.js"; | ||
import { TransactionResult } from "./transaction/TransactionResult.js"; | ||
import { TransactionResult, } from "./transaction/TransactionResult.js"; | ||
/** | ||
@@ -161,3 +160,3 @@ * Class used to handle requests to the CubicWeb API. | ||
}); | ||
return new TransactionResult(transaction, resultSets.map((r) => new ResultSet(r))); | ||
return new TransactionResult(transaction, resultSets); | ||
} | ||
@@ -170,3 +169,3 @@ async jsonTransaction(transaction) { | ||
}); | ||
return new TransactionResult(transaction, resultSets.map((r) => new ResultSet(r))); | ||
return new TransactionResult(transaction, resultSets); | ||
} | ||
@@ -173,0 +172,0 @@ handleUserErrors(error) { |
@@ -21,3 +21,3 @@ /** | ||
*/ | ||
column(c: number): RQLQueryCellRef; | ||
column(c: number | string): RQLQueryCellRef; | ||
} | ||
@@ -39,5 +39,5 @@ /** | ||
readonly row: number; | ||
readonly column: number; | ||
constructor(queryUUID: string, row: number, column: number); | ||
readonly column: number | string; | ||
constructor(queryUUID: string, row: number, column: number | string); | ||
} | ||
//# sourceMappingURL=references.d.ts.map |
@@ -38,4 +38,4 @@ import { RQLQueryCellRef, RQLQueryRowRef } from "./references.js"; | ||
*/ | ||
cellRef(row: number, column: number): RQLQueryCellRef; | ||
cellRef(row: number, column: number | string): RQLQueryCellRef; | ||
} | ||
//# sourceMappingURL=RQLQuery.d.ts.map |
/** | ||
* Interface representing the json returned by the API for a single result set | ||
* | ||
* @category Api | ||
*/ | ||
export interface RawResultSet { | ||
readonly rows: ResultSetCell[][]; | ||
readonly column_names: string[]; | ||
} | ||
/** | ||
* Interface representing the json returned by the API for a single row in a result set | ||
* | ||
* @category Api | ||
*/ | ||
export type RawResultSetRow = ResultSetCell[]; | ||
/** | ||
* Type representing a final value in a result set. | ||
@@ -11,7 +26,14 @@ * | ||
/** | ||
* Type representing a row returned in a result set. | ||
* Class representing a row returned in a result set. | ||
* | ||
* @category Api | ||
*/ | ||
export type ResultSetRow<T extends ReadonlyArray<ResultSetCell> = ReadonlyArray<ResultSetCell>> = T; | ||
export declare class ResultSetRow implements Iterable<ResultSetCell> { | ||
readonly columnNames: string[]; | ||
private readonly cells; | ||
constructor(columnNames: string[], cells: RawResultSetRow); | ||
[Symbol.iterator](): Generator<ResultSetCell, void, unknown>; | ||
get length(): number; | ||
getCell(column: number | string): ResultSetCell; | ||
} | ||
/** | ||
@@ -22,6 +44,11 @@ * Class representing a RQL request result. | ||
*/ | ||
export declare class ResultSet<T extends ReadonlyArray<ResultSetCell> = ReadonlyArray<ResultSetCell>> { | ||
readonly rows: ReadonlyArray<T>; | ||
constructor(rows: ReadonlyArray<T>); | ||
export declare class ResultSet { | ||
#private; | ||
readonly columnNames: string[]; | ||
constructor(rawResultSet: RawResultSet); | ||
[Symbol.iterator](): Generator<ResultSetRow, void, unknown>; | ||
get length(): number; | ||
getRow(row: number): ResultSetRow; | ||
getCell(row: number, column: number | string): ResultSetCell; | ||
} | ||
//# sourceMappingURL=ResultSet.d.ts.map |
/** | ||
* Class representing a row returned in a result set. | ||
* | ||
* @category Api | ||
*/ | ||
export class ResultSetRow { | ||
columnNames; | ||
cells; | ||
constructor(columnNames, cells) { | ||
this.columnNames = columnNames; | ||
this.cells = cells; | ||
} | ||
*[Symbol.iterator]() { | ||
for (const cell of this.cells) { | ||
yield cell; | ||
} | ||
} | ||
get length() { | ||
return this.cells.length; | ||
} | ||
getCell(column) { | ||
if (typeof column === "number") { | ||
return this.cells[column]; | ||
} | ||
else { | ||
const columnIndex = this.columnNames.indexOf(column); | ||
return this.cells[columnIndex]; | ||
} | ||
} | ||
} | ||
/** | ||
* Class representing a RQL request result. | ||
@@ -7,7 +37,29 @@ * | ||
export class ResultSet { | ||
rows; | ||
constructor(rows) { | ||
this.rows = rows; | ||
columnNames; | ||
#rows; | ||
constructor(rawResultSet) { | ||
this.columnNames = rawResultSet.column_names; | ||
this.#rows = rawResultSet.rows; | ||
} | ||
*[Symbol.iterator]() { | ||
for (const r of this.#rows) { | ||
yield new ResultSetRow(this.columnNames, r); | ||
} | ||
} | ||
get length() { | ||
return this.#rows.length; | ||
} | ||
getRow(row) { | ||
return new ResultSetRow(this.columnNames, this.#rows[row]); | ||
} | ||
getCell(row, column) { | ||
if (typeof column === "number") { | ||
return this.#rows[row][column]; | ||
} | ||
else { | ||
const columnIndex = this.columnNames.indexOf(column); | ||
return this.#rows[row][columnIndex]; | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=ResultSet.js.map |
@@ -1,2 +0,2 @@ | ||
import { ResultSet, ResultSetCell, ResultSetRow } from "../ResultSet.js"; | ||
import { RawResultSet, ResultSet, ResultSetCell, ResultSetRow } from "../ResultSet.js"; | ||
import { RQLQuery } from "../query/RQLQuery.js"; | ||
@@ -6,2 +6,11 @@ import { RQLQueryCellRef, RQLQueryRowRef } from "../query/references.js"; | ||
/** | ||
* Interface representing the json returned by the API when executing | ||
* a Transaction | ||
* | ||
* @category Api | ||
*/ | ||
export interface RawTransactionResult { | ||
readonly result_sets: RawResultSet[]; | ||
} | ||
/** | ||
* Class representing the result of a transaction. | ||
@@ -27,4 +36,4 @@ * | ||
private transaction; | ||
private resultSets; | ||
constructor(transaction: Transaction, resultSets: ReadonlyArray<ResultSet>); | ||
private rawResultSets; | ||
constructor(transaction: Transaction, rawTransactionResult: RawTransactionResult); | ||
getResultSet(query: RQLQuery): ResultSet; | ||
@@ -31,0 +40,0 @@ getRow(ref: RQLQueryRowRef): ResultSetRow; |
import { getQueryIndexInTransaction } from "../../utils.js"; | ||
import { ResultSet, } from "../ResultSet.js"; | ||
/** | ||
@@ -23,20 +24,23 @@ * Class representing the result of a transaction. | ||
transaction; | ||
resultSets; | ||
constructor(transaction, resultSets) { | ||
rawResultSets; | ||
constructor(transaction, rawTransactionResult) { | ||
this.transaction = transaction; | ||
this.resultSets = resultSets; | ||
this.rawResultSets = rawTransactionResult.result_sets; | ||
} | ||
getResultSet(query) { | ||
const index = getQueryIndexInTransaction(this.transaction, query.queryUUID); | ||
return this.resultSets[index]; | ||
const resultSet = new ResultSet(this.rawResultSets[index]); | ||
return resultSet; | ||
} | ||
getRow(ref) { | ||
const index = getQueryIndexInTransaction(this.transaction, ref.queryUUID); | ||
return this.resultSets[index].rows[ref.row]; | ||
const resultSet = new ResultSet(this.rawResultSets[index]); | ||
return resultSet.getRow(ref.row); | ||
} | ||
getCell(ref) { | ||
const index = getQueryIndexInTransaction(this.transaction, ref.queryUUID); | ||
return this.resultSets[index].rows[ref.row][ref.column]; | ||
const resultSet = new ResultSet(this.rawResultSets[index]); | ||
return resultSet.getCell(ref.row, ref.column); | ||
} | ||
} | ||
//# sourceMappingURL=TransactionResult.js.map |
@@ -13,3 +13,3 @@ // Raw Schema | ||
export * from "./errors.js"; | ||
export { ResultSet } from "./api/ResultSet.js"; | ||
export { ResultSet, ResultSetRow } from "./api/ResultSet.js"; | ||
export { default as Client } from "./api/Client.js"; | ||
@@ -16,0 +16,0 @@ export { Transaction } from "./api/transaction/Transaction.js"; |
@@ -5,3 +5,3 @@ { | ||
"author": "Logilab", | ||
"version": "3.0.0-alpha.14", | ||
"version": "3.0.0-alpha.15", | ||
"license": "LGPL-3.0-or-later", | ||
@@ -8,0 +8,0 @@ "scripts": { |
@@ -10,3 +10,3 @@ # @cubicweb/client | ||
**Compatible with [API cube](https://forge.extranet.logilab.fr/cubicweb/cubes/api) version 0.14 only.** | ||
**Compatible with [API cube](https://forge.extranet.logilab.fr/cubicweb/cubes/api) version 0.15 only.** | ||
@@ -13,0 +13,0 @@ ## Installation |
import { ValidationError } from "../errors.js"; | ||
import { RawSchema } from "../schema/raw/Schema.js"; | ||
import { getBinariesFromTransaction, serializeQueryParams } from "../utils.js"; | ||
import { ResultSet, ResultSetCell } from "./ResultSet.js"; | ||
import { RQLBinary } from "./binary/RQLBinary.js"; | ||
import { RQLQueryCellRef } from "./query/references.js"; | ||
import { Transaction } from "./transaction/Transaction.js"; | ||
import { TransactionResult } from "./transaction/TransactionResult.js"; | ||
import { | ||
RawTransactionResult, | ||
TransactionResult, | ||
} from "./transaction/TransactionResult.js"; | ||
@@ -65,6 +67,2 @@ /** | ||
type RawTransactionResult = ReadonlyArray< | ||
ReadonlyArray<ReadonlyArray<ResultSetCell>> | ||
>; | ||
/** | ||
@@ -241,6 +239,3 @@ * Class used to handle requests to the CubicWeb API. | ||
); | ||
return new TransactionResult( | ||
transaction, | ||
resultSets.map((r) => new ResultSet(r)) | ||
); | ||
return new TransactionResult(transaction, resultSets); | ||
} | ||
@@ -257,6 +252,3 @@ | ||
); | ||
return new TransactionResult( | ||
transaction, | ||
resultSets.map((r) => new ResultSet(r)) | ||
); | ||
return new TransactionResult(transaction, resultSets); | ||
} | ||
@@ -263,0 +255,0 @@ |
@@ -20,3 +20,3 @@ /** | ||
*/ | ||
column(c: number): RQLQueryCellRef { | ||
column(c: number | string): RQLQueryCellRef { | ||
return new RQLQueryCellRef(this.queryUUID, this.row, c); | ||
@@ -42,4 +42,4 @@ } | ||
public readonly row: number, | ||
public readonly column: number | ||
public readonly column: number | string | ||
) {} | ||
} |
@@ -48,5 +48,5 @@ import { v4 as uuidv4 } from "uuid"; | ||
*/ | ||
cellRef(row: number, column: number): RQLQueryCellRef { | ||
cellRef(row: number, column: number | string): RQLQueryCellRef { | ||
return new RQLQueryCellRef(this.queryUUID, row, column); | ||
} | ||
} |
/** | ||
* Interface representing the json returned by the API for a single result set | ||
* | ||
* @category Api | ||
*/ | ||
export interface RawResultSet { | ||
readonly rows: ResultSetCell[][]; | ||
readonly column_names: string[]; | ||
} | ||
/** | ||
* Interface representing the json returned by the API for a single row in a result set | ||
* | ||
* @category Api | ||
*/ | ||
export type RawResultSetRow = ResultSetCell[]; | ||
/** | ||
* Type representing a final value in a result set. | ||
@@ -12,10 +29,32 @@ * | ||
/** | ||
* Type representing a row returned in a result set. | ||
* Class representing a row returned in a result set. | ||
* | ||
* @category Api | ||
*/ | ||
export type ResultSetRow< | ||
T extends ReadonlyArray<ResultSetCell> = ReadonlyArray<ResultSetCell> | ||
> = T; | ||
export class ResultSetRow implements Iterable<ResultSetCell> { | ||
constructor( | ||
public readonly columnNames: string[], | ||
private readonly cells: RawResultSetRow | ||
) {} | ||
*[Symbol.iterator]() { | ||
for (const cell of this.cells) { | ||
yield cell; | ||
} | ||
} | ||
get length() { | ||
return this.cells.length; | ||
} | ||
getCell(column: number | string) { | ||
if (typeof column === "number") { | ||
return this.cells[column]; | ||
} else { | ||
const columnIndex = this.columnNames.indexOf(column); | ||
return this.cells[columnIndex]; | ||
} | ||
} | ||
} | ||
/** | ||
@@ -26,6 +65,33 @@ * Class representing a RQL request result. | ||
*/ | ||
export class ResultSet< | ||
T extends ReadonlyArray<ResultSetCell> = ReadonlyArray<ResultSetCell> | ||
> { | ||
constructor(public readonly rows: ReadonlyArray<T>) {} | ||
export class ResultSet { | ||
public readonly columnNames: string[]; | ||
readonly #rows: RawResultSetRow[]; | ||
constructor(rawResultSet: RawResultSet) { | ||
this.columnNames = rawResultSet.column_names; | ||
this.#rows = rawResultSet.rows; | ||
} | ||
*[Symbol.iterator]() { | ||
for (const r of this.#rows) { | ||
yield new ResultSetRow(this.columnNames, r); | ||
} | ||
} | ||
get length() { | ||
return this.#rows.length; | ||
} | ||
getRow(row: number): ResultSetRow { | ||
return new ResultSetRow(this.columnNames, this.#rows[row]); | ||
} | ||
getCell(row: number, column: number | string): ResultSetCell { | ||
if (typeof column === "number") { | ||
return this.#rows[row][column]; | ||
} else { | ||
const columnIndex = this.columnNames.indexOf(column); | ||
return this.#rows[row][columnIndex]; | ||
} | ||
} | ||
} |
import { getQueryIndexInTransaction } from "../../utils.js"; | ||
import { ResultSet, ResultSetCell, ResultSetRow } from "../ResultSet.js"; | ||
import { | ||
RawResultSet, | ||
ResultSet, | ||
ResultSetCell, | ||
ResultSetRow, | ||
} from "../ResultSet.js"; | ||
import { RQLQuery } from "../query/RQLQuery.js"; | ||
@@ -8,2 +13,12 @@ import { RQLQueryCellRef, RQLQueryRowRef } from "../query/references.js"; | ||
/** | ||
* Interface representing the json returned by the API when executing | ||
* a Transaction | ||
* | ||
* @category Api | ||
*/ | ||
export interface RawTransactionResult { | ||
readonly result_sets: RawResultSet[]; | ||
} | ||
/** | ||
* Class representing the result of a transaction. | ||
@@ -28,10 +43,15 @@ * | ||
export class TransactionResult { | ||
private rawResultSets: RawResultSet[]; | ||
constructor( | ||
private transaction: Transaction, | ||
private resultSets: ReadonlyArray<ResultSet> | ||
) {} | ||
rawTransactionResult: RawTransactionResult | ||
) { | ||
this.rawResultSets = rawTransactionResult.result_sets; | ||
} | ||
getResultSet(query: RQLQuery): ResultSet { | ||
const index = getQueryIndexInTransaction(this.transaction, query.queryUUID); | ||
return this.resultSets[index]; | ||
const resultSet = new ResultSet(this.rawResultSets[index]); | ||
return resultSet; | ||
} | ||
@@ -41,3 +61,4 @@ | ||
const index = getQueryIndexInTransaction(this.transaction, ref.queryUUID); | ||
return this.resultSets[index].rows[ref.row]; | ||
const resultSet = new ResultSet(this.rawResultSets[index]); | ||
return resultSet.getRow(ref.row); | ||
} | ||
@@ -47,4 +68,5 @@ | ||
const index = getQueryIndexInTransaction(this.transaction, ref.queryUUID); | ||
return this.resultSets[index].rows[ref.row][ref.column]; | ||
const resultSet = new ResultSet(this.rawResultSets[index]); | ||
return resultSet.getCell(ref.row, ref.column); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
188265
4111