> For the complete documentation index, see [llms.txt](https://krypt0nn.gitbook.io/empathize/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krypt0nn.gitbook.io/empathize/api/os-api/ipc.md).

# IPC

## IPCRecord object

| Property | Type   | Description                                 |
| -------- | ------ | ------------------------------------------- |
| id       | number | randomly generated id of record             |
| time     | number | timestamp (in ms) when this record was made |
| data     | any    | content of this record                      |

### record.pop()

Remove record from the storage

```typescript
import { IPC } from '@empathize/framework';

IPC.read().then((records) => {
    records.forEach((record) => {
        if (record.data == 'test-data')
            record.pop(); // Otherwise this record will remain in IPC.read() output
    });
});
```

### record.get()

Get object of record values

```typescript
import { IPC } from '@empathize/framework';

IPC.read().then((records) => {
    records.forEach((record) => {
        if (record.data == 'test-data')
        {
            // record.pop() method returns this record after its deletion
            // and we can call its .get() method after that
            const recordData = record.pop().get();
            
            // It will output { id: '...', time: '...', data: '...' }
            console.log(recordData);
        }
    });
});
```

## IPC class

### IPC.file

File where ipc records should be stored

### IPC.read()

Get IPC records

```typescript
import { IPC } from '@empathize/framework';

IPC.read().then((records) => {
    for (const record of records)
        console.log(record.data);
});
```

### IPC.write(data)

Create record

```typescript
import { IPC } from '@empathize/framework';

// It can be string, ..
IPC.write('test-record');

// ..object or something else
IPC.write({
    example_field: 'example_value'
});
```

### IPC.remove(record)

Remove record

```typescript
import { IPC } from '@empathize/framework';

IPC.write('test-record').then((record) => {
    // Remove this record after 3 seconds
    setTimeout(() => {
        // Can be IPCRecord object or record id
        IPC.remove(record);
    }, 3000);
});
```

### IPC.purge()

Remove all records

```typescript
import { IPC, promisify } from '@empathize/framework';

promisify(async () => {
    // Add 10 records
    for (let i = 0; i < 10; ++i)
        await IPC.write('test');
    
    // Records amount: 10
    console.log(`Records amount: ${(await IPC.read()).length}`);
    
    // Remove all records
    await IPC.purge();
    
    // Records amount: 0
    console.log(`Records amount: ${(await IPC.read()).length}`);
});
```
