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

@logilab/cwclientlibjs

Package Overview
Dependencies
Maintainers
6
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@logilab/cwclientlibjs - npm Package Compare versions

Comparing version 0.2.6 to 1.0.0

35

build/client.d.ts

@@ -0,1 +1,3 @@

import { Schema, EntitySchema } from './providers';
export declare function applySchema(jsonEntity: any): EntitySchema;
/**

@@ -13,6 +15,2 @@ * Interface for an http response

content: any;
/**
* The response headers
*/
headers: Headers;
}

@@ -32,11 +30,2 @@ /**

}
export interface HttpRequestOptions {
method: string;
content: any;
contentType: string;
accept: string;
headers: Headers;
responseHeaders: string[];
allowCrossOrigin: boolean;
}
/**

@@ -58,3 +47,3 @@ * An HTTP client for a cubicweb instance

*/
request(path: string, options: Partial<HttpRequestOptions>): Promise<HttpResponse>;
request(path: string, method: string, content: any, contentType: string | null, accept: string): Promise<HttpResponse>;
}

@@ -91,3 +80,3 @@ /**

hasCookies(): boolean;
request(path: string, options: Partial<HttpRequestOptions>): Promise<HttpResponse>;
request(path: string, method: string, content: any, contentType: string | null, accept: string): Promise<HttpResponse>;
/**

@@ -129,3 +118,3 @@ * Performs login onto the associated cubicweb instance

constructor(baseUrl: string, tokenName: string, tokenValue: string, hashMethod?: SignedContentHashMethod);
request(path: string, options: Partial<HttpRequestOptions>): Promise<HttpResponse>;
request(path: string, method: string, content: any, contentType: string, accept: string): Promise<HttpResponse>;
}

@@ -212,6 +201,2 @@ /**

/**
* The underlying HTTP client
*/
readonly httpClient: HttpClient;
/**
* Executes a RQL query

@@ -242,2 +227,10 @@ * @param query The RQL query

/**
* Fetch the cubicweb schema from a server supporting cubicweb_rqlcontroller
*/
getSchema(): Promise<Schema>;
/**
* Fetch the cubicweb schema hash from a server supporting cubicweb_rqlcontroller
*/
getSchemaHash(): Promise<string | null>;
/**
* Executes RQL queries in a transaction through RQL/IO v1.0

@@ -276,2 +269,4 @@ * @param queries The queries

}): Promise<RqlSolutions>;
getSchema(): Promise<Schema>;
getSchemaHash(): Promise<string | null>;
queryAndTransform(query: string, params: {

@@ -278,0 +273,0 @@ [key: string]: any;

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

import { RqlClient, HttpClient } from './client';
import { RqlClient } from './client';
/**

@@ -190,3 +190,3 @@ * A complete schema

load(): Promise<Schema>;
getSchemaHash(): Promise<string>;
getSchemaHash(): Promise<string | null>;
}

@@ -224,5 +224,8 @@ /**

*/
/**
* Promise used to fetch the most recent schema hash from the server
*/
readonly getSchemaHash: () => Promise<string | null>;
constructor(inner: EntitySchemasLoader, storageKey: string, hashStorageKey?: string | null, isCacheUsable?: (schema: Schema) => Promise<boolean>, onRetrieved?: (schema: Schema) => Promise<Schema>);
load(): Promise<Schema>;
getSchemaHash(): Promise<string>;
/**

@@ -236,8 +239,8 @@ * Loads from the inner loader

*/
export declare class HttpEntitySchemasLoader implements EntitySchemasLoader {
export declare class RqlEntitySchemasLoader implements EntitySchemasLoader {
/**
* The client to use
* The RQL client to use
*/
readonly client: HttpClient;
constructor(client: HttpClient);
readonly rqlClient: RqlClient;
constructor(rqlClient: RqlClient);
/**

@@ -247,8 +250,3 @@ * Loads all entity schemas

load(): Promise<Schema>;
getSchemaHash(): Promise<string>;
/**
* Transforms the retrieve schema in JSON form into an entity schema
* @param jsonEntity The retrieved schema
*/
private applySchema;
getSchemaHash(): Promise<string | null>;
}

@@ -284,3 +282,2 @@ /**

constructor(loader: EntitySchemasLoader);
getSchemaHash(): Promise<string>;
/**

@@ -314,4 +311,5 @@ * Loads the content of the

*/
constructor(rqlClient: RqlClient, loader?: EntitySchemasLoader);
constructor(rqlClient: RqlClient, storageKey?: string, hashStorageKey?: string | null, isCacheUsable?: (schema: Schema) => Promise<boolean>, onRetrieved?: (schema: Schema) => Promise<Schema>);
getEntitySchemaFor(eid: number): Promise<EntitySchema | null>;
getSchemaHash(): Promise<string | null>;
}

