@secondlayer/shared 0.2.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/README.md +19 -0
- package/dist/src/crypto/hmac.d.ts +26 -0
- package/dist/src/crypto/hmac.js +75 -0
- package/dist/src/crypto/hmac.js.map +10 -0
- package/dist/src/db/index.d.ts +227 -0
- package/dist/src/db/index.js +75 -0
- package/dist/src/db/index.js.map +11 -0
- package/dist/src/db/jsonb.d.ts +13 -0
- package/dist/src/db/jsonb.js +35 -0
- package/dist/src/db/jsonb.js.map +10 -0
- package/dist/src/db/queries/accounts.d.ts +179 -0
- package/dist/src/db/queries/accounts.js +39 -0
- package/dist/src/db/queries/accounts.js.map +10 -0
- package/dist/src/db/queries/integrity.d.ts +178 -0
- package/dist/src/db/queries/integrity.js +68 -0
- package/dist/src/db/queries/integrity.js.map +10 -0
- package/dist/src/db/queries/metrics.d.ts +179 -0
- package/dist/src/db/queries/metrics.js +51 -0
- package/dist/src/db/queries/metrics.js.map +10 -0
- package/dist/src/db/queries/usage.d.ts +205 -0
- package/dist/src/db/queries/usage.js +117 -0
- package/dist/src/db/queries/usage.js.map +11 -0
- package/dist/src/db/queries/views.d.ts +191 -0
- package/dist/src/db/queries/views.js +111 -0
- package/dist/src/db/queries/views.js.map +11 -0
- package/dist/src/db/schema.d.ts +207 -0
- package/dist/src/db/schema.js +3 -0
- package/dist/src/db/schema.js.map +9 -0
- package/dist/src/env.d.ts +7 -0
- package/dist/src/env.js +60 -0
- package/dist/src/env.js.map +10 -0
- package/dist/src/errors.d.ts +51 -0
- package/dist/src/errors.js +103 -0
- package/dist/src/errors.js.map +10 -0
- package/dist/src/index.d.ts +464 -0
- package/dist/src/index.js +642 -0
- package/dist/src/index.js.map +19 -0
- package/dist/src/lib/plans.d.ts +10 -0
- package/dist/src/lib/plans.js +34 -0
- package/dist/src/lib/plans.js.map +10 -0
- package/dist/src/logger.d.ts +2 -0
- package/dist/src/logger.js +130 -0
- package/dist/src/logger.js.map +11 -0
- package/dist/src/node/client.d.ts +35 -0
- package/dist/src/node/client.js +56 -0
- package/dist/src/node/client.js.map +10 -0
- package/dist/src/node/hiro-client.d.ts +186 -0
- package/dist/src/node/hiro-client.js +410 -0
- package/dist/src/node/hiro-client.js.map +12 -0
- package/dist/src/queue/index.d.ts +50 -0
- package/dist/src/queue/index.js +176 -0
- package/dist/src/queue/index.js.map +12 -0
- package/dist/src/queue/listener.d.ts +20 -0
- package/dist/src/queue/listener.js +63 -0
- package/dist/src/queue/listener.js.map +10 -0
- package/dist/src/queue/recovery.d.ts +14 -0
- package/dist/src/queue/recovery.js +100 -0
- package/dist/src/queue/recovery.js.map +12 -0
- package/dist/src/schemas/filters.d.ts +30 -0
- package/dist/src/schemas/filters.js +133 -0
- package/dist/src/schemas/filters.js.map +10 -0
- package/dist/src/schemas/index.d.ts +109 -0
- package/dist/src/schemas/index.js +228 -0
- package/dist/src/schemas/index.js.map +12 -0
- package/dist/src/schemas/views.d.ts +51 -0
- package/dist/src/schemas/views.js +29 -0
- package/dist/src/schemas/views.js.map +10 -0
- package/dist/src/types.d.ts +102 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +9 -0
- package/migrations/0001_initial.ts +182 -0
- package/migrations/0002_api_keys.ts +38 -0
- package/migrations/0003_tenant_isolation.ts +114 -0
- package/migrations/0004_accounts_and_usage.ts +90 -0
- package/migrations/0005_sessions.ts +42 -0
- package/package.json +128 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/db/jsonb.ts
|
|
14
|
+
import { sql } from "kysely";
|
|
15
|
+
function jsonb(value) {
|
|
16
|
+
const escaped = JSON.stringify(value).replace(/'/g, "''");
|
|
17
|
+
return sql`${sql.raw(`'${escaped}'::jsonb`)}`;
|
|
18
|
+
}
|
|
19
|
+
function parseJsonb(value) {
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(value);
|
|
23
|
+
} catch {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return value ?? {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/db/queries/views.ts
|
|
31
|
+
import { sql as sql2 } from "kysely";
|
|
32
|
+
function pgSchemaName(viewName, keyPrefix) {
|
|
33
|
+
const safeName = viewName.replace(/-/g, "_");
|
|
34
|
+
if (!keyPrefix) {
|
|
35
|
+
return `view_${safeName}`;
|
|
36
|
+
}
|
|
37
|
+
const safePrefix = keyPrefix.replace(/^sk-sl_/, "").replace(/-/g, "_");
|
|
38
|
+
return `view_${safePrefix}_${safeName}`;
|
|
39
|
+
}
|
|
40
|
+
async function registerView(db, data) {
|
|
41
|
+
return await db.insertInto("views").values({
|
|
42
|
+
name: data.name,
|
|
43
|
+
version: data.version,
|
|
44
|
+
definition: jsonb(data.definition),
|
|
45
|
+
schema_hash: data.schemaHash,
|
|
46
|
+
handler_path: data.handlerPath,
|
|
47
|
+
api_key_id: data.apiKeyId ?? null,
|
|
48
|
+
schema_name: data.schemaName ?? null
|
|
49
|
+
}).onConflict((oc) => oc.columns(["name", "api_key_id"]).doUpdateSet({
|
|
50
|
+
version: data.version,
|
|
51
|
+
definition: jsonb(data.definition),
|
|
52
|
+
schema_hash: data.schemaHash,
|
|
53
|
+
handler_path: data.handlerPath,
|
|
54
|
+
schema_name: data.schemaName ?? null,
|
|
55
|
+
updated_at: new Date
|
|
56
|
+
})).returningAll().executeTakeFirstOrThrow();
|
|
57
|
+
}
|
|
58
|
+
async function getView(db, name, apiKeyId) {
|
|
59
|
+
let query = db.selectFrom("views").selectAll().where("name", "=", name);
|
|
60
|
+
if (apiKeyId) {
|
|
61
|
+
query = query.where("api_key_id", "=", apiKeyId);
|
|
62
|
+
}
|
|
63
|
+
return await query.executeTakeFirst() ?? null;
|
|
64
|
+
}
|
|
65
|
+
async function listViews(db, apiKeyId) {
|
|
66
|
+
let query = db.selectFrom("views").selectAll();
|
|
67
|
+
if (apiKeyId) {
|
|
68
|
+
query = query.where("api_key_id", "=", apiKeyId);
|
|
69
|
+
}
|
|
70
|
+
return query.execute();
|
|
71
|
+
}
|
|
72
|
+
async function updateViewStatus(db, name, status, lastProcessedBlock) {
|
|
73
|
+
await db.updateTable("views").set({
|
|
74
|
+
status,
|
|
75
|
+
...lastProcessedBlock !== undefined ? { last_processed_block: lastProcessedBlock } : {},
|
|
76
|
+
updated_at: new Date
|
|
77
|
+
}).where("name", "=", name).execute();
|
|
78
|
+
}
|
|
79
|
+
async function recordViewProcessed(db, name, processed, errors, lastError) {
|
|
80
|
+
await db.updateTable("views").set({
|
|
81
|
+
total_processed: sql2`total_processed + ${processed}`,
|
|
82
|
+
total_errors: sql2`total_errors + ${errors}`,
|
|
83
|
+
...lastError ? { last_error: lastError, last_error_at: new Date } : {},
|
|
84
|
+
updated_at: new Date
|
|
85
|
+
}).where("name", "=", name).execute();
|
|
86
|
+
}
|
|
87
|
+
async function updateViewHandlerPath(db, name, handlerPath) {
|
|
88
|
+
await db.updateTable("views").set({ handler_path: handlerPath, updated_at: new Date }).where("name", "=", name).execute();
|
|
89
|
+
}
|
|
90
|
+
async function deleteView(db, name, apiKeyId) {
|
|
91
|
+
const view = await getView(db, name, apiKeyId);
|
|
92
|
+
if (!view)
|
|
93
|
+
return null;
|
|
94
|
+
const schemaName = view.schema_name ?? pgSchemaName(name);
|
|
95
|
+
await sql2`DROP SCHEMA IF EXISTS ${sql2.raw(`"${schemaName}"`)} CASCADE`.execute(db);
|
|
96
|
+
await db.deleteFrom("views").where("id", "=", view.id).execute();
|
|
97
|
+
return view;
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
updateViewStatus,
|
|
101
|
+
updateViewHandlerPath,
|
|
102
|
+
registerView,
|
|
103
|
+
recordViewProcessed,
|
|
104
|
+
pgSchemaName,
|
|
105
|
+
listViews,
|
|
106
|
+
getView,
|
|
107
|
+
deleteView
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//# debugId=C19949368802BB4964756E2164756E21
|
|
111
|
+
//# sourceMappingURL=views.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/db/jsonb.ts", "../src/db/queries/views.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { sql } from \"kysely\";\n\n/**\n * Safely encode a JS value as a JSONB literal for Kysely inserts/updates.\n * Kysely + postgres.js double-encodes JSON when using parameterized queries\n * with ::jsonb casts. This uses sql.raw to inline a properly escaped literal.\n */\nexport function jsonb(value: unknown) {\n const escaped = JSON.stringify(value).replace(/'/g, \"''\");\n return sql`${sql.raw(`'${escaped}'::jsonb`)}`;\n}\n\n/**\n * Safely parse a JSONB value from the database.\n * Handles double-encoded strings where postgres.js returns a JSON string\n * instead of a parsed object.\n */\nexport function parseJsonb<T = unknown>(value: unknown): T {\n if (typeof value === \"string\") {\n try {\n return JSON.parse(value) as T;\n } catch {\n return value as T;\n }\n }\n return (value ?? {}) as T;\n}\n",
|
|
6
|
+
"import { sql, type Kysely } from \"kysely\";\nimport { jsonb } from \"../jsonb.ts\";\nimport type { Database } from \"../types.ts\";\n\n/**\n * Convert a view name to its PostgreSQL schema name.\n * With keyPrefix: \"view_{prefix}_{name}\" (tenant-isolated)\n * Without keyPrefix: \"view_{name}\" (backward compat)\n */\nexport function pgSchemaName(viewName: string, keyPrefix?: string): string {\n const safeName = viewName.replace(/-/g, \"_\");\n if (!keyPrefix) {\n return `view_${safeName}`;\n }\n const safePrefix = keyPrefix.replace(/^sk-sl_/, \"\").replace(/-/g, \"_\");\n return `view_${safePrefix}_${safeName}`;\n}\n\nexport async function registerView(\n db: Kysely<Database>,\n data: {\n name: string;\n version: string;\n definition: Record<string, unknown>;\n schemaHash: string;\n handlerPath: string;\n apiKeyId?: string;\n schemaName?: string;\n },\n) {\n return await db\n .insertInto(\"views\")\n .values({\n name: data.name,\n version: data.version,\n definition: jsonb(data.definition) as any,\n schema_hash: data.schemaHash,\n handler_path: data.handlerPath,\n api_key_id: data.apiKeyId ?? null,\n schema_name: data.schemaName ?? null,\n })\n .onConflict((oc) =>\n oc.columns([\"name\", \"api_key_id\"]).doUpdateSet({\n version: data.version,\n definition: jsonb(data.definition) as any,\n schema_hash: data.schemaHash,\n handler_path: data.handlerPath,\n schema_name: data.schemaName ?? null,\n updated_at: new Date(),\n }),\n )\n .returningAll()\n .executeTakeFirstOrThrow();\n}\n\nexport async function getView(db: Kysely<Database>, name: string, apiKeyId?: string) {\n let query = db\n .selectFrom(\"views\")\n .selectAll()\n .where(\"name\", \"=\", name);\n\n if (apiKeyId) {\n query = query.where(\"api_key_id\", \"=\", apiKeyId);\n }\n\n return (await query.executeTakeFirst()) ?? null;\n}\n\nexport async function listViews(db: Kysely<Database>, apiKeyId?: string) {\n let query = db.selectFrom(\"views\").selectAll();\n if (apiKeyId) {\n query = query.where(\"api_key_id\", \"=\", apiKeyId);\n }\n return query.execute();\n}\n\nexport async function updateViewStatus(\n db: Kysely<Database>,\n name: string,\n status: string,\n lastProcessedBlock?: number,\n) {\n await db\n .updateTable(\"views\")\n .set({\n status,\n ...(lastProcessedBlock !== undefined ? { last_processed_block: lastProcessedBlock } : {}),\n updated_at: new Date(),\n })\n .where(\"name\", \"=\", name)\n .execute();\n}\n\nexport async function recordViewProcessed(\n db: Kysely<Database>,\n name: string,\n processed: number,\n errors: number,\n lastError?: string,\n) {\n await db\n .updateTable(\"views\")\n .set({\n total_processed: sql`total_processed + ${processed}`,\n total_errors: sql`total_errors + ${errors}`,\n ...(lastError\n ? { last_error: lastError, last_error_at: new Date() }\n : {}),\n updated_at: new Date(),\n })\n .where(\"name\", \"=\", name)\n .execute();\n}\n\nexport async function updateViewHandlerPath(\n db: Kysely<Database>,\n name: string,\n handlerPath: string,\n) {\n await db\n .updateTable(\"views\")\n .set({ handler_path: handlerPath, updated_at: new Date() })\n .where(\"name\", \"=\", name)\n .execute();\n}\n\nexport async function deleteView(db: Kysely<Database>, name: string, apiKeyId?: string) {\n const view = await getView(db, name, apiKeyId);\n if (!view) return null;\n\n // Use stored schema_name if available, otherwise compute\n const schemaName = view.schema_name ?? pgSchemaName(name);\n\n // Drop the view's schema (CASCADE drops all tables within)\n await sql`DROP SCHEMA IF EXISTS ${sql.raw(`\"${schemaName}\"`)} CASCADE`.execute(db);\n\n // Remove from registry\n await db.deleteFrom(\"views\").where(\"id\", \"=\", view.id).execute();\n\n return view;\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": "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",
|
|
9
|
+
"debugId": "C19949368802BB4964756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { Generated, Insertable, Selectable, Updateable } from "kysely";
|
|
2
|
+
interface BlocksTable {
|
|
3
|
+
height: number;
|
|
4
|
+
hash: string;
|
|
5
|
+
parent_hash: string;
|
|
6
|
+
burn_block_height: number;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
canonical: Generated<boolean>;
|
|
9
|
+
created_at: Generated<Date>;
|
|
10
|
+
}
|
|
11
|
+
interface TransactionsTable {
|
|
12
|
+
tx_id: string;
|
|
13
|
+
block_height: number;
|
|
14
|
+
type: string;
|
|
15
|
+
sender: string;
|
|
16
|
+
status: string;
|
|
17
|
+
contract_id: string | null;
|
|
18
|
+
function_name: string | null;
|
|
19
|
+
raw_tx: string;
|
|
20
|
+
created_at: Generated<Date>;
|
|
21
|
+
}
|
|
22
|
+
interface EventsTable {
|
|
23
|
+
id: Generated<string>;
|
|
24
|
+
tx_id: string;
|
|
25
|
+
block_height: number;
|
|
26
|
+
event_index: number;
|
|
27
|
+
type: string;
|
|
28
|
+
data: unknown;
|
|
29
|
+
created_at: Generated<Date>;
|
|
30
|
+
}
|
|
31
|
+
interface StreamsTable {
|
|
32
|
+
id: Generated<string>;
|
|
33
|
+
name: string;
|
|
34
|
+
status: Generated<string>;
|
|
35
|
+
filters: unknown;
|
|
36
|
+
options: Generated<unknown>;
|
|
37
|
+
webhook_url: string;
|
|
38
|
+
webhook_secret: string | null;
|
|
39
|
+
api_key_id: string | null;
|
|
40
|
+
created_at: Generated<Date>;
|
|
41
|
+
updated_at: Generated<Date>;
|
|
42
|
+
}
|
|
43
|
+
interface StreamMetricsTable {
|
|
44
|
+
stream_id: string;
|
|
45
|
+
last_triggered_at: Date | null;
|
|
46
|
+
last_triggered_block: number | null;
|
|
47
|
+
total_deliveries: Generated<number>;
|
|
48
|
+
failed_deliveries: Generated<number>;
|
|
49
|
+
error_message: string | null;
|
|
50
|
+
}
|
|
51
|
+
interface JobsTable {
|
|
52
|
+
id: Generated<string>;
|
|
53
|
+
stream_id: string;
|
|
54
|
+
block_height: number;
|
|
55
|
+
status: Generated<string>;
|
|
56
|
+
attempts: Generated<number>;
|
|
57
|
+
locked_at: Date | null;
|
|
58
|
+
locked_by: string | null;
|
|
59
|
+
error: string | null;
|
|
60
|
+
backfill: Generated<boolean>;
|
|
61
|
+
created_at: Generated<Date>;
|
|
62
|
+
completed_at: Date | null;
|
|
63
|
+
}
|
|
64
|
+
interface IndexProgressTable {
|
|
65
|
+
network: string;
|
|
66
|
+
last_indexed_block: Generated<number>;
|
|
67
|
+
last_contiguous_block: Generated<number>;
|
|
68
|
+
highest_seen_block: Generated<number>;
|
|
69
|
+
updated_at: Generated<Date>;
|
|
70
|
+
}
|
|
71
|
+
interface DeliveriesTable {
|
|
72
|
+
id: Generated<string>;
|
|
73
|
+
stream_id: string;
|
|
74
|
+
job_id: string | null;
|
|
75
|
+
block_height: number;
|
|
76
|
+
status: string;
|
|
77
|
+
status_code: number | null;
|
|
78
|
+
response_time_ms: number | null;
|
|
79
|
+
attempts: Generated<number>;
|
|
80
|
+
error: string | null;
|
|
81
|
+
payload: unknown;
|
|
82
|
+
created_at: Generated<Date>;
|
|
83
|
+
}
|
|
84
|
+
interface ViewsTable {
|
|
85
|
+
id: Generated<string>;
|
|
86
|
+
name: string;
|
|
87
|
+
version: Generated<string>;
|
|
88
|
+
status: Generated<string>;
|
|
89
|
+
definition: unknown;
|
|
90
|
+
schema_hash: string;
|
|
91
|
+
handler_path: string;
|
|
92
|
+
schema_name: string | null;
|
|
93
|
+
last_processed_block: Generated<number>;
|
|
94
|
+
last_error: string | null;
|
|
95
|
+
last_error_at: Date | null;
|
|
96
|
+
total_processed: Generated<number>;
|
|
97
|
+
total_errors: Generated<number>;
|
|
98
|
+
api_key_id: string | null;
|
|
99
|
+
created_at: Generated<Date>;
|
|
100
|
+
updated_at: Generated<Date>;
|
|
101
|
+
}
|
|
102
|
+
interface ApiKeysTable {
|
|
103
|
+
id: Generated<string>;
|
|
104
|
+
key_hash: string;
|
|
105
|
+
key_prefix: string;
|
|
106
|
+
name: string | null;
|
|
107
|
+
status: Generated<string>;
|
|
108
|
+
rate_limit: Generated<number>;
|
|
109
|
+
ip_address: string;
|
|
110
|
+
account_id: string;
|
|
111
|
+
last_used_at: Date | null;
|
|
112
|
+
revoked_at: Date | null;
|
|
113
|
+
created_at: Generated<Date>;
|
|
114
|
+
}
|
|
115
|
+
interface AccountsTable {
|
|
116
|
+
id: Generated<string>;
|
|
117
|
+
email: string;
|
|
118
|
+
plan: Generated<string>;
|
|
119
|
+
created_at: Generated<Date>;
|
|
120
|
+
}
|
|
121
|
+
interface SessionsTable {
|
|
122
|
+
id: Generated<string>;
|
|
123
|
+
token_hash: string;
|
|
124
|
+
token_prefix: string;
|
|
125
|
+
account_id: string;
|
|
126
|
+
ip_address: string;
|
|
127
|
+
expires_at: Generated<Date>;
|
|
128
|
+
revoked_at: Date | null;
|
|
129
|
+
last_used_at: Date | null;
|
|
130
|
+
created_at: Generated<Date>;
|
|
131
|
+
}
|
|
132
|
+
interface MagicLinksTable {
|
|
133
|
+
id: Generated<string>;
|
|
134
|
+
email: string;
|
|
135
|
+
token: string;
|
|
136
|
+
expires_at: Date;
|
|
137
|
+
used_at: Date | null;
|
|
138
|
+
created_at: Generated<Date>;
|
|
139
|
+
}
|
|
140
|
+
interface UsageDailyTable {
|
|
141
|
+
account_id: string;
|
|
142
|
+
date: string;
|
|
143
|
+
api_requests: Generated<number>;
|
|
144
|
+
deliveries: Generated<number>;
|
|
145
|
+
}
|
|
146
|
+
interface UsageSnapshotsTable {
|
|
147
|
+
id: Generated<string>;
|
|
148
|
+
account_id: string;
|
|
149
|
+
measured_at: Generated<Date>;
|
|
150
|
+
storage_bytes: Generated<number>;
|
|
151
|
+
}
|
|
152
|
+
interface Database {
|
|
153
|
+
blocks: BlocksTable;
|
|
154
|
+
transactions: TransactionsTable;
|
|
155
|
+
events: EventsTable;
|
|
156
|
+
streams: StreamsTable;
|
|
157
|
+
stream_metrics: StreamMetricsTable;
|
|
158
|
+
jobs: JobsTable;
|
|
159
|
+
index_progress: IndexProgressTable;
|
|
160
|
+
deliveries: DeliveriesTable;
|
|
161
|
+
views: ViewsTable;
|
|
162
|
+
api_keys: ApiKeysTable;
|
|
163
|
+
accounts: AccountsTable;
|
|
164
|
+
sessions: SessionsTable;
|
|
165
|
+
magic_links: MagicLinksTable;
|
|
166
|
+
usage_daily: UsageDailyTable;
|
|
167
|
+
usage_snapshots: UsageSnapshotsTable;
|
|
168
|
+
}
|
|
169
|
+
type Block = Selectable<BlocksTable>;
|
|
170
|
+
type InsertBlock = Insertable<BlocksTable>;
|
|
171
|
+
type UpdateBlock = Updateable<BlocksTable>;
|
|
172
|
+
type Transaction = Selectable<TransactionsTable>;
|
|
173
|
+
type InsertTransaction = Insertable<TransactionsTable>;
|
|
174
|
+
type UpdateTransaction = Updateable<TransactionsTable>;
|
|
175
|
+
type Event = Selectable<EventsTable>;
|
|
176
|
+
type InsertEvent = Insertable<EventsTable>;
|
|
177
|
+
type UpdateEvent = Updateable<EventsTable>;
|
|
178
|
+
type Stream = Selectable<StreamsTable>;
|
|
179
|
+
type InsertStream = Insertable<StreamsTable>;
|
|
180
|
+
type UpdateStreamRow = Updateable<StreamsTable>;
|
|
181
|
+
type StreamMetrics = Selectable<StreamMetricsTable>;
|
|
182
|
+
type InsertStreamMetrics = Insertable<StreamMetricsTable>;
|
|
183
|
+
type UpdateStreamMetrics = Updateable<StreamMetricsTable>;
|
|
184
|
+
type Job = Selectable<JobsTable>;
|
|
185
|
+
type InsertJob = Insertable<JobsTable>;
|
|
186
|
+
type UpdateJob = Updateable<JobsTable>;
|
|
187
|
+
type IndexProgress = Selectable<IndexProgressTable>;
|
|
188
|
+
type InsertIndexProgress = Insertable<IndexProgressTable>;
|
|
189
|
+
type UpdateIndexProgress = Updateable<IndexProgressTable>;
|
|
190
|
+
type Delivery = Selectable<DeliveriesTable>;
|
|
191
|
+
type InsertDelivery = Insertable<DeliveriesTable>;
|
|
192
|
+
type UpdateDelivery = Updateable<DeliveriesTable>;
|
|
193
|
+
type View = Selectable<ViewsTable>;
|
|
194
|
+
type InsertView = Insertable<ViewsTable>;
|
|
195
|
+
type UpdateView = Updateable<ViewsTable>;
|
|
196
|
+
type ApiKey = Selectable<ApiKeysTable>;
|
|
197
|
+
type InsertApiKey = Insertable<ApiKeysTable>;
|
|
198
|
+
type UpdateApiKey = Updateable<ApiKeysTable>;
|
|
199
|
+
type Account = Selectable<AccountsTable>;
|
|
200
|
+
type InsertAccount = Insertable<AccountsTable>;
|
|
201
|
+
type MagicLink = Selectable<MagicLinksTable>;
|
|
202
|
+
type InsertMagicLink = Insertable<MagicLinksTable>;
|
|
203
|
+
type Session = Selectable<SessionsTable>;
|
|
204
|
+
type InsertSession = Insertable<SessionsTable>;
|
|
205
|
+
type UsageDaily = Selectable<UsageDailyTable>;
|
|
206
|
+
type UsageSnapshot = Selectable<UsageSnapshotsTable>;
|
|
207
|
+
export { ViewsTable, View, UsageSnapshotsTable, UsageSnapshot, UsageDailyTable, UsageDaily, UpdateView, UpdateTransaction, UpdateStreamRow, UpdateStreamMetrics, UpdateJob, UpdateIndexProgress, UpdateEvent, UpdateDelivery, UpdateBlock, UpdateApiKey, TransactionsTable, Transaction, StreamsTable, StreamMetricsTable, StreamMetrics, Stream, SessionsTable, Session, MagicLinksTable, MagicLink, JobsTable, Job, InsertView, InsertTransaction, InsertStreamMetrics, InsertStream, InsertSession, InsertMagicLink, InsertJob, InsertIndexProgress, InsertEvent, InsertDelivery, InsertBlock, InsertApiKey, InsertAccount, IndexProgressTable, IndexProgress, EventsTable, Event, Delivery, DeliveriesTable, Database, BlocksTable, Block, ApiKeysTable, ApiKey, AccountsTable, Account };
|
package/dist/src/env.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/env.ts
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
var networksSchema = z.string().transform((val) => {
|
|
16
|
+
const networks = val.split(",").map((n) => n.trim()).filter(Boolean);
|
|
17
|
+
const valid = ["mainnet", "testnet"];
|
|
18
|
+
for (const n of networks) {
|
|
19
|
+
if (!valid.includes(n)) {
|
|
20
|
+
throw new Error(`Invalid network: ${n}. Must be one of: ${valid.join(", ")}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return networks;
|
|
24
|
+
});
|
|
25
|
+
var envSchema = z.object({
|
|
26
|
+
DATABASE_URL: z.preprocess((val) => typeof val === "string" && val.length === 0 ? undefined : val, z.string().url().optional()),
|
|
27
|
+
NETWORK: z.enum(["mainnet", "testnet"]).optional(),
|
|
28
|
+
NETWORKS: networksSchema.optional(),
|
|
29
|
+
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
|
30
|
+
NODE_ENV: z.enum(["development", "production", "test"]).default("development")
|
|
31
|
+
});
|
|
32
|
+
var cachedEnv = null;
|
|
33
|
+
function getEnv() {
|
|
34
|
+
if (cachedEnv) {
|
|
35
|
+
return cachedEnv;
|
|
36
|
+
}
|
|
37
|
+
const result = envSchema.safeParse(process.env);
|
|
38
|
+
if (!result.success) {
|
|
39
|
+
console.error("❌ Invalid environment configuration:");
|
|
40
|
+
console.error(result.error.format());
|
|
41
|
+
throw new Error("Invalid environment configuration");
|
|
42
|
+
}
|
|
43
|
+
let enabledNetworks;
|
|
44
|
+
if (result.data.NETWORKS && result.data.NETWORKS.length > 0) {
|
|
45
|
+
enabledNetworks = result.data.NETWORKS;
|
|
46
|
+
} else if (result.data.NETWORK) {
|
|
47
|
+
enabledNetworks = [result.data.NETWORK];
|
|
48
|
+
} else {
|
|
49
|
+
enabledNetworks = ["mainnet"];
|
|
50
|
+
}
|
|
51
|
+
cachedEnv = { ...result.data, enabledNetworks };
|
|
52
|
+
return cachedEnv;
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
getEnv,
|
|
56
|
+
envSchema
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//# debugId=36753D595F72E07A64756E2164756E21
|
|
60
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/env.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { z } from \"zod\";\n\n// Parse comma-separated networks\nconst networksSchema = z.string().transform((val) => {\n const networks = val.split(\",\").map((n) => n.trim()).filter(Boolean);\n const valid = [\"mainnet\", \"testnet\"];\n for (const n of networks) {\n if (!valid.includes(n)) {\n throw new Error(`Invalid network: ${n}. Must be one of: ${valid.join(\", \")}`);\n }\n }\n return networks as (\"mainnet\" | \"testnet\")[];\n});\n\nconst envSchema = z.object({\n // DATABASE_URL is optional - consumers must provide their own\n DATABASE_URL: z.preprocess(\n (val) => (typeof val === \"string\" && val.length === 0) ? undefined : val,\n z.string().url().optional(),\n ),\n // Single network (deprecated, for backwards compatibility)\n NETWORK: z.enum([\"mainnet\", \"testnet\"]).optional(),\n // Multiple networks (comma-separated)\n NETWORKS: networksSchema.optional(),\n LOG_LEVEL: z.enum([\"debug\", \"info\", \"warn\", \"error\"]).default(\"info\"),\n NODE_ENV: z.enum([\"development\", \"production\", \"test\"]).default(\"development\"),\n});\n\nexport type Env = z.infer<typeof envSchema> & {\n enabledNetworks: (\"mainnet\" | \"testnet\")[];\n};\n\nlet cachedEnv: Env | null = null;\n\nexport function getEnv(): Env {\n if (cachedEnv) {\n return cachedEnv;\n }\n\n const result = envSchema.safeParse(process.env);\n\n if (!result.success) {\n console.error(\"❌ Invalid environment configuration:\");\n console.error(result.error.format());\n throw new Error(\"Invalid environment configuration\");\n }\n\n // Compute enabled networks from NETWORKS or NETWORK\n let enabledNetworks: (\"mainnet\" | \"testnet\")[];\n if (result.data.NETWORKS && result.data.NETWORKS.length > 0) {\n enabledNetworks = result.data.NETWORKS;\n } else if (result.data.NETWORK) {\n enabledNetworks = [result.data.NETWORK];\n } else {\n enabledNetworks = [\"mainnet\"]; // Default\n }\n\n cachedEnv = { ...result.data, enabledNetworks };\n return cachedEnv;\n}\n\n// Export for testing\nexport { envSchema };\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;AAAA;AAGA,IAAM,iBAAiB,EAAE,OAAO,EAAE,UAAU,CAAC,QAAQ;AAAA,EACnD,MAAM,WAAW,IAAI,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,OAAO;AAAA,EACnE,MAAM,QAAQ,CAAC,WAAW,SAAS;AAAA,EACnC,WAAW,KAAK,UAAU;AAAA,IACxB,IAAI,CAAC,MAAM,SAAS,CAAC,GAAG;AAAA,MACtB,MAAM,IAAI,MAAM,oBAAoB,sBAAsB,MAAM,KAAK,IAAI,GAAG;AAAA,IAC9E;AAAA,EACF;AAAA,EACA,OAAO;AAAA,CACR;AAED,IAAM,YAAY,EAAE,OAAO;AAAA,EAEzB,cAAc,EAAE,WACd,CAAC,QAAS,OAAO,QAAQ,YAAY,IAAI,WAAW,IAAK,YAAY,KACrE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,CAC5B;AAAA,EAEA,SAAS,EAAE,KAAK,CAAC,WAAW,SAAS,CAAC,EAAE,SAAS;AAAA,EAEjD,UAAU,eAAe,SAAS;AAAA,EAClC,WAAW,EAAE,KAAK,CAAC,SAAS,QAAQ,QAAQ,OAAO,CAAC,EAAE,QAAQ,MAAM;AAAA,EACpE,UAAU,EAAE,KAAK,CAAC,eAAe,cAAc,MAAM,CAAC,EAAE,QAAQ,aAAa;AAC/E,CAAC;AAMD,IAAI,YAAwB;AAErB,SAAS,MAAM,GAAQ;AAAA,EAC5B,IAAI,WAAW;AAAA,IACb,OAAO;AAAA,EACT;AAAA,EAEA,MAAM,SAAS,UAAU,UAAU,QAAQ,GAAG;AAAA,EAE9C,IAAI,CAAC,OAAO,SAAS;AAAA,IACnB,QAAQ,MAAM,sCAAqC;AAAA,IACnD,QAAQ,MAAM,OAAO,MAAM,OAAO,CAAC;AAAA,IACnC,MAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAAA,EAGA,IAAI;AAAA,EACJ,IAAI,OAAO,KAAK,YAAY,OAAO,KAAK,SAAS,SAAS,GAAG;AAAA,IAC3D,kBAAkB,OAAO,KAAK;AAAA,EAChC,EAAO,SAAI,OAAO,KAAK,SAAS;AAAA,IAC9B,kBAAkB,CAAC,OAAO,KAAK,OAAO;AAAA,EACxC,EAAO;AAAA,IACL,kBAAkB,CAAC,SAAS;AAAA;AAAA,EAG9B,YAAY,KAAK,OAAO,MAAM,gBAAgB;AAAA,EAC9C,OAAO;AAAA;",
|
|
8
|
+
"debugId": "36753D595F72E07A64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Stacks Streams errors
|
|
3
|
+
*/
|
|
4
|
+
declare class StreamsError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
constructor(code: string, message: string, cause?: unknown);
|
|
8
|
+
toJSON(): {};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Stream not found error
|
|
12
|
+
*/
|
|
13
|
+
declare class StreamNotFoundError extends StreamsError {
|
|
14
|
+
constructor(streamId: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validation error for invalid input
|
|
18
|
+
*/
|
|
19
|
+
declare class ValidationError extends StreamsError {
|
|
20
|
+
constructor(message: string, cause?: unknown);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Database operation error
|
|
24
|
+
*/
|
|
25
|
+
declare class DatabaseError extends StreamsError {
|
|
26
|
+
constructor(message: string, cause?: unknown);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Webhook delivery error
|
|
30
|
+
*/
|
|
31
|
+
declare class WebhookDeliveryError extends StreamsError {
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
constructor(message: string, statusCode?: number, cause?: unknown);
|
|
34
|
+
toJSON(): {};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Filter evaluation error
|
|
38
|
+
*/
|
|
39
|
+
declare class FilterEvaluationError extends StreamsError {
|
|
40
|
+
constructor(message: string, cause?: unknown);
|
|
41
|
+
}
|
|
42
|
+
declare class AuthenticationError extends StreamsError {
|
|
43
|
+
constructor(message: string);
|
|
44
|
+
}
|
|
45
|
+
declare class AuthorizationError extends StreamsError {
|
|
46
|
+
constructor(message: string);
|
|
47
|
+
}
|
|
48
|
+
declare class RateLimitError extends StreamsError {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
export { WebhookDeliveryError, ValidationError, StreamsError, StreamNotFoundError, RateLimitError, FilterEvaluationError, DatabaseError, AuthorizationError, AuthenticationError };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/errors.ts
|
|
14
|
+
class StreamsError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
cause;
|
|
17
|
+
constructor(code, message, cause) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.cause = cause;
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
23
|
+
}
|
|
24
|
+
toJSON() {
|
|
25
|
+
return {
|
|
26
|
+
name: this.name,
|
|
27
|
+
code: this.code,
|
|
28
|
+
message: this.message,
|
|
29
|
+
stack: this.stack,
|
|
30
|
+
cause: this.cause
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class StreamNotFoundError extends StreamsError {
|
|
36
|
+
constructor(streamId) {
|
|
37
|
+
super("STREAM_NOT_FOUND", `Stream not found: ${streamId}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class ValidationError extends StreamsError {
|
|
42
|
+
constructor(message, cause) {
|
|
43
|
+
super("VALIDATION_ERROR", message, cause);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
class DatabaseError extends StreamsError {
|
|
48
|
+
constructor(message, cause) {
|
|
49
|
+
super("DATABASE_ERROR", message, cause);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
class WebhookDeliveryError extends StreamsError {
|
|
54
|
+
statusCode;
|
|
55
|
+
constructor(message, statusCode, cause) {
|
|
56
|
+
super("WEBHOOK_DELIVERY_ERROR", message, cause);
|
|
57
|
+
this.statusCode = statusCode;
|
|
58
|
+
}
|
|
59
|
+
toJSON() {
|
|
60
|
+
return {
|
|
61
|
+
...super.toJSON(),
|
|
62
|
+
statusCode: this.statusCode
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class FilterEvaluationError extends StreamsError {
|
|
68
|
+
constructor(message, cause) {
|
|
69
|
+
super("FILTER_EVALUATION_ERROR", message, cause);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
class AuthenticationError extends StreamsError {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super("AUTHENTICATION_ERROR", message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class AuthorizationError extends StreamsError {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super("AUTHORIZATION_ERROR", message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class RateLimitError extends StreamsError {
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super("RATE_LIMIT_ERROR", message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
WebhookDeliveryError,
|
|
92
|
+
ValidationError,
|
|
93
|
+
StreamsError,
|
|
94
|
+
StreamNotFoundError,
|
|
95
|
+
RateLimitError,
|
|
96
|
+
FilterEvaluationError,
|
|
97
|
+
DatabaseError,
|
|
98
|
+
AuthorizationError,
|
|
99
|
+
AuthenticationError
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//# debugId=6ACA7F80BF720CB464756E2164756E21
|
|
103
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Base error class for all Stacks Streams errors\n */\nexport class StreamsError extends Error {\n public code: string;\n public override cause?: unknown;\n\n constructor(\n code: string,\n message: string,\n cause?: unknown\n ) {\n super(message);\n this.code = code;\n this.cause = cause;\n this.name = this.constructor.name;\n Error.captureStackTrace?.(this, this.constructor);\n }\n\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n stack: this.stack,\n cause: this.cause,\n };\n }\n}\n\n/**\n * Stream not found error\n */\nexport class StreamNotFoundError extends StreamsError {\n constructor(streamId: string) {\n super(\"STREAM_NOT_FOUND\", `Stream not found: ${streamId}`);\n }\n}\n\n/**\n * Validation error for invalid input\n */\nexport class ValidationError extends StreamsError {\n constructor(message: string, cause?: unknown) {\n super(\"VALIDATION_ERROR\", message, cause);\n }\n}\n\n/**\n * Database operation error\n */\nexport class DatabaseError extends StreamsError {\n constructor(message: string, cause?: unknown) {\n super(\"DATABASE_ERROR\", message, cause);\n }\n}\n\n/**\n * Webhook delivery error\n */\nexport class WebhookDeliveryError extends StreamsError {\n constructor(\n message: string,\n public statusCode?: number,\n cause?: unknown\n ) {\n super(\"WEBHOOK_DELIVERY_ERROR\", message, cause);\n }\n\n override toJSON() {\n return {\n ...super.toJSON(),\n statusCode: this.statusCode,\n };\n }\n}\n\n/**\n * Filter evaluation error\n */\nexport class FilterEvaluationError extends StreamsError {\n constructor(message: string, cause?: unknown) {\n super(\"FILTER_EVALUATION_ERROR\", message, cause);\n }\n}\n\nexport class AuthenticationError extends StreamsError {\n constructor(message: string) {\n super(\"AUTHENTICATION_ERROR\", message);\n }\n}\n\nexport class AuthorizationError extends StreamsError {\n constructor(message: string) {\n super(\"AUTHORIZATION_ERROR\", message);\n }\n}\n\nexport class RateLimitError extends StreamsError {\n constructor(message: string) {\n super(\"RATE_LIMIT_ERROR\", message);\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;AAGO,MAAM,qBAAqB,MAAM;AAAA,EAC/B;AAAA,EACS;AAAA,EAEhB,WAAW,CACT,MACA,SACA,OACA;AAAA,IACA,MAAM,OAAO;AAAA,IACb,KAAK,OAAO;AAAA,IACZ,KAAK,QAAQ;AAAA,IACb,KAAK,OAAO,KAAK,YAAY;AAAA,IAC7B,MAAM,oBAAoB,MAAM,KAAK,WAAW;AAAA;AAAA,EAGlD,MAAM,GAAG;AAAA,IACP,OAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,OAAO,KAAK;AAAA,IACd;AAAA;AAEJ;AAAA;AAKO,MAAM,4BAA4B,aAAa;AAAA,EACpD,WAAW,CAAC,UAAkB;AAAA,IAC5B,MAAM,oBAAoB,qBAAqB,UAAU;AAAA;AAE7D;AAAA;AAKO,MAAM,wBAAwB,aAAa;AAAA,EAChD,WAAW,CAAC,SAAiB,OAAiB;AAAA,IAC5C,MAAM,oBAAoB,SAAS,KAAK;AAAA;AAE5C;AAAA;AAKO,MAAM,sBAAsB,aAAa;AAAA,EAC9C,WAAW,CAAC,SAAiB,OAAiB;AAAA,IAC5C,MAAM,kBAAkB,SAAS,KAAK;AAAA;AAE1C;AAAA;AAKO,MAAM,6BAA6B,aAAa;AAAA,EAG5C;AAAA,EAFT,WAAW,CACT,SACO,YACP,OACA;AAAA,IACA,MAAM,0BAA0B,SAAS,KAAK;AAAA,IAHvC;AAAA;AAAA,EAMA,MAAM,GAAG;AAAA,IAChB,OAAO;AAAA,SACF,MAAM,OAAO;AAAA,MAChB,YAAY,KAAK;AAAA,IACnB;AAAA;AAEJ;AAAA;AAKO,MAAM,8BAA8B,aAAa;AAAA,EACtD,WAAW,CAAC,SAAiB,OAAiB;AAAA,IAC5C,MAAM,2BAA2B,SAAS,KAAK;AAAA;AAEnD;AAAA;AAEO,MAAM,4BAA4B,aAAa;AAAA,EACpD,WAAW,CAAC,SAAiB;AAAA,IAC3B,MAAM,wBAAwB,OAAO;AAAA;AAEzC;AAAA;AAEO,MAAM,2BAA2B,aAAa;AAAA,EACnD,WAAW,CAAC,SAAiB;AAAA,IAC3B,MAAM,uBAAuB,OAAO;AAAA;AAExC;AAAA;AAEO,MAAM,uBAAuB,aAAa;AAAA,EAC/C,WAAW,CAAC,SAAiB;AAAA,IAC3B,MAAM,oBAAoB,OAAO;AAAA;AAErC;",
|
|
8
|
+
"debugId": "6ACA7F80BF720CB464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|