@cuboapp/api-backend 1.0.14 → 1.0.16
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/package.json +1 -1
- package/src/crdt/index.ts +10 -19
- package/src/crdt/types.ts +1 -1
package/package.json
CHANGED
package/src/crdt/index.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import { QueryTypes } from '@cuboapp/database'
|
|
2
2
|
import { CuboApiEntitiesMap, CuboEntity } from '@cuboapp/types'
|
|
3
3
|
import { Database } from '@hocuspocus/extension-database'
|
|
4
|
-
import {
|
|
5
|
-
beforeSyncPayload,
|
|
6
|
-
Document,
|
|
7
|
-
Hocuspocus,
|
|
8
|
-
onChangePayload,
|
|
9
|
-
onLoadDocumentPayload,
|
|
10
|
-
onStoreDocumentPayload,
|
|
11
|
-
Server
|
|
12
|
-
} from '@hocuspocus/server'
|
|
4
|
+
import { Server } from '@hocuspocus/server'
|
|
13
5
|
import { IncomingHttpHeaders } from 'http'
|
|
14
6
|
import * as Y from 'yjs'
|
|
15
7
|
|
|
16
8
|
import { CuboBackendApi } from '..'
|
|
17
|
-
import {
|
|
9
|
+
import { CuboDirectConnection } from './types'
|
|
18
10
|
|
|
19
11
|
export * from './types'
|
|
20
12
|
|
|
13
|
+
export * from '@hocuspocus/server'
|
|
14
|
+
|
|
21
15
|
export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
22
16
|
public server: Server
|
|
23
17
|
private documentPrefix = 'cubo'
|
|
@@ -43,7 +37,7 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
43
37
|
|
|
44
38
|
const { entityAlias, id } = this.parseDocumentName(documentName)
|
|
45
39
|
|
|
46
|
-
console.log('fetch', entityAlias, id)
|
|
40
|
+
// console.log('fetch', entityAlias, id)
|
|
47
41
|
if (id <= 0) {
|
|
48
42
|
return null
|
|
49
43
|
}
|
|
@@ -66,7 +60,7 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
66
60
|
|
|
67
61
|
const db = await this.api.helpers.getConnection('write')
|
|
68
62
|
|
|
69
|
-
const [data] = await db.connection.query(`SELECT ${fieldKey} from ${entityAlias} where id
|
|
63
|
+
const [data] = await db.connection.query(`SELECT ${fieldKey} from ${entityAlias} where id = :id`, {
|
|
70
64
|
type: QueryTypes.SELECT,
|
|
71
65
|
replacements: {
|
|
72
66
|
id
|
|
@@ -78,7 +72,6 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
78
72
|
}
|
|
79
73
|
|
|
80
74
|
const raw = (data as any)[fieldKey]
|
|
81
|
-
// console.log('raw', raw)
|
|
82
75
|
|
|
83
76
|
if (!raw) {
|
|
84
77
|
return null
|
|
@@ -150,7 +143,7 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
150
143
|
],
|
|
151
144
|
onAuthenticate: async (data) => {
|
|
152
145
|
try {
|
|
153
|
-
return onAuthenticate?.(this.api, data)
|
|
146
|
+
return await onAuthenticate?.(this.api, data)
|
|
154
147
|
} catch (err) {
|
|
155
148
|
throw new Error('Ошибка авторизации: ' + err)
|
|
156
149
|
}
|
|
@@ -278,13 +271,13 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
278
271
|
}
|
|
279
272
|
|
|
280
273
|
public isCrdtSupported(entity: CuboEntity) {
|
|
281
|
-
const hasCrdtField = entity.fields.some((f) => f.alias === this.api.options.crdt?.fieldAlias || this.defaultCrdtFieldAlias)
|
|
274
|
+
const hasCrdtField = entity.fields.some((f) => f.alias === (this.api.options.crdt?.fieldAlias || this.defaultCrdtFieldAlias))
|
|
282
275
|
|
|
283
276
|
return hasCrdtField
|
|
284
277
|
}
|
|
285
278
|
|
|
286
279
|
public getCrdtField(entity: CuboEntity) {
|
|
287
|
-
const crdtField = entity.fields.find((f) => f.alias === this.api.options.crdt?.fieldAlias || this.defaultCrdtFieldAlias)
|
|
280
|
+
const crdtField = entity.fields.find((f) => f.alias === (this.api.options.crdt?.fieldAlias || this.defaultCrdtFieldAlias))
|
|
288
281
|
|
|
289
282
|
return crdtField
|
|
290
283
|
}
|
|
@@ -308,7 +301,7 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
308
301
|
return this.server.hocuspocus.openDirectConnection(documentName, context)
|
|
309
302
|
}
|
|
310
303
|
|
|
311
|
-
public async connectionDisconnect(connection:
|
|
304
|
+
public async connectionDisconnect(connection: CuboDirectConnection) {
|
|
312
305
|
const { document, instance, context } = connection
|
|
313
306
|
|
|
314
307
|
if (document) {
|
|
@@ -414,5 +407,3 @@ export class CuboCrdt<T extends CuboApiEntitiesMap<T>> {
|
|
|
414
407
|
return Buffer.from(Y.encodeStateAsUpdate(document))
|
|
415
408
|
}
|
|
416
409
|
}
|
|
417
|
-
|
|
418
|
-
export { beforeSyncPayload, DirectConnection, Document, Hocuspocus, onChangePayload, onLoadDocumentPayload, onStoreDocumentPayload }
|
package/src/crdt/types.ts
CHANGED