igalshilman commented on a change in pull request #269:
URL: https://github.com/apache/flink-statefun/pull/269#discussion_r710008050



##########
File path: statefun-sdk-js/src/storage.ts
##########
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+'use strict';
+
+import "./generated/request-reply_pb";
+import {TypedValueSupport} from "./types";
+import {Type, ValueSpec} from "./core";
+
+const M = 
global.proto.io.statefun.sdk.reqreply.FromFunction.PersistedValueMutation;
+
+const DEL = 
global.proto.io.statefun.sdk.reqreply.FromFunction.PersistedValueMutation.MutationType['DELETE'];
+
+// noinspection JSUnresolvedVariable
+const MOD = 
global.proto.io.statefun.sdk.reqreply.FromFunction.PersistedValueMutation.MutationType['MODIFY'];
+
+// noinspection JSValidateJSDoc
+class Value {
+    readonly #name;
+    readonly #type;
+    #box;
+    #mutated;
+    #deleted;
+
+    /**
+     *
+     * @param {string} name
+     * @param {Type} type
+     * @param {proto.io.statefun.sdk.reqreply.TypedValue} box
+     */
+    constructor(name: string, type: Type<any>, box: any) {
+        this.#name = name;
+        this.#type = type;
+        this.#box = box;
+        this.#mutated = false;
+        this.#deleted = false;
+    }
+
+    getValue<T>(): T | null {
+        if (this.#deleted) {
+            return null;
+        }
+        return TypedValueSupport.parseTypedValue(this.#box, this.#type);
+    }
+
+    setValue(jsObject: any) {
+        if (jsObject === undefined || jsObject === null) {
+            this.#mutated = true;
+            this.#deleted = true;
+            this.#box = null;
+        } else {
+            this.#mutated = true;
+            this.#deleted = false;
+            this.#box = TypedValueSupport.toTypedValue(jsObject, this.#type);
+        }
+    }
+
+    get name() {
+        return this.#name;
+    }
+
+    // internal helpers
+
+    asMutation(): any {

Review comment:
       Unfortunately everywhere that we are interacting with a Protobuf 
generated class, a specific type wouldn't work, as the types are being added to 
the global scope at runtime.
   Luckily tho,  none of these points are a part of the SDK surface, so this 
will give us the freedom to improve this over time.
   I think that a proper solution would be to find a Protobuf compiler that 
knows how to generate a TypeScript classes, or alternatively hide Protobuf 
behind a vanilla shim. 
   Anyways I wouldn't want to deal with that right now.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to