![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@logilab/cwclientlibjs
Advanced tools
Javascript clone of the cwclientlib python library that wraps the rqlcontroller API offered by the cubicweb-rqlcontroller cube.
If you want to communicate with the API Cube, use cubicwebjs instead.
To read about the rql client, go to Section Client.ts. To read about the providers, go to Section Providers.ts.
The client namespace provides helpers to run RQL queries on a cubicweb instance with the rqlcontroller cube.
The class CwRqlClient implements the interface RqlClient and provides the following functions:
A RqlClient relies on an HttpClient. Two implementations are available CwSimpleHttpClient and CwSigningHttpClient.
CwSimpleHttpClient 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). 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. The CSRF token
will be included if allowsCrossOrigin
is false (the default).
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, true)
);
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]]
});
rqlClient.queryBindings(query).then(res => {
console.log(res); // [{'X': 123, 'Y': 1}, {'X':234, 'Y':2}]
});
rqlClient.queryAndTransform(query, 'rdf').then(res => {
console.log(res); // equivalent to http://my-cubicweb-instance-base-url/view?rql=Any X, Y WHERE X is BlogEntry, X entry_of Y &vid=rdf
});
rqlClient.transactionV1([query]).then(res => {
console.log(res); // [[[123,1], [234, 2]]]
});
rqlClient.transactionV2([query]).then(res => {
console.log(res); // [{rows: [[123,1], [234, 2]], variables : ['X','Y']}]
});
CwSigningHttpClient 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.
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]]
});
The provider namespace provides two main objects: EntitySchemaProvider and EntityProvider.
A RqlEntitySchemaProvider provides an interface to load a CubicWeb instance Schema.
A EntitySchemaProvider provides the following functions:
An RqlEntitySchemaProvider can instantiate a LocalStorageEntitySchemasLoader 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.
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.If no 'storageKey' value is given, a
RqlEntitySchemasLoader will be instantiated and the
schema will be queried at every call of the load
function.
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));
// Schema will not be cached
const schemaProvider = new providers.RqlEntitySchemaProvider(rqlClient);
// Schema will be cached
const schemaProviderWithLocalStorage = new providers.RqlEntitySchemaProvider(
rqlClient,
'mySchemaStorageKey'
);
// load a schema
schemaProvider.load().then((schema: providers.Schema) => {
console.log(schema);
});
// load a schema
schemaProviderWithLocalStorage.load().then((schema: providers.Schema) => {
console.log(schema);
});
A Schema is a json object with two entries:
Example instanciation of a schema object:
{
"metadata": {
"timestamp": "2020-04-20T09:35:49.183Z"
},
"entities": [
{
"eid": 30,
"name": "BlogEntry",
"modificationDate": "2009/09/01 12:15:04",
"specializes": null,
"attributes": [
{"eid": 78, "name": "title", "type": "String", "cardinality": 2}
],
"relationsTo": [
{
"eid": 6055,
"name": "entry_of",
"from": 30,
"fromName": "BlogEntry",
"fromCardinality": 1,
"to": 6044,
"toName": "Blog",
"toCardinality": 1,
"description": ""
}
],
"relationsFrom": [
{
"eid": 711,
"name": "tags",
"from": 61,
"fromName": "Tag",
"fromCardinality": 1,
"to": 30,
"toName": "BlogEntry",
"toCardinality": 1,
"description": "indicates that an entity is classified by a given tag"
}
]
}
]
}
Three entity Providers:
Each EntityProvider provides the following functions:
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));
// Schema will not be cached
const schemaProvider = new providers.RqlEntitySchemaProvider(
rqlClient,
'storageKey'
);
const rqlEntityProvider = new providers.RqlEntityProvider(
rqlClient,
schemaProvider
);
const eJsonEntityProvider = new providers.EJsonExportEntityProvider(rqlClient);
const cachedEntityProvider = new providers.CachedEntityProvider(
rqlEntityProvider
);
cachedEntityProvider.getEntity(123456).then(entity => {
console.log(entity);
});
An entity will be a json object, whose keys are defined by its EntitySchema (CWEType)
{
"@eid": 123456,
"@type": "BlogEntry",
"title": "Super Blog Post",
"entry_of_BlogEntry_Blog": [11111],
"tags_Tag_BlogEntry": [765432, 99999],
"modification_date": "2010/03/01 18:45:52"
}
The tests relies on an instance with the test-server
cube to run.
The Dockerfile located in test-server
creates an image with an instance ready for
use. Building it is as simple as:
docker build -t cw-test-server .
You can then run the instance using docker run
:
docker run -p 8080:8080 cw-test-server
Once the instance is running, launch the tests:
npm run test
By default the test instance is running on "http://localhost:8080". If you need
to start it on a different host/port, use the CW_BASE_URL
environment
variable.
There seems to be a problem with Cookie handling: in the doRequestFetch
function. 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.
FAQs
client library for CubicWeb's rqlcontroller API
We found that @logilab/cwclientlibjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.