New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cubicweb/client

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cubicweb/client - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

32

lib/api/Api.d.ts
import { RawSchema } from "../schema/raw/Schema";
import { TransactionResult, Transaction } from "./Transaction";
/**

@@ -6,2 +7,3 @@ * Type representing an RQL request and its associated parameters.

export type RQLQuery = [string, RQLParams];
export type RQLParamValue = string | number | boolean | null;
/**

@@ -11,3 +13,3 @@ * Type representing RQL parameters to send along a request.

export interface RQLParams {
[key: string]: string | number;
[key: string]: RQLParamValue;
}

@@ -101,29 +103,3 @@ /**

currentUser(): Promise<CurrentUser>;
/**
* Starts a new transaction.
*
* @returns A promise with the transaction uuid
*/
transactionBegin(): Promise<string>;
/**
* Executes a RQL request as part of a transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
* @param query The RQL query to send
* @param params The additional parameters for the request
* @returns A promise with the request's result set
*/
transactionExecute(uuid: string, query: string, params: RQLParams): Promise<ResultSet | null>;
/**
* Commits the transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
*/
transactionCommit(uuid: string): Promise<null>;
/**
* Rollbacks the transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
*/
transactionRollback(uuid: string): Promise<null>;
executeTransaction(transaction: Transaction): Promise<TransactionResult>;
private handleUserErrors;

@@ -130,0 +106,0 @@ }

89

lib/api/Api.js

@@ -13,2 +13,3 @@ "use strict";

