@temporalio/proto 1.16.1 → 1.17.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/lib/patch-protobuf-root.js +44 -6
- package/lib/patch-protobuf-root.js.map +1 -1
- package/package.json +2 -2
- package/protos/index.d.ts +3 -3
- package/protos/json-module.js +3734 -190
- package/protos/root.d.ts +19721 -11269
- package/src/patch-protobuf-root.ts +44 -11
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// Properties used internally by protobufjs on Namespace/ReflectionObject instances.
|
|
2
|
+
// A protobuf package component that happens to share one of these names must not be
|
|
3
|
+
// promoted to a direct property, or it would corrupt protobufjs's internal state.
|
|
4
|
+
// (Such types are still reachable via root.lookup() or root.nested traversal.)
|
|
5
|
+
const ROOT_PROPS = new Set([
|
|
2
6
|
'options',
|
|
3
7
|
'parsedOptions',
|
|
4
8
|
'name',
|
|
@@ -8,7 +12,7 @@ const ROOT_PROPS = [
|
|
|
8
12
|
'filename',
|
|
9
13
|
'nested',
|
|
10
14
|
'_nestedArray',
|
|
11
|
-
];
|
|
15
|
+
]);
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Create a version of `root` with non-nested namespaces to match the generated types.
|
|
@@ -18,26 +22,55 @@ const ROOT_PROPS = [
|
|
|
18
22
|
* @returns A new patched `root`
|
|
19
23
|
*/
|
|
20
24
|
export function patchProtobufRoot<T extends Record<string, unknown>>(root: T): T {
|
|
21
|
-
|
|
25
|
+
const patched = _patchProtobufRoot(root);
|
|
26
|
+
|
|
27
|
+
// Protobufjs >=7.5.2 added a fast-path cache in Namespace#lookup() that accesses
|
|
28
|
+
// `this.root._fullyQualifiedObjects`. The `root` accessor is defined as a non-enumerable
|
|
29
|
+
// getter on `ReflectionObject.prototype`, so it is not copied by `for...in` loops.
|
|
30
|
+
// When the patched root is imported via `import * as proto from '@temporalio/proto'`,
|
|
31
|
+
// TypeScript's `__importStar` helper wraps the CJS module in a plain object by iterating
|
|
32
|
+
// own enumerable properties with `for...in` + `hasOwnProperty`. Because `root` is
|
|
33
|
+
// non-enumerable, it is skipped, the wrapper's `root` is `undefined`, and any subsequent
|
|
34
|
+
// `this.root._fullyQualifiedObjects` access crashes.
|
|
35
|
+
// Defining `root` as an own **enumerable** getter ensures `__importStar` includes it in
|
|
36
|
+
// the wrapper, so that `wrapper.root` delegates back to the patched root (which has the
|
|
37
|
+
// proper `_fullyQualifiedObjects` map and full prototype chain).
|
|
38
|
+
if (!Object.getOwnPropertyDescriptor(patched, 'root')) {
|
|
39
|
+
Object.defineProperty(patched, 'root', {
|
|
40
|
+
get(this: any) {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
42
|
+
let ptr = this;
|
|
43
|
+
while (ptr.parent !== null) ptr = ptr.parent;
|
|
44
|
+
return ptr;
|
|
45
|
+
},
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return patched;
|
|
22
52
|
}
|
|
23
53
|
|
|
24
54
|
function _patchProtobufRoot<T extends Record<string, unknown>>(root: T, name?: string): T {
|
|
25
55
|
const newRoot = new (root.constructor as any)(isNamespace(root) ? name : {});
|
|
26
56
|
for (const key in root) {
|
|
57
|
+
// 'root' is a getter-only accessor defined on ReflectionObject.prototype. Trying to
|
|
58
|
+
// assign it as a plain property on a new Root/Namespace instance throws in strict mode.
|
|
59
|
+
// It is also safe to skip because each object correctly resolves its own root at runtime
|
|
60
|
+
// by traversing the parent chain. The top-level own enumerable getter is added separately
|
|
61
|
+
// by patchProtobufRoot() after recursion completes.
|
|
62
|
+
if (key === 'root') continue;
|
|
27
63
|
newRoot[key] = root[key];
|
|
28
64
|
}
|
|
29
65
|
|
|
30
66
|
if (isRecord(root.nested)) {
|
|
31
67
|
for (const typeOrNamespace in root.nested) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
isNamespace(value) ? 'namespace' : 'type'
|
|
37
|
-
}. This may result in protobufjs not working property.`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
68
|
+
// Skip names that protobufjs uses internally — overriding them would corrupt
|
|
69
|
+
// the namespace object's internal state. Types/namespaces with these names are
|
|
70
|
+
// still reachable via root.lookup() or by traversing root.nested manually.
|
|
71
|
+
if (ROOT_PROPS.has(typeOrNamespace)) continue;
|
|
40
72
|
|
|
73
|
+
const value = root.nested[typeOrNamespace];
|
|
41
74
|
if (isNamespace(value)) {
|
|
42
75
|
newRoot[typeOrNamespace] = _patchProtobufRoot(value, typeOrNamespace);
|
|
43
76
|
} else if (isType(value)) {
|