@peers-app/peers-sdk 0.1.4
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 +1 -0
- package/dist/context/data-context.d.ts +31 -0
- package/dist/context/data-context.js +56 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.js +19 -0
- package/dist/context/user-context-singleton.d.ts +11 -0
- package/dist/context/user-context-singleton.js +121 -0
- package/dist/context/user-context.d.ts +55 -0
- package/dist/context/user-context.js +205 -0
- package/dist/data/assistants.d.ts +68 -0
- package/dist/data/assistants.js +64 -0
- package/dist/data/change-tracking.d.ts +219 -0
- package/dist/data/change-tracking.js +119 -0
- package/dist/data/channels.d.ts +29 -0
- package/dist/data/channels.js +25 -0
- package/dist/data/data-locks.d.ts +37 -0
- package/dist/data/data-locks.js +180 -0
- package/dist/data/data-locks.test.d.ts +1 -0
- package/dist/data/data-locks.test.js +456 -0
- package/dist/data/device-sync-info.d.ts +19 -0
- package/dist/data/device-sync-info.js +24 -0
- package/dist/data/devices.d.ts +51 -0
- package/dist/data/devices.js +36 -0
- package/dist/data/embeddings.d.ts +47 -0
- package/dist/data/embeddings.js +36 -0
- package/dist/data/files/file-read-stream.d.ts +27 -0
- package/dist/data/files/file-read-stream.js +195 -0
- package/dist/data/files/file-write-stream.d.ts +20 -0
- package/dist/data/files/file-write-stream.js +113 -0
- package/dist/data/files/file.types.d.ts +47 -0
- package/dist/data/files/file.types.js +55 -0
- package/dist/data/files/files.d.ts +28 -0
- package/dist/data/files/files.js +127 -0
- package/dist/data/files/files.test.d.ts +1 -0
- package/dist/data/files/files.test.js +728 -0
- package/dist/data/files/index.d.ts +4 -0
- package/dist/data/files/index.js +23 -0
- package/dist/data/group-member-roles.d.ts +9 -0
- package/dist/data/group-member-roles.js +25 -0
- package/dist/data/group-members.d.ts +39 -0
- package/dist/data/group-members.js +68 -0
- package/dist/data/group-members.test.d.ts +1 -0
- package/dist/data/group-members.test.js +287 -0
- package/dist/data/group-permissions.d.ts +8 -0
- package/dist/data/group-permissions.js +73 -0
- package/dist/data/group-share.d.ts +50 -0
- package/dist/data/group-share.js +196 -0
- package/dist/data/groups.d.ts +50 -0
- package/dist/data/groups.js +73 -0
- package/dist/data/groups.test.d.ts +1 -0
- package/dist/data/groups.test.js +153 -0
- package/dist/data/index.d.ts +31 -0
- package/dist/data/index.js +47 -0
- package/dist/data/knowledge/knowledge-frames.d.ts +34 -0
- package/dist/data/knowledge/knowledge-frames.js +34 -0
- package/dist/data/knowledge/knowledge-links.d.ts +30 -0
- package/dist/data/knowledge/knowledge-links.js +25 -0
- package/dist/data/knowledge/knowledge-values.d.ts +35 -0
- package/dist/data/knowledge/knowledge-values.js +35 -0
- package/dist/data/knowledge/peer-types.d.ts +112 -0
- package/dist/data/knowledge/peer-types.js +27 -0
- package/dist/data/knowledge/predicates.d.ts +34 -0
- package/dist/data/knowledge/predicates.js +27 -0
- package/dist/data/messages.d.ts +57 -0
- package/dist/data/messages.js +97 -0
- package/dist/data/orm/client-proxy.data-source.d.ts +27 -0
- package/dist/data/orm/client-proxy.data-source.js +65 -0
- package/dist/data/orm/cursor.d.ts +25 -0
- package/dist/data/orm/cursor.js +47 -0
- package/dist/data/orm/cursor.test.d.ts +1 -0
- package/dist/data/orm/cursor.test.js +315 -0
- package/dist/data/orm/data-query.d.ts +96 -0
- package/dist/data/orm/data-query.js +208 -0
- package/dist/data/orm/data-query.mongo.d.ts +17 -0
- package/dist/data/orm/data-query.mongo.js +267 -0
- package/dist/data/orm/data-query.mongo.test.d.ts +1 -0
- package/dist/data/orm/data-query.mongo.test.js +398 -0
- package/dist/data/orm/data-query.sqlite.d.ts +14 -0
- package/dist/data/orm/data-query.sqlite.js +297 -0
- package/dist/data/orm/data-query.sqlite.test.d.ts +1 -0
- package/dist/data/orm/data-query.sqlite.test.js +377 -0
- package/dist/data/orm/data-query.test.d.ts +1 -0
- package/dist/data/orm/data-query.test.js +553 -0
- package/dist/data/orm/decorators.d.ts +6 -0
- package/dist/data/orm/decorators.js +21 -0
- package/dist/data/orm/dependency-injection.test.d.ts +1 -0
- package/dist/data/orm/dependency-injection.test.js +171 -0
- package/dist/data/orm/doc.d.ts +26 -0
- package/dist/data/orm/doc.js +124 -0
- package/dist/data/orm/event-registry.d.ts +24 -0
- package/dist/data/orm/event-registry.js +40 -0
- package/dist/data/orm/event-registry.test.d.ts +1 -0
- package/dist/data/orm/event-registry.test.js +44 -0
- package/dist/data/orm/factory.d.ts +8 -0
- package/dist/data/orm/factory.js +147 -0
- package/dist/data/orm/index.d.ts +16 -0
- package/dist/data/orm/index.js +32 -0
- package/dist/data/orm/multi-cursors.d.ts +11 -0
- package/dist/data/orm/multi-cursors.js +146 -0
- package/dist/data/orm/multi-cursors.test.d.ts +1 -0
- package/dist/data/orm/multi-cursors.test.js +455 -0
- package/dist/data/orm/sql-db.d.ts +6 -0
- package/dist/data/orm/sql-db.js +2 -0
- package/dist/data/orm/sql.data-source.d.ts +38 -0
- package/dist/data/orm/sql.data-source.js +379 -0
- package/dist/data/orm/sql.data-source.test.d.ts +1 -0
- package/dist/data/orm/sql.data-source.test.js +406 -0
- package/dist/data/orm/subscribable.data-source.d.ts +25 -0
- package/dist/data/orm/subscribable.data-source.js +72 -0
- package/dist/data/orm/table-container-events.test.d.ts +1 -0
- package/dist/data/orm/table-container-events.test.js +93 -0
- package/dist/data/orm/table-container.d.ts +39 -0
- package/dist/data/orm/table-container.js +96 -0
- package/dist/data/orm/table-definitions.system.d.ts +9 -0
- package/dist/data/orm/table-definitions.system.js +29 -0
- package/dist/data/orm/table-definitions.type.d.ts +19 -0
- package/dist/data/orm/table-definitions.type.js +2 -0
- package/dist/data/orm/table-dependencies.d.ts +32 -0
- package/dist/data/orm/table-dependencies.js +2 -0
- package/dist/data/orm/table.d.ts +42 -0
- package/dist/data/orm/table.event-source.test.d.ts +1 -0
- package/dist/data/orm/table.event-source.test.js +341 -0
- package/dist/data/orm/table.js +244 -0
- package/dist/data/orm/types.d.ts +20 -0
- package/dist/data/orm/types.js +115 -0
- package/dist/data/orm/types.test.d.ts +1 -0
- package/dist/data/orm/types.test.js +71 -0
- package/dist/data/package-permissions.d.ts +7 -0
- package/dist/data/package-permissions.js +18 -0
- package/dist/data/packages.d.ts +92 -0
- package/dist/data/packages.js +90 -0
- package/dist/data/peer-events/peer-event-handlers.d.ts +21 -0
- package/dist/data/peer-events/peer-event-handlers.js +28 -0
- package/dist/data/peer-events/peer-event-types.d.ts +119 -0
- package/dist/data/peer-events/peer-event-types.js +29 -0
- package/dist/data/peer-events/peer-events.d.ts +41 -0
- package/dist/data/peer-events/peer-events.js +102 -0
- package/dist/data/persistent-vars.d.ts +87 -0
- package/dist/data/persistent-vars.js +230 -0
- package/dist/data/tool-tests.d.ts +37 -0
- package/dist/data/tool-tests.js +27 -0
- package/dist/data/tools.d.ts +358 -0
- package/dist/data/tools.js +48 -0
- package/dist/data/user-permissions.d.ts +15 -0
- package/dist/data/user-permissions.js +39 -0
- package/dist/data/user-permissions.test.d.ts +1 -0
- package/dist/data/user-permissions.test.js +252 -0
- package/dist/data/users.d.ts +38 -0
- package/dist/data/users.js +73 -0
- package/dist/data/workflow-logs.d.ts +106 -0
- package/dist/data/workflow-logs.js +67 -0
- package/dist/data/workflow-runs.d.ts +103 -0
- package/dist/data/workflow-runs.js +313 -0
- package/dist/data/workflows.d.ts +16 -0
- package/dist/data/workflows.js +21 -0
- package/dist/device/connection.d.ts +41 -0
- package/dist/device/connection.js +249 -0
- package/dist/device/connection.test.d.ts +1 -0
- package/dist/device/connection.test.js +292 -0
- package/dist/device/device-election.d.ts +36 -0
- package/dist/device/device-election.js +137 -0
- package/dist/device/device.d.ts +22 -0
- package/dist/device/device.js +110 -0
- package/dist/device/device.test.d.ts +1 -0
- package/dist/device/device.test.js +203 -0
- package/dist/device/get-trust-level.d.ts +3 -0
- package/dist/device/get-trust-level.js +87 -0
- package/dist/device/socket.type.d.ts +20 -0
- package/dist/device/socket.type.js +15 -0
- package/dist/device/streamed-socket.d.ts +27 -0
- package/dist/device/streamed-socket.js +154 -0
- package/dist/device/streamed-socket.test.d.ts +1 -0
- package/dist/device/streamed-socket.test.js +44 -0
- package/dist/events.d.ts +35 -0
- package/dist/events.js +128 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +50 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.js +234 -0
- package/dist/keys.test.d.ts +1 -0
- package/dist/keys.test.js +215 -0
- package/dist/mentions.d.ts +9 -0
- package/dist/mentions.js +46 -0
- package/dist/observable.d.ts +19 -0
- package/dist/observable.js +112 -0
- package/dist/observable.test.d.ts +1 -0
- package/dist/observable.test.js +183 -0
- package/dist/package-loader/get-require.d.ts +10 -0
- package/dist/package-loader/get-require.js +31 -0
- package/dist/package-loader/index.d.ts +1 -0
- package/dist/package-loader/index.js +17 -0
- package/dist/package-loader/package-loader.d.ts +16 -0
- package/dist/package-loader/package-loader.js +102 -0
- package/dist/peers-ui/peers-ui.d.ts +15 -0
- package/dist/peers-ui/peers-ui.js +23 -0
- package/dist/peers-ui/peers-ui.types.d.ts +35 -0
- package/dist/peers-ui/peers-ui.types.js +3 -0
- package/dist/rpc-types.d.ts +45 -0
- package/dist/rpc-types.js +47 -0
- package/dist/serial-json.d.ts +5 -0
- package/dist/serial-json.js +186 -0
- package/dist/serial-json.test.d.ts +1 -0
- package/dist/serial-json.test.js +86 -0
- package/dist/system-ids.d.ts +6 -0
- package/dist/system-ids.js +10 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/tools-factory.d.ts +5 -0
- package/dist/tools/tools-factory.js +34 -0
- package/dist/types/app-nav.d.ts +18 -0
- package/dist/types/app-nav.js +10 -0
- package/dist/types/assistant-runner-args.d.ts +9 -0
- package/dist/types/assistant-runner-args.js +2 -0
- package/dist/types/field-type.d.ts +37 -0
- package/dist/types/field-type.js +26 -0
- package/dist/types/peer-device.d.ts +40 -0
- package/dist/types/peer-device.js +14 -0
- package/dist/types/peers-package.d.ts +23 -0
- package/dist/types/peers-package.js +2 -0
- package/dist/types/workflow-logger.d.ts +2 -0
- package/dist/types/workflow-logger.js +2 -0
- package/dist/types/workflow-run-context.d.ts +12 -0
- package/dist/types/workflow-run-context.js +2 -0
- package/dist/types/workflow.d.ts +72 -0
- package/dist/types/workflow.js +24 -0
- package/dist/types/zod-types.d.ts +7 -0
- package/dist/types/zod-types.js +12 -0
- package/dist/users.query.d.ts +13 -0
- package/dist/users.query.js +134 -0
- package/dist/utils.d.ts +39 -0
- package/dist/utils.js +240 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +140 -0
- package/package.json +50 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateGroupShare = generateGroupShare;
|
|
4
|
+
exports.validateGroupShare = validateGroupShare;
|
|
5
|
+
exports.estimateGroupShareSize = estimateGroupShareSize;
|
|
6
|
+
exports.checkQRCodeCompatibility = checkQRCodeCompatibility;
|
|
7
|
+
exports.copyToClipboard = copyToClipboard;
|
|
8
|
+
const __1 = require("..");
|
|
9
|
+
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
10
|
+
const group_member_roles_1 = require("./group-member-roles");
|
|
11
|
+
const group_members_1 = require("./group-members");
|
|
12
|
+
const groups_1 = require("./groups");
|
|
13
|
+
/**
|
|
14
|
+
* Generates a GroupShare object containing the group and its admin+ members
|
|
15
|
+
* @param groupId The ID of the group to share
|
|
16
|
+
* @returns Promise<GroupShare> The shareable group data
|
|
17
|
+
* @throws Error if group not found or user lacks permission
|
|
18
|
+
*/
|
|
19
|
+
async function generateGroupShare(groupId) {
|
|
20
|
+
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
21
|
+
// Get the group from user's context
|
|
22
|
+
const group = await (0, groups_1.Groups)(userContext.userDataContext).get(groupId);
|
|
23
|
+
if (!group) {
|
|
24
|
+
throw new Error('Group not found');
|
|
25
|
+
}
|
|
26
|
+
// Get group data context and members
|
|
27
|
+
const groupDataContext = userContext.getDataContext(groupId);
|
|
28
|
+
const groupMembersTable = (0, group_members_1.GroupMembers)(groupDataContext);
|
|
29
|
+
// Get the 5 newest admins to seed the members table with for the initial connection
|
|
30
|
+
const adminMembers = await groupMembersTable.list({ deleted: { $ne: true }, role: { $gte: group_member_roles_1.GroupMemberRole.Admin } }, { pageSize: 5, sortBy: ['-groupMemberId'] });
|
|
31
|
+
if (adminMembers.length === 0) {
|
|
32
|
+
console.warn('No admin members, first connection will rely exclusively on founder');
|
|
33
|
+
}
|
|
34
|
+
const groupShare = {
|
|
35
|
+
group,
|
|
36
|
+
groupMembers: adminMembers,
|
|
37
|
+
};
|
|
38
|
+
return groupShare;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Imports a GroupShare object, creating the group and seeding admin members
|
|
42
|
+
* @param groupShareJson JSON string containing the GroupShare data
|
|
43
|
+
* @returns Promise<string> The imported group ID
|
|
44
|
+
* @throws Error if JSON invalid or import fails
|
|
45
|
+
*/
|
|
46
|
+
async function importGroupShare(groupShareJson) {
|
|
47
|
+
// Parse and validate JSON
|
|
48
|
+
let groupShare;
|
|
49
|
+
try {
|
|
50
|
+
groupShare = JSON.parse(groupShareJson);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error('Invalid JSON format');
|
|
54
|
+
}
|
|
55
|
+
// Validate structure - maybe redo this with a zod schema
|
|
56
|
+
if (!validateGroupShare(groupShare)) {
|
|
57
|
+
throw new Error('Invalid GroupShare structure');
|
|
58
|
+
}
|
|
59
|
+
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
60
|
+
const { group, groupMembers } = groupShare;
|
|
61
|
+
// Check if group already exists
|
|
62
|
+
const existingGroup = await (0, groups_1.Groups)(userContext.userDataContext).get(group.groupId);
|
|
63
|
+
if (existingGroup) {
|
|
64
|
+
throw new Error(`Group "${group.name}" already exists`);
|
|
65
|
+
}
|
|
66
|
+
// Save group to user's groups table
|
|
67
|
+
await (0, groups_1.Groups)(userContext.userDataContext).save(group, { restoreIfDeleted: true });
|
|
68
|
+
// Get group data context for the new group
|
|
69
|
+
const groupDataContext = userContext.getDataContext(group.groupId);
|
|
70
|
+
// Save the group data to the group's own context
|
|
71
|
+
const groupsTable = (0, groups_1.Groups)(groupDataContext);
|
|
72
|
+
const groupsTableDataSource = getLowestDataSource(groupsTable);
|
|
73
|
+
await groupsTableDataSource.save(group);
|
|
74
|
+
// Save all admin members as seed data for device recognition
|
|
75
|
+
const groupMembersTable = (0, group_members_1.GroupMembers)(groupDataContext);
|
|
76
|
+
const groupMembersDataSource = getLowestDataSource(groupMembersTable);
|
|
77
|
+
for (const member of groupMembers) {
|
|
78
|
+
await groupMembersDataSource.save(member);
|
|
79
|
+
}
|
|
80
|
+
return group.groupId;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validates that an object has the correct GroupShare structure
|
|
84
|
+
* @param obj Object to validate
|
|
85
|
+
* @returns boolean True if valid GroupShare structure
|
|
86
|
+
*/
|
|
87
|
+
function validateGroupShare(obj) {
|
|
88
|
+
if (!obj || typeof obj !== 'object') {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
// Check group structure
|
|
92
|
+
if (!obj.group || typeof obj.group !== 'object') {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const group = obj.group;
|
|
96
|
+
if (!group.groupId || !group.name || typeof group.groupId !== 'string' || typeof group.name !== 'string') {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// Check groupMembers structure
|
|
100
|
+
if (!Array.isArray(obj.groupMembers)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
for (const member of obj.groupMembers) {
|
|
104
|
+
if (!member || typeof member !== 'object') {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (!member.groupMemberId || !member.groupId || !member.userId ||
|
|
108
|
+
typeof member.groupMemberId !== 'string' ||
|
|
109
|
+
typeof member.groupId !== 'string' ||
|
|
110
|
+
typeof member.userId !== 'string' ||
|
|
111
|
+
typeof member.role !== 'number' ||
|
|
112
|
+
member.role < group_member_roles_1.GroupMemberRole.Admin) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Estimates the size of a GroupShare object when serialized to JSON
|
|
120
|
+
* @param groupShare The GroupShare object to estimate
|
|
121
|
+
* @returns number Estimated size in characters
|
|
122
|
+
*/
|
|
123
|
+
function estimateGroupShareSize(groupShare) {
|
|
124
|
+
return JSON.stringify(groupShare).length;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if a GroupShare object would fit in a QR code of the specified version
|
|
128
|
+
* @param groupShare The GroupShare object to check
|
|
129
|
+
* @param qrVersion QR code version (10, 20, or 40)
|
|
130
|
+
* @returns Object with size info and QR code compatibility
|
|
131
|
+
*/
|
|
132
|
+
function checkQRCodeCompatibility(groupShare, qrVersion = 20) {
|
|
133
|
+
const size = estimateGroupShareSize(groupShare);
|
|
134
|
+
const limits = {
|
|
135
|
+
10: 1273, // Version 10 limit
|
|
136
|
+
20: 3057, // Version 20 limit
|
|
137
|
+
40: 7089 // Version 40 limit
|
|
138
|
+
};
|
|
139
|
+
const maxSize = limits[qrVersion];
|
|
140
|
+
const fits = size <= maxSize;
|
|
141
|
+
const usagePercent = Math.round((size / maxSize) * 100);
|
|
142
|
+
return {
|
|
143
|
+
size,
|
|
144
|
+
maxSize,
|
|
145
|
+
fits,
|
|
146
|
+
usagePercent,
|
|
147
|
+
qrVersion,
|
|
148
|
+
memberCount: groupShare.groupMembers.length
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Copies text to clipboard with fallback handling
|
|
153
|
+
* @param text Text to copy to clipboard
|
|
154
|
+
* @returns Promise<boolean> True if successful
|
|
155
|
+
*/
|
|
156
|
+
async function copyToClipboard(text) {
|
|
157
|
+
try {
|
|
158
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
159
|
+
await navigator.clipboard.writeText(text);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Fallback for older browsers
|
|
164
|
+
const textArea = document.createElement('textarea');
|
|
165
|
+
textArea.value = text;
|
|
166
|
+
textArea.style.position = 'fixed';
|
|
167
|
+
textArea.style.opacity = '0';
|
|
168
|
+
document.body.appendChild(textArea);
|
|
169
|
+
textArea.focus();
|
|
170
|
+
textArea.select();
|
|
171
|
+
const success = document.execCommand('copy');
|
|
172
|
+
document.body.removeChild(textArea);
|
|
173
|
+
return success;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error('Failed to copy to clipboard:', error);
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// get around circular dependency issue
|
|
182
|
+
setTimeout(async () => {
|
|
183
|
+
__1.rpcServerCalls.importGroupShare = (groupShareJson) => importGroupShare(groupShareJson);
|
|
184
|
+
}, 10);
|
|
185
|
+
function getLowestDataSource(table) {
|
|
186
|
+
let ds = table.dataSource;
|
|
187
|
+
for (let i = 0; i < 100; i++) {
|
|
188
|
+
if (ds.dataSource) {
|
|
189
|
+
ds = ds.dataSource;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return ds;
|
|
196
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { DataContext } from "../context/data-context";
|
|
3
|
+
import { GroupMemberRole } from "./group-member-roles";
|
|
4
|
+
import { ISaveOptions, Table } from "./orm";
|
|
5
|
+
export declare const groupSchema: z.ZodObject<{
|
|
6
|
+
groupId: z.ZodEffects<z.ZodString, string, string>;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
description: z.ZodString;
|
|
9
|
+
iconClassName: z.ZodOptional<z.ZodString>;
|
|
10
|
+
publicRole: z.ZodOptional<z.ZodNativeEnum<typeof GroupMemberRole>>;
|
|
11
|
+
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
founderUserId: z.ZodString;
|
|
13
|
+
signature: z.ZodString;
|
|
14
|
+
publicKey: z.ZodString;
|
|
15
|
+
publicBoxKey: z.ZodString;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
signature: string;
|
|
20
|
+
publicKey: string;
|
|
21
|
+
groupId: string;
|
|
22
|
+
founderUserId: string;
|
|
23
|
+
publicBoxKey: string;
|
|
24
|
+
disabled?: boolean | undefined;
|
|
25
|
+
iconClassName?: string | undefined;
|
|
26
|
+
publicRole?: GroupMemberRole | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
signature: string;
|
|
31
|
+
publicKey: string;
|
|
32
|
+
groupId: string;
|
|
33
|
+
founderUserId: string;
|
|
34
|
+
publicBoxKey: string;
|
|
35
|
+
disabled?: boolean | undefined;
|
|
36
|
+
iconClassName?: string | undefined;
|
|
37
|
+
publicRole?: GroupMemberRole | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
export type IGroup = z.infer<typeof groupSchema>;
|
|
40
|
+
export declare const groupsTableName = "Groups";
|
|
41
|
+
export declare class GroupsTable extends Table<IGroup> {
|
|
42
|
+
static isPassthrough: boolean;
|
|
43
|
+
save(group: IGroup, opts?: ISaveOptions): Promise<IGroup>;
|
|
44
|
+
delete(groupId: string): Promise<void>;
|
|
45
|
+
/** @deprecated Direct inserts forbidden; use save() */
|
|
46
|
+
insert(..._args: Parameters<Table<IGroup>['insert']>): never;
|
|
47
|
+
/** @deprecated Direct updates forbidden; use save() */
|
|
48
|
+
update(..._args: Parameters<Table<IGroup>['update']>): never;
|
|
49
|
+
}
|
|
50
|
+
export declare function Groups(dataContext?: DataContext): GroupsTable;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroupsTable = exports.groupsTableName = exports.groupSchema = void 0;
|
|
4
|
+
exports.Groups = Groups;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const user_context_singleton_1 = require("../context/user-context-singleton");
|
|
7
|
+
const zod_types_1 = require("../types/zod-types");
|
|
8
|
+
const group_member_roles_1 = require("./group-member-roles");
|
|
9
|
+
const group_permissions_1 = require("./group-permissions");
|
|
10
|
+
const orm_1 = require("./orm");
|
|
11
|
+
const table_definitions_system_1 = require("./orm/table-definitions.system");
|
|
12
|
+
const types_1 = require("./orm/types");
|
|
13
|
+
exports.groupSchema = zod_1.z.object({
|
|
14
|
+
groupId: zod_types_1.zodPeerId,
|
|
15
|
+
name: zod_1.z.string(),
|
|
16
|
+
description: zod_1.z.string(),
|
|
17
|
+
iconClassName: zod_1.z.string().optional().describe('Icon class name for the group (e.g., bi-people-fill)'),
|
|
18
|
+
publicRole: zod_1.z.nativeEnum(group_member_roles_1.GroupMemberRole).optional().describe('Whether the group is publicly readable'),
|
|
19
|
+
disabled: zod_1.z.boolean().optional().describe('Whether the group is currently disabled'),
|
|
20
|
+
founderUserId: zod_1.z.string().describe('The user ID of the group founder'),
|
|
21
|
+
signature: zod_1.z.string().describe('The signed hash of this data excluding the signature itself'),
|
|
22
|
+
publicKey: zod_1.z.string().describe('The public key of the group used to verify a data has come from a group member with write permissions or higher'),
|
|
23
|
+
publicBoxKey: zod_1.z.string().describe('The public key used to encrypt data that only group members with writer permissions or higher can decrypt'),
|
|
24
|
+
});
|
|
25
|
+
exports.groupsTableName = 'Groups';
|
|
26
|
+
const metaData = {
|
|
27
|
+
name: exports.groupsTableName,
|
|
28
|
+
description: 'groups',
|
|
29
|
+
primaryKeyName: 'groupId',
|
|
30
|
+
fields: (0, types_1.schemaToFields)(exports.groupSchema),
|
|
31
|
+
iconClassName: 'bi bi-people-fill',
|
|
32
|
+
indexes: [
|
|
33
|
+
{ fields: ['name'] },
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
class GroupsTable extends orm_1.Table {
|
|
37
|
+
static isPassthrough = false;
|
|
38
|
+
async save(group, opts) {
|
|
39
|
+
if (GroupsTable.isPassthrough) {
|
|
40
|
+
return super.save(group, opts);
|
|
41
|
+
}
|
|
42
|
+
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
43
|
+
const userContextGroups = Groups(userContext.userDataContext);
|
|
44
|
+
if (userContextGroups === this) {
|
|
45
|
+
// users can do whatever they want to groups in their personal space
|
|
46
|
+
return super.save(group, opts);
|
|
47
|
+
}
|
|
48
|
+
const oldGroup = await this.get(group.groupId);
|
|
49
|
+
await (0, group_permissions_1.verifyGroupSignature)(group, oldGroup);
|
|
50
|
+
return super.save(group, opts);
|
|
51
|
+
}
|
|
52
|
+
async delete(groupId) {
|
|
53
|
+
const userContext = await (0, user_context_singleton_1.getUserContext)();
|
|
54
|
+
const userContextGroups = Groups(userContext.userDataContext);
|
|
55
|
+
if (userContextGroups === this) {
|
|
56
|
+
return super.delete(groupId);
|
|
57
|
+
}
|
|
58
|
+
throw new Error('Only deleting groups from the user context Groups table is allowed');
|
|
59
|
+
}
|
|
60
|
+
/** @deprecated Direct inserts forbidden; use save() */
|
|
61
|
+
insert(..._args) {
|
|
62
|
+
throw new Error('Direct inserts forbidden; use save()');
|
|
63
|
+
}
|
|
64
|
+
/** @deprecated Direct updates forbidden; use save() */
|
|
65
|
+
update(..._args) {
|
|
66
|
+
throw new Error('Direct updates forbidden; use save()');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.GroupsTable = GroupsTable;
|
|
70
|
+
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, exports.groupSchema, GroupsTable);
|
|
71
|
+
function Groups(dataContext) {
|
|
72
|
+
return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, exports.groupSchema, GroupsTable);
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const keys_1 = require("../keys");
|
|
4
|
+
const group_member_roles_1 = require("./group-member-roles");
|
|
5
|
+
// Test the signature logic directly without full ORM dependencies
|
|
6
|
+
describe('Groups Signature Logic', () => {
|
|
7
|
+
let testGroup;
|
|
8
|
+
let ownerKeys;
|
|
9
|
+
let adminKeys;
|
|
10
|
+
let unauthorizedKeys;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
ownerKeys = (0, keys_1.newKeys)();
|
|
13
|
+
adminKeys = (0, keys_1.newKeys)();
|
|
14
|
+
unauthorizedKeys = (0, keys_1.newKeys)();
|
|
15
|
+
testGroup = {
|
|
16
|
+
groupId: 'test-group-1',
|
|
17
|
+
name: 'Test Group',
|
|
18
|
+
description: 'A test group',
|
|
19
|
+
publicRole: group_member_roles_1.GroupMemberRole.Reader,
|
|
20
|
+
disabled: false,
|
|
21
|
+
signature: '',
|
|
22
|
+
founderUserId: '',
|
|
23
|
+
publicKey: ownerKeys.publicKey,
|
|
24
|
+
publicBoxKey: ownerKeys.publicKey
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
describe('basic signature functionality', () => {
|
|
28
|
+
it('should add signature to group object', () => {
|
|
29
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
30
|
+
expect(signedGroup.signature).toBeTruthy();
|
|
31
|
+
expect(signedGroup.signature).toContain(':');
|
|
32
|
+
expect(signedGroup.name).toBe(testGroup.name);
|
|
33
|
+
expect(signedGroup.groupId).toBe(testGroup.groupId);
|
|
34
|
+
});
|
|
35
|
+
it('should verify valid signature', () => {
|
|
36
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
37
|
+
const isValid = (0, keys_1.isObjectSignatureValid)(signedGroup);
|
|
38
|
+
expect(isValid).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it('should reject invalid signature after modification', () => {
|
|
41
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
42
|
+
// Modify the group after signing
|
|
43
|
+
signedGroup.name = 'Modified Name';
|
|
44
|
+
const isValid = (0, keys_1.isObjectSignatureValid)(signedGroup);
|
|
45
|
+
expect(isValid).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
it('should extract correct public key from signature', () => {
|
|
48
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
49
|
+
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
50
|
+
expect(extractedKey).toBe(ownerKeys.publicKey);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('basic signing with different keys', () => {
|
|
54
|
+
it('should create valid signature with owner key', () => {
|
|
55
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
56
|
+
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
57
|
+
expect(extractedKey).toBe(ownerKeys.publicKey);
|
|
58
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
it('should create valid signature with admin key', () => {
|
|
61
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, adminKeys.secretKey);
|
|
62
|
+
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
63
|
+
expect(extractedKey).toBe(adminKeys.publicKey);
|
|
64
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
it('should create valid signature with any key', () => {
|
|
67
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, unauthorizedKeys.secretKey);
|
|
68
|
+
const extractedKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedGroup);
|
|
69
|
+
expect(extractedKey).toBe(unauthorizedKeys.publicKey);
|
|
70
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true); // Signature is cryptographically valid
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('signature tampering detection', () => {
|
|
74
|
+
it('should detect tampered signature', () => {
|
|
75
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(testGroup, ownerKeys.secretKey);
|
|
76
|
+
// Tamper with signature by adding extra characters
|
|
77
|
+
signedGroup.signature = signedGroup.signature + 'tampered';
|
|
78
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
it('should detect empty signature', () => {
|
|
81
|
+
testGroup.signature = '';
|
|
82
|
+
expect((0, keys_1.isObjectSignatureValid)(testGroup)).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
it('should detect malformed signature', () => {
|
|
85
|
+
testGroup.signature = 'malformed-signature';
|
|
86
|
+
expect((0, keys_1.isObjectSignatureValid)(testGroup)).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
it('should handle signature without colon separator', () => {
|
|
89
|
+
testGroup.signature = 'noseparator';
|
|
90
|
+
expect((0, keys_1.isObjectSignatureValid)(testGroup)).toBe(false);
|
|
91
|
+
expect((0, keys_1.getPublicKeyFromObjectSignature)(testGroup)).toBeUndefined();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('complex group objects', () => {
|
|
95
|
+
it('should handle groups with all optional fields', () => {
|
|
96
|
+
const complexGroup = {
|
|
97
|
+
...testGroup,
|
|
98
|
+
publicRole: group_member_roles_1.GroupMemberRole.Writer,
|
|
99
|
+
disabled: true,
|
|
100
|
+
};
|
|
101
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(complexGroup, ownerKeys.secretKey);
|
|
102
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
103
|
+
expect(signedGroup.publicRole).toBe(group_member_roles_1.GroupMemberRole.Writer);
|
|
104
|
+
expect(signedGroup.disabled).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
it('should handle groups without optional fields', () => {
|
|
107
|
+
const simpleGroup = {
|
|
108
|
+
groupId: testGroup.groupId,
|
|
109
|
+
name: testGroup.name,
|
|
110
|
+
description: testGroup.description,
|
|
111
|
+
signature: '',
|
|
112
|
+
founderUserId: '',
|
|
113
|
+
publicKey: ownerKeys.publicKey,
|
|
114
|
+
publicBoxKey: ownerKeys.publicKey
|
|
115
|
+
};
|
|
116
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(simpleGroup, ownerKeys.secretKey);
|
|
117
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
118
|
+
expect(signedGroup.publicRole).toBeUndefined();
|
|
119
|
+
expect(signedGroup.disabled).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
describe('edge cases', () => {
|
|
123
|
+
it('should handle long group names and descriptions', () => {
|
|
124
|
+
const longGroup = {
|
|
125
|
+
...testGroup,
|
|
126
|
+
name: 'A'.repeat(1000),
|
|
127
|
+
description: 'B'.repeat(5000),
|
|
128
|
+
};
|
|
129
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(longGroup, ownerKeys.secretKey);
|
|
130
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
it('should handle special characters in group data', () => {
|
|
133
|
+
const specialGroup = {
|
|
134
|
+
...testGroup,
|
|
135
|
+
name: 'Group with 🚀 emojis and "quotes" & <html>',
|
|
136
|
+
description: 'Contains\nnewlines\tand\ttabs',
|
|
137
|
+
};
|
|
138
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(specialGroup, ownerKeys.secretKey);
|
|
139
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
140
|
+
expect(signedGroup.name).toContain('🚀');
|
|
141
|
+
expect(signedGroup.description).toContain('\n');
|
|
142
|
+
});
|
|
143
|
+
it('should handle empty strings', () => {
|
|
144
|
+
const emptyGroup = {
|
|
145
|
+
...testGroup,
|
|
146
|
+
name: '',
|
|
147
|
+
description: '',
|
|
148
|
+
};
|
|
149
|
+
const signedGroup = (0, keys_1.addSignatureToObject)(emptyGroup, ownerKeys.secretKey);
|
|
150
|
+
expect((0, keys_1.isObjectSignatureValid)(signedGroup)).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export * from "./assistants";
|
|
2
|
+
export * from "./channels";
|
|
3
|
+
export * from "./change-tracking";
|
|
4
|
+
export * from "./data-locks";
|
|
5
|
+
export * from "./device-sync-info";
|
|
6
|
+
export * from "./devices";
|
|
7
|
+
export * from "./embeddings";
|
|
8
|
+
export * from "./files";
|
|
9
|
+
export * from "./group-permissions";
|
|
10
|
+
export * from "./groups";
|
|
11
|
+
export * from "./group-members";
|
|
12
|
+
export * from "./group-member-roles";
|
|
13
|
+
export * from "./group-share";
|
|
14
|
+
export * from "./knowledge/knowledge-frames";
|
|
15
|
+
export * from "./knowledge/knowledge-links";
|
|
16
|
+
export * from "./knowledge/knowledge-values";
|
|
17
|
+
export * from "./knowledge/peer-types";
|
|
18
|
+
export * from "./knowledge/predicates";
|
|
19
|
+
export * from "./messages";
|
|
20
|
+
export * from "./packages";
|
|
21
|
+
export * from "./peer-events/peer-event-handlers";
|
|
22
|
+
export * from "./peer-events/peer-event-types";
|
|
23
|
+
export * from "./peer-events/peer-events";
|
|
24
|
+
export * from "./persistent-vars";
|
|
25
|
+
export * from "./tool-tests";
|
|
26
|
+
export * from "./tools";
|
|
27
|
+
export * from "./users";
|
|
28
|
+
export * from "./user-permissions";
|
|
29
|
+
export * from "./workflow-logs";
|
|
30
|
+
export * from "./workflow-runs";
|
|
31
|
+
export * from "./workflows";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./assistants"), exports);
|
|
18
|
+
__exportStar(require("./channels"), exports);
|
|
19
|
+
__exportStar(require("./change-tracking"), exports);
|
|
20
|
+
__exportStar(require("./data-locks"), exports);
|
|
21
|
+
__exportStar(require("./device-sync-info"), exports);
|
|
22
|
+
__exportStar(require("./devices"), exports);
|
|
23
|
+
__exportStar(require("./embeddings"), exports);
|
|
24
|
+
__exportStar(require("./files"), exports);
|
|
25
|
+
__exportStar(require("./group-permissions"), exports);
|
|
26
|
+
__exportStar(require("./groups"), exports);
|
|
27
|
+
__exportStar(require("./group-members"), exports);
|
|
28
|
+
__exportStar(require("./group-member-roles"), exports);
|
|
29
|
+
__exportStar(require("./group-share"), exports);
|
|
30
|
+
__exportStar(require("./knowledge/knowledge-frames"), exports);
|
|
31
|
+
__exportStar(require("./knowledge/knowledge-links"), exports);
|
|
32
|
+
__exportStar(require("./knowledge/knowledge-values"), exports);
|
|
33
|
+
__exportStar(require("./knowledge/peer-types"), exports);
|
|
34
|
+
__exportStar(require("./knowledge/predicates"), exports);
|
|
35
|
+
__exportStar(require("./messages"), exports);
|
|
36
|
+
__exportStar(require("./packages"), exports);
|
|
37
|
+
__exportStar(require("./peer-events/peer-event-handlers"), exports);
|
|
38
|
+
__exportStar(require("./peer-events/peer-event-types"), exports);
|
|
39
|
+
__exportStar(require("./peer-events/peer-events"), exports);
|
|
40
|
+
__exportStar(require("./persistent-vars"), exports);
|
|
41
|
+
__exportStar(require("./tool-tests"), exports);
|
|
42
|
+
__exportStar(require("./tools"), exports);
|
|
43
|
+
__exportStar(require("./users"), exports);
|
|
44
|
+
__exportStar(require("./user-permissions"), exports);
|
|
45
|
+
__exportStar(require("./workflow-logs"), exports);
|
|
46
|
+
__exportStar(require("./workflow-runs"), exports);
|
|
47
|
+
__exportStar(require("./workflows"), exports);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { DataContext } from "../../context/data-context";
|
|
3
|
+
declare const knowledgeFrameSchema: z.ZodObject<{
|
|
4
|
+
knowledgeFrameId: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
body: z.ZodString;
|
|
7
|
+
conclusion: z.ZodOptional<z.ZodString>;
|
|
8
|
+
knowledgeValueIds: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
|
|
9
|
+
modified: z.ZodNumber;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
name: string;
|
|
12
|
+
body: string;
|
|
13
|
+
knowledgeFrameId: string;
|
|
14
|
+
knowledgeValueIds: string[];
|
|
15
|
+
modified: number;
|
|
16
|
+
conclusion?: string | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
name: string;
|
|
19
|
+
body: string;
|
|
20
|
+
knowledgeFrameId: string;
|
|
21
|
+
knowledgeValueIds: string[];
|
|
22
|
+
modified: number;
|
|
23
|
+
conclusion?: string | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
export type IKnowledgeFrame = z.infer<typeof knowledgeFrameSchema>;
|
|
26
|
+
export declare function KnowledgeFrames(dataContext?: DataContext): import("../orm").Table<{
|
|
27
|
+
name: string;
|
|
28
|
+
body: string;
|
|
29
|
+
knowledgeFrameId: string;
|
|
30
|
+
knowledgeValueIds: string[];
|
|
31
|
+
modified: number;
|
|
32
|
+
conclusion?: string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KnowledgeFrames = KnowledgeFrames;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const types_1 = require("../orm/types");
|
|
6
|
+
const user_context_singleton_1 = require("../../context/user-context-singleton");
|
|
7
|
+
const table_definitions_system_1 = require("../orm/table-definitions.system");
|
|
8
|
+
const zod_types_1 = require("../../types/zod-types");
|
|
9
|
+
// Think of a knowledge frame as like a "hub note" in Roam Research
|
|
10
|
+
// besides just linking content together with a central topic,
|
|
11
|
+
// it is also a way to explore and idea by surfacing new links and generating new knowledge values
|
|
12
|
+
const knowledgeFrameSchema = zod_1.z.object({
|
|
13
|
+
knowledgeFrameId: zod_types_1.zodPeerId,
|
|
14
|
+
name: zod_1.z.string().describe('The name or topic of the knowledge frame'),
|
|
15
|
+
body: zod_1.z.string().describe('Describe the purpose / thesis / goal of the knowledge frame'),
|
|
16
|
+
conclusion: zod_1.z.string().optional().describe('The conclusion of the knowledge frame'),
|
|
17
|
+
knowledgeValueIds: zod_types_1.zodPeerId.array().describe('The knowledge values that are included in the frame'),
|
|
18
|
+
// knowledgeLinkIds: zodPeerId.array().describe('The knowledge links that are allowed in the frame'),
|
|
19
|
+
// excludedValueIds: zodPeerId.array().describe('The knowledge values that are explicitly excluded from the frame'),
|
|
20
|
+
// allowedPredicateIds: zodPeerId.array().describe('The predicates that are allowed in the frame'),
|
|
21
|
+
// allowedpeerTypeIds: zodPeerId.array().describe('The value types that are allowed in the frame'),
|
|
22
|
+
modified: zod_1.z.number().describe('The last time the frame was modified'),
|
|
23
|
+
});
|
|
24
|
+
const metaData = {
|
|
25
|
+
name: 'KnowledgeFrames',
|
|
26
|
+
description: "The knowledge frames in the system",
|
|
27
|
+
primaryKeyName: 'knowledgeFrameId',
|
|
28
|
+
fields: (0, types_1.schemaToFields)(knowledgeFrameSchema),
|
|
29
|
+
iconClassName: 'bi bi-window-dock',
|
|
30
|
+
};
|
|
31
|
+
(0, table_definitions_system_1.registerSystemTableDefinition)(metaData, knowledgeFrameSchema);
|
|
32
|
+
function KnowledgeFrames(dataContext) {
|
|
33
|
+
return (0, user_context_singleton_1.getTableContainer)(dataContext).getTable(metaData, knowledgeFrameSchema);
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { DataContext } from "../../context/data-context";
|
|
3
|
+
declare const knowledgeLinkSchema: z.ZodObject<{
|
|
4
|
+
knowledgeLinkId: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
subjectValueId: z.ZodEffects<z.ZodString, string, string>;
|
|
6
|
+
predicateId: z.ZodEffects<z.ZodString, string, string>;
|
|
7
|
+
predicateValue: z.ZodAny;
|
|
8
|
+
objectValueId: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
knowledgeLinkId: string;
|
|
11
|
+
subjectValueId: string;
|
|
12
|
+
predicateId: string;
|
|
13
|
+
predicateValue?: any;
|
|
14
|
+
objectValueId?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
knowledgeLinkId: string;
|
|
17
|
+
subjectValueId: string;
|
|
18
|
+
predicateId: string;
|
|
19
|
+
predicateValue?: any;
|
|
20
|
+
objectValueId?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export type IKnowledgeLink = z.infer<typeof knowledgeLinkSchema>;
|
|
23
|
+
export declare function KnowledgeLinks(dataContext?: DataContext): import("../orm").Table<{
|
|
24
|
+
knowledgeLinkId: string;
|
|
25
|
+
subjectValueId: string;
|
|
26
|
+
predicateId: string;
|
|
27
|
+
predicateValue?: any;
|
|
28
|
+
objectValueId?: string | undefined;
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|