const Errors_1 = require("../Errors");
const Transaction_1 = require("./Transaction");
/**

@@ -35,8 +36,2 @@ * Class used to handle requests to the CubicWeb API.

this._version = "v1";
this._transactionApiUrl = {
begin: "",
execute: "",
commit: "",
rollback: "",
};
this._apiUrl = apiUrl;

@@ -47,4 +42,3 @@ this._rqlApiUrl = this.getApiRoute("rql");

this._currentUserApiUrl = this.getApiRoute("current-user");
Object.keys(this._transactionApiUrl).forEach((k) => (this._transactionApiUrl[k] =
this.getApiRoute(`transaction/${k}`)));
this._transactionApiUrl = this.getApiRoute("transaction");
}

@@ -129,70 +123,25 @@ get apiUrl() {

}
/**
* Starts a new transaction.
*
* @returns A promise with the transaction uuid
*/
transactionBegin() {
executeTransaction(transaction) {
return __awaiter(this, void 0, void 0, function* () {
return nonNullFetchApi(this._transactionApiUrl.begin, {
const data = transaction.queries.map((transactionQuery) => ({
query: transactionQuery.query,
params: Object.fromEntries(Object.entries(transactionQuery.params).map(([key, value]) => [
key,
(0, Transaction_1.isTransactionQueryRef)(value)
? {
queryIndex: value.queryIndex,
row: value.row,
column: value.column,
}
: value,
])),
}));
const resultSets = yield nonNullFetchApi(this._transactionApiUrl, {
method: "POST",
credentials: "include",
body: JSON.stringify(data),
});
return new Transaction_1.TransactionResult(resultSets);
});
}
/**
* Executes a RQL request as part of a transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
* @param query The RQL query to send
* @param params The additional parameters for the request
* @returns A promise with the request's result set
*/
transactionExecute(uuid, query, params) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield fetchApi(this._transactionApiUrl.execute, {
method: "POST",
body: JSON.stringify({ uuid, query, params }),
credentials: "include",
});
}
catch (e) {
this.handleUserErrors(e);
}
});
}
/**
* Commits the transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
*/
transactionCommit(uuid) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield fetchApi(this._transactionApiUrl.commit, {
method: "POST",
body: JSON.stringify({ uuid }),
credentials: "include",
});
}
catch (e) {
this.handleUserErrors(e);
}
});
}
/**
* Rollbacks the transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
*/
transactionRollback(uuid) {
return __awaiter(this, void 0, void 0, function* () {
return fetchApi(this._transactionApiUrl.rollback, {
method: "POST",
body: JSON.stringify({ uuid }),
credentials: "include",
});
});
}
handleUserErrors(error) {

@@ -199,0 +148,0 @@ if (typeof error === "object" &&

@@ -17,3 +17,3 @@ import { Schema } from "../schema/classes/Schema";

*/
constructor(apiUrl: string, { transactionBackend: transactionBackend, }: {
constructor(apiUrl: string, options?: {
transactionBackend?: TransactionBackend;

@@ -20,0 +20,0 @@ });

@@ -29,6 +29,7 @@ "use strict";

*/
constructor(apiUrl, { transactionBackend: transactionBackend, }) {
constructor(apiUrl, options = {}) {
this.api = new Api_1.default(apiUrl);
const { transactionBackend } = options;
if (transactionBackend === undefined) {
this.transactionBackend = new Transaction_1.NativeTransactionBackend();
this.transactionBackend = new Transaction_1.NativeTransactionBackend(this.api);
}

@@ -35,0 +36,0 @@ else {

@@ -1,5 +0,5 @@

import { ResultSet } from "./Api";
import Api, { ResultSet, RQLParamValue } from "./Api";
export declare class Transaction {
private _queries;
push(query: string, params: Record<string, string | number | TransactionQueryRef>): TransactionQuery;
push(query: string, params: Record<string, RQLParamValue | TransactionQueryRef>): TransactionQuery;
get queries(): ReadonlyArray<TransactionQuery>;

@@ -19,14 +19,16 @@ }

readonly query: string;
readonly params: Record<string, string | number | TransactionQueryRef>;
readonly params: Record<string, RQLParamValue | TransactionQueryRef>;
readonly index: number;
constructor(query: string, params: Record<string, string | number | TransactionQueryRef>, index: number);
constructor(query: string, params: Record<string, RQLParamValue | TransactionQueryRef>, index: number);
ref(row?: number, column?: number): TransactionQueryRef;
}
export declare function isTransactionQueryRef(value: string | number | TransactionQueryRef): value is TransactionQueryRef;
export declare function isTransactionQueryRef(value: RQLParamValue | TransactionQueryRef): value is TransactionQueryRef;
export interface TransactionBackend {
execute(transaction: Transaction): Promise<TransactionResult>;
}
export declare class NativeTransactionBackend {
execute(): Promise<TransactionResult>;
export declare class NativeTransactionBackend implements TransactionBackend {
private _api;
constructor(_api: Api);
execute(transaction: Transaction): Promise<TransactionResult>;
}
//# sourceMappingURL=Transaction.d.ts.map

@@ -53,2 +53,3 @@ "use strict";

return (typeof value === "object" &&
value !== null &&
["queryIndex", "row", "column"].every((key) => Object.keys(value).includes(key)));

@@ -58,5 +59,8 @@ }

class NativeTransactionBackend {
execute() {
constructor(_api) {
this._api = _api;
}
execute(transaction) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("NativeTransactionBackend.execute not yet implemented.");
return this._api.executeTransaction(transaction);
});

@@ -63,0 +67,0 @@ }

@@ -9,6 +9,2 @@ /**

/**
* All the possible operators inside a constraint.
*/
export type ConstraintOperator = ">" | ">=" | "<" | "<=";
/**
* THe type of a constraint message when one is present.

@@ -30,4 +26,47 @@ */

}>;
/**
* Reference to an attribute used in constraints.
*
* @property \_\_attribute\_\_ name of the attribute in the same entity
*/
export interface Attribute {
__attribute__: string;
}
export interface TimeDelta {
days: number;
seconds: number;
microseconds: number;
}
/**
* Represents a date relative to the current date at the time of the check.
*
* @property \_\_today\_\_ always true
* @property offset delta to current date at the time of the check
* @property type name of the Python class used to do the comparison
*/
export interface Today {
__today__: true;
offset: TimeDelta | null;
type: "Datetime" | "TZDatetime" | "Date";
}
/**
* Represents a datetime relative to the current datetime at the time of the check.
*
* @property \_\_now\_\_ always true
* @property offset delta to current date at the time of the check
*/
export interface Now {
__now__: true;
offset: TimeDelta;
}
/**
* All the possible operators inside a constraint.
*/
export type ConstraintOperator = ">" | ">=" | "<" | "<=";
/**
* @property value.boundary boudary value to compare the attribut
*
*/
export type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
boundary: number | null;
boundary: Attribute | Today | Now | number | null;
op: ConstraintOperator;

@@ -34,0 +73,0 @@ msg: ConstraintMessage;

@@ -5,3 +5,3 @@ {

"author": "Logilab",
"version": "2.0.0",
"version": "2.1.0",
"license": "LGPL-3.0-or-later",

@@ -8,0 +8,0 @@ "main": "lib/index.js",

import { ValidationError } from "../Errors";
import { RawSchema } from "../schema/raw/Schema";
import {
TransactionResult,
Transaction,
isTransactionQueryRef,
} from "./Transaction";

@@ -9,2 +14,3 @@ /**

export type RQLParamValue = string | number | boolean | null;
/**

@@ -14,3 +20,3 @@ * Type representing RQL parameters to send along a request.

export interface RQLParams {
[key: string]: string | number;
[key: string]: RQLParamValue;
}

@@ -68,8 +74,3 @@

private _currentUserApiUrl: string;
private _transactionApiUrl = {
begin: "",
execute: "",
commit: "",
rollback: "",
};
private _transactionApiUrl: string;

@@ -92,7 +93,3 @@ /**

this._currentUserApiUrl = this.getApiRoute("current-user");
Object.keys(this._transactionApiUrl).forEach(
(k) =>
(this._transactionApiUrl[k as keyof typeof this._transactionApiUrl] =
this.getApiRoute(`transaction/${k}`))
);
this._transactionApiUrl = this.getApiRoute("transaction");
}

@@ -174,68 +171,31 @@

/**
* Starts a new transaction.
*
* @returns A promise with the transaction uuid
*/
async transactionBegin(): Promise<string> {
return nonNullFetchApi<string>(this._transactionApiUrl.begin, {
method: "POST",
credentials: "include",
});
}
/**
* Executes a RQL request as part of a transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
* @param query The RQL query to send
* @param params The additional parameters for the request
* @returns A promise with the request's result set
*/
async transactionExecute(
uuid: string,
query: string,
params: RQLParams
): Promise<ResultSet | null> {
try {
return await fetchApi<ResultSet>(this._transactionApiUrl.execute, {
async executeTransaction(
transaction: Transaction
): Promise<TransactionResult> {
const data = transaction.queries.map((transactionQuery) => ({
query: transactionQuery.query,
params: Object.fromEntries(
Object.entries(transactionQuery.params).map(([key, value]) => [
key,
isTransactionQueryRef(value)
? {
queryIndex: value.queryIndex,
row: value.row,
column: value.column,
}
: value,
])
),
}));
const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
this._transactionApiUrl,
{
method: "POST",
body: JSON.stringify({ uuid, query, params }),
credentials: "include",
});
} catch (e) {
this.handleUserErrors(e);
}
body: JSON.stringify(data),
}
);
return new TransactionResult(resultSets);
}
/**
* Commits the transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
*/
async transactionCommit(uuid: string): Promise<null> {
try {
return await fetchApi<null>(this._transactionApiUrl.commit, {
method: "POST",
body: JSON.stringify({ uuid }),
credentials: "include",
});
} catch (e) {
this.handleUserErrors(e);
}
}
/**
* Rollbacks the transaction identified by the given uuid.
*
* @param uuid The transaction's uuid
*/
async transactionRollback(uuid: string): Promise<null> {
return fetchApi<null>(this._transactionApiUrl.rollback, {
method: "POST",
body: JSON.stringify({ uuid }),
credentials: "include",
});
}
private handleUserErrors(error: unknown): never {

@@ -242,0 +202,0 @@ if (

@@ -26,9 +26,8 @@ import { Schema } from "../schema/classes/Schema";

apiUrl: string,
{
transactionBackend: transactionBackend,
}: { transactionBackend?: TransactionBackend }
options: { transactionBackend?: TransactionBackend } = {}
) {
this.api = new Api(apiUrl);
const { transactionBackend } = options;
if (transactionBackend === undefined) {
this.transactionBackend = new NativeTransactionBackend();
this.transactionBackend = new NativeTransactionBackend(this.api);
} else {

@@ -35,0 +34,0 @@ this.transactionBackend = transactionBackend;

@@ -1,2 +0,2 @@

import { ResultSet } from "./Api";
import Api, { ResultSet, RQLParamValue } from "./Api";

@@ -8,3 +8,3 @@ export class Transaction {

query: string,
params: Record<string, string | number | TransactionQueryRef>
params: Record<string, RQLParamValue | TransactionQueryRef>
): TransactionQuery {

@@ -42,6 +42,3 @@ const stackedQuery = new TransactionQuery(

public readonly query: string,
public readonly params: Record<
string,
string | number | TransactionQueryRef
>,
public readonly params: Record<string, RQLParamValue | TransactionQueryRef>,
public readonly index: number

@@ -60,6 +57,7 @@ ) {}

export function isTransactionQueryRef(
value: string | number | TransactionQueryRef
value: RQLParamValue | TransactionQueryRef
): value is TransactionQueryRef {
return (
typeof value === "object" &&
value !== null &&
["queryIndex", "row", "column"].every((key) =>

@@ -75,6 +73,7 @@ Object.keys(value).includes(key)

export class NativeTransactionBackend {
async execute(): Promise<TransactionResult> {
throw new Error("NativeTransactionBackend.execute not yet implemented.");
export class NativeTransactionBackend implements TransactionBackend {
constructor(private _api: Api) {}
async execute(transaction: Transaction): Promise<TransactionResult> {
return this._api.executeTransaction(transaction);
}
}

@@ -13,7 +13,2 @@ /**

/**
* All the possible operators inside a constraint.
*/
export type ConstraintOperator = ">" | ">=" | "<" | "<=";
/**
* THe type of a constraint message when one is present.

@@ -38,5 +33,57 @@ */

/**
* Reference to an attribute used in constraints.
*
* @property \_\_attribute\_\_ name of the attribute in the same entity
*/
export interface Attribute {
__attribute__: string;
}
export interface TimeDelta {
days: number;
seconds: number;
microseconds: number;
}
/**
* Represents a date relative to the current date at the time of the check.
*
* @property \_\_today\_\_ always true
* @property offset delta to current date at the time of the check
* @property type name of the Python class used to do the comparison
*/
export interface Today {
__today__: true;
offset: TimeDelta | null;
type: "Datetime" | "TZDatetime" | "Date";
}
/**
* Represents a datetime relative to the current datetime at the time of the check.
*
* @property \_\_now\_\_ always true
* @property offset delta to current date at the time of the check
*/
export interface Now {
__now__: true;
offset: TimeDelta;
}
/**
* All the possible operators inside a constraint.
*/
export type ConstraintOperator = ">" | ">=" | "<" | "<=";
/**
* @property value.boundary boudary value to compare the attribut
*
*/
export type BoundaryConstraint = ConstraintBase<
"BoundaryConstraint",
{ boundary: number | null; op: ConstraintOperator; msg: ConstraintMessage }
{
boundary: Attribute | Today | Now | number | null;
op: ConstraintOperator;
msg: ConstraintMessage;
}
>;

@@ -43,0 +90,0 @@ export type IntervalBoundConstraint = ConstraintBase<

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc