docpouch-client 0.8.5 → 0.8.7
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 +305 -0
- package/dist/index.d.ts +116 -1
- package/dist/index.js +3 -3
- package/package.json +10 -6
- package/src/index.ts +150 -14
- package/tsconfig.json +1 -1
- package/dist/types.d.ts +0 -108
- package/dist/types.js +0 -2
- package/src/types.ts +0 -134
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# docpouch-client
|
|
2
|
+
|
|
3
|
+
A TypeScript client library for interacting with the [docPouch](https://github.com/BFH-JTF/doc-pouch) database API.
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
docpouch-client provides a simple and intuitive interface to access the docPouch API, allowing you to manage users,
|
|
8
|
+
documents, data structures, and document types. It also supports real-time synchronization via WebSockets.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install docpouch-client
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Initializing the Client
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import docPouchClient from 'docpouch-client';
|
|
22
|
+
|
|
23
|
+
// Initialize the client with the server URL
|
|
24
|
+
const client = new docPouchClient('https://your-docpouch-server.com', 80);
|
|
25
|
+
|
|
26
|
+
// Initialize with a callback for real-time updates
|
|
27
|
+
const client = new docPouchClient('https://your-docpouch-server.com', 80,
|
|
28
|
+
(event, data) => {
|
|
29
|
+
console.log(`Received event: ${event}`, data);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Authentication
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Login to get an authentication token
|
|
38
|
+
const loginResponse = await client.login({
|
|
39
|
+
name: 'username',
|
|
40
|
+
password: 'password'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (loginResponse) {
|
|
44
|
+
console.log('Login successful!');
|
|
45
|
+
console.log(`Token: ${loginResponse.token}`);
|
|
46
|
+
} else {
|
|
47
|
+
console.log('Login failed');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Set an existing token
|
|
51
|
+
client.setToken('your-auth-token');
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### User Management
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// List all users
|
|
58
|
+
const users = await client.listUsers();
|
|
59
|
+
|
|
60
|
+
// Create a new user
|
|
61
|
+
const newUser = await client.createUser({
|
|
62
|
+
name: 'newuser',
|
|
63
|
+
password: 'password',
|
|
64
|
+
department: 'IT',
|
|
65
|
+
group: 'Developers',
|
|
66
|
+
isAdmin: false
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Update a user
|
|
70
|
+
await client.updateUser('user-id', {
|
|
71
|
+
department: 'Engineering',
|
|
72
|
+
group: 'Frontend'
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Remove a user
|
|
76
|
+
await client.removeUser('user-id');
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Document Management
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Create a new document
|
|
83
|
+
const newDocument = await client.createDocument({
|
|
84
|
+
type: 17,
|
|
85
|
+
subType: 11,
|
|
86
|
+
title: "Mission Statement",
|
|
87
|
+
content: "{\"msg\": \"We strive for a world that...\"}",
|
|
88
|
+
shareWithGroup: false,
|
|
89
|
+
shareWithDepartment: false
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Update a document
|
|
93
|
+
await client.updateDocument('document-id', {
|
|
94
|
+
title: 'Updated Mission Statement',
|
|
95
|
+
content: '{"msg": "Our updated mission..."}'
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Delete a document
|
|
99
|
+
await client.deleteDocument('document-id');
|
|
100
|
+
|
|
101
|
+
// Fetch documents by query
|
|
102
|
+
const documents = await client.fetchDocuments([
|
|
103
|
+
{type: 17, subType: 11}
|
|
104
|
+
]);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Data Structure Management
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
// Create a new data structure
|
|
111
|
+
const newStructure = await client.createDataStructure({
|
|
112
|
+
title: "Data resulting from Vision-Mission-Value-Canvas",
|
|
113
|
+
fields: [
|
|
114
|
+
{
|
|
115
|
+
name: "Mission value statement",
|
|
116
|
+
type: "string"
|
|
117
|
+
},
|
|
118
|
+
// Add more fields as needed
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Update a data structure
|
|
123
|
+
await client.updateDataStructure('structure-id', {
|
|
124
|
+
title: 'Updated Structure Title',
|
|
125
|
+
fields: [
|
|
126
|
+
{name: 'New Field Name', type: 'number'}
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Delete a data structure
|
|
131
|
+
await client.deleteDataStructure('structure-id');
|
|
132
|
+
|
|
133
|
+
// List all data structures
|
|
134
|
+
const structures = await client.listDataStructures();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Document Type Management
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// List all document types
|
|
141
|
+
const docTypes = await client.listDocumentTypes();
|
|
142
|
+
|
|
143
|
+
// Create or update a document type
|
|
144
|
+
const newDocType = await client.createOrUpdateDocumentType({
|
|
145
|
+
name: "HR Wages",
|
|
146
|
+
description: "HR Wage information Document listing wages per personnel ID",
|
|
147
|
+
type: 14,
|
|
148
|
+
subType: 2,
|
|
149
|
+
defaultStructureID: 'structure-id'
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Delete a document type
|
|
153
|
+
await client.deleteDocumentType('doc-type-id');
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## API Reference
|
|
157
|
+
|
|
158
|
+
### Client Class
|
|
159
|
+
|
|
160
|
+
#### Constructor
|
|
161
|
+
|
|
162
|
+
- `new docPouchClient(baseUrl: string, port: number, callback?: (event: string, data: any) => void)`
|
|
163
|
+
|
|
164
|
+
#### Methods
|
|
165
|
+
|
|
166
|
+
- `login(credentials: { name: string, password: string }): Promise<{ token: string } | null>`
|
|
167
|
+
- `setToken(token: string): void`
|
|
168
|
+
- `listUsers(): Promise<UserDisplay[]>`
|
|
169
|
+
- `createUser(userData: UserCreation): Promise<UserDisplay>`
|
|
170
|
+
- `updateUser(id: string, userData: UserUpdate): Promise<void>`
|
|
171
|
+
- `removeUser(id: string): Promise<void>`
|
|
172
|
+
- `createDocument(docData: NewDocument): Promise<Document>`
|
|
173
|
+
- `updateDocument(id: string, docData: Partial<Document>): Promise<void>`
|
|
174
|
+
- `deleteDocument(id: string): Promise<void>`
|
|
175
|
+
- `fetchDocuments(query: DocumentQuery[]): Promise<Document[]>`
|
|
176
|
+
- `createDataStructure(structureData: DataStructureCreation): Promise<DataStructure>`
|
|
177
|
+
- `updateDataStructure(id: string, structureData: Partial<DataStructure>): Promise<void>`
|
|
178
|
+
- `deleteDataStructure(id: string): Promise<void>`
|
|
179
|
+
- `listDataStructures(): Promise<DataStructure[]>`
|
|
180
|
+
- `listDocumentTypes(): Promise<DocumentTypeEdit[]>`
|
|
181
|
+
- `createOrUpdateDocumentType(typeData: DocumentTypeEdit): Promise<void>`
|
|
182
|
+
- `deleteDocumentType(id: string): Promise<void>`
|
|
183
|
+
|
|
184
|
+
## Types
|
|
185
|
+
|
|
186
|
+
### UserDisplay
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
{
|
|
190
|
+
_id: number;
|
|
191
|
+
name: string;
|
|
192
|
+
email ? : string;
|
|
193
|
+
department: string;
|
|
194
|
+
group: string;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### UserCreation
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
{
|
|
202
|
+
name: string;
|
|
203
|
+
password: string;
|
|
204
|
+
email ? : string;
|
|
205
|
+
department: string;
|
|
206
|
+
group: string;
|
|
207
|
+
isAdmin: boolean;
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### UserUpdate
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
{
|
|
215
|
+
name ? : string;
|
|
216
|
+
password ? : string;
|
|
217
|
+
email ? : string;
|
|
218
|
+
isAdmin ? : boolean;
|
|
219
|
+
department ? : string;
|
|
220
|
+
group ? : string;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Document
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
{
|
|
228
|
+
_id: string;
|
|
229
|
+
type: number;
|
|
230
|
+
subType: number;
|
|
231
|
+
title: string;
|
|
232
|
+
content: string;
|
|
233
|
+
shareWithGroup: boolean;
|
|
234
|
+
shareWithDepartment: boolean;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### NewDocument
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
{
|
|
242
|
+
type: number;
|
|
243
|
+
subType: number;
|
|
244
|
+
title: string;
|
|
245
|
+
content: string;
|
|
246
|
+
shareWithGroup: boolean;
|
|
247
|
+
shareWithDepartment: boolean;
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### DocumentQuery
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
{
|
|
255
|
+
_id ? : string;
|
|
256
|
+
type ? : number;
|
|
257
|
+
subType ? : number;
|
|
258
|
+
title ? : string;
|
|
259
|
+
description ? : string;
|
|
260
|
+
shareWithGroup ? : boolean;
|
|
261
|
+
shareWithDepartment ? : boolean;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### DataStructure
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
{
|
|
269
|
+
_id: number;
|
|
270
|
+
title: string;
|
|
271
|
+
fields: DataField[];
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### DataStructureCreation
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
{
|
|
279
|
+
title: string;
|
|
280
|
+
fields: DataField[];
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### DataField
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
{
|
|
288
|
+
name: string;
|
|
289
|
+
type: 'number' | 'string' | 'boolean' | 'array' | 'structure';
|
|
290
|
+
items ? : string; // For array and structure types
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### DocumentTypeEdit
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
{
|
|
298
|
+
_id ? : string;
|
|
299
|
+
name: string;
|
|
300
|
+
description ? : string;
|
|
301
|
+
type: number;
|
|
302
|
+
subType: number;
|
|
303
|
+
defaultStructureID ? : string;
|
|
304
|
+
}
|
|
305
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { I_UserEntry, I_UserLogin, I_UserCreation, I_UserUpdate, I_UserDisplay, I_DocumentEntry, I_DataStructure, I_LoginResponse, I_DocumentQuery, I_StructureCreation, I_WsMessage, I_EventString, I_DocumentType } from "./types.js";
|
|
2
1
|
import { Socket } from "socket.io-client";
|
|
3
2
|
/**
|
|
4
3
|
* Client for interacting with docPouch API.
|
|
@@ -91,3 +90,119 @@ export default class docPouchClient {
|
|
|
91
90
|
private initWebSocket;
|
|
92
91
|
private request;
|
|
93
92
|
}
|
|
93
|
+
export interface I_UserEntry extends I_UserCreation {
|
|
94
|
+
_id: string;
|
|
95
|
+
}
|
|
96
|
+
export interface I_UserLogin {
|
|
97
|
+
name: string;
|
|
98
|
+
password: string;
|
|
99
|
+
}
|
|
100
|
+
export interface I_UserCreation {
|
|
101
|
+
name: string;
|
|
102
|
+
password: string;
|
|
103
|
+
email?: string;
|
|
104
|
+
department: string;
|
|
105
|
+
group: string;
|
|
106
|
+
isAdmin: boolean;
|
|
107
|
+
}
|
|
108
|
+
export interface I_UserUpdate {
|
|
109
|
+
_id: string;
|
|
110
|
+
name?: string;
|
|
111
|
+
password?: string;
|
|
112
|
+
email?: string;
|
|
113
|
+
department?: string;
|
|
114
|
+
group?: string;
|
|
115
|
+
isAdmin?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface I_UserDisplay {
|
|
118
|
+
_id: string;
|
|
119
|
+
username: string;
|
|
120
|
+
department: string;
|
|
121
|
+
group: string;
|
|
122
|
+
email?: string;
|
|
123
|
+
}
|
|
124
|
+
export interface I_LoginResponse {
|
|
125
|
+
token: string;
|
|
126
|
+
isAdmin: boolean;
|
|
127
|
+
userName: string;
|
|
128
|
+
}
|
|
129
|
+
export interface I_DocumentEntry extends I_DocumentCreationOwned {
|
|
130
|
+
_id: string;
|
|
131
|
+
}
|
|
132
|
+
export interface I_DocumentCreation {
|
|
133
|
+
title: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
type: number;
|
|
136
|
+
subType: number;
|
|
137
|
+
content: any;
|
|
138
|
+
shareWithGroup: boolean;
|
|
139
|
+
shareWithDepartment: boolean;
|
|
140
|
+
}
|
|
141
|
+
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
142
|
+
owner: string;
|
|
143
|
+
}
|
|
144
|
+
export interface I_DocumentUpdate extends I_DocumentQuery {
|
|
145
|
+
_id: string;
|
|
146
|
+
content?: any;
|
|
147
|
+
description?: string;
|
|
148
|
+
}
|
|
149
|
+
export interface I_DocumentQuery {
|
|
150
|
+
_id?: string;
|
|
151
|
+
owner?: string;
|
|
152
|
+
title?: string;
|
|
153
|
+
type?: number;
|
|
154
|
+
subType?: number;
|
|
155
|
+
shareWithGroup?: boolean;
|
|
156
|
+
shareWithDepartment?: boolean;
|
|
157
|
+
}
|
|
158
|
+
export interface I_DataStructure {
|
|
159
|
+
_id?: string | undefined;
|
|
160
|
+
name: string;
|
|
161
|
+
description: string;
|
|
162
|
+
fields: I_StructureField[];
|
|
163
|
+
}
|
|
164
|
+
export interface I_StructureField {
|
|
165
|
+
name: string;
|
|
166
|
+
type: string;
|
|
167
|
+
items?: string;
|
|
168
|
+
}
|
|
169
|
+
export interface I_StructureEntry {
|
|
170
|
+
_id?: string;
|
|
171
|
+
name: string;
|
|
172
|
+
description: string;
|
|
173
|
+
fields: I_StructureField[];
|
|
174
|
+
}
|
|
175
|
+
export interface I_StructureCreation {
|
|
176
|
+
name: string;
|
|
177
|
+
description?: string;
|
|
178
|
+
fields: I_StructureField[];
|
|
179
|
+
}
|
|
180
|
+
export interface I_StructureUpdate {
|
|
181
|
+
_id: string;
|
|
182
|
+
name?: string;
|
|
183
|
+
description?: string;
|
|
184
|
+
fields?: I_StructureField[];
|
|
185
|
+
}
|
|
186
|
+
export interface I_DocumentType {
|
|
187
|
+
_id?: string;
|
|
188
|
+
type: number;
|
|
189
|
+
subType: number;
|
|
190
|
+
name: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
defaultStructureID?: string;
|
|
193
|
+
}
|
|
194
|
+
export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" | "newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" | "removedUser" | "removedStructure" | "removedDocument" | "removedType";
|
|
195
|
+
export interface I_WsMessage {
|
|
196
|
+
newDocument?: I_DocumentEntry;
|
|
197
|
+
newStructure?: I_StructureEntry;
|
|
198
|
+
newUser?: I_UserEntry;
|
|
199
|
+
removedID?: string;
|
|
200
|
+
changedDocument?: I_DocumentUpdate;
|
|
201
|
+
changedStructure?: I_StructureUpdate;
|
|
202
|
+
changedUser?: I_UserUpdate;
|
|
203
|
+
confirmSubscription?: boolean;
|
|
204
|
+
confirmUnsubscription?: boolean;
|
|
205
|
+
heartbeatPing?: number;
|
|
206
|
+
heartbeatPong?: number;
|
|
207
|
+
newType?: I_DocumentType;
|
|
208
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -94,7 +94,7 @@ export default class docPouchClient {
|
|
|
94
94
|
if (this.realTimeSync) {
|
|
95
95
|
this.initWebSocket();
|
|
96
96
|
}
|
|
97
|
-
return { token: response.token, isAdmin: response.isAdmin };
|
|
97
|
+
return { token: response.token, isAdmin: response.isAdmin, userName: response.userName };
|
|
98
98
|
}
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
@@ -141,7 +141,7 @@ export default class docPouchClient {
|
|
|
141
141
|
}
|
|
142
142
|
// Data Type Endpoints
|
|
143
143
|
async createType(type) {
|
|
144
|
-
return await this.request('/types/write', '
|
|
144
|
+
return await this.request('/types/write', 'POST', type);
|
|
145
145
|
}
|
|
146
146
|
async removeType(typeID) {
|
|
147
147
|
return await this.request(`/types/remove/${typeID}`, 'DELETE');
|
|
@@ -150,7 +150,7 @@ export default class docPouchClient {
|
|
|
150
150
|
return await this.request('/types/list', 'GET');
|
|
151
151
|
}
|
|
152
152
|
async updateType(updatedType) {
|
|
153
|
-
await this.request(`/types/write`, '
|
|
153
|
+
await this.request(`/types/write`, 'POST', updatedType);
|
|
154
154
|
}
|
|
155
155
|
setToken(token) {
|
|
156
156
|
console.log("Setting token to:", token ? "***token***" : "null");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docpouch-client",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
"author": "Jan Frecè",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"description": "A small class to more easily access the docPouch API",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/BFH-JTF/docpouch-client"
|
|
27
|
+
},
|
|
24
28
|
"devDependencies": {
|
|
25
29
|
"@types/jest": "^30.0.0",
|
|
26
|
-
"@types/node": "^24.0.
|
|
27
|
-
"jest": "^30.0.
|
|
28
|
-
"ts-jest": "^29.4.0"
|
|
30
|
+
"@types/node": "^24.0.7",
|
|
31
|
+
"jest": "^30.0.3",
|
|
32
|
+
"ts-jest": "^29.4.0",
|
|
33
|
+
"typescript": "^5.8.3"
|
|
29
34
|
},
|
|
30
35
|
"dependencies": {
|
|
31
|
-
"socket.io-client": "^4.8.1"
|
|
32
|
-
"typescript": "^5.8.3"
|
|
36
|
+
"socket.io-client": "^4.8.1"
|
|
33
37
|
}
|
|
34
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
I_UserEntry,
|
|
3
|
-
I_UserLogin,
|
|
4
|
-
I_UserCreation,
|
|
5
|
-
I_UserUpdate,
|
|
6
|
-
I_UserDisplay,
|
|
7
|
-
I_DocumentEntry,
|
|
8
|
-
I_DataStructure,
|
|
9
|
-
I_LoginResponse, I_DocumentQuery, I_StructureCreation, I_WsMessage, I_EventString, I_DocumentType
|
|
10
|
-
} from "./types.js";
|
|
11
1
|
import {io, Socket} from "socket.io-client";
|
|
12
2
|
import packetJson from '../package.json'
|
|
13
3
|
|
|
@@ -134,7 +124,7 @@ export default class docPouchClient {
|
|
|
134
124
|
this.initWebSocket();
|
|
135
125
|
}
|
|
136
126
|
|
|
137
|
-
return {token: response.token, isAdmin: response.isAdmin};
|
|
127
|
+
return {token: response.token, isAdmin: response.isAdmin, userName: response.userName};
|
|
138
128
|
}
|
|
139
129
|
return null;
|
|
140
130
|
}
|
|
@@ -195,7 +185,7 @@ export default class docPouchClient {
|
|
|
195
185
|
|
|
196
186
|
// Data Type Endpoints
|
|
197
187
|
async createType(type: I_DocumentType): Promise<I_DocumentType> {
|
|
198
|
-
return await this.request<I_DocumentType>('/types/write', '
|
|
188
|
+
return await this.request<I_DocumentType>('/types/write', 'POST', type);
|
|
199
189
|
}
|
|
200
190
|
|
|
201
191
|
async removeType(typeID: string) {
|
|
@@ -207,7 +197,7 @@ export default class docPouchClient {
|
|
|
207
197
|
}
|
|
208
198
|
|
|
209
199
|
async updateType(updatedType: I_DocumentType): Promise<void> {
|
|
210
|
-
await this.request<void>(`/types/write`, '
|
|
200
|
+
await this.request<void>(`/types/write`, 'POST', updatedType);
|
|
211
201
|
}
|
|
212
202
|
|
|
213
203
|
setToken(token: string | null): void {
|
|
@@ -393,5 +383,151 @@ export default class docPouchClient {
|
|
|
393
383
|
|
|
394
384
|
return await response.json() as T;
|
|
395
385
|
}
|
|
396
|
-
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Common type definitions for both frontend and backend
|
|
389
|
+
|
|
390
|
+
// User related types
|
|
391
|
+
export interface I_UserEntry extends I_UserCreation{
|
|
392
|
+
_id: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export interface I_UserLogin {
|
|
396
|
+
name: string;
|
|
397
|
+
password: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface I_UserCreation {
|
|
401
|
+
name: string;
|
|
402
|
+
password: string;
|
|
403
|
+
email?: string;
|
|
404
|
+
department: string;
|
|
405
|
+
group: string;
|
|
406
|
+
isAdmin: boolean;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface I_UserUpdate {
|
|
410
|
+
_id: string;
|
|
411
|
+
name?: string;
|
|
412
|
+
password?: string;
|
|
413
|
+
email?: string;
|
|
414
|
+
department?: string;
|
|
415
|
+
group?: string;
|
|
416
|
+
isAdmin?: boolean;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export interface I_UserDisplay {
|
|
420
|
+
_id: string;
|
|
421
|
+
username: string;
|
|
422
|
+
department: string;
|
|
423
|
+
group: string;
|
|
424
|
+
email?: string;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export interface I_LoginResponse {
|
|
428
|
+
token: string;
|
|
429
|
+
isAdmin: boolean;
|
|
430
|
+
userName: string;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Document related types
|
|
434
|
+
export interface I_DocumentEntry extends I_DocumentCreationOwned{
|
|
435
|
+
_id: string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface I_DocumentCreation {
|
|
439
|
+
title: string;
|
|
440
|
+
description?: string;
|
|
441
|
+
type: number;
|
|
442
|
+
subType: number;
|
|
443
|
+
content: any;
|
|
444
|
+
shareWithGroup: boolean;
|
|
445
|
+
shareWithDepartment: boolean;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
450
|
+
owner: string;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface I_DocumentUpdate extends I_DocumentQuery{
|
|
454
|
+
_id: string;
|
|
455
|
+
content?: any;
|
|
456
|
+
description?: string;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export interface I_DocumentQuery {
|
|
460
|
+
_id?: string;
|
|
461
|
+
owner?: string;
|
|
462
|
+
title?: string;
|
|
463
|
+
type?: number;
|
|
464
|
+
subType?: number;
|
|
465
|
+
shareWithGroup?: boolean;
|
|
466
|
+
shareWithDepartment?: boolean;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
// Structure related types
|
|
471
|
+
export interface I_DataStructure {
|
|
472
|
+
_id?: string | undefined;
|
|
473
|
+
name: string;
|
|
474
|
+
description: string;
|
|
475
|
+
fields: I_StructureField[];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export interface I_StructureField {
|
|
479
|
+
name: string;
|
|
480
|
+
type: string;
|
|
481
|
+
items?: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export interface I_StructureEntry {
|
|
485
|
+
_id?: string;
|
|
486
|
+
name: string;
|
|
487
|
+
description: string;
|
|
488
|
+
fields: I_StructureField[];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
export interface I_StructureCreation {
|
|
493
|
+
name: string;
|
|
494
|
+
description?: string;
|
|
495
|
+
fields: I_StructureField[];
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export interface I_StructureUpdate {
|
|
499
|
+
_id: string;
|
|
500
|
+
name?: string;
|
|
501
|
+
description?: string;
|
|
502
|
+
fields?: I_StructureField[];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Document type related types
|
|
506
|
+
export interface I_DocumentType {
|
|
507
|
+
_id?: string;
|
|
508
|
+
type: number;
|
|
509
|
+
subType: number;
|
|
510
|
+
name: string;
|
|
511
|
+
description?: string;
|
|
512
|
+
defaultStructureID?: string;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// WebSocket-related types
|
|
516
|
+
export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
|
|
517
|
+
"newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" |
|
|
518
|
+
"removedUser" | "removedStructure" | "removedDocument" | "removedType";
|
|
519
|
+
|
|
520
|
+
export interface I_WsMessage {
|
|
521
|
+
newDocument?: I_DocumentEntry;
|
|
522
|
+
newStructure?: I_StructureEntry;
|
|
523
|
+
newUser?: I_UserEntry;
|
|
524
|
+
removedID?: string;
|
|
525
|
+
changedDocument?: I_DocumentUpdate;
|
|
526
|
+
changedStructure?: I_StructureUpdate;
|
|
527
|
+
changedUser?: I_UserUpdate;
|
|
528
|
+
confirmSubscription?: boolean;
|
|
529
|
+
confirmUnsubscription?: boolean;
|
|
530
|
+
heartbeatPing?: number;
|
|
531
|
+
heartbeatPong?: number;
|
|
532
|
+
newType?: I_DocumentType;
|
|
397
533
|
}
|
package/tsconfig.json
CHANGED
package/dist/types.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
export interface I_UserEntry extends I_UserCreation {
|
|
2
|
-
_id: string;
|
|
3
|
-
}
|
|
4
|
-
export interface I_UserLogin {
|
|
5
|
-
name: string;
|
|
6
|
-
password: string;
|
|
7
|
-
}
|
|
8
|
-
export interface I_UserCreation {
|
|
9
|
-
name: string;
|
|
10
|
-
password: string;
|
|
11
|
-
email?: string;
|
|
12
|
-
department: string;
|
|
13
|
-
group: string;
|
|
14
|
-
isAdmin: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface I_UserUpdate {
|
|
17
|
-
name?: string;
|
|
18
|
-
password?: string;
|
|
19
|
-
email?: string;
|
|
20
|
-
department?: string;
|
|
21
|
-
group?: string;
|
|
22
|
-
isAdmin?: boolean;
|
|
23
|
-
}
|
|
24
|
-
export interface I_UserDisplay {
|
|
25
|
-
_id: string;
|
|
26
|
-
username: string;
|
|
27
|
-
department: string;
|
|
28
|
-
group: string;
|
|
29
|
-
email?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface I_LoginResponse {
|
|
32
|
-
token: string;
|
|
33
|
-
isAdmin: boolean;
|
|
34
|
-
}
|
|
35
|
-
export interface I_DocumentEntry extends I_DocumentCreationOwned {
|
|
36
|
-
_id: string;
|
|
37
|
-
}
|
|
38
|
-
export interface I_DocumentCreation {
|
|
39
|
-
title: string;
|
|
40
|
-
description?: string;
|
|
41
|
-
type: number;
|
|
42
|
-
subType: number;
|
|
43
|
-
content: any;
|
|
44
|
-
}
|
|
45
|
-
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
46
|
-
owner: string;
|
|
47
|
-
}
|
|
48
|
-
export interface I_DocumentUpdate extends I_DocumentQuery {
|
|
49
|
-
_id: string;
|
|
50
|
-
content?: any;
|
|
51
|
-
description?: string;
|
|
52
|
-
}
|
|
53
|
-
export interface I_DocumentQuery {
|
|
54
|
-
_id?: string;
|
|
55
|
-
owner?: string;
|
|
56
|
-
title?: string;
|
|
57
|
-
type?: number;
|
|
58
|
-
subType?: number;
|
|
59
|
-
}
|
|
60
|
-
export interface I_DataStructure {
|
|
61
|
-
_id?: string | undefined;
|
|
62
|
-
name: string;
|
|
63
|
-
description: string;
|
|
64
|
-
reference?: any;
|
|
65
|
-
fields: any[];
|
|
66
|
-
}
|
|
67
|
-
export interface I_StructureEntry {
|
|
68
|
-
_id?: string;
|
|
69
|
-
name: string;
|
|
70
|
-
description: string;
|
|
71
|
-
reference?: any;
|
|
72
|
-
fields: any[];
|
|
73
|
-
}
|
|
74
|
-
export interface I_StructureCreation {
|
|
75
|
-
name: string;
|
|
76
|
-
description?: string;
|
|
77
|
-
reference?: any;
|
|
78
|
-
fields: any[];
|
|
79
|
-
}
|
|
80
|
-
export interface I_StructureUpdate {
|
|
81
|
-
_id: string;
|
|
82
|
-
name?: string;
|
|
83
|
-
description?: string;
|
|
84
|
-
reference?: any;
|
|
85
|
-
fields?: any[];
|
|
86
|
-
}
|
|
87
|
-
export interface I_DocumentType {
|
|
88
|
-
_id?: string;
|
|
89
|
-
type: number;
|
|
90
|
-
subType: number;
|
|
91
|
-
name: string;
|
|
92
|
-
description?: string;
|
|
93
|
-
defaultStructureID?: string;
|
|
94
|
-
}
|
|
95
|
-
export type I_EventString = 'subscribe' | 'unsubscribe' | 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" | "newUser" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "confirmSubscription" | "confirmUnsubscription" | "removedUser" | "removedStructure" | "removedDocument";
|
|
96
|
-
export interface I_WsMessage {
|
|
97
|
-
newDocument?: I_DocumentEntry;
|
|
98
|
-
newStructure?: I_StructureEntry;
|
|
99
|
-
newUser?: I_UserEntry;
|
|
100
|
-
removedID?: string;
|
|
101
|
-
changedDocument?: I_DocumentUpdate;
|
|
102
|
-
changedStructure?: I_StructureUpdate;
|
|
103
|
-
changedUser?: I_UserUpdate;
|
|
104
|
-
confirmSubscription?: boolean;
|
|
105
|
-
confirmUnsubscription?: boolean;
|
|
106
|
-
heartbeatPing?: number;
|
|
107
|
-
heartbeatPong?: number;
|
|
108
|
-
}
|
package/dist/types.js
DELETED
package/src/types.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// Common type definitions for both frontend and backend
|
|
2
|
-
|
|
3
|
-
// User related types
|
|
4
|
-
export interface I_UserEntry extends I_UserCreation{
|
|
5
|
-
_id: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface I_UserLogin {
|
|
9
|
-
name: string;
|
|
10
|
-
password: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface I_UserCreation {
|
|
14
|
-
name: string;
|
|
15
|
-
password: string;
|
|
16
|
-
email?: string;
|
|
17
|
-
department: string;
|
|
18
|
-
group: string;
|
|
19
|
-
isAdmin: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface I_UserUpdate {
|
|
23
|
-
name?: string;
|
|
24
|
-
password?: string;
|
|
25
|
-
email?: string;
|
|
26
|
-
department?: string;
|
|
27
|
-
group?: string;
|
|
28
|
-
isAdmin?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface I_UserDisplay {
|
|
32
|
-
_id: string;
|
|
33
|
-
username: string;
|
|
34
|
-
department: string;
|
|
35
|
-
group: string;
|
|
36
|
-
email?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface I_LoginResponse {
|
|
40
|
-
token: string;
|
|
41
|
-
isAdmin: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Document related types
|
|
45
|
-
export interface I_DocumentEntry extends I_DocumentCreationOwned{
|
|
46
|
-
_id: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface I_DocumentCreation {
|
|
50
|
-
title: string;
|
|
51
|
-
description?: string;
|
|
52
|
-
type: number;
|
|
53
|
-
subType: number;
|
|
54
|
-
content: any;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
58
|
-
owner: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface I_DocumentUpdate extends I_DocumentQuery{
|
|
62
|
-
_id: string;
|
|
63
|
-
content?: any;
|
|
64
|
-
description?: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface I_DocumentQuery {
|
|
68
|
-
_id?: string;
|
|
69
|
-
owner?: string;
|
|
70
|
-
title?: string;
|
|
71
|
-
type?: number;
|
|
72
|
-
subType?: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Structure related types
|
|
76
|
-
export interface I_DataStructure {
|
|
77
|
-
_id?: string | undefined;
|
|
78
|
-
name: string;
|
|
79
|
-
description: string;
|
|
80
|
-
reference?: any;
|
|
81
|
-
fields: any[];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface I_StructureEntry {
|
|
85
|
-
_id?: string;
|
|
86
|
-
name: string;
|
|
87
|
-
description: string;
|
|
88
|
-
reference?: any;
|
|
89
|
-
fields: any[];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface I_StructureCreation {
|
|
93
|
-
name: string;
|
|
94
|
-
description?: string;
|
|
95
|
-
reference?: any;
|
|
96
|
-
fields: any[];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export interface I_StructureUpdate {
|
|
100
|
-
_id: string;
|
|
101
|
-
name?: string;
|
|
102
|
-
description?: string;
|
|
103
|
-
reference?: any;
|
|
104
|
-
fields?: any[];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Document type related types
|
|
108
|
-
export interface I_DocumentType {
|
|
109
|
-
_id?: string;
|
|
110
|
-
type: number;
|
|
111
|
-
subType: number;
|
|
112
|
-
name: string;
|
|
113
|
-
description?: string;
|
|
114
|
-
defaultStructureID?: string;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// WebSocket-related types
|
|
118
|
-
export type I_EventString = 'subscribe' | 'unsubscribe' | 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
|
|
119
|
-
"newUser" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "confirmSubscription" |
|
|
120
|
-
"confirmUnsubscription" | "removedUser" | "removedStructure" | "removedDocument";
|
|
121
|
-
|
|
122
|
-
export interface I_WsMessage {
|
|
123
|
-
newDocument?: I_DocumentEntry;
|
|
124
|
-
newStructure?: I_StructureEntry;
|
|
125
|
-
newUser?: I_UserEntry;
|
|
126
|
-
removedID?: string;
|
|
127
|
-
changedDocument?: I_DocumentUpdate;
|
|
128
|
-
changedStructure?: I_StructureUpdate;
|
|
129
|
-
changedUser?: I_UserUpdate;
|
|
130
|
-
confirmSubscription?: boolean;
|
|
131
|
-
confirmUnsubscription?: boolean;
|
|
132
|
-
heartbeatPing?: number;
|
|
133
|
-
heartbeatPong?: number;
|
|
134
|
-
}
|