@nu-art/live-docs-backend 0.500.0 → 0.500.6
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Module } from '@nu-art/ts-common';
|
|
2
2
|
import { DB_Document, LiveDocHistoryReqParams, LiveDocReqParams, Request_UpdateDocument } from '@nu-art/live-docs-shared';
|
|
3
3
|
import { API_LiveDoc } from '@nu-art/live-docs-shared/api';
|
|
4
|
-
export declare const CollectionName_LiveDocs = "live-docs";
|
|
5
4
|
type Config = {
|
|
6
5
|
projectId: string;
|
|
7
6
|
};
|
|
@@ -50,10 +50,10 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
50
50
|
done = true;
|
|
51
51
|
};
|
|
52
52
|
import { addItemToArrayAtIndex, ApiException, auditBy, BadImplementationException, Module, removeItemFromArray } from '@nu-art/ts-common';
|
|
53
|
-
import {
|
|
53
|
+
import { DBDef_DocumentHistory, } from '@nu-art/live-docs-shared';
|
|
54
|
+
import { ModuleBE_Firebase } from '@nu-art/firebase-backend';
|
|
54
55
|
import { ApiHandler } from '@nu-art/http-server';
|
|
55
56
|
import { ApiDef_LiveDoc } from '@nu-art/live-docs-shared/api';
|
|
56
|
-
export const CollectionName_LiveDocs = 'live-docs';
|
|
57
57
|
let ModuleBE_LiveDocs_Class = (() => {
|
|
58
58
|
let _classSuper = Module;
|
|
59
59
|
let _instanceExtraInitializers = [];
|
|
@@ -79,7 +79,7 @@ let ModuleBE_LiveDocs_Class = (() => {
|
|
|
79
79
|
super.init();
|
|
80
80
|
this.setDefaultConfig({ projectId: process.env.GCLOUD_PROJECT || '' });
|
|
81
81
|
const firestore = ModuleBE_Firebase.createAdminSession(this.config.projectId).getFirestore();
|
|
82
|
-
this.livedocs = firestore.getCollection(
|
|
82
|
+
this.livedocs = firestore.getCollection(DBDef_DocumentHistory);
|
|
83
83
|
}
|
|
84
84
|
async get(params) {
|
|
85
85
|
return this.getLiveDoc(params);
|
|
@@ -92,8 +92,9 @@ let ModuleBE_LiveDocs_Class = (() => {
|
|
|
92
92
|
}
|
|
93
93
|
async changeHistory(params) {
|
|
94
94
|
const key = params.key;
|
|
95
|
-
return await this.livedocs.
|
|
96
|
-
const
|
|
95
|
+
return await this.livedocs.runTransaction(async () => {
|
|
96
|
+
const results = await this.livedocs.query.custom({ where: { key } });
|
|
97
|
+
const docsHistory = results[0];
|
|
97
98
|
if (!docsHistory)
|
|
98
99
|
throw new BadImplementationException(`Cannot change history of an non-existing doc with key: ${key}`);
|
|
99
100
|
switch (params.change) {
|
|
@@ -109,7 +110,7 @@ let ModuleBE_LiveDocs_Class = (() => {
|
|
|
109
110
|
break;
|
|
110
111
|
}
|
|
111
112
|
docsHistory._audit = auditBy('temp-no-user');
|
|
112
|
-
await
|
|
113
|
+
await this.livedocs.set.item(docsHistory);
|
|
113
114
|
return docsHistory.docs[docsHistory.index];
|
|
114
115
|
});
|
|
115
116
|
}
|
|
@@ -132,19 +133,18 @@ let ModuleBE_LiveDocs_Class = (() => {
|
|
|
132
133
|
}
|
|
133
134
|
if (liveDocHistory.index > 0) {
|
|
134
135
|
this.logDebug(`Rewriting history, current index ${liveDocHistory.index}`);
|
|
135
|
-
// this.logDebug(`Rewriting history, current history ${JSON.stringify(liveDocHistory.docs, null, 2)}`);
|
|
136
136
|
liveDocHistory.docs.splice(0, liveDocHistory.index);
|
|
137
137
|
}
|
|
138
138
|
if (liveDocHistory.docs.length === 0 || liveDocHistory.docs[0].document !== docDB.document)
|
|
139
139
|
addItemToArrayAtIndex(liveDocHistory.docs, docDB, 0);
|
|
140
140
|
if (liveDocHistory.docs.length > 30)
|
|
141
141
|
removeItemFromArray(liveDocHistory.docs, liveDocHistory.docs[liveDocHistory.docs.length - 1]);
|
|
142
|
-
await this.livedocs.
|
|
142
|
+
await this.livedocs.set.item(liveDocHistory);
|
|
143
143
|
return docDB;
|
|
144
144
|
}
|
|
145
145
|
async getLiveDocHistory(docKey) {
|
|
146
|
-
const
|
|
147
|
-
return
|
|
146
|
+
const results = await this.livedocs.query.custom({ where: { key: docKey } });
|
|
147
|
+
return results[0] || { docs: [], key: docKey, index: 0 };
|
|
148
148
|
}
|
|
149
149
|
async getLiveDoc(params) {
|
|
150
150
|
const liveDocHistory = await this.getLiveDocHistory(params.key);
|
|
@@ -154,8 +154,6 @@ let ModuleBE_LiveDocs_Class = (() => {
|
|
|
154
154
|
if (liveDocHistory.docs && liveDocHistory.docs.length > 0 && liveDocHistory.docs[liveDocHistory.index]) {
|
|
155
155
|
this.logDebug(`Getting live doc from index: ${liveDocHistory.index}`);
|
|
156
156
|
liveDoc = liveDocHistory.docs[liveDocHistory.index];
|
|
157
|
-
//@ts-ignore
|
|
158
|
-
delete liveDoc.key;
|
|
159
157
|
}
|
|
160
158
|
return liveDoc;
|
|
161
159
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/live-docs-backend",
|
|
3
|
-
"version": "0.500.
|
|
3
|
+
"version": "0.500.6",
|
|
4
4
|
"description": "Live docs Backend",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TacB0sS",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
}
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@nu-art/live-docs-shared": "0.500.
|
|
42
|
-
"@nu-art/firebase-backend": "0.500.
|
|
43
|
-
"@nu-art/firebase-shared": "0.500.
|
|
44
|
-
"@nu-art/ts-common": "0.500.
|
|
41
|
+
"@nu-art/live-docs-shared": "0.500.6",
|
|
42
|
+
"@nu-art/firebase-backend": "0.500.6",
|
|
43
|
+
"@nu-art/firebase-shared": "0.500.6",
|
|
44
|
+
"@nu-art/ts-common": "0.500.6",
|
|
45
45
|
"express": "^4.18.2",
|
|
46
46
|
"firebase": "^11.9.0",
|
|
47
47
|
"firebase-admin": "13.4.0",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"react": "^18.0.0",
|
|
51
51
|
"react-dom": "^18.0.0",
|
|
52
52
|
"react-router-dom": "^6.9.0",
|
|
53
|
-
"@nu-art/http-server": "
|
|
54
|
-
"@nu-art/api-types": "
|
|
53
|
+
"@nu-art/http-server": "0.500.6",
|
|
54
|
+
"@nu-art/api-types": "0.500.6"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/react": "^18.0.0",
|