this.me 2.9.4 → 2.9.5

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.
@@ -0,0 +1,79 @@
1
+ // Attributes methods
2
+ /**
3
+ * @module Attributes
4
+ * @description Methods to manage attributes for the `Me` class, with key-vaue pairs.
5
+ */
6
+ /**
7
+ * @description Adds or updates an attribute for the `me` instance.
8
+ *
9
+ * This method allows you to dynamically add or update descriptive attributes
10
+ * for the `me` instance. Attributes are stored as key-value pairs, where:
11
+ * - The **key** represents the name of the attribute (e.g., "name", "age", "location").
12
+ * - The **value** represents the data associated with that attribute (e.g., "Sui Gn", 30, "Earth").
13
+ *
14
+ * You can add as many key-value pairs as you want, giving you the flexibility to describe
15
+ * the `me` instance with plain data. The attributes are stored in an object, and each call
16
+ * to `be` either adds a new attribute or updates an existing one if the key already exists.
17
+ *
18
+ * This approach ensures that the `me` instance can evolve and be customized over time
19
+ * with additional or modified attributes as needed.
20
+ *
21
+ * @param {string} key - The attribute key (e.g., "name").
22
+ * @param {string|number|boolean|Object} value - The attribute value associated with the key.
23
+ * This can be any data type (e.g., string, number, boolean, or even a nested object).
24
+ *
25
+ * @example
26
+ * // Adding a single attribute
27
+ * me.be("name", "Sui Gn");
28
+ * console.log(me.getAttributes()); // { name: "Sui Gn" }
29
+ *
30
+ * // Adding multiple attributes
31
+ * me.be("age", 30);
32
+ * me.be("location", "Earth");
33
+ * console.log(me.getAttributes());
34
+ * // Output: { name: "Sui Gn", age: 30, location: "Earth" }
35
+ *
36
+ * // Updating an existing attribute
37
+ * me.be("name", "John Doe");
38
+ * console.log(me.getAttributes());
39
+ * // Output: { name: "John Doe", age: 30, location: "Earth" }
40
+ *
41
+ * // Using complex data types
42
+ * me.be("preferences", { theme: "dark", language: "en" });
43
+ * console.log(me.getAttributes());
44
+ * // Output: { name: "John Doe", age: 30, location: "Earth", preferences: { theme: "dark", language: "en" } }
45
+ */
46
+ export function be(attributes, key, value) {
47
+ if (!key || typeof key !== 'string') {
48
+ throw new Error('Invalid key for attribute');
49
+ }
50
+ attributes[key] = value;
51
+ }
52
+ /**
53
+ * @description Retrieves all attributes associated with the `me` instance.
54
+ *
55
+ * This method provides access to the current set of attributes stored in the `me` instance
56
+ * as an object containing key-value pairs. Each key represents the name of an attribute,
57
+ * and its corresponding value represents the data stored for that attribute.
58
+ *
59
+ * You can either:
60
+ * - Retrieve all attributes at once as a single object.
61
+ * - Access specific attributes directly using their keys.
62
+ *
63
+ * @returns {Object} An object containing all the key-value pairs representing
64
+ * the attributes of the `me` instance.
65
+ *
66
+ * @example
67
+ * // Retrieving all attributes
68
+ * console.log(me.getAttributes());
69
+ * // Output: { name: "Sui Gn", age: 30, location: "Earth" }
70
+ *
71
+ * // Accessing specific attributes by their key
72
+ * const attributes = me.getAttributes();
73
+ * console.log(attributes.name); // "Sui Gn"
74
+ * console.log(attributes.age); // 30
75
+ * console.log(attributes.location); // "Earth"
76
+ */
77
+ export function getAttributes(attributes) {
78
+ return attributes;
79
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @module Identity
3
+ * @description Methods to manage identity for the `Me` class.
4
+ */
5
+
6
+ /**
7
+ * Sets up the identity for a `Me` instance.
8
+ * @function
9
+ * @param {string} username - The username to set for the identity.
10
+ * @returns {Object} The identity object containing the username.
11
+ *
12
+ * @example
13
+ * const identity = setup("suiGn");
14
+ * console.log(identity); // { username: "suiGn" }
15
+ */
16
+ export function setup(username) {
17
+ return { username };
18
+ }
19
+
20
+ /**
21
+ * Retrieves the username (identity) of the `Me` instance.
22
+ * @function
23
+ * @param {Object} identity - The identity object of the `Me` instance.
24
+ * @returns {Object} The `Me` username identity object.
25
+ *
26
+ * @example
27
+ * console.log(getMe({ username: "suiGn" })); // { username: "suiGn" }
28
+ */
29
+ export function getMe(identity) {
30
+ return identity;
31
+ }
@@ -0,0 +1,73 @@
1
+ // this.me/src/methods/properties.js
2
+ /**
3
+ * @module Properties
4
+ * @description Methods to manage properties for the `Me` class.
5
+ */
6
+
7
+ /**
8
+ * Validates a property before adding it.
9
+ * @function
10
+ * @param {Object} property - The property to validate.
11
+ * @throws {Error} If the property is invalid.
12
+ */
13
+ function validateProperty(property) {
14
+ if (!property || typeof property !== 'object') {
15
+ throw new Error('Invalid property: Must be a non-null object.');
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Adds a property to the identity.
21
+ * @function
22
+ * @param {Array} properties - The properties array to update.
23
+ * @param {Object} property - The property to add (e.g., { type: "ETH", address: "0x123..." }).
24
+ */
25
+ function addProperty(properties, property) {
26
+ validateProperty(property);
27
+ properties.push(property);
28
+ }
29
+
30
+ /**
31
+ * Retrieves all properties for the identity.
32
+ * @function
33
+ * @param {Array} properties - The properties array to retrieve from.
34
+ * @returns {Array} The properties array.
35
+ */
36
+ function getProperties(properties) {
37
+ return [...properties]; // Return a shallow copy to prevent mutation outside
38
+ }
39
+
40
+ /**
41
+ * Removes a property from the identity.
42
+ * @function
43
+ * @param {Array} properties - The properties array to update.
44
+ * @param {Object} property - The property to remove.
45
+ */
46
+ function removeProperty(properties, property) {
47
+ validateProperty(property);
48
+ const index = properties.findIndex(p => JSON.stringify(p) === JSON.stringify(property));
49
+ if (index !== -1) properties.splice(index, 1);
50
+ }
51
+
52
+ /**
53
+ * Checks if a specific property exists.
54
+ * @function
55
+ * @param {Array} properties - The properties array.
56
+ * @param {Object} property - The property to check.
57
+ * @returns {boolean} True if the property exists, otherwise false.
58
+ */
59
+ function hasProperty(properties, property) {
60
+ validateProperty(property);
61
+ return properties.some(p => JSON.stringify(p) === JSON.stringify(property));
62
+ }
63
+
64
+ // Named exports
65
+ export { addProperty, getProperties, removeProperty, hasProperty };
66
+
67
+ // Default export (optional for easier import as an object)
68
+ export default {
69
+ addProperty,
70
+ getProperties,
71
+ removeProperty,
72
+ hasProperty
73
+ };
@@ -0,0 +1,31 @@
1
+ //this.me/src/methods/reactions.js
2
+ /**
3
+ * @module Reactions
4
+ * @description Methods to manage reactions for the `Me` class.
5
+ */
6
+ /**
7
+ * Add a reaction to a target.
8
+ * @function
9
+ * @param {Array} reactions - The reactions array to update.
10
+ * @param {string} type - The type of reaction (e.g., "like", "comment").
11
+ * @param {string} target - The target of the reaction (e.g., "PostID").
12
+ * @param {string} [content=null] - Additional content for the reaction (e.g., a comment).
13
+ * @throws {Error} If the type or target is invalid.
14
+ */
15
+ export function react(reactions, type, target, content = null) {
16
+ if (!type || !target) {
17
+ throw new Error('Invalid reaction parameters');
18
+ }
19
+ reactions.push({ type, target, content, timestamp: new Date() });
20
+ }
21
+
22
+ /**
23
+ * Retrieve all reactions for the identity.
24
+ * @function
25
+ * @param {Array} reactions - The reactions array to retrieve from.
26
+ * @returns {Array} The reactions array.
27
+ * @instance
28
+ */
29
+ export function getReactions(reactions) {
30
+ return reactions;
31
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module Relationships
3
+ * @description Manages user relationships.
4
+ */
5
+
6
+ // Function to add a relationship
7
+ export function addRelationship(relationships, relationship) {
8
+ if (!relationship || !relationship.type || !relationship.username) {
9
+ throw new Error('Invalid relationship object. Must include type and username.');
10
+ }
11
+
12
+ relationships.push(relationship);
13
+ }
14
+
15
+ // Function to retrieve relationships
16
+ export function getRelationships(relationships, type = null) {
17
+ if (type) {
18
+ return relationships.filter(rel => rel.type === type);
19
+ }
20
+ return relationships;
21
+ }
22
+
23
+ // Function to initialize relationships for a user
24
+ export function createRelationships() {
25
+ return [];
26
+ }
@@ -0,0 +1,19 @@
1
+ // setup.js
2
+ import { mkdirSync, existsSync } from 'fs';
3
+ import { homedir } from 'os';
4
+ import path from 'path';
5
+ const root = path.join(homedir(), '.this');
6
+ const mePath = path.join(root, 'me');
7
+ if (!existsSync(root)) {
8
+ mkdirSync(root);
9
+ console.log('✅ Created ~/.this root directory');
10
+ } else {
11
+ console.log('✅ ~/.this root directory already exists');
12
+ }
13
+
14
+ if (!existsSync(mePath)) {
15
+ mkdirSync(mePath);
16
+ console.log('✅ Created ~/.this/me directory');
17
+ } else {
18
+ console.log('✅ ~/.this/me directory already exists');
19
+ }
@@ -0,0 +1,31 @@
1
+ import { existsSync, mkdirSync } from 'fs';
2
+ import { homedir } from 'os';
3
+ import path from 'path';
4
+
5
+ const root = path.join(homedir(), '.this');
6
+ const mePath = path.join(root, 'me');
7
+
8
+ export function validateSetup() {
9
+ let updated = false;
10
+
11
+ if (!existsSync(root)) {
12
+ mkdirSync(root);
13
+ console.log('✅ Created ~/.this root directory');
14
+ updated = true;
15
+ }
16
+
17
+ if (!existsSync(mePath)) {
18
+ mkdirSync(mePath);
19
+ console.log('✅ Created ~/.this/me directory');
20
+ updated = true;
21
+ }
22
+
23
+ if (!updated) {
24
+ console.log('.me >> init.');
25
+ }
26
+ }
27
+
28
+ // Run directly if script is executed as entry point
29
+ if (import.meta.url === `file://${process.argv[1]}`) {
30
+ validateSetup();
31
+ }
package/src/.me.cli.js DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- //.me.cli.js
3
- import { program } from 'commander';
4
- import { meMainChoices } from './CLI/me_MainChoices.js';
5
- import AddMe from './CLI/AddMe.js';
6
- import LogMe from './CLI/LogMe.js';
7
- program
8
- .description('.Me Command Line Interface')
9
- .version('1.0.0')
10
- .action(meMainChoices);
11
-
12
- program.command('add-me')
13
- .description('+ Add .me')
14
- .action(AddMe);
15
-
16
- program.command('log-me')
17
- .description('Log .me')
18
- .action(LogMe);
19
-
20
- program.parse(process.argv);