mftsccs-node 0.0.53 → 0.0.55

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