mftsccs-node 0.2.7 → 0.2.8
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/README.md +1148 -11
- package/dist/bundle.js +1 -1
- package/dist/types/Api/Create/CreateTheCharacter.d.ts +42 -0
- package/dist/types/Api/Create/CreateTheConceptApi.d.ts +50 -0
- package/dist/types/Api/Create/CreateTheConnectionApi.d.ts +51 -0
- package/dist/types/Api/Create/CreateTheTextData.d.ts +56 -0
- package/dist/types/Api/Delete/DeleteConceptInBackend.d.ts +43 -0
- package/dist/types/Api/DeleteConnectionApiBulk.d.ts +55 -0
- package/dist/types/Api/DeleteTheConcept.d.ts +64 -0
- package/dist/types/Api/DeleteTheConnection.d.ts +76 -0
- package/dist/types/Api/GetAiData.d.ts +36 -0
- package/dist/types/Api/GetAllConcepts.d.ts +42 -0
- package/dist/types/Api/GetAllConceptsByType.d.ts +45 -0
- package/dist/types/Api/GetAllConnections.d.ts +48 -0
- package/dist/types/Api/GetAllConnectionsOfComposition.d.ts +79 -0
- package/dist/types/Api/GetAllConnectionsOfCompositionBulk.d.ts +90 -0
- package/dist/types/Api/GetAllLinkerConnectionsFromTheConcept.d.ts +52 -0
- package/dist/types/Api/GetAllLinkerConnectionsToTheConcept.d.ts +61 -0
- package/dist/types/Api/GetAllPrefetchConnections.d.ts +51 -0
- package/dist/types/Api/GetCharacterDataByCharacter.d.ts +31 -0
- package/dist/types/Api/GetCompositionConnectionsBetweenTwoConcepts.d.ts +39 -0
- package/dist/types/Api/GetConcept.d.ts +47 -0
- package/dist/types/Api/GetConceptBulk.d.ts +68 -0
- package/dist/types/Api/GetConceptByCharacterAndType.d.ts +75 -0
- package/dist/types/Api/GetConceptByCharacterValue.d.ts +47 -0
- package/dist/types/Api/GetConnection.d.ts +49 -0
- package/dist/types/Api/GetConnectionBulk.d.ts +46 -0
- package/dist/types/Api/GetConnectionOfTheConcept.d.ts +50 -0
- package/dist/types/Api/GetConnectionToTheConcept.d.ts +56 -0
- package/dist/types/Api/GetReservedConnectionIds.d.ts +36 -0
- package/dist/types/Api/GetReservedIds.d.ts +37 -0
- package/dist/types/Api/Login.d.ts +38 -0
- package/dist/types/Api/MakeTheNameInBackend.d.ts +39 -0
- package/dist/types/Api/MakeTheTypeConceptApi.d.ts +40 -0
- package/dist/types/Api/RecursiveSearch.d.ts +43 -0
- package/dist/types/Api/Search/FreeschemaQueryApi.d.ts +46 -0
- package/dist/types/Api/Search/Search.d.ts +67 -0
- package/dist/types/Api/Search/SearchInternalApi.d.ts +69 -0
- package/dist/types/Api/Search/SearchLinkMultipleApi.d.ts +90 -0
- package/dist/types/Api/Search/SearchWithLinker.d.ts +97 -0
- package/dist/types/Api/SearchConcept/GetConceptByCharacterAndCategoryApi.d.ts +39 -0
- package/dist/types/Api/SearchConcept/GetConceptByCharacterAndCategoryDirect.d.ts +47 -0
- package/dist/types/Api/Session/CreateSession.d.ts +45 -0
- package/dist/types/Api/Session/CreateSessionVisit.d.ts +43 -0
- package/dist/types/Api/Signin.d.ts +48 -0
- package/dist/types/Api/Signup.d.ts +44 -0
- package/dist/types/Api/View/ViewInternalDataApi.d.ts +50 -0
- package/dist/types/Constants/ApiConstants.d.ts +226 -0
- package/dist/types/Constants/FormatConstants.d.ts +81 -0
- package/dist/types/DataStructures/BaseUrl.d.ts +210 -0
- package/dist/types/DataStructures/BinaryCharacterTree.d.ts +211 -0
- package/dist/types/DataStructures/BinaryTree.d.ts +139 -0
- package/dist/types/DataStructures/BinaryTypeTree.d.ts +196 -0
- package/dist/types/DataStructures/CharacterRepository.d.ts +109 -0
- package/dist/types/DataStructures/Composition/Composition.d.ts +103 -0
- package/dist/types/DataStructures/Composition/CompositionBinaryTree.d.ts +104 -0
- package/dist/types/DataStructures/Composition/CompositionNode.d.ts +202 -0
- package/dist/types/DataStructures/Concept.d.ts +110 -0
- package/dist/types/DataStructures/ConceptData.d.ts +292 -0
- package/dist/types/DataStructures/ConceptsToDraw.d.ts +168 -0
- package/dist/types/DataStructures/Connection.d.ts +76 -0
- package/dist/types/DataStructures/ConnectionBinaryTree/ConnectionBinaryTree.d.ts +115 -0
- package/dist/types/DataStructures/ConnectionBinaryTree/ConnectionNode.d.ts +169 -0
- package/dist/types/DataStructures/ConnectionBinaryTree/ConnectionTypeTree.d.ts +82 -0
- package/dist/types/DataStructures/ConnectionData.d.ts +191 -0
- package/dist/types/DataStructures/Count/CountInfo.d.ts +73 -0
- package/dist/types/DataStructures/FilterSearch.d.ts +84 -0
- package/dist/types/DataStructures/IdentifierFlags.d.ts +34 -0
- package/dist/types/DataStructures/Local/LConcept.d.ts +105 -0
- package/dist/types/DataStructures/Local/LConnection.d.ts +83 -0
- package/dist/types/DataStructures/Local/LNode.d.ts +190 -0
- package/dist/types/DataStructures/Local/LocalBinaryCharacterTree.d.ts +133 -0
- package/dist/types/DataStructures/Local/LocalBinaryTree.d.ts +135 -0
- package/dist/types/DataStructures/Local/LocalBinaryTypeTree.d.ts +147 -0
- package/dist/types/DataStructures/Local/LocalConceptData.d.ts +100 -0
- package/dist/types/DataStructures/Local/LocalConnectionData.d.ts +109 -0
- package/dist/types/DataStructures/Local/LocalSyncData.d.ts +89 -0
- package/dist/types/DataStructures/PatcherStructure.d.ts +86 -0
- package/dist/types/DataStructures/ReferentInfo.d.ts +68 -0
- package/dist/types/DataStructures/ReservedIds.d.ts +101 -0
- package/dist/types/DataStructures/Responses/ErrorResponse.d.ts +184 -22
- package/dist/types/DataStructures/Responses/StandardResponses.d.ts +65 -0
- package/dist/types/DataStructures/Returner.d.ts +59 -0
- package/dist/types/DataStructures/Search/FreeschemaQuery.d.ts +165 -0
- package/dist/types/DataStructures/Search/SearchStructure.d.ts +69 -0
- package/dist/types/DataStructures/SearchQuery.d.ts +130 -0
- package/dist/types/DataStructures/Security/TokenStorage.d.ts +48 -0
- package/dist/types/DataStructures/Session/SessionData.d.ts +118 -0
- package/dist/types/DataStructures/SettingData.d.ts +32 -0
- package/dist/types/DataStructures/Settings.d.ts +27 -0
- package/dist/types/DataStructures/SigninModel.d.ts +50 -0
- package/dist/types/DataStructures/SignupModel.d.ts +50 -0
- package/dist/types/DataStructures/SyncData.d.ts +206 -0
- package/dist/types/DataStructures/TheCharacter.d.ts +87 -0
- package/dist/types/DataStructures/TheTexts.d.ts +92 -0
- package/dist/types/DataStructures/Transaction/Transaction.d.ts +294 -4
- package/dist/types/DataStructures/User/UserBinaryTree.d.ts +117 -0
- package/dist/types/DataStructures/User/UserNode.d.ts +130 -0
- package/dist/types/Database/GetConceptFromIndexDb.d.ts +9 -0
- package/dist/types/Database/NoIndexDb.d.ts +169 -0
- package/dist/types/Database/indexdblocal.d.ts +42 -0
- package/dist/types/Database/indexeddb.d.ts +43 -0
- package/dist/types/Drawing/ConceptDraw.d.ts +28 -0
- package/dist/types/Drawing/ConceptEvents.d.ts +46 -0
- package/dist/types/Helpers/CheckIfExists.d.ts +159 -0
- package/dist/types/Helpers/RemoveFromArray.d.ts +66 -0
- package/dist/types/Helpers/UniqueInsert.d.ts +28 -0
- package/dist/types/Services/CheckForConnectionDeletion.d.ts +190 -0
- package/dist/types/Services/Common/DecodeCountInfo.d.ts +54 -0
- package/dist/types/Services/Common/ErrorPosting.d.ts +49 -0
- package/dist/types/Services/Common/RegexFunction.d.ts +28 -0
- package/dist/types/Services/Composition/BuildComposition.d.ts +37 -0
- package/dist/types/Services/Composition/CompositionCache.d.ts +89 -0
- package/dist/types/Services/Composition/CreateCompositionCache.d.ts +43 -0
- package/dist/types/Services/Conversion/ConvertConcepts.d.ts +83 -0
- package/dist/types/Services/CreateBinaryTreeFromData.d.ts +38 -0
- package/dist/types/Services/CreateCharacterBinaryTreeFromData.d.ts +42 -0
- package/dist/types/Services/CreateConnectionBetweenTwoConcepts.d.ts +206 -0
- package/dist/types/Services/CreateDefaultConcept.d.ts +114 -0
- package/dist/types/Services/CreateTheComposition.d.ts +101 -0
- package/dist/types/Services/CreateTheConcept.d.ts +179 -0
- package/dist/types/Services/CreateTheConnection.d.ts +59 -0
- package/dist/types/Services/CreateTheConnectionGeneral.d.ts +127 -0
- package/dist/types/Services/CreateTypeTreeFromData.d.ts +43 -0
- package/dist/types/Services/Delete/DeleteConnectionByType.d.ts +52 -5
- package/dist/types/Services/Delete/GetAllConnectionByType.d.ts +57 -9
- package/dist/types/Services/DeleteConcept.d.ts +136 -0
- package/dist/types/Services/DeleteConnection.d.ts +194 -0
- package/dist/types/Services/FindConeceptsFromConnection.d.ts +179 -0
- package/dist/types/Services/FindConnectionsOfCompositionBulkInMemory.d.ts +157 -0
- package/dist/types/Services/GenerateHexNumber.d.ts +64 -0
- package/dist/types/Services/GetComposition.d.ts +331 -0
- package/dist/types/Services/GetCompositionBulk.d.ts +251 -3
- package/dist/types/Services/GetCompositionList.d.ts +130 -0
- package/dist/types/Services/GetConceptByCharacter.d.ts +84 -0
- package/dist/types/Services/GetConnections.d.ts +72 -0
- package/dist/types/Services/GetDataFromIndexDb.d.ts +79 -0
- package/dist/types/Services/GetLink.d.ts +104 -0
- package/dist/types/Services/GetLinkerConnectionFromConcept.d.ts +99 -0
- package/dist/types/Services/GetMaximumConnectionSyncTime.d.ts +57 -0
- package/dist/types/Services/GetRelation.d.ts +162 -0
- package/dist/types/Services/GetTheConcept.d.ts +71 -0
- package/dist/types/Services/GetTheReferent.d.ts +74 -0
- package/dist/types/Services/InitializeSystem.d.ts +119 -0
- package/dist/types/Services/Local/CreateDefaultLConcept.d.ts +48 -0
- package/dist/types/Services/Local/CreateLocalBinaryTreeFromData.d.ts +49 -0
- package/dist/types/Services/Local/CreateLocalBinaryTypeTreeFromData.d.ts +54 -0
- package/dist/types/Services/Local/CreateLocalCharacterBinaryTree.d.ts +60 -0
- package/dist/types/Services/Local/CreateTheCompositionLocal.d.ts +70 -0
- package/dist/types/Services/Local/CreateTheConceptLocal.d.ts +58 -0
- package/dist/types/Services/Local/CreateTheConnectionLocal.d.ts +56 -0
- package/dist/types/Services/Local/GetCompositionListLocal.d.ts +103 -0
- package/dist/types/Services/Local/GetCompositionLocal.d.ts +96 -0
- package/dist/types/Services/Local/GetConceptByCharacterLocal.d.ts +57 -0
- package/dist/types/Services/Local/MakeTheConceptLocal.d.ts +71 -0
- package/dist/types/Services/Local/MakeTheInstanceConceptLocal.d.ts +89 -0
- package/dist/types/Services/Local/MakeTheTypeLocal.d.ts +71 -0
- package/dist/types/Services/Local/UpdateCompositionLocal.d.ts +101 -0
- package/dist/types/Services/MakeTheCharacter.d.ts +74 -0
- package/dist/types/Services/MakeTheCharacterData.d.ts +65 -0
- package/dist/types/Services/MakeTheInstanceConcept.d.ts +75 -0
- package/dist/types/Services/MakeTheName.d.ts +81 -0
- package/dist/types/Services/MakeTheTimestamp.d.ts +68 -0
- package/dist/types/Services/MakeTheTypeConcept.d.ts +68 -0
- package/dist/types/Services/Mqtt/publishMessage.d.ts +27 -0
- package/dist/types/Services/Mqtt/subscribeMessage.d.ts +23 -0
- package/dist/types/Services/PatchComposition.d.ts +105 -0
- package/dist/types/Services/Search/DataIdFormat.d.ts +96 -24
- package/dist/types/Services/Search/FormatData.d.ts +92 -17
- package/dist/types/Services/Search/JustIdFormat.d.ts +91 -16
- package/dist/types/Services/Search/NewFormat.d.ts +4 -0
- package/dist/types/Services/Search/SearchLinkInternal.d.ts +28 -0
- package/dist/types/Services/Search/SearchLinkMultiple.d.ts +58 -0
- package/dist/types/Services/Search/SearchWithTypeAndLinker.d.ts +92 -24
- package/dist/types/Services/Search/orderingConnections.d.ts +34 -0
- package/dist/types/Services/SplitStrings.d.ts +50 -0
- package/dist/types/Services/UpdateComposition.d.ts +123 -0
- package/dist/types/Services/User/UserTranslation.d.ts +102 -0
- package/dist/types/Services/View/ViewInternalData.d.ts +32 -0
- package/dist/types/WrapperFunctions/SchemaQueryObservable.d.ts +140 -5
- package/dist/types/app.d.ts +72 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,1161 @@
|
|
|
1
|
-
|
|
1
|
+
# CCS-JS (Concept Connection System)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**mftsccs-node** - Full Pack of Concept and Connection System
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A powerful TypeScript library for building knowledge graphs and managing complex relationships between concepts. CCS-JS provides a complete solution for creating, querying, and managing concepts and connections with support for offline-first architecture, transactions, and flexible schema querying.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/mftsccs-node)
|
|
8
|
+
[](https://opensource.org/licenses/ISC)
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
## 📚 Documentation
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Full documentation available at: [https://documentation.freeschema.com](https://documentation.freeschema.com)
|
|
12
13
|
|
|
14
|
+
## 🚀 Installation
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
```bash
|
|
17
|
+
npm install mftsccs-node
|
|
18
|
+
```
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
## 📋 Table of Contents
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
- [Quick Start](#quick-start)
|
|
23
|
+
- [Core Concepts](#core-concepts)
|
|
24
|
+
- [Key Features](#key-features)
|
|
25
|
+
- [API Reference](#api-reference)
|
|
26
|
+
- [Initialization](#initialization)
|
|
27
|
+
- [Session Management](#session-management)
|
|
28
|
+
- [Creating Concepts](#creating-concepts-maketheinstanceconcept)
|
|
29
|
+
- [Creating Connections](#creating-connections-createconnection)
|
|
30
|
+
- [Querying with FreeschemaQuery](#querying-with-freeschemaquery)
|
|
31
|
+
- [Using Transactions](#using-transactions)
|
|
32
|
+
- [Advanced Usage](#advanced-usage)
|
|
33
|
+
- [Development](#development)
|
|
34
|
+
- [Contributing](#contributing)
|
|
35
|
+
- [License](#license)
|
|
19
36
|
|
|
20
|
-
|
|
37
|
+
---
|
|
21
38
|
|
|
22
|
-
|
|
39
|
+
## 🎯 Quick Start
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { init, MakeTheInstanceConcept, CreateConnection, Transaction } from 'mftsccs-node';
|
|
43
|
+
|
|
44
|
+
// Initialize the system
|
|
45
|
+
init(
|
|
46
|
+
'https://api.freeschema.com', // API URL
|
|
47
|
+
'https://ai.freeschema.com', // AI URL
|
|
48
|
+
'your-access-token' // Authentication token
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Create concepts
|
|
52
|
+
const user = await MakeTheInstanceConcept(
|
|
53
|
+
"user", // type
|
|
54
|
+
"john_doe", // referent (value)
|
|
55
|
+
false, // composition flag
|
|
56
|
+
1, // userId
|
|
57
|
+
4, // accessId
|
|
58
|
+
999 // sessionId
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const post = await MakeTheInstanceConcept(
|
|
62
|
+
"post",
|
|
63
|
+
"My First Post",
|
|
64
|
+
false,
|
|
65
|
+
1,
|
|
66
|
+
4,
|
|
67
|
+
999
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// Create a connection
|
|
71
|
+
const connection = await CreateConnection(
|
|
72
|
+
user,
|
|
73
|
+
post,
|
|
74
|
+
"authored" // relationship type
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
console.log('Concept and connection created successfully!');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 💡 Core Concepts
|
|
83
|
+
|
|
84
|
+
### Concept
|
|
85
|
+
A **Concept** is the fundamental unit of knowledge in CCS-JS. It represents any entity, idea, or data point with:
|
|
86
|
+
- **Type**: Classification of the concept (e.g., "user", "post", "comment")
|
|
87
|
+
- **Referent**: The actual value or content
|
|
88
|
+
- **Metadata**: User ownership, access control, timestamps
|
|
89
|
+
- **Relationships**: References to category, type, and other concepts
|
|
90
|
+
|
|
91
|
+
### Connection
|
|
92
|
+
A **Connection** represents a directed relationship between two concepts:
|
|
93
|
+
- Links concepts together with semantic meaning
|
|
94
|
+
- Typed relationships (e.g., "authored", "contains", "belongs_to")
|
|
95
|
+
- Supports ordering, security, and access control
|
|
96
|
+
- Can be queried bidirectionally
|
|
97
|
+
|
|
98
|
+
### Composition
|
|
99
|
+
A **Composition** is a hierarchical structure of related concepts and connections:
|
|
100
|
+
- Nested concept graphs
|
|
101
|
+
- Recursive data structures
|
|
102
|
+
- JSON-like organization
|
|
103
|
+
- Efficient serialization/deserialization
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## ✨ Key Features
|
|
108
|
+
|
|
109
|
+
- 🔄 **Offline-First Architecture**: Local IndexedDB storage with backend synchronization
|
|
110
|
+
- 🔐 **Security & Access Control**: Fine-grained permissions per concept/connection
|
|
111
|
+
- 🌳 **Binary Tree Indexing**: O(log n) lookups by ID, character, and type
|
|
112
|
+
- 📦 **Transactions**: ACID-like operations with rollback support
|
|
113
|
+
- 🔍 **Flexible Querying**: Multiple search strategies including FreeschemaQuery
|
|
114
|
+
- 🚀 **Performance Optimized**: Request deduplication, caching, and bulk operations
|
|
115
|
+
- 📡 **Real-time Sync**: MQTT support for distributed updates
|
|
116
|
+
- 🎯 **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 📖 API Reference
|
|
121
|
+
|
|
122
|
+
### Initialization
|
|
123
|
+
|
|
124
|
+
Initialize the CCS system before performing any operations:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { init, updateAccessToken } from 'mftsccs-node';
|
|
128
|
+
|
|
129
|
+
// Initialize with backend URLs and auth token
|
|
130
|
+
init(
|
|
131
|
+
'https://api.freeschema.com', // Base API URL
|
|
132
|
+
'https://ai.freeschema.com', // AI service URL
|
|
133
|
+
'your-bearer-access-token' // Authentication token
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
// Update token later if needed
|
|
137
|
+
updateAccessToken('new-access-token');
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Important**:
|
|
141
|
+
- Call `init()` once at application startup
|
|
142
|
+
- System loads data from IndexedDB asynchronously
|
|
143
|
+
- Check `IdentifierFlags` to ensure data is loaded before queries
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { IdentifierFlags } from 'mftsccs-node';
|
|
147
|
+
|
|
148
|
+
// Wait for data to load
|
|
149
|
+
if (IdentifierFlags.isDataLoaded) {
|
|
150
|
+
// Safe to query concepts
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
### Session Management
|
|
157
|
+
|
|
158
|
+
CCS-JS includes built-in session tracking capabilities that monitor user activity and enable analytics. The system uses the `X-SESSION-ID` header to track sessions across requests, which is particularly useful when integrating with backend middleware.
|
|
159
|
+
|
|
160
|
+
#### How Session Management Works
|
|
161
|
+
|
|
162
|
+
1. **Automatic Session Creation**: When your application initializes, a session ID is automatically fetched or created
|
|
163
|
+
2. **Session Tracking**: The `X-SESSION-ID` header is included in API requests to track user activity
|
|
164
|
+
3. **Middleware Integration**: Your backend middleware can intercept and use this header for session management
|
|
165
|
+
4. **Session Analytics**: Track user behavior, page visits, and interaction patterns
|
|
166
|
+
|
|
167
|
+
#### Session Data Structure
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { SessionData } from 'mftsccs-node';
|
|
171
|
+
|
|
172
|
+
const session = new SessionData();
|
|
173
|
+
session.id = "unique-session-id";
|
|
174
|
+
session.userId = "123";
|
|
175
|
+
session.email = "user@example.com";
|
|
176
|
+
session.remote_address = "192.168.1.100";
|
|
177
|
+
session.http_user_agent = navigator.userAgent;
|
|
178
|
+
session.server_name = "api.example.com";
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Creating a Session
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { CreateSession, SessionData } from 'mftsccs-node';
|
|
185
|
+
|
|
186
|
+
// Initialize session data
|
|
187
|
+
const sessionData = new SessionData();
|
|
188
|
+
sessionData.userId = "123";
|
|
189
|
+
sessionData.email = "user@example.com";
|
|
190
|
+
sessionData.remote_address = "192.168.1.100";
|
|
191
|
+
sessionData.http_user_agent = navigator.userAgent;
|
|
192
|
+
sessionData.server_port = "443";
|
|
193
|
+
sessionData.server_name = "api.example.com";
|
|
194
|
+
|
|
195
|
+
// Create session in backend
|
|
196
|
+
const session = await CreateSession(sessionData);
|
|
197
|
+
if (session) {
|
|
198
|
+
console.log('Session created:', session.id);
|
|
199
|
+
// Store session ID for subsequent requests
|
|
200
|
+
localStorage.setItem('sessionId', session.id);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Tracking Session Visits
|
|
205
|
+
|
|
206
|
+
Track specific URL visits within a session:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { CreateSessionVisit } from 'mftsccs-node';
|
|
210
|
+
|
|
211
|
+
// Track page visit
|
|
212
|
+
await CreateSessionVisit(
|
|
213
|
+
sessionId,
|
|
214
|
+
'/dashboard'
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// Track another page
|
|
218
|
+
await CreateSessionVisit(
|
|
219
|
+
sessionId,
|
|
220
|
+
'/products/123'
|
|
221
|
+
);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### Middleware Integration Example
|
|
225
|
+
|
|
226
|
+
On your backend, you can use middleware to intercept the `X-SESSION-ID` header:
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
// Express.js middleware example
|
|
230
|
+
app.use((req, res, next) => {
|
|
231
|
+
const sessionId = req.headers['x-session-id'];
|
|
232
|
+
|
|
233
|
+
if (!sessionId) {
|
|
234
|
+
// Create new session
|
|
235
|
+
const newSessionId = generateSessionId();
|
|
236
|
+
res.setHeader('X-SESSION-ID', newSessionId);
|
|
237
|
+
req.sessionId = newSessionId;
|
|
238
|
+
} else {
|
|
239
|
+
// Use existing session
|
|
240
|
+
req.sessionId = sessionId;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
next();
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
#### Session Lifecycle
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { CreateSession, CreateSessionVisit, SessionData } from 'mftsccs-node';
|
|
251
|
+
|
|
252
|
+
// 1. Initialize session on app load
|
|
253
|
+
async function initializeSession() {
|
|
254
|
+
let sessionId = localStorage.getItem('sessionId');
|
|
255
|
+
|
|
256
|
+
if (!sessionId) {
|
|
257
|
+
// Create new session
|
|
258
|
+
const sessionData = new SessionData();
|
|
259
|
+
sessionData.userId = getCurrentUserId();
|
|
260
|
+
sessionData.email = getCurrentUserEmail();
|
|
261
|
+
sessionData.http_user_agent = navigator.userAgent;
|
|
262
|
+
|
|
263
|
+
const session = await CreateSession(sessionData);
|
|
264
|
+
if (session) {
|
|
265
|
+
sessionId = session.id;
|
|
266
|
+
localStorage.setItem('sessionId', sessionId);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return sessionId;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// 2. Track navigation
|
|
274
|
+
async function trackPageVisit(url: string) {
|
|
275
|
+
const sessionId = localStorage.getItem('sessionId');
|
|
276
|
+
if (sessionId) {
|
|
277
|
+
await CreateSessionVisit(sessionId, url);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 3. Use in application
|
|
282
|
+
const sessionId = await initializeSession();
|
|
283
|
+
|
|
284
|
+
// Track page views
|
|
285
|
+
trackPageVisit(window.location.pathname);
|
|
286
|
+
|
|
287
|
+
// Track on navigation
|
|
288
|
+
window.addEventListener('popstate', () => {
|
|
289
|
+
trackPageVisit(window.location.pathname);
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
#### Session Properties
|
|
294
|
+
|
|
295
|
+
The SessionData class captures comprehensive session information:
|
|
296
|
+
|
|
297
|
+
| Property | Type | Description |
|
|
298
|
+
|----------|------|-------------|
|
|
299
|
+
| `id` | `string` | Unique session identifier |
|
|
300
|
+
| `userId` | `string` | User ID associated with session |
|
|
301
|
+
| `email` | `string` | User's email address |
|
|
302
|
+
| `remote_address` | `string` | Client's IP address |
|
|
303
|
+
| `server_port` | `string` | Server port number |
|
|
304
|
+
| `server_address` | `string` | Server IP address |
|
|
305
|
+
| `server_name` | `string` | Server hostname/domain |
|
|
306
|
+
| `server_software` | `string` | Server software version |
|
|
307
|
+
| `http_user_agent` | `string` | Client browser/app information |
|
|
308
|
+
| `self` | `string` | Self-referential identifier |
|
|
309
|
+
| `port` | `string` | Client port number |
|
|
310
|
+
|
|
311
|
+
#### Benefits of Session Management
|
|
312
|
+
|
|
313
|
+
- ✅ **User Analytics**: Track user behavior and interaction patterns
|
|
314
|
+
- ✅ **Session Persistence**: Maintain state across multiple requests
|
|
315
|
+
- ✅ **Security**: Monitor and validate session authenticity
|
|
316
|
+
- ✅ **Debugging**: Trace user actions for troubleshooting
|
|
317
|
+
- ✅ **Personalization**: Enable session-based customization
|
|
318
|
+
- ✅ **Automatic Integration**: Works seamlessly with middleware
|
|
319
|
+
|
|
320
|
+
#### Best Practices
|
|
321
|
+
|
|
322
|
+
1. **Initialize Early**: Create sessions during application bootstrap
|
|
323
|
+
2. **Persist Session ID**: Store in localStorage or sessionStorage
|
|
324
|
+
3. **Track Key Events**: Log important user interactions
|
|
325
|
+
4. **Respect Privacy**: Comply with data protection regulations
|
|
326
|
+
5. **Session Expiry**: Implement timeout mechanisms on backend
|
|
327
|
+
6. **Secure Transmission**: Always use HTTPS for session data
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
### Creating Concepts: MakeTheInstanceConcept
|
|
332
|
+
|
|
333
|
+
The primary method for creating typed concepts in the system.
|
|
334
|
+
|
|
335
|
+
#### Signature
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
MakeTheInstanceConcept(
|
|
339
|
+
type: string,
|
|
340
|
+
referent: string,
|
|
341
|
+
composition: boolean = false,
|
|
342
|
+
userId: number,
|
|
343
|
+
accessId: number,
|
|
344
|
+
sessionId: number = 999,
|
|
345
|
+
referentId: number = 0,
|
|
346
|
+
actions?: InnerActions
|
|
347
|
+
): Promise<Concept>
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### Parameters
|
|
351
|
+
|
|
352
|
+
| Parameter | Type | Description |
|
|
353
|
+
|-----------|------|-------------|
|
|
354
|
+
| `type` | `string` | The type identifier (automatically prefixed with "the_" if needed) |
|
|
355
|
+
| `referent` | `string` | The actual value/content of the concept |
|
|
356
|
+
| `composition` | `boolean` | Whether this is a composition concept (default: `false`) |
|
|
357
|
+
| `userId` | `number` | ID of the user creating the concept |
|
|
358
|
+
| `accessId` | `number` | Access control level |
|
|
359
|
+
| `sessionId` | `number` | Session tracking ID (default: `999`) |
|
|
360
|
+
| `referentId` | `number` | Optional referent concept ID (default: `0`) |
|
|
361
|
+
| `actions` | `InnerActions` | Optional transaction actions tracker |
|
|
362
|
+
|
|
363
|
+
#### Examples
|
|
364
|
+
|
|
365
|
+
**Basic Concept Creation:**
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { MakeTheInstanceConcept } from 'mftsccs-node';
|
|
369
|
+
|
|
370
|
+
// Create a user concept
|
|
371
|
+
const user = await MakeTheInstanceConcept(
|
|
372
|
+
"user",
|
|
373
|
+
"alice@example.com",
|
|
374
|
+
false,
|
|
375
|
+
1, // userId
|
|
376
|
+
4, // accessId
|
|
377
|
+
999 // sessionId
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
console.log('User created:', user.id);
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Creating Different Types:**
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
// Create a product
|
|
387
|
+
const product = await MakeTheInstanceConcept(
|
|
388
|
+
"product",
|
|
389
|
+
"Premium Laptop",
|
|
390
|
+
false,
|
|
391
|
+
1,
|
|
392
|
+
4
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
// Create a category
|
|
396
|
+
const category = await MakeTheInstanceConcept(
|
|
397
|
+
"category",
|
|
398
|
+
"Electronics",
|
|
399
|
+
false,
|
|
400
|
+
1,
|
|
401
|
+
4
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
// Create a review
|
|
405
|
+
const review = await MakeTheInstanceConcept(
|
|
406
|
+
"review",
|
|
407
|
+
"Great product! Highly recommend.",
|
|
408
|
+
false,
|
|
409
|
+
1,
|
|
410
|
+
4
|
|
411
|
+
);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Long Text Handling:**
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// Strings > 255 characters are automatically stored as text data
|
|
418
|
+
const longArticle = "Lorem ipsum...".repeat(100); // > 255 chars
|
|
419
|
+
|
|
420
|
+
const article = await MakeTheInstanceConcept(
|
|
421
|
+
"article",
|
|
422
|
+
longArticle,
|
|
423
|
+
false,
|
|
424
|
+
1,
|
|
425
|
+
4
|
|
426
|
+
);
|
|
427
|
+
// Automatically creates both concept and separate text data entry
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**Composition Concepts:**
|
|
431
|
+
|
|
432
|
+
```typescript
|
|
433
|
+
// Create a composition concept for complex hierarchical data
|
|
434
|
+
const complexData = await MakeTheInstanceConcept(
|
|
435
|
+
"order",
|
|
436
|
+
"ORDER-123",
|
|
437
|
+
true, // composition = true
|
|
438
|
+
1,
|
|
439
|
+
4
|
|
440
|
+
);
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### Key Features
|
|
444
|
+
|
|
445
|
+
- ✅ **Automatic type prefixing**: Type "user" becomes "the_user"
|
|
446
|
+
- ✅ **Deduplication**: Checks for existing concepts by character and type
|
|
447
|
+
- ✅ **Text overflow handling**: Strings > 255 chars stored separately
|
|
448
|
+
- ✅ **Type concept creation**: Automatically creates/retrieves type concepts
|
|
449
|
+
- ✅ **Immediate availability**: Returns concept with type information populated
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
### Creating Connections: CreateConnection
|
|
454
|
+
|
|
455
|
+
Creates typed connections between concepts with semantic relationships.
|
|
456
|
+
|
|
457
|
+
#### Signature
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
CreateConnection(
|
|
461
|
+
ofTheConcept: Concept,
|
|
462
|
+
toTheConcept: Concept,
|
|
463
|
+
typeConnection: string,
|
|
464
|
+
actions?: InnerActions
|
|
465
|
+
): Promise<Connection>
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
#### Parameters
|
|
469
|
+
|
|
470
|
+
| Parameter | Type | Description |
|
|
471
|
+
|-----------|------|-------------|
|
|
472
|
+
| `ofTheConcept` | `Concept` | Source concept (from) |
|
|
473
|
+
| `toTheConcept` | `Concept` | Target concept (to) |
|
|
474
|
+
| `typeConnection` | `string` | Relationship type name |
|
|
475
|
+
| `actions` | `InnerActions` | Optional transaction actions tracker |
|
|
476
|
+
|
|
477
|
+
#### Examples
|
|
478
|
+
|
|
479
|
+
**Simple Connection:**
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
import { CreateConnection } from 'mftsccs-node';
|
|
483
|
+
|
|
484
|
+
const author = await MakeTheInstanceConcept("user", "jane_doe", false, 1, 4);
|
|
485
|
+
const book = await MakeTheInstanceConcept("book", "TypeScript Guide", false, 1, 4);
|
|
486
|
+
|
|
487
|
+
// Create "authored" connection
|
|
488
|
+
const connection = await CreateConnection(
|
|
489
|
+
author,
|
|
490
|
+
book,
|
|
491
|
+
"authored"
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
console.log('Connection created:', connection.id);
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
**Building a Knowledge Graph:**
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
// Create concepts
|
|
501
|
+
const company = await MakeTheInstanceConcept("company", "TechCorp", false, 1, 4);
|
|
502
|
+
const employee = await MakeTheInstanceConcept("employee", "Bob Smith", false, 1, 4);
|
|
503
|
+
const project = await MakeTheInstanceConcept("project", "Project Alpha", false, 1, 4);
|
|
504
|
+
|
|
505
|
+
// Create relationships
|
|
506
|
+
await CreateConnection(employee, company, "works_at");
|
|
507
|
+
await CreateConnection(employee, project, "assigned_to");
|
|
508
|
+
await CreateConnection(project, company, "owned_by");
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
#### Advanced Connection Options
|
|
512
|
+
|
|
513
|
+
**Bidirectional Connections with Counting:**
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
import { CreateConnectionBetweenTwoConcepts } from 'mftsccs-node';
|
|
517
|
+
|
|
518
|
+
// Create bidirectional "friends_with" connection
|
|
519
|
+
await CreateConnectionBetweenTwoConcepts(
|
|
520
|
+
user1,
|
|
521
|
+
user2,
|
|
522
|
+
"friends_with",
|
|
523
|
+
true, // both directions
|
|
524
|
+
true // enable counting
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
// Creates connections:
|
|
528
|
+
// - "users_s_friends_with_s" (forward)
|
|
529
|
+
// - "users_s_friends_with_by" (backward)
|
|
530
|
+
// - Maintains count concepts for analytics
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
**Type-Aware Connection Naming:**
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
// Connection types include concept types in the name
|
|
537
|
+
const author = await MakeTheInstanceConcept("author", "John Doe", false, 1, 4);
|
|
538
|
+
const book = await MakeTheInstanceConcept("book", "My Book", false, 1, 4);
|
|
539
|
+
|
|
540
|
+
await CreateConnectionBetweenTwoConcepts(
|
|
541
|
+
author,
|
|
542
|
+
book,
|
|
543
|
+
"authored"
|
|
544
|
+
);
|
|
545
|
+
// Creates connection type: "authors_s_authored_s"
|
|
546
|
+
|
|
547
|
+
// This enables queries like:
|
|
548
|
+
// "Show all books_s_authored_s_by author"
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
### Querying with FreeschemaQuery
|
|
554
|
+
|
|
555
|
+
Perform flexible, schema-independent queries on concepts.
|
|
556
|
+
|
|
557
|
+
#### Signature
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
FreeschemaQueryApi(
|
|
561
|
+
query: FreeschemaQuery,
|
|
562
|
+
token?: string
|
|
563
|
+
): Promise<Concept[]>
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
#### FreeschemaQuery Structure
|
|
567
|
+
|
|
568
|
+
```typescript
|
|
569
|
+
interface FreeschemaQuery {
|
|
570
|
+
type?: string; // Concept type filter
|
|
571
|
+
search?: string; // Text search term
|
|
572
|
+
composition?: number; // Composition ID
|
|
573
|
+
inpage?: number; // Results per page
|
|
574
|
+
page?: number; // Page number
|
|
575
|
+
userId?: number; // User ID filter
|
|
576
|
+
format?: number; // Response format (1-7)
|
|
577
|
+
linker?: string[]; // Relationship filters
|
|
578
|
+
selectConnectionLinker?: string[];
|
|
579
|
+
selectionType?: string[];
|
|
580
|
+
conceptType?: string;
|
|
581
|
+
filterSearch?: FilterSearch[]; // Complex filters
|
|
582
|
+
connectionSelectionLinker?: string[];
|
|
583
|
+
connectionOfTheLinker?: string[];
|
|
584
|
+
excludeCompositionIds?: number[];
|
|
585
|
+
includeCompositionIds?: number[];
|
|
586
|
+
nestedSelectionLinker?: string[][];
|
|
587
|
+
excludeConnectionIds?: number[];
|
|
588
|
+
createdTime?: string;
|
|
589
|
+
updatedTime?: string;
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
#### Examples
|
|
594
|
+
|
|
595
|
+
**Basic Search:**
|
|
596
|
+
|
|
597
|
+
```typescript
|
|
598
|
+
import { FreeschemaQueryApi } from 'mftsccs-node';
|
|
599
|
+
|
|
600
|
+
// Search for users
|
|
601
|
+
const query = {
|
|
602
|
+
type: "user",
|
|
603
|
+
inpage: 20,
|
|
604
|
+
page: 1
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
const users = await FreeschemaQueryApi(query, "auth-token");
|
|
608
|
+
console.log(`Found ${users.length} users`);
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**Text Search:**
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
// Search for posts containing "typescript"
|
|
615
|
+
const query = {
|
|
616
|
+
type: "post",
|
|
617
|
+
search: "typescript",
|
|
618
|
+
inpage: 10
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
const posts = await FreeschemaQueryApi(query, "auth-token");
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
**Composition Query:**
|
|
625
|
+
|
|
626
|
+
```typescript
|
|
627
|
+
// Get all concepts within a specific composition
|
|
628
|
+
const query = {
|
|
629
|
+
composition: 12345,
|
|
630
|
+
format: 2, // DATAID format
|
|
631
|
+
inpage: 50
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
const concepts = await FreeschemaQueryApi(query, "auth-token");
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
**Advanced Filtering:**
|
|
638
|
+
|
|
639
|
+
```typescript
|
|
640
|
+
// Complex query with filters
|
|
641
|
+
const query = {
|
|
642
|
+
type: "product",
|
|
643
|
+
filterSearch: [
|
|
644
|
+
{
|
|
645
|
+
type: "price",
|
|
646
|
+
search: "100",
|
|
647
|
+
logicoperator: "less_than",
|
|
648
|
+
composition: 0,
|
|
649
|
+
index: 0,
|
|
650
|
+
name: "price_filter",
|
|
651
|
+
operateon: "number"
|
|
652
|
+
}
|
|
653
|
+
],
|
|
654
|
+
linker: ["category_s"],
|
|
655
|
+
inpage: 20
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
const affordableProducts = await FreeschemaQueryApi(query, "auth-token");
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
**Cross-Composition Search:**
|
|
662
|
+
|
|
663
|
+
```typescript
|
|
664
|
+
// Search across multiple compositions
|
|
665
|
+
const query = {
|
|
666
|
+
type: "document",
|
|
667
|
+
includeCompositionIds: [100, 200, 300],
|
|
668
|
+
excludeCompositionIds: [150],
|
|
669
|
+
search: "important",
|
|
670
|
+
inpage: 50
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
const documents = await FreeschemaQueryApi(query, "auth-token");
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
#### Response Formats
|
|
677
|
+
|
|
678
|
+
Use the `format` parameter to control response structure:
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
import { NORMAL, DATAID, JUSTDATA, ALLID, DATAIDDATE, RAW, LISTNORMAL } from 'mftsccs-node';
|
|
682
|
+
|
|
683
|
+
const query = {
|
|
684
|
+
type: "user",
|
|
685
|
+
format: DATAID // format = 2
|
|
686
|
+
};
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
| Format | Value | Description |
|
|
690
|
+
|--------|-------|-------------|
|
|
691
|
+
| `NORMAL` | 1 | Standard format with all concept data |
|
|
692
|
+
| `DATAID` | 2 | Includes ID and metadata wrapper |
|
|
693
|
+
| `JUSTDATA` | 3 | Only the data without metadata |
|
|
694
|
+
| `ALLID` | 6 | All IDs format |
|
|
695
|
+
| `DATAIDDATE` | 4 | Data with ID and date |
|
|
696
|
+
| `RAW` | 5 | Raw data format |
|
|
697
|
+
| `LISTNORMAL` | 7 | List normal format |
|
|
698
|
+
|
|
699
|
+
---
|
|
700
|
+
|
|
701
|
+
### Using Transactions
|
|
702
|
+
|
|
703
|
+
Transactions provide ACID-like guarantees for batch operations with rollback support.
|
|
704
|
+
|
|
705
|
+
#### Transaction Class
|
|
706
|
+
|
|
707
|
+
```typescript
|
|
708
|
+
class Transaction {
|
|
709
|
+
initialize(): Promise<void>;
|
|
710
|
+
MakeTheInstanceConcept(...): Promise<Concept>;
|
|
711
|
+
CreateConnection(...): Promise<Connection>;
|
|
712
|
+
MakeTheTypeConcept(...): Promise<Concept>;
|
|
713
|
+
CreateTheConnectionGeneral(...): Promise<Connection>;
|
|
714
|
+
commitTransaction(): Promise<void>;
|
|
715
|
+
rollbackTransaction(): Promise<void>;
|
|
716
|
+
}
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
#### Basic Transaction Usage
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
import { Transaction } from 'mftsccs-node';
|
|
723
|
+
|
|
724
|
+
const transaction = new Transaction();
|
|
725
|
+
await transaction.initialize();
|
|
726
|
+
|
|
727
|
+
try {
|
|
728
|
+
// Create multiple concepts
|
|
729
|
+
const user = await transaction.MakeTheInstanceConcept(
|
|
730
|
+
"user",
|
|
731
|
+
"alice@example.com",
|
|
732
|
+
false,
|
|
733
|
+
1,
|
|
734
|
+
4
|
|
735
|
+
);
|
|
736
|
+
|
|
737
|
+
const profile = await transaction.MakeTheInstanceConcept(
|
|
738
|
+
"profile",
|
|
739
|
+
"Alice's Profile",
|
|
740
|
+
false,
|
|
741
|
+
1,
|
|
742
|
+
4
|
|
743
|
+
);
|
|
744
|
+
|
|
745
|
+
// Create connection
|
|
746
|
+
await transaction.CreateConnection(user, profile, "has_profile");
|
|
747
|
+
|
|
748
|
+
// Commit all changes
|
|
749
|
+
await transaction.commitTransaction();
|
|
750
|
+
console.log('Transaction committed successfully');
|
|
751
|
+
|
|
752
|
+
} catch (error) {
|
|
753
|
+
// Rollback on error
|
|
754
|
+
await transaction.rollbackTransaction();
|
|
755
|
+
console.error('Transaction rolled back:', error);
|
|
756
|
+
}
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
#### Complex Transaction Example
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
const transaction = new Transaction();
|
|
763
|
+
await transaction.initialize();
|
|
764
|
+
|
|
765
|
+
try {
|
|
766
|
+
// Create a blog post with author, tags, and comments
|
|
767
|
+
const author = await transaction.MakeTheInstanceConcept(
|
|
768
|
+
"author",
|
|
769
|
+
"John Doe",
|
|
770
|
+
false,
|
|
771
|
+
1,
|
|
772
|
+
4
|
|
773
|
+
);
|
|
774
|
+
|
|
775
|
+
const post = await transaction.MakeTheInstanceConcept(
|
|
776
|
+
"post",
|
|
777
|
+
"Introduction to CCS-JS",
|
|
778
|
+
false,
|
|
779
|
+
1,
|
|
780
|
+
4
|
|
781
|
+
);
|
|
782
|
+
|
|
783
|
+
const tag1 = await transaction.MakeTheInstanceConcept(
|
|
784
|
+
"tag",
|
|
785
|
+
"typescript",
|
|
786
|
+
false,
|
|
787
|
+
1,
|
|
788
|
+
4
|
|
789
|
+
);
|
|
790
|
+
|
|
791
|
+
const tag2 = await transaction.MakeTheInstanceConcept(
|
|
792
|
+
"tag",
|
|
793
|
+
"tutorial",
|
|
794
|
+
false,
|
|
795
|
+
1,
|
|
796
|
+
4
|
|
797
|
+
);
|
|
798
|
+
|
|
799
|
+
// Create all relationships
|
|
800
|
+
await transaction.CreateConnection(author, post, "authored");
|
|
801
|
+
await transaction.CreateConnection(post, tag1, "tagged_with");
|
|
802
|
+
await transaction.CreateConnection(post, tag2, "tagged_with");
|
|
803
|
+
|
|
804
|
+
// Commit the entire graph
|
|
805
|
+
await transaction.commitTransaction();
|
|
806
|
+
|
|
807
|
+
} catch (error) {
|
|
808
|
+
await transaction.rollbackTransaction();
|
|
809
|
+
console.error('Failed to create blog post:', error);
|
|
810
|
+
}
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
#### Transaction with Error Handling
|
|
814
|
+
|
|
815
|
+
```typescript
|
|
816
|
+
async function createUserWithProfile(email: string, profileData: string) {
|
|
817
|
+
const transaction = new Transaction();
|
|
818
|
+
await transaction.initialize();
|
|
819
|
+
|
|
820
|
+
try {
|
|
821
|
+
// Create user
|
|
822
|
+
const user = await transaction.MakeTheInstanceConcept(
|
|
823
|
+
"user",
|
|
824
|
+
email,
|
|
825
|
+
false,
|
|
826
|
+
1,
|
|
827
|
+
4
|
|
828
|
+
);
|
|
829
|
+
|
|
830
|
+
// Validate user creation
|
|
831
|
+
if (!user || user.id === 0) {
|
|
832
|
+
throw new Error('Failed to create user');
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// Create profile
|
|
836
|
+
const profile = await transaction.MakeTheInstanceConcept(
|
|
837
|
+
"profile",
|
|
838
|
+
profileData,
|
|
839
|
+
false,
|
|
840
|
+
1,
|
|
841
|
+
4
|
|
842
|
+
);
|
|
843
|
+
|
|
844
|
+
// Link them
|
|
845
|
+
await transaction.CreateConnection(user, profile, "has_profile");
|
|
846
|
+
|
|
847
|
+
// Commit
|
|
848
|
+
await transaction.commitTransaction();
|
|
849
|
+
return { user, profile };
|
|
850
|
+
|
|
851
|
+
} catch (error) {
|
|
852
|
+
// Automatic rollback
|
|
853
|
+
await transaction.rollbackTransaction();
|
|
854
|
+
throw new Error(`Transaction failed: ${error}`);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
#### Benefits of Transactions
|
|
860
|
+
|
|
861
|
+
- ✅ **Atomicity**: All operations succeed or all fail
|
|
862
|
+
- ✅ **Consistency**: Data remains in valid state
|
|
863
|
+
- ✅ **Rollback Support**: Automatic cleanup on failure
|
|
864
|
+
- ✅ **Batch Tracking**: All changes tracked together
|
|
865
|
+
- ✅ **Error Recovery**: Graceful handling of failures
|
|
866
|
+
|
|
867
|
+
---
|
|
868
|
+
|
|
869
|
+
## 🔧 Advanced Usage
|
|
870
|
+
|
|
871
|
+
### Compositions
|
|
872
|
+
|
|
873
|
+
Create and query hierarchical data structures:
|
|
874
|
+
|
|
875
|
+
```typescript
|
|
876
|
+
import { CreateComposition, GetComposition } from 'mftsccs-node';
|
|
877
|
+
|
|
878
|
+
// Create nested composition
|
|
879
|
+
const data = {
|
|
880
|
+
user: "john_doe",
|
|
881
|
+
profile: {
|
|
882
|
+
name: "John Doe",
|
|
883
|
+
email: "john@example.com",
|
|
884
|
+
settings: {
|
|
885
|
+
theme: "dark",
|
|
886
|
+
notifications: true
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
posts: ["post1", "post2"]
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
const composition = await CreateComposition(
|
|
893
|
+
data,
|
|
894
|
+
"user_profile",
|
|
895
|
+
1,
|
|
896
|
+
4,
|
|
897
|
+
999
|
|
898
|
+
);
|
|
899
|
+
|
|
900
|
+
// Retrieve and reconstruct
|
|
901
|
+
const retrieved = await GetComposition(composition.id);
|
|
902
|
+
console.log(retrieved); // Full nested structure
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
### Local Storage (Offline Support)
|
|
906
|
+
|
|
907
|
+
Work with local concepts for offline functionality:
|
|
908
|
+
|
|
909
|
+
```typescript
|
|
910
|
+
import {
|
|
911
|
+
CreateTheConceptLocal,
|
|
912
|
+
GetCompositionLocal,
|
|
913
|
+
MakeTheInstanceConceptLocal
|
|
914
|
+
} from 'mftsccs-node';
|
|
915
|
+
|
|
916
|
+
// Create local concept (survives offline)
|
|
917
|
+
const localConcept = await MakeTheInstanceConceptLocal(
|
|
918
|
+
"note",
|
|
919
|
+
"Offline note",
|
|
920
|
+
1,
|
|
921
|
+
4
|
|
922
|
+
);
|
|
923
|
+
|
|
924
|
+
// Retrieve from local storage
|
|
925
|
+
const composition = await GetCompositionLocal(
|
|
926
|
+
localConcept.id,
|
|
927
|
+
localConcept.userId
|
|
928
|
+
);
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
### Bulk Operations
|
|
932
|
+
|
|
933
|
+
Optimize performance with bulk operations:
|
|
934
|
+
|
|
935
|
+
```typescript
|
|
936
|
+
import {
|
|
937
|
+
GetConceptBulk,
|
|
938
|
+
GetConnectionBulk
|
|
939
|
+
} from 'mftsccs-node';
|
|
940
|
+
|
|
941
|
+
// Fetch multiple concepts at once
|
|
942
|
+
const conceptIds = [123, 456, 789];
|
|
943
|
+
const concepts = await GetConceptBulk(conceptIds);
|
|
944
|
+
|
|
945
|
+
// Fetch multiple connections
|
|
946
|
+
const connectionIds = [1, 2, 3, 4, 5];
|
|
947
|
+
const connections = await GetConnectionBulk(connectionIds);
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
### Relationship Queries
|
|
951
|
+
|
|
952
|
+
Navigate relationships between concepts:
|
|
953
|
+
|
|
954
|
+
```typescript
|
|
955
|
+
import {
|
|
956
|
+
GetLink,
|
|
957
|
+
GetRelation,
|
|
958
|
+
GetConnectionOfTheConcept
|
|
959
|
+
} from 'mftsccs-node';
|
|
960
|
+
|
|
961
|
+
// Get all "authored" books by an author
|
|
962
|
+
const books = await GetLink(
|
|
963
|
+
"the_book",
|
|
964
|
+
"authored",
|
|
965
|
+
authorId,
|
|
966
|
+
userId
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
// Get reverse relationship (books to authors)
|
|
970
|
+
const authors = await GetRelation(
|
|
971
|
+
"the_author",
|
|
972
|
+
"authored",
|
|
973
|
+
bookId,
|
|
974
|
+
userId
|
|
975
|
+
);
|
|
976
|
+
|
|
977
|
+
// Get connections from a concept
|
|
978
|
+
const connections = await GetConnectionOfTheConcept(
|
|
979
|
+
connectionTypeId,
|
|
980
|
+
conceptId,
|
|
981
|
+
userId,
|
|
982
|
+
10, // inpage
|
|
983
|
+
1 // page
|
|
984
|
+
);
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
---
|
|
988
|
+
|
|
989
|
+
## 🛠️ Development
|
|
990
|
+
|
|
991
|
+
### Prerequisites
|
|
992
|
+
|
|
993
|
+
- Node.js 14+
|
|
994
|
+
- npm or yarn
|
|
995
|
+
- TypeScript 5.3+
|
|
996
|
+
|
|
997
|
+
### Environment Setup
|
|
998
|
+
|
|
999
|
+
Create environment files from the example:
|
|
1000
|
+
|
|
1001
|
+
```bash
|
|
1002
|
+
# For development
|
|
1003
|
+
cp .env.example .env.development
|
|
1004
|
+
|
|
1005
|
+
# For production
|
|
1006
|
+
cp .env.example .env.production
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
### Build from Source
|
|
1010
|
+
|
|
1011
|
+
```bash
|
|
1012
|
+
# Clone the repository
|
|
1013
|
+
git clone https://github.com/Mentor-Friends/tsccs-dev.git
|
|
1014
|
+
cd tsccs-dev
|
|
1015
|
+
|
|
1016
|
+
# Install dependencies
|
|
1017
|
+
npm install
|
|
1018
|
+
|
|
1019
|
+
# Build the project
|
|
1020
|
+
npm run build
|
|
1021
|
+
|
|
1022
|
+
# Run in development mode
|
|
1023
|
+
npm run dev
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
### Project Structure
|
|
1027
|
+
|
|
1028
|
+
```
|
|
1029
|
+
ccs-js/
|
|
1030
|
+
├── src/
|
|
1031
|
+
│ ├── Api/ # Backend API integration (45 files)
|
|
1032
|
+
│ ├── Services/ # Business logic layer (73+ files)
|
|
1033
|
+
│ ├── DataStructures/ # Core data models (70+ files)
|
|
1034
|
+
│ ├── Database/ # IndexedDB persistence (4 files)
|
|
1035
|
+
│ ├── Constants/ # Configuration (2 files)
|
|
1036
|
+
│ ├── Helpers/ # Utility functions (3 files)
|
|
1037
|
+
│ ├── Drawing/ # UI visualization (2 files)
|
|
1038
|
+
│ ├── WrapperFunctions/ # Observable wrappers (1 file)
|
|
1039
|
+
│ └── app.ts # Main entry point
|
|
1040
|
+
├── dist/ # Compiled output
|
|
1041
|
+
├── webpack.config.js # Build configuration
|
|
1042
|
+
├── tsconfig.json # TypeScript config
|
|
1043
|
+
└── package.json
|
|
1044
|
+
```
|
|
1045
|
+
|
|
1046
|
+
### Scripts
|
|
1047
|
+
|
|
1048
|
+
```bash
|
|
1049
|
+
npm start # Build with webpack (production)
|
|
1050
|
+
npm run dev # Development build with watch mode
|
|
1051
|
+
npm run build # Production build
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
---
|
|
1055
|
+
|
|
1056
|
+
## 📝 Examples
|
|
1057
|
+
|
|
1058
|
+
### E-commerce System
|
|
1059
|
+
|
|
1060
|
+
```typescript
|
|
1061
|
+
// Create product catalog
|
|
1062
|
+
const electronics = await MakeTheInstanceConcept("category", "Electronics", false, 1, 4);
|
|
1063
|
+
const laptop = await MakeTheInstanceConcept("product", "Premium Laptop", false, 1, 4);
|
|
1064
|
+
const review = await MakeTheInstanceConcept("review", "Great product!", false, 1, 4);
|
|
1065
|
+
|
|
1066
|
+
// Build relationships
|
|
1067
|
+
await CreateConnection(laptop, electronics, "belongs_to");
|
|
1068
|
+
await CreateConnection(review, laptop, "reviews");
|
|
1069
|
+
```
|
|
1070
|
+
|
|
1071
|
+
### Social Network
|
|
1072
|
+
|
|
1073
|
+
```typescript
|
|
1074
|
+
const transaction = new Transaction();
|
|
1075
|
+
await transaction.initialize();
|
|
1076
|
+
|
|
1077
|
+
try {
|
|
1078
|
+
const user1 = await transaction.MakeTheInstanceConcept("user", "alice", false, 1, 4);
|
|
1079
|
+
const user2 = await transaction.MakeTheInstanceConcept("user", "bob", false, 1, 4);
|
|
1080
|
+
const post = await transaction.MakeTheInstanceConcept("post", "Hello World", false, 1, 4);
|
|
1081
|
+
|
|
1082
|
+
await transaction.CreateConnection(user1, user2, "follows");
|
|
1083
|
+
await transaction.CreateConnection(user1, post, "created");
|
|
1084
|
+
await transaction.CreateConnection(user2, post, "liked");
|
|
1085
|
+
|
|
1086
|
+
await transaction.commitTransaction();
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
await transaction.rollbackTransaction();
|
|
1089
|
+
}
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
### Document Management
|
|
1093
|
+
|
|
1094
|
+
```typescript
|
|
1095
|
+
// Create document hierarchy
|
|
1096
|
+
const folder = await MakeTheInstanceConcept("folder", "Projects", false, 1, 4);
|
|
1097
|
+
const doc = await MakeTheInstanceConcept("document", "README", false, 1, 4);
|
|
1098
|
+
const version = await MakeTheInstanceConcept("version", "v1.0", false, 1, 4);
|
|
1099
|
+
|
|
1100
|
+
await CreateConnection(doc, folder, "contained_in");
|
|
1101
|
+
await CreateConnection(version, doc, "version_of");
|
|
1102
|
+
|
|
1103
|
+
// Query documents
|
|
1104
|
+
const query = {
|
|
1105
|
+
type: "document",
|
|
1106
|
+
linker: ["contained_in_s"],
|
|
1107
|
+
composition: folder.id
|
|
1108
|
+
};
|
|
1109
|
+
const documents = await FreeschemaQueryApi(query, "token");
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
---
|
|
1113
|
+
|
|
1114
|
+
## 🤝 Contributing
|
|
1115
|
+
|
|
1116
|
+
Contributions are welcome! Please follow these steps:
|
|
1117
|
+
|
|
1118
|
+
1. Fork the repository
|
|
1119
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
1120
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
1121
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
1122
|
+
5. Open a Pull Request
|
|
1123
|
+
|
|
1124
|
+
### Coding Standards
|
|
1125
|
+
|
|
1126
|
+
- Follow TypeScript best practices
|
|
1127
|
+
- Add JSDoc comments for all public APIs
|
|
1128
|
+
- Write unit tests for new features
|
|
1129
|
+
- Update documentation as needed
|
|
1130
|
+
|
|
1131
|
+
---
|
|
1132
|
+
|
|
1133
|
+
## 📄 License
|
|
1134
|
+
|
|
1135
|
+
This project is licensed under the ISC License.
|
|
1136
|
+
|
|
1137
|
+
---
|
|
1138
|
+
|
|
1139
|
+
## 🔗 Links
|
|
1140
|
+
|
|
1141
|
+
- **Documentation**: [https://documentation.freeschema.com](https://documentation.freeschema.com)
|
|
1142
|
+
- **GitHub**: [https://github.com/Mentor-Friends/tsccs-dev](https://github.com/Mentor-Friends/tsccs-dev)
|
|
1143
|
+
- **Issues**: [https://github.com/Mentor-Friends/tsccs-dev/issues](https://github.com/Mentor-Friends/tsccs-dev/issues)
|
|
1144
|
+
- **npm Package**: [https://www.npmjs.com/package/mftsccs-node](https://www.npmjs.com/package/mftsccs-node)
|
|
1145
|
+
|
|
1146
|
+
---
|
|
1147
|
+
|
|
1148
|
+
## 📞 Support
|
|
1149
|
+
|
|
1150
|
+
For questions and support:
|
|
1151
|
+
- Open an issue on GitHub
|
|
1152
|
+
- Check the documentation at [documentation.freeschema.com](https://documentation.freeschema.com)
|
|
1153
|
+
- Contact: Mentor Friends
|
|
1154
|
+
|
|
1155
|
+
---
|
|
1156
|
+
|
|
1157
|
+
**Made with ❤️ by Mentor Friends**
|
|
1158
|
+
|
|
1159
|
+
*Version 0.0.52*
|
|
23
1160
|
|
|
24
1161
|
|