@@ -318,0 +316,0 @@ /**

{
"name": "@logilab/cwclientlibjs",
"version": "0.2.6",
"version": "1.0.0",
"description": "client library for CubicWeb's rqlcontroller API",

@@ -46,3 +46,3 @@ "homepage": "https://forge.extranet.logilab.fr/open-source/cwclientlibjs",

"ts-node": "^8.3.0",
"typescript": "^3.9.3",
"typescript": "^3.5.3",
"typescript-formatter": "^7.2.2",

@@ -49,0 +49,0 @@ "web-ext": "^3.1.1",

# cwclientlibjs - client library for CubicWeb's rqlcontroller
Javascript clone of the cwclientlib python library that wraps the rqlcontroller API offered by the cubicweb-rqlcontroller cube.
Javascript clone of the cwclientlib python library that wraps the rqlcontroller
API offered by the cubicweb-rqlcontroller cube.
To read about the rql client, go to [Section Client.ts](#client.ts).
To read about the providers, go to [Section Providers.ts](#providers.ts).
To read about the rql client, go to [Section Client.ts](#client.ts). To read
about the providers, go to [Section Providers.ts](#providers.ts).
For internal use : [sonarqube analysis](https://sonarqube.k.intra.logilab.fr/dashboard?id=open-source-cwclientlibjs)
## Client.ts
The [client](src/client.ts) namespace provides helpers to run RQL queries on a cubicweb instance with the rqlcontroller cube.
The [client](src/client.ts) namespace provides helpers to run RQL queries on a
cubicweb instance with the rqlcontroller cube.
The class [CwRqlClient](src/client.ts#L690) implements the interface [RqlClient](src/client.ts#L644) and provides the following functions:
The class [CwRqlClient](src/client.ts#L690) implements the interface
[RqlClient](src/client.ts#L644) and provides the following functions:
- **queryRows(query:string, params?:any)**: runs query on the cubicweb instance and returns the results as [RqlRows](src/client.ts#L553) in a Promise. This function calls transactionV1
- **queryBindings(query:string, params?)**: runs query on the cubicweb instance with and returns the results as [RqlSolutions](src/client.ts#L586) in a Promise. This function calls transactionV2
- **queryAndTransform(query:string, params?,viewId)**: Build the url corresponding to the query with a given viewId and returns the content in a Promise
- **transactionV1(queries)**: runs a set of queries with the rqlio/1.0 interface and returns the query results or throws an error if something went wrong
- **transactionV2(queries)**: runs a set of queries with the rqlio/2.0 interface and returns the query results as [RqlIoV2TransactionResponse](src/client.ts#L576)
- **queryRows(query:string, params?:any)**: runs query on the cubicweb
instance and returns the results as [RqlRows](src/client.ts#L553) in a
Promise. This function calls transactionV1
- **queryBindings(query:string, params?)**: runs query on the cubicweb
instance with and returns the results as [RqlSolutions](src/client.ts#L586)
in a Promise. This function calls transactionV2
- **queryAndTransform(query:string, params?,viewId)**: Build the url
corresponding to the query with a given viewId and returns the content in a
Promise
- **transactionV1(queries)**: runs a set of queries with the rqlio/1.0
interface and returns the query results or throws an error if something went
wrong
- **transactionV2(queries)**: runs a set of queries with the rqlio/2.0
interface and returns the query results as
[RqlIoV2TransactionResponse](src/client.ts#L576)
A RqlClient relies on an HttpClient. Two implementations are available [CwSimpleHttpClient](src/client.ts#L332) and [CwSigningHttpClient](src/client.ts#L462).
A RqlClient relies on an HttpClient. Two implementations are available
[CwSimpleHttpClient](src/client.ts#L332) and
[CwSigningHttpClient](src/client.ts#L462).
[CwSimpleHttpClient](src/client.ts#L332) requires a baseUrl (the base url of a cubicweb instance). A boolean can be added to allow cross origin requests.
The CwSimpleHttpClient can perform a doLogin(login,password) operation on the cubicweb instance and perform the queries by using cookies (see [Known issues](#known-issues)).
It can also be transformed into a CwSigningHttpClient (toSigningClient()) after a doLogin() operation. It requires that the CubicWeb user has at least an enabled token linked to his/her account.
[CwSigningHttpClient](src/client.ts#L462) requires a baseUrl (the base url of a cubicweb instance), a tokenName, a tokenValue and a hashMethod code. Each request will contain a Authorization header with the connection token and its hashed value.
### CwSimpleHttpClient: anonymous request
[CwSimpleHttpClient](src/client.ts#L332) requires a baseUrl (the base url of a
cubicweb instance). A boolean can be added to allow cross origin requests. The
CwSimpleHttpClient can perform a doLogin(login,password) operation on the
cubicweb instance and perform the queries by using cookies (see [Known
issues](#known-issues)). It can also be transformed into a CwSigningHttpClient
(toSigningClient()) after a doLogin() operation. It requires that the CubicWeb
user has at least an enabled token linked to his/her account.
```javascript

@@ -61,25 +83,69 @@ import {providers, client} from '@logilab/cwclientlibjs';

### CwSigningHttpClient: authenticated requests.
[CwSigningHttpClient](src/client.ts#L462) requires a baseUrl (the base url of a
cubicweb instance), a tokenName, a tokenValue and a hashMethod code. Each
request will contain an Authorization header with the connection token and its
hashed value.
These tokens are managed on your CubicWeb instance under Profile > Actions > Add
> Authentication Token.
```javascript
import {providers, client} from '@logilab/cwclientlibjs';
// url is the base url of your cubicweb instance
const url = 'http://my-cubicweb-instance-base-url/';
const rqlClient = new client.CwRqlClient(
new client.CwSimpleHttpClient(url, "my-token-name", "1a2b3c4d5e6f...")
);
const query = 'Any X, Y WHERE X is BlogEntry, X entry_of Y';
rqlClient.queryRows(query).then(res => {
console.log(res); // [[123,1], [234, 2]]
});
```
## Providers.ts
The [provider](src/providers.ts) namespace provides two main objects: [EntitySchemaProvider](#entityschemaprovider) and [EntityProvider](#entityprovider).
The [provider](src/providers.ts) namespace provides two main objects:
[EntitySchemaProvider](#entityschemaprovider) and
[EntityProvider](#entityprovider).
### EntitySchemaProvider
A [RqlEntitySchemaProvider](src/providers.ts#L593) provides an interface to load a CubicWeb instance Schema.
A [RqlEntitySchemaProvider](src/providers.ts#L593) provides an interface to load
a CubicWeb instance Schema.
A EntitySchemaProvider provides the following functions:
- **getAllRelationsFor(typeEid:number)**: Outputs two lists: relationsFrom and relationsTo relative to the CWEType referenced by typeEid
- **getEntitySchemaByName(typeName: string)**: Retrieves a CWEType (as EntitySchema) from its name
- **getEntitySchemaById(typeEid: number)** : Retrieves a CWEType (as EntitySchema) from its eid
- **getEntitySchemaFor(eid:number)** : Retrieves a CWEType (as EntitySchema) for a given instance number
- **getAllRelationsFor(typeEid:number)**: Outputs two lists: relationsFrom and
relationsTo relative to the CWEType referenced by typeEid
- **getEntitySchemaByName(typeName: string)**: Retrieves a CWEType (as
EntitySchema) from its name
- **getEntitySchemaById(typeEid: number)** : Retrieves a CWEType (as
EntitySchema) from its eid
- **getEntitySchemaFor(eid:number)** : Retrieves a CWEType (as EntitySchema)
for a given instance number
- **load()**: Loads the Schema
An RqlEntitySchemaProvider can instantiate a [LocalStorageEntitySchemasLoader](src/providers.ts#L259) which will store the schema in the browser's window.localStorage, if given a 'storageKey' value.
Additionnaly, two functions: **isCacheUsable** and **onRetrieved** can be given to the RqlEntitySchemaProvider, they can be used to deal with schema versioning.
An RqlEntitySchemaProvider can instantiate a
[LocalStorageEntitySchemasLoader](src/providers.ts#L259) which will store the
schema in the browser's window.localStorage, if given a 'storageKey' value.
Additionnaly, two functions: **isCacheUsable** and **onRetrieved** can be given
to the RqlEntitySchemaProvider, they can be used to deal with schema versioning.
- **isCacheUsable** is called in a LocalStorageEntitySchemasLoader, it takes a `providers.Schema` as input and outputs a boolean Promise. If the promise is resolved with the value `true`, the schema will be loaded from the localStorage. Otherwise, if will be queried and loaded from the cubicweb instance again.
- **onRetrieved** is called after the schema has been queried and loaded from the cubicweb instance.
- **isCacheUsable** is called in a LocalStorageEntitySchemasLoader, it takes a
`providers.Schema` as input and outputs a boolean Promise. If the promise is
resolved with the value `true`, the schema will be loaded from the
localStorage. Otherwise, if will be queried and loaded from the cubicweb
instance again.
- **onRetrieved** is called after the schema has been queried and loaded from
the cubicweb instance.
If no 'storageKey' value is given, a [RqlEntitySchemasLoader](src/providers.ts#L340) will be instantiated and the schema will be queried at every call of the `load` function.
If no 'storageKey' value is given, a
[RqlEntitySchemasLoader](src/providers.ts#L340) will be instantiated and the
schema will be queried at every call of the `load` function.

@@ -116,4 +182,6 @@ ```javascript

- a **metadata** object which is computed on the schema load. At the moment, the metadata contains the schema loading timestamp.
- **entities**: a list of EntitySchema, each EntitySchema describes a CWEType, its attributes and to and from relations.
- a **metadata** object which is computed on the schema load. At the moment,
the metadata contains the schema loading timestamp.
- **entities**: a list of EntitySchema, each EntitySchema describes a CWEType,
its attributes and to and from relations.

@@ -171,5 +239,9 @@ Example instanciation of a schema object:

- [RqlEntityProvider](src/providers.ts#L682): Provides access to entities through a RQL enpoint. An EntitySchemaProvider can be specified on implementation, for example to cache the Schema in the localStorage.
- [EJsonExportEntityProvider](src/providers.ts#L812): Provides access to entities through the ejsonexport view of a RQL endpoint
- [CachedEntityProvider](src/providers.ts#L859): Caches the access to entities provided by another provider
- [RqlEntityProvider](src/providers.ts#L682): Provides access to entities
through a RQL enpoint. An EntitySchemaProvider can be specified on
implementation, for example to cache the Schema in the localStorage.
- [EJsonExportEntityProvider](src/providers.ts#L812): Provides access to
entities through the ejsonexport view of a RQL endpoint
- [CachedEntityProvider](src/providers.ts#L859): Caches the access to entities
provided by another provider

@@ -179,4 +251,8 @@ Each EntityProvider provides the following functions:

- **getEntity(eid:number)**: Gets an entity given its eid
- **getEntityGivenSchema(eid:number, entitySchema: EntitySchema)**: Gets an entity given its expected entitySchema (CWEType, list of attributes, relations to and from)
- **getEntityTitleGivenSchema(eid: number, entitySchema EntitySchema)** : Gets the title for an entity, i.e., the value of the first attribute in the list of the entitySchema attributes.
- **getEntityGivenSchema(eid:number, entitySchema: EntitySchema)**: Gets an
entity given its expected entitySchema (CWEType, list of attributes,
relations to and from)
- **getEntityTitleGivenSchema(eid: number, entitySchema EntitySchema)** : Gets
the title for an entity, i.e., the value of the first attribute in the list
of the entitySchema attributes.

@@ -211,3 +287,4 @@ ```javascript

An entity will be a json object, whose keys are defined by its EntitySchema (CWEType)
An entity will be a json object, whose keys are defined by its EntitySchema
(CWEType)

@@ -231,3 +308,5 @@ ```json

There seems to be a problem with Cookie handling: in the [doRequestFetch function](src/client.ts#L107). The headers of the request seem to be empty for every response.
Therefore, the login functionality is broken for the moment as it requires to access the `Set-Cookie` fields of HTTP Responses.
There seems to be a problem with Cookie handling: in the [doRequestFetch
function](src/client.ts#L107). The headers of the request seem to be empty for
every response. Therefore, the login functionality is broken for the moment as
it requires to access the `Set-Cookie` fields of HTTP Responses.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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