### Start DataJoint LabBook Application Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/user.md This command starts the DataJoint LabBook application and its dependencies using Docker Compose. It requires Docker and Docker Compose to be installed, and the `docker-compose-deploy.yaml` file to be present. The command specifies versions for PHARUS and DJLABBOOK. It runs the services in detached mode. ```bash PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml up -d ``` -------------------------------- ### GET /schema Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Fetches a list of all available database schemas that the authenticated user has access to. ```APIDOC ## GET /schema ### Description Lists all available database schemas accessible to the authenticated user. ### Method GET ### Endpoint /schema ### Parameters None ### Response #### Success Response (200) - **schemaNames** (array) - An array of strings, where each string is the name of an available schema. #### Response Example ```json { "schemaNames": [ "experiment_schema", "production_schema", "analysis_schema" ] } ``` #### Error Response (500) - **error** (string) - A message describing the server error during schema listing. ``` -------------------------------- ### Fetch Schema List - GET /schema (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Lists all available database schemas that the authenticated user has access to. Returns a JSON object containing an array of schema names. Requires JWT authorization. ```typescript fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken } }) .then(result => { if (result.status === 500) { result.text().then(errorMessage => { throw new Error(errorMessage) }); } return result.json(); }) .then(result => { // result.schemaNames: array of schema names console.log('Available schemas:', result.schemaNames); }) .catch((error) => { console.error('Error fetching schemas:', error); }) ``` -------------------------------- ### Docker Production Deployment Configuration (Bash) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Provides bash commands for deploying the DataJoint LabBook project in a production environment using Docker Compose. This includes downloading the configuration file, setting version variables, pulling images, starting services in detached mode, checking status, viewing logs, and stopping the services. ```bash # docker-compose-deploy.yaml - Production deployment # Download the deployment file curl -L https://github.com/datajoint/datajoint-labbook/releases/latest/download/docker-compose-deploy.yaml -o docker-compose-deploy.yaml # Set version environment variables export PHARUS_VERSION=0.1.0 export DJLABBOOK_VERSION=0.1.0 # Pull latest images PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml pull # Start services PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml up -d # Check service status docker-compose -f docker-compose-deploy.yaml ps # View logs docker-compose -f docker-compose-deploy.yaml logs -f # Stop services PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml down ``` -------------------------------- ### Stop DataJoint LabBook Application Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/user.md This command stops the DataJoint LabBook application and its associated services managed by Docker Compose. It requires Docker and Docker Compose to be installed, and the `docker-compose-deploy.yaml` file to be present. This command will shut down the containers defined in the docker-compose file. ```bash PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml down ``` -------------------------------- ### GET /schema/{schema}/table Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves all tables within a specified schema, organized by their type (Manual, Lookup, Computed, Imported, Part). ```APIDOC ## GET /schema/{schema}/table ### Description Retrieves all tables within a schema organized by table type (Manual, Lookup, Computed, Imported, Part). ### Method GET ### Endpoint `/schema/{schema}/table` ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema to retrieve tables from. ### Request Example ```typescript // Example using fetch API fetch('/schema/experiment_schema/table', { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken } }) ``` ### Response #### Success Response (200) - **tableTypes** (object) - An object where keys are table types (Manual, Lookup, Computed, Imported, Part) and values are arrays of table names belonging to that type. #### Response Example ```json { "tableTypes": { "Manual": ["Table1", "Table2"], "Lookup": ["LookupTable1"], "Computed": [], "Imported": [], "Part": [] } } ``` ``` -------------------------------- ### GET /schema/{schema}/table/{table}/definition Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves the DataJoint table definition for a specified table. This returns the complete table structure, including attributes, types, and relationships, as a string. ```APIDOC ## GET /schema/{schema}/table/{table}/definition ### Description Retrieves the DataJoint table definition string showing the complete table structure and relationships. ### Method GET ### Endpoint /schema/{schema}/table/{table}/definition ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema containing the table. - **table** (string) - Required - The name of the table to retrieve the definition for. ### Response #### Success Response (200) - **definition** (string) - The DataJoint table definition as a string. #### Response Example ``` "subject (Ingest) # Subject information\n subject_id : bigint unsigned auto_increment# Unique identifier for the subject\n subject_name : char(8) not null # Name of the subject (e.g. Mouse_001)\n date_of_birth : date not null # Date of birth of the subject\n sex : enum('M','F','U') not null # Sex of the subject\n weight : blob null # Latest weight measurement (g)" ``` #### Error Response (e.g., 404) - **error** (string) - A message describing the error if the table or schema is not found. ``` -------------------------------- ### Fetch Table Definition - GET /schema/{schema}/table/{table}/definition (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves the DataJoint table definition as a string, detailing the table's structure, attributes, and relationships. This is useful for understanding the schema of a specific table. Requires JWT authentication. ```typescript fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table/subject/definition`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken } }) .then(result => { if (!result.ok) { result.text().then(errorMessage => { throw Error(`${result.status} - ${result.statusText}: (${errorMessage})`) }) } return result.text() }) .then(result => { // result contains the table definition as a string console.log('Table definition:\n', result); }) .catch(error => { console.error('Problem fetching table information:', error) }) ``` -------------------------------- ### Fetch Table List - GET /schema/{schema}/table (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves a list of all tables within a specified schema from the DataJoint LabBook backend. It organizes tables by their type (Manual, Lookup, Computed, Imported, Part). Requires a JWT token for authorization and handles potential 500 errors by returning the error message. ```typescript // SideMenu.tsx - Fetching tables for a schema fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken } }) .then(result => { if (result.status === 500) { result.text().then(errorMessage => { throw new Error(errorMessage) }); } return result.json(); }) .then(result => { // result.tableTypes: object with arrays for each table type // {Manual: [...], Lookup: [...], Computed: [...], Imported: [...], Part: [...]} console.log('Manual tables:', result.tableTypes.Manual); console.log('Lookup tables:', result.tableTypes.Lookup); }) .catch((error) => { console.error('Error fetching tables:', error); }) ``` -------------------------------- ### Fetch Table Records - GET /schema/{schema}/table/{table}/record Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves paginated records from a specified table. Supports optional filtering using base64-encoded restriction parameters and allows specifying the number of records per page and the page number. ```APIDOC ## GET /schema/{schema}/table/{table}/record ### Description Retrieves paginated table records with optional filtering through base64-encoded restriction parameters. ### Method GET ### Endpoint /schema/{schema}/table/{table}/record ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema. - **table** (string) - Required - The name of the table. #### Query Parameters - **limit** (integer) - Optional - The maximum number of records to return per page. Defaults to 25. - **page** (integer) - Optional - The page number to retrieve. Defaults to 1. - **restriction** (string) - Optional - A base64-encoded JSON string representing an array of restriction objects. Each object specifies an attribute, an operation, and a value for filtering. #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., 'Bearer '). ### Request Example (with restrictions) ``` GET /schema/experiment_schema/table/subject/record?limit=25&page=1&restriction=W3sibmFtZSI6ImF0dHJpYnV0ZU5hbWUiOiJzdWJqZWN0X2lkIiwiIiwiYmFzZTY0K1VzZXIiLCJvcGVyYXRpb24iOiI9IiwidmFsdWUiOiIxMjM0NSJ9LHsibmFtZSI6ImF0dHJpYnV0ZU5hbWUiOiJhZ2UiLCJvcGVyYXRpb24iOiI%2BPSIsInZhbHVlIjoiMTgifV0%3D ``` (The `restriction` parameter in the example above is a base64 encoded representation of `[{"attributeName": "subject_id", "operation": "=", "value": "12345"}, {"attributeName": "age", "operation": ">=", "value": "18"}]`) ### Response #### Success Response (200) - **records** (array) - An array of tuples representing the table records. - **totalCount** (integer) - The total number of records matching the query (before pagination). #### Response Example ```json { "records": [ ["12345", 25, "male", ...], ["12346", 30, "female", ...] ], "totalCount": 150 } ``` ``` -------------------------------- ### Fetch Table Attributes - GET /schema/{schema}/table/{table}/attribute Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves metadata about table columns, including data types, primary/secondary attribute status, nullability, default values, and constraints. This is essential for rendering table views and input forms. ```APIDOC ## GET /schema/{schema}/table/{table}/attribute ### Description Retrieves metadata about table columns including data types, primary/secondary attributes, nullable status, default values, and constraints. ### Method GET ### Endpoint /schema/{schema}/table/{table}/attribute ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema. - **table** (string) - Required - The name of the table. #### Request Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., 'Bearer '). ### Response #### Success Response (200) - **attributes** (object) - An object containing attribute metadata. - **primary** (array) - An array of strings, where each string is the name of a primary key attribute. - **secondary** (array) - An array of arrays, where each inner array contains metadata for a non-primary attribute: `[name, type, nullable, defaultValue, autoIncrement]`. #### Response Example ```json { "attributes": { "primary": ["subject_id"], "secondary": [ ["age", "int", false, null, false], ["gender", "enum('male', 'female')", true, null, false] ] } } ``` ``` -------------------------------- ### Build Documentation with Docker Compose (Bash) Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/dev_notes.md Build the project's documentation using a separate Docker Compose configuration. This command spins up services defined in `docker-compose-docs.yaml` to generate the documentation, which will be available at `/docs/build/html/index.html`. ```bash docker-compose -f docker-compose-docs.yaml up ``` -------------------------------- ### Docker Deployment Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Instructions for deploying DataJoint LabBook using Docker Compose for production environments. ```APIDOC ## Docker Deployment Production deployment using Docker Compose with Pharus backend and Nginx reverse proxy. ### Download Deployment File ```bash curl -L https://github.com/datajoint/datajoint-labbook/releases/latest/download/docker-compose-deploy.yaml -o docker-compose-deploy.yaml ``` ### Set Version Environment Variables ```bash export PHARUS_VERSION=0.1.0 export DJLABBOOK_VERSION=0.1.0 ``` ### Pull Latest Images ```bash PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml pull ``` ### Start Services ```bash PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml up -d ``` ### Check Service Status ```bash docker-compose -f docker-compose-deploy.yaml ps ``` ### View Logs ```bash docker-compose -f docker-compose-deploy.yaml logs -f ``` ### Stop Services ```bash PHARUS_VERSION=0.1.0 DJLABBOOK_VERSION=0.1.0 docker-compose -f docker-compose-deploy.yaml down ``` ``` -------------------------------- ### Initialize Git Submodules (Bash) Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/dev_notes.md Initialize and update git submodules, specifically for the 'pharus' dependency. These commands ensure that nested repositories are properly set up and their latest versions are fetched after cloning the main repository. ```bash git submodule init git submodule update ``` -------------------------------- ### Run Test Watcher with Docker Exec (Bash) Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/dev_notes.md Execute the test watcher within the running DataJoint LabBook Docker container. This allows for continuous testing during development or running tests once with coverage reporting. Ensure the `datajoint-labbook_datajoint-labbook_1` container is active. ```bash docker exec -it datajoint-labbook_datajoint-labbook_1 npm test -- --coverage # OR to just run it once: docker exec -ite CI=true datajoint-labbook_datajoint-labbook_1 npm test -- --coverage ``` -------------------------------- ### Configure Local Docker Environment Variables (Bash) Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/dev_notes.md Modify these environment variables in your `docker-compose.yaml` file to configure the Python version, Docker image type, and distribution for the DataJoint LabBook environment. These settings control the build and runtime characteristics of the containers. ```bash PY_VER=3.8 # (pharus) Python version: 3.6|3.7|3.8 IMAGE=djtest # (pharus) Image type: djbase|djtest|djlab|djlabhub DISTRO=alpine # (pharus) Distribution: alpine|debian ``` -------------------------------- ### Add New Git Submodule (Bash) Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/dev_notes.md Add a new git submodule to the project, specifying the branch to track and the repository URL. This is used for integrating external dependencies like 'pharus' with their own git history. ```bash git submodule add -b master git@github.com:datajoint/pharus.git ``` -------------------------------- ### User Authentication - POST /login Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Authenticates a user against the MySQL database via the Pharus backend. Upon successful authentication, it returns a JWT token containing encrypted database credentials for subsequent API requests. ```APIDOC ## POST /login ### Description Authenticates a user against the MySQL database through the Pharus backend. Returns a JWT token containing encrypted database credentials for subsequent API requests. ### Method POST ### Endpoint /login ### Parameters #### Request Body - **databaseAddress** (string) - Required - The address of the database (e.g., 'localhost:3306'). - **username** (string) - Required - The database username. - **password** (string) - Required - The database password. ### Request Example ```json { "databaseAddress": "localhost:3306", "username": "myuser", "password": "mypassword" } ``` ### Response #### Success Response (200) - **jwt** (string) - The generated JWT token. #### Response Example ```json { "jwt": "" } ``` #### Error Response (500) - **errorMessage** (string) - A message detailing the authentication failure. ``` -------------------------------- ### Authenticate User with Pharus Backend - TypeScript Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Handles user authentication against the MySQL database via the Pharus backend. It sends database credentials and receives a JWT token upon successful authentication. This token is essential for subsequent API requests. ```typescript const response = await fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/login`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ databaseAddress: 'localhost:3306', username: 'myuser', password: 'mypassword' }) }) if (response.status === 500) { const errorMessage = await response.text(); console.error('Authentication failed:', errorMessage); return; } const jsonObject = await response.json(); const jwtToken = jsonObject.jwt; // Store JWT token for subsequent API calls ``` -------------------------------- ### Update Git Submodules to Latest (Bash) Source: https://github.com/datajoint/datajoint-labbook/blob/master/docs/sphinx/dev_notes.md Fetch the latest changes from all git submodules. This command iterates through each submodule and pulls the most recent commits from their respective remote repositories, typically from the master branch. ```bash git submodule foreach git pull ``` -------------------------------- ### Utility Functions Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Utility functions for comparing sets and parsing JSON with special numeric values. ```APIDOC ## Utility Functions ### isEqualSet Compares two Set objects for equality by checking size and element membership. ```typescript function isEqualSet(a: Set, b: Set): boolean { if (a.size !== b.size) { return false; } for (let element of a) { if (!b.has(element)) { return false; } } return true; } ``` ### reviver (JSON Parser) Custom JSON reviver function to restore special numeric values (NaN, Infinity, -Infinity) from string representations. ```typescript function reviver(key: any, value: string) { if (value === '***NaN***') { return NaN; } if (value === '***Infinity***') { return Infinity; } if (value === '***-Infinity***') { return -Infinity; } return value; } // Usage example: // fetch(apiUrl).then(result => result.text()).then(result => { // const data = JSON.parse(result.replace(/(NaN|-?Infinity)/g, '"***$1***"'), reviver); // }); ``` ``` -------------------------------- ### Insert Record - POST /schema/{schema}/table/{table}/record (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Inserts a new record (tuple) into a specified DataJoint table. It performs validation for required fields, nullable attributes, and data types. Requires a JWT token for authorization and specifies the backend prefix via environment variables. ```typescript const tupleBuffer = { subject_id: '12345', subject_name: 'Mouse_001', date_of_birth: '2024-01-15', sex: 'M', weight: 25.5 }; fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table/subject/record`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken }, body: JSON.stringify({records: [tupleBuffer]}) }) .then(result => { if (result.status === 500) { result.text().then(errorMessage => { throw new Error(errorMessage) }) } return result.text(); }) .then(result => { console.log('Insert successful'); // Refresh table content to show new record }) .catch((error) => { console.error('Insert failed:', error.message); }) ``` -------------------------------- ### POST /schema/{schema}/table/{table}/record Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Inserts a new record (tuple) into a specified DataJoint table. It validates input against table constraints, including required fields, nullability, and data types. The request body should contain an array of records to be inserted. ```APIDOC ## POST /schema/{schema}/table/{table}/record ### Description Inserts a new tuple into the specified table with validation for required fields, nullable attributes, and data type constraints. ### Method POST ### Endpoint /schema/{schema}/table/{table}/record ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema containing the table. - **table** (string) - Required - The name of the table to insert the record into. #### Request Body - **records** (array) - Required - An array of record objects to insert. - Each record object should contain key-value pairs corresponding to the table's attributes. ### Request Example ```json { "records": [ { "subject_id": "12345", "subject_name": "Mouse_001", "date_of_birth": "2024-01-15", "sex": "M", "weight": 25.5 } ] } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating successful insertion. #### Response Example ```json "Insert successful" ``` #### Error Response (500) - **error** (string) - A message describing the server error during insertion. ``` -------------------------------- ### Fetch Table Records with Filtering - TypeScript Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves paginated records from a table, supporting optional filtering via base64-encoded restriction parameters. This function allows for targeted data retrieval and pagination for large datasets. ```typescript const restrictionsInAPIFormat = [ { attributeName: 'subject_id', operation: '=', value: '12345' }, { attributeName: 'age', operation: '>=', value: '18' } ]; const restrictionParam = encodeURIComponent(btoa(JSON.stringify(restrictionsInAPIFormat))); const apiUrl = `${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table/subject/record?limit=25&page=1&restriction=${restrictionParam}`; fetch(apiUrl, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken }, }) .then(result => { if (!result.ok) throw Error(`${result.status} - ${result.statusText}`); return result.text(); }) .then(result => JSON.parse(result.replace(/(NaN|-?Infinity)/g, '"***$1***"'), reviver)) .then(result => { // result.records: array of tuples // result.totalCount: total number of matching records console.log('Records:', result.records); console.log('Total count:', result.totalCount); console.log('Max pages:', Math.ceil(result.totalCount / 25)); }) .catch(error => console.error('Problem fetching table content:', error)) ``` -------------------------------- ### Fetch Table Attributes - TypeScript Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Retrieves metadata for table columns, including data types, primary/secondary attribute status, nullability, default values, and constraints. This information is crucial for understanding table structure and for building dynamic forms. ```typescript fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table/subject/attribute`, { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken }, }) .then(result => { if (!result.ok) { result.text().then(errorMessage => { throw Error(`${result.status} - ${result.statusText}: (${errorMessage})`) }) } return result.json() }) .then(result => { // result.attributes.primary: array of primary key attributes // result.attributes.secondary: array of non-primary attributes // Each attribute: [name, type, nullable, defaultValue, autoIncrement] console.log('Primary keys:', result.attributes.primary); console.log('Secondary attributes:', result.attributes.secondary); }) .catch(error => { console.error('Problem fetching table attributes:', error); }) ``` -------------------------------- ### DELETE /schema/{schema}/table/{table}/record Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Deletes a record from a DataJoint table based on its primary key. The deletion is performed using base64-encoded restrictions and will fail if the record has child dependencies. ```APIDOC ## DELETE /schema/{schema}/table/{table}/record ### Description Deletes a tuple identified by primary key values using base64-encoded restrictions. Fails if the record has child dependencies. ### Method DELETE ### Endpoint /schema/{schema}/table/{table}/record ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema containing the table. - **table** (string) - Required - The name of the table to delete the record from. #### Query Parameters - **restriction** (string) - Required - A base64-encoded JSON string representing the primary key(s) of the record to delete. ### Request Example ``` DELETE /schema/experiment_schema/table/subject/record?restriction=eyJhdHRyaWJ1dGVOYW1lIjoiIHN1YmplY3RfaWQiLCAib3BlcmF0aW9uIjoiPSIsICJ2YWx1ZSI6IjEyMzQ1In1d ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating successful deletion. #### Response Example ```json "Delete successful" ``` #### Error Response (500, 409) - **error** (string) - A message describing the server error or conflict during deletion. ``` -------------------------------- ### Compare Sets for Equality - isEqualSet (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt A utility function to determine if two JavaScript Set objects are equal. Equality is defined as having the same number of elements and containing the exact same elements. This is useful for detecting changes in sets of configurations or restrictions. ```typescript // Utils.tsx - Comparing restriction sets function isEqualSet(a: Set, b: Set): boolean { if (a.size !== b.size) { return false; } for (let element of a) { if (!b.has(element)) { return false; } } return true; } // Usage example const previousRestrictions = new Set([ {attributeName: 'age', operation: '>=', value: '18'} ]); const currentRestrictions = new Set([ {attributeName: 'age', operation: '>=', value: '21'} ]); if (!isEqualSet(previousRestrictions, currentRestrictions)) { // Restrictions changed, refetch table content fetchTableContent(); } ``` -------------------------------- ### Custom JSON Reviver for Special Numbers (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt A custom reviver function for JSON.parse that correctly parses special numeric values like NaN, Infinity, and -Infinity, which are often represented as strings in API responses. It converts specific string patterns back into their corresponding JavaScript numeric types. ```typescript // Utils.tsx - Parsing API responses with special numeric values function reviver(key: any, value: string) { if (value === '***NaN***') { return NaN; } if (value === '***Infinity***') { return Infinity; } if (value === '***-Infinity***') { return -Infinity; } return value; } // Usage when parsing API responses fetch(apiUrl, {method: 'GET', headers: {...}}) .then(result => result.text()) .then(result => { // Replace special values before parsing const data = JSON.parse( result.replace(/(NaN|-?Infinity)/g, '"***$1***"'), reviver ); // data now contains proper numeric values console.log(data.records); }) ``` -------------------------------- ### PATCH /schema/{schema}/table/{table}/record Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Updates an existing record in a DataJoint table. Only non-primary key attributes can be modified. The request body specifies the record to update by its primary keys and includes the fields to be changed. ```APIDOC ## PATCH /schema/{schema}/table/{table}/record ### Description Updates an existing tuple with new values for non-primary key attributes. ### Method PATCH ### Endpoint /schema/{schema}/table/{table}/record ### Parameters #### Path Parameters - **schema** (string) - Required - The name of the schema containing the table. - **table** (string) - Required - The name of the table to update. #### Request Body - **records** (array) - Required - An array containing the record object to update. - The record object must include primary key fields to identify the tuple. - Include the fields to be updated with their new values. ### Request Example ```json { "records": [ { "subject_id": "12345", "weight": 26.2, "notes": "Updated weight measurement" } ] } ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating successful update. #### Response Example ```json "Update successful" ``` #### Error Response (500) - **error** (string) - A message describing the server error during update. ``` -------------------------------- ### Update Record - PATCH /schema/{schema}/table/{table}/record (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Updates an existing record in a DataJoint table by providing new values for non-primary key attributes. The record to be updated is identified by its primary keys. Requires authentication via JWT token. ```typescript const tupleBuffer = { // Primary keys (identify the record) subject_id: '12345', // Updated fields weight: 26.2, notes: 'Updated weight measurement' }; fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table/subject/record`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken }, body: JSON.stringify({records: [tupleBuffer]}) }) .then(result => { if (result.status === 500) { result.text().then(errorMessage => { throw new Error(errorMessage) }) } return result.text(); }) .then(result => { console.log('Update successful'); // Refresh table content to show updated values }) .catch((error) => { console.error('Update failed:', error.message); }) ``` -------------------------------- ### Delete Record - DELETE /schema/{schema}/table/{table}/record (TypeScript) Source: https://context7.com/datajoint/datajoint-labbook/llms.txt Deletes a record from a DataJoint table using its primary key values. The primary keys are encoded in a base64 format within the restriction query parameter. This operation will fail if the record has dependent child records. ```typescript const tupleToDelete = { subject_id: '12345' }; // Convert primary keys to restrictions var restrictionsInAPIFormat = []; for (const [key, value] of Object.entries(tupleToDelete)) { restrictionsInAPIFormat.push({ attributeName: key, operation: '=', value: String(value) }) } const restrictionParam = encodeURIComponent(btoa(JSON.stringify(restrictionsInAPIFormat))); fetch(`${process.env.REACT_APP_DJLABBOOK_BACKEND_PREFIX}/schema/experiment_schema/table/subject/record?restriction=${restrictionParam}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtToken } }) .then(result => { if (result.status === 500 || result.status === 409) { result.text().then(errorMessage => { throw Error(`${result.status} - ${result.statusText}: (${errorMessage})`) }) } return result.text() }) .then(result => { console.log('Delete successful:', result); // Refresh table content to reflect deletion }) .catch(error => { console.error('Delete failed:', error.message); }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.