aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-08-13 16:31:13 -0400
committerbobzel <zzzman@gmail.com>2024-08-13 16:31:13 -0400
commit5960fa9635c28c2b609826005cb7595ec6b9fb75 (patch)
tree809485b4eec82cd8ccbc76d21eb036eb303efc5f
parent2d0237c80167986fc72c2894bac311c732b910d4 (diff)
fixed bugs introduced cleaning up database list ops.
-rw-r--r--src/client/DocServer.ts16
-rw-r--r--src/fields/Doc.ts2
-rw-r--r--src/server/Message.ts2
-rw-r--r--src/server/websocket.ts7
4 files changed, 16 insertions, 11 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 33fa928f2..c644308b7 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -34,7 +34,7 @@ export namespace DocServer {
throw new Error("Can't use DocServer without calling init first");
}
let _UpdateField: (id: string, diff: serverOpType) => void = errorFunc;
- let _CreateField: (field: Doc) => void = errorFunc;
+ let _CreateDocField: (field: Doc) => void = errorFunc;
export function AddServerHandler<T>(socket: Socket, message: Message<T>, handler: (args: T) => void) {
socket.on(message.Message, Utils.loggingCallback('Incoming', handler, message.Name));
@@ -132,7 +132,7 @@ export namespace DocServer {
export function makeReadOnly() {
if (!_isReadOnly) {
_isReadOnly = true;
- _CreateField = field => {
+ _CreateDocField = field => {
_cache[field[Id]] = field;
};
_UpdateField = emptyFunction;
@@ -357,20 +357,20 @@ export namespace DocServer {
}
/**
- * A wrapper around the function local variable _createField.
+ * A wrapper around the function local variable _CreateDocField.
* This allows us to swap in different executions while comfortably
* calling the same function throughout the code base (such as in Util.makeReadonly())
* @param field the [RefField] to be serialized and sent to the server to be stored in the database
*/
- export function CreateField(field: Doc) {
+ export function CreateDocField(field: Doc) {
_cacheNeedsUpdate = true;
- _CreateField(field);
+ _CreateDocField(field);
}
- function _CreateFieldImpl(field: Doc) {
+ function _CreateDocFieldImpl(field: Doc) {
_cache[field[Id]] = field;
const initialState = SerializationHelper.Serialize(field);
- ClientUtils.CurrentUserEmail() !== 'guest' && DocServer.Emit(_socket, MessageStore.CreateField, initialState);
+ ClientUtils.CurrentUserEmail() !== 'guest' && DocServer.Emit(_socket, MessageStore.CreateDocField, initialState);
}
// NOTIFY THE SERVER OF AN UPDATE TO A DOC'S STATE
@@ -462,7 +462,7 @@ export namespace DocServer {
_GetCachedRefField = _GetCachedRefFieldImpl;
SetObjGetRefField((_GetRefField = _GetRefFieldImpl));
SetObjGetRefFields((_GetRefFields = _GetRefFieldsImpl));
- _CreateField = _CreateFieldImpl;
+ _CreateDocField = _CreateDocFieldImpl;
_UpdateField = _UpdateFieldImpl;
/**
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index ad7609895..2ae9dbf02 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -329,7 +329,7 @@ export class Doc extends RefField {
});
this[SelfProxy] = docProxy;
if (!id || forceSave) {
- DocServer.CreateField(docProxy);
+ DocServer.CreateDocField(docProxy);
}
// eslint-disable-next-line no-constructor-return
return docProxy; // need to return the proxy from the constructor so that all our added fields will get called
diff --git a/src/server/Message.ts b/src/server/Message.ts
index 4599708c9..b904a5ba3 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -56,7 +56,7 @@ export namespace MessageStore {
export const GetRefField = new Message<string>('Get Ref Field');
export const GetRefFields = new Message<string[]>('Get Ref Fields');
export const UpdateField = new Message<Diff>('Update Ref Field');
- export const CreateField = new Message<Reference>('Create Ref Field');
+ export const CreateDocField = new Message<Reference>('Create Ref Field');
export const DeleteField = new Message<string>('Delete field');
export const DeleteFields = new Message<string[]>('Delete fields');
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index f10455680..f588151a5 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -240,7 +240,7 @@ export namespace WebSocket {
// if the client and server have different versions of the data after
// deletion, they will have different lengths and the server will
// send its version of the data to the client
- const sendBack = diff.diff.length !== remListItems.length;
+ const sendBack = diff.diff.length !== diff.diff.$set[updatefield].fields.length;
delete diff.diff.length;
Database.Instance.update(
diff.id,
@@ -306,6 +306,10 @@ export namespace WebSocket {
});
}
+ function CreateDocField(newValue: serializedDoctype) {
+ Database.Instance.insert(newValue);
+ }
+
export async function initialize(isRelease: boolean, credentials: SecureContextOptions) {
let io: Server;
if (isRelease) {
@@ -367,6 +371,7 @@ export namespace WebSocket {
ServerUtils.AddServerHandler(socket, MessageStore.DeleteAll, () => doDelete(false));
}
+ ServerUtils.AddServerHandler(socket, MessageStore.CreateDocField, CreateDocField);
ServerUtils.AddServerHandler(socket, MessageStore.UpdateField, diff => UpdateField(socket, diff));
ServerUtils.AddServerHandler(socket, MessageStore.DeleteField, id => DeleteField(socket, id));
ServerUtils.AddServerHandler(socket, MessageStore.DeleteFields, ids => DeleteFields(socket, ids));