@crvouga/mockingbird-runtime 0.0.0-stage → 0.0.2
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 +131 -2
- package/dist/adapter-node.d.ts +2521 -0
- package/dist/adapter-node.js +6920 -0
- package/dist/adapter-node.js.map +7 -0
- package/dist/admin-ui.js +25 -0
- package/dist/admin-ui.js.map +7 -0
- package/dist/chunk-2KDYLZXC.js +118 -0
- package/dist/chunk-2KDYLZXC.js.map +7 -0
- package/dist/chunk-2Y25NPCV.js +1289 -0
- package/dist/chunk-2Y25NPCV.js.map +7 -0
- package/dist/chunk-4SAK6MQT.js +246 -0
- package/dist/chunk-4SAK6MQT.js.map +7 -0
- package/dist/chunk-ANCCZFF2.js +778 -0
- package/dist/chunk-ANCCZFF2.js.map +7 -0
- package/dist/chunk-EBGYPQPA.js +198 -0
- package/dist/chunk-EBGYPQPA.js.map +7 -0
- package/dist/chunk-EQLY2YOA.js +274 -0
- package/dist/chunk-EQLY2YOA.js.map +7 -0
- package/dist/chunk-G62YDIIJ.js +7664 -0
- package/dist/chunk-G62YDIIJ.js.map +7 -0
- package/dist/chunk-HU6IOAFC.js +437 -0
- package/dist/chunk-HU6IOAFC.js.map +7 -0
- package/dist/chunk-RNAHPNUJ.js +97 -0
- package/dist/chunk-RNAHPNUJ.js.map +7 -0
- package/dist/chunk-UP4QOSFD.js +87 -0
- package/dist/chunk-UP4QOSFD.js.map +7 -0
- package/dist/chunk-XNS34BPF.js +2489 -0
- package/dist/chunk-XNS34BPF.js.map +7 -0
- package/dist/core.d.ts +356 -0
- package/dist/core.js +51 -0
- package/dist/core.js.map +7 -0
- package/dist/crypto-XS5XCMRJ.js +21 -0
- package/dist/crypto-XS5XCMRJ.js.map +7 -0
- package/dist/helpers-UD7CG4WQ.js +18 -0
- package/dist/helpers-UD7CG4WQ.js.map +7 -0
- package/dist/http-codec.d.ts +72 -0
- package/dist/http-codec.js +25 -0
- package/dist/http-codec.js.map +7 -0
- package/dist/http-provider.d.ts +3243 -0
- package/dist/http-provider.js +37920 -0
- package/dist/http-provider.js.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +7 -0
- package/dist/mqtt-broker/node.d.ts +632 -0
- package/dist/mqtt-broker/node.js +355 -0
- package/dist/mqtt-broker/node.js.map +7 -0
- package/dist/mqtt-broker.d.ts +990 -0
- package/dist/mqtt-broker.js +913 -0
- package/dist/mqtt-broker.js.map +7 -0
- package/dist/openapi-metadata.d.ts +290 -0
- package/dist/openapi-metadata.js +28 -0
- package/dist/openapi-metadata.js.map +7 -0
- package/dist/openapi.d.ts +252 -0
- package/dist/openapi.js +45 -0
- package/dist/openapi.js.map +7 -0
- package/dist/preview/artifacts.d.ts +19 -0
- package/dist/preview/artifacts.js +40 -0
- package/dist/preview/artifacts.js.map +7 -0
- package/dist/preview/bridge.d.ts +21 -0
- package/dist/preview/bridge.js +9 -0
- package/dist/preview/bridge.js.map +7 -0
- package/dist/preview/harness.d.ts +12 -0
- package/dist/preview/harness.js +65 -0
- package/dist/preview/harness.js.map +7 -0
- package/dist/preview/host.d.ts +30 -0
- package/dist/preview/host.js +70 -0
- package/dist/preview/host.js.map +7 -0
- package/dist/service/admin.d.ts +106 -0
- package/dist/service/admin.js +340 -0
- package/dist/service/admin.js.map +7 -0
- package/dist/service.d.ts +2665 -0
- package/dist/service.js +264 -0
- package/dist/service.js.map +7 -0
- package/dist/sqlite.d.ts +69 -0
- package/dist/sqlite.js +19 -0
- package/dist/sqlite.js.map +7 -0
- package/dist/ui.d.ts +37 -0
- package/dist/ui.js +702 -0
- package/dist/ui.js.map +7 -0
- package/package.json +135 -4
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// ../sqlite/dist/default.js
|
|
2
|
+
import { Database } from "@crvouga/mockingbird-service-sqlite";
|
|
3
|
+
var createDefaultSqlite = () => new Database();
|
|
4
|
+
var resolveSqlite = (sqlite) => sqlite ?? createDefaultSqlite();
|
|
5
|
+
|
|
6
|
+
// ../sqlite/dist/migrate.js
|
|
7
|
+
var ensureMigrationsTable = (sqlite) => {
|
|
8
|
+
sqlite.exec(`
|
|
9
|
+
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
10
|
+
id TEXT PRIMARY KEY NOT NULL,
|
|
11
|
+
applied_at INTEGER NOT NULL
|
|
12
|
+
)
|
|
13
|
+
`);
|
|
14
|
+
};
|
|
15
|
+
var assertUniqueIds = (migrations) => {
|
|
16
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const { id } of migrations) {
|
|
18
|
+
if (seen.has(id))
|
|
19
|
+
throw new Error(`migrate: duplicate migration id "${id}"; ids must be unique`);
|
|
20
|
+
seen.add(id);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var migrate = (sqlite, migrations) => {
|
|
24
|
+
assertUniqueIds(migrations);
|
|
25
|
+
ensureMigrationsTable(sqlite);
|
|
26
|
+
const applied = new Set(sqlite.prepare("SELECT id FROM schema_migrations").all().map((row) => row.id));
|
|
27
|
+
const pending = migrations.filter((migration) => !applied.has(migration.id));
|
|
28
|
+
if (pending.length === 0)
|
|
29
|
+
return;
|
|
30
|
+
const insert = sqlite.prepare("INSERT INTO schema_migrations (id, applied_at) VALUES (?, ?)");
|
|
31
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
32
|
+
sqlite.transaction(() => {
|
|
33
|
+
for (const migration of pending) {
|
|
34
|
+
sqlite.exec(migration.sql);
|
|
35
|
+
insert.run(migration.id, now);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var listAppliedMigrations = (sqlite) => {
|
|
40
|
+
ensureMigrationsTable(sqlite);
|
|
41
|
+
return sqlite.prepare("SELECT id FROM schema_migrations ORDER BY applied_at ASC, rowid ASC").all().map((row) => row.id);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// ../sqlite/dist/schema.js
|
|
45
|
+
var CORE_MIGRATIONS = [
|
|
46
|
+
{
|
|
47
|
+
id: "20260322_core_records_sequences",
|
|
48
|
+
sql: `
|
|
49
|
+
CREATE TABLE IF NOT EXISTS mockingbird_records (
|
|
50
|
+
namespace TEXT NOT NULL,
|
|
51
|
+
collection TEXT NOT NULL,
|
|
52
|
+
id TEXT NOT NULL,
|
|
53
|
+
seq INTEGER NOT NULL,
|
|
54
|
+
value TEXT NOT NULL,
|
|
55
|
+
PRIMARY KEY (namespace, collection, id)
|
|
56
|
+
);
|
|
57
|
+
CREATE INDEX IF NOT EXISTS mockingbird_records_seq
|
|
58
|
+
ON mockingbird_records (namespace, collection, seq);
|
|
59
|
+
CREATE TABLE IF NOT EXISTS mockingbird_sequences (
|
|
60
|
+
namespace TEXT NOT NULL,
|
|
61
|
+
name TEXT NOT NULL,
|
|
62
|
+
kind TEXT NOT NULL,
|
|
63
|
+
value INTEGER NOT NULL,
|
|
64
|
+
PRIMARY KEY (namespace, name, kind)
|
|
65
|
+
);
|
|
66
|
+
`
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
var LEGACY_TABLES = [
|
|
70
|
+
["emulates_records", "mockingbird_records"],
|
|
71
|
+
["emulators_records", "mockingbird_records"],
|
|
72
|
+
["emulates_sequences", "mockingbird_sequences"],
|
|
73
|
+
["emulators_sequences", "mockingbird_sequences"]
|
|
74
|
+
];
|
|
75
|
+
var LEGACY_INDEXES = [
|
|
76
|
+
["emulates_records_seq", "mockingbird_records_seq"],
|
|
77
|
+
["emulators_records_seq", "mockingbird_records_seq"]
|
|
78
|
+
];
|
|
79
|
+
var namesOf = (sqlite, type) => new Set(sqlite.prepare("SELECT name FROM sqlite_master WHERE type = ?").all(type).map((row) => row.name));
|
|
80
|
+
var migrateCore = (sqlite) => {
|
|
81
|
+
migrate(sqlite, CORE_MIGRATIONS);
|
|
82
|
+
const tables = namesOf(sqlite, "table");
|
|
83
|
+
const indexes = namesOf(sqlite, "index");
|
|
84
|
+
sqlite.transaction(() => {
|
|
85
|
+
for (const [from, to] of LEGACY_TABLES) {
|
|
86
|
+
if (!tables.has(from) || tables.has(to))
|
|
87
|
+
continue;
|
|
88
|
+
sqlite.exec(`ALTER TABLE ${from} RENAME TO ${to}`);
|
|
89
|
+
tables.delete(from);
|
|
90
|
+
tables.add(to);
|
|
91
|
+
}
|
|
92
|
+
for (const [from, to] of LEGACY_INDEXES) {
|
|
93
|
+
if (!indexes.has(from) || indexes.has(to))
|
|
94
|
+
continue;
|
|
95
|
+
sqlite.exec(`DROP INDEX ${from}`);
|
|
96
|
+
sqlite.exec(`CREATE INDEX ${to} ON mockingbird_records (namespace, collection, seq)`);
|
|
97
|
+
indexes.delete(from);
|
|
98
|
+
indexes.add(to);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
var clearNamespace = (sqlite, namespace) => {
|
|
103
|
+
sqlite.transaction(() => {
|
|
104
|
+
sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ?").run(namespace);
|
|
105
|
+
sqlite.prepare("DELETE FROM mockingbird_sequences WHERE namespace = ?").run(namespace);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
createDefaultSqlite,
|
|
111
|
+
resolveSqlite,
|
|
112
|
+
migrate,
|
|
113
|
+
listAppliedMigrations,
|
|
114
|
+
CORE_MIGRATIONS,
|
|
115
|
+
migrateCore,
|
|
116
|
+
clearNamespace
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=chunk-2KDYLZXC.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../sqlite/src/default.ts", "../../sqlite/src/migrate.ts", "../../sqlite/src/schema.ts"],
|
|
4
|
+
"sourcesContent": ["import { Database } from \"@crvouga/mockingbird-service-sqlite\"\nimport type { SqliteClient } from \"./client.js\"\n\n/** Construct the default in-memory SQLite client (`@crvouga/mockingbird-service-sqlite`). */\nexport const createDefaultSqlite = (): SqliteClient => new Database()\n\n/** Use the injected client, or fall back to {@link createDefaultSqlite}. */\nexport const resolveSqlite = (sqlite?: SqliteClient): SqliteClient =>\n sqlite ?? createDefaultSqlite()\n", "import type { SqliteClient } from \"./client.js\"\n\n/** One named, ordered schema change applied exactly once per client. */\nexport type Migration = {\n /** Stable id stored in `schema_migrations`. Must be unique across the list. */\n id: string\n sql: string\n}\n\nconst ensureMigrationsTable = (sqlite: SqliteClient) => {\n sqlite.exec(`\n CREATE TABLE IF NOT EXISTS schema_migrations (\n id TEXT PRIMARY KEY NOT NULL,\n applied_at INTEGER NOT NULL\n )\n `)\n}\n\nconst assertUniqueIds = (migrations: readonly Migration[]) => {\n const seen = new Set<string>()\n for (const { id } of migrations) {\n if (seen.has(id)) throw new Error(`migrate: duplicate migration id \"${id}\"; ids must be unique`)\n seen.add(id)\n }\n}\n\n/**\n * Apply pending migrations in order inside a single transaction.\n *\n * Idempotent: already-applied ids are skipped. Re-running with the same list\n * is a no-op after the first successful boot.\n *\n * @throws {Error} If two migrations in the list share an id; nothing is applied.\n */\nexport const migrate = (sqlite: SqliteClient, migrations: readonly Migration[]): void => {\n assertUniqueIds(migrations)\n ensureMigrationsTable(sqlite)\n const applied = new Set(\n sqlite\n .prepare(\"SELECT id FROM schema_migrations\")\n .all<{ id: string }>()\n .map((row) => row.id),\n )\n const pending = migrations.filter((migration) => !applied.has(migration.id))\n if (pending.length === 0) return\n\n const insert = sqlite.prepare(\"INSERT INTO schema_migrations (id, applied_at) VALUES (?, ?)\")\n const now = Math.floor(Date.now() / 1000)\n sqlite.transaction(() => {\n for (const migration of pending) {\n sqlite.exec(migration.sql)\n insert.run(migration.id, now)\n }\n })\n}\n\n/**\n * Applied migration ids in application order: by `applied_at`, then `rowid`.\n * `schema_migrations` is a rowid table, so `rowid` follows insertion order and\n * breaks same-second ties in the order the migrations ran.\n */\nexport const listAppliedMigrations = (sqlite: SqliteClient): string[] => {\n ensureMigrationsTable(sqlite)\n return sqlite\n .prepare(\"SELECT id FROM schema_migrations ORDER BY applied_at ASC, rowid ASC\")\n .all<{ id: string }>()\n .map((row) => row.id)\n}\n", "import type { SqliteClient } from \"./client.js\"\nimport { type Migration, migrate } from \"./migrate.js\"\n\n/**\n * Core Mockingbird service schema: namespaced JSON records and counters.\n *\n * Applied on every service boot via {@link migrateCore}.\n */\nexport const CORE_MIGRATIONS: readonly Migration[] = [\n {\n id: \"20260322_core_records_sequences\",\n sql: `\n CREATE TABLE IF NOT EXISTS mockingbird_records (\n namespace TEXT NOT NULL,\n collection TEXT NOT NULL,\n id TEXT NOT NULL,\n seq INTEGER NOT NULL,\n value TEXT NOT NULL,\n PRIMARY KEY (namespace, collection, id)\n );\n CREATE INDEX IF NOT EXISTS mockingbird_records_seq\n ON mockingbird_records (namespace, collection, seq);\n CREATE TABLE IF NOT EXISTS mockingbird_sequences (\n namespace TEXT NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n value INTEGER NOT NULL,\n PRIMARY KEY (namespace, name, kind)\n );\n `,\n },\n]\n\n/**\n * Table and index names from the unfinished product rename.\n * Renamed in place so a database created under those names keeps its rows.\n */\nconst LEGACY_TABLES = [\n [\"emulates_records\", \"mockingbird_records\"],\n [\"emulators_records\", \"mockingbird_records\"],\n [\"emulates_sequences\", \"mockingbird_sequences\"],\n [\"emulators_sequences\", \"mockingbird_sequences\"],\n] as const\nconst LEGACY_INDEXES = [\n [\"emulates_records_seq\", \"mockingbird_records_seq\"],\n [\"emulators_records_seq\", \"mockingbird_records_seq\"],\n] as const\n\nconst namesOf = (sqlite: SqliteClient, type: \"table\" | \"index\"): Set<string> =>\n new Set(\n sqlite\n .prepare(\"SELECT name FROM sqlite_master WHERE type = ?\")\n .all<{ name: string }>(type)\n .map((row) => row.name),\n )\n\n/** Apply {@link CORE_MIGRATIONS}, then rename a database that still uses the former table names. */\nexport const migrateCore = (sqlite: SqliteClient): void => {\n migrate(sqlite, CORE_MIGRATIONS)\n const tables = namesOf(sqlite, \"table\")\n const indexes = namesOf(sqlite, \"index\")\n sqlite.transaction(() => {\n for (const [from, to] of LEGACY_TABLES) {\n if (!tables.has(from) || tables.has(to)) continue\n sqlite.exec(`ALTER TABLE ${from} RENAME TO ${to}`)\n tables.delete(from)\n tables.add(to)\n }\n for (const [from, to] of LEGACY_INDEXES) {\n if (!indexes.has(from) || indexes.has(to)) continue\n // The sqlite port accepts ALTER TABLE, not ALTER INDEX.\n sqlite.exec(`DROP INDEX ${from}`)\n sqlite.exec(`CREATE INDEX ${to} ON mockingbird_records (namespace, collection, seq)`)\n indexes.delete(from)\n indexes.add(to)\n }\n })\n}\n\n/** Delete every record and sequence belonging to `namespace`. */\nexport const clearNamespace = (sqlite: SqliteClient, namespace: string): void => {\n sqlite.transaction(() => {\n sqlite.prepare(\"DELETE FROM mockingbird_records WHERE namespace = ?\").run(namespace)\n sqlite.prepare(\"DELETE FROM mockingbird_sequences WHERE namespace = ?\").run(namespace)\n })\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB;AAIlB,IAAM,sBAAsB,MAAoB,IAAI,SAAQ;AAG5D,IAAM,gBAAgB,CAAC,WAC5B,UAAU,oBAAmB;;;ACC/B,IAAM,wBAAwB,CAAC,WAAwB;AACrD,SAAO,KAAK;;;;;GAKX;AACH;AAEA,IAAM,kBAAkB,CAAC,eAAoC;AAC3D,QAAM,OAAO,oBAAI,IAAG;AACpB,aAAW,EAAE,GAAE,KAAM,YAAY;AAC/B,QAAI,KAAK,IAAI,EAAE;AAAG,YAAM,IAAI,MAAM,oCAAoC,EAAE,uBAAuB;AAC/F,SAAK,IAAI,EAAE;EACb;AACF;AAUO,IAAM,UAAU,CAAC,QAAsB,eAA0C;AACtF,kBAAgB,UAAU;AAC1B,wBAAsB,MAAM;AAC5B,QAAM,UAAU,IAAI,IAClB,OACG,QAAQ,kCAAkC,EAC1C,IAAG,EACH,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;AAEzB,QAAM,UAAU,WA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