@protoc-gen-go-wasmjs/runtime 0.0.14

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.
@@ -0,0 +1,223 @@
1
+ // src/schema/types.ts
2
+ var FieldType = /* @__PURE__ */ ((FieldType2) => {
3
+ FieldType2["STRING"] = "string";
4
+ FieldType2["NUMBER"] = "number";
5
+ FieldType2["BOOLEAN"] = "boolean";
6
+ FieldType2["MESSAGE"] = "message";
7
+ FieldType2["REPEATED"] = "repeated";
8
+ FieldType2["MAP"] = "map";
9
+ FieldType2["ONEOF"] = "oneof";
10
+ return FieldType2;
11
+ })(FieldType || {});
12
+
13
+ // src/schema/base-deserializer.ts
14
+ var BaseDeserializer = class {
15
+ constructor(schemaRegistry, factory) {
16
+ this.schemaRegistry = schemaRegistry;
17
+ this.factory = factory;
18
+ }
19
+ /**
20
+ * Deserialize an object using schema information
21
+ * @param instance The target instance to populate
22
+ * @param data The source data to deserialize from
23
+ * @param messageType The fully qualified message type (e.g., "library.v1.Book")
24
+ * @returns The populated instance
25
+ */
26
+ deserialize(instance, data, messageType) {
27
+ if (!data || typeof data !== "object") {
28
+ return instance;
29
+ }
30
+ const schema = this.schemaRegistry[messageType];
31
+ if (!schema) {
32
+ return this.fallbackDeserialize(instance, data);
33
+ }
34
+ for (const fieldSchema of schema.fields) {
35
+ const fieldValue = data[fieldSchema.name];
36
+ if (fieldValue === null || fieldValue === void 0) {
37
+ continue;
38
+ }
39
+ this.deserializeField(instance, fieldSchema, fieldValue);
40
+ }
41
+ return instance;
42
+ }
43
+ /**
44
+ * Deserialize a single field based on its schema
45
+ */
46
+ deserializeField(instance, fieldSchema, fieldValue) {
47
+ const fieldName = fieldSchema.name;
48
+ switch (fieldSchema.type) {
49
+ case "string" /* STRING */:
50
+ case "number" /* NUMBER */:
51
+ case "boolean" /* BOOLEAN */:
52
+ instance[fieldName] = fieldValue;
53
+ break;
54
+ case "message" /* MESSAGE */:
55
+ if (fieldSchema.repeated) {
56
+ instance[fieldName] = this.deserializeMessageArray(
57
+ fieldValue,
58
+ fieldSchema.messageType,
59
+ instance,
60
+ fieldName
61
+ );
62
+ } else {
63
+ instance[fieldName] = this.deserializeMessageField(
64
+ fieldValue,
65
+ fieldSchema.messageType,
66
+ instance,
67
+ fieldName
68
+ );
69
+ }
70
+ break;
71
+ case "repeated" /* REPEATED */:
72
+ if (Array.isArray(fieldValue)) {
73
+ instance[fieldName] = [...fieldValue];
74
+ }
75
+ break;
76
+ case "oneof" /* ONEOF */:
77
+ instance[fieldName] = fieldValue;
78
+ break;
79
+ case "map" /* MAP */:
80
+ instance[fieldName] = { ...fieldValue };
81
+ break;
82
+ default:
83
+ instance[fieldName] = fieldValue;
84
+ break;
85
+ }
86
+ }
87
+ /**
88
+ * Deserialize a single message field
89
+ */
90
+ deserializeMessageField(fieldValue, messageType, parent, attributeName) {
91
+ let factoryMethod;
92
+ if (this.factory.getFactoryMethod) {
93
+ factoryMethod = this.factory.getFactoryMethod(messageType);
94
+ } else {
95
+ const factoryMethodName = this.getFactoryMethodName(messageType);
96
+ factoryMethod = this.factory[factoryMethodName];
97
+ }
98
+ if (factoryMethod) {
99
+ const result = factoryMethod(parent, attributeName, void 0, fieldValue);
100
+ if (result.fullyLoaded) {
101
+ return result.instance;
102
+ } else {
103
+ return this.deserialize(result.instance, fieldValue, messageType);
104
+ }
105
+ }
106
+ return this.fallbackDeserialize({}, fieldValue);
107
+ }
108
+ /**
109
+ * Deserialize an array of message objects
110
+ */
111
+ deserializeMessageArray(fieldValue, messageType, parent, attributeName) {
112
+ if (!Array.isArray(fieldValue)) {
113
+ return [];
114
+ }
115
+ let factoryMethod;
116
+ if (this.factory.getFactoryMethod) {
117
+ factoryMethod = this.factory.getFactoryMethod(messageType);
118
+ } else {
119
+ const factoryMethodName = this.getFactoryMethodName(messageType);
120
+ factoryMethod = this.factory[factoryMethodName];
121
+ }
122
+ return fieldValue.map((item, index) => {
123
+ if (factoryMethod) {
124
+ const result = factoryMethod(parent, attributeName, index, item);
125
+ if (result.fullyLoaded) {
126
+ return result.instance;
127
+ } else {
128
+ return this.deserialize(result.instance, item, messageType);
129
+ }
130
+ }
131
+ return this.fallbackDeserialize({}, item);
132
+ });
133
+ }
134
+ /**
135
+ * Convert message type to factory method name
136
+ * "library.v1.Book" -> "newBook"
137
+ */
138
+ getFactoryMethodName(messageType) {
139
+ const parts = messageType.split(".");
140
+ const typeName = parts[parts.length - 1];
141
+ return "new" + typeName;
142
+ }
143
+ /**
144
+ * Fallback deserializer for when no schema is available
145
+ */
146
+ fallbackDeserialize(instance, data) {
147
+ if (!data || typeof data !== "object") {
148
+ return instance;
149
+ }
150
+ for (const [key, value] of Object.entries(data)) {
151
+ if (value !== null && value !== void 0) {
152
+ instance[key] = value;
153
+ }
154
+ }
155
+ return instance;
156
+ }
157
+ /**
158
+ * Create and deserialize a new instance of a message type
159
+ */
160
+ createAndDeserialize(messageType, data) {
161
+ let factoryMethod;
162
+ if (this.factory.getFactoryMethod) {
163
+ factoryMethod = this.factory.getFactoryMethod(messageType);
164
+ } else {
165
+ const factoryMethodName = this.getFactoryMethodName(messageType);
166
+ factoryMethod = this.factory[factoryMethodName];
167
+ }
168
+ if (!factoryMethod) {
169
+ throw new Error(`Could not find factory method to deserialize: ${messageType}`);
170
+ }
171
+ const result = factoryMethod(void 0, void 0, void 0, data);
172
+ if (result.fullyLoaded) {
173
+ return result.instance;
174
+ } else {
175
+ return this.deserialize(result.instance, data, messageType);
176
+ }
177
+ }
178
+ };
179
+
180
+ // src/schema/base-registry.ts
181
+ var BaseSchemaRegistry = class {
182
+ constructor(schemaRegistry) {
183
+ this.schemaRegistry = schemaRegistry;
184
+ }
185
+ /**
186
+ * Get schema for a message type
187
+ */
188
+ getSchema(messageType) {
189
+ return this.schemaRegistry[messageType];
190
+ }
191
+ /**
192
+ * Get field schema by name
193
+ */
194
+ getFieldSchema(messageType, fieldName) {
195
+ const schema = this.getSchema(messageType);
196
+ return schema?.fields.find((field) => field.name === fieldName);
197
+ }
198
+ /**
199
+ * Get field schema by proto field ID
200
+ */
201
+ getFieldSchemaById(messageType, fieldId) {
202
+ const schema = this.getSchema(messageType);
203
+ return schema?.fields.find((field) => field.id === fieldId);
204
+ }
205
+ /**
206
+ * Check if field is part of a oneof group
207
+ */
208
+ isOneofField(messageType, fieldName) {
209
+ const fieldSchema = this.getFieldSchema(messageType, fieldName);
210
+ return fieldSchema?.oneofGroup !== void 0;
211
+ }
212
+ /**
213
+ * Get all fields in a oneof group
214
+ */
215
+ getOneofFields(messageType, oneofGroup) {
216
+ const schema = this.getSchema(messageType);
217
+ return schema?.fields.filter((field) => field.oneofGroup === oneofGroup) || [];
218
+ }
219
+ };
220
+
221
+ export { BaseDeserializer, BaseSchemaRegistry, FieldType };
222
+ //# sourceMappingURL=index.mjs.map
223
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/schema/types.ts","../../src/schema/base-deserializer.ts","../../src/schema/base-registry.ts"],"names":["FieldType"],"mappings":";AAiBO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AACL,EAAAA,WAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,WAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,WAAA,UAAA,CAAA,GAAW,UAAA;AACX,EAAAA,WAAA,KAAA,CAAA,GAAM,KAAA;AACN,EAAAA,WAAA,OAAA,CAAA,GAAQ,OAAA;AAPE,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;;;ACGL,IAAe,mBAAf,MAAgC;AAAA,EAC3B,WAAA,CACE,gBACA,OAAA,EACV;AAFU,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAAA,EACT;AAAA;AAAA;AAAA;AA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AK,SAAA,CAAU,WAAW,CAAA;AACzC,IAAA,OAAO,MAAA,EAAQ,OAAO,MAAA,CAAO,CAAA,KAAA,KAAS,MAAM,UAAA,KAAe,UAAU,KAAK,EAAC;AAAA,EAC7E;AACF","file":"index.mjs","sourcesContent":["// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Field type enumeration for proto field types\n */\nexport enum FieldType {\n STRING = \"string\",\n NUMBER = \"number\", \n BOOLEAN = \"boolean\",\n MESSAGE = \"message\",\n REPEATED = \"repeated\",\n MAP = \"map\",\n ONEOF = \"oneof\"\n}\n\n/**\n * Schema interface for field definitions\n */\nexport interface FieldSchema {\n name: string;\n type: FieldType;\n id: number; // Proto field number (e.g., text_query = 1)\n messageType?: string; // For MESSAGE type fields\n repeated?: boolean; // For array fields\n mapKeyType?: FieldType; // For MAP type fields\n mapValueType?: FieldType | string; // For MAP type fields\n oneofGroup?: string; // For ONEOF fields\n optional?: boolean;\n}\n\n/**\n * Message schema interface\n */\nexport interface MessageSchema {\n name: string;\n fields: FieldSchema[];\n oneofGroups?: string[]; // List of oneof group names\n}\n","// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FieldType, FieldSchema, MessageSchema } from './types.js';\nimport { FactoryInterface, FactoryResult } from '../types/factory.js';\n\n/**\n * Base deserializer class containing all non-template-dependent logic\n */\nexport abstract class BaseDeserializer {\n protected constructor(\n protected schemaRegistry: Record<string, MessageSchema>,\n protected factory: FactoryInterface\n ) {}\n\n /**\n * Deserialize an object using schema information\n * @param instance The target instance to populate\n * @param data The source data to deserialize from\n * @param messageType The fully qualified message type (e.g., \"library.v1.Book\")\n * @returns The populated instance\n */\n deserialize<T>(instance: T, data: any, messageType: string): T {\n if (!data || typeof data !== 'object') {\n return instance;\n }\n\n const schema = this.schemaRegistry[messageType];\n if (!schema) {\n // Fallback to simple property copying if no schema found\n return this.fallbackDeserialize(instance, data);\n }\n\n // Process each field according to its schema\n for (const fieldSchema of schema.fields) {\n const fieldValue = data[fieldSchema.name];\n if (fieldValue === null || fieldValue === undefined) {\n continue;\n }\n\n this.deserializeField(instance, fieldSchema, fieldValue);\n }\n\n return instance;\n }\n\n /**\n * Deserialize a single field based on its schema\n */\n protected deserializeField(instance: any, fieldSchema: FieldSchema, fieldValue: any): void {\n const fieldName = fieldSchema.name;\n\n switch (fieldSchema.type) {\n case FieldType.STRING:\n case FieldType.NUMBER:\n case FieldType.BOOLEAN:\n // Simple primitive types - direct assignment\n instance[fieldName] = fieldValue;\n break;\n\n case FieldType.MESSAGE:\n if (fieldSchema.repeated) {\n // Handle repeated message fields (arrays)\n instance[fieldName] = this.deserializeMessageArray(\n fieldValue,\n fieldSchema.messageType!,\n instance,\n fieldName\n );\n } else {\n // Handle single message field\n instance[fieldName] = this.deserializeMessageField(\n fieldValue,\n fieldSchema.messageType!,\n instance,\n fieldName\n );\n }\n break;\n\n case FieldType.REPEATED:\n // Handle repeated primitive fields\n if (Array.isArray(fieldValue)) {\n instance[fieldName] = [...fieldValue]; // Simple copy for primitives\n }\n break;\n\n case FieldType.ONEOF:\n // Handle oneof fields (would need additional logic for union types)\n instance[fieldName] = fieldValue;\n break;\n\n case FieldType.MAP:\n // Handle map fields (would need additional schema info for key/value types)\n instance[fieldName] = { ...fieldValue };\n break;\n\n default:\n // Fallback to direct assignment\n instance[fieldName] = fieldValue;\n break;\n }\n }\n\n /**\n * Deserialize a single message field\n */\n protected deserializeMessageField(\n fieldValue: any,\n messageType: string,\n parent: any,\n attributeName: string\n ): any {\n // Try to get factory method using cross-package delegation\n let factoryMethod;\n \n if (this.factory.getFactoryMethod) {\n factoryMethod = this.factory.getFactoryMethod(messageType);\n } else {\n // Fallback to simple method name lookup\n const factoryMethodName = this.getFactoryMethodName(messageType);\n factoryMethod = (this.factory as any)[factoryMethodName];\n }\n\n if (factoryMethod) {\n const result = factoryMethod(parent, attributeName, undefined, fieldValue);\n if (result.fullyLoaded) {\n return result.instance;\n } else {\n // Factory created instance but didn't populate - use deserializer\n return this.deserialize(result.instance, fieldValue, messageType);\n }\n }\n\n // No factory method found - fallback\n return this.fallbackDeserialize({}, fieldValue);\n }\n\n /**\n * Deserialize an array of message objects\n */\n protected deserializeMessageArray(\n fieldValue: any[],\n messageType: string,\n parent: any,\n attributeName: string\n ): any[] {\n if (!Array.isArray(fieldValue)) {\n return [];\n }\n\n // Try to get factory method using cross-package delegation\n let factoryMethod;\n \n if (this.factory.getFactoryMethod) {\n factoryMethod = this.factory.getFactoryMethod(messageType);\n } else {\n // Fallback to simple method name lookup\n const factoryMethodName = this.getFactoryMethodName(messageType);\n factoryMethod = (this.factory as any)[factoryMethodName];\n }\n\n return fieldValue.map((item, index) => {\n if (factoryMethod) {\n const result = factoryMethod(parent, attributeName, index, item);\n if (result.fullyLoaded) {\n return result.instance;\n } else {\n // Factory created instance but didn't populate - use deserializer\n return this.deserialize(result.instance, item, messageType);\n }\n }\n\n // No factory method found - fallback\n return this.fallbackDeserialize({}, item);\n });\n }\n\n /**\n * Convert message type to factory method name\n * \"library.v1.Book\" -> \"newBook\"\n */\n protected getFactoryMethodName(messageType: string): string {\n const parts = messageType.split('.');\n const typeName = parts[parts.length - 1]; // Get last part (e.g., \"Book\")\n return 'new' + typeName;\n }\n\n /**\n * Fallback deserializer for when no schema is available\n */\n protected fallbackDeserialize<T>(instance: T, data: any): T {\n if (!data || typeof data !== 'object') {\n return instance;\n }\n\n for (const [key, value] of Object.entries(data)) {\n if (value !== null && value !== undefined) {\n (instance as any)[key] = value;\n }\n }\n\n return instance;\n }\n\n /**\n * Create and deserialize a new instance of a message type\n */\n createAndDeserialize<T>(messageType: string, data: any): T {\n // Try to get factory method using cross-package delegation\n let factoryMethod;\n \n if (this.factory.getFactoryMethod) {\n factoryMethod = this.factory.getFactoryMethod(messageType);\n } else {\n // Fallback to simple method name lookup\n const factoryMethodName = this.getFactoryMethodName(messageType);\n factoryMethod = (this.factory as any)[factoryMethodName];\n }\n\n if (!factoryMethod) {\n throw new Error(`Could not find factory method to deserialize: ${messageType}`)\n }\n\n const result = factoryMethod(undefined, undefined, undefined, data);\n if (result.fullyLoaded) {\n return result.instance;\n } else {\n return this.deserialize(result.instance, data, messageType);\n }\n }\n}\n","// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FieldSchema, MessageSchema } from './types.js';\n\n/**\n * Base schema registry with utility methods for schema operations\n */\nexport class BaseSchemaRegistry {\n constructor(protected schemaRegistry: Record<string, MessageSchema>) {}\n\n /**\n * Get schema for a message type\n */\n getSchema(messageType: string): MessageSchema | undefined {\n return this.schemaRegistry[messageType];\n }\n\n /**\n * Get field schema by name\n */\n getFieldSchema(messageType: string, fieldName: string): FieldSchema | undefined {\n const schema = this.getSchema(messageType);\n return schema?.fields.find(field => field.name === fieldName);\n }\n\n /**\n * Get field schema by proto field ID\n */\n getFieldSchemaById(messageType: string, fieldId: number): FieldSchema | undefined {\n const schema = this.getSchema(messageType);\n return schema?.fields.find(field => field.id === fieldId);\n }\n\n /**\n * Check if field is part of a oneof group\n */\n isOneofField(messageType: string, fieldName: string): boolean {\n const fieldSchema = this.getFieldSchema(messageType, fieldName);\n return fieldSchema?.oneofGroup !== undefined;\n }\n\n /**\n * Get all fields in a oneof group\n */\n getOneofFields(messageType: string, oneofGroup: string): FieldSchema[] {\n const schema = this.getSchema(messageType);\n return schema?.fields.filter(field => field.oneofGroup === oneofGroup) || [];\n }\n}\n"]}
@@ -0,0 +1,90 @@
1
+ export { b as FactoryInterface, a as FactoryMethod, F as FactoryResult } from '../factory-DqksufjU.mjs';
2
+
3
+ /**
4
+ * Patch operations for modifying protobuf message fields
5
+ */
6
+ declare enum PatchOperation {
7
+ SET = "SET",
8
+ INSERT_LIST = "INSERT_LIST",
9
+ REMOVE_LIST = "REMOVE_LIST",
10
+ MOVE_LIST = "MOVE_LIST",
11
+ INSERT_MAP = "INSERT_MAP",
12
+ REMOVE_MAP = "REMOVE_MAP",
13
+ CLEAR_LIST = "CLEAR_LIST",
14
+ CLEAR_MAP = "CLEAR_MAP"
15
+ }
16
+ /**
17
+ * A single patch operation on a protobuf message field
18
+ */
19
+ interface MessagePatch {
20
+ /** The type of operation to perform */
21
+ operation: PatchOperation;
22
+ /** Path to the field being modified (e.g., "players[2].name", "places['tile_123'].latitude") */
23
+ fieldPath: string;
24
+ /** The new value to set (for SET, INSERT_LIST, INSERT_MAP operations) */
25
+ value?: any;
26
+ /** Index for list operations (INSERT_LIST, REMOVE_LIST, MOVE_LIST) */
27
+ index?: number;
28
+ /** Map key for map operations (INSERT_MAP, REMOVE_MAP) */
29
+ key?: string;
30
+ /** Source index for MOVE_LIST operations */
31
+ oldIndex?: number;
32
+ /** Monotonically increasing change number for ordering */
33
+ changeNumber: number;
34
+ /** Timestamp when the change was created (microseconds since epoch) */
35
+ timestamp: number;
36
+ /** Optional user ID who made the change (for conflict resolution) */
37
+ userId?: string;
38
+ /** Optional transaction ID to group related patches */
39
+ transactionId?: string;
40
+ }
41
+ /**
42
+ * A batch of patches applied to a single entity
43
+ */
44
+ interface PatchBatch {
45
+ /** The fully qualified protobuf message type (e.g., "example.Game") */
46
+ messageType: string;
47
+ /** The unique identifier of the entity being modified */
48
+ entityId: string;
49
+ /** List of patches to apply in order */
50
+ patches: MessagePatch[];
51
+ /** The highest change number in this batch */
52
+ changeNumber: number;
53
+ /** Source of the changes */
54
+ source: PatchSource;
55
+ /** Optional metadata about the batch */
56
+ metadata?: Record<string, string>;
57
+ }
58
+ /**
59
+ * Source of patch changes
60
+ */
61
+ declare enum PatchSource {
62
+ LOCAL = "LOCAL",
63
+ REMOTE = "REMOTE",
64
+ SERVER = "SERVER",
65
+ STORAGE = "STORAGE"
66
+ }
67
+ /**
68
+ * Response message for methods that return patches
69
+ */
70
+ interface PatchResponse {
71
+ /** The patches to apply */
72
+ patchBatches: PatchBatch[];
73
+ /** Success status */
74
+ success: boolean;
75
+ /** Error message if success is false */
76
+ errorMessage?: string;
77
+ /** The new change number after applying these patches */
78
+ newChangeNumber: number;
79
+ }
80
+ /**
81
+ * Transport interface for receiving patch updates
82
+ */
83
+ interface ChangeTransport {
84
+ /** Register callback for incoming changes */
85
+ onChanges(callback: (batches: PatchBatch[]) => void): void;
86
+ /** Disconnect from the transport */
87
+ disconnect(): void;
88
+ }
89
+
90
+ export { type ChangeTransport, type MessagePatch, type PatchBatch, PatchOperation, type PatchResponse, PatchSource };
@@ -0,0 +1,90 @@
1
+ export { b as FactoryInterface, a as FactoryMethod, F as FactoryResult } from '../factory-DqksufjU.js';
2
+
3
+ /**
4
+ * Patch operations for modifying protobuf message fields
5
+ */
6
+ declare enum PatchOperation {
7
+ SET = "SET",
8
+ INSERT_LIST = "INSERT_LIST",
9
+ REMOVE_LIST = "REMOVE_LIST",
10
+ MOVE_LIST = "MOVE_LIST",
11
+ INSERT_MAP = "INSERT_MAP",
12
+ REMOVE_MAP = "REMOVE_MAP",
13
+ CLEAR_LIST = "CLEAR_LIST",
14
+ CLEAR_MAP = "CLEAR_MAP"
15
+ }
16
+ /**
17
+ * A single patch operation on a protobuf message field
18
+ */
19
+ interface MessagePatch {
20
+ /** The type of operation to perform */
21
+ operation: PatchOperation;
22
+ /** Path to the field being modified (e.g., "players[2].name", "places['tile_123'].latitude") */
23
+ fieldPath: string;
24
+ /** The new value to set (for SET, INSERT_LIST, INSERT_MAP operations) */
25
+ value?: any;
26
+ /** Index for list operations (INSERT_LIST, REMOVE_LIST, MOVE_LIST) */
27
+ index?: number;
28
+ /** Map key for map operations (INSERT_MAP, REMOVE_MAP) */
29
+ key?: string;
30
+ /** Source index for MOVE_LIST operations */
31
+ oldIndex?: number;
32
+ /** Monotonically increasing change number for ordering */
33
+ changeNumber: number;
34
+ /** Timestamp when the change was created (microseconds since epoch) */
35
+ timestamp: number;
36
+ /** Optional user ID who made the change (for conflict resolution) */
37
+ userId?: string;
38
+ /** Optional transaction ID to group related patches */
39
+ transactionId?: string;
40
+ }
41
+ /**
42
+ * A batch of patches applied to a single entity
43
+ */
44
+ interface PatchBatch {
45
+ /** The fully qualified protobuf message type (e.g., "example.Game") */
46
+ messageType: string;
47
+ /** The unique identifier of the entity being modified */
48
+ entityId: string;
49
+ /** List of patches to apply in order */
50
+ patches: MessagePatch[];
51
+ /** The highest change number in this batch */
52
+ changeNumber: number;
53
+ /** Source of the changes */
54
+ source: PatchSource;
55
+ /** Optional metadata about the batch */
56
+ metadata?: Record<string, string>;
57
+ }
58
+ /**
59
+ * Source of patch changes
60
+ */
61
+ declare enum PatchSource {
62
+ LOCAL = "LOCAL",
63
+ REMOTE = "REMOTE",
64
+ SERVER = "SERVER",
65
+ STORAGE = "STORAGE"
66
+ }
67
+ /**
68
+ * Response message for methods that return patches
69
+ */
70
+ interface PatchResponse {
71
+ /** The patches to apply */
72
+ patchBatches: PatchBatch[];
73
+ /** Success status */
74
+ success: boolean;
75
+ /** Error message if success is false */
76
+ errorMessage?: string;
77
+ /** The new change number after applying these patches */
78
+ newChangeNumber: number;
79
+ }
80
+ /**
81
+ * Transport interface for receiving patch updates
82
+ */
83
+ interface ChangeTransport {
84
+ /** Register callback for incoming changes */
85
+ onChanges(callback: (batches: PatchBatch[]) => void): void;
86
+ /** Disconnect from the transport */
87
+ disconnect(): void;
88
+ }
89
+
90
+ export { type ChangeTransport, type MessagePatch, type PatchBatch, PatchOperation, type PatchResponse, PatchSource };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ // src/types/patches.ts
4
+ var PatchOperation = /* @__PURE__ */ ((PatchOperation2) => {
5
+ PatchOperation2["SET"] = "SET";
6
+ PatchOperation2["INSERT_LIST"] = "INSERT_LIST";
7
+ PatchOperation2["REMOVE_LIST"] = "REMOVE_LIST";
8
+ PatchOperation2["MOVE_LIST"] = "MOVE_LIST";
9
+ PatchOperation2["INSERT_MAP"] = "INSERT_MAP";
10
+ PatchOperation2["REMOVE_MAP"] = "REMOVE_MAP";
11
+ PatchOperation2["CLEAR_LIST"] = "CLEAR_LIST";
12
+ PatchOperation2["CLEAR_MAP"] = "CLEAR_MAP";
13
+ return PatchOperation2;
14
+ })(PatchOperation || {});
15
+ var PatchSource = /* @__PURE__ */ ((PatchSource2) => {
16
+ PatchSource2["LOCAL"] = "LOCAL";
17
+ PatchSource2["REMOTE"] = "REMOTE";
18
+ PatchSource2["SERVER"] = "SERVER";
19
+ PatchSource2["STORAGE"] = "STORAGE";
20
+ return PatchSource2;
21
+ })(PatchSource || {});
22
+
23
+ exports.PatchOperation = PatchOperation;
24
+ exports.PatchSource = PatchSource;
25
+ //# sourceMappingURL=index.js.map
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/patches.ts"],"names":["PatchOperation","PatchSource"],"mappings":";;;AAiBO,IAAK,cAAA,qBAAAA,eAAAA,KAAL;AACL,EAAAA,gBAAA,KAAA,CAAA,GAAM,KAAA;AACN,EAAAA,gBAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,gBAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,gBAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,gBAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,gBAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AARF,EAAA,OAAAA,eAAAA;AAAA,CAAA,EAAA,cAAA,IAAA,EAAA;AAwEL,IAAK,WAAA,qBAAAC,YAAAA,KAAL;AACL,EAAAA,aAAA,OAAA,CAAA,GAAQ,OAAA;AACR,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,SAAA,CAAA,GAAU,SAAA;AAJA,EAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA","file":"index.js","sourcesContent":["// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Patch operations for modifying protobuf message fields\n */\nexport enum PatchOperation {\n SET = 'SET',\n INSERT_LIST = 'INSERT_LIST',\n REMOVE_LIST = 'REMOVE_LIST',\n MOVE_LIST = 'MOVE_LIST',\n INSERT_MAP = 'INSERT_MAP',\n REMOVE_MAP = 'REMOVE_MAP',\n CLEAR_LIST = 'CLEAR_LIST',\n CLEAR_MAP = 'CLEAR_MAP',\n}\n\n/**\n * A single patch operation on a protobuf message field\n */\nexport interface MessagePatch {\n /** The type of operation to perform */\n operation: PatchOperation;\n \n /** Path to the field being modified (e.g., \"players[2].name\", \"places['tile_123'].latitude\") */\n fieldPath: string;\n \n /** The new value to set (for SET, INSERT_LIST, INSERT_MAP operations) */\n value?: any;\n \n /** Index for list operations (INSERT_LIST, REMOVE_LIST, MOVE_LIST) */\n index?: number;\n \n /** Map key for map operations (INSERT_MAP, REMOVE_MAP) */\n key?: string;\n \n /** Source index for MOVE_LIST operations */\n oldIndex?: number;\n \n /** Monotonically increasing change number for ordering */\n changeNumber: number;\n \n /** Timestamp when the change was created (microseconds since epoch) */\n timestamp: number;\n \n /** Optional user ID who made the change (for conflict resolution) */\n userId?: string;\n \n /** Optional transaction ID to group related patches */\n transactionId?: string;\n}\n\n/**\n * A batch of patches applied to a single entity\n */\nexport interface PatchBatch {\n /** The fully qualified protobuf message type (e.g., \"example.Game\") */\n messageType: string;\n \n /** The unique identifier of the entity being modified */\n entityId: string;\n \n /** List of patches to apply in order */\n patches: MessagePatch[];\n \n /** The highest change number in this batch */\n changeNumber: number;\n \n /** Source of the changes */\n source: PatchSource;\n \n /** Optional metadata about the batch */\n metadata?: Record<string, string>;\n}\n\n/**\n * Source of patch changes\n */\nexport enum PatchSource {\n LOCAL = 'LOCAL',\n REMOTE = 'REMOTE', \n SERVER = 'SERVER',\n STORAGE = 'STORAGE',\n}\n\n/**\n * Response message for methods that return patches\n */\nexport interface PatchResponse {\n /** The patches to apply */\n patchBatches: PatchBatch[];\n \n /** Success status */\n success: boolean;\n \n /** Error message if success is false */\n errorMessage?: string;\n \n /** The new change number after applying these patches */\n newChangeNumber: number;\n}\n\n/**\n * Transport interface for receiving patch updates\n */\nexport interface ChangeTransport {\n /** Register callback for incoming changes */\n onChanges(callback: (batches: PatchBatch[]) => void): void;\n \n /** Disconnect from the transport */\n disconnect(): void;\n}\n"]}
@@ -0,0 +1,23 @@
1
+ // src/types/patches.ts
2
+ var PatchOperation = /* @__PURE__ */ ((PatchOperation2) => {
3
+ PatchOperation2["SET"] = "SET";
4
+ PatchOperation2["INSERT_LIST"] = "INSERT_LIST";
5
+ PatchOperation2["REMOVE_LIST"] = "REMOVE_LIST";
6
+ PatchOperation2["MOVE_LIST"] = "MOVE_LIST";
7
+ PatchOperation2["INSERT_MAP"] = "INSERT_MAP";
8
+ PatchOperation2["REMOVE_MAP"] = "REMOVE_MAP";
9
+ PatchOperation2["CLEAR_LIST"] = "CLEAR_LIST";
10
+ PatchOperation2["CLEAR_MAP"] = "CLEAR_MAP";
11
+ return PatchOperation2;
12
+ })(PatchOperation || {});
13
+ var PatchSource = /* @__PURE__ */ ((PatchSource2) => {
14
+ PatchSource2["LOCAL"] = "LOCAL";
15
+ PatchSource2["REMOTE"] = "REMOTE";
16
+ PatchSource2["SERVER"] = "SERVER";
17
+ PatchSource2["STORAGE"] = "STORAGE";
18
+ return PatchSource2;
19
+ })(PatchSource || {});
20
+
21
+ export { PatchOperation, PatchSource };
22
+ //# sourceMappingURL=index.mjs.map
23
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/patches.ts"],"names":["PatchOperation","PatchSource"],"mappings":";AAiBO,IAAK,cAAA,qBAAAA,eAAAA,KAAL;AACL,EAAAA,gBAAA,KAAA,CAAA,GAAM,KAAA;AACN,EAAAA,gBAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,gBAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AACZ,EAAAA,gBAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,gBAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,gBAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,gBAAA,WAAA,CAAA,GAAY,WAAA;AARF,EAAA,OAAAA,eAAAA;AAAA,CAAA,EAAA,cAAA,IAAA,EAAA;AAwEL,IAAK,WAAA,qBAAAC,YAAAA,KAAL;AACL,EAAAA,aAAA,OAAA,CAAA,GAAQ,OAAA;AACR,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,SAAA,CAAA,GAAU,SAAA;AAJA,EAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA","file":"index.mjs","sourcesContent":["// Copyright 2025 Sri Panyam\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Patch operations for modifying protobuf message fields\n */\nexport enum PatchOperation {\n SET = 'SET',\n INSERT_LIST = 'INSERT_LIST',\n REMOVE_LIST = 'REMOVE_LIST',\n MOVE_LIST = 'MOVE_LIST',\n INSERT_MAP = 'INSERT_MAP',\n REMOVE_MAP = 'REMOVE_MAP',\n CLEAR_LIST = 'CLEAR_LIST',\n CLEAR_MAP = 'CLEAR_MAP',\n}\n\n/**\n * A single patch operation on a protobuf message field\n */\nexport interface MessagePatch {\n /** The type of operation to perform */\n operation: PatchOperation;\n \n /** Path to the field being modified (e.g., \"players[2].name\", \"places['tile_123'].latitude\") */\n fieldPath: string;\n \n /** The new value to set (for SET, INSERT_LIST, INSERT_MAP operations) */\n value?: any;\n \n /** Index for list operations (INSERT_LIST, REMOVE_LIST, MOVE_LIST) */\n index?: number;\n \n /** Map key for map operations (INSERT_MAP, REMOVE_MAP) */\n key?: string;\n \n /** Source index for MOVE_LIST operations */\n oldIndex?: number;\n \n /** Monotonically increasing change number for ordering */\n changeNumber: number;\n \n /** Timestamp when the change was created (microseconds since epoch) */\n timestamp: number;\n \n /** Optional user ID who made the change (for conflict resolution) */\n userId?: string;\n \n /** Optional transaction ID to group related patches */\n transactionId?: string;\n}\n\n/**\n * A batch of patches applied to a single entity\n */\nexport interface PatchBatch {\n /** The fully qualified protobuf message type (e.g., \"example.Game\") */\n messageType: string;\n \n /** The unique identifier of the entity being modified */\n entityId: string;\n \n /** List of patches to apply in order */\n patches: MessagePatch[];\n \n /** The highest change number in this batch */\n changeNumber: number;\n \n /** Source of the changes */\n source: PatchSource;\n \n /** Optional metadata about the batch */\n metadata?: Record<string, string>;\n}\n\n/**\n * Source of patch changes\n */\nexport enum PatchSource {\n LOCAL = 'LOCAL',\n REMOTE = 'REMOTE', \n SERVER = 'SERVER',\n STORAGE = 'STORAGE',\n}\n\n/**\n * Response message for methods that return patches\n */\nexport interface PatchResponse {\n /** The patches to apply */\n patchBatches: PatchBatch[];\n \n /** Success status */\n success: boolean;\n \n /** Error message if success is false */\n errorMessage?: string;\n \n /** The new change number after applying these patches */\n newChangeNumber: number;\n}\n\n/**\n * Transport interface for receiving patch updates\n */\nexport interface ChangeTransport {\n /** Register callback for incoming changes */\n onChanges(callback: (batches: PatchBatch[]) => void): void;\n \n /** Disconnect from the transport */\n disconnect(): void;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@protoc-gen-go-wasmjs/runtime",
3
+ "version": "0.0.14",
4
+ "description": "Runtime utilities for protoc-gen-go-wasmjs generated code",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist/index.mjs",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./browser": {
15
+ "types": "./dist/browser/index.d.ts",
16
+ "import": "./dist/browser/index.mjs",
17
+ "require": "./dist/browser/index.js"
18
+ },
19
+ "./schema": {
20
+ "types": "./dist/schema/index.d.ts",
21
+ "import": "./dist/schema/index.mjs",
22
+ "require": "./dist/schema/index.js"
23
+ },
24
+ "./client": {
25
+ "types": "./dist/client/index.d.ts",
26
+ "import": "./dist/client/index.mjs",
27
+ "require": "./dist/client/index.js"
28
+ },
29
+ "./types": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "import": "./dist/types/index.mjs",
32
+ "require": "./dist/types/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist/**/*",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "dev": "tsup --watch",
43
+ "clean": "rimraf dist",
44
+ "typecheck": "tsc --noEmit",
45
+ "test": "vitest",
46
+ "test:ci": "vitest run",
47
+ "prepublishOnly": "pnpm run clean && pnpm run build"
48
+ },
49
+ "keywords": [
50
+ "protobuf",
51
+ "grpc",
52
+ "wasm",
53
+ "typescript",
54
+ "code-generation"
55
+ ],
56
+ "author": "Sri Panyam",
57
+ "license": "Apache-2.0",
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/panyam/protoc-gen-go-wasmjs.git",
61
+ "directory": "runtime-package"
62
+ },
63
+ "homepage": "https://github.com/panyam/protoc-gen-go-wasmjs#readme",
64
+ "bugs": {
65
+ "url": "https://github.com/panyam/protoc-gen-go-wasmjs/issues"
66
+ },
67
+ "devDependencies": {
68
+ "@types/node": "^20.0.0",
69
+ "rimraf": "^5.0.0",
70
+ "tsup": "^8.0.0",
71
+ "typescript": "^5.0.0",
72
+ "vitest": "^1.0.0"
73
+ },
74
+ "engines": {
75
+ "node": ">=16"
76
+ },
77
+ "sideEffects": false
78
+ }