@temporalio/proto 0.23.0 → 1.0.0
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/LICENSE.md +1 -1
- package/README.md +1 -1
- package/package.json +7 -9
- package/protos/index.d.ts +1 -1
- package/protos/json-module.js +1753 -481
- package/protos/root.d.ts +18911 -13025
- package/src/patch-protobuf-root.ts +66 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const ROOT_PROPS = [
|
|
2
|
+
'options',
|
|
3
|
+
'parsedOptions',
|
|
4
|
+
'name',
|
|
5
|
+
'parent',
|
|
6
|
+
'resolved',
|
|
7
|
+
'comment',
|
|
8
|
+
'filename',
|
|
9
|
+
'nested',
|
|
10
|
+
'_nestedArray',
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a version of `root` with non-nested namespaces to match the generated types.
|
|
15
|
+
* For more information, see:
|
|
16
|
+
* https://github.com/temporalio/sdk-typescript/blob/main/docs/protobuf-libraries.md#current-solution
|
|
17
|
+
* @param root Generated by `pbjs -t json-module -w commonjs -o json-module.js *.proto`
|
|
18
|
+
* @returns A new patched `root`
|
|
19
|
+
*/
|
|
20
|
+
export function patchProtobufRoot<T extends Record<string, unknown>>(root: T): T {
|
|
21
|
+
return _patchProtobufRoot(root);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _patchProtobufRoot<T extends Record<string, unknown>>(root: T, name?: string): T {
|
|
25
|
+
const newRoot = new (root.constructor as any)(isNamespace(root) ? name : {});
|
|
26
|
+
for (const key in root) {
|
|
27
|
+
newRoot[key] = root[key];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (isRecord(root.nested)) {
|
|
31
|
+
for (const typeOrNamespace in root.nested) {
|
|
32
|
+
const value = root.nested[typeOrNamespace];
|
|
33
|
+
if (ROOT_PROPS.includes(typeOrNamespace)) {
|
|
34
|
+
console.log(
|
|
35
|
+
`patchProtobufRoot warning: overriding property '${typeOrNamespace}' that is used by protobufjs with the '${typeOrNamespace}' protobuf ${
|
|
36
|
+
isNamespace(value) ? 'namespace' : 'type'
|
|
37
|
+
}. This may result in protobufjs not working property.`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isNamespace(value)) {
|
|
42
|
+
newRoot[typeOrNamespace] = _patchProtobufRoot(value, typeOrNamespace);
|
|
43
|
+
} else if (isType(value)) {
|
|
44
|
+
newRoot[typeOrNamespace] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return newRoot;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type Type = Record<string, unknown>;
|
|
53
|
+
type Namespace = { nested: Record<string, unknown> };
|
|
54
|
+
|
|
55
|
+
function isType(value: unknown): value is Type {
|
|
56
|
+
return isRecord(value) && value.constructor.name === 'Type';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isNamespace(value: unknown): value is Namespace {
|
|
60
|
+
return isRecord(value) && value.constructor.name === 'Namespace';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Duplicate from type-helpers instead of importing in order to avoid circular dependency
|
|
64
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
65
|
+
return typeof value === 'object' && value !== null;
|
|
66
|
+
}
|