this.me 2.9.4 → 2.9.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +17 -58
- package/index.js +0 -2
- package/md/Index.md +134 -0
- package/md/{context.md → Inmutabilidad_de_la_Identidad_basica.md} +4 -2
- package/md/Questions.md +62 -0
- package/md/hot_encoding.md +44 -0
- package/package.json +1 -1
- package/src/example.js +1 -1
- package/src/me.js +33 -35
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
<img src="https://
|
|
1
|
+
<img src="https://docs.neurons.me/media/all-this/webP/this.me.webp" alt="SVG Image" width="250" height="250">
|
|
2
2
|
|
|
3
3
|
# THIS.ME
|
|
4
|
-
**This.Me** is a data-structured identity.
|
|
5
|
-
<img src="https://suign.github.io/assets/imgs/point.png" alt="Me" width="144"> Consider **.me** as a point.
|
|
4
|
+
> **This.Me** is a data-structured identity designed to generate and manage identities, attributes, properties and more.
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
# Getting Started:
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
1. ### **Install `this.me`:**
|
|
8
|
+
1. ##### **Install `this.me`:**
|
|
12
9
|
Open your terminal and run the following command to install the `this.me` package:
|
|
13
10
|
```js
|
|
14
11
|
npm install this.me
|
|
15
12
|
```
|
|
16
13
|
|
|
17
|
-
2.
|
|
14
|
+
2. ##### **Import `Me` in Your Project:**
|
|
18
15
|
In the JavaScript file where you want to use `this.me`, import the `Me` class.
|
|
19
16
|
```js
|
|
20
17
|
import Me from 'this.me';
|
|
@@ -41,21 +38,15 @@ me.be({ name: "Alice", phone: "33550000" });
|
|
|
41
38
|
```
|
|
42
39
|
|
|
43
40
|
**1. Registry as a Service:**
|
|
44
|
-
|
|
45
41
|
• The registry becomes a centralized service hosted by an authority (e.g., neurons.me).
|
|
46
|
-
|
|
47
42
|
• This service would handle the verification and management of all Me instances across the network.
|
|
48
43
|
|
|
49
44
|
**Example Flow:**
|
|
50
|
-
|
|
51
45
|
1. **Setup**: A developer installs this.me and configures it to connect to neurons.me.
|
|
52
|
-
|
|
53
46
|
2. **User Registration**: Users register their Me identity through the service, and the library connects to the neurons.me registry for verification.
|
|
54
|
-
|
|
55
47
|
3. **Service Interaction**: When a user interacts with a service that uses this.me, the service can trust the identity by querying the selected registry.
|
|
56
48
|
|
|
57
49
|
**Implementation:**
|
|
58
|
-
|
|
59
50
|
```js
|
|
60
51
|
import Me from 'this.me';
|
|
61
52
|
const config = {
|
|
@@ -66,67 +57,35 @@ me.register({ password: 'securePass123', email: 'alice@example.com' });
|
|
|
66
57
|
// Verify and interact with services using the connected registry
|
|
67
58
|
```
|
|
68
59
|
|
|
69
|
-
|
|
70
|
-
|
|
71
60
|
--------
|
|
72
61
|
<img src="https://suign.github.io/assets/imgs/monads.png" alt="Cleak Me Please" width="244">Hello, I am **.me**
|
|
73
|
-
|
|
74
62
|
### ❯ add.me
|
|
75
63
|
----
|
|
76
64
|
|
|
77
65
|
###### Using the CLI and this.me globally to manage user sessions.
|
|
78
|
-
|
|
79
66
|
```bash
|
|
80
67
|
npm i -g this.me
|
|
81
68
|
```
|
|
69
|
+
----------
|
|
82
70
|
|
|
71
|
+
# What is All.This?
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
--------
|
|
86
|
-
To represent the combinations of **“me, you, him, her, it, us, them”** in a neural network, we need to convert the elements into a suitable format for neural network processing, such as one-hot encoding, and design a neural network architecture that can process these inputs.
|
|
73
|
+
###### Modular Data Structures:
|
|
87
74
|
|
|
88
|
-
|
|
89
|
-
1. **One-Hot Encoding:** Convert each element (“me”, “you”, “him”, “her”, “it”, “us”, “them”) into a one-hot encoded vector.
|
|
90
|
-
2. **Combination Representation:** Create input vectors for each combination by combining the one-hot encoded vectors.
|
|
91
|
-
3. **Neural Network Design:** Design a simple neural network to process these input vectors.
|
|
75
|
+
**Each module** in **[all.this](https://neurons.me/all-this)** represents a specific **datastructure**. These **classes** encapsulate the functionalities and **data specific to their domain.**
|
|
92
76
|
|
|
93
|
-
|
|
94
|
-
One-hot encoding represents each element as a binary vector with a single high (1) value and the rest low (0). For the elements “me”, “you”, “him”, “her”, “it”, “us”, “them”, we can assign the following one-hot encoded vectors:
|
|
77
|
+
**[this.me](https://docs.neurons.me/this.me/index.html) - [this.audio](https://docs.neurons.me/this.audio/index.html) - [this.text](https://docs.neurons.me/this.text/index.html) - [this.wallet](https://docs.neurons.me/this.wallet/index.html) - [this.img](https://docs.neurons.me/this.img/index.html) - [this.pixel](https://docs.neurons.me/this.pixel/index.html) - [be.this](https://docs.neurons.me/be.this/index.html) - [this.DOM](https://docs.neurons.me/this.DOM/index.html) - [this.env](https://docs.neurons.me/this.env/index.html) - [this.GUI](https://docs.neurons.me/this.GUI/index.html) - [this.be](https://docs.neurons.me/this.be/index.html) - [this.video](https://docs.neurons.me/this.video/index.html) - [this.dictionaries](https://docs.neurons.me/this.dictionaries/index.html)**
|
|
95
78
|
|
|
96
|
-
|
|
97
|
-
// Create Me instances
|
|
98
|
-
const meInstance = new Me('me');
|
|
99
|
-
const youInstance = new Me('you');
|
|
100
|
-
const himInstance = new Me('him');
|
|
101
|
-
const herInstance = new Me('her');
|
|
102
|
-
const itInstance = new Me('it');
|
|
103
|
-
const usInstance = new Me('us');
|
|
104
|
-
const themInstance = new Me('them');
|
|
105
|
-
|
|
106
|
-
// One-hot encoding representation
|
|
107
|
-
const subjects = {
|
|
108
|
-
'me': [1, 0, 0, 0, 0, 0, 0],
|
|
109
|
-
'you': [0, 1, 0, 0, 0, 0, 0],
|
|
110
|
-
'him': [0, 0, 1, 0, 0, 0, 0],
|
|
111
|
-
'her': [0, 0, 0, 1, 0, 0, 0],
|
|
112
|
-
'it': [0, 0, 0, 0, 1, 0, 0],
|
|
113
|
-
'us': [0, 0, 0, 0, 0, 1, 0],
|
|
114
|
-
'them': [0, 0, 0, 0, 0, 0, 1]
|
|
115
|
-
};
|
|
116
|
-
```
|
|
79
|
+
#### Contribution
|
|
117
80
|
|
|
118
|
-
|
|
119
|
-
For each combination, we can create an input vector by combining the one-hot encoded vectors of its elements. For example:
|
|
120
|
-
Combination “me, you” would be represented as the sum of the one-hot vectors for “me” and “you”:
|
|
81
|
+
If you are interested in collaborating or wish to share your insights, please feel free to reach out or contribute to the project.
|
|
121
82
|
|
|
122
|
-
|
|
123
|
-
[1, 0, 0, 0, 0, 0, 0] + [0, 1, 0, 0, 0, 0, 0] = [1, 1, 0, 0, 0, 0, 0]
|
|
124
|
-
```
|
|
125
|
-
---
|
|
126
|
-
### Me Deviation Formula
|
|
127
|
-
**How Spread Out the data Points are around the .me?**
|
|
83
|
+
#### License & Policies
|
|
128
84
|
|
|
85
|
+
- **License**: MIT License (see LICENSE for details).
|
|
129
86
|
|
|
130
|
-
|
|
87
|
+
- **Learn more** at **https://docs.neurons.me**
|
|
131
88
|
|
|
89
|
+
[Terms](https://docs.neurons.me/terms-and-conditions) | [Privacy](https://docs.neurons.me/privacy-policy)
|
|
132
90
|
|
|
91
|
+
<img src="https://docs.neurons.me/neurons.me.webp" alt="neurons.me logo" width="123" height="123">
|
package/index.js
CHANGED
package/md/Index.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
### **Index of `this.me` Structure**
|
|
2
|
+
Here’s a comprehensive list of the components and their purposes within the `this.me` class:
|
|
3
|
+
|
|
4
|
+
#### **1. Identity**
|
|
5
|
+
- **Description:** Immutable attributes defining the core identity of the user.
|
|
6
|
+
#### **2. Attributes**
|
|
7
|
+
- **Description:** Flexible traits and descriptive properties of the user.
|
|
8
|
+
#### **3. Relationships**
|
|
9
|
+
- **Description:** Connections and associations with others.
|
|
10
|
+
#### **4. Reactions**
|
|
11
|
+
- **Description:** User’s interactions and engagements with the world.
|
|
12
|
+
#### **5. Properties**
|
|
13
|
+
- **Description:** Items owned or managed by the user.
|
|
14
|
+
|
|
15
|
+
------
|
|
16
|
+
|
|
17
|
+
### **1. The Me Structure Overview**
|
|
18
|
+
#### **Core Components**
|
|
19
|
+
- **Identity:** The foundation of the `this.me` object.
|
|
20
|
+
- Immutable attributes: `username`, `DID`.
|
|
21
|
+
- Core methods for validation and setup.
|
|
22
|
+
|
|
23
|
+
------
|
|
24
|
+
|
|
25
|
+
- **Attributes:** Fundamental identity traits.
|
|
26
|
+
Store and manage user traits dynamically:
|
|
27
|
+
- Examples: Name, age, location, pronouns, bio.
|
|
28
|
+
**Use `.be()` to add or update attributes.**
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
```json
|
|
32
|
+
{ name: 'John Doe', age: 30, location: 'Earth' }
|
|
33
|
+
```
|
|
34
|
+
Implement `be()` as a flexible key-value store.
|
|
35
|
+
Add validation for specific attributes (if required).
|
|
36
|
+
|
|
37
|
+
------
|
|
38
|
+
|
|
39
|
+
- **Relationships:** Connections with others.
|
|
40
|
+
- Examples: Friends, groups, networks, organizations.
|
|
41
|
+
**Contacts:** Individual connections.
|
|
42
|
+
**Groups:** Collections of users with shared context.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
.relationships.addContact({ username: 'alice', status: 'friend' });
|
|
46
|
+
.relationships.createGroup({ name: 'Family', members: ['alice', 'bob'] });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Define `addContact` and `createGroup` methods.
|
|
50
|
+
Enable nested relationship structures (e.g., groups of groups).
|
|
51
|
+
|
|
52
|
+
------
|
|
53
|
+
|
|
54
|
+
- **Reactions:** How a user interacts with the world.
|
|
55
|
+
Streamline all user engagements under `.react()`
|
|
56
|
+
- Examples: Likes, comments, shares, emotions.
|
|
57
|
+
- Categorization Rationale:
|
|
58
|
+
- Keeps all engagements unified.
|
|
59
|
+
- Expands easily (adding emojis, advanced reactions).
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
.react.add({ type: 'like', target: 'PostID' });
|
|
63
|
+
.react.add({ type: 'comment', target: 'PhotoID', content: 'Great pic!' });
|
|
64
|
+
```
|
|
65
|
+
Design a structure to store and retrieve reactions efficiently.
|
|
66
|
+
Define a `log` system for reaction history.
|
|
67
|
+
|
|
68
|
+
------
|
|
69
|
+
|
|
70
|
+
- **Properties:** Things the user owns or manages.
|
|
71
|
+
Attach external, modular objects as user-owned assets:
|
|
72
|
+
- Use `this.me.properties` as a unified interface for ownership.
|
|
73
|
+
- Modular objects like `Wallet`, `Device`, `File`.
|
|
74
|
+
- Examples: Wallets, devices, digital files, accounts.
|
|
75
|
+
- **Sub-Methods:** Add, Share, Transfer Ownership, Revoke Access.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const jabellae = new Me('jabellae'); // Create a new Me instance
|
|
79
|
+
const wallet = new Wallet({ type: 'ETH', address: '0x123...' }); // Create a wallet object
|
|
80
|
+
jabellae.addProperty(wallet); // Add wallet as a property to Me
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Implement `add`, `share`, `transferOwnership`, and `revokeAccess` methods for properties. Define modular objects (`Wallet`, `Device`) independently.
|
|
84
|
+
|
|
85
|
+
1. **Creating a Wallet**
|
|
86
|
+
The wallet is created independently and then added to the `Me` instance's properties.
|
|
87
|
+
```javascript
|
|
88
|
+
const jabellae = new Me('jabellae'); // Create a new Me instance
|
|
89
|
+
const wallet = new Wallet({ type: 'ETH', address: '0x123...' }); // Create a wallet object
|
|
90
|
+
jabellae.addProperty(wallet); // Add wallet as a property to Me
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
2. **Sharing the Wallet**
|
|
94
|
+
Sharing logic is handled by the `Me` instance, not the property itself.
|
|
95
|
+
```javascript
|
|
96
|
+
jabellae.shareProperty(wallet, 'otherMe', { permissions: 'view' });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
3. **Transferring Ownership**
|
|
100
|
+
Ownership transfer is also managed by the `Me` instance.
|
|
101
|
+
```javascript
|
|
102
|
+
jabellae.transferOwnership(wallet, 'otherMe');
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
------
|
|
106
|
+
------
|
|
107
|
+
------
|
|
108
|
+
|
|
109
|
+
### **2. Why Independent Objects?**
|
|
110
|
+
#### **Modularity**
|
|
111
|
+
- Keeps the `this.me` instance *agnostic* of specifics.
|
|
112
|
+
- Allows new property types to integrate seamlessly.
|
|
113
|
+
|
|
114
|
+
#### **Reusability**
|
|
115
|
+
- Each property (e.g., `this.wallet`, `this.device`) operates independently.
|
|
116
|
+
- Can be ported across `this.me` instances without coupling.
|
|
117
|
+
|
|
118
|
+
#### **Transferability**
|
|
119
|
+
- Ownership is a property-level concern.
|
|
120
|
+
- Example:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
const wallet = new Wallet(owner = "me");
|
|
124
|
+
wallet.transferOwnership("otherMeInstance");
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### **Separation of Concerns**
|
|
128
|
+
- Identity (`this.me`) manages relationships, attributes, and higher-level user interactions.
|
|
129
|
+
- Objects like `Wallet` or `Device` manage their specific functionality.
|
|
130
|
+
|
|
131
|
+
#### **Scalability**
|
|
132
|
+
- Adding a new property type is as simple as:
|
|
133
|
+
1. Defining the object (e.g., `Vehicle`).
|
|
134
|
+
2. Registering it with `this.me`.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
El mayor acto de rebelión en un mundo que busca controlarte es ser libre de verdad.
|
|
2
|
+
|
|
3
|
+
**this.me** y el proceso de autenticación con **Cleaker** como una red de identificación descentralizada (**DID**) tiene sentido dentro de un marco de criptografía y autenticación distribuida. A continuación, desgloso los puntos importantes para asegurarnos de que el concepto sea claro y funcional:
|
|
2
4
|
|
|
3
5
|
### **Inmutabilidad de la Identidad Básica**
|
|
4
|
-
|
|
6
|
+
**this.me** se basa en la creación de una identidad. Los componentes inmutables que mencionas (nombre de usuario, email y la red de autenticación) son fundamentales para que el sistema garantice que la identidad siempre se pueda verificar a partir de un hash único.
|
|
5
7
|
|
|
6
8
|
1. **Nombre de Usuario (username)**: El nombre de usuario es clave en la identidad. No puede cambiar una vez creado porque el hash que lo representa depende de esta cadena de caracteres.
|
|
7
9
|
2. **Correo Electrónico (email)**: Esto actúa como otra pieza inmutable, probablemente porque es un dato importante para autenticar usuarios a través de redes o servicios.
|
package/md/Questions.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Key Questions to Address
|
|
2
|
+
Identity Core: What defines the essence of .me?
|
|
3
|
+
Relationships: How does .me relate to others, groups, or larger entities?
|
|
4
|
+
Belongings: What does .me own or have as personal items?
|
|
5
|
+
Modularity: How do we allow external objects to seamlessly integrate with .me?
|
|
6
|
+
Hierarchy of Interactions: How do we classify interactions into tiers (self, relationships, society, etc.)?
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
### **1. Identity Core: What defines the essence of `.me`?**
|
|
10
|
+
- **Essence Defined:**
|
|
11
|
+
- **Immutable Core Attributes:** `username` and `DID` (Decentralized Identifier).
|
|
12
|
+
- Clearly distinguishes the user's unique existence in the digital realm.
|
|
13
|
+
- **Practical Implementation:**
|
|
14
|
+
- Identity core is foundational and unchangeable, ensuring trust and consistency across systems.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
### **2. Relationships: How does `.me` relate to others, groups, or larger entities?**
|
|
19
|
+
- **Connections Defined:**
|
|
20
|
+
- **Contacts:** Direct relationships (e.g., friends, acquaintances).
|
|
21
|
+
- **Groups:** Collections with shared contexts (e.g., family, organizations, societies).
|
|
22
|
+
- **Methods:**
|
|
23
|
+
- `.relationships.addContact()` to add individual connections.
|
|
24
|
+
- `.relationships.createGroup()` to organize groups dynamically.
|
|
25
|
+
- **Hierarchy:**
|
|
26
|
+
- Nested structures enable relationships at various tiers (e.g., groups of groups, organizations within societies).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### **3. Belongings: What does `.me` own or have as personal items?**
|
|
31
|
+
- **Properties Defined:**
|
|
32
|
+
- Everything the user owns or manages (e.g., wallets, devices, digital files).
|
|
33
|
+
- **Methods for Ownership:**
|
|
34
|
+
- `.properties.add()`, `.properties.share()`, `.properties.transferOwnership()`, `.properties.revokeAccess()`.
|
|
35
|
+
- **Modular Approach:**
|
|
36
|
+
- Allows external objects like `Wallet`, `Device`, or `Vehicle` to integrate without hardcoding.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### **4. Modularity: How do we allow external objects to seamlessly integrate with `.me`?**
|
|
41
|
+
- **Independent Objects:**
|
|
42
|
+
- Objects like `Wallet`, `Device`, etc., are designed and managed outside the `this.me` instance.
|
|
43
|
+
- **Integration:**
|
|
44
|
+
- These objects are registered to `this.me` via methods like `.addProperty()`.
|
|
45
|
+
- They maintain their internal logic while adhering to the ownership and interaction protocols defined by `.me`.
|
|
46
|
+
- **Advantages:**
|
|
47
|
+
- Scalability: Easy to introduce new objects without modifying the `this.me` core.
|
|
48
|
+
- Transferability: Ownership can move across `.me` instances seamlessly.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### **5. Hierarchy of Interactions: How do we classify interactions into tiers (self, relationships, society, etc.)?**
|
|
53
|
+
- **Tiers of Interactions:**
|
|
54
|
+
- **Reactions:** Personal engagements (`like`, `comment`, `share`).
|
|
55
|
+
- **Relationships:** Broader social connections (individuals, groups, organizations).
|
|
56
|
+
- **Attributes:** How `.me` defines itself (e.g., status, bio, pronouns).
|
|
57
|
+
- **Properties:** Interaction with owned or managed items.
|
|
58
|
+
- **Unified Structure:**
|
|
59
|
+
- Centralized under `.reactions` and `.relationships`.
|
|
60
|
+
- Interaction types remain modular and expandable, allowing for a hierarchy to emerge naturally through usage (e.g., personal to societal interactions).
|
|
61
|
+
|
|
62
|
+
---
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
### Neural Networks - **One-Hot Encoding**
|
|
2
|
+
--------
|
|
3
|
+
To represent the combinations of **“me, you, him, her, it, us, them”** in a neural network, we need to convert the elements into a suitable format for neural network processing, such as one-hot encoding, and design a neural network architecture that can process these inputs.
|
|
4
|
+
|
|
5
|
+
Here’s a step-by-step approach to achieve this:
|
|
6
|
+
1. **One-Hot Encoding:** Convert each element (“me”, “you”, “him”, “her”, “it”, “us”, “them”) into a one-hot encoded vector.
|
|
7
|
+
2. **Combination Representation:** Create input vectors for each combination by combining the one-hot encoded vectors.
|
|
8
|
+
3. **Neural Network Design:** Design a simple neural network to process these input vectors.
|
|
9
|
+
|
|
10
|
+
#### Step 1: One-Hot Encoding
|
|
11
|
+
One-hot encoding represents each element as a binary vector with a single high (1) value and the rest low (0). For the elements “me”, “you”, “him”, “her”, “it”, “us”, “them”, we can assign the following one-hot encoded vectors:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// Create Me instances
|
|
15
|
+
const meInstance = new Me('me');
|
|
16
|
+
const youInstance = new Me('you');
|
|
17
|
+
const himInstance = new Me('him');
|
|
18
|
+
const herInstance = new Me('her');
|
|
19
|
+
const itInstance = new Me('it');
|
|
20
|
+
const usInstance = new Me('us');
|
|
21
|
+
const themInstance = new Me('them');
|
|
22
|
+
|
|
23
|
+
// One-hot encoding representation
|
|
24
|
+
const subjects = {
|
|
25
|
+
'me': [1, 0, 0, 0, 0, 0, 0],
|
|
26
|
+
'you': [0, 1, 0, 0, 0, 0, 0],
|
|
27
|
+
'him': [0, 0, 1, 0, 0, 0, 0],
|
|
28
|
+
'her': [0, 0, 0, 1, 0, 0, 0],
|
|
29
|
+
'it': [0, 0, 0, 0, 1, 0, 0],
|
|
30
|
+
'us': [0, 0, 0, 0, 0, 1, 0],
|
|
31
|
+
'them': [0, 0, 0, 0, 0, 0, 1]
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### Step 2: Combination Representation
|
|
36
|
+
For each combination, we can create an input vector by combining the one-hot encoded vectors of its elements. For example:
|
|
37
|
+
Combination “me, you” would be represented as the sum of the one-hot vectors for “me” and “you”:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
[1, 0, 0, 0, 0, 0, 0] + [0, 1, 0, 0, 0, 0, 0] = [1, 1, 0, 0, 0, 0, 0]
|
|
41
|
+
```
|
|
42
|
+
---
|
|
43
|
+
### Me Deviation Formula
|
|
44
|
+
**How Spread Out the data Points are around the .me?**
|
package/package.json
CHANGED
package/src/example.js
CHANGED
package/src/me.js
CHANGED
|
@@ -1,56 +1,54 @@
|
|
|
1
1
|
//this.me/src/me.js
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Me{
|
|
7
|
-
// Static property to keep track of all users globally
|
|
8
|
-
static registry = {};
|
|
9
|
-
|
|
10
|
-
constructor(username = 'monad') {
|
|
2
|
+
import Registry from './registry';
|
|
3
|
+
class Me {
|
|
4
|
+
static registry = Registry.load();
|
|
5
|
+
constructor(username = 'default') {
|
|
11
6
|
if (Me.registry[username]) {
|
|
12
|
-
throw new Error(`Username ${username} already exists
|
|
7
|
+
throw new Error(`Username ${username} already exists.`);
|
|
13
8
|
}
|
|
14
|
-
|
|
9
|
+
|
|
10
|
+
this.username = username;
|
|
15
11
|
this.identity = {
|
|
16
|
-
username
|
|
17
|
-
|
|
18
|
-
host: this.getHostInfo()
|
|
12
|
+
username,
|
|
13
|
+
devices: [],
|
|
19
14
|
};
|
|
20
|
-
Me.registry[username] = this; // Add to global registry
|
|
21
|
-
}
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return username;
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error('Incorrect username. Only letters and numbers are allowed, and it must be between 1 and 21 characters.');
|
|
29
|
-
}
|
|
16
|
+
this.addDevice(); // Automatically adds the current device
|
|
17
|
+
Me.registry[username] = this.identity;
|
|
18
|
+
Registry.save(Me.registry);
|
|
30
19
|
}
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
static load(username) {
|
|
22
|
+
if (!Me.registry[username]) {
|
|
23
|
+
throw new Error(`Username ${username} does not exist.`);
|
|
24
|
+
}
|
|
25
|
+
return new Me(username, Me.registry[username]);
|
|
34
26
|
}
|
|
35
27
|
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
addDevice(deviceInfo = null) {
|
|
29
|
+
const device = deviceInfo || {
|
|
30
|
+
deviceId: crypto.randomUUID(),
|
|
38
31
|
hostname: os.hostname(),
|
|
39
32
|
platform: os.platform(),
|
|
40
|
-
|
|
33
|
+
isPrimary: this.identity.devices.length === 0,
|
|
41
34
|
};
|
|
35
|
+
|
|
36
|
+
this.identity.devices.push(device);
|
|
37
|
+
Registry.save(Me.registry);
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
removeDevice(deviceId) {
|
|
41
|
+
this.identity.devices = this.identity.devices.filter((d) => d.deviceId !== deviceId);
|
|
42
|
+
Registry.save(Me.registry);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
listDevices() {
|
|
46
|
+
return this.identity.devices;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
// Static method to retrieve all users
|
|
51
49
|
static getAllUsers() {
|
|
52
|
-
return Me.registry;
|
|
50
|
+
return Object.keys(Me.registry);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
export default Me;
|
|
54
|
+
export default Me;
|