mftsccs-browser 2.2.20-beta → 2.2.22-beta
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 +1073 -11
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +1 -0
- package/dist/main.bundle.js +1 -1
- package/dist/serviceWorker.bundle.js +1 -1
- package/dist/types/Api/Create/CreateTheCharacter.d.ts +21 -0
- package/dist/types/Api/Create/CreateTheConceptApi.d.ts +18 -0
- package/dist/types/Api/Create/CreateTheConnectionApi.d.ts +16 -0
- package/dist/types/Api/Create/CreateTheGhostConceptApi.d.ts +25 -0
- package/dist/types/Api/Create/CreateTheGhostConnectionApi.d.ts +16 -0
- package/dist/types/Api/Create/CreateTheTextData.d.ts +16 -0
- package/dist/types/Api/Delete/DeleteConceptInBackend.d.ts +13 -0
- package/dist/types/Api/Delete/DeleteUserInBackend.d.ts +18 -0
- package/dist/types/Api/DeleteConnectionApiBulk.d.ts +1 -0
- package/dist/types/Api/DeleteConnectionBulkApi.d.ts +19 -0
- package/dist/types/Api/DeleteTheConcept.d.ts +19 -0
- package/dist/types/Api/DeleteTheConnection.d.ts +19 -0
- package/dist/types/Api/GetAiData.d.ts +9 -0
- package/dist/types/Api/GetAllConcepts.d.ts +10 -0
- package/dist/types/Api/GetAllConceptsByType.d.ts +11 -0
- package/dist/types/Api/GetAllConnections.d.ts +10 -0
- package/dist/types/Api/GetAllConnectionsOfComposition.d.ts +20 -0
- package/dist/types/Api/GetAllConnectionsOfCompositionBulk.d.ts +20 -0
- package/dist/types/Api/GetAllLinkerConnectionsFromTheConcept.d.ts +10 -0
- package/dist/types/Api/GetAllLinkerConnectionsToTheConcept.d.ts +10 -0
- package/dist/types/Api/GetAllPrefetchConnections.d.ts +11 -0
- package/dist/types/Api/GetCharacterDataByCharacter.d.ts +10 -0
- package/dist/types/Api/GetCompositionConnectionsBetweenTwoConcepts.d.ts +12 -0
- package/dist/types/Api/GetConceptBulk.d.ts +10 -0
- package/dist/types/Api/GetConceptByCharacterAndType.d.ts +14 -0
- package/dist/types/Api/GetConceptByCharacterValue.d.ts +10 -0
- package/dist/types/Api/GetConnection.d.ts +13 -0
- package/dist/types/Api/GetConnectionOfTheConcept.d.ts +14 -0
- package/dist/types/Api/GetConnectionToTheConcept.d.ts +15 -0
- package/dist/types/Api/GetConnections/GetConnectionsByTypeApi.d.ts +12 -0
- package/dist/types/Api/GetReservedConnectionIds.d.ts +9 -0
- package/dist/types/Api/GetReservedIds.d.ts +9 -0
- package/dist/types/Api/Images/GetImages.d.ts +14 -0
- package/dist/types/Api/Local/GetLocalConceptByCharacterValue.d.ts +11 -0
- package/dist/types/Api/Login.d.ts +77 -0
- package/dist/types/Api/MakeTheNameInBackend.d.ts +13 -0
- package/dist/types/Api/Prototype/CreatePrototype.d.ts +12 -0
- package/dist/types/Api/Prototype/Selector.d.ts +11 -0
- package/dist/types/Api/RecursiveSearch.d.ts +61 -0
- package/dist/types/Api/Search/FreeschemaQueryApi.d.ts +16 -0
- package/dist/types/Api/Search/Search.d.ts +72 -0
- package/dist/types/Api/Search/SearchInternalApi.d.ts +25 -0
- package/dist/types/Api/Search/SearchLinkMultipleApi.d.ts +13 -0
- package/dist/types/Api/Search/SearchWithLinker.d.ts +14 -0
- package/dist/types/Api/Search/SearchWithTypeAndLinker.d.ts +12 -0
- package/dist/types/Api/SearchConcept/GetConceptByCharacterAndCategoryApi.d.ts +10 -0
- package/dist/types/Api/SearchConcept/GetConceptByCharacterAndCategoryDirect.d.ts +11 -0
- package/dist/types/Api/SearchConcept/GetTypeConceptByBulk.d.ts +13 -0
- package/dist/types/Api/Session/CreateSession.d.ts +14 -0
- package/dist/types/Api/Session/CreateSessionVisit.d.ts +11 -0
- package/dist/types/Api/Signin.d.ts +21 -0
- package/dist/types/Api/Signup.d.ts +53 -11
- package/dist/types/Api/Translate/TranslateLocalToReal.d.ts +10 -0
- package/dist/types/Api/View/ViewInternalDataApi.d.ts +14 -0
- package/dist/types/DataStructures/BaseUrl.d.ts +1 -0
- package/dist/types/DataStructures/Transaction/Transaction.d.ts +30 -0
- package/dist/types/Services/AccessControl/AccessControlCacheService.d.ts +19 -0
- package/dist/types/Services/AccessControl/AccessControlService.d.ts +267 -0
- package/dist/types/Services/AccessControl/PermissionSet.d.ts +8 -0
- package/dist/types/Services/CreateTheConcept.d.ts +118 -0
- package/dist/types/Services/CreateTheConnection.d.ts +59 -6
- package/dist/types/Services/Delete/DeleteConnectionByType.d.ts +13 -0
- package/dist/types/Services/Delete/GetAllConnectionByType.d.ts +16 -0
- package/dist/types/Services/GetComposition.d.ts +64 -7
- package/dist/types/Services/GetTheConcept.d.ts +91 -4
- package/dist/types/Services/Local/ConvertFromLConceptToConcept.d.ts +39 -0
- package/dist/types/Services/Local/ConvertFromLConnectionToConnection.d.ts +45 -0
- package/dist/types/Services/Local/CreateConnectionBetweenTwoConceptsLocal.d.ts +41 -0
- package/dist/types/Services/Local/CreateDefaultLConcept.d.ts +44 -0
- package/dist/types/Services/Local/CreateLocalBinaryTreeFromData.d.ts +6 -1
- package/dist/types/Services/Local/CreateLocalBinaryTypeTreeFromData.d.ts +8 -0
- package/dist/types/Services/Local/CreateLocalCharacterBinaryTree.d.ts +8 -0
- package/dist/types/Services/Local/CreateTheCompositionLocal.d.ts +100 -10
- package/dist/types/Services/Local/CreateTheConceptLocal.d.ts +80 -18
- package/dist/types/Services/Local/CreateTheConnectionLocal.d.ts +135 -11
- package/dist/types/Services/Local/DeleteConceptLocal.d.ts +46 -0
- package/dist/types/Services/Local/GetCompositionListLocal.d.ts +31 -8
- package/dist/types/Services/Local/GetCompositionLocal.d.ts +95 -0
- package/dist/types/Services/Local/GetConceptByCharacterLocal.d.ts +48 -2
- package/dist/types/Services/Local/GetConnectionOfTheConceptLocal.d.ts +17 -0
- package/dist/types/Services/Local/GetRelationLocal.d.ts +20 -0
- package/dist/types/Services/Local/GetTheConceptLocal.d.ts +60 -6
- package/dist/types/Services/Local/MakeTheConceptLocal.d.ts +20 -0
- package/dist/types/Services/Local/MakeTheInstanceConceptLocal.d.ts +160 -14
- package/dist/types/Services/Local/MakeTheTypeLocal.d.ts +29 -9
- package/dist/types/Services/Local/UpdateCompositionLocal.d.ts +39 -0
- package/dist/types/Services/MakeTheLocalConcept.d.ts +0 -0
- package/dist/types/Services/MakeTheName.d.ts +2 -0
- package/dist/types/Services/auth/AuthService.d.ts +1 -0
- package/dist/types/Widgets/BaseObserver.d.ts +14 -11
- package/dist/types/Widgets/BaseWidget.d.ts +24 -11
- package/dist/types/Widgets/BuilderSpeceficFunctions.d.ts +9 -0
- package/dist/types/Widgets/BuilderStatefulWidget.d.ts +352 -2
- package/dist/types/Widgets/CacheWidget.service.d.ts +60 -0
- package/dist/types/Widgets/NormalizeStyles.service.d.ts +9 -0
- package/dist/types/Widgets/RenderPage.service.d.ts +9 -4
- package/dist/types/Widgets/RenderWidgetLibrary.service.d.ts +12 -4
- package/dist/types/Widgets/RenderWidgetService.d.ts +158 -21
- package/dist/types/Widgets/StatefulWidget.d.ts +94 -29
- package/dist/types/Widgets/WidgetBuild.d.ts +41 -0
- package/dist/types/Widgets/WidgetTree.d.ts +31 -0
- package/dist/types/Widgets/mainView.class.d.ts +21 -0
- package/dist/types/WrapperFunctions/DepenedencyObserver.d.ts +48 -27
- package/dist/types/WrapperFunctions/GetCompositionListObservable.d.ts +34 -2
- package/dist/types/WrapperFunctions/GetCompositionObservable.d.ts +24 -2
- package/dist/types/WrapperFunctions/GetLinkListObservable.d.ts +38 -9
- package/dist/types/WrapperFunctions/GetLinkObservable.d.ts +30 -12
- package/dist/types/WrapperFunctions/RecursiveSearchObservable.d.ts +34 -16
- package/dist/types/WrapperFunctions/SchemaQueryObservable.d.ts +41 -5
- package/dist/types/WrapperFunctions/SearchLinkMultipleAllObservable.d.ts +24 -3
- package/dist/types/app.d.ts +183 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,1086 @@
|
|
|
1
|
-
|
|
1
|
+
# mftsccs-browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/mftsccs-browser)
|
|
4
|
+
[](https://opensource.org/licenses/ISC)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
> A comprehensive TypeScript/JavaScript package for managing concepts, connections, and compositions in a knowledge graph structure.
|
|
6
7
|
|
|
7
|
-
##
|
|
8
|
+
## Table of Contents
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
- [Overview](#overview)
|
|
11
|
+
- [Features](#features)
|
|
12
|
+
- [Installation](#installation)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [Core Concepts](#core-concepts)
|
|
15
|
+
- [Documentation](#documentation)
|
|
16
|
+
- [API Overview](#api-overview)
|
|
17
|
+
- [Configuration](#configuration)
|
|
18
|
+
- [Examples](#examples)
|
|
19
|
+
- [Development](#development)
|
|
20
|
+
- [Publishing to npm](#publishing-to-npm)
|
|
21
|
+
- [Contributing](#contributing)
|
|
22
|
+
- [License](#license)
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
## Overview
|
|
12
25
|
|
|
26
|
+
**mftsccs-browser** is a powerful browser-based data management library that implements a sophisticated Concept & Connection System (TSCCS). It provides a flexible way to model, store, and query knowledge graphs with support for both online and offline operations.
|
|
13
27
|
|
|
14
|
-
|
|
28
|
+
### 📚 Fully Documented
|
|
15
29
|
|
|
16
|
-
|
|
30
|
+
**Every function, class, and method is documented with concise JSDoc comments** - making it easy for developers to understand and use the package. Hover over any function in your IDE to see parameter types, descriptions, examples, and return values.
|
|
17
31
|
|
|
18
|
-
|
|
32
|
+
### What is it for?
|
|
19
33
|
|
|
20
|
-
|
|
34
|
+
- Building knowledge graphs and semantic networks
|
|
35
|
+
- Managing complex relational data in browser applications
|
|
36
|
+
- Creating applications that need offline-first data management
|
|
37
|
+
- Implementing concept-based search and discovery systems
|
|
38
|
+
- Building applications with hierarchical and networked data structures
|
|
21
39
|
|
|
22
|
-
|
|
40
|
+
## Features
|
|
23
41
|
|
|
42
|
+
### Core Data Management
|
|
43
|
+
- **Concept & Connection Management**: Create and manage entities (concepts) and their relationships (connections)
|
|
44
|
+
- **Simplified Connection API** ⭐: `CreateConnection()` auto-creates type concepts, saving developer time
|
|
45
|
+
- **Composition System**: Build complex hierarchical structures from concepts and connections
|
|
46
|
+
- **Transaction Support (ACID Compliant)** ⭐: Atomic operations with commit/rollback for data integrity
|
|
47
|
+
- Atomicity: All-or-nothing operations
|
|
48
|
+
- Consistency: Guaranteed valid data state
|
|
49
|
+
- Isolation: Transaction isolation
|
|
50
|
+
- Durability: Permanent committed changes
|
|
51
|
+
- Bulk batching: Efficient multi-operation server sync
|
|
52
|
+
|
|
53
|
+
### Offline & Sync
|
|
54
|
+
- **Offline-First Architecture**: Full IndexedDB support with intelligent caching and virtual ID system
|
|
55
|
+
- **Virtual ID System**: Negative IDs for local/offline, positive for synced, ghost IDs for reference preservation
|
|
56
|
+
- **Sync Capabilities**: Seamless sync between local and remote data with automatic conflict resolution
|
|
57
|
+
- **Service Worker Support**: Optional background processing for better performance
|
|
58
|
+
|
|
59
|
+
### Search & Query
|
|
60
|
+
- **FreeschemaQuery System** ⭐: Flexible, schema-free querying with filters, nested relationships, and multiple output formats
|
|
61
|
+
- **Advanced Search**: Powerful search capabilities with filters, type matching, relationship queries, and recursive searches
|
|
62
|
+
- **Binary Tree Indexing**: Fast in-memory indexing for optimal performance
|
|
63
|
+
- **Bulk Operations**: Efficient batch processing for concepts, connections, and searches
|
|
64
|
+
|
|
65
|
+
### Reactive & UI
|
|
66
|
+
- **Widget System** ⭐: React-like component framework with lifecycle hooks, state management, and parent-child composition
|
|
67
|
+
- **StatefulWidget**: Full lifecycle management (before_render, render, after_render)
|
|
68
|
+
- **BuilderStatefulWidget**: Dynamic code execution and concept integration
|
|
69
|
+
- **Observable Integration**: Real-time UI updates when data changes
|
|
70
|
+
- **Reactive State Management**: Observable pattern with automatic change detection and subscriber notifications
|
|
71
|
+
|
|
72
|
+
### Developer Experience
|
|
73
|
+
- **Type System**: Strong TypeScript typing throughout with comprehensive JSDoc documentation
|
|
74
|
+
- **Comprehensive Documentation**: All functions, classes, and methods documented with concise JSDoc comments
|
|
75
|
+
- **Session Management**: Built-in user authentication and session handling
|
|
76
|
+
- **Transaction API**: Simple, intuitive API for complex multi-step operations
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install mftsccs-browser
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or using yarn:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
yarn add mftsccs-browser
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
### Basic Usage
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
import { init, MakeTheInstanceConceptLocal, GetTheConceptLocal } from 'mftsccs-browser';
|
|
96
|
+
|
|
97
|
+
// Initialize the package
|
|
98
|
+
await init({
|
|
99
|
+
url: 'https://your-backend-api.com',
|
|
100
|
+
clientUrl: 'https://your-app.com',
|
|
101
|
+
secureCoreModePath: false
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Create a concept (recommended: local-first with transactions)
|
|
105
|
+
const newConcept = await MakeTheInstanceConceptLocal(
|
|
106
|
+
'the_name', // Type (always use "the_" prefix)
|
|
107
|
+
'My First Concept', // Value/referent
|
|
108
|
+
false, // composition mode (false = get-or-create)
|
|
109
|
+
userId, // User ID
|
|
110
|
+
accessId, // Access ID
|
|
111
|
+
sessionId // Session ID
|
|
112
|
+
);
|
|
113
|
+
console.log('Created:', newConcept);
|
|
114
|
+
|
|
115
|
+
// Retrieve a concept
|
|
116
|
+
const concept = await GetTheConceptLocal(newConcept.id);
|
|
117
|
+
console.log('Retrieved:', concept);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Using Transactions (Recommended)
|
|
121
|
+
|
|
122
|
+
The `LocalTransaction` class provides a robust transaction pattern with commit and rollback support. **Always use transactions for multi-step operations** to ensure ACID compliance and enable bulk batching to the server.
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
import { LocalTransaction } from 'mftsccs-browser';
|
|
126
|
+
|
|
127
|
+
// Initialize a new transaction
|
|
128
|
+
const transaction = new LocalTransaction();
|
|
129
|
+
await transaction.initialize();
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
// Create concepts within the transaction
|
|
133
|
+
const person = await transaction.MakeTheInstanceConceptLocal(
|
|
134
|
+
'the_person', // Type
|
|
135
|
+
'Alice', // Value
|
|
136
|
+
false, // composition mode
|
|
137
|
+
userId,
|
|
138
|
+
accessId,
|
|
139
|
+
sessionId
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const email = await transaction.MakeTheInstanceConceptLocal(
|
|
143
|
+
'the_email',
|
|
144
|
+
'alice@example.com',
|
|
145
|
+
false,
|
|
146
|
+
userId,
|
|
147
|
+
accessId,
|
|
148
|
+
sessionId
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// Create connection - RECOMMENDED: Use CreateConnection ⭐
|
|
152
|
+
// Auto-creates type concept, no manual MakeTheTypeConceptLocal() needed
|
|
153
|
+
await transaction.CreateConnection(
|
|
154
|
+
person, // Pass concept objects directly
|
|
155
|
+
email,
|
|
156
|
+
'has_email' // Type string - automatically handled
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Commit all changes to server in one atomic operation
|
|
160
|
+
await transaction.commitTransaction();
|
|
161
|
+
console.log('Transaction committed successfully');
|
|
162
|
+
|
|
163
|
+
} catch (error) {
|
|
164
|
+
// Rollback all changes if any operation fails
|
|
165
|
+
await transaction.rollbackTransaction();
|
|
166
|
+
console.error('Transaction rolled back:', error);
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Manual Transaction Tracking (Alternative Approach)
|
|
171
|
+
|
|
172
|
+
For simpler cases, you can manually track actions:
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
import { MakeTheInstanceConceptLocal, CreateConnection, LocalSyncData } from 'mftsccs-browser';
|
|
176
|
+
|
|
177
|
+
// Initialize actions tracker
|
|
178
|
+
const actions = { concepts: [], connections: [] };
|
|
179
|
+
|
|
180
|
+
// Create multiple concepts with action tracking
|
|
181
|
+
const person = await MakeTheInstanceConceptLocal(
|
|
182
|
+
'the_person', 'Alice', false, userId, accessId, sessionId, 0, actions
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const email = await MakeTheInstanceConceptLocal(
|
|
186
|
+
'the_email', 'alice@example.com', false, userId, accessId, sessionId, 0, actions
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// Create connection with action tracking - RECOMMENDED: Use CreateConnection ⭐
|
|
190
|
+
await CreateConnection(
|
|
191
|
+
person, // Pass concept objects
|
|
192
|
+
email,
|
|
193
|
+
'has_email', // Type string - auto-creates type concept
|
|
194
|
+
actions
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// Sync all tracked changes to server in one batch
|
|
198
|
+
await LocalSyncData.SyncDataOnline(undefined, actions);
|
|
199
|
+
console.log('Synced:', actions.concepts.length, 'concepts,', actions.connections.length, 'connections');
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### With Service Worker (Recommended for Production)
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
import { init, sendMessage } from 'mftsccs-browser';
|
|
206
|
+
|
|
207
|
+
// Initialize with service worker
|
|
208
|
+
await init({
|
|
209
|
+
url: 'https://your-backend-api.com',
|
|
210
|
+
clientUrl: 'https://your-app.com',
|
|
211
|
+
secureCoreModePath: true, // Enable service worker mode
|
|
212
|
+
serviceWorkerPath: '/service-worker.js'
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// All operations automatically use the service worker
|
|
216
|
+
const concepts = await sendMessage('getConcept', { id: 123 });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Core Concepts
|
|
220
|
+
|
|
221
|
+
### 1. Concept
|
|
222
|
+
A **Concept** represents an entity or node in your knowledge graph. Each concept has:
|
|
223
|
+
- A unique `id` (positive for server-synced, negative for local/virtual)
|
|
224
|
+
- A `characterValue` (text representation)
|
|
225
|
+
- `typeId` and `categoryId` for classification
|
|
226
|
+
- Relationships to other concepts via connections
|
|
227
|
+
|
|
228
|
+
**Best Practice**: Use `MakeTheInstanceConceptLocal()` to create concepts with the get-or-create pattern and transaction support. Always use the `"the_"` prefix for type parameters (e.g., `"the_name"`, `"the_email"`).
|
|
229
|
+
|
|
230
|
+
### 2. Connection
|
|
231
|
+
A **Connection** represents a directed relationship between two concepts:
|
|
232
|
+
- `ofTheConceptId` → `toTheConceptId` (from → to)
|
|
233
|
+
- `typeId` to classify the connection type
|
|
234
|
+
- `orderId` for ordering multiple connections
|
|
235
|
+
|
|
236
|
+
**Best Practice**: Use `CreateConnection()` to create connections - it's simpler and saves development time:
|
|
237
|
+
- ✅ **Automatic Type Creation**: No need to call `MakeTheTypeConceptLocal()` manually
|
|
238
|
+
- ✅ **Intuitive API**: Pass concept objects directly (not IDs)
|
|
239
|
+
- ✅ **Less Boilerplate**: Just provide the type string (e.g., `'has_email'`)
|
|
240
|
+
- ✅ **Transaction Compatible**: Works seamlessly with `LocalTransaction` for ACID compliance
|
|
241
|
+
|
|
242
|
+
Use `CreateTheConnectionLocal()` only when you need fine-grained control or already have the typeId.
|
|
243
|
+
|
|
244
|
+
### 3. Composition
|
|
245
|
+
A **Composition** is a structured grouping that includes:
|
|
246
|
+
- A main concept
|
|
247
|
+
- Associated connections
|
|
248
|
+
- Related concepts
|
|
249
|
+
- Nested sub-compositions
|
|
250
|
+
|
|
251
|
+
### 4. Transaction (ACID Compliance) ⭐
|
|
252
|
+
A **Transaction** provides atomic, consistent operations with commit and rollback capabilities:
|
|
253
|
+
- **Atomicity**: All operations succeed or fail together
|
|
254
|
+
- **Consistency**: Data remains in valid state
|
|
255
|
+
- **Isolation**: Transactions are isolated from each other
|
|
256
|
+
- **Durability**: Committed changes are permanent
|
|
257
|
+
|
|
258
|
+
**Why Transactions Matter:**
|
|
259
|
+
- ✅ **Bulk Operations**: Send multiple concepts/connections in a single batch to the server
|
|
260
|
+
- ✅ **Data Integrity**: Guarantee all-or-nothing operations (no partial updates)
|
|
261
|
+
- ✅ **Rollback Support**: Undo all changes if any operation fails
|
|
262
|
+
- ✅ **Performance**: Reduce network calls by batching operations
|
|
263
|
+
- ✅ **ACID Compliant**: Ensure database-level consistency guarantees
|
|
264
|
+
|
|
265
|
+
**Best Practice**: Use `LocalTransaction` class for all multi-step operations to ensure data consistency and optimal performance.
|
|
266
|
+
|
|
267
|
+
### 5. FreeschemaQuery (Flexible Querying) ⭐
|
|
268
|
+
A **FreeschemaQuery** is the primary querying mechanism for retrieving data from your knowledge graph:
|
|
269
|
+
- **Schema-Free**: Query without rigid schema constraints
|
|
270
|
+
- **Declarative**: Describe what you want, not how to get it
|
|
271
|
+
- **Filters**: Complex filtering with AND/OR logic operators
|
|
272
|
+
- **Nested Queries**: Navigate relationships through multiple levels
|
|
273
|
+
- **Multiple Formats**: Get data in the format that suits your use case
|
|
274
|
+
- **Observable**: Real-time updates when data changes
|
|
275
|
+
|
|
276
|
+
**Key Capabilities:**
|
|
277
|
+
- ✅ **Type-Based Queries**: Find all concepts of a specific type (e.g., "person", "organization")
|
|
278
|
+
- ✅ **Complex Filters**: Combine multiple filters with logical operators (=, !=, like, >, <, >=, <=)
|
|
279
|
+
- ✅ **Relationship Navigation**: Query connected concepts through typeConnections
|
|
280
|
+
- ✅ **Deep Nesting**: Build complex queries by composing multiple FreeschemaQuery objects
|
|
281
|
+
- ✅ **Pagination**: Handle large datasets efficiently with page/inpage parameters
|
|
282
|
+
- ✅ **Reactive Updates**: Use observables for automatic UI updates
|
|
283
|
+
|
|
284
|
+
**Best Practice**: Use `FreeschemaQuery` for all data retrieval operations. See the [FreeschemaQuery Guide](./docs/FREESCHEMA_QUERY.md) for comprehensive examples.
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
const transaction = new LocalTransaction();
|
|
288
|
+
await transaction.initialize();
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
// Multiple operations tracked automatically
|
|
292
|
+
await transaction.MakeTheInstanceConceptLocal(...);
|
|
293
|
+
await transaction.CreateConnectionBetweenTwoConceptsLocal(...);
|
|
294
|
+
|
|
295
|
+
// Commit all changes in one atomic batch
|
|
296
|
+
await transaction.commitTransaction();
|
|
297
|
+
} catch (error) {
|
|
298
|
+
// Rollback if anything fails
|
|
299
|
+
await transaction.rollbackTransaction();
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
For detailed explanations, see [Core Concepts Documentation](./docs/CORE_CONCEPTS.md).
|
|
304
|
+
|
|
305
|
+
## Documentation
|
|
306
|
+
|
|
307
|
+
Comprehensive documentation is available throughout the codebase with JSDoc comments on all functions, classes, and methods.
|
|
308
|
+
|
|
309
|
+
### Documentation Guides
|
|
310
|
+
|
|
311
|
+
- **[Getting Started Guide](./docs/GETTING_STARTED.md)**: Detailed initialization and first steps
|
|
312
|
+
- **[Core Concepts](./docs/CORE_CONCEPTS.md)**: In-depth explanation of concepts, connections, and compositions
|
|
313
|
+
- **[FreeschemaQuery Guide](./docs/FREESCHEMA_QUERY.md)**: Complete querying system with filters, nested queries, and examples ⭐
|
|
314
|
+
- **[Widget System Guide](./docs/WIDGET_SYSTEM.md)**: Component framework for building reactive UIs with lifecycle management ⭐
|
|
315
|
+
|
|
316
|
+
### Inline Documentation
|
|
317
|
+
|
|
318
|
+
All code is fully documented with concise JSDoc comments:
|
|
319
|
+
|
|
320
|
+
#### API Layer (`src/Api/`)
|
|
321
|
+
- **Create APIs**: Creating concepts, connections, characters, text data, and ghost syncing
|
|
322
|
+
- **Get/Retrieve APIs**: Fetching concepts, connections, compositions (single and bulk operations)
|
|
323
|
+
- **Search APIs**: Internal search, linker-based queries, freeschema queries, recursive searches
|
|
324
|
+
- **Delete APIs**: Concept and connection deletion (single and bulk)
|
|
325
|
+
- **Authentication APIs**: Login, signin, signup functionality
|
|
326
|
+
- **Session APIs**: Session creation and visit tracking
|
|
327
|
+
- **Utility APIs**: Type concepts, prototypes, translations, images
|
|
328
|
+
|
|
329
|
+
#### Services Layer (`src/Services/`)
|
|
330
|
+
- **Local Services** (`src/Services/Local/`): Offline-first operations with IndexedDB
|
|
331
|
+
- Concept operations (create, get, update, delete)
|
|
332
|
+
- Connection management (local connections, named connections)
|
|
333
|
+
- Composition handling (JSON conversion, patching, bulk retrieval)
|
|
334
|
+
- Binary tree indexing for performance
|
|
335
|
+
- Virtual ID system (negative IDs for local, positive for synced)
|
|
336
|
+
- **Core Services**: Main business logic for concepts, connections, and compositions
|
|
337
|
+
|
|
338
|
+
#### Widget System (`src/Widgets/`)
|
|
339
|
+
- **BaseWidget**: Foundation widget class with DOM management
|
|
340
|
+
- **StatefulWidget**: Stateful widgets with full lifecycle (mount, render, update)
|
|
341
|
+
- **BuilderStatefulWidget**: Advanced builder pattern widgets
|
|
342
|
+
- **RenderServices**: Page and widget rendering utilities
|
|
343
|
+
- **CacheWidget**: Generic caching system with LRU and TTL support
|
|
344
|
+
- **Observable Pattern**: BaseObserver for reactive UI updates
|
|
345
|
+
|
|
346
|
+
#### Reactive Wrappers (`src/WrapperFunctions/`)
|
|
347
|
+
- **DependencyObserver**: Base observable class for reactive state management
|
|
348
|
+
- **Observable Wrappers**: GetComposition, GetLink, RecursiveSearch, SchemaQuery observables
|
|
349
|
+
- Automatic change detection and subscriber notifications for real-time updates
|
|
350
|
+
|
|
351
|
+
## API Overview
|
|
352
|
+
|
|
353
|
+
### Creating Data (Recommended Approach)
|
|
354
|
+
|
|
355
|
+
```javascript
|
|
356
|
+
import {
|
|
357
|
+
MakeTheInstanceConceptLocal,
|
|
358
|
+
CreateConnection,
|
|
359
|
+
CreateTheCompositionLocal
|
|
360
|
+
} from 'mftsccs-browser';
|
|
361
|
+
|
|
362
|
+
// Create concepts (local-first, with get-or-create pattern)
|
|
363
|
+
const person = await MakeTheInstanceConceptLocal(
|
|
364
|
+
'the_person', // Type with "the_" prefix
|
|
365
|
+
'Alice', // Value
|
|
366
|
+
false, // composition mode: false = get-or-create, true = always create new
|
|
367
|
+
userId,
|
|
368
|
+
accessId,
|
|
369
|
+
sessionId
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
const email = await MakeTheInstanceConceptLocal(
|
|
373
|
+
'the_email',
|
|
374
|
+
'alice@example.com',
|
|
375
|
+
false,
|
|
376
|
+
userId,
|
|
377
|
+
accessId,
|
|
378
|
+
sessionId
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
// Create connection - RECOMMENDED: CreateConnection (simplified API) ⭐
|
|
382
|
+
// Automatically creates the connection type concept if it doesn't exist
|
|
383
|
+
const connection = await CreateConnection(
|
|
384
|
+
person, // Source concept object
|
|
385
|
+
email, // Target concept object
|
|
386
|
+
'has_email' // Type string - auto-creates type concept
|
|
387
|
+
);
|
|
388
|
+
// ✅ No need to call MakeTheTypeConceptLocal() manually!
|
|
389
|
+
// ✅ Pass concept objects directly (not IDs)
|
|
390
|
+
// ✅ Saves developer time and reduces boilerplate
|
|
391
|
+
|
|
392
|
+
// Alternative: CreateTheConnectionLocal (manual type creation required)
|
|
393
|
+
// Use this if you already have the typeId or need fine-grained control
|
|
394
|
+
const connectionTypeId = await MakeTheTypeConceptLocal('has_email', userId, userId, userId);
|
|
395
|
+
const manualConnection = await CreateTheConnectionLocal(
|
|
396
|
+
person.id, // Must extract ID manually
|
|
397
|
+
email.id, // Must extract ID manually
|
|
398
|
+
connectionTypeId, // Must create type concept first
|
|
399
|
+
1000 // orderId
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
// Create a composition from JSON (local-first)
|
|
403
|
+
const composition = await CreateTheCompositionLocal(
|
|
404
|
+
{
|
|
405
|
+
the_title: 'My Project',
|
|
406
|
+
the_description: 'Project details...',
|
|
407
|
+
the_status: 'Active'
|
|
408
|
+
},
|
|
409
|
+
mainConceptId,
|
|
410
|
+
userId
|
|
411
|
+
);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Using Transactions for Batch Operations
|
|
415
|
+
|
|
416
|
+
```javascript
|
|
417
|
+
import { MakeTheInstanceConceptLocal, LocalSyncData } from 'mftsccs-browser';
|
|
418
|
+
|
|
419
|
+
// Track all changes in a transaction
|
|
420
|
+
const actions = { concepts: [], connections: [] };
|
|
421
|
+
|
|
422
|
+
// Create multiple concepts with transaction tracking
|
|
423
|
+
const project = await MakeTheInstanceConceptLocal(
|
|
424
|
+
'the_project', 'New Project', false, userId, accessId, sessionId, undefined, actions
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
const task1 = await MakeTheInstanceConceptLocal(
|
|
428
|
+
'the_task', 'Task 1', false, userId, accessId, sessionId, undefined, actions
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
const task2 = await MakeTheInstanceConceptLocal(
|
|
432
|
+
'the_task', 'Task 2', false, userId, accessId, sessionId, undefined, actions
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
// Sync all changes to server in one batch
|
|
436
|
+
await LocalSyncData.SyncDataOnline(undefined, actions);
|
|
437
|
+
console.log(`Synced ${actions.concepts.length} concepts and ${actions.connections.length} connections`);
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Retrieving Data
|
|
441
|
+
|
|
442
|
+
```javascript
|
|
443
|
+
import { GetTheConceptLocal, GetCompositionLocal } from 'mftsccs-browser';
|
|
444
|
+
|
|
445
|
+
// Get a concept by ID (works with both positive and negative IDs)
|
|
446
|
+
const concept = await GetTheConceptLocal(conceptId);
|
|
447
|
+
|
|
448
|
+
// Get a composition with all related data
|
|
449
|
+
const composition = await GetCompositionLocal(conceptId);
|
|
450
|
+
|
|
451
|
+
// Get composition with ID wrapper (DATAID format)
|
|
452
|
+
const compositionWithId = await GetCompositionLocalWithId(conceptId);
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Querying Data (FreeschemaQuery) ⭐
|
|
456
|
+
|
|
457
|
+
FreeschemaQuery is the recommended way to query your knowledge graph with flexible filtering and relationship navigation.
|
|
458
|
+
|
|
459
|
+
```javascript
|
|
460
|
+
import { FreeschemaQuery, FreeschemaQueryApi, FilterSearch, DATAID } from 'mftsccs-browser';
|
|
461
|
+
|
|
462
|
+
// Simple type-based query
|
|
463
|
+
const query = new FreeschemaQuery();
|
|
464
|
+
query.type = "person"; // Query all person concepts
|
|
465
|
+
query.outputFormat = DATAID; // Structured output
|
|
466
|
+
query.inpage = 20; // 20 results per page
|
|
467
|
+
query.page = 1; // First page
|
|
468
|
+
|
|
469
|
+
const results = await FreeschemaQueryApi(query, authToken);
|
|
470
|
+
|
|
471
|
+
// Query with filters
|
|
472
|
+
const filterQuery = new FreeschemaQuery();
|
|
473
|
+
filterQuery.type = "employee";
|
|
474
|
+
|
|
475
|
+
const deptFilter = new FilterSearch();
|
|
476
|
+
deptFilter.name = "dept_filter";
|
|
477
|
+
deptFilter.type = "the_department";
|
|
478
|
+
deptFilter.search = "Engineering";
|
|
479
|
+
deptFilter.logicoperator = "=";
|
|
480
|
+
|
|
481
|
+
filterQuery.filters = [deptFilter];
|
|
482
|
+
filterQuery.filterLogic = "( dept_filter )";
|
|
483
|
+
|
|
484
|
+
const engineers = await FreeschemaQueryApi(filterQuery, authToken);
|
|
485
|
+
|
|
486
|
+
// Query with nested relationships
|
|
487
|
+
const personQuery = new FreeschemaQuery();
|
|
488
|
+
personQuery.type = "person";
|
|
489
|
+
personQuery.selectors = ["the_name"];
|
|
490
|
+
|
|
491
|
+
// Get emails (nested query)
|
|
492
|
+
const emailQuery = new FreeschemaQuery();
|
|
493
|
+
emailQuery.typeConnection = "has_email";
|
|
494
|
+
emailQuery.name = "emails";
|
|
495
|
+
emailQuery.selectors = ["the_email"];
|
|
496
|
+
|
|
497
|
+
personQuery.freeschemaQueries = [emailQuery];
|
|
498
|
+
|
|
499
|
+
const personsWithEmails = await FreeschemaQueryApi(personQuery, authToken);
|
|
500
|
+
// Returns persons with their emails nested in the results
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
**See the [FreeschemaQuery Guide](./docs/FREESCHEMA_QUERY.md) for complete documentation with advanced examples.**
|
|
504
|
+
|
|
505
|
+
### Legacy Search Functions
|
|
506
|
+
|
|
507
|
+
These functions are still supported but FreeschemaQuery is recommended for new code:
|
|
508
|
+
|
|
509
|
+
```javascript
|
|
510
|
+
import { SearchConcept, SearchWithLinker, SearchWithTypeAndLinker } from 'mftsccs-browser';
|
|
511
|
+
|
|
512
|
+
// Simple search
|
|
513
|
+
const results = await SearchConcept('search term');
|
|
514
|
+
|
|
515
|
+
// Search with relationship filter
|
|
516
|
+
const linkedResults = await SearchWithLinker('search term', linkerConceptId);
|
|
517
|
+
|
|
518
|
+
// Advanced search with type and linker
|
|
519
|
+
const typedResults = await SearchWithTypeAndLinker('search term', typeId, linkerConceptId);
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Deleting Data
|
|
523
|
+
|
|
524
|
+
```javascript
|
|
525
|
+
import { DeleteConceptById, DeleteConnectionById } from 'mftsccs-browser';
|
|
526
|
+
|
|
527
|
+
// Delete a concept
|
|
528
|
+
await DeleteConceptById(conceptId);
|
|
529
|
+
|
|
530
|
+
// Delete a connection
|
|
531
|
+
await DeleteConnectionById(connectionId);
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
## Configuration
|
|
535
|
+
|
|
536
|
+
### Initialization Options
|
|
537
|
+
|
|
538
|
+
```javascript
|
|
539
|
+
await init({
|
|
540
|
+
// Required: Backend API URL
|
|
541
|
+
url: 'https://api.example.com',
|
|
542
|
+
|
|
543
|
+
// Required: Your application URL
|
|
544
|
+
clientUrl: 'https://app.example.com',
|
|
545
|
+
|
|
546
|
+
// Optional: Enable service worker mode (recommended for production)
|
|
547
|
+
secureCoreModePath: false,
|
|
548
|
+
|
|
549
|
+
// Optional: Custom service worker path
|
|
550
|
+
serviceWorkerPath: '/sw.js',
|
|
551
|
+
|
|
552
|
+
// Optional: Enable detailed logging
|
|
553
|
+
makeBaseSecure: true,
|
|
554
|
+
|
|
555
|
+
// Optional: Custom configuration
|
|
556
|
+
identificationKey: 'your-app-key'
|
|
557
|
+
});
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### Environment Variables
|
|
561
|
+
|
|
562
|
+
For development, create a `.env.development` file:
|
|
563
|
+
|
|
564
|
+
```env
|
|
565
|
+
BACKEND_URL=https://dev-api.example.com
|
|
566
|
+
CLIENT_URL=http://localhost:3000
|
|
567
|
+
SECURE_MODE=false
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
For production, create a `.env.production` file:
|
|
571
|
+
|
|
572
|
+
```env
|
|
573
|
+
BACKEND_URL=https://api.example.com
|
|
574
|
+
CLIENT_URL=https://app.example.com
|
|
575
|
+
SECURE_MODE=true
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
## Examples
|
|
579
|
+
|
|
580
|
+
### Example 1: Building a Knowledge Graph with Transactions
|
|
581
|
+
|
|
582
|
+
```javascript
|
|
583
|
+
import { init, LocalTransaction, GetCompositionLocal } from 'mftsccs-browser';
|
|
584
|
+
|
|
585
|
+
// Initialize
|
|
586
|
+
await init({ url: API_URL, clientUrl: CLIENT_URL });
|
|
587
|
+
|
|
588
|
+
// Create a transaction for atomic operations
|
|
589
|
+
const transaction = new LocalTransaction();
|
|
590
|
+
await transaction.initialize();
|
|
591
|
+
|
|
592
|
+
try {
|
|
593
|
+
// Create concepts within the transaction
|
|
594
|
+
const person = await transaction.MakeTheInstanceConceptLocal(
|
|
595
|
+
'the_person', 'John Doe', false, userId, accessId, sessionId
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
const company = await transaction.MakeTheInstanceConceptLocal(
|
|
599
|
+
'the_organization', 'Acme Corp', false, userId, accessId, sessionId
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
const role = await transaction.MakeTheInstanceConceptLocal(
|
|
603
|
+
'the_role', 'Software Engineer', false, userId, accessId, sessionId
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
// Create connections within the transaction using simplified API ⭐
|
|
607
|
+
// Auto-creates type concepts - no manual MakeTheTypeConceptLocal() needed!
|
|
608
|
+
await transaction.CreateConnection(person, company, 'works_at');
|
|
609
|
+
await transaction.CreateConnection(person, role, 'has_role');
|
|
610
|
+
|
|
611
|
+
// Commit all changes atomically to server
|
|
612
|
+
await transaction.commitTransaction();
|
|
613
|
+
console.log('Knowledge graph created and synced successfully');
|
|
614
|
+
|
|
615
|
+
// Get the full composition (works with synced IDs)
|
|
616
|
+
const personProfile = await GetCompositionLocal(person.id);
|
|
617
|
+
console.log('Person Profile:', personProfile);
|
|
618
|
+
|
|
619
|
+
} catch (error) {
|
|
620
|
+
// Rollback all changes if anything fails
|
|
621
|
+
await transaction.rollbackTransaction();
|
|
622
|
+
console.error('Transaction failed and rolled back:', error);
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
### Example 2: Searching and Filtering
|
|
627
|
+
|
|
628
|
+
```javascript
|
|
629
|
+
import { SearchConcept, SearchWithTypeAndLinker } from 'mftsccs-browser';
|
|
630
|
+
|
|
631
|
+
// Search for all concepts matching a term
|
|
632
|
+
const allResults = await SearchConcept('software');
|
|
633
|
+
|
|
634
|
+
// Search for people who work at a specific company
|
|
635
|
+
const employees = await SearchWithTypeAndLinker(
|
|
636
|
+
'engineer',
|
|
637
|
+
TYPE_PERSON,
|
|
638
|
+
companyConceptId
|
|
639
|
+
);
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Example 3: Offline-First Application with Transactions
|
|
643
|
+
|
|
644
|
+
```javascript
|
|
645
|
+
import { init, LocalTransaction, GetTheConceptLocal } from 'mftsccs-browser';
|
|
646
|
+
|
|
647
|
+
// Initialize
|
|
648
|
+
await init({ url: API_URL, clientUrl: CLIENT_URL });
|
|
649
|
+
|
|
650
|
+
// Create a transaction that works offline
|
|
651
|
+
const transaction = new LocalTransaction();
|
|
652
|
+
await transaction.initialize();
|
|
653
|
+
|
|
654
|
+
try {
|
|
655
|
+
// Create concepts offline - gets negative virtual IDs
|
|
656
|
+
const draft = await transaction.MakeTheInstanceConceptLocal(
|
|
657
|
+
'the_note', 'Draft Article', false, userId, accessId, sessionId
|
|
658
|
+
);
|
|
659
|
+
console.log('Created offline with virtual ID:', draft.id); // Negative ID (e.g., -12345)
|
|
660
|
+
|
|
661
|
+
// Create a composition from JSON
|
|
662
|
+
const article = await transaction.CreateTheCompositionLocal(
|
|
663
|
+
{
|
|
664
|
+
the_title: 'My Article',
|
|
665
|
+
the_content: 'Article content here...',
|
|
666
|
+
the_author: 'John Doe',
|
|
667
|
+
the_status: 'Draft'
|
|
668
|
+
},
|
|
669
|
+
draft.id,
|
|
670
|
+
userId,
|
|
671
|
+
accessId,
|
|
672
|
+
sessionId
|
|
673
|
+
);
|
|
674
|
+
|
|
675
|
+
// Work continues offline with virtual IDs...
|
|
676
|
+
console.log('Transaction has:', transaction.actions.concepts.length, 'concepts');
|
|
677
|
+
|
|
678
|
+
// When online, commit transaction - syncs everything atomically
|
|
679
|
+
await transaction.commitTransaction();
|
|
680
|
+
console.log('All offline changes synced to server');
|
|
681
|
+
|
|
682
|
+
// After sync, virtual IDs become positive (real server IDs)
|
|
683
|
+
// Ghost IDs preserve original negative IDs for local references
|
|
684
|
+
const synced = await GetTheConceptLocal(draft.id);
|
|
685
|
+
console.log('Real ID:', synced.id, '| Ghost ID:', synced.ghostId);
|
|
686
|
+
|
|
687
|
+
} catch (error) {
|
|
688
|
+
// Rollback if sync fails (stays offline)
|
|
689
|
+
await transaction.rollbackTransaction();
|
|
690
|
+
console.error('Transaction rolled back, data remains local:', error);
|
|
691
|
+
}
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
### Example 4: Reactive State Management with Observables
|
|
695
|
+
|
|
696
|
+
```javascript
|
|
697
|
+
import { GetCompositionListener, DependencyObserver } from 'mftsccs-browser';
|
|
698
|
+
|
|
699
|
+
// Create an observable that watches a composition
|
|
700
|
+
const compositionObserver = GetCompositionListener(
|
|
701
|
+
conceptId,
|
|
702
|
+
userId,
|
|
703
|
+
'JUSTDATA', // Output format
|
|
704
|
+
1, // Page number
|
|
705
|
+
10 // Items per page
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
// Subscribe to changes
|
|
709
|
+
compositionObserver.subscribe((data) => {
|
|
710
|
+
console.log('Composition updated:', data);
|
|
711
|
+
// Update your UI automatically when data changes
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
// The observer automatically detects when:
|
|
715
|
+
// - The concept is modified
|
|
716
|
+
// - Connected concepts are updated
|
|
717
|
+
// - Connections are added/removed
|
|
718
|
+
// All subscribers are notified with fresh data
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
### Example 5: Building UI with Widget System
|
|
722
|
+
|
|
723
|
+
The Widget System provides a React-like component framework for building interactive UIs.
|
|
724
|
+
|
|
725
|
+
```javascript
|
|
726
|
+
import { StatefulWidget, FreeschemaQuery, SchemaQueryListener, DATAID } from 'mftsccs-browser';
|
|
727
|
+
|
|
728
|
+
class PersonListWidget extends StatefulWidget {
|
|
729
|
+
constructor() {
|
|
730
|
+
super();
|
|
731
|
+
this.state = {
|
|
732
|
+
persons: [],
|
|
733
|
+
loading: true
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// Lifecycle: Setup after mount
|
|
738
|
+
before_render() {
|
|
739
|
+
this.setupObserver();
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
setupObserver() {
|
|
743
|
+
// Create query
|
|
744
|
+
const query = new FreeschemaQuery();
|
|
745
|
+
query.type = "person";
|
|
746
|
+
query.outputFormat = DATAID;
|
|
747
|
+
query.inpage = 10;
|
|
748
|
+
query.selectors = ["the_name", "the_email"];
|
|
749
|
+
|
|
750
|
+
// Nested query for phone numbers
|
|
751
|
+
const phoneQuery = new FreeschemaQuery();
|
|
752
|
+
phoneQuery.typeConnection = "has_phone";
|
|
753
|
+
phoneQuery.name = "phone";
|
|
754
|
+
phoneQuery.selectors = ["the_phone"];
|
|
755
|
+
|
|
756
|
+
query.freeschemaQueries = [phoneQuery];
|
|
757
|
+
|
|
758
|
+
// Subscribe to real-time updates
|
|
759
|
+
SchemaQueryListener(query, "").subscribe((results) => {
|
|
760
|
+
this.state.persons = results;
|
|
761
|
+
this.state.loading = false;
|
|
762
|
+
this.render(); // Auto-update UI
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Template
|
|
767
|
+
getHtml() {
|
|
768
|
+
if (this.state.loading) {
|
|
769
|
+
return '<div class="loading">Loading persons...</div>';
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const personList = this.state.persons.map(p => `
|
|
773
|
+
<div class="person-card">
|
|
774
|
+
<h3>${p.person.the_name.characterValue}</h3>
|
|
775
|
+
<p>Email: ${p.person.the_email?.characterValue || 'N/A'}</p>
|
|
776
|
+
<p>Phone: ${p.person.phone?.the_phone?.characterValue || 'N/A'}</p>
|
|
777
|
+
</div>
|
|
778
|
+
`).join('');
|
|
779
|
+
|
|
780
|
+
return `
|
|
781
|
+
<div class="person-list">
|
|
782
|
+
<h2>Team Members</h2>
|
|
783
|
+
${personList}
|
|
784
|
+
</div>
|
|
785
|
+
`;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// Mount widget
|
|
790
|
+
const widget = new PersonListWidget();
|
|
791
|
+
widget.mount(document.getElementById('app'));
|
|
792
|
+
|
|
793
|
+
// Widget automatically updates when:
|
|
794
|
+
// - New persons are created
|
|
795
|
+
// - Existing persons are modified
|
|
796
|
+
// - Phone numbers change
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
**See the [Widget System Guide](./docs/WIDGET_SYSTEM.md) for complete documentation including:**
|
|
800
|
+
- Lifecycle hooks (before_render, render, after_render)
|
|
801
|
+
- State management and change detection
|
|
802
|
+
- Parent-child widget composition
|
|
803
|
+
- Event handling
|
|
804
|
+
- BuilderStatefulWidget for dynamic code execution
|
|
805
|
+
- Complete examples (Todo list, Dashboard, Forms)
|
|
806
|
+
|
|
807
|
+
## Development
|
|
808
|
+
|
|
809
|
+
### Setup for Development
|
|
810
|
+
|
|
811
|
+
1. Clone the repository:
|
|
812
|
+
```bash
|
|
813
|
+
git clone https://github.com/Mentor-Friends/tsccs-dev.git
|
|
814
|
+
cd tsccs-dev
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
2. Install dependencies:
|
|
818
|
+
```bash
|
|
819
|
+
npm install
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
3. Create environment file:
|
|
823
|
+
```bash
|
|
824
|
+
cp .env.example .env.development
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
4. Edit `.env.development` with your configuration
|
|
828
|
+
|
|
829
|
+
### Build Commands
|
|
830
|
+
|
|
831
|
+
```bash
|
|
832
|
+
# Development build with watch mode
|
|
833
|
+
npm run dev
|
|
834
|
+
|
|
835
|
+
# Production build
|
|
836
|
+
npm run build
|
|
837
|
+
|
|
838
|
+
# Start production bundle
|
|
839
|
+
npm start
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
### Project Structure
|
|
843
|
+
|
|
844
|
+
```
|
|
845
|
+
src/
|
|
846
|
+
├── Api/ # API endpoint wrappers (55+ documented functions)
|
|
847
|
+
│ ├── Create/ # Create operations (concepts, connections, ghost sync)
|
|
848
|
+
│ ├── Delete/ # Delete operations
|
|
849
|
+
│ ├── Search/ # Search APIs (internal, linker, freeschema)
|
|
850
|
+
│ ├── Session/ # Session management
|
|
851
|
+
│ ├── SearchConcept/ # Concept search utilities
|
|
852
|
+
│ └── ... # Get, Retrieve, and utility APIs
|
|
853
|
+
├── Services/ # Business logic and operations
|
|
854
|
+
│ ├── Local/ # Local/offline operations (21 documented files)
|
|
855
|
+
│ └── ... # Core services
|
|
856
|
+
├── Widgets/ # UI widget system (13 documented files)
|
|
857
|
+
│ ├── BaseWidget.ts # Foundation widget class
|
|
858
|
+
│ ├── StatefulWidget.ts # Stateful widget with lifecycle
|
|
859
|
+
│ └── ... # Render services, caching, observers
|
|
860
|
+
├── WrapperFunctions/ # Reactive observable wrappers (8 documented files)
|
|
861
|
+
├── DataStructures/ # Core data models (Concept, Connection, etc.)
|
|
862
|
+
├── Database/ # IndexedDB management
|
|
863
|
+
├── Constants/ # Configuration constants
|
|
864
|
+
├── Middleware/ # Logging, monitoring, error handling
|
|
865
|
+
├── ServiceWorker/ # Service worker implementation
|
|
866
|
+
└── app.ts # Main entry point and exports
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
### Documentation Coverage
|
|
870
|
+
|
|
871
|
+
**All code is fully documented with concise JSDoc comments:**
|
|
872
|
+
|
|
873
|
+
- ✅ **55+ API functions** documented (Create, Get, Search, Delete, Session, etc.)
|
|
874
|
+
- ✅ **21 Local Service files** documented (offline-first operations)
|
|
875
|
+
- ✅ **13 Widget files** documented (UI framework with 76+ methods)
|
|
876
|
+
- ✅ **8 Observable wrappers** documented (reactive state management)
|
|
877
|
+
- ✅ All parameters, return types, and complex logic explained
|
|
878
|
+
- ✅ Examples provided for key functions
|
|
879
|
+
- ✅ Professional, concise style for quick understanding
|
|
880
|
+
|
|
881
|
+
## Publishing to npm
|
|
882
|
+
|
|
883
|
+
### Prerequisites
|
|
884
|
+
|
|
885
|
+
1. Ensure you have an npm account: [Sign up at npmjs.com](https://www.npmjs.com/signup)
|
|
886
|
+
2. Login to npm from your terminal:
|
|
887
|
+
```bash
|
|
888
|
+
npm login
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
### Pre-publish Checklist
|
|
892
|
+
|
|
893
|
+
Before publishing, ensure:
|
|
894
|
+
|
|
895
|
+
- [ ] Version number is updated in [package.json](package.json:3)
|
|
896
|
+
- [ ] All tests pass: `npm test`
|
|
897
|
+
- [ ] Build succeeds: `npm run build`
|
|
898
|
+
- [ ] [README.md](README.md) is up to date
|
|
899
|
+
- [ ] [CHANGELOG.md](CHANGELOG.md) documents changes (if applicable)
|
|
900
|
+
- [ ] Git repository is clean and committed
|
|
901
|
+
|
|
902
|
+
### Publishing Steps
|
|
903
|
+
|
|
904
|
+
#### 1. Update Version
|
|
905
|
+
|
|
906
|
+
Use semantic versioning (MAJOR.MINOR.PATCH):
|
|
907
|
+
|
|
908
|
+
```bash
|
|
909
|
+
# For bug fixes
|
|
910
|
+
npm version patch
|
|
911
|
+
|
|
912
|
+
# For new features (backwards compatible)
|
|
913
|
+
npm version minor
|
|
914
|
+
|
|
915
|
+
# For breaking changes
|
|
916
|
+
npm version major
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
This automatically:
|
|
920
|
+
- Updates `version` in package.json
|
|
921
|
+
- Creates a git commit
|
|
922
|
+
- Creates a git tag
|
|
923
|
+
|
|
924
|
+
#### 2. Build the Package
|
|
925
|
+
|
|
926
|
+
```bash
|
|
927
|
+
npm run build
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
This creates the `dist/` folder with:
|
|
931
|
+
- `dist/main.bundle.js` - Main bundle
|
|
932
|
+
- `dist/types/` - TypeScript declarations
|
|
933
|
+
|
|
934
|
+
#### 3. Test the Package Locally (Optional but Recommended)
|
|
935
|
+
|
|
936
|
+
```bash
|
|
937
|
+
# Create a tarball
|
|
938
|
+
npm pack
|
|
939
|
+
|
|
940
|
+
# This creates mftsccs-browser-X.X.X.tgz
|
|
941
|
+
# Test it in another project:
|
|
942
|
+
cd /path/to/test-project
|
|
943
|
+
npm install /path/to/mftsccs-browser-X.X.X.tgz
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
#### 4. Publish to npm
|
|
947
|
+
|
|
948
|
+
```bash
|
|
949
|
+
# For beta/pre-release versions
|
|
950
|
+
npm publish --tag beta
|
|
951
|
+
|
|
952
|
+
# For stable releases
|
|
953
|
+
npm publish
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
#### 5. Push to Git
|
|
957
|
+
|
|
958
|
+
```bash
|
|
959
|
+
git push origin main --tags
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
### Publishing Beta Versions
|
|
963
|
+
|
|
964
|
+
For testing before stable release:
|
|
965
|
+
|
|
966
|
+
```bash
|
|
967
|
+
# Update to beta version
|
|
968
|
+
npm version 2.1.171-beta
|
|
969
|
+
|
|
970
|
+
# Build
|
|
971
|
+
npm run build
|
|
972
|
+
|
|
973
|
+
# Publish with beta tag
|
|
974
|
+
npm publish --tag beta
|
|
975
|
+
|
|
976
|
+
# Users can install with:
|
|
977
|
+
# npm install mftsccs-browser@beta
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
### Automated Publishing with GitHub Actions (Recommended)
|
|
981
|
+
|
|
982
|
+
Create `.github/workflows/publish.yml`:
|
|
983
|
+
|
|
984
|
+
```yaml
|
|
985
|
+
name: Publish to npm
|
|
986
|
+
|
|
987
|
+
on:
|
|
988
|
+
release:
|
|
989
|
+
types: [created]
|
|
990
|
+
|
|
991
|
+
jobs:
|
|
992
|
+
publish:
|
|
993
|
+
runs-on: ubuntu-latest
|
|
994
|
+
steps:
|
|
995
|
+
- uses: actions/checkout@v3
|
|
996
|
+
- uses: actions/setup-node@v3
|
|
997
|
+
with:
|
|
998
|
+
node-version: '18'
|
|
999
|
+
registry-url: 'https://registry.npmjs.org'
|
|
1000
|
+
- run: npm install
|
|
1001
|
+
- run: npm run build
|
|
1002
|
+
- run: npm test
|
|
1003
|
+
- run: npm publish
|
|
1004
|
+
env:
|
|
1005
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
1006
|
+
```
|
|
1007
|
+
|
|
1008
|
+
Then:
|
|
1009
|
+
1. Add your npm token to GitHub Secrets as `NPM_TOKEN`
|
|
1010
|
+
2. Create a GitHub release
|
|
1011
|
+
3. The package publishes automatically
|
|
1012
|
+
|
|
1013
|
+
### Managing Versions
|
|
1014
|
+
|
|
1015
|
+
```bash
|
|
1016
|
+
# View current version
|
|
1017
|
+
npm version
|
|
1018
|
+
|
|
1019
|
+
# View published versions
|
|
1020
|
+
npm view mftsccs-browser versions
|
|
1021
|
+
|
|
1022
|
+
# Unpublish a version (within 72 hours)
|
|
1023
|
+
npm unpublish mftsccs-browser@2.1.170-beta
|
|
1024
|
+
|
|
1025
|
+
# Deprecate a version
|
|
1026
|
+
npm deprecate mftsccs-browser@2.1.170-beta "Use version 2.1.171 instead"
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
### Package Scope and Access
|
|
1030
|
+
|
|
1031
|
+
This package is currently unscoped. To publish as a scoped package:
|
|
1032
|
+
|
|
1033
|
+
1. Update [package.json](package.json:2):
|
|
1034
|
+
```json
|
|
1035
|
+
{
|
|
1036
|
+
"name": "@mentor-friends/mftsccs-browser"
|
|
1037
|
+
}
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
2. Publish with public access:
|
|
1041
|
+
```bash
|
|
1042
|
+
npm publish --access public
|
|
1043
|
+
```
|
|
1044
|
+
|
|
1045
|
+
## Contributing
|
|
1046
|
+
|
|
1047
|
+
Contributions are welcome! Please follow these steps:
|
|
1048
|
+
|
|
1049
|
+
1. Fork the repository
|
|
1050
|
+
2. Create a feature branch: `git checkout -b feature/my-feature`
|
|
1051
|
+
3. Make your changes
|
|
1052
|
+
4. Add tests for new functionality
|
|
1053
|
+
5. Commit your changes: `git commit -am 'Add new feature'`
|
|
1054
|
+
6. Push to the branch: `git push origin feature/my-feature`
|
|
1055
|
+
7. Submit a pull request
|
|
1056
|
+
|
|
1057
|
+
### Coding Standards
|
|
1058
|
+
|
|
1059
|
+
- Follow TypeScript best practices
|
|
1060
|
+
- Maintain existing code style
|
|
1061
|
+
- Add concise JSDoc comments for all public APIs and functions
|
|
1062
|
+
- Keep descriptions brief (1-3 sentences)
|
|
1063
|
+
- Document all parameters with types
|
|
1064
|
+
- Include return value documentation
|
|
1065
|
+
- Add examples for complex functions
|
|
1066
|
+
- Mark complex logic with "Complex Logic" callouts
|
|
1067
|
+
- Write unit tests for new features
|
|
1068
|
+
- Update documentation as needed
|
|
1069
|
+
|
|
1070
|
+
## Support
|
|
1071
|
+
|
|
1072
|
+
- **Issues**: [GitHub Issues](https://github.com/Mentor-Friends/tsccs-dev/issues)
|
|
1073
|
+
- **Repository**: [https://github.com/Mentor-Friends/tsccs-dev](https://github.com/Mentor-Friends/tsccs-dev)
|
|
1074
|
+
|
|
1075
|
+
## License
|
|
1076
|
+
|
|
1077
|
+
ISC License - see [LICENSE](LICENSE) file for details.
|
|
1078
|
+
|
|
1079
|
+
## Author
|
|
1080
|
+
|
|
1081
|
+
**Mentor Friends**
|
|
1082
|
+
|
|
1083
|
+
---
|
|
1084
|
+
|
|
1085
|
+
Made with ❤️ by the Mentor Friends team
|
|
24
1086
|
|