@rimori/client 1.1.2 → 1.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 +21 -0
- package/dist/controller/SharedContentController.d.ts +16 -0
- package/dist/controller/SharedContentController.js +28 -3
- package/dist/core.d.ts +1 -0
- package/dist/plugin/RimoriClient.d.ts +6 -0
- package/dist/plugin/RimoriClient.js +8 -0
- package/package.json +1 -1
- package/src/controller/SharedContentController.ts +42 -2
- package/src/core.ts +2 -1
- package/src/plugin/RimoriClient.ts +8 -0
package/README.md
CHANGED
|
@@ -857,6 +857,27 @@ interface MyPluginData extends SharedContent<any> {
|
|
|
857
857
|
}
|
|
858
858
|
```
|
|
859
859
|
|
|
860
|
+
The SharedContent has this type definition:
|
|
861
|
+
|
|
862
|
+
````
|
|
863
|
+
export interface SharedContent<T> {
|
|
864
|
+
/** The type/category of the content (e.g. 'grammar_exercises', 'flashcards', etc.) */
|
|
865
|
+
contentType: string;
|
|
866
|
+
|
|
867
|
+
/** The human readable title/topic of the content */
|
|
868
|
+
topic: string;
|
|
869
|
+
|
|
870
|
+
/** Array of keywords/tags associated with the content for search and categorization */
|
|
871
|
+
keywords: string[];
|
|
872
|
+
|
|
873
|
+
/** The actual content data of type T */
|
|
874
|
+
data: T;
|
|
875
|
+
|
|
876
|
+
/** Whether this content should only be visible to the creator. Defaults to false if not specified */
|
|
877
|
+
privateTopic?: boolean;
|
|
878
|
+
}
|
|
879
|
+
```
|
|
880
|
+
|
|
860
881
|
## Examples
|
|
861
882
|
|
|
862
883
|
### Complete Plugin Example
|
|
@@ -59,11 +59,27 @@ export declare class SharedContentController {
|
|
|
59
59
|
* @throws {Error} if update fails.
|
|
60
60
|
*/
|
|
61
61
|
updateSharedContent<T>(id: string, updates: Partial<SharedContent<T>>): Promise<BasicAssignment<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* Soft delete shared content by setting the deleted_at timestamp.
|
|
64
|
+
* @param id - The ID of the content to delete.
|
|
65
|
+
* @returns The deleted shared content record.
|
|
66
|
+
* @throws {Error} if deletion fails or content not found.
|
|
67
|
+
*/
|
|
68
|
+
deleteSharedContent(id: string): Promise<BasicAssignment<any>>;
|
|
62
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Interface representing shared content in the system.
|
|
72
|
+
* @template T The type of data stored in the content
|
|
73
|
+
*/
|
|
63
74
|
export interface SharedContent<T> {
|
|
75
|
+
/** The type/category of the content (e.g. 'grammar_exercises', 'flashcards', etc.) */
|
|
64
76
|
contentType: string;
|
|
77
|
+
/** The human readable title/topic of the content */
|
|
65
78
|
topic: string;
|
|
79
|
+
/** Array of keywords/tags associated with the content for search and categorization */
|
|
66
80
|
keywords: string[];
|
|
81
|
+
/** The actual content data of type T */
|
|
67
82
|
data: T;
|
|
83
|
+
/** Whether this content should only be visible to the creator. Defaults to false if not specified */
|
|
68
84
|
privateTopic?: boolean;
|
|
69
85
|
}
|
|
@@ -28,6 +28,7 @@ export class SharedContentController {
|
|
|
28
28
|
.select("*, scc:shared_content_completed(id)")
|
|
29
29
|
.eq('content_type', contentType)
|
|
30
30
|
.is('scc.id', null)
|
|
31
|
+
.is('deleted_at', null)
|
|
31
32
|
.limit(10);
|
|
32
33
|
if (filter) {
|
|
33
34
|
query.contains('data', filter);
|
|
@@ -82,7 +83,8 @@ export class SharedContentController {
|
|
|
82
83
|
const query = this.supabase.from("shared_content")
|
|
83
84
|
.select("topic, keywords, scc:shared_content_completed(id)")
|
|
84
85
|
.eq('content_type', contentType)
|
|
85
|
-
.not('scc.id', 'is', null)
|
|
86
|
+
.not('scc.id', 'is', null)
|
|
87
|
+
.is('deleted_at', null);
|
|
86
88
|
if (filter) {
|
|
87
89
|
query.contains('data', filter);
|
|
88
90
|
}
|
|
@@ -96,7 +98,7 @@ export class SharedContentController {
|
|
|
96
98
|
}
|
|
97
99
|
getSharedContent(contentType, id) {
|
|
98
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const { data, error } = yield this.supabase.from("shared_content").select().eq('content_type', contentType).eq('id', id).single();
|
|
101
|
+
const { data, error } = yield this.supabase.from("shared_content").select().eq('content_type', contentType).eq('id', id).is('deleted_at', null).single();
|
|
100
102
|
if (error) {
|
|
101
103
|
console.error('error fetching shared content:', error);
|
|
102
104
|
throw new Error('error fetching shared content');
|
|
@@ -118,7 +120,7 @@ export class SharedContentController {
|
|
|
118
120
|
*/
|
|
119
121
|
getSharedContentList(contentType, filter, limit) {
|
|
120
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
const query = this.supabase.from("shared_content").select("*").eq('content_type', contentType).limit(limit !== null && limit !== void 0 ? limit : 30);
|
|
123
|
+
const query = this.supabase.from("shared_content").select("*").eq('content_type', contentType).is('deleted_at', null).limit(limit !== null && limit !== void 0 ? limit : 30);
|
|
122
124
|
if (filter) {
|
|
123
125
|
query.contains('data', filter);
|
|
124
126
|
}
|
|
@@ -188,4 +190,27 @@ export class SharedContentController {
|
|
|
188
190
|
return updatedContent[0];
|
|
189
191
|
});
|
|
190
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Soft delete shared content by setting the deleted_at timestamp.
|
|
195
|
+
* @param id - The ID of the content to delete.
|
|
196
|
+
* @returns The deleted shared content record.
|
|
197
|
+
* @throws {Error} if deletion fails or content not found.
|
|
198
|
+
*/
|
|
199
|
+
deleteSharedContent(id) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const { data: deletedContent, error } = yield this.supabase
|
|
202
|
+
.from("shared_content")
|
|
203
|
+
.update({ deleted_at: new Date().toISOString() })
|
|
204
|
+
.eq('id', id)
|
|
205
|
+
.select();
|
|
206
|
+
if (error) {
|
|
207
|
+
console.error('error deleting shared content:', error);
|
|
208
|
+
throw new Error('error deleting shared content');
|
|
209
|
+
}
|
|
210
|
+
if (!deletedContent || deletedContent.length === 0) {
|
|
211
|
+
throw new Error('shared content not found or already deleted');
|
|
212
|
+
}
|
|
213
|
+
return deletedContent[0];
|
|
214
|
+
});
|
|
215
|
+
}
|
|
191
216
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -172,6 +172,12 @@ export declare class RimoriClient {
|
|
|
172
172
|
* @param assignmentId The id of the shared content item to complete.
|
|
173
173
|
*/
|
|
174
174
|
complete: (contentType: string, assignmentId: string) => Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Delete a shared content item.
|
|
177
|
+
* @param id The id of the shared content item to delete.
|
|
178
|
+
* @returns The deleted shared content item.
|
|
179
|
+
*/
|
|
180
|
+
delete: (id: string) => Promise<BasicAssignment<any>>;
|
|
175
181
|
};
|
|
176
182
|
};
|
|
177
183
|
}
|
|
@@ -176,6 +176,14 @@ export class RimoriClient {
|
|
|
176
176
|
*/
|
|
177
177
|
complete: (contentType, assignmentId) => __awaiter(this, void 0, void 0, function* () {
|
|
178
178
|
return yield this.sharedContentController.completeSharedContent(contentType, assignmentId);
|
|
179
|
+
}),
|
|
180
|
+
/**
|
|
181
|
+
* Delete a shared content item.
|
|
182
|
+
* @param id The id of the shared content item to delete.
|
|
183
|
+
* @returns The deleted shared content item.
|
|
184
|
+
*/
|
|
185
|
+
delete: (id) => __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
return yield this.sharedContentController.deleteSharedContent(id);
|
|
179
187
|
})
|
|
180
188
|
}
|
|
181
189
|
};
|
package/package.json
CHANGED
|
@@ -46,6 +46,7 @@ export class SharedContentController {
|
|
|
46
46
|
.select("*, scc:shared_content_completed(id)")
|
|
47
47
|
.eq('content_type', contentType)
|
|
48
48
|
.is('scc.id', null)
|
|
49
|
+
.is('deleted_at', null)
|
|
49
50
|
.limit(10);
|
|
50
51
|
|
|
51
52
|
if (filter) {
|
|
@@ -113,6 +114,7 @@ export class SharedContentController {
|
|
|
113
114
|
.select("topic, keywords, scc:shared_content_completed(id)")
|
|
114
115
|
.eq('content_type', contentType)
|
|
115
116
|
.not('scc.id', 'is', null)
|
|
117
|
+
.is('deleted_at', null)
|
|
116
118
|
|
|
117
119
|
if (filter) {
|
|
118
120
|
query.contains('data', filter);
|
|
@@ -128,7 +130,7 @@ export class SharedContentController {
|
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
public async getSharedContent<T>(contentType: string, id: string): Promise<BasicAssignment<T>> {
|
|
131
|
-
const { data, error } = await this.supabase.from("shared_content").select().eq('content_type', contentType).eq('id', id).single();
|
|
133
|
+
const { data, error } = await this.supabase.from("shared_content").select().eq('content_type', contentType).eq('id', id).is('deleted_at', null).single();
|
|
132
134
|
if (error) {
|
|
133
135
|
console.error('error fetching shared content:', error);
|
|
134
136
|
throw new Error('error fetching shared content');
|
|
@@ -148,7 +150,7 @@ export class SharedContentController {
|
|
|
148
150
|
* @returns Array of shared content matching the criteria.
|
|
149
151
|
*/
|
|
150
152
|
public async getSharedContentList<T>(contentType: string, filter?: SharedContentFilter, limit?: number): Promise<BasicAssignment<T>[]> {
|
|
151
|
-
const query = this.supabase.from("shared_content").select("*").eq('content_type', contentType).limit(limit ?? 30);
|
|
153
|
+
const query = this.supabase.from("shared_content").select("*").eq('content_type', contentType).is('deleted_at', null).limit(limit ?? 30);
|
|
152
154
|
|
|
153
155
|
if (filter) {
|
|
154
156
|
query.contains('data', filter);
|
|
@@ -221,12 +223,50 @@ export class SharedContentController {
|
|
|
221
223
|
|
|
222
224
|
return updatedContent[0];
|
|
223
225
|
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Soft delete shared content by setting the deleted_at timestamp.
|
|
229
|
+
* @param id - The ID of the content to delete.
|
|
230
|
+
* @returns The deleted shared content record.
|
|
231
|
+
* @throws {Error} if deletion fails or content not found.
|
|
232
|
+
*/
|
|
233
|
+
public async deleteSharedContent(id: string): Promise<BasicAssignment<any>> {
|
|
234
|
+
const { data: deletedContent, error } = await this.supabase
|
|
235
|
+
.from("shared_content")
|
|
236
|
+
.update({ deleted_at: new Date().toISOString() })
|
|
237
|
+
.eq('id', id)
|
|
238
|
+
.select();
|
|
239
|
+
|
|
240
|
+
if (error) {
|
|
241
|
+
console.error('error deleting shared content:', error);
|
|
242
|
+
throw new Error('error deleting shared content');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (!deletedContent || deletedContent.length === 0) {
|
|
246
|
+
throw new Error('shared content not found or already deleted');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return deletedContent[0];
|
|
250
|
+
}
|
|
224
251
|
}
|
|
225
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Interface representing shared content in the system.
|
|
255
|
+
* @template T The type of data stored in the content
|
|
256
|
+
*/
|
|
226
257
|
export interface SharedContent<T> {
|
|
258
|
+
/** The type/category of the content (e.g. 'grammar_exercises', 'flashcards', etc.) */
|
|
227
259
|
contentType: string;
|
|
260
|
+
|
|
261
|
+
/** The human readable title/topic of the content */
|
|
228
262
|
topic: string;
|
|
263
|
+
|
|
264
|
+
/** Array of keywords/tags associated with the content for search and categorization */
|
|
229
265
|
keywords: string[];
|
|
266
|
+
|
|
267
|
+
/** The actual content data of type T */
|
|
230
268
|
data: T;
|
|
269
|
+
|
|
270
|
+
/** Whether this content should only be visible to the creator. Defaults to false if not specified */
|
|
231
271
|
privateTopic?: boolean;
|
|
232
272
|
}
|
package/src/core.ts
CHANGED
|
@@ -4,4 +4,5 @@ export * from "./plugin/PluginController";
|
|
|
4
4
|
export * from "./utils/difficultyConverter";
|
|
5
5
|
export * from "./utils/PluginUtils";
|
|
6
6
|
export * from "./worker/WorkerSetup";
|
|
7
|
-
export * from "./utils/Language";
|
|
7
|
+
export * from "./utils/Language";
|
|
8
|
+
export { SharedContent, BasicAssignment } from "./controller/SharedContentController";
|
|
@@ -293,6 +293,14 @@ export class RimoriClient {
|
|
|
293
293
|
*/
|
|
294
294
|
complete: async (contentType: string, assignmentId: string) => {
|
|
295
295
|
return await this.sharedContentController.completeSharedContent(contentType, assignmentId);
|
|
296
|
+
},
|
|
297
|
+
/**
|
|
298
|
+
* Delete a shared content item.
|
|
299
|
+
* @param id The id of the shared content item to delete.
|
|
300
|
+
* @returns The deleted shared content item.
|
|
301
|
+
*/
|
|
302
|
+
delete: async (id: string): Promise<BasicAssignment<any>> => {
|
|
303
|
+
return await this.sharedContentController.deleteSharedContent(id);
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
306
|
}
|