repro-nest 0.0.204 → 0.0.205

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.
Files changed (3) hide show
  1. package/dist/index.js +65 -28
  2. package/package.json +1 -1
  3. package/src/index.ts +59 -24
package/dist/index.js CHANGED
@@ -93,39 +93,76 @@ function flushQueryFinalizers(query, value, threw, error) {
93
93
  catch { }
94
94
  }
95
95
  function patchMongooseExecCapture(targetMongoose = mongoose) {
96
+ // Patch Query.prototype.exec to capture resolved results for trace return values.
96
97
  try {
97
98
  const Qp = targetMongoose?.Query?.prototype;
98
- if (!Qp || Qp.__repro_exec_patched)
99
- return;
100
- const origExec = Qp.exec;
101
- if (typeof origExec !== 'function')
102
- return;
103
- Qp.__repro_exec_patched = true;
104
- Qp.exec = function reproPatchedExec(...args) {
105
- try {
106
- this.__repro_is_query = true;
99
+ if (Qp && !Qp.__repro_exec_patched) {
100
+ const origExec = Qp.exec;
101
+ if (typeof origExec === 'function') {
102
+ Qp.__repro_exec_patched = true;
103
+ Qp.exec = function reproPatchedExec(...args) {
104
+ try {
105
+ this.__repro_is_query = true;
106
+ }
107
+ catch { }
108
+ const p = origExec.apply(this, args);
109
+ try {
110
+ if (p && typeof p.then === 'function') {
111
+ this.__repro_result_promise = p;
112
+ p.then((res) => {
113
+ try {
114
+ this.__repro_result = res;
115
+ }
116
+ catch { }
117
+ flushQueryFinalizers(this, res, false, null);
118
+ return res;
119
+ }, (err) => {
120
+ flushQueryFinalizers(this, undefined, true, err);
121
+ return err;
122
+ });
123
+ }
124
+ }
125
+ catch { }
126
+ return p;
127
+ };
107
128
  }
108
- catch { }
109
- const p = origExec.apply(this, args);
110
- try {
111
- if (p && typeof p.then === 'function') {
112
- this.__repro_result_promise = p;
113
- p.then((res) => {
114
- try {
115
- this.__repro_result = res;
129
+ }
130
+ }
131
+ catch { }
132
+ // Patch Aggregate.prototype.exec as well so aggregation pipelines surface their results in traces.
133
+ try {
134
+ const Ap = targetMongoose?.Aggregate?.prototype;
135
+ if (Ap && !Ap.__repro_agg_exec_patched) {
136
+ const origAggExec = Ap.exec;
137
+ if (typeof origAggExec === 'function') {
138
+ Ap.__repro_agg_exec_patched = true;
139
+ Ap.exec = function reproPatchedAggExec(...args) {
140
+ try {
141
+ this.__repro_is_query = true;
142
+ }
143
+ catch { }
144
+ const p = origAggExec.apply(this, args);
145
+ try {
146
+ if (p && typeof p.then === 'function') {
147
+ this.__repro_result_promise = p;
148
+ p.then((res) => {
149
+ try {
150
+ this.__repro_result = res;
151
+ }
152
+ catch { }
153
+ flushQueryFinalizers(this, res, false, null);
154
+ return res;
155
+ }, (err) => {
156
+ flushQueryFinalizers(this, undefined, true, err);
157
+ return err;
158
+ });
116
159
  }
117
- catch { }
118
- flushQueryFinalizers(this, res, false, null);
119
- return res;
120
- }, (err) => {
121
- flushQueryFinalizers(this, undefined, true, err);
122
- return err;
123
- });
124
- }
160
+ }
161
+ catch { }
162
+ return p;
163
+ };
125
164
  }
126
- catch { }
127
- return p;
128
- };
165
+ }
129
166
  }
130
167
  catch { }
131
168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repro-nest",
3
- "version": "0.0.204",
3
+ "version": "0.0.205",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -87,33 +87,68 @@ function flushQueryFinalizers(query: any, value: any, threw: boolean, error: any
87
87
  }
88
88
 
89
89
  function patchMongooseExecCapture(targetMongoose: any = mongoose) {
90
+ // Patch Query.prototype.exec to capture resolved results for trace return values.
90
91
  try {
91
92
  const Qp: any = targetMongoose?.Query?.prototype;
92
- if (!Qp || Qp.__repro_exec_patched) return;
93
- const origExec = Qp.exec;
94
- if (typeof origExec !== 'function') return;
95
- Qp.__repro_exec_patched = true;
96
- Qp.exec = function reproPatchedExec(this: any, ...args: any[]) {
97
- try { (this as any).__repro_is_query = true; } catch {}
98
- const p = origExec.apply(this, args);
99
- try {
100
- if (p && typeof p.then === 'function') {
101
- this.__repro_result_promise = p;
102
- p.then(
103
- (res: any) => {
104
- try { this.__repro_result = res; } catch {}
105
- flushQueryFinalizers(this, res, false, null);
106
- return res;
107
- },
108
- (err: any) => {
109
- flushQueryFinalizers(this, undefined, true, err);
110
- return err;
93
+ if (Qp && !Qp.__repro_exec_patched) {
94
+ const origExec = Qp.exec;
95
+ if (typeof origExec === 'function') {
96
+ Qp.__repro_exec_patched = true;
97
+ Qp.exec = function reproPatchedExec(this: any, ...args: any[]) {
98
+ try { (this as any).__repro_is_query = true; } catch {}
99
+ const p = origExec.apply(this, args);
100
+ try {
101
+ if (p && typeof p.then === 'function') {
102
+ this.__repro_result_promise = p;
103
+ p.then(
104
+ (res: any) => {
105
+ try { this.__repro_result = res; } catch {}
106
+ flushQueryFinalizers(this, res, false, null);
107
+ return res;
108
+ },
109
+ (err: any) => {
110
+ flushQueryFinalizers(this, undefined, true, err);
111
+ return err;
112
+ }
113
+ );
111
114
  }
112
- );
113
- }
114
- } catch {}
115
- return p;
116
- };
115
+ } catch {}
116
+ return p;
117
+ };
118
+ }
119
+ }
120
+ } catch {}
121
+
122
+ // Patch Aggregate.prototype.exec as well so aggregation pipelines surface their results in traces.
123
+ try {
124
+ const Ap: any = targetMongoose?.Aggregate?.prototype;
125
+ if (Ap && !Ap.__repro_agg_exec_patched) {
126
+ const origAggExec = Ap.exec;
127
+ if (typeof origAggExec === 'function') {
128
+ Ap.__repro_agg_exec_patched = true;
129
+ Ap.exec = function reproPatchedAggExec(this: any, ...args: any[]) {
130
+ try { (this as any).__repro_is_query = true; } catch {}
131
+ const p = origAggExec.apply(this, args);
132
+ try {
133
+ if (p && typeof p.then === 'function') {
134
+ this.__repro_result_promise = p;
135
+ p.then(
136
+ (res: any) => {
137
+ try { this.__repro_result = res; } catch {}
138
+ flushQueryFinalizers(this, res, false, null);
139
+ return res;
140
+ },
141
+ (err: any) => {
142
+ flushQueryFinalizers(this, undefined, true, err);
143
+ return err;
144
+ }
145
+ );
146
+ }
147
+ } catch {}
148
+ return p;
149
+ };
150
+ }
151
+ }
117
152
  } catch {}
118
153
  }
119
154