dynamodb-reactive 0.2.2 → 0.2.3
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/README.md +9 -16
- package/dist/{client-r_tnzwqi.d.ts → client-Zb67giI5.d.ts} +5 -0
- package/dist/client.cjs +38 -18
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +38 -18
- package/dist/client.js.map +1 -1
- package/dist/infra.cjs +5 -16
- package/dist/infra.cjs.map +1 -1
- package/dist/infra.d.cts +1 -8
- package/dist/infra.d.ts +1 -8
- package/dist/infra.js +5 -16
- package/dist/infra.js.map +1 -1
- package/dist/react.cjs +38 -18
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +38 -18
- package/dist/react.js.map +1 -1
- package/dist/server.cjs +35 -66
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +35 -66
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -2068,7 +2068,7 @@ async function mapWithConcurrency(values, concurrency, mapper) {
|
|
|
2068
2068
|
await Promise.all(workers);
|
|
2069
2069
|
return results;
|
|
2070
2070
|
}
|
|
2071
|
-
function
|
|
2071
|
+
async function processRecord(record, utils) {
|
|
2072
2072
|
const tableName = extractTableName(record);
|
|
2073
2073
|
if (!tableName || !record.dynamodb) {
|
|
2074
2074
|
throw new Error("Malformed DynamoDB stream record");
|
|
@@ -2079,84 +2079,53 @@ function extractRecordAffectedKeys(record) {
|
|
|
2079
2079
|
const item = unmarshall(image);
|
|
2080
2080
|
for (const key of extractAffectedKeys(tableName, item)) affectedKeys.add(key);
|
|
2081
2081
|
}
|
|
2082
|
-
return affectedKeys;
|
|
2083
|
-
}
|
|
2084
|
-
function subscriptionKey(subscription) {
|
|
2085
|
-
return JSON.stringify([
|
|
2086
|
-
subscription.connectionId,
|
|
2087
|
-
subscription.subscriptionId
|
|
2088
|
-
]);
|
|
2089
|
-
}
|
|
2090
|
-
function failureIdentifier(record, cause) {
|
|
2091
|
-
const itemIdentifier = record.dynamodb?.SequenceNumber;
|
|
2092
|
-
if (!itemIdentifier) {
|
|
2093
|
-
throw new Error("Failed DynamoDB stream record has no sequence number", {
|
|
2094
|
-
cause
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
return itemIdentifier;
|
|
2098
|
-
}
|
|
2099
|
-
async function processStreamEvent(event, utils) {
|
|
2100
|
-
const failures = /* @__PURE__ */ new Map();
|
|
2101
|
-
const dependencies = /* @__PURE__ */ new Map();
|
|
2102
|
-
for (const [recordIndex, record] of event.Records.entries()) {
|
|
2103
|
-
try {
|
|
2104
|
-
for (const dependencyKey of extractRecordAffectedKeys(record)) {
|
|
2105
|
-
const recordIndexes = dependencies.get(dependencyKey) ?? /* @__PURE__ */ new Set();
|
|
2106
|
-
recordIndexes.add(recordIndex);
|
|
2107
|
-
dependencies.set(dependencyKey, recordIndexes);
|
|
2108
|
-
}
|
|
2109
|
-
} catch (error2) {
|
|
2110
|
-
error("[stream] Record dependency extraction failed:", error2);
|
|
2111
|
-
failures.set(recordIndex, error2);
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
2082
|
const subscriptions = /* @__PURE__ */ new Map();
|
|
2115
|
-
await mapWithConcurrency(
|
|
2116
|
-
[...
|
|
2083
|
+
const lookupResults = await mapWithConcurrency(
|
|
2084
|
+
[...affectedKeys],
|
|
2117
2085
|
MAX_FANOUT_CONCURRENCY,
|
|
2118
|
-
|
|
2119
|
-
try {
|
|
2120
|
-
const affectedSubscriptions = await utils.findAffectedSubscriptions(dependencyKey);
|
|
2121
|
-
for (const subscription of affectedSubscriptions) {
|
|
2122
|
-
const key = subscriptionKey(subscription);
|
|
2123
|
-
const work = subscriptions.get(key) ?? {
|
|
2124
|
-
...subscription,
|
|
2125
|
-
recordIndexes: /* @__PURE__ */ new Set()
|
|
2126
|
-
};
|
|
2127
|
-
for (const recordIndex of recordIndexes) {
|
|
2128
|
-
work.recordIndexes.add(recordIndex);
|
|
2129
|
-
}
|
|
2130
|
-
subscriptions.set(key, work);
|
|
2131
|
-
}
|
|
2132
|
-
} catch (error2) {
|
|
2133
|
-
error("[stream] Subscription dependency lookup failed:", error2);
|
|
2134
|
-
for (const recordIndex of recordIndexes) {
|
|
2135
|
-
failures.set(recordIndex, error2);
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2086
|
+
(key) => utils.findAffectedSubscriptions(key)
|
|
2139
2087
|
);
|
|
2088
|
+
for (const result of lookupResults) {
|
|
2089
|
+
for (const subscription of result) {
|
|
2090
|
+
subscriptions.set(
|
|
2091
|
+
`${subscription.connectionId}\0${subscription.subscriptionId}`,
|
|
2092
|
+
subscription
|
|
2093
|
+
);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2140
2096
|
await mapWithConcurrency(
|
|
2141
2097
|
[...subscriptions.values()],
|
|
2142
2098
|
MAX_FANOUT_CONCURRENCY,
|
|
2143
|
-
|
|
2099
|
+
({ connectionId, subscriptionId }) => utils.processSubscription(connectionId, subscriptionId)
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
async function processStreamEvent(event, utils) {
|
|
2103
|
+
const results = await mapWithConcurrency(
|
|
2104
|
+
event.Records,
|
|
2105
|
+
MAX_FANOUT_CONCURRENCY,
|
|
2106
|
+
async (record) => {
|
|
2144
2107
|
try {
|
|
2145
|
-
await
|
|
2108
|
+
await processRecord(record, utils);
|
|
2109
|
+
return null;
|
|
2146
2110
|
} catch (error2) {
|
|
2147
|
-
error("[stream]
|
|
2148
|
-
|
|
2149
|
-
|
|
2111
|
+
error("[stream] Record failed:", error2);
|
|
2112
|
+
const itemIdentifier = record.dynamodb?.SequenceNumber;
|
|
2113
|
+
if (!itemIdentifier) {
|
|
2114
|
+
throw new Error(
|
|
2115
|
+
"Failed DynamoDB stream record has no sequence number",
|
|
2116
|
+
{ cause: error2 }
|
|
2117
|
+
);
|
|
2150
2118
|
}
|
|
2119
|
+
return {
|
|
2120
|
+
itemIdentifier
|
|
2121
|
+
};
|
|
2151
2122
|
}
|
|
2152
2123
|
}
|
|
2153
2124
|
);
|
|
2154
2125
|
return {
|
|
2155
|
-
batchItemFailures:
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
return [{ itemIdentifier: failureIdentifier(record, cause) }];
|
|
2159
|
-
})
|
|
2126
|
+
batchItemFailures: results.filter(
|
|
2127
|
+
(failure) => failure !== null
|
|
2128
|
+
)
|
|
2160
2129
|
};
|
|
2161
2130
|
}
|
|
2162
2131
|
function clients(config) {
|