@warlock.js/devtools 5.55.0 → 5.56.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/CHANGELOG.md +29 -0
- package/README.md +26 -13
- package/cjs/ai-source-DTpxumMA.cjs +381 -0
- package/cjs/ai-source-DTpxumMA.cjs.map +1 -0
- package/cjs/auth-DzU0gHDG.cjs +1655 -0
- package/cjs/auth-DzU0gHDG.cjs.map +1 -0
- package/cjs/boot-BQi0Etor.cjs +138 -0
- package/cjs/boot-BQi0Etor.cjs.map +1 -0
- package/cjs/capture-CqIiaznN.cjs +1342 -0
- package/cjs/capture-CqIiaznN.cjs.map +1 -0
- package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
- package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
- package/cjs/collector-CJbQbzzK.cjs +271 -0
- package/cjs/collector-CJbQbzzK.cjs.map +1 -0
- package/cjs/contracts-CVmplkNb.cjs +112 -0
- package/cjs/contracts-CVmplkNb.cjs.map +1 -0
- package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
- package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
- package/cjs/errors-CyZp5yS-.cjs +177 -0
- package/cjs/errors-CyZp5yS-.cjs.map +1 -0
- package/cjs/histogram-BaI-PnCv.cjs +102 -0
- package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
- package/cjs/http-CabcUwBx.cjs +870 -0
- package/cjs/http-CabcUwBx.cjs.map +1 -0
- package/cjs/index.cjs +1 -1
- package/cjs/insights-BKtqxdnP.cjs +811 -0
- package/cjs/insights-BKtqxdnP.cjs.map +1 -0
- package/cjs/ip-DbNhPOzi.cjs +153 -0
- package/cjs/ip-DbNhPOzi.cjs.map +1 -0
- package/cjs/migrations-w7GMsrQw.cjs +297 -0
- package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
- package/cjs/openapi-CC7OAUc6.cjs +52 -0
- package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
- package/cjs/options-CWqFC5__.cjs +181 -0
- package/cjs/options-CWqFC5__.cjs.map +1 -0
- package/cjs/panels-B0dAfGbJ.cjs +298 -0
- package/cjs/panels-B0dAfGbJ.cjs.map +1 -0
- package/cjs/process-panel-DEOnLxoT.cjs +48 -0
- package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
- package/cjs/production/index.cjs +238 -0
- package/cjs/production/index.cjs.map +1 -0
- package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
- package/cjs/server-B6xdeKS8.cjs +184 -0
- package/cjs/server-B6xdeKS8.cjs.map +1 -0
- package/cjs/{src-Xwm3Eel9.cjs → src-Ce-3Lniv.cjs} +163 -295
- package/cjs/src-Ce-3Lniv.cjs.map +1 -0
- package/cjs/store-aq207T8v.cjs +9 -0
- package/cjs/stream-route-BGJa-zQu.cjs +875 -0
- package/cjs/stream-route-BGJa-zQu.cjs.map +1 -0
- package/esm/devtools-connector.d.mts +16 -13
- package/esm/devtools-connector.d.mts.map +1 -1
- package/esm/devtools-connector.mjs +127 -18
- package/esm/devtools-connector.mjs.map +1 -1
- package/esm/index.d.mts +3 -2
- package/esm/options.mjs +2 -1
- package/esm/options.mjs.map +1 -1
- package/esm/panels.mjs +50 -5
- package/esm/panels.mjs.map +1 -1
- package/esm/production/auth/common-passwords.mjs +303 -0
- package/esm/production/auth/common-passwords.mjs.map +1 -0
- package/esm/production/auth/default-crypto.mjs +19 -0
- package/esm/production/auth/default-crypto.mjs.map +1 -0
- package/esm/production/auth/helpers.mjs +77 -0
- package/esm/production/auth/helpers.mjs.map +1 -0
- package/esm/production/auth/index.mjs +6 -0
- package/esm/production/auth/passkeys.mjs +96 -0
- package/esm/production/auth/passkeys.mjs.map +1 -0
- package/esm/production/auth/service.mjs +1166 -0
- package/esm/production/auth/service.mjs.map +1 -0
- package/esm/production/boot.mjs +138 -0
- package/esm/production/boot.mjs.map +1 -0
- package/esm/production/capture/dev-stats.mjs +83 -0
- package/esm/production/capture/dev-stats.mjs.map +1 -0
- package/esm/production/capture/engine.mjs +442 -0
- package/esm/production/capture/engine.mjs.map +1 -0
- package/esm/production/capture/explain.mjs +271 -0
- package/esm/production/capture/explain.mjs.map +1 -0
- package/esm/production/capture/filter.mjs +24 -0
- package/esm/production/capture/filter.mjs.map +1 -0
- package/esm/production/capture/index.mjs +7 -0
- package/esm/production/capture/production-capture.mjs +134 -0
- package/esm/production/capture/production-capture.mjs.map +1 -0
- package/esm/production/capture/redact.mjs +109 -0
- package/esm/production/capture/redact.mjs.map +1 -0
- package/esm/production/capture/stats-stores.mjs +300 -0
- package/esm/production/capture/stats-stores.mjs.map +1 -0
- package/esm/production/cli/actions.mjs +151 -0
- package/esm/production/cli/actions.mjs.map +1 -0
- package/esm/production/cli/index.d.mts +17 -0
- package/esm/production/cli/index.d.mts.map +1 -0
- package/esm/production/cli/index.mjs +86 -0
- package/esm/production/cli/index.mjs.map +1 -0
- package/esm/production/contracts.d.mts +592 -0
- package/esm/production/contracts.d.mts.map +1 -0
- package/esm/production/contracts.mjs +95 -0
- package/esm/production/contracts.mjs.map +1 -0
- package/esm/production/errors.d.mts +31 -0
- package/esm/production/errors.d.mts.map +1 -0
- package/esm/production/errors.mjs +142 -0
- package/esm/production/errors.mjs.map +1 -0
- package/esm/production/http/access.mjs +124 -0
- package/esm/production/http/access.mjs.map +1 -0
- package/esm/production/http/auth-routes.mjs +280 -0
- package/esm/production/http/auth-routes.mjs.map +1 -0
- package/esm/production/http/client.mjs +57 -0
- package/esm/production/http/client.mjs.map +1 -0
- package/esm/production/http/constants.mjs +11 -0
- package/esm/production/http/constants.mjs.map +1 -0
- package/esm/production/http/context.mjs +14 -0
- package/esm/production/http/context.mjs.map +1 -0
- package/esm/production/http/cookie.mjs +39 -0
- package/esm/production/http/cookie.mjs.map +1 -0
- package/esm/production/http/headers.mjs +25 -0
- package/esm/production/http/headers.mjs.map +1 -0
- package/esm/production/http/index.mjs +10 -0
- package/esm/production/http/ip.mjs +130 -0
- package/esm/production/http/ip.mjs.map +1 -0
- package/esm/production/http/mount.mjs +300 -0
- package/esm/production/http/mount.mjs.map +1 -0
- package/esm/production/http/state.mjs +54 -0
- package/esm/production/http/state.mjs.map +1 -0
- package/esm/production/index.d.mts +6 -0
- package/esm/production/index.mjs +5 -0
- package/esm/production/insights/cap-report.mjs +67 -0
- package/esm/production/insights/cap-report.mjs.map +1 -0
- package/esm/production/insights/health.mjs +88 -0
- package/esm/production/insights/health.mjs.map +1 -0
- package/esm/production/insights/index.mjs +10 -0
- package/esm/production/insights/insights.mjs +167 -0
- package/esm/production/insights/insights.mjs.map +1 -0
- package/esm/production/insights/instance.mjs +24 -0
- package/esm/production/insights/instance.mjs.map +1 -0
- package/esm/production/insights/jobs.mjs +100 -0
- package/esm/production/insights/jobs.mjs.map +1 -0
- package/esm/production/insights/reporter.mjs +59 -0
- package/esm/production/insights/reporter.mjs.map +1 -0
- package/esm/production/insights/resources.mjs +139 -0
- package/esm/production/insights/resources.mjs.map +1 -0
- package/esm/production/insights/writer.mjs +72 -0
- package/esm/production/insights/writer.mjs.map +1 -0
- package/esm/production/openapi.mjs +52 -0
- package/esm/production/openapi.mjs.map +1 -0
- package/esm/production/options.d.mts +60 -0
- package/esm/production/options.d.mts.map +1 -0
- package/esm/production/options.mjs +170 -0
- package/esm/production/options.mjs.map +1 -0
- package/esm/production/stats/histogram.mjs +67 -0
- package/esm/production/stats/histogram.mjs.map +1 -0
- package/esm/production/stats/merge.mjs +106 -0
- package/esm/production/stats/merge.mjs.map +1 -0
- package/esm/production/store/cascade-store.mjs +322 -0
- package/esm/production/store/cascade-store.mjs.map +1 -0
- package/esm/production/store/index.mjs +5 -0
- package/esm/production/store/mapping.mjs +258 -0
- package/esm/production/store/mapping.mjs.map +1 -0
- package/esm/production/store/memory-store.mjs +291 -0
- package/esm/production/store/memory-store.mjs.map +1 -0
- package/esm/production/store/migrations.d.mts +11 -0
- package/esm/production/store/migrations.d.mts.map +1 -0
- package/esm/production/store/migrations.mjs +29 -0
- package/esm/production/store/migrations.mjs.map +1 -0
- package/esm/production/store/models/account.migration.mjs +34 -0
- package/esm/production/store/models/account.migration.mjs.map +1 -0
- package/esm/production/store/models/account.model.mjs +13 -0
- package/esm/production/store/models/account.model.mjs.map +1 -0
- package/esm/production/store/models/audit.migration.mjs +30 -0
- package/esm/production/store/models/audit.migration.mjs.map +1 -0
- package/esm/production/store/models/audit.model.mjs +13 -0
- package/esm/production/store/models/audit.model.mjs.map +1 -0
- package/esm/production/store/models/base.mjs +27 -0
- package/esm/production/store/models/base.mjs.map +1 -0
- package/esm/production/store/models/index.mjs +17 -0
- package/esm/production/store/models/invite.migration.mjs +26 -0
- package/esm/production/store/models/invite.migration.mjs.map +1 -0
- package/esm/production/store/models/invite.model.mjs +13 -0
- package/esm/production/store/models/invite.model.mjs.map +1 -0
- package/esm/production/store/models/report.migration.mjs +20 -0
- package/esm/production/store/models/report.migration.mjs.map +1 -0
- package/esm/production/store/models/report.model.mjs +13 -0
- package/esm/production/store/models/report.model.mjs.map +1 -0
- package/esm/production/store/models/sample.migration.mjs +25 -0
- package/esm/production/store/models/sample.migration.mjs.map +1 -0
- package/esm/production/store/models/sample.model.mjs +13 -0
- package/esm/production/store/models/sample.model.mjs.map +1 -0
- package/esm/production/store/models/session.migration.mjs +31 -0
- package/esm/production/store/models/session.migration.mjs.map +1 -0
- package/esm/production/store/models/session.model.mjs +13 -0
- package/esm/production/store/models/session.model.mjs.map +1 -0
- package/esm/production/store/models/state.migration.mjs +26 -0
- package/esm/production/store/models/state.migration.mjs.map +1 -0
- package/esm/production/store/models/state.model.mjs +13 -0
- package/esm/production/store/models/state.model.mjs.map +1 -0
- package/esm/query-shape.mjs +14 -1
- package/esm/query-shape.mjs.map +1 -1
- package/esm/server/explain-route.mjs +26 -1
- package/esm/server/explain-route.mjs.map +1 -1
- package/esm/server/index.mjs +9 -4
- package/esm/server/index.mjs.map +1 -1
- package/esm/server/insights-routes.mjs +62 -0
- package/esm/server/insights-routes.mjs.map +1 -0
- package/esm/server/log-routes.mjs +32 -5
- package/esm/server/log-routes.mjs.map +1 -1
- package/esm/server/openapi-routes.mjs +3 -2
- package/esm/server/openapi-routes.mjs.map +1 -1
- package/esm/server/requests-routes.mjs +125 -0
- package/esm/server/requests-routes.mjs.map +1 -1
- package/esm/server/session-routes.mjs +42 -0
- package/esm/server/session-routes.mjs.map +1 -0
- package/esm/server/stream-route.mjs +81 -11
- package/esm/server/stream-route.mjs.map +1 -1
- package/esm/server/ui-assets.mjs +34 -25
- package/esm/server/ui-assets.mjs.map +1 -1
- package/esm/sources/log-source.mjs +14 -1
- package/esm/sources/log-source.mjs.map +1 -1
- package/esm/types.d.mts +202 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/ui-root.mjs +9 -4
- package/esm/ui-root.mjs.map +1 -1
- package/llms-full.txt +159 -21
- package/llms.txt +2 -2
- package/package.json +32 -8
- package/skills/SKILL.md +159 -21
- package/ui/dashboard/assets/app.css +3 -0
- package/ui/dashboard/assets/app.js +50 -0
- package/ui/dashboard/build-info.json +21 -0
- package/ui/dashboard/index.html +15 -0
- package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
- package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
- package/cjs/server-B11ShQYE.cjs +0 -628
- package/cjs/server-B11ShQYE.cjs.map +0 -1
- package/cjs/src-Xwm3Eel9.cjs.map +0 -1
- package/ui/app.css +0 -376
- package/ui/app.js +0 -1158
- package/ui/index.html +0 -28
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { rateLimitClient } from "../http/ip.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/devtools/src/production/store/mapping.ts
|
|
4
|
+
/** A number from a column that a driver may return as a string (PostgreSQL `bigint`). */
|
|
5
|
+
function toNumber(value) {
|
|
6
|
+
if (typeof value === "number") return value;
|
|
7
|
+
const parsed = Number(value);
|
|
8
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
9
|
+
}
|
|
10
|
+
/** Like `toNumber`, keeping `null` for a missing value. */
|
|
11
|
+
function toNumberOrNull(value) {
|
|
12
|
+
return value === null || value === void 0 ? null : toNumber(value);
|
|
13
|
+
}
|
|
14
|
+
function toStringOrNull(value) {
|
|
15
|
+
return typeof value === "string" ? value : null;
|
|
16
|
+
}
|
|
17
|
+
function toBoolean(value) {
|
|
18
|
+
return value === true || value === 1 || value === "true" || value === "t";
|
|
19
|
+
}
|
|
20
|
+
/** Parses JSON text; a value a driver already parsed passes through. */
|
|
21
|
+
function parseJson(value, fallback) {
|
|
22
|
+
if (typeof value === "string") try {
|
|
23
|
+
return JSON.parse(value);
|
|
24
|
+
} catch {
|
|
25
|
+
return fallback;
|
|
26
|
+
}
|
|
27
|
+
return value === null || value === void 0 ? fallback : value;
|
|
28
|
+
}
|
|
29
|
+
function toArray(value) {
|
|
30
|
+
const parsed = parseJson(value, []);
|
|
31
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
32
|
+
}
|
|
33
|
+
const ACCOUNT_COLUMNS = {
|
|
34
|
+
email: "email",
|
|
35
|
+
role: "role",
|
|
36
|
+
passwordHash: "password_hash",
|
|
37
|
+
passwordSource: "password_source",
|
|
38
|
+
mustChangePassword: "must_change_password",
|
|
39
|
+
totpSecret: "totp_secret",
|
|
40
|
+
totpEnabledAt: "totp_enabled_at",
|
|
41
|
+
totpLastStep: "totp_last_step",
|
|
42
|
+
recoveryCodes: "recovery_codes",
|
|
43
|
+
passkeys: "passkeys",
|
|
44
|
+
failuresResetAt: "failures_reset_at",
|
|
45
|
+
createdAt: "created_at",
|
|
46
|
+
updatedAt: "updated_at",
|
|
47
|
+
lastLoginAt: "last_login_at",
|
|
48
|
+
createdBy: "created_by",
|
|
49
|
+
version: "version"
|
|
50
|
+
};
|
|
51
|
+
function accountToRow(record) {
|
|
52
|
+
return {
|
|
53
|
+
id: record.id,
|
|
54
|
+
...fieldsToRow(ACCOUNT_COLUMNS, record)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function accountPatchToRow(patch) {
|
|
58
|
+
return fieldsToRow(ACCOUNT_COLUMNS, patch);
|
|
59
|
+
}
|
|
60
|
+
function rowToAccount(row) {
|
|
61
|
+
return {
|
|
62
|
+
id: String(row.id),
|
|
63
|
+
email: String(row.email),
|
|
64
|
+
role: row.role,
|
|
65
|
+
passwordHash: String(row.password_hash),
|
|
66
|
+
passwordSource: row.password_source,
|
|
67
|
+
mustChangePassword: toBoolean(row.must_change_password),
|
|
68
|
+
totpSecret: toStringOrNull(row.totp_secret),
|
|
69
|
+
totpEnabledAt: toNumberOrNull(row.totp_enabled_at),
|
|
70
|
+
totpLastStep: toNumberOrNull(row.totp_last_step),
|
|
71
|
+
recoveryCodes: toArray(row.recovery_codes),
|
|
72
|
+
passkeys: toArray(row.passkeys),
|
|
73
|
+
failuresResetAt: toNumberOrNull(row.failures_reset_at),
|
|
74
|
+
createdAt: toNumber(row.created_at),
|
|
75
|
+
updatedAt: toNumber(row.updated_at),
|
|
76
|
+
lastLoginAt: toNumberOrNull(row.last_login_at),
|
|
77
|
+
createdBy: toStringOrNull(row.created_by),
|
|
78
|
+
version: toNumber(row.version)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const SESSION_COLUMNS = {
|
|
82
|
+
tokenHash: "token_hash",
|
|
83
|
+
accountId: "account_id",
|
|
84
|
+
stage: "stage",
|
|
85
|
+
csrfSecret: "csrf_secret",
|
|
86
|
+
createdAt: "created_at",
|
|
87
|
+
lastSeenAt: "last_seen_at",
|
|
88
|
+
expiresAt: "expires_at",
|
|
89
|
+
ip: "ip",
|
|
90
|
+
userAgent: "user_agent",
|
|
91
|
+
pendingTotpSecret: "pending_totp_secret",
|
|
92
|
+
challenge: "challenge",
|
|
93
|
+
challengeExpiresAt: "challenge_expires_at",
|
|
94
|
+
version: "version"
|
|
95
|
+
};
|
|
96
|
+
function sessionToRow(record) {
|
|
97
|
+
return {
|
|
98
|
+
id: record.id,
|
|
99
|
+
...fieldsToRow(SESSION_COLUMNS, record)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function sessionPatchToRow(patch) {
|
|
103
|
+
return fieldsToRow(SESSION_COLUMNS, patch);
|
|
104
|
+
}
|
|
105
|
+
function rowToSession(row) {
|
|
106
|
+
return {
|
|
107
|
+
id: String(row.id),
|
|
108
|
+
tokenHash: String(row.token_hash),
|
|
109
|
+
accountId: String(row.account_id),
|
|
110
|
+
stage: row.stage,
|
|
111
|
+
csrfSecret: String(row.csrf_secret),
|
|
112
|
+
createdAt: toNumber(row.created_at),
|
|
113
|
+
lastSeenAt: toNumber(row.last_seen_at),
|
|
114
|
+
expiresAt: toNumber(row.expires_at),
|
|
115
|
+
ip: toStringOrNull(row.ip),
|
|
116
|
+
userAgent: toStringOrNull(row.user_agent),
|
|
117
|
+
pendingTotpSecret: toStringOrNull(row.pending_totp_secret),
|
|
118
|
+
challenge: toStringOrNull(row.challenge),
|
|
119
|
+
challengeExpiresAt: toNumberOrNull(row.challenge_expires_at),
|
|
120
|
+
version: toNumber(row.version)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function inviteToRow(record) {
|
|
124
|
+
return {
|
|
125
|
+
id: record.id,
|
|
126
|
+
token_hash: record.tokenHash,
|
|
127
|
+
email: record.email,
|
|
128
|
+
role: record.role,
|
|
129
|
+
created_by: record.createdBy,
|
|
130
|
+
created_at: record.createdAt,
|
|
131
|
+
expires_at: record.expiresAt,
|
|
132
|
+
used_at: record.usedAt,
|
|
133
|
+
account_id: record.accountId
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function rowToInvite(row) {
|
|
137
|
+
return {
|
|
138
|
+
id: String(row.id),
|
|
139
|
+
tokenHash: String(row.token_hash),
|
|
140
|
+
email: String(row.email),
|
|
141
|
+
role: row.role,
|
|
142
|
+
createdBy: toStringOrNull(row.created_by),
|
|
143
|
+
createdAt: toNumber(row.created_at),
|
|
144
|
+
expiresAt: toNumber(row.expires_at),
|
|
145
|
+
usedAt: toNumberOrNull(row.used_at),
|
|
146
|
+
accountId: toStringOrNull(row.account_id)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function auditToRow(entry) {
|
|
150
|
+
return {
|
|
151
|
+
id: entry.id,
|
|
152
|
+
type: entry.type,
|
|
153
|
+
occurred_at: entry.at,
|
|
154
|
+
account_id: entry.accountId,
|
|
155
|
+
email: entry.email,
|
|
156
|
+
ip: entry.ip,
|
|
157
|
+
ip_bucket: entry.ip === null ? null : rateLimitClient(entry.ip),
|
|
158
|
+
user_agent: entry.userAgent,
|
|
159
|
+
detail: entry.detail,
|
|
160
|
+
ref: entry.ref
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function rowToAudit(row) {
|
|
164
|
+
return {
|
|
165
|
+
id: String(row.id),
|
|
166
|
+
at: toNumber(row.occurred_at),
|
|
167
|
+
type: row.type,
|
|
168
|
+
accountId: toStringOrNull(row.account_id),
|
|
169
|
+
email: toStringOrNull(row.email),
|
|
170
|
+
ip: toStringOrNull(row.ip),
|
|
171
|
+
userAgent: toStringOrNull(row.user_agent),
|
|
172
|
+
detail: parseJson(row.detail, {}),
|
|
173
|
+
ref: String(row.ref)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const STATE_COLUMNS = {
|
|
177
|
+
disabled: "disabled",
|
|
178
|
+
disabledPathHash: "disabled_path_hash",
|
|
179
|
+
disabledAt: "disabled_at",
|
|
180
|
+
disabledBy: "disabled_by",
|
|
181
|
+
lockedUntil: "locked_until",
|
|
182
|
+
failuresResetAt: "failures_reset_at",
|
|
183
|
+
updatedAt: "updated_at",
|
|
184
|
+
version: "version"
|
|
185
|
+
};
|
|
186
|
+
function stateToRow(record) {
|
|
187
|
+
return fieldsToRow(STATE_COLUMNS, record);
|
|
188
|
+
}
|
|
189
|
+
function statePatchToRow(patch) {
|
|
190
|
+
return fieldsToRow(STATE_COLUMNS, patch);
|
|
191
|
+
}
|
|
192
|
+
function rowToState(row) {
|
|
193
|
+
return {
|
|
194
|
+
disabled: toBoolean(row.disabled),
|
|
195
|
+
disabledPathHash: toStringOrNull(row.disabled_path_hash),
|
|
196
|
+
disabledAt: toNumberOrNull(row.disabled_at),
|
|
197
|
+
disabledBy: toStringOrNull(row.disabled_by),
|
|
198
|
+
lockedUntil: toNumberOrNull(row.locked_until),
|
|
199
|
+
failuresResetAt: toNumberOrNull(row.failures_reset_at),
|
|
200
|
+
updatedAt: toNumber(row.updated_at),
|
|
201
|
+
version: toNumber(row.version)
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* `detail` is JSON text, not a JSON column: a sample holds keys from request
|
|
206
|
+
* data (headers, query names) and MongoDB rejects or misreads field names
|
|
207
|
+
* that start with `$` or contain dots.
|
|
208
|
+
*/
|
|
209
|
+
function sampleToRow(sample) {
|
|
210
|
+
return {
|
|
211
|
+
id: sample.id,
|
|
212
|
+
instance: sample.instance,
|
|
213
|
+
started_at: sample.startedAt,
|
|
214
|
+
status: sample.summary.status ?? null,
|
|
215
|
+
method: sample.summary.method.toUpperCase(),
|
|
216
|
+
path: sample.summary.path,
|
|
217
|
+
summary: sample.summary,
|
|
218
|
+
detail: sample.detail === null ? null : JSON.stringify(sample.detail)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function rowToSampleSummary(row) {
|
|
222
|
+
return parseJson(row.summary, {});
|
|
223
|
+
}
|
|
224
|
+
function rowToSample(row) {
|
|
225
|
+
const detail = row.detail;
|
|
226
|
+
return {
|
|
227
|
+
id: String(row.id),
|
|
228
|
+
instance: String(row.instance),
|
|
229
|
+
startedAt: toNumber(row.started_at),
|
|
230
|
+
summary: parseJson(row.summary, {}),
|
|
231
|
+
detail: detail === null || detail === void 0 ? null : parseJson(detail, null)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/** `data` is JSON text for the same reason as a sample's `detail`. */
|
|
235
|
+
function reportToRow(report) {
|
|
236
|
+
return {
|
|
237
|
+
id: report.instance.id,
|
|
238
|
+
seen_at: report.at,
|
|
239
|
+
data: JSON.stringify(report)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function rowToReport(row) {
|
|
243
|
+
return parseJson(row.data, {});
|
|
244
|
+
}
|
|
245
|
+
/** Maps the defined fields of `source` to their columns. */
|
|
246
|
+
function fieldsToRow(columns, source) {
|
|
247
|
+
const row = {};
|
|
248
|
+
const values = source;
|
|
249
|
+
for (const [field, column] of Object.entries(columns)) {
|
|
250
|
+
const value = values[field];
|
|
251
|
+
if (value !== void 0) row[column] = value;
|
|
252
|
+
}
|
|
253
|
+
return row;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
//#endregion
|
|
257
|
+
export { accountPatchToRow, accountToRow, auditToRow, inviteToRow, parseJson, reportToRow, rowToAccount, rowToAudit, rowToInvite, rowToReport, rowToSample, rowToSampleSummary, rowToSession, rowToState, sampleToRow, sessionPatchToRow, sessionToRow, statePatchToRow, stateToRow, toBoolean, toNumber, toNumberOrNull, toStringOrNull };
|
|
258
|
+
//# sourceMappingURL=mapping.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/mapping.ts"],"sourcesContent":["import type { DevtoolsAuditEntry, DevtoolsInstanceReport } from \"../contracts\";\nimport { rateLimitClient } from \"../http/ip\";\nimport type {\n DevtoolsAccountPatch,\n DevtoolsAccountRecord,\n DevtoolsInviteRecord,\n DevtoolsPasskeyRecord,\n DevtoolsSessionPatch,\n DevtoolsSessionRecord,\n DevtoolsStatePatch,\n DevtoolsStateRecord,\n DevtoolsStoredSample,\n} from \"./types\";\n\n/**\n * The record <-> row mapping of the cascade store. Rows use snake_case column\n * names; times are epoch milliseconds in integer columns on every driver.\n * Pure functions, so they are tested without a database.\n */\nexport type Row = Record<string, unknown>;\n\n/** A number from a column that a driver may return as a string (PostgreSQL `bigint`). */\nexport function toNumber(value: unknown): number {\n if (typeof value === \"number\") return value;\n\n const parsed = Number(value);\n\n return Number.isFinite(parsed) ? parsed : 0;\n}\n\n/** Like `toNumber`, keeping `null` for a missing value. */\nexport function toNumberOrNull(value: unknown): number | null {\n return value === null || value === undefined ? null : toNumber(value);\n}\n\nexport function toStringOrNull(value: unknown): string | null {\n return typeof value === \"string\" ? value : null;\n}\n\nexport function toBoolean(value: unknown): boolean {\n return value === true || value === 1 || value === \"true\" || value === \"t\";\n}\n\n/** Parses JSON text; a value a driver already parsed passes through. */\nexport function parseJson<T>(value: unknown, fallback: T): T {\n if (typeof value === \"string\") {\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n }\n\n return value === null || value === undefined ? fallback : (value as T);\n}\n\nfunction toArray<T>(value: unknown): T[] {\n const parsed = parseJson<unknown>(value, []);\n\n return Array.isArray(parsed) ? (parsed as T[]) : [];\n}\n\n// ---------------------------------------------------------------------------\n// Accounts\n// ---------------------------------------------------------------------------\n\nconst ACCOUNT_COLUMNS = {\n email: \"email\",\n role: \"role\",\n passwordHash: \"password_hash\",\n passwordSource: \"password_source\",\n mustChangePassword: \"must_change_password\",\n totpSecret: \"totp_secret\",\n totpEnabledAt: \"totp_enabled_at\",\n totpLastStep: \"totp_last_step\",\n recoveryCodes: \"recovery_codes\",\n passkeys: \"passkeys\",\n failuresResetAt: \"failures_reset_at\",\n createdAt: \"created_at\",\n updatedAt: \"updated_at\",\n lastLoginAt: \"last_login_at\",\n createdBy: \"created_by\",\n version: \"version\",\n} as const satisfies Record<keyof Omit<DevtoolsAccountRecord, \"id\">, string>;\n\nexport function accountToRow(record: DevtoolsAccountRecord): Row {\n return { id: record.id, ...fieldsToRow(ACCOUNT_COLUMNS, record) };\n}\n\nexport function accountPatchToRow(patch: DevtoolsAccountPatch): Row {\n return fieldsToRow(ACCOUNT_COLUMNS, patch);\n}\n\nexport function rowToAccount(row: Row): DevtoolsAccountRecord {\n return {\n id: String(row.id),\n email: String(row.email),\n role: row.role as DevtoolsAccountRecord[\"role\"],\n passwordHash: String(row.password_hash),\n passwordSource: row.password_source as DevtoolsAccountRecord[\"passwordSource\"],\n mustChangePassword: toBoolean(row.must_change_password),\n totpSecret: toStringOrNull(row.totp_secret),\n totpEnabledAt: toNumberOrNull(row.totp_enabled_at),\n totpLastStep: toNumberOrNull(row.totp_last_step),\n recoveryCodes: toArray<string>(row.recovery_codes),\n passkeys: toArray<DevtoolsPasskeyRecord>(row.passkeys),\n failuresResetAt: toNumberOrNull(row.failures_reset_at),\n createdAt: toNumber(row.created_at),\n updatedAt: toNumber(row.updated_at),\n lastLoginAt: toNumberOrNull(row.last_login_at),\n createdBy: toStringOrNull(row.created_by),\n version: toNumber(row.version),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Sessions\n// ---------------------------------------------------------------------------\n\nconst SESSION_COLUMNS = {\n tokenHash: \"token_hash\",\n accountId: \"account_id\",\n stage: \"stage\",\n csrfSecret: \"csrf_secret\",\n createdAt: \"created_at\",\n lastSeenAt: \"last_seen_at\",\n expiresAt: \"expires_at\",\n ip: \"ip\",\n userAgent: \"user_agent\",\n pendingTotpSecret: \"pending_totp_secret\",\n challenge: \"challenge\",\n challengeExpiresAt: \"challenge_expires_at\",\n version: \"version\",\n} as const satisfies Record<keyof Omit<DevtoolsSessionRecord, \"id\">, string>;\n\nexport function sessionToRow(record: DevtoolsSessionRecord): Row {\n return { id: record.id, ...fieldsToRow(SESSION_COLUMNS, record) };\n}\n\nexport function sessionPatchToRow(patch: DevtoolsSessionPatch): Row {\n return fieldsToRow(SESSION_COLUMNS, patch);\n}\n\nexport function rowToSession(row: Row): DevtoolsSessionRecord {\n return {\n id: String(row.id),\n tokenHash: String(row.token_hash),\n accountId: String(row.account_id),\n stage: row.stage as DevtoolsSessionRecord[\"stage\"],\n csrfSecret: String(row.csrf_secret),\n createdAt: toNumber(row.created_at),\n lastSeenAt: toNumber(row.last_seen_at),\n expiresAt: toNumber(row.expires_at),\n ip: toStringOrNull(row.ip),\n userAgent: toStringOrNull(row.user_agent),\n pendingTotpSecret: toStringOrNull(row.pending_totp_secret),\n challenge: toStringOrNull(row.challenge),\n challengeExpiresAt: toNumberOrNull(row.challenge_expires_at),\n version: toNumber(row.version),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Invites\n// ---------------------------------------------------------------------------\n\nexport function inviteToRow(record: DevtoolsInviteRecord): Row {\n return {\n id: record.id,\n token_hash: record.tokenHash,\n email: record.email,\n role: record.role,\n created_by: record.createdBy,\n created_at: record.createdAt,\n expires_at: record.expiresAt,\n used_at: record.usedAt,\n account_id: record.accountId,\n };\n}\n\nexport function rowToInvite(row: Row): DevtoolsInviteRecord {\n return {\n id: String(row.id),\n tokenHash: String(row.token_hash),\n email: String(row.email),\n role: row.role as DevtoolsInviteRecord[\"role\"],\n createdBy: toStringOrNull(row.created_by),\n createdAt: toNumber(row.created_at),\n expiresAt: toNumber(row.expires_at),\n usedAt: toNumberOrNull(row.used_at),\n accountId: toStringOrNull(row.account_id),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Audit\n// ---------------------------------------------------------------------------\n\nexport function auditToRow(entry: DevtoolsAuditEntry): Row {\n return {\n id: entry.id,\n type: entry.type,\n occurred_at: entry.at,\n account_id: entry.accountId,\n email: entry.email,\n ip: entry.ip,\n // What the per-IP limit counts by: the address, or its /64 for IPv6.\n ip_bucket: entry.ip === null ? null : rateLimitClient(entry.ip),\n user_agent: entry.userAgent,\n detail: entry.detail,\n ref: entry.ref,\n };\n}\n\nexport function rowToAudit(row: Row): DevtoolsAuditEntry {\n return {\n id: String(row.id),\n at: toNumber(row.occurred_at),\n type: row.type as DevtoolsAuditEntry[\"type\"],\n accountId: toStringOrNull(row.account_id),\n email: toStringOrNull(row.email),\n ip: toStringOrNull(row.ip),\n userAgent: toStringOrNull(row.user_agent),\n detail: parseJson<DevtoolsAuditEntry[\"detail\"]>(row.detail, {}),\n ref: String(row.ref),\n };\n}\n\n// ---------------------------------------------------------------------------\n// State\n// ---------------------------------------------------------------------------\n\nconst STATE_COLUMNS = {\n disabled: \"disabled\",\n disabledPathHash: \"disabled_path_hash\",\n disabledAt: \"disabled_at\",\n disabledBy: \"disabled_by\",\n lockedUntil: \"locked_until\",\n failuresResetAt: \"failures_reset_at\",\n updatedAt: \"updated_at\",\n version: \"version\",\n} as const satisfies Record<keyof DevtoolsStateRecord, string>;\n\nexport function stateToRow(record: DevtoolsStateRecord): Row {\n return fieldsToRow(STATE_COLUMNS, record);\n}\n\nexport function statePatchToRow(patch: DevtoolsStatePatch): Row {\n return fieldsToRow(STATE_COLUMNS, patch);\n}\n\nexport function rowToState(row: Row): DevtoolsStateRecord {\n return {\n disabled: toBoolean(row.disabled),\n disabledPathHash: toStringOrNull(row.disabled_path_hash),\n disabledAt: toNumberOrNull(row.disabled_at),\n disabledBy: toStringOrNull(row.disabled_by),\n lockedUntil: toNumberOrNull(row.locked_until),\n failuresResetAt: toNumberOrNull(row.failures_reset_at),\n updatedAt: toNumber(row.updated_at),\n version: toNumber(row.version),\n };\n}\n\n// ---------------------------------------------------------------------------\n// Samples and reports\n// ---------------------------------------------------------------------------\n\n/**\n * `detail` is JSON text, not a JSON column: a sample holds keys from request\n * data (headers, query names) and MongoDB rejects or misreads field names\n * that start with `$` or contain dots.\n */\nexport function sampleToRow(sample: DevtoolsStoredSample): Row {\n return {\n id: sample.id,\n instance: sample.instance,\n started_at: sample.startedAt,\n status: sample.summary.status ?? null,\n method: sample.summary.method.toUpperCase(),\n path: sample.summary.path,\n summary: sample.summary,\n detail: sample.detail === null ? null : JSON.stringify(sample.detail),\n };\n}\n\nexport function rowToSampleSummary(row: Row): DevtoolsStoredSample[\"summary\"] {\n return parseJson<DevtoolsStoredSample[\"summary\"]>(row.summary, {} as never);\n}\n\nexport function rowToSample(row: Row): DevtoolsStoredSample {\n const detail = row.detail;\n\n return {\n id: String(row.id),\n instance: String(row.instance),\n startedAt: toNumber(row.started_at),\n summary: parseJson<DevtoolsStoredSample[\"summary\"]>(row.summary, {} as never),\n detail:\n detail === null || detail === undefined\n ? null\n : parseJson<DevtoolsStoredSample[\"detail\"]>(detail, null),\n };\n}\n\n/** `data` is JSON text for the same reason as a sample's `detail`. */\nexport function reportToRow(report: DevtoolsInstanceReport): Row {\n return {\n id: report.instance.id,\n seen_at: report.at,\n data: JSON.stringify(report),\n };\n}\n\nexport function rowToReport(row: Row): DevtoolsInstanceReport {\n return parseJson<DevtoolsInstanceReport>(row.data, {} as never);\n}\n\n// ---------------------------------------------------------------------------\n\n/** Maps the defined fields of `source` to their columns. */\nfunction fieldsToRow(columns: Record<string, string>, source: object): Row {\n const row: Row = {};\n const values = source as Record<string, unknown>;\n\n for (const [field, column] of Object.entries(columns)) {\n const value = values[field];\n\n if (value !== undefined) row[column] = value;\n }\n\n return row;\n}\n"],"mappings":";;;;AAsBA,SAAgB,SAAS,OAAwB;CAC/C,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,MAAM,SAAS,OAAO,KAAK;CAE3B,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS;AAC5C;;AAGA,SAAgB,eAAe,OAA+B;CAC5D,OAAO,UAAU,QAAQ,UAAU,SAAY,OAAO,SAAS,KAAK;AACtE;AAEA,SAAgB,eAAe,OAA+B;CAC5D,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAgB,UAAU,OAAyB;CACjD,OAAO,UAAU,QAAQ,UAAU,KAAK,UAAU,UAAU,UAAU;AACxE;;AAGA,SAAgB,UAAa,OAAgB,UAAgB;CAC3D,IAAI,OAAO,UAAU,UACnB,IAAI;EACF,OAAO,KAAK,MAAM,KAAK;CACzB,QAAQ;EACN,OAAO;CACT;CAGF,OAAO,UAAU,QAAQ,UAAU,SAAY,WAAY;AAC7D;AAEA,SAAS,QAAW,OAAqB;CACvC,MAAM,SAAS,UAAmB,OAAO,CAAC,CAAC;CAE3C,OAAO,MAAM,QAAQ,MAAM,IAAK,SAAiB,CAAC;AACpD;AAMA,MAAM,kBAAkB;CACtB,OAAO;CACP,MAAM;CACN,cAAc;CACd,gBAAgB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SAAS,CAAC,CAAU;AAC5E;AAEA,SAAgB,YAAY,KAAgC;CAC1D,MAAM,SAAS,IAAI;CAEnB,OAAO;EACL,IAAI,OAAO,IAAI,EAAE;EACjB,UAAU,OAAO,IAAI,QAAQ;EAC7B,WAAW,SAAS,IAAI,UAAU;EAClC,SAAS,UAA2C,IAAI,SAAS,CAAC,CAAU;EAC5E,QACE,WAAW,QAAQ,WAAW,SAC1B,OACA,UAA0C,QAAQ,IAAI;CAC9D;AACF;;AAGA,SAAgB,YAAY,QAAqC;CAC/D,OAAO;EACL,IAAI,OAAO,SAAS;EACpB,SAAS,OAAO;EAChB,MAAM,KAAK,UAAU,MAAM;CAC7B;AACF;AAEA,SAAgB,YAAY,KAAkC;CAC5D,OAAO,UAAkC,IAAI,MAAM,CAAC,CAAU;AAChE;;AAKA,SAAS,YAAY,SAAiC,QAAqB;CACzE,MAAM,MAAW,CAAC;CAClB,MAAM,SAAS;CAEf,KAAK,MAAM,CAAC,OAAO,WAAW,OAAO,QAAQ,OAAO,GAAG;EACrD,MAAM,QAAQ,OAAO;EAErB,IAAI,UAAU,QAAW,IAAI,UAAU;CACzC;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { DevtoolsStoreConflictError } from "../errors.mjs";
|
|
2
|
+
import { rateLimitClient } from "../http/ip.mjs";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
|
|
5
|
+
//#region ../../packages/devtools/src/production/store/memory-store.ts
|
|
6
|
+
/** A structural copy, so callers never hold the store's own objects. */
|
|
7
|
+
function copy(value) {
|
|
8
|
+
return structuredClone(value);
|
|
9
|
+
}
|
|
10
|
+
/** The state row before anything was written. */
|
|
11
|
+
function defaultStateRecord(now = 0) {
|
|
12
|
+
return {
|
|
13
|
+
disabled: false,
|
|
14
|
+
disabledPathHash: null,
|
|
15
|
+
disabledAt: null,
|
|
16
|
+
disabledBy: null,
|
|
17
|
+
lockedUntil: null,
|
|
18
|
+
failuresResetAt: null,
|
|
19
|
+
updatedAt: now,
|
|
20
|
+
version: 0
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Whether `status` matches a sample filter value: `"5xx"`, `"4xx"`, `"404"`. */
|
|
24
|
+
function sampleStatusMatches(filter, status) {
|
|
25
|
+
if (status === void 0) return false;
|
|
26
|
+
const value = filter.trim().toLowerCase();
|
|
27
|
+
if (/^[1-5]xx$/.test(value)) return Math.floor(status / 100) === Number(value[0]);
|
|
28
|
+
return String(status) === value;
|
|
29
|
+
}
|
|
30
|
+
/** Whether a sample summary passes `filter` (everything but `limit`). */
|
|
31
|
+
function sampleMatches(summary, filter) {
|
|
32
|
+
if (filter.status !== void 0 && !sampleStatusMatches(filter.status, summary.status)) return false;
|
|
33
|
+
if (filter.method !== void 0 && summary.method.toUpperCase() !== filter.method.toUpperCase()) return false;
|
|
34
|
+
if (filter.route !== void 0) {
|
|
35
|
+
const needle = filter.route.toLowerCase();
|
|
36
|
+
if (!`${summary.route ?? ""} ${summary.path}`.toLowerCase().includes(needle)) return false;
|
|
37
|
+
}
|
|
38
|
+
if (filter.q !== void 0 && !summary.path.toLowerCase().includes(filter.q.toLowerCase())) return false;
|
|
39
|
+
if (filter.since !== void 0 && summary.startedAt < filter.since) return false;
|
|
40
|
+
if (filter.until !== void 0 && summary.startedAt > filter.until) return false;
|
|
41
|
+
if (filter.instance !== void 0 && summary.instance !== filter.instance) return false;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* An in-process `DevtoolsStore` for specs (and nothing else: it is neither
|
|
46
|
+
* shared between processes nor kept across restarts). It follows the store
|
|
47
|
+
* contract exactly, compare-and-set included, so a spec written against it
|
|
48
|
+
* holds for the database store too.
|
|
49
|
+
*
|
|
50
|
+
* `now` is read for `updatedAt` stamps; pass a fake clock in specs.
|
|
51
|
+
*/
|
|
52
|
+
function createMemoryStore(options = {}) {
|
|
53
|
+
const now = options.now ?? Date.now;
|
|
54
|
+
const accounts = /* @__PURE__ */ new Map();
|
|
55
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
56
|
+
const invites = /* @__PURE__ */ new Map();
|
|
57
|
+
const audit = [];
|
|
58
|
+
const samples = /* @__PURE__ */ new Map();
|
|
59
|
+
const reports = /* @__PURE__ */ new Map();
|
|
60
|
+
let state = null;
|
|
61
|
+
return {
|
|
62
|
+
async verify() {},
|
|
63
|
+
accounts: {
|
|
64
|
+
async findByEmail(email) {
|
|
65
|
+
for (const account of accounts.values()) if (account.email === email) return copy(account);
|
|
66
|
+
return null;
|
|
67
|
+
},
|
|
68
|
+
async findById(id) {
|
|
69
|
+
const account = accounts.get(id);
|
|
70
|
+
return account ? copy(account) : null;
|
|
71
|
+
},
|
|
72
|
+
async list() {
|
|
73
|
+
return [...accounts.values()].sort((a, b) => a.createdAt - b.createdAt).map(copy);
|
|
74
|
+
},
|
|
75
|
+
async countAdmins() {
|
|
76
|
+
return [...accounts.values()].filter((account) => account.role === "admin").length;
|
|
77
|
+
},
|
|
78
|
+
async create(input) {
|
|
79
|
+
for (const account of accounts.values()) if (account.email === input.email) throw new DevtoolsStoreConflictError("email");
|
|
80
|
+
const at = now();
|
|
81
|
+
const record = {
|
|
82
|
+
...copy(input),
|
|
83
|
+
id: randomUUID(),
|
|
84
|
+
createdAt: at,
|
|
85
|
+
updatedAt: at,
|
|
86
|
+
version: 1
|
|
87
|
+
};
|
|
88
|
+
accounts.set(record.id, record);
|
|
89
|
+
return copy(record);
|
|
90
|
+
},
|
|
91
|
+
async update(id, expectedVersion, patch) {
|
|
92
|
+
const current = accounts.get(id);
|
|
93
|
+
if (!current || current.version !== expectedVersion) return null;
|
|
94
|
+
if (patch.email !== void 0 && patch.email !== current.email) {
|
|
95
|
+
for (const account of accounts.values()) if (account.email === patch.email) throw new DevtoolsStoreConflictError("email");
|
|
96
|
+
}
|
|
97
|
+
const next = {
|
|
98
|
+
...current,
|
|
99
|
+
...copy(patch),
|
|
100
|
+
id,
|
|
101
|
+
createdAt: current.createdAt,
|
|
102
|
+
updatedAt: now(),
|
|
103
|
+
version: current.version + 1
|
|
104
|
+
};
|
|
105
|
+
accounts.set(id, next);
|
|
106
|
+
return copy(next);
|
|
107
|
+
},
|
|
108
|
+
async remove(id) {
|
|
109
|
+
return accounts.delete(id);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
sessions: {
|
|
113
|
+
async create(input) {
|
|
114
|
+
const record = {
|
|
115
|
+
...copy(input),
|
|
116
|
+
id: randomUUID(),
|
|
117
|
+
version: 1
|
|
118
|
+
};
|
|
119
|
+
sessions.set(record.id, record);
|
|
120
|
+
return copy(record);
|
|
121
|
+
},
|
|
122
|
+
async findByTokenHash(tokenHash) {
|
|
123
|
+
for (const session of sessions.values()) if (session.tokenHash === tokenHash) return copy(session);
|
|
124
|
+
return null;
|
|
125
|
+
},
|
|
126
|
+
async listForAccount(accountId) {
|
|
127
|
+
return [...sessions.values()].filter((session) => session.accountId === accountId).sort((a, b) => b.createdAt - a.createdAt).map(copy);
|
|
128
|
+
},
|
|
129
|
+
async update(id, expectedVersion, patch) {
|
|
130
|
+
const current = sessions.get(id);
|
|
131
|
+
if (!current || current.version !== expectedVersion) return null;
|
|
132
|
+
const next = {
|
|
133
|
+
...current,
|
|
134
|
+
...copy(patch),
|
|
135
|
+
id,
|
|
136
|
+
accountId: current.accountId,
|
|
137
|
+
version: current.version + 1
|
|
138
|
+
};
|
|
139
|
+
sessions.set(id, next);
|
|
140
|
+
return copy(next);
|
|
141
|
+
},
|
|
142
|
+
async remove(id) {
|
|
143
|
+
return sessions.delete(id);
|
|
144
|
+
},
|
|
145
|
+
async removeForAccount(accountId, exceptId) {
|
|
146
|
+
let removed = 0;
|
|
147
|
+
for (const session of [...sessions.values()]) if (session.accountId === accountId && session.id !== exceptId) {
|
|
148
|
+
sessions.delete(session.id);
|
|
149
|
+
removed++;
|
|
150
|
+
}
|
|
151
|
+
return removed;
|
|
152
|
+
},
|
|
153
|
+
async removeExpired(at) {
|
|
154
|
+
let removed = 0;
|
|
155
|
+
for (const session of [...sessions.values()]) if (session.expiresAt < at) {
|
|
156
|
+
sessions.delete(session.id);
|
|
157
|
+
removed++;
|
|
158
|
+
}
|
|
159
|
+
return removed;
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
invites: {
|
|
163
|
+
async create(input) {
|
|
164
|
+
const record = {
|
|
165
|
+
...copy(input),
|
|
166
|
+
id: randomUUID(),
|
|
167
|
+
usedAt: null,
|
|
168
|
+
accountId: null
|
|
169
|
+
};
|
|
170
|
+
invites.set(record.id, record);
|
|
171
|
+
return copy(record);
|
|
172
|
+
},
|
|
173
|
+
async findByTokenHash(tokenHash) {
|
|
174
|
+
for (const invite of invites.values()) if (invite.tokenHash === tokenHash) return copy(invite);
|
|
175
|
+
return null;
|
|
176
|
+
},
|
|
177
|
+
async list(listOptions = {}) {
|
|
178
|
+
return [...invites.values()].filter((invite) => listOptions.includeUsed === true || invite.usedAt === null).sort((a, b) => b.createdAt - a.createdAt).map(copy);
|
|
179
|
+
},
|
|
180
|
+
async markUsed(id, at, accountId) {
|
|
181
|
+
const invite = invites.get(id);
|
|
182
|
+
if (!invite || invite.usedAt !== null || at >= invite.expiresAt) return false;
|
|
183
|
+
invites.set(id, {
|
|
184
|
+
...invite,
|
|
185
|
+
usedAt: at,
|
|
186
|
+
accountId
|
|
187
|
+
});
|
|
188
|
+
return true;
|
|
189
|
+
},
|
|
190
|
+
async remove(id) {
|
|
191
|
+
return invites.delete(id);
|
|
192
|
+
},
|
|
193
|
+
async removeExpired(at) {
|
|
194
|
+
let removed = 0;
|
|
195
|
+
for (const invite of [...invites.values()]) if (invite.usedAt === null && invite.expiresAt < at) {
|
|
196
|
+
invites.delete(invite.id);
|
|
197
|
+
removed++;
|
|
198
|
+
}
|
|
199
|
+
return removed;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
audit: {
|
|
203
|
+
async append(entry) {
|
|
204
|
+
const record = {
|
|
205
|
+
...copy(entry),
|
|
206
|
+
id: randomUUID()
|
|
207
|
+
};
|
|
208
|
+
audit.push(record);
|
|
209
|
+
return copy(record);
|
|
210
|
+
},
|
|
211
|
+
async list(filter) {
|
|
212
|
+
const limit = Math.max(1, Math.min(500, filter.limit));
|
|
213
|
+
return audit.filter((entry) => (filter.types === void 0 || filter.types.includes(entry.type)) && (filter.accountId === void 0 || entry.accountId === filter.accountId) && (filter.before === void 0 || entry.at < filter.before)).sort((a, b) => b.at - a.at).slice(0, limit).map(copy);
|
|
214
|
+
},
|
|
215
|
+
async count(filter) {
|
|
216
|
+
return audit.filter((entry) => filter.types.includes(entry.type) && entry.at >= filter.since && (filter.accountId === void 0 || entry.accountId === filter.accountId) && (filter.ip === void 0 || entry.ip !== null && rateLimitClient(entry.ip) === rateLimitClient(filter.ip))).length;
|
|
217
|
+
},
|
|
218
|
+
async prune(before) {
|
|
219
|
+
const kept = audit.filter((entry) => entry.at >= before);
|
|
220
|
+
const removed = audit.length - kept.length;
|
|
221
|
+
audit.splice(0, audit.length, ...kept);
|
|
222
|
+
return removed;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
state: {
|
|
226
|
+
async read() {
|
|
227
|
+
return copy(state ?? defaultStateRecord(now()));
|
|
228
|
+
},
|
|
229
|
+
async update(expectedVersion, patch) {
|
|
230
|
+
const current = state ?? defaultStateRecord(now());
|
|
231
|
+
if (current.version !== expectedVersion) return null;
|
|
232
|
+
state = {
|
|
233
|
+
...current,
|
|
234
|
+
...copy(patch),
|
|
235
|
+
updatedAt: now(),
|
|
236
|
+
version: current.version + 1
|
|
237
|
+
};
|
|
238
|
+
return copy(state);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
samples: {
|
|
242
|
+
async insert(list) {
|
|
243
|
+
for (const sample of list) samples.set(sample.id, copy(sample));
|
|
244
|
+
},
|
|
245
|
+
async list(filter) {
|
|
246
|
+
const limit = Math.max(1, Math.min(1e3, filter.limit));
|
|
247
|
+
return [...samples.values()].map((sample) => sample.summary).filter((summary) => sampleMatches(summary, filter)).sort((a, b) => b.startedAt - a.startedAt).slice(0, limit).map(copy);
|
|
248
|
+
},
|
|
249
|
+
async get(id) {
|
|
250
|
+
const sample = samples.get(id);
|
|
251
|
+
return sample ? copy(sample) : null;
|
|
252
|
+
},
|
|
253
|
+
async prune(before) {
|
|
254
|
+
let removed = 0;
|
|
255
|
+
for (const sample of [...samples.values()]) if (sample.startedAt < before) {
|
|
256
|
+
samples.delete(sample.id);
|
|
257
|
+
removed++;
|
|
258
|
+
}
|
|
259
|
+
return removed;
|
|
260
|
+
},
|
|
261
|
+
async clear() {
|
|
262
|
+
const removed = samples.size;
|
|
263
|
+
samples.clear();
|
|
264
|
+
return removed;
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
reports: {
|
|
268
|
+
async write(report) {
|
|
269
|
+
reports.set(report.instance.id, copy(report));
|
|
270
|
+
},
|
|
271
|
+
async list(seenSince) {
|
|
272
|
+
return [...reports.values()].filter((report) => report.at >= seenSince).sort((a, b) => b.at - a.at).map(copy);
|
|
273
|
+
},
|
|
274
|
+
async prune(seenBefore) {
|
|
275
|
+
let removed = 0;
|
|
276
|
+
for (const report of [...reports.values()]) if (report.at < seenBefore) {
|
|
277
|
+
reports.delete(report.instance.id);
|
|
278
|
+
removed++;
|
|
279
|
+
}
|
|
280
|
+
return removed;
|
|
281
|
+
},
|
|
282
|
+
async remove(instanceId) {
|
|
283
|
+
return reports.delete(instanceId);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
//#endregion
|
|
290
|
+
export { createMemoryStore, defaultStateRecord, sampleMatches, sampleStatusMatches };
|
|
291
|
+
//# sourceMappingURL=memory-store.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/memory-store.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n DevtoolsAuditEntry,\n DevtoolsInstanceReport,\n DevtoolsSampleSummary,\n} from \"../contracts\";\nimport { DevtoolsStoreConflictError } from \"../errors\";\nimport { rateLimitClient } from \"../http/ip\";\nimport type {\n DevtoolsAccountRecord,\n DevtoolsInviteRecord,\n DevtoolsSampleFilter,\n DevtoolsSessionRecord,\n DevtoolsStateRecord,\n DevtoolsStore,\n DevtoolsStoredSample,\n} from \"./types\";\n\n/** A structural copy, so callers never hold the store's own objects. */\nfunction copy<T>(value: T): T {\n return structuredClone(value);\n}\n\n/** The state row before anything was written. */\nexport function defaultStateRecord(now = 0): DevtoolsStateRecord {\n return {\n disabled: false,\n disabledPathHash: null,\n disabledAt: null,\n disabledBy: null,\n lockedUntil: null,\n failuresResetAt: null,\n updatedAt: now,\n version: 0,\n };\n}\n\n/** Whether `status` matches a sample filter value: `\"5xx\"`, `\"4xx\"`, `\"404\"`. */\nexport function sampleStatusMatches(filter: string, status: number | undefined): boolean {\n if (status === undefined) return false;\n\n const value = filter.trim().toLowerCase();\n\n if (/^[1-5]xx$/.test(value)) return Math.floor(status / 100) === Number(value[0]);\n\n return String(status) === value;\n}\n\n/** Whether a sample summary passes `filter` (everything but `limit`). */\nexport function sampleMatches(\n summary: DevtoolsSampleSummary,\n filter: DevtoolsSampleFilter,\n): boolean {\n if (filter.status !== undefined && !sampleStatusMatches(filter.status, summary.status))\n return false;\n if (filter.method !== undefined && summary.method.toUpperCase() !== filter.method.toUpperCase()) {\n return false;\n }\n\n if (filter.route !== undefined) {\n const needle = filter.route.toLowerCase();\n const haystack = `${summary.route ?? \"\"} ${summary.path}`.toLowerCase();\n\n if (!haystack.includes(needle)) return false;\n }\n\n if (filter.q !== undefined && !summary.path.toLowerCase().includes(filter.q.toLowerCase())) {\n return false;\n }\n\n if (filter.since !== undefined && summary.startedAt < filter.since) return false;\n if (filter.until !== undefined && summary.startedAt > filter.until) return false;\n if (filter.instance !== undefined && summary.instance !== filter.instance) return false;\n\n return true;\n}\n\n/**\n * An in-process `DevtoolsStore` for specs (and nothing else: it is neither\n * shared between processes nor kept across restarts). It follows the store\n * contract exactly, compare-and-set included, so a spec written against it\n * holds for the database store too.\n *\n * `now` is read for `updatedAt` stamps; pass a fake clock in specs.\n */\nexport function createMemoryStore(options: { now?: () => number } = {}): DevtoolsStore {\n const now = options.now ?? Date.now;\n const accounts = new Map<string, DevtoolsAccountRecord>();\n const sessions = new Map<string, DevtoolsSessionRecord>();\n const invites = new Map<string, DevtoolsInviteRecord>();\n const audit: DevtoolsAuditEntry[] = [];\n const samples = new Map<string, DevtoolsStoredSample>();\n const reports = new Map<string, DevtoolsInstanceReport>();\n let state: DevtoolsStateRecord | null = null;\n\n return {\n async verify() {},\n\n accounts: {\n async findByEmail(email) {\n for (const account of accounts.values()) {\n if (account.email === email) return copy(account);\n }\n\n return null;\n },\n async findById(id) {\n const account = accounts.get(id);\n\n return account ? copy(account) : null;\n },\n async list() {\n return [...accounts.values()].sort((a, b) => a.createdAt - b.createdAt).map(copy);\n },\n async countAdmins() {\n return [...accounts.values()].filter((account) => account.role === \"admin\").length;\n },\n async create(input) {\n for (const account of accounts.values()) {\n if (account.email === input.email) throw new DevtoolsStoreConflictError(\"email\");\n }\n\n const at = now();\n const record: DevtoolsAccountRecord = {\n ...copy(input),\n id: randomUUID(),\n createdAt: at,\n updatedAt: at,\n version: 1,\n };\n\n accounts.set(record.id, record);\n\n return copy(record);\n },\n async update(id, expectedVersion, patch) {\n const current = accounts.get(id);\n\n if (!current || current.version !== expectedVersion) return null;\n\n if (patch.email !== undefined && patch.email !== current.email) {\n for (const account of accounts.values()) {\n if (account.email === patch.email) throw new DevtoolsStoreConflictError(\"email\");\n }\n }\n\n const next: DevtoolsAccountRecord = {\n ...current,\n ...copy(patch),\n id,\n createdAt: current.createdAt,\n updatedAt: now(),\n version: current.version + 1,\n };\n\n accounts.set(id, next);\n\n return copy(next);\n },\n async remove(id) {\n return accounts.delete(id);\n },\n },\n\n sessions: {\n async create(input) {\n const record: DevtoolsSessionRecord = { ...copy(input), id: randomUUID(), version: 1 };\n\n sessions.set(record.id, record);\n\n return copy(record);\n },\n async findByTokenHash(tokenHash) {\n for (const session of sessions.values()) {\n if (session.tokenHash === tokenHash) return copy(session);\n }\n\n return null;\n },\n async listForAccount(accountId) {\n return [...sessions.values()]\n .filter((session) => session.accountId === accountId)\n .sort((a, b) => b.createdAt - a.createdAt)\n .map(copy);\n },\n async update(id, expectedVersion, patch) {\n const current = sessions.get(id);\n\n if (!current || current.version !== expectedVersion) return null;\n\n const next: DevtoolsSessionRecord = {\n ...current,\n ...copy(patch),\n id,\n accountId: current.accountId,\n version: current.version + 1,\n };\n\n sessions.set(id, next);\n\n return copy(next);\n },\n async remove(id) {\n return sessions.delete(id);\n },\n async removeForAccount(accountId, exceptId) {\n let removed = 0;\n\n for (const session of [...sessions.values()]) {\n if (session.accountId === accountId && session.id !== exceptId) {\n sessions.delete(session.id);\n removed++;\n }\n }\n\n return removed;\n },\n async removeExpired(at) {\n let removed = 0;\n\n for (const session of [...sessions.values()]) {\n if (session.expiresAt < at) {\n sessions.delete(session.id);\n removed++;\n }\n }\n\n return removed;\n },\n },\n\n invites: {\n async create(input) {\n const record: DevtoolsInviteRecord = {\n ...copy(input),\n id: randomUUID(),\n usedAt: null,\n accountId: null,\n };\n\n invites.set(record.id, record);\n\n return copy(record);\n },\n async findByTokenHash(tokenHash) {\n for (const invite of invites.values()) {\n if (invite.tokenHash === tokenHash) return copy(invite);\n }\n\n return null;\n },\n async list(listOptions = {}) {\n return [...invites.values()]\n .filter((invite) => listOptions.includeUsed === true || invite.usedAt === null)\n .sort((a, b) => b.createdAt - a.createdAt)\n .map(copy);\n },\n async markUsed(id, at, accountId) {\n const invite = invites.get(id);\n\n if (!invite || invite.usedAt !== null || at >= invite.expiresAt) return false;\n\n invites.set(id, { ...invite, usedAt: at, accountId });\n\n return true;\n },\n async remove(id) {\n return invites.delete(id);\n },\n async removeExpired(at) {\n let removed = 0;\n\n for (const invite of [...invites.values()]) {\n if (invite.usedAt === null && invite.expiresAt < at) {\n invites.delete(invite.id);\n removed++;\n }\n }\n\n return removed;\n },\n },\n\n audit: {\n async append(entry) {\n const record: DevtoolsAuditEntry = { ...copy(entry), id: randomUUID() };\n\n audit.push(record);\n\n return copy(record);\n },\n async list(filter) {\n const limit = Math.max(1, Math.min(500, filter.limit));\n\n return audit\n .filter(\n (entry) =>\n (filter.types === undefined || filter.types.includes(entry.type)) &&\n (filter.accountId === undefined || entry.accountId === filter.accountId) &&\n (filter.before === undefined || entry.at < filter.before),\n )\n .sort((a, b) => b.at - a.at)\n .slice(0, limit)\n .map(copy);\n },\n async count(filter) {\n return audit.filter(\n (entry) =>\n filter.types.includes(entry.type) &&\n entry.at >= filter.since &&\n (filter.accountId === undefined || entry.accountId === filter.accountId) &&\n (filter.ip === undefined ||\n (entry.ip !== null && rateLimitClient(entry.ip) === rateLimitClient(filter.ip))),\n ).length;\n },\n async prune(before) {\n const kept = audit.filter((entry) => entry.at >= before);\n const removed = audit.length - kept.length;\n\n audit.splice(0, audit.length, ...kept);\n\n return removed;\n },\n },\n\n state: {\n async read() {\n return copy(state ?? defaultStateRecord(now()));\n },\n async update(expectedVersion, patch) {\n const current = state ?? defaultStateRecord(now());\n\n if (current.version !== expectedVersion) return null;\n\n state = { ...current, ...copy(patch), updatedAt: now(), version: current.version + 1 };\n\n return copy(state);\n },\n },\n\n samples: {\n async insert(list) {\n for (const sample of list) samples.set(sample.id, copy(sample));\n },\n async list(filter) {\n const limit = Math.max(1, Math.min(1000, filter.limit));\n\n return [...samples.values()]\n .map((sample) => sample.summary)\n .filter((summary) => sampleMatches(summary, filter))\n .sort((a, b) => b.startedAt - a.startedAt)\n .slice(0, limit)\n .map(copy);\n },\n async get(id) {\n const sample = samples.get(id);\n\n return sample ? copy(sample) : null;\n },\n async prune(before) {\n let removed = 0;\n\n for (const sample of [...samples.values()]) {\n if (sample.startedAt < before) {\n samples.delete(sample.id);\n removed++;\n }\n }\n\n return removed;\n },\n async clear() {\n const removed = samples.size;\n\n samples.clear();\n\n return removed;\n },\n },\n\n reports: {\n async write(report) {\n reports.set(report.instance.id, copy(report));\n },\n async list(seenSince) {\n return [...reports.values()]\n .filter((report) => report.at >= seenSince)\n .sort((a, b) => b.at - a.at)\n .map(copy);\n },\n async prune(seenBefore) {\n let removed = 0;\n\n for (const report of [...reports.values()]) {\n if (report.at < seenBefore) {\n reports.delete(report.instance.id);\n removed++;\n }\n }\n\n return removed;\n },\n async remove(instanceId) {\n return reports.delete(instanceId);\n },\n },\n };\n}\n"],"mappings":";;;;;;AAmBA,SAAS,KAAQ,OAAa;CAC5B,OAAO,gBAAgB,KAAK;AAC9B;;AAGA,SAAgB,mBAAmB,MAAM,GAAwB;CAC/D,OAAO;EACL,UAAU;EACV,kBAAkB;EAClB,YAAY;EACZ,YAAY;EACZ,aAAa;EACb,iBAAiB;EACjB,WAAW;EACX,SAAS;CACX;AACF;;AAGA,SAAgB,oBAAoB,QAAgB,QAAqC;CACvF,IAAI,WAAW,QAAW,OAAO;CAEjC,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY;CAExC,IAAI,YAAY,KAAK,KAAK,GAAG,OAAO,KAAK,MAAM,SAAS,GAAG,MAAM,OAAO,MAAM,EAAE;CAEhF,OAAO,OAAO,MAAM,MAAM;AAC5B;;AAGA,SAAgB,cACd,SACA,QACS;CACT,IAAI,OAAO,WAAW,UAAa,CAAC,oBAAoB,OAAO,QAAQ,QAAQ,MAAM,GACnF,OAAO;CACT,IAAI,OAAO,WAAW,UAAa,QAAQ,OAAO,YAAY,MAAM,OAAO,OAAO,YAAY,GAC5F,OAAO;CAGT,IAAI,OAAO,UAAU,QAAW;EAC9B,MAAM,SAAS,OAAO,MAAM,YAAY;EAGxC,IAAI,CAFa,GAAG,QAAQ,SAAS,GAAG,GAAG,QAAQ,OAAO,YAE9C,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO;CACzC;CAEA,IAAI,OAAO,MAA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M,IAAI;GACjC;GACA,MAAM,MAAM,QAAQ;IAClB,IAAI,UAAU;IAEd,KAAK,MAAM,UAAU,CAAC,GAAG,QAAQ,OAAO,CAAC,GACvC,IAAI,OAAO,YAAY,QAAQ;KAC7B,QAAQ,OAAO,OAAO,EAAE;KACxB;IACF;IAGF,OAAO;GACT;GACA,MAAM,QAAQ;IACZ,MAAM,UAAU,QAAQ;IAExB,QAAQ,MAAM;IAEd,OAAO;GACT;EACF;EAEA,SAAS;GACP,MAAM,MAAM,QAAQ;IAClB,QAAQ,IAAI,OAAO,SAAS,IAAI,KAAK,MAAM,CAAC;GAC9C;GACA,MAAM,KAAK,WAAW;IACpB,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CACzB,QAAQ,WAAW,OAAO,MAAM,SAAS,CAAC,CAC1C,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAC3B,IAAI,IAAI;GACb;GACA,MAAM,MAAM,YAAY;IACtB,IAAI,UAAU;IAEd,KAAK,MAAM,UAAU,CAAC,GAAG,QAAQ,OAAO,CAAC,GACvC,IAAI,OAAO,KAAK,YAAY;KAC1B,QAAQ,OAAO,OAAO,SAAS,EAAE;KACjC;IACF;IAGF,OAAO;GACT;GACA,MAAM,OAAO,YAAY;IACvB,OAAO,QAAQ,OAAO,UAAU;GAClC;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MigrationConstructor } from "@warlock.js/cascade";
|
|
2
|
+
//#region ../../packages/devtools/src/production/store/migrations.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The migrations of the production monitor's tables/collections:
|
|
5
|
+
* `devtools_accounts`, `devtools_sessions`, `devtools_invites`,
|
|
6
|
+
* `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`.
|
|
7
|
+
* An app lists them in `warlock.config.ts > database.migrations`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const devtoolsMigrations: readonly MigrationConstructor[];
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=migrations.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.mts","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/migrations.ts"],"mappings":";;;;;;;;qBAiBa,6BAA6B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DevtoolsAccountsMigration } from "./models/account.migration.mjs";
|
|
2
|
+
import { DevtoolsAuditMigration } from "./models/audit.migration.mjs";
|
|
3
|
+
import { DevtoolsInvitesMigration } from "./models/invite.migration.mjs";
|
|
4
|
+
import { DevtoolsReportsMigration } from "./models/report.migration.mjs";
|
|
5
|
+
import { DevtoolsSamplesMigration } from "./models/sample.migration.mjs";
|
|
6
|
+
import { DevtoolsSessionsMigration } from "./models/session.migration.mjs";
|
|
7
|
+
import { DevtoolsStateMigration } from "./models/state.migration.mjs";
|
|
8
|
+
import "./models/index.mjs";
|
|
9
|
+
|
|
10
|
+
//#region ../../packages/devtools/src/production/store/migrations.ts
|
|
11
|
+
/**
|
|
12
|
+
* The migrations of the production monitor's tables/collections:
|
|
13
|
+
* `devtools_accounts`, `devtools_sessions`, `devtools_invites`,
|
|
14
|
+
* `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`.
|
|
15
|
+
* An app lists them in `warlock.config.ts > database.migrations`.
|
|
16
|
+
*/
|
|
17
|
+
const devtoolsMigrations = [
|
|
18
|
+
DevtoolsAccountsMigration,
|
|
19
|
+
DevtoolsSessionsMigration,
|
|
20
|
+
DevtoolsInvitesMigration,
|
|
21
|
+
DevtoolsAuditMigration,
|
|
22
|
+
DevtoolsStateMigration,
|
|
23
|
+
DevtoolsSamplesMigration,
|
|
24
|
+
DevtoolsReportsMigration
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { devtoolsMigrations };
|
|
29
|
+
//# sourceMappingURL=migrations.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/store/migrations.ts"],"sourcesContent":["import type { MigrationConstructor } from \"@warlock.js/cascade\";\nimport {\n DevtoolsAccountsMigration,\n DevtoolsAuditMigration,\n DevtoolsInvitesMigration,\n DevtoolsReportsMigration,\n DevtoolsSamplesMigration,\n DevtoolsSessionsMigration,\n DevtoolsStateMigration,\n} from \"./models\";\n\n/**\n * The migrations of the production monitor's tables/collections:\n * `devtools_accounts`, `devtools_sessions`, `devtools_invites`,\n * `devtools_audit`, `devtools_state`, `devtools_samples`, `devtools_reports`.\n * An app lists them in `warlock.config.ts > database.migrations`.\n */\nexport const devtoolsMigrations: readonly MigrationConstructor[] = [\n DevtoolsAccountsMigration,\n DevtoolsSessionsMigration,\n DevtoolsInvitesMigration,\n DevtoolsAuditMigration,\n DevtoolsStateMigration,\n DevtoolsSamplesMigration,\n DevtoolsReportsMigration,\n];\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,qBAAsD;CACjE;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|