dynamodb-reactive 0.1.10 → 0.1.11
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/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/{chunk-BIEVX2SA.js → chunk-FZMBRLFY.js} +4 -2
- package/dist/chunk-FZMBRLFY.js.map +1 -0
- package/dist/client.js +2 -1
- package/dist/core.js +1 -0
- package/dist/index.js +1 -0
- package/dist/infra.js +1 -0
- package/dist/infra.js.map +1 -1
- package/dist/react.js +2 -1
- package/dist/server.js +391 -25
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BIEVX2SA.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -1,10 +1,331 @@
|
|
|
1
1
|
import { SystemTableNames } from './chunk-L4NOAOXX.js';
|
|
2
|
+
import { __commonJS, __toESM } from './chunk-5WRI5ZAA.js';
|
|
2
3
|
import { DynamoDBClient, ExecuteStatementCommand } from '@aws-sdk/client-dynamodb';
|
|
3
4
|
import { UpdateCommand, DeleteCommand, PutCommand, GetCommand, DynamoDBDocumentClient, QueryCommand } from '@aws-sdk/lib-dynamodb';
|
|
4
5
|
import { unmarshall } from '@aws-sdk/util-dynamodb';
|
|
5
6
|
import jsonpatch from 'fast-json-patch';
|
|
6
7
|
import { ApiGatewayManagementApiClient, PostToConnectionCommand, GoneException } from '@aws-sdk/client-apigatewaymanagementapi';
|
|
7
8
|
|
|
9
|
+
// ../../node_modules/.pnpm/ag-common@0.0.864_jiti@2.6.1_postcss@8.5.6/node_modules/ag-common/dist/common/helpers/array.js
|
|
10
|
+
var require_array = __commonJS({
|
|
11
|
+
"../../node_modules/.pnpm/ag-common@0.0.864_jiti@2.6.1_postcss@8.5.6/node_modules/ag-common/dist/common/helpers/array.js"(exports$1) {
|
|
12
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
13
|
+
exports$1.insertElementAtIndex = exports$1.distinct = exports$1.notEmpty = exports$1.partition = exports$1.chunk = exports$1.take = exports$1.flat = exports$1.arrayToObject = void 0;
|
|
14
|
+
exports$1.distinctBy = distinctBy;
|
|
15
|
+
exports$1.findLastIndex = findLastIndex;
|
|
16
|
+
var arrayToObject = (arr, keyF, valueF) => {
|
|
17
|
+
const ret = {};
|
|
18
|
+
if (!arr || !keyF) {
|
|
19
|
+
return ret;
|
|
20
|
+
}
|
|
21
|
+
arr.forEach((v) => {
|
|
22
|
+
const k = keyF(v);
|
|
23
|
+
ret[k] = valueF(v);
|
|
24
|
+
});
|
|
25
|
+
return ret;
|
|
26
|
+
};
|
|
27
|
+
exports$1.arrayToObject = arrayToObject;
|
|
28
|
+
var flat = (arr) => [].concat(...arr);
|
|
29
|
+
exports$1.flat = flat;
|
|
30
|
+
var take = (array, num) => {
|
|
31
|
+
const safeNum = Math.max(0, Math.min(num, array.length));
|
|
32
|
+
const part = array.slice(0, safeNum);
|
|
33
|
+
const rest = array.slice(safeNum);
|
|
34
|
+
return { part, rest };
|
|
35
|
+
};
|
|
36
|
+
exports$1.take = take;
|
|
37
|
+
var chunk = (array, max) => {
|
|
38
|
+
const rows = [];
|
|
39
|
+
let row = [];
|
|
40
|
+
for (const k in array) {
|
|
41
|
+
const item = array[k];
|
|
42
|
+
row.push(item);
|
|
43
|
+
if (row.length >= max) {
|
|
44
|
+
rows.push(row);
|
|
45
|
+
row = [];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (row.length > 0) {
|
|
49
|
+
rows.push(row);
|
|
50
|
+
}
|
|
51
|
+
return rows;
|
|
52
|
+
};
|
|
53
|
+
exports$1.chunk = chunk;
|
|
54
|
+
var partition = (array, func) => !array.length ? null : [array.filter((r) => func(r)), array.filter((r) => !func(r))];
|
|
55
|
+
exports$1.partition = partition;
|
|
56
|
+
var notEmpty = (value) => value !== null && value !== void 0 && value !== false && value !== "";
|
|
57
|
+
exports$1.notEmpty = notEmpty;
|
|
58
|
+
function distinctBy(data, key, ignoreEmpty) {
|
|
59
|
+
if (!data || data.length === 0) {
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
const hashSet = /* @__PURE__ */ new Set();
|
|
63
|
+
return data.filter((x) => {
|
|
64
|
+
let keyVal;
|
|
65
|
+
if (typeof key === "string") {
|
|
66
|
+
keyVal = x[key];
|
|
67
|
+
} else {
|
|
68
|
+
keyVal = key(x);
|
|
69
|
+
}
|
|
70
|
+
if (!keyVal && ignoreEmpty) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!hashSet.has(keyVal)) {
|
|
74
|
+
hashSet.add(keyVal);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
var distinct = (arr) => [
|
|
81
|
+
...new Set(arr)
|
|
82
|
+
];
|
|
83
|
+
exports$1.distinct = distinct;
|
|
84
|
+
function findLastIndex(arr, predicate) {
|
|
85
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
86
|
+
if (predicate(arr[i], i, arr)) {
|
|
87
|
+
return i;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
var insertElementAtIndex = (arr, element, index) => [...arr.slice(0, index), element, ...arr.slice(index)];
|
|
93
|
+
exports$1.insertElementAtIndex = insertElementAtIndex;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// ../../node_modules/.pnpm/ag-common@0.0.864_jiti@2.6.1_postcss@8.5.6/node_modules/ag-common/dist/common/helpers/string/redact.js
|
|
98
|
+
var require_redact = __commonJS({
|
|
99
|
+
"../../node_modules/.pnpm/ag-common@0.0.864_jiti@2.6.1_postcss@8.5.6/node_modules/ag-common/dist/common/helpers/string/redact.js"(exports$1) {
|
|
100
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
101
|
+
exports$1.redactString = redactString;
|
|
102
|
+
exports$1.redactObject = redactObject;
|
|
103
|
+
function redactString(str) {
|
|
104
|
+
let ret = str;
|
|
105
|
+
ret = ret || "";
|
|
106
|
+
const repl = "$1<redacted>$2";
|
|
107
|
+
ret = ret.replace(/(\b)grant_type.+?(\b)/gm, repl);
|
|
108
|
+
ret = ret.replace(/(\b)Bearer .+?(\b)/gm, repl);
|
|
109
|
+
ret = ret.replace(/(eyJ[\w-_.]*\.[\w-_.]*\.[\w-_.]*)/gim, "<redacted>");
|
|
110
|
+
ret = ret.replace(/(\b)(sk_live_|sk_test_|pk_live_|pk_test_)[\w-]+/gi, "$1<redacted>");
|
|
111
|
+
ret = ret.replace(/(\b)(AKIA[0-9A-Z]{16})/gi, "$1<redacted>");
|
|
112
|
+
ret = ret.replace(/(aws_secret_access_key["\s]*[:=]["\s]*)([0-9a-zA-Z/+]{40})/gi, "$1<redacted>");
|
|
113
|
+
ret = ret.replace(/(\b)(AIza[0-9A-Za-z\\-_]{35})/gi, "$1<redacted>");
|
|
114
|
+
ret = ret.replace(/(\b)(ya29\.[0-9A-Za-z\\-_]+)/gi, "$1<redacted>");
|
|
115
|
+
ret = ret.replace(/(\b)(glpat-[a-zA-Z0-9\\-_]{20})/gi, "$1<redacted>");
|
|
116
|
+
ret = ret.replace(/(\b)(ghp_[a-zA-Z0-9]{36})/gi, "$1<redacted>");
|
|
117
|
+
ret = ret.replace(/(\b)(github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})/gi, "$1<redacted>");
|
|
118
|
+
ret = ret.replace(/(password["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
119
|
+
ret = ret.replace(/(passwd["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
120
|
+
ret = ret.replace(/(pwd["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
121
|
+
ret = ret.replace(/(secret["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
122
|
+
ret = ret.replace(/(token["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
123
|
+
ret = ret.replace(/(^|[^a-zA-Z])(api_?key|private_?key|secret_?key)["\s]*[:=]["\s]*([^",\s}]+)/gi, "$1$2<redacted>");
|
|
124
|
+
ret = ret.replace(/(auth["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
125
|
+
ret = ret.replace(/(mongodb:\/\/[^:]+:)([^@]+)(@)/gi, "$1<redacted>$3");
|
|
126
|
+
ret = ret.replace(/(mysql:\/\/[^:]+:)([^@]+)(@)/gi, "$1<redacted>$3");
|
|
127
|
+
ret = ret.replace(/(postgresql:\/\/[^:]+:)([^@]+)(@)/gi, "$1<redacted>$3");
|
|
128
|
+
ret = ret.replace(/(redis:\/\/[^:]+:)([^@]+)(@)/gi, "$1<redacted>$3");
|
|
129
|
+
ret = ret.replace(/(\b)([3-6]\d{3}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{3,4})(\b)/g, "$1<redacted>$3");
|
|
130
|
+
ret = ret.replace(/(\b)(\d{3}[-\s]?\d{2}[-\s]?\d{4})(\b)/g, "$1<redacted>$3");
|
|
131
|
+
ret = ret.replace(/(-----BEGIN [A-Z\s]+PRIVATE KEY-----)([\s\S]*?)(-----END [A-Z\s]+PRIVATE KEY-----)/gi, "$1\n<redacted>\n$3");
|
|
132
|
+
ret = ret.replace(/(sessionid["\s]*[:=]["\s]*)([a-zA-Z0-9]{32,})/gi, "$1<redacted>");
|
|
133
|
+
ret = ret.replace(/(session["\s]*[:=]["\s]*)([a-zA-Z0-9]{32,})/gi, "$1<redacted>");
|
|
134
|
+
ret = ret.replace(/(csrftoken["\s]*[:=]["\s]*)([a-zA-Z0-9]{32,})/gi, "$1<redacted>");
|
|
135
|
+
ret = ret.replace(/(DATABASE_URL["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
136
|
+
ret = ret.replace(/(REDIS_URL["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
137
|
+
ret = ret.replace(/(SMTP_PASSWORD["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
138
|
+
ret = ret.replace(/(ENCRYPTION_KEY["\s]*[:=]["\s]*)([^",\s}]+)/gi, "$1<redacted>");
|
|
139
|
+
ret = ret.replace(/\b([a-zA-Z0-9+/=_-]{20,})\b/g, (match) => {
|
|
140
|
+
if (match.endsWith("==") && match.length > 30) {
|
|
141
|
+
return "<redacted>";
|
|
142
|
+
}
|
|
143
|
+
if (getShannonEntropy(match) > 4.5) {
|
|
144
|
+
return "<redacted>";
|
|
145
|
+
}
|
|
146
|
+
return match;
|
|
147
|
+
});
|
|
148
|
+
return ret;
|
|
149
|
+
}
|
|
150
|
+
function getShannonEntropy(str) {
|
|
151
|
+
var _a;
|
|
152
|
+
const len = str.length;
|
|
153
|
+
if (len === 0)
|
|
154
|
+
return 0;
|
|
155
|
+
const frequencies = /* @__PURE__ */ new Map();
|
|
156
|
+
for (const char of str) {
|
|
157
|
+
frequencies.set(char, ((_a = frequencies.get(char)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
158
|
+
}
|
|
159
|
+
let entropy = 0;
|
|
160
|
+
for (const count of frequencies.values()) {
|
|
161
|
+
const p = count / len;
|
|
162
|
+
entropy -= p * Math.log2(p);
|
|
163
|
+
}
|
|
164
|
+
return entropy;
|
|
165
|
+
}
|
|
166
|
+
function redactObject(ob) {
|
|
167
|
+
if (typeof ob === "string") {
|
|
168
|
+
return redactString(ob);
|
|
169
|
+
} else if (typeof ob === "object") {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(redactString(JSON.stringify(ob)));
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return ob;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return ob;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// ../../node_modules/.pnpm/ag-common@0.0.864_jiti@2.6.1_postcss@8.5.6/node_modules/ag-common/dist/common/helpers/log.js
|
|
182
|
+
var require_log = __commonJS({
|
|
183
|
+
"../../node_modules/.pnpm/ag-common@0.0.864_jiti@2.6.1_postcss@8.5.6/node_modules/ag-common/dist/common/helpers/log.js"(exports$1) {
|
|
184
|
+
Object.defineProperty(exports$1, "__esModule", { value: true });
|
|
185
|
+
exports$1.fatal = exports$1.error = exports$1.trace = exports$1.warn = exports$1.info = exports$1.debug = exports$1.SetLogLevel = exports$1.SetLogShim = exports$1.GetLogLevel = void 0;
|
|
186
|
+
var array_1 = require_array();
|
|
187
|
+
var redact_1 = require_redact();
|
|
188
|
+
var GetLogLevel = (l) => ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"].findIndex((s) => s === l);
|
|
189
|
+
exports$1.GetLogLevel = GetLogLevel;
|
|
190
|
+
var logShim;
|
|
191
|
+
var SetLogShim = (ls) => {
|
|
192
|
+
logShim = ls;
|
|
193
|
+
};
|
|
194
|
+
exports$1.SetLogShim = SetLogShim;
|
|
195
|
+
var userLogLevel;
|
|
196
|
+
var SetLogLevel = (l) => {
|
|
197
|
+
const lu = (l !== null && l !== void 0 ? l : "INFO").toUpperCase();
|
|
198
|
+
if ((0, exports$1.GetLogLevel)(lu) === -1) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
userLogLevel = lu;
|
|
202
|
+
};
|
|
203
|
+
exports$1.SetLogLevel = SetLogLevel;
|
|
204
|
+
function logprocess(type, args) {
|
|
205
|
+
if (!userLogLevel) {
|
|
206
|
+
(0, exports$1.SetLogLevel)(process.env.LOG_LEVEL);
|
|
207
|
+
}
|
|
208
|
+
const min = (0, exports$1.GetLogLevel)(userLogLevel !== null && userLogLevel !== void 0 ? userLogLevel : "WARN");
|
|
209
|
+
const typesLogLevel = (0, exports$1.GetLogLevel)(type);
|
|
210
|
+
if (typesLogLevel < min) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const datetime = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-GB");
|
|
214
|
+
const log = [
|
|
215
|
+
`[${datetime}]`,
|
|
216
|
+
type,
|
|
217
|
+
...args.filter(array_1.notEmpty).map((s) => {
|
|
218
|
+
if (s instanceof Error) {
|
|
219
|
+
return (0, redact_1.redactObject)({
|
|
220
|
+
message: s.message,
|
|
221
|
+
name: s.name,
|
|
222
|
+
stack: s.stack
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return (0, redact_1.redactObject)(s);
|
|
226
|
+
})
|
|
227
|
+
];
|
|
228
|
+
if (logShim) {
|
|
229
|
+
logShim(...log);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
switch (type) {
|
|
233
|
+
case "TRACE": {
|
|
234
|
+
console.trace(...log);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "DEBUG": {
|
|
238
|
+
console.debug(...log);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "INFO": {
|
|
242
|
+
console.log(...log);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "WARN": {
|
|
246
|
+
console.warn(...log);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "ERROR": {
|
|
250
|
+
console.error(...log);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case "FATAL": {
|
|
254
|
+
console.error(...log);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
default: {
|
|
258
|
+
console.log(...log);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function printStackTrace(...args) {
|
|
264
|
+
var _a;
|
|
265
|
+
const callstack = [];
|
|
266
|
+
let isCallstackPopulated = false;
|
|
267
|
+
try {
|
|
268
|
+
throw new Error("Test");
|
|
269
|
+
} catch (e) {
|
|
270
|
+
const er = e;
|
|
271
|
+
if (er.stack) {
|
|
272
|
+
const lines = er.stack.split("\n");
|
|
273
|
+
for (let i = 0, len = lines.length; i < len; i += 1) {
|
|
274
|
+
callstack.push(` ${lines[i]} `);
|
|
275
|
+
}
|
|
276
|
+
callstack.shift();
|
|
277
|
+
isCallstackPopulated = true;
|
|
278
|
+
} else if (window.opera && er.message) {
|
|
279
|
+
const lines = er.message.split("\n");
|
|
280
|
+
for (let i = 0, len = lines.length; i < len; i += 1) {
|
|
281
|
+
if (lines[i].match(/^\s*[A-Za-z0-9\-_$]+\(/)) {
|
|
282
|
+
let entry = lines[i];
|
|
283
|
+
if (lines[i + 1]) {
|
|
284
|
+
entry += ` at ${lines[i + 1]}`;
|
|
285
|
+
i += 1;
|
|
286
|
+
}
|
|
287
|
+
callstack.push(entry);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
callstack.shift();
|
|
291
|
+
isCallstackPopulated = true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (!isCallstackPopulated) {
|
|
295
|
+
let currentFunction = args.callee.caller;
|
|
296
|
+
while (currentFunction) {
|
|
297
|
+
const fn = currentFunction.toString();
|
|
298
|
+
const fname = (_a = fn.substring(fn.indexOf("function") + 8, fn.indexOf("("))) !== null && _a !== void 0 ? _a : "anonymous";
|
|
299
|
+
callstack.push(fname);
|
|
300
|
+
currentFunction = currentFunction.caller;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return callstack.join("\n");
|
|
304
|
+
}
|
|
305
|
+
var debug3 = (...args) => logprocess("DEBUG", args);
|
|
306
|
+
exports$1.debug = debug3;
|
|
307
|
+
var info2 = (...args) => logprocess("INFO", args);
|
|
308
|
+
exports$1.info = info2;
|
|
309
|
+
var warn3 = (...args) => logprocess("WARN", args);
|
|
310
|
+
exports$1.warn = warn3;
|
|
311
|
+
var trace = (...args) => {
|
|
312
|
+
args.push(printStackTrace());
|
|
313
|
+
logprocess("TRACE", args);
|
|
314
|
+
};
|
|
315
|
+
exports$1.trace = trace;
|
|
316
|
+
var error = (...args) => {
|
|
317
|
+
args.push(printStackTrace());
|
|
318
|
+
logprocess("ERROR", args);
|
|
319
|
+
};
|
|
320
|
+
exports$1.error = error;
|
|
321
|
+
var fatal = (...args) => {
|
|
322
|
+
args.push(printStackTrace());
|
|
323
|
+
logprocess("FATAL", args);
|
|
324
|
+
};
|
|
325
|
+
exports$1.fatal = fatal;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
8
329
|
// ../server/src/procedure.ts
|
|
9
330
|
var ProcedureBuilder = class _ProcedureBuilder {
|
|
10
331
|
inputSchema;
|
|
@@ -740,6 +1061,7 @@ function batchPatches(patchSets) {
|
|
|
740
1061
|
const allPatches = patchSets.flat();
|
|
741
1062
|
return optimizePatches(allPatches);
|
|
742
1063
|
}
|
|
1064
|
+
var import_log = __toESM(require_log());
|
|
743
1065
|
function createReactiveHandler(config) {
|
|
744
1066
|
const ttlSeconds = config.ttlSeconds ?? 3600;
|
|
745
1067
|
const prefix = config.tablePrefix ? `${config.tablePrefix}-` : "";
|
|
@@ -755,6 +1077,11 @@ function createReactiveHandler(config) {
|
|
|
755
1077
|
async function handleRequest(request, headers) {
|
|
756
1078
|
try {
|
|
757
1079
|
const connectionId = request.connectionId;
|
|
1080
|
+
(0, import_log.debug)("[reactive-handler] handleRequest:", {
|
|
1081
|
+
type: request.type,
|
|
1082
|
+
connectionId,
|
|
1083
|
+
path: "path" in request ? request.path : void 0
|
|
1084
|
+
});
|
|
758
1085
|
const ctx = await config.getContext({ connectionId, headers });
|
|
759
1086
|
const dependencyTracker = new DependencyTracker();
|
|
760
1087
|
const db = createDbContext(config.dbConfig ?? {}, dependencyTracker);
|
|
@@ -795,7 +1122,7 @@ function createReactiveHandler(config) {
|
|
|
795
1122
|
const queryMetadata = dependencyTracker.getQueryMetadata();
|
|
796
1123
|
const dependencyKeys = dependencyTracker.getDependencyKeys();
|
|
797
1124
|
if (!queryMetadata) {
|
|
798
|
-
|
|
1125
|
+
(0, import_log.warn)("[reactive-handler] No query metadata captured for subscription");
|
|
799
1126
|
}
|
|
800
1127
|
const now = Date.now();
|
|
801
1128
|
const ttl = Math.floor(now / 1e3) + ttlSeconds;
|
|
@@ -834,11 +1161,13 @@ function createReactiveHandler(config) {
|
|
|
834
1161
|
})
|
|
835
1162
|
);
|
|
836
1163
|
}
|
|
837
|
-
|
|
1164
|
+
(0, import_log.debug)("[reactive-handler] Subscription created:", {
|
|
838
1165
|
connectionId,
|
|
839
1166
|
subscriptionId: request.subscriptionId,
|
|
840
|
-
|
|
841
|
-
|
|
1167
|
+
tableName: queryMetadata?.tableName,
|
|
1168
|
+
filterConditions: queryMetadata?.filterConditions,
|
|
1169
|
+
dependencies: dependencyKeys,
|
|
1170
|
+
resultCount: Array.isArray(result) ? result.length : 1
|
|
842
1171
|
});
|
|
843
1172
|
return {
|
|
844
1173
|
type: "snapshot",
|
|
@@ -870,7 +1199,7 @@ function createReactiveHandler(config) {
|
|
|
870
1199
|
Key: { pk: connectionId, sk: request.subscriptionId }
|
|
871
1200
|
})
|
|
872
1201
|
);
|
|
873
|
-
|
|
1202
|
+
(0, import_log.debug)("[reactive-handler] Subscription removed:", {
|
|
874
1203
|
connectionId,
|
|
875
1204
|
subscriptionId: request.subscriptionId
|
|
876
1205
|
});
|
|
@@ -905,7 +1234,7 @@ function createReactiveHandler(config) {
|
|
|
905
1234
|
Item: connectionEntry
|
|
906
1235
|
})
|
|
907
1236
|
);
|
|
908
|
-
|
|
1237
|
+
(0, import_log.debug)("[reactive-handler] Connection registered:", connectionEntry);
|
|
909
1238
|
}
|
|
910
1239
|
async function unregisterConnection(connectionId) {
|
|
911
1240
|
await docClient.send(
|
|
@@ -914,7 +1243,7 @@ function createReactiveHandler(config) {
|
|
|
914
1243
|
Key: { connectionId }
|
|
915
1244
|
})
|
|
916
1245
|
);
|
|
917
|
-
|
|
1246
|
+
(0, import_log.debug)("[reactive-handler] Connection unregistered:", connectionId);
|
|
918
1247
|
}
|
|
919
1248
|
async function query(path, input, headers) {
|
|
920
1249
|
const ctx = await config.getContext({ connectionId: "query", headers });
|
|
@@ -946,6 +1275,7 @@ function createReactiveHandler(config) {
|
|
|
946
1275
|
createCaller
|
|
947
1276
|
};
|
|
948
1277
|
}
|
|
1278
|
+
var import_log2 = __toESM(require_log());
|
|
949
1279
|
function createStreamHandler(config) {
|
|
950
1280
|
const connectionsTable = config.connectionsTableName ?? SystemTableNames.connections;
|
|
951
1281
|
const dependenciesTable = config.dependenciesTableName ?? SystemTableNames.dependencies;
|
|
@@ -958,6 +1288,11 @@ function createStreamHandler(config) {
|
|
|
958
1288
|
endpoint: config.apiGatewayEndpoint
|
|
959
1289
|
});
|
|
960
1290
|
async function handler(event) {
|
|
1291
|
+
(0, import_log2.debug)(
|
|
1292
|
+
"[stream-handler] Processing stream event with",
|
|
1293
|
+
event.Records.length,
|
|
1294
|
+
"records"
|
|
1295
|
+
);
|
|
961
1296
|
const affectedSubscriptions = /* @__PURE__ */ new Map();
|
|
962
1297
|
for (const record of event.Records) {
|
|
963
1298
|
if (!record.dynamodb) continue;
|
|
@@ -976,8 +1311,15 @@ function createStreamHandler(config) {
|
|
|
976
1311
|
affectedKeys.add(key);
|
|
977
1312
|
}
|
|
978
1313
|
}
|
|
1314
|
+
(0, import_log2.debug)("[stream-handler] Affected keys:", Array.from(affectedKeys));
|
|
979
1315
|
for (const key of affectedKeys) {
|
|
980
1316
|
const subscriptions = await findAffectedSubscriptions(key);
|
|
1317
|
+
(0, import_log2.debug)(
|
|
1318
|
+
"[stream-handler] Found",
|
|
1319
|
+
subscriptions.length,
|
|
1320
|
+
"subscriptions for key:",
|
|
1321
|
+
key
|
|
1322
|
+
);
|
|
981
1323
|
for (const sub of subscriptions) {
|
|
982
1324
|
const connId = sub.connectionId;
|
|
983
1325
|
const subId = sub.subscriptionId;
|
|
@@ -988,6 +1330,10 @@ function createStreamHandler(config) {
|
|
|
988
1330
|
}
|
|
989
1331
|
}
|
|
990
1332
|
}
|
|
1333
|
+
(0, import_log2.debug)(
|
|
1334
|
+
"[stream-handler] Total affected subscriptions:",
|
|
1335
|
+
affectedSubscriptions.size
|
|
1336
|
+
);
|
|
991
1337
|
const sendPromises = [];
|
|
992
1338
|
for (const [connectionId, subscriptionIds] of affectedSubscriptions) {
|
|
993
1339
|
for (const subscriptionId of subscriptionIds) {
|
|
@@ -1018,34 +1364,51 @@ function createStreamHandler(config) {
|
|
|
1018
1364
|
subscriptionId: item.subscriptionId
|
|
1019
1365
|
}));
|
|
1020
1366
|
} catch (error) {
|
|
1021
|
-
|
|
1367
|
+
(0, import_log2.error)("[stream-handler] Error finding affected subscriptions:", error);
|
|
1022
1368
|
return [];
|
|
1023
1369
|
}
|
|
1024
1370
|
}
|
|
1025
1371
|
async function processSubscription(connectionId, subscriptionId) {
|
|
1372
|
+
(0, import_log2.debug)("[stream-handler] Processing subscription:", {
|
|
1373
|
+
connectionId,
|
|
1374
|
+
subscriptionId
|
|
1375
|
+
});
|
|
1026
1376
|
try {
|
|
1027
1377
|
const queryState = await getQueryState(connectionId, subscriptionId);
|
|
1028
1378
|
if (!queryState) {
|
|
1029
|
-
|
|
1030
|
-
|
|
1379
|
+
(0, import_log2.warn)(
|
|
1380
|
+
"[stream-handler] Subscription not found:",
|
|
1381
|
+
connectionId,
|
|
1382
|
+
subscriptionId
|
|
1031
1383
|
);
|
|
1032
1384
|
return;
|
|
1033
1385
|
}
|
|
1386
|
+
(0, import_log2.debug)("[stream-handler] Query metadata:", {
|
|
1387
|
+
tableName: queryState.queryMetadata.tableName,
|
|
1388
|
+
filterConditions: queryState.queryMetadata.filterConditions,
|
|
1389
|
+
lastResultCount: queryState.lastResult?.length
|
|
1390
|
+
});
|
|
1034
1391
|
const newResult = await executeQueryFromMetadata(
|
|
1035
1392
|
queryState.queryMetadata
|
|
1036
1393
|
);
|
|
1394
|
+
(0, import_log2.debug)("[stream-handler] New result count:", newResult.length);
|
|
1037
1395
|
if (!hasChanges(queryState.lastResult, newResult)) {
|
|
1396
|
+
(0, import_log2.debug)("[stream-handler] No changes detected, skipping patch");
|
|
1038
1397
|
return;
|
|
1039
1398
|
}
|
|
1040
1399
|
const patches = generatePatches(queryState.lastResult, newResult);
|
|
1400
|
+
(0, import_log2.debug)("[stream-handler] Generated", patches.length, "patches");
|
|
1041
1401
|
await updateQueryState(connectionId, subscriptionId, newResult);
|
|
1042
1402
|
await sendPatch(connectionId, subscriptionId, patches);
|
|
1403
|
+
(0, import_log2.debug)("[stream-handler] Patch sent successfully");
|
|
1043
1404
|
} catch (error) {
|
|
1044
1405
|
if (error instanceof GoneException) {
|
|
1045
1406
|
await cleanupConnection(connectionId);
|
|
1046
1407
|
} else {
|
|
1047
|
-
|
|
1048
|
-
|
|
1408
|
+
(0, import_log2.error)(
|
|
1409
|
+
"[stream-handler] Error processing subscription:",
|
|
1410
|
+
connectionId,
|
|
1411
|
+
subscriptionId,
|
|
1049
1412
|
error
|
|
1050
1413
|
);
|
|
1051
1414
|
}
|
|
@@ -1064,7 +1427,7 @@ function createStreamHandler(config) {
|
|
|
1064
1427
|
);
|
|
1065
1428
|
return response.Item ?? null;
|
|
1066
1429
|
} catch (error) {
|
|
1067
|
-
|
|
1430
|
+
(0, import_log2.error)("[stream-handler] Error getting query state:", error);
|
|
1068
1431
|
return null;
|
|
1069
1432
|
}
|
|
1070
1433
|
}
|
|
@@ -1084,8 +1447,8 @@ function createStreamHandler(config) {
|
|
|
1084
1447
|
(item) => unmarshall(item)
|
|
1085
1448
|
);
|
|
1086
1449
|
} catch (error) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1450
|
+
(0, import_log2.error)("[stream-handler] Error executing query from metadata:", error);
|
|
1451
|
+
(0, import_log2.error)("[stream-handler] Statement:", statement);
|
|
1089
1452
|
return [];
|
|
1090
1453
|
}
|
|
1091
1454
|
}
|
|
@@ -1177,7 +1540,7 @@ function createStreamHandler(config) {
|
|
|
1177
1540
|
})
|
|
1178
1541
|
);
|
|
1179
1542
|
} catch (error) {
|
|
1180
|
-
|
|
1543
|
+
(0, import_log2.error)("[stream-handler] Error updating query state:", error);
|
|
1181
1544
|
}
|
|
1182
1545
|
}
|
|
1183
1546
|
async function sendPatch(connectionId, subscriptionId, patches) {
|
|
@@ -1197,11 +1560,11 @@ function createStreamHandler(config) {
|
|
|
1197
1560
|
if (error instanceof GoneException) {
|
|
1198
1561
|
throw error;
|
|
1199
1562
|
}
|
|
1200
|
-
|
|
1563
|
+
(0, import_log2.error)("[stream-handler] Error sending patch to", connectionId, error);
|
|
1201
1564
|
}
|
|
1202
1565
|
}
|
|
1203
1566
|
async function cleanupConnection(connectionId) {
|
|
1204
|
-
|
|
1567
|
+
(0, import_log2.info)("[stream-handler] Cleaning up disconnected connection:", connectionId);
|
|
1205
1568
|
try {
|
|
1206
1569
|
const queriesResponse = await docClient.send(
|
|
1207
1570
|
new QueryCommand({
|
|
@@ -1244,11 +1607,14 @@ function createStreamHandler(config) {
|
|
|
1244
1607
|
}
|
|
1245
1608
|
})
|
|
1246
1609
|
);
|
|
1247
|
-
|
|
1248
|
-
|
|
1610
|
+
(0, import_log2.info)(
|
|
1611
|
+
"[stream-handler] Cleaned up connection:",
|
|
1612
|
+
connectionId,
|
|
1613
|
+
subscriptions.length,
|
|
1614
|
+
"subscriptions removed"
|
|
1249
1615
|
);
|
|
1250
1616
|
} catch (error) {
|
|
1251
|
-
|
|
1617
|
+
(0, import_log2.error)("[stream-handler] Error cleaning up connection:", error);
|
|
1252
1618
|
}
|
|
1253
1619
|
}
|
|
1254
1620
|
return { handler };
|
|
@@ -1271,10 +1637,10 @@ function createConnectHandler(config) {
|
|
|
1271
1637
|
}
|
|
1272
1638
|
})
|
|
1273
1639
|
);
|
|
1274
|
-
|
|
1640
|
+
(0, import_log2.debug)("[stream-handler] Connection established:", connectionId);
|
|
1275
1641
|
return { statusCode: 200 };
|
|
1276
1642
|
} catch (error) {
|
|
1277
|
-
|
|
1643
|
+
(0, import_log2.error)("[stream-handler] Error creating connection:", error);
|
|
1278
1644
|
return { statusCode: 500 };
|
|
1279
1645
|
}
|
|
1280
1646
|
};
|
|
@@ -1294,10 +1660,10 @@ function createDisconnectHandler(config) {
|
|
|
1294
1660
|
Key: { connectionId }
|
|
1295
1661
|
})
|
|
1296
1662
|
);
|
|
1297
|
-
|
|
1663
|
+
(0, import_log2.debug)("[stream-handler] Connection removed:", connectionId);
|
|
1298
1664
|
return { statusCode: 200 };
|
|
1299
1665
|
} catch (error) {
|
|
1300
|
-
|
|
1666
|
+
(0, import_log2.error)("[stream-handler] Error removing connection:", error);
|
|
1301
1667
|
return { statusCode: 500 };
|
|
1302
1668
|
}
|
|
1303
1669
|
};
|