@tinycloud/cli 0.7.2-beta.0 → 0.7.3-beta.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/dist/index.js +981 -909
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -36401,324 +36401,831 @@ var coerce = {
|
|
|
36401
36401
|
};
|
|
36402
36402
|
var NEVER = INVALID;
|
|
36403
36403
|
|
|
36404
|
-
// ../
|
|
36405
|
-
var
|
|
36406
|
-
|
|
36407
|
-
|
|
36408
|
-
|
|
36409
|
-
|
|
36410
|
-
|
|
36411
|
-
|
|
36412
|
-
|
|
36413
|
-
|
|
36414
|
-
|
|
36415
|
-
|
|
36416
|
-
|
|
36417
|
-
|
|
36418
|
-
|
|
36419
|
-
|
|
36420
|
-
|
|
36421
|
-
|
|
36422
|
-
|
|
36423
|
-
|
|
36424
|
-
|
|
36425
|
-
|
|
36426
|
-
|
|
36427
|
-
|
|
36428
|
-
|
|
36429
|
-
|
|
36430
|
-
|
|
36431
|
-
|
|
36432
|
-
|
|
36433
|
-
|
|
36434
|
-
|
|
36435
|
-
|
|
36436
|
-
|
|
36437
|
-
|
|
36438
|
-
|
|
36439
|
-
|
|
36440
|
-
}
|
|
36441
|
-
|
|
36442
|
-
|
|
36443
|
-
|
|
36444
|
-
|
|
36445
|
-
|
|
36446
|
-
|
|
36447
|
-
|
|
36448
|
-
var TelemetryEvents = {
|
|
36449
|
-
SPAN: "telemetry.span",
|
|
36450
|
-
SERVICE_REQUEST: "service.request",
|
|
36451
|
-
SERVICE_RESPONSE: "service.response",
|
|
36452
|
-
SERVICE_ERROR: "service.error",
|
|
36453
|
-
SERVICE_RETRY: "service.retry",
|
|
36454
|
-
SESSION_CHANGED: "session.changed",
|
|
36455
|
-
SESSION_EXPIRED: "session.expired"
|
|
36456
|
-
};
|
|
36457
|
-
function ok(data) {
|
|
36458
|
-
return { ok: true, data };
|
|
36459
|
-
}
|
|
36460
|
-
function err(error) {
|
|
36461
|
-
return { ok: false, error };
|
|
36462
|
-
}
|
|
36463
|
-
function serviceError(code2, message, service, options) {
|
|
36464
|
-
return {
|
|
36465
|
-
code: code2,
|
|
36466
|
-
message,
|
|
36467
|
-
service,
|
|
36468
|
-
cause: options?.cause,
|
|
36469
|
-
meta: options?.meta
|
|
36470
|
-
};
|
|
36471
|
-
}
|
|
36472
|
-
var DEBUG_FLAG = "TinyCloud_debug";
|
|
36473
|
-
var MAX_EVENTS = 1e3;
|
|
36474
|
-
function getGlobal() {
|
|
36475
|
-
return globalThis;
|
|
36476
|
-
}
|
|
36477
|
-
function nowMs() {
|
|
36478
|
-
const performanceNow = globalThis.performance?.now?.bind(globalThis.performance);
|
|
36479
|
-
return typeof performanceNow === "function" ? performanceNow() : Date.now();
|
|
36480
|
-
}
|
|
36481
|
-
function isTrue(value) {
|
|
36482
|
-
return value === true || value === "true" || value === "1";
|
|
36483
|
-
}
|
|
36484
|
-
function getProcessDebugFlag() {
|
|
36485
|
-
const processLike = globalThis.process;
|
|
36486
|
-
return processLike?.env?.[DEBUG_FLAG];
|
|
36487
|
-
}
|
|
36488
|
-
function isBrowserWindow() {
|
|
36489
|
-
const global2 = getGlobal();
|
|
36490
|
-
return global2.window === globalThis;
|
|
36404
|
+
// ../bootstrap/dist/generated/capabilities.js
|
|
36405
|
+
var CAPABILITIES = [
|
|
36406
|
+
{ urn: "tinycloud.kv/get", service: "tinycloud.kv", status: "active" },
|
|
36407
|
+
{ urn: "tinycloud.kv/list", service: "tinycloud.kv", status: "active" },
|
|
36408
|
+
{ urn: "tinycloud.kv/metadata", service: "tinycloud.kv", status: "active" },
|
|
36409
|
+
{ urn: "tinycloud.kv/put", service: "tinycloud.kv", status: "active" },
|
|
36410
|
+
{ urn: "tinycloud.kv/del", service: "tinycloud.kv", status: "active" },
|
|
36411
|
+
{ urn: "tinycloud.kv/delete", service: "tinycloud.kv", status: "deprecated-alias", aliasOf: "tinycloud.kv/del" },
|
|
36412
|
+
{ urn: "tinycloud.sql/read", service: "tinycloud.sql", status: "active" },
|
|
36413
|
+
{ urn: "tinycloud.sql/select", service: "tinycloud.sql", status: "deprecated-alias", aliasOf: "tinycloud.sql/read" },
|
|
36414
|
+
{ urn: "tinycloud.sql/write", service: "tinycloud.sql", status: "active" },
|
|
36415
|
+
{ urn: "tinycloud.sql/schema", service: "tinycloud.sql", status: "active" },
|
|
36416
|
+
{ urn: "tinycloud.sql/admin", service: "tinycloud.sql", status: "active", implies: ["tinycloud.sql/schema"] },
|
|
36417
|
+
{ urn: "tinycloud.sql/*", service: "tinycloud.sql", status: "active", implies: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/schema", "tinycloud.sql/admin"] },
|
|
36418
|
+
{ urn: "tinycloud.duckdb/read", service: "tinycloud.duckdb", status: "active" },
|
|
36419
|
+
{ urn: "tinycloud.duckdb/write", service: "tinycloud.duckdb", status: "active" },
|
|
36420
|
+
{ urn: "tinycloud.duckdb/admin", service: "tinycloud.duckdb", status: "active" },
|
|
36421
|
+
{ urn: "tinycloud.duckdb/import", service: "tinycloud.duckdb", status: "active" },
|
|
36422
|
+
{ urn: "tinycloud.duckdb/export", service: "tinycloud.duckdb", status: "active" },
|
|
36423
|
+
{ urn: "tinycloud.duckdb/select", service: "tinycloud.duckdb", status: "deprecated-alias", aliasOf: "tinycloud.duckdb/read" },
|
|
36424
|
+
{ urn: "tinycloud.duckdb/*", service: "tinycloud.duckdb", status: "active", implies: ["tinycloud.duckdb/read", "tinycloud.duckdb/write", "tinycloud.duckdb/admin", "tinycloud.duckdb/import", "tinycloud.duckdb/export"] },
|
|
36425
|
+
{ urn: "tinycloud.capabilities/read", service: "tinycloud.capabilities", status: "active" },
|
|
36426
|
+
{ urn: "tinycloud.hooks/subscribe", service: "tinycloud.hooks", status: "active" },
|
|
36427
|
+
{ urn: "tinycloud.hooks/register", service: "tinycloud.hooks", status: "active" },
|
|
36428
|
+
{ urn: "tinycloud.hooks/list", service: "tinycloud.hooks", status: "active" },
|
|
36429
|
+
{ urn: "tinycloud.hooks/unregister", service: "tinycloud.hooks", status: "active" },
|
|
36430
|
+
{ urn: "tinycloud.encryption/decrypt", service: "tinycloud.encryption", status: "active" },
|
|
36431
|
+
{ urn: "tinycloud.encryption/network.create", service: "tinycloud.encryption", status: "active" },
|
|
36432
|
+
{ urn: "tinycloud.encryption/network.revoke", service: "tinycloud.encryption", status: "active" },
|
|
36433
|
+
{ urn: "tinycloud.space/host", service: "tinycloud.space", status: "active" },
|
|
36434
|
+
{ urn: "tinycloud.space/create", service: "tinycloud.space", status: "active" },
|
|
36435
|
+
{ urn: "tinycloud.space/list", service: "tinycloud.space", status: "active" },
|
|
36436
|
+
{ urn: "tinycloud.space/info", service: "tinycloud.space", status: "active" },
|
|
36437
|
+
{ urn: "tinycloud.vfs/get", service: "tinycloud.vfs", status: "reserved" },
|
|
36438
|
+
{ urn: "tinycloud.vfs/list", service: "tinycloud.vfs", status: "reserved" },
|
|
36439
|
+
{ urn: "tinycloud.vfs/metadata", service: "tinycloud.vfs", status: "reserved" },
|
|
36440
|
+
{ urn: "tinycloud.vfs/put", service: "tinycloud.vfs", status: "reserved" },
|
|
36441
|
+
{ urn: "tinycloud.vfs/delete", service: "tinycloud.vfs", status: "reserved" }
|
|
36442
|
+
];
|
|
36443
|
+
|
|
36444
|
+
// ../bootstrap/dist/capabilities.js
|
|
36445
|
+
function actionKey(action) {
|
|
36446
|
+
if (action === "*") return "ALL";
|
|
36447
|
+
return action.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
36491
36448
|
}
|
|
36492
|
-
function
|
|
36493
|
-
|
|
36494
|
-
return void 0;
|
|
36495
|
-
}
|
|
36496
|
-
try {
|
|
36497
|
-
return globalThis.localStorage;
|
|
36498
|
-
} catch {
|
|
36499
|
-
return void 0;
|
|
36500
|
-
}
|
|
36449
|
+
function serviceOf(urn) {
|
|
36450
|
+
return urn.slice("tinycloud.".length, urn.indexOf("/"));
|
|
36501
36451
|
}
|
|
36502
|
-
function
|
|
36503
|
-
|
|
36504
|
-
if (!storage) {
|
|
36505
|
-
return void 0;
|
|
36506
|
-
}
|
|
36507
|
-
try {
|
|
36508
|
-
return storage.getItem(DEBUG_FLAG);
|
|
36509
|
-
} catch {
|
|
36510
|
-
return void 0;
|
|
36511
|
-
}
|
|
36452
|
+
function actionOf(urn) {
|
|
36453
|
+
return urn.slice(urn.indexOf("/") + 1);
|
|
36512
36454
|
}
|
|
36513
|
-
function
|
|
36514
|
-
const
|
|
36515
|
-
|
|
36516
|
-
|
|
36455
|
+
function deriveServiceConstants(service) {
|
|
36456
|
+
const out = {};
|
|
36457
|
+
for (const entry of CAPABILITIES) {
|
|
36458
|
+
if (serviceOf(entry.urn) !== service) continue;
|
|
36459
|
+
out[actionKey(actionOf(entry.urn))] = entry.urn;
|
|
36517
36460
|
}
|
|
36518
|
-
|
|
36519
|
-
if (enabled) {
|
|
36520
|
-
storage.setItem(DEBUG_FLAG, "true");
|
|
36521
|
-
} else {
|
|
36522
|
-
storage.removeItem(DEBUG_FLAG);
|
|
36523
|
-
}
|
|
36524
|
-
} catch {
|
|
36525
|
-
}
|
|
36526
|
-
}
|
|
36527
|
-
function shouldStartEnabled() {
|
|
36528
|
-
const global2 = getGlobal();
|
|
36529
|
-
return isTrue(global2[DEBUG_FLAG]) || isTrue(getStoredDebugFlag()) || isTrue(getProcessDebugFlag());
|
|
36461
|
+
return out;
|
|
36530
36462
|
}
|
|
36531
|
-
var
|
|
36532
|
-
|
|
36533
|
-
|
|
36534
|
-
|
|
36535
|
-
|
|
36536
|
-
|
|
36537
|
-
|
|
36538
|
-
|
|
36539
|
-
|
|
36540
|
-
|
|
36541
|
-
|
|
36542
|
-
|
|
36543
|
-
|
|
36544
|
-
|
|
36545
|
-
|
|
36463
|
+
var KV = deriveServiceConstants("kv");
|
|
36464
|
+
var SQL = {
|
|
36465
|
+
...deriveServiceConstants("sql"),
|
|
36466
|
+
EXECUTE: "tinycloud.sql/execute",
|
|
36467
|
+
EXPORT: "tinycloud.sql/export"
|
|
36468
|
+
};
|
|
36469
|
+
var DUCKDB = {
|
|
36470
|
+
...deriveServiceConstants("duckdb"),
|
|
36471
|
+
DESCRIBE: "tinycloud.duckdb/describe",
|
|
36472
|
+
EXECUTE: "tinycloud.duckdb/execute"
|
|
36473
|
+
};
|
|
36474
|
+
var CAPABILITIES2 = deriveServiceConstants("capabilities");
|
|
36475
|
+
var HOOKS = deriveServiceConstants("hooks");
|
|
36476
|
+
var ENCRYPTION = deriveServiceConstants("encryption");
|
|
36477
|
+
var SPACE = deriveServiceConstants("space");
|
|
36478
|
+
|
|
36479
|
+
// ../bootstrap/dist/index.js
|
|
36480
|
+
var DEFAULT_MANIFEST_SPACE = "applications";
|
|
36481
|
+
var ACCOUNT_REGISTRY_SPACE = "account";
|
|
36482
|
+
var ACCOUNT_REGISTRY_PATH = "applications/";
|
|
36483
|
+
var SECRETS_SPACE = "secrets";
|
|
36484
|
+
var BOOTSTRAP_DEFAULT_SPACE = "default";
|
|
36485
|
+
var BOOTSTRAP_PUBLIC_SPACE = "public";
|
|
36486
|
+
var BOOTSTRAP_ENCRYPTION_NETWORK_NAME = "default";
|
|
36487
|
+
var BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE = `urn:tinycloud:encryption:{ownerDid}:${BOOTSTRAP_ENCRYPTION_NETWORK_NAME}`;
|
|
36488
|
+
var DEFAULT_EXPIRY_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
36489
|
+
var VAULT_PERMISSION_SERVICE = "tinycloud.vault";
|
|
36490
|
+
var ENCRYPTION_PERMISSION_SERVICE = "tinycloud.encryption";
|
|
36491
|
+
var ENCRYPTION_MANIFEST_SPACE = "encryption";
|
|
36492
|
+
var NETWORK_CREATE_ACTION = ENCRYPTION.NETWORK_CREATE;
|
|
36493
|
+
var BOOTSTRAP_SPACE_NAMES = [
|
|
36494
|
+
BOOTSTRAP_DEFAULT_SPACE,
|
|
36495
|
+
DEFAULT_MANIFEST_SPACE,
|
|
36496
|
+
ACCOUNT_REGISTRY_SPACE,
|
|
36497
|
+
SECRETS_SPACE,
|
|
36498
|
+
BOOTSTRAP_PUBLIC_SPACE
|
|
36499
|
+
];
|
|
36500
|
+
var TINYCLOUD_DEFAULT_SPACE_MANIFEST = {
|
|
36501
|
+
app_id: "xyz.tinycloud.default",
|
|
36502
|
+
name: "TinyCloud Default Space",
|
|
36503
|
+
space: BOOTSTRAP_DEFAULT_SPACE,
|
|
36504
|
+
prefix: "",
|
|
36505
|
+
defaults: false,
|
|
36506
|
+
includePublicSpace: false,
|
|
36507
|
+
permissions: [
|
|
36508
|
+
{
|
|
36509
|
+
service: "tinycloud.kv",
|
|
36510
|
+
space: BOOTSTRAP_DEFAULT_SPACE,
|
|
36511
|
+
// Empty path = whole service on this space. Do NOT use "/": the recap
|
|
36512
|
+
// encoder joins it as `<space>/<service>//`, which the node's byte-prefix
|
|
36513
|
+
// resource matching can never extend (real paths start `<service>/x…`).
|
|
36514
|
+
path: "",
|
|
36515
|
+
actions: ["get", "put", "del", "list", "metadata"]
|
|
36516
|
+
},
|
|
36517
|
+
{
|
|
36518
|
+
service: "tinycloud.sql",
|
|
36519
|
+
space: BOOTSTRAP_DEFAULT_SPACE,
|
|
36520
|
+
path: "",
|
|
36521
|
+
actions: ["read", "write"]
|
|
36546
36522
|
}
|
|
36547
|
-
|
|
36548
|
-
|
|
36549
|
-
|
|
36550
|
-
|
|
36551
|
-
|
|
36552
|
-
|
|
36553
|
-
|
|
36554
|
-
|
|
36523
|
+
]
|
|
36524
|
+
};
|
|
36525
|
+
var TINYCLOUD_APPLICATIONS_SPACE_MANIFEST = {
|
|
36526
|
+
app_id: "xyz.tinycloud.applications",
|
|
36527
|
+
name: "TinyCloud Applications Space",
|
|
36528
|
+
space: DEFAULT_MANIFEST_SPACE,
|
|
36529
|
+
prefix: "",
|
|
36530
|
+
defaults: false,
|
|
36531
|
+
includePublicSpace: false,
|
|
36532
|
+
permissions: [
|
|
36533
|
+
{
|
|
36534
|
+
service: "tinycloud.kv",
|
|
36535
|
+
space: DEFAULT_MANIFEST_SPACE,
|
|
36536
|
+
// Empty path = whole service on this space. Do NOT use "/": the recap
|
|
36537
|
+
// encoder joins it as `<space>/<service>//`, which the node's byte-prefix
|
|
36538
|
+
// resource matching can never extend (real paths start `<service>/x…`).
|
|
36539
|
+
path: "",
|
|
36540
|
+
actions: ["get", "put", "del", "list", "metadata"]
|
|
36541
|
+
},
|
|
36542
|
+
{
|
|
36543
|
+
service: "tinycloud.sql",
|
|
36544
|
+
space: DEFAULT_MANIFEST_SPACE,
|
|
36545
|
+
path: "",
|
|
36546
|
+
actions: ["read", "write"]
|
|
36555
36547
|
}
|
|
36556
|
-
|
|
36557
|
-
|
|
36558
|
-
|
|
36559
|
-
|
|
36560
|
-
|
|
36561
|
-
|
|
36562
|
-
|
|
36563
|
-
|
|
36564
|
-
|
|
36565
|
-
|
|
36548
|
+
]
|
|
36549
|
+
};
|
|
36550
|
+
var TINYCLOUD_ACCOUNT_SPACE_MANIFEST = {
|
|
36551
|
+
app_id: "xyz.tinycloud.account",
|
|
36552
|
+
name: "TinyCloud Account Registry",
|
|
36553
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36554
|
+
prefix: "",
|
|
36555
|
+
defaults: false,
|
|
36556
|
+
includePublicSpace: false,
|
|
36557
|
+
permissions: [
|
|
36558
|
+
{
|
|
36559
|
+
service: "tinycloud.kv",
|
|
36560
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36561
|
+
path: "applications/",
|
|
36562
|
+
actions: ["get", "put", "list"]
|
|
36563
|
+
},
|
|
36564
|
+
{
|
|
36565
|
+
service: "tinycloud.kv",
|
|
36566
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36567
|
+
path: "spaces/",
|
|
36568
|
+
actions: ["get", "put", "list"]
|
|
36569
|
+
},
|
|
36570
|
+
{
|
|
36571
|
+
service: "tinycloud.sql",
|
|
36572
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36573
|
+
path: "account",
|
|
36574
|
+
actions: ["read", "write", "schema"]
|
|
36566
36575
|
}
|
|
36567
|
-
|
|
36568
|
-
|
|
36569
|
-
|
|
36570
|
-
|
|
36571
|
-
|
|
36572
|
-
|
|
36573
|
-
|
|
36574
|
-
|
|
36576
|
+
]
|
|
36577
|
+
};
|
|
36578
|
+
var TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST = {
|
|
36579
|
+
app_id: "xyz.tinycloud.secrets",
|
|
36580
|
+
name: "TinyCloud Secrets",
|
|
36581
|
+
space: SECRETS_SPACE,
|
|
36582
|
+
prefix: "",
|
|
36583
|
+
defaults: false,
|
|
36584
|
+
includePublicSpace: false,
|
|
36585
|
+
permissions: [
|
|
36586
|
+
{
|
|
36587
|
+
service: "tinycloud.vault",
|
|
36588
|
+
space: SECRETS_SPACE,
|
|
36589
|
+
path: "secrets/",
|
|
36590
|
+
actions: ["read"],
|
|
36591
|
+
skipPrefix: true
|
|
36592
|
+
},
|
|
36593
|
+
{
|
|
36594
|
+
service: "tinycloud.kv",
|
|
36595
|
+
space: SECRETS_SPACE,
|
|
36596
|
+
path: "variables",
|
|
36597
|
+
actions: ["list", "metadata"],
|
|
36598
|
+
skipPrefix: true
|
|
36599
|
+
},
|
|
36600
|
+
{
|
|
36601
|
+
service: "tinycloud.kv",
|
|
36602
|
+
space: SECRETS_SPACE,
|
|
36603
|
+
path: "variables/",
|
|
36604
|
+
actions: ["get", "put", "del", "list", "metadata"],
|
|
36605
|
+
skipPrefix: true
|
|
36606
|
+
},
|
|
36607
|
+
{
|
|
36608
|
+
service: "tinycloud.sql",
|
|
36609
|
+
space: SECRETS_SPACE,
|
|
36610
|
+
path: "default",
|
|
36611
|
+
actions: ["read", "write", "schema"],
|
|
36612
|
+
skipPrefix: true
|
|
36613
|
+
},
|
|
36614
|
+
{
|
|
36615
|
+
service: "tinycloud.capabilities",
|
|
36616
|
+
space: SECRETS_SPACE,
|
|
36617
|
+
path: "",
|
|
36618
|
+
actions: ["read"],
|
|
36619
|
+
skipPrefix: true
|
|
36620
|
+
}
|
|
36621
|
+
]
|
|
36622
|
+
};
|
|
36623
|
+
var TINYCLOUD_PUBLIC_SPACE_MANIFEST = {
|
|
36624
|
+
app_id: "xyz.tinycloud.public",
|
|
36625
|
+
name: "TinyCloud Public Space",
|
|
36626
|
+
space: BOOTSTRAP_PUBLIC_SPACE,
|
|
36627
|
+
prefix: "",
|
|
36628
|
+
defaults: false,
|
|
36629
|
+
includePublicSpace: false,
|
|
36630
|
+
permissions: [
|
|
36631
|
+
{
|
|
36632
|
+
service: "tinycloud.kv",
|
|
36633
|
+
space: BOOTSTRAP_PUBLIC_SPACE,
|
|
36634
|
+
path: "",
|
|
36635
|
+
actions: ["get", "list", "metadata"]
|
|
36636
|
+
}
|
|
36637
|
+
]
|
|
36638
|
+
};
|
|
36639
|
+
var BOOTSTRAP_SPACE_MANIFESTS = {
|
|
36640
|
+
[BOOTSTRAP_DEFAULT_SPACE]: TINYCLOUD_DEFAULT_SPACE_MANIFEST,
|
|
36641
|
+
[DEFAULT_MANIFEST_SPACE]: TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
|
|
36642
|
+
[ACCOUNT_REGISTRY_SPACE]: TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
|
|
36643
|
+
[SECRETS_SPACE]: TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
|
|
36644
|
+
[BOOTSTRAP_PUBLIC_SPACE]: TINYCLOUD_PUBLIC_SPACE_MANIFEST
|
|
36645
|
+
};
|
|
36646
|
+
var BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS = [
|
|
36647
|
+
TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST
|
|
36648
|
+
];
|
|
36649
|
+
var ACCOUNT_INDEX_SCHEMA = [
|
|
36650
|
+
`CREATE TABLE IF NOT EXISTS applications (
|
|
36651
|
+
app_id TEXT PRIMARY KEY,
|
|
36652
|
+
name TEXT,
|
|
36653
|
+
description TEXT,
|
|
36654
|
+
updated_at TEXT,
|
|
36655
|
+
manifest_json TEXT NOT NULL
|
|
36656
|
+
)`,
|
|
36657
|
+
`CREATE TABLE IF NOT EXISTS application_state (
|
|
36658
|
+
app_id TEXT PRIMARY KEY,
|
|
36659
|
+
manifest_hash TEXT NOT NULL,
|
|
36660
|
+
indexed_at TEXT NOT NULL
|
|
36661
|
+
)`,
|
|
36662
|
+
`CREATE TABLE IF NOT EXISTS spaces (
|
|
36663
|
+
space_id TEXT PRIMARY KEY,
|
|
36664
|
+
name TEXT NOT NULL,
|
|
36665
|
+
owner_did TEXT NOT NULL,
|
|
36666
|
+
type TEXT NOT NULL,
|
|
36667
|
+
permissions_json TEXT NOT NULL,
|
|
36668
|
+
status TEXT NOT NULL,
|
|
36669
|
+
registered_at TEXT,
|
|
36670
|
+
updated_at TEXT NOT NULL,
|
|
36671
|
+
expires_at TEXT
|
|
36672
|
+
)`,
|
|
36673
|
+
`CREATE TABLE IF NOT EXISTS delegations (
|
|
36674
|
+
cid TEXT PRIMARY KEY,
|
|
36675
|
+
direction TEXT NOT NULL,
|
|
36676
|
+
space_id TEXT NOT NULL,
|
|
36677
|
+
space_name TEXT,
|
|
36678
|
+
counterparty_did TEXT NOT NULL,
|
|
36679
|
+
delegate_did TEXT NOT NULL,
|
|
36680
|
+
delegator_did TEXT,
|
|
36681
|
+
path TEXT NOT NULL,
|
|
36682
|
+
actions_json TEXT NOT NULL,
|
|
36683
|
+
expiry TEXT NOT NULL,
|
|
36684
|
+
status TEXT NOT NULL,
|
|
36685
|
+
created_at TEXT,
|
|
36686
|
+
updated_at TEXT NOT NULL
|
|
36687
|
+
)`,
|
|
36688
|
+
`CREATE TABLE IF NOT EXISTS sync_state (
|
|
36689
|
+
source TEXT PRIMARY KEY,
|
|
36690
|
+
synced_at TEXT NOT NULL,
|
|
36691
|
+
count INTEGER NOT NULL
|
|
36692
|
+
)`,
|
|
36693
|
+
"CREATE INDEX IF NOT EXISTS idx_delegations_direction ON delegations(direction)",
|
|
36694
|
+
"CREATE INDEX IF NOT EXISTS idx_delegations_space ON delegations(space_id)",
|
|
36695
|
+
"CREATE INDEX IF NOT EXISTS idx_delegations_counterparty ON delegations(counterparty_did)",
|
|
36696
|
+
"CREATE INDEX IF NOT EXISTS idx_spaces_owner ON spaces(owner_did)",
|
|
36697
|
+
"CREATE INDEX IF NOT EXISTS idx_spaces_type ON spaces(type)"
|
|
36698
|
+
];
|
|
36699
|
+
var SECRET_RECORDS_SCHEMA = [
|
|
36700
|
+
`CREATE TABLE IF NOT EXISTS secret_records (
|
|
36701
|
+
scope TEXT NOT NULL,
|
|
36702
|
+
name TEXT NOT NULL,
|
|
36703
|
+
provider_id TEXT,
|
|
36704
|
+
custom_note TEXT,
|
|
36705
|
+
created_at TEXT NOT NULL,
|
|
36706
|
+
updated_at TEXT NOT NULL,
|
|
36707
|
+
last_tested TEXT,
|
|
36708
|
+
test_status TEXT,
|
|
36709
|
+
test_message TEXT,
|
|
36710
|
+
PRIMARY KEY(scope, name)
|
|
36711
|
+
)`
|
|
36712
|
+
];
|
|
36713
|
+
var BOOTSTRAP_MANIFEST = {
|
|
36714
|
+
spaces: BOOTSTRAP_SPACE_NAMES.map((name2) => ({
|
|
36715
|
+
name: name2,
|
|
36716
|
+
manifest: BOOTSTRAP_SPACE_MANIFESTS[name2],
|
|
36717
|
+
persistedAsApplication: name2 === SECRETS_SPACE
|
|
36718
|
+
})),
|
|
36719
|
+
applications: BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS,
|
|
36720
|
+
accountIndexSchema: ACCOUNT_INDEX_SCHEMA,
|
|
36721
|
+
secretRecordsSchema: SECRET_RECORDS_SCHEMA,
|
|
36722
|
+
encryptionNetwork: {
|
|
36723
|
+
name: BOOTSTRAP_ENCRYPTION_NETWORK_NAME
|
|
36575
36724
|
}
|
|
36576
|
-
|
|
36577
|
-
|
|
36578
|
-
|
|
36725
|
+
};
|
|
36726
|
+
function cloneManifest(manifest) {
|
|
36727
|
+
return {
|
|
36728
|
+
...manifest,
|
|
36729
|
+
permissions: manifest.permissions?.map((permission) => ({
|
|
36730
|
+
...permission,
|
|
36731
|
+
actions: [...permission.actions]
|
|
36732
|
+
}))
|
|
36733
|
+
};
|
|
36734
|
+
}
|
|
36735
|
+
function actionUrn(service, action) {
|
|
36736
|
+
return action.includes("/") ? action : `${service}/${action}`;
|
|
36737
|
+
}
|
|
36738
|
+
function applyPrefix(prefix, path, skipPrefix) {
|
|
36739
|
+
if (skipPrefix === true || prefix === "" || path === "") {
|
|
36740
|
+
return path;
|
|
36741
|
+
}
|
|
36742
|
+
if (path === "/") {
|
|
36743
|
+
return `${prefix}/`;
|
|
36744
|
+
}
|
|
36745
|
+
const trimmedPrefix = prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
36746
|
+
const trimmedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
36747
|
+
return `${trimmedPrefix}/${trimmedPath}`;
|
|
36748
|
+
}
|
|
36749
|
+
function expandVaultPermission(entry) {
|
|
36750
|
+
return entry.actions.map((action) => {
|
|
36751
|
+
const normalized = action.startsWith("tinycloud.vault/") ? action.slice("tinycloud.vault/".length) : action.startsWith("tinycloud.kv/") ? action.slice("tinycloud.kv/".length) : action;
|
|
36752
|
+
const mapped = normalized === "read" || normalized === "get" ? KV.GET : normalized === "write" || normalized === "put" ? KV.PUT : normalized === "delete" || normalized === "del" ? KV.DEL : normalized === "list" ? KV.LIST : normalized === "metadata" ? KV.METADATA : void 0;
|
|
36753
|
+
if (mapped === void 0) {
|
|
36754
|
+
throw new Error(`unknown vault action ${JSON.stringify(action)}`);
|
|
36579
36755
|
}
|
|
36580
|
-
const
|
|
36581
|
-
this.log(`${event}.start`, data);
|
|
36756
|
+
const normalizedPath = entry.path.startsWith("/") ? entry.path.slice(1) : entry.path;
|
|
36582
36757
|
return {
|
|
36583
|
-
|
|
36584
|
-
|
|
36585
|
-
|
|
36586
|
-
|
|
36587
|
-
|
|
36588
|
-
durationMs: endedAt - startedAt,
|
|
36589
|
-
startedAt,
|
|
36590
|
-
endedAt,
|
|
36591
|
-
level: "debug",
|
|
36592
|
-
timestamp: Date.now(),
|
|
36593
|
-
timestampIso: (/* @__PURE__ */ new Date()).toISOString()
|
|
36594
|
-
});
|
|
36595
|
-
}
|
|
36758
|
+
...entry,
|
|
36759
|
+
service: "tinycloud.kv",
|
|
36760
|
+
path: `vault/${normalizedPath}`,
|
|
36761
|
+
actions: [mapped],
|
|
36762
|
+
skipPrefix: true
|
|
36596
36763
|
};
|
|
36764
|
+
});
|
|
36765
|
+
}
|
|
36766
|
+
function expandPermissionEntry(entry, prefix, inheritedSpace) {
|
|
36767
|
+
if (entry.service === VAULT_PERMISSION_SERVICE) {
|
|
36768
|
+
return expandVaultPermission(entry).flatMap(
|
|
36769
|
+
(expanded) => expandPermissionEntry(expanded, prefix, inheritedSpace)
|
|
36770
|
+
);
|
|
36597
36771
|
}
|
|
36598
|
-
|
|
36599
|
-
|
|
36600
|
-
|
|
36601
|
-
|
|
36602
|
-
|
|
36603
|
-
|
|
36604
|
-
|
|
36605
|
-
|
|
36606
|
-
return result;
|
|
36607
|
-
} catch (error) {
|
|
36608
|
-
timer2.stop({ ok: false, error });
|
|
36609
|
-
throw error;
|
|
36772
|
+
const skipPrefix = entry.skipPrefix === true || entry.service === ENCRYPTION_PERMISSION_SERVICE;
|
|
36773
|
+
return [
|
|
36774
|
+
{
|
|
36775
|
+
service: entry.service,
|
|
36776
|
+
space: entry.service === ENCRYPTION_PERMISSION_SERVICE ? ENCRYPTION_MANIFEST_SPACE : entry.space ?? inheritedSpace,
|
|
36777
|
+
path: applyPrefix(prefix, entry.path, skipPrefix),
|
|
36778
|
+
actions: entry.actions.map((action) => actionUrn(entry.service, action)),
|
|
36779
|
+
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
36610
36780
|
}
|
|
36611
|
-
|
|
36612
|
-
|
|
36613
|
-
|
|
36614
|
-
|
|
36781
|
+
];
|
|
36782
|
+
}
|
|
36783
|
+
function dedupeResources(resources) {
|
|
36784
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
36785
|
+
for (const resource of resources) {
|
|
36786
|
+
const key2 = `${resource.service}\0${resource.space}\0${resource.path}`;
|
|
36787
|
+
const existing = byKey.get(key2);
|
|
36788
|
+
if (!existing) {
|
|
36789
|
+
byKey.set(key2, { ...resource, actions: [...resource.actions] });
|
|
36790
|
+
continue;
|
|
36615
36791
|
}
|
|
36616
|
-
const
|
|
36617
|
-
|
|
36618
|
-
|
|
36619
|
-
|
|
36620
|
-
return result;
|
|
36621
|
-
} catch (error) {
|
|
36622
|
-
timer2.stop({ ok: false, error });
|
|
36623
|
-
throw error;
|
|
36792
|
+
for (const action of resource.actions) {
|
|
36793
|
+
if (!existing.actions.includes(action)) {
|
|
36794
|
+
existing.actions.push(action);
|
|
36795
|
+
}
|
|
36624
36796
|
}
|
|
36625
36797
|
}
|
|
36626
|
-
|
|
36627
|
-
|
|
36628
|
-
|
|
36629
|
-
|
|
36630
|
-
|
|
36631
|
-
|
|
36632
|
-
|
|
36633
|
-
|
|
36634
|
-
|
|
36635
|
-
|
|
36636
|
-
|
|
36637
|
-
|
|
36798
|
+
return [...byKey.values()];
|
|
36799
|
+
}
|
|
36800
|
+
function withCapabilitiesReadForSpaces(resources) {
|
|
36801
|
+
const spaces = new Set(
|
|
36802
|
+
resources.filter((resource) => resource.service !== ENCRYPTION_PERMISSION_SERVICE).map((resource) => resource.space)
|
|
36803
|
+
);
|
|
36804
|
+
return dedupeResources([
|
|
36805
|
+
...resources,
|
|
36806
|
+
...[...spaces].map((space) => ({
|
|
36807
|
+
service: "tinycloud.capabilities",
|
|
36808
|
+
space,
|
|
36809
|
+
path: "",
|
|
36810
|
+
actions: [CAPABILITIES2.READ]
|
|
36811
|
+
}))
|
|
36812
|
+
]);
|
|
36813
|
+
}
|
|
36814
|
+
function accountRegistryPermissions() {
|
|
36815
|
+
return [
|
|
36816
|
+
{
|
|
36817
|
+
service: "tinycloud.kv",
|
|
36818
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36819
|
+
path: ACCOUNT_REGISTRY_PATH,
|
|
36820
|
+
actions: [KV.GET, KV.PUT, KV.LIST]
|
|
36821
|
+
},
|
|
36822
|
+
{
|
|
36823
|
+
service: "tinycloud.kv",
|
|
36824
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36825
|
+
path: "spaces/",
|
|
36826
|
+
actions: [KV.GET, KV.PUT, KV.LIST]
|
|
36827
|
+
},
|
|
36828
|
+
{
|
|
36829
|
+
service: "tinycloud.sql",
|
|
36830
|
+
space: ACCOUNT_REGISTRY_SPACE,
|
|
36831
|
+
path: "account",
|
|
36832
|
+
actions: [SQL.READ, SQL.WRITE, SQL.SCHEMA]
|
|
36638
36833
|
}
|
|
36639
|
-
|
|
36834
|
+
];
|
|
36835
|
+
}
|
|
36836
|
+
function composeManifestRequest(inputs, options = {}) {
|
|
36837
|
+
if (!Array.isArray(inputs) || inputs.length === 0) {
|
|
36838
|
+
throw new Error("composeManifestRequest requires at least one manifest");
|
|
36839
|
+
}
|
|
36840
|
+
const includeAccountRegistryPermissions = options.includeAccountRegistryPermissions ?? true;
|
|
36841
|
+
const manifests = inputs.map(cloneManifest);
|
|
36842
|
+
const resources = manifests.flatMap((manifest) => {
|
|
36843
|
+
const prefix = manifest.prefix ?? manifest.app_id;
|
|
36844
|
+
const space = manifest.space ?? DEFAULT_MANIFEST_SPACE;
|
|
36845
|
+
const explicit = manifest.permissions ?? [];
|
|
36846
|
+
return explicit.flatMap((entry) => expandPermissionEntry(entry, prefix, space));
|
|
36847
|
+
});
|
|
36848
|
+
if (includeAccountRegistryPermissions) {
|
|
36849
|
+
resources.push(...accountRegistryPermissions());
|
|
36850
|
+
}
|
|
36851
|
+
const manifestsByAppId = /* @__PURE__ */ new Map();
|
|
36852
|
+
for (const manifest of manifests) {
|
|
36853
|
+
const current = manifestsByAppId.get(manifest.app_id) ?? [];
|
|
36854
|
+
current.push(cloneManifest(manifest));
|
|
36855
|
+
manifestsByAppId.set(manifest.app_id, current);
|
|
36856
|
+
}
|
|
36857
|
+
return {
|
|
36858
|
+
manifests,
|
|
36859
|
+
resources: withCapabilitiesReadForSpaces(resources),
|
|
36860
|
+
delegationTargets: [],
|
|
36861
|
+
registryRecords: includeAccountRegistryPermissions ? [...manifestsByAppId.entries()].map(([app_id, appManifests]) => ({
|
|
36862
|
+
key: `${ACCOUNT_REGISTRY_PATH}${app_id}`,
|
|
36863
|
+
app_id,
|
|
36864
|
+
manifests: appManifests
|
|
36865
|
+
})) : [],
|
|
36866
|
+
expiryMs: DEFAULT_EXPIRY_MS,
|
|
36867
|
+
includePublicSpace: manifests.some(
|
|
36868
|
+
(manifest) => manifest.includePublicSpace ?? true
|
|
36869
|
+
)
|
|
36870
|
+
};
|
|
36871
|
+
}
|
|
36872
|
+
function composeBootstrapSpaceManifest(space) {
|
|
36873
|
+
return composeManifestRequest([BOOTSTRAP_SPACE_MANIFESTS[space]], {
|
|
36874
|
+
includeAccountRegistryPermissions: false
|
|
36875
|
+
});
|
|
36876
|
+
}
|
|
36877
|
+
var BOOTSTRAP_SESSION_REQUESTS = Object.freeze(
|
|
36878
|
+
Object.fromEntries(
|
|
36879
|
+
BOOTSTRAP_SPACE_NAMES.map((space) => [
|
|
36880
|
+
space,
|
|
36881
|
+
composeBootstrapSpaceManifest(space)
|
|
36882
|
+
])
|
|
36883
|
+
)
|
|
36884
|
+
);
|
|
36885
|
+
var ACCOUNT_SESSION_RAW_ALLOWLIST = Object.freeze([
|
|
36886
|
+
{
|
|
36887
|
+
service: "tinycloud.encryption",
|
|
36888
|
+
resource: BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
|
|
36889
|
+
actions: [NETWORK_CREATE_ACTION]
|
|
36640
36890
|
}
|
|
36891
|
+
]);
|
|
36892
|
+
var BOOTSTRAP_ALLOWLIST = Object.freeze(
|
|
36893
|
+
BOOTSTRAP_SPACE_NAMES.flatMap((space) => [
|
|
36894
|
+
{
|
|
36895
|
+
kind: "session",
|
|
36896
|
+
service: "tinycloud.session",
|
|
36897
|
+
space,
|
|
36898
|
+
actions: ["siwe"],
|
|
36899
|
+
resources: BOOTSTRAP_SESSION_REQUESTS[space].resources,
|
|
36900
|
+
...space === ACCOUNT_REGISTRY_SPACE ? { rawAbilities: ACCOUNT_SESSION_RAW_ALLOWLIST } : {}
|
|
36901
|
+
},
|
|
36902
|
+
{
|
|
36903
|
+
kind: "space/host",
|
|
36904
|
+
service: "tinycloud.space",
|
|
36905
|
+
space,
|
|
36906
|
+
actions: [SPACE.HOST]
|
|
36907
|
+
}
|
|
36908
|
+
])
|
|
36909
|
+
);
|
|
36910
|
+
|
|
36911
|
+
// ../sdk-services/dist/index.js
|
|
36912
|
+
var ErrorCodes = {
|
|
36913
|
+
// Common errors
|
|
36914
|
+
NOT_FOUND: "NOT_FOUND",
|
|
36915
|
+
AUTH_EXPIRED: "AUTH_EXPIRED",
|
|
36916
|
+
AUTH_REQUIRED: "AUTH_REQUIRED",
|
|
36917
|
+
AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED",
|
|
36918
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
36919
|
+
TIMEOUT: "TIMEOUT",
|
|
36920
|
+
ABORTED: "ABORTED",
|
|
36921
|
+
INVALID_INPUT: "INVALID_INPUT",
|
|
36922
|
+
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
36923
|
+
// KV-specific errors
|
|
36924
|
+
KV_NOT_FOUND: "KV_NOT_FOUND",
|
|
36925
|
+
KV_WRITE_FAILED: "KV_WRITE_FAILED",
|
|
36926
|
+
// SQL-specific errors
|
|
36927
|
+
SQL_ERROR: "SQL_ERROR",
|
|
36928
|
+
SQL_PERMISSION_DENIED: "SQL_PERMISSION_DENIED",
|
|
36929
|
+
SQL_DATABASE_NOT_FOUND: "SQL_DATABASE_NOT_FOUND",
|
|
36930
|
+
SQL_RESPONSE_TOO_LARGE: "SQL_RESPONSE_TOO_LARGE",
|
|
36931
|
+
SQL_QUOTA_EXCEEDED: "SQL_QUOTA_EXCEEDED",
|
|
36932
|
+
SQL_INVALID_STATEMENT: "SQL_INVALID_STATEMENT",
|
|
36933
|
+
SQL_SCHEMA_ERROR: "SQL_SCHEMA_ERROR",
|
|
36934
|
+
SQL_READONLY_VIOLATION: "SQL_READONLY_VIOLATION",
|
|
36935
|
+
// Storage quota errors
|
|
36936
|
+
STORAGE_QUOTA_EXCEEDED: "STORAGE_QUOTA_EXCEEDED",
|
|
36937
|
+
STORAGE_LIMIT_REACHED: "STORAGE_LIMIT_REACHED",
|
|
36938
|
+
// DuckDB-specific errors
|
|
36939
|
+
DUCKDB_ERROR: "DUCKDB_ERROR",
|
|
36940
|
+
DUCKDB_PERMISSION_DENIED: "DUCKDB_PERMISSION_DENIED",
|
|
36941
|
+
DUCKDB_DATABASE_NOT_FOUND: "DUCKDB_DATABASE_NOT_FOUND",
|
|
36942
|
+
DUCKDB_RESPONSE_TOO_LARGE: "DUCKDB_RESPONSE_TOO_LARGE",
|
|
36943
|
+
DUCKDB_QUOTA_EXCEEDED: "DUCKDB_QUOTA_EXCEEDED",
|
|
36944
|
+
DUCKDB_INVALID_STATEMENT: "DUCKDB_INVALID_STATEMENT",
|
|
36945
|
+
DUCKDB_SCHEMA_ERROR: "DUCKDB_SCHEMA_ERROR",
|
|
36946
|
+
DUCKDB_READONLY_VIOLATION: "DUCKDB_READONLY_VIOLATION"
|
|
36641
36947
|
};
|
|
36642
|
-
var
|
|
36643
|
-
|
|
36644
|
-
|
|
36645
|
-
|
|
36948
|
+
var defaultRetryPolicy = {
|
|
36949
|
+
maxAttempts: 3,
|
|
36950
|
+
backoff: "exponential",
|
|
36951
|
+
baseDelayMs: 1e3,
|
|
36952
|
+
maxDelayMs: 1e4,
|
|
36953
|
+
retryableErrors: [ErrorCodes.NETWORK_ERROR, ErrorCodes.TIMEOUT]
|
|
36954
|
+
};
|
|
36955
|
+
var TelemetryEvents = {
|
|
36956
|
+
SPAN: "telemetry.span",
|
|
36957
|
+
SERVICE_REQUEST: "service.request",
|
|
36958
|
+
SERVICE_RESPONSE: "service.response",
|
|
36959
|
+
SERVICE_ERROR: "service.error",
|
|
36960
|
+
SERVICE_RETRY: "service.retry",
|
|
36961
|
+
SESSION_CHANGED: "session.changed",
|
|
36962
|
+
SESSION_EXPIRED: "session.expired"
|
|
36963
|
+
};
|
|
36964
|
+
function ok(data) {
|
|
36965
|
+
return { ok: true, data };
|
|
36646
36966
|
}
|
|
36647
|
-
function
|
|
36648
|
-
|
|
36649
|
-
return tinyCloudDebugLogger;
|
|
36967
|
+
function err(error) {
|
|
36968
|
+
return { ok: false, error };
|
|
36650
36969
|
}
|
|
36651
|
-
function
|
|
36652
|
-
return
|
|
36970
|
+
function serviceError(code2, message, service, options) {
|
|
36971
|
+
return {
|
|
36972
|
+
code: code2,
|
|
36973
|
+
message,
|
|
36974
|
+
service,
|
|
36975
|
+
cause: options?.cause,
|
|
36976
|
+
meta: options?.meta
|
|
36977
|
+
};
|
|
36653
36978
|
}
|
|
36654
|
-
|
|
36655
|
-
|
|
36979
|
+
var DEBUG_FLAG = "TinyCloud_debug";
|
|
36980
|
+
var MAX_EVENTS = 1e3;
|
|
36981
|
+
function getGlobal() {
|
|
36982
|
+
return globalThis;
|
|
36656
36983
|
}
|
|
36657
|
-
function
|
|
36658
|
-
const
|
|
36659
|
-
|
|
36660
|
-
global2.enableTinyCloudDebug = enableTinyCloudDebug;
|
|
36661
|
-
global2.disableTinyCloudDebug = disableTinyCloudDebug;
|
|
36662
|
-
global2.getTinyCloudDebugLogs = getTinyCloudDebugLogs;
|
|
36663
|
-
global2.clearTinyCloudDebugLogs = clearTinyCloudDebugLogs;
|
|
36984
|
+
function nowMs() {
|
|
36985
|
+
const performanceNow = globalThis.performance?.now?.bind(globalThis.performance);
|
|
36986
|
+
return typeof performanceNow === "function" ? performanceNow() : Date.now();
|
|
36664
36987
|
}
|
|
36665
|
-
|
|
36666
|
-
|
|
36667
|
-
/** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
|
|
36668
|
-
code: external_exports.string(),
|
|
36669
|
-
/** Human-readable error message */
|
|
36670
|
-
message: external_exports.string(),
|
|
36671
|
-
/** Service that produced the error (e.g., 'kv', 'sql') */
|
|
36672
|
-
service: external_exports.string(),
|
|
36673
|
-
/** Original error if this wraps another error - not validated since Error is a class */
|
|
36674
|
-
cause: external_exports.unknown().optional(),
|
|
36675
|
-
/** Additional metadata about the error - passthrough allows any object properties */
|
|
36676
|
-
meta: external_exports.object({}).passthrough().optional()
|
|
36677
|
-
});
|
|
36678
|
-
function createResultSchema(dataSchema, errorSchema = ServiceErrorSchema) {
|
|
36679
|
-
return external_exports.discriminatedUnion("ok", [
|
|
36680
|
-
external_exports.object({
|
|
36681
|
-
ok: external_exports.literal(true),
|
|
36682
|
-
data: dataSchema
|
|
36683
|
-
}),
|
|
36684
|
-
external_exports.object({
|
|
36685
|
-
ok: external_exports.literal(false),
|
|
36686
|
-
error: errorSchema
|
|
36687
|
-
})
|
|
36688
|
-
]);
|
|
36988
|
+
function isTrue(value) {
|
|
36989
|
+
return value === true || value === "true" || value === "1";
|
|
36689
36990
|
}
|
|
36690
|
-
|
|
36691
|
-
|
|
36692
|
-
|
|
36693
|
-
etag: external_exports.string().optional(),
|
|
36694
|
-
/** Content type of the stored value */
|
|
36695
|
-
contentType: external_exports.string().optional(),
|
|
36696
|
-
/** Last modification timestamp */
|
|
36697
|
-
lastModified: external_exports.string().optional(),
|
|
36698
|
-
/** Content length in bytes */
|
|
36699
|
-
contentLength: external_exports.number().optional()
|
|
36700
|
-
});
|
|
36701
|
-
function createKVResponseSchema(dataSchema) {
|
|
36702
|
-
return external_exports.object({
|
|
36703
|
-
/** The data payload */
|
|
36704
|
-
data: dataSchema,
|
|
36705
|
-
/** Response headers with metadata */
|
|
36706
|
-
headers: KVResponseHeadersSchema
|
|
36707
|
-
});
|
|
36991
|
+
function getProcessDebugFlag() {
|
|
36992
|
+
const processLike = globalThis.process;
|
|
36993
|
+
return processLike?.env?.[DEBUG_FLAG];
|
|
36708
36994
|
}
|
|
36709
|
-
|
|
36710
|
-
|
|
36711
|
-
|
|
36712
|
-
|
|
36713
|
-
|
|
36714
|
-
|
|
36715
|
-
|
|
36716
|
-
|
|
36717
|
-
|
|
36718
|
-
|
|
36719
|
-
|
|
36720
|
-
|
|
36721
|
-
}
|
|
36995
|
+
function isBrowserWindow() {
|
|
36996
|
+
const global2 = getGlobal();
|
|
36997
|
+
return global2.window === globalThis;
|
|
36998
|
+
}
|
|
36999
|
+
function getLocalStorage() {
|
|
37000
|
+
if (!isBrowserWindow()) {
|
|
37001
|
+
return void 0;
|
|
37002
|
+
}
|
|
37003
|
+
try {
|
|
37004
|
+
return globalThis.localStorage;
|
|
37005
|
+
} catch {
|
|
37006
|
+
return void 0;
|
|
37007
|
+
}
|
|
37008
|
+
}
|
|
37009
|
+
function getStoredDebugFlag() {
|
|
37010
|
+
const storage = getLocalStorage();
|
|
37011
|
+
if (!storage) {
|
|
37012
|
+
return void 0;
|
|
37013
|
+
}
|
|
37014
|
+
try {
|
|
37015
|
+
return storage.getItem(DEBUG_FLAG);
|
|
37016
|
+
} catch {
|
|
37017
|
+
return void 0;
|
|
37018
|
+
}
|
|
37019
|
+
}
|
|
37020
|
+
function setStoredDebugFlag(enabled) {
|
|
37021
|
+
const storage = getLocalStorage();
|
|
37022
|
+
if (!storage) {
|
|
37023
|
+
return;
|
|
37024
|
+
}
|
|
37025
|
+
try {
|
|
37026
|
+
if (enabled) {
|
|
37027
|
+
storage.setItem(DEBUG_FLAG, "true");
|
|
37028
|
+
} else {
|
|
37029
|
+
storage.removeItem(DEBUG_FLAG);
|
|
37030
|
+
}
|
|
37031
|
+
} catch {
|
|
37032
|
+
}
|
|
37033
|
+
}
|
|
37034
|
+
function shouldStartEnabled() {
|
|
37035
|
+
const global2 = getGlobal();
|
|
37036
|
+
return isTrue(global2[DEBUG_FLAG]) || isTrue(getStoredDebugFlag()) || isTrue(getProcessDebugFlag());
|
|
37037
|
+
}
|
|
37038
|
+
var TinyCloudDebugLogger = class {
|
|
37039
|
+
constructor() {
|
|
37040
|
+
this.enabled = shouldStartEnabled();
|
|
37041
|
+
this.sequence = 0;
|
|
37042
|
+
this.events = [];
|
|
37043
|
+
this.maxEvents = MAX_EVENTS;
|
|
37044
|
+
}
|
|
37045
|
+
isEnabled() {
|
|
37046
|
+
return this.enabled || isTrue(getGlobal()[DEBUG_FLAG]) || isTrue(getProcessDebugFlag());
|
|
37047
|
+
}
|
|
37048
|
+
enable(options = {}) {
|
|
37049
|
+
this.enabled = true;
|
|
37050
|
+
getGlobal()[DEBUG_FLAG] = true;
|
|
37051
|
+
if (options.persist !== false) {
|
|
37052
|
+
setStoredDebugFlag(true);
|
|
37053
|
+
}
|
|
37054
|
+
this.log("debug.enabled", { persisted: options.persist !== false });
|
|
37055
|
+
}
|
|
37056
|
+
disable(options = {}) {
|
|
37057
|
+
this.log("debug.disabled", { persisted: options.persist !== false });
|
|
37058
|
+
this.enabled = false;
|
|
37059
|
+
getGlobal()[DEBUG_FLAG] = false;
|
|
37060
|
+
if (options.persist !== false) {
|
|
37061
|
+
setStoredDebugFlag(false);
|
|
37062
|
+
}
|
|
37063
|
+
}
|
|
37064
|
+
clear() {
|
|
37065
|
+
this.events = [];
|
|
37066
|
+
}
|
|
37067
|
+
getLogs() {
|
|
37068
|
+
return [...this.events];
|
|
37069
|
+
}
|
|
37070
|
+
log(event, data, message) {
|
|
37071
|
+
if (!this.isEnabled()) {
|
|
37072
|
+
return void 0;
|
|
37073
|
+
}
|
|
37074
|
+
return this.record({
|
|
37075
|
+
event,
|
|
37076
|
+
data,
|
|
37077
|
+
message,
|
|
37078
|
+
level: "debug",
|
|
37079
|
+
timestamp: Date.now(),
|
|
37080
|
+
timestampIso: (/* @__PURE__ */ new Date()).toISOString()
|
|
37081
|
+
});
|
|
37082
|
+
}
|
|
37083
|
+
startTimer(event, data) {
|
|
37084
|
+
if (!this.isEnabled()) {
|
|
37085
|
+
return { stop: () => void 0 };
|
|
37086
|
+
}
|
|
37087
|
+
const startedAt = nowMs();
|
|
37088
|
+
this.log(`${event}.start`, data);
|
|
37089
|
+
return {
|
|
37090
|
+
stop: (finishData) => {
|
|
37091
|
+
const endedAt = nowMs();
|
|
37092
|
+
return this.record({
|
|
37093
|
+
event: `${event}.end`,
|
|
37094
|
+
data: finishData,
|
|
37095
|
+
durationMs: endedAt - startedAt,
|
|
37096
|
+
startedAt,
|
|
37097
|
+
endedAt,
|
|
37098
|
+
level: "debug",
|
|
37099
|
+
timestamp: Date.now(),
|
|
37100
|
+
timestampIso: (/* @__PURE__ */ new Date()).toISOString()
|
|
37101
|
+
});
|
|
37102
|
+
}
|
|
37103
|
+
};
|
|
37104
|
+
}
|
|
37105
|
+
async timeAsync(event, operation, data) {
|
|
37106
|
+
if (!this.isEnabled()) {
|
|
37107
|
+
return operation();
|
|
37108
|
+
}
|
|
37109
|
+
const timer2 = this.startTimer(event, data);
|
|
37110
|
+
try {
|
|
37111
|
+
const result = await operation();
|
|
37112
|
+
timer2.stop({ ok: true });
|
|
37113
|
+
return result;
|
|
37114
|
+
} catch (error) {
|
|
37115
|
+
timer2.stop({ ok: false, error });
|
|
37116
|
+
throw error;
|
|
37117
|
+
}
|
|
37118
|
+
}
|
|
37119
|
+
time(event, operation, data) {
|
|
37120
|
+
if (!this.isEnabled()) {
|
|
37121
|
+
return operation();
|
|
37122
|
+
}
|
|
37123
|
+
const timer2 = this.startTimer(event, data);
|
|
37124
|
+
try {
|
|
37125
|
+
const result = operation();
|
|
37126
|
+
timer2.stop({ ok: true });
|
|
37127
|
+
return result;
|
|
37128
|
+
} catch (error) {
|
|
37129
|
+
timer2.stop({ ok: false, error });
|
|
37130
|
+
throw error;
|
|
37131
|
+
}
|
|
37132
|
+
}
|
|
37133
|
+
record(event) {
|
|
37134
|
+
const debugEvent = {
|
|
37135
|
+
...event,
|
|
37136
|
+
sequence: ++this.sequence
|
|
37137
|
+
};
|
|
37138
|
+
this.events.push(debugEvent);
|
|
37139
|
+
if (this.events.length > this.maxEvents) {
|
|
37140
|
+
this.events.splice(0, this.events.length - this.maxEvents);
|
|
37141
|
+
}
|
|
37142
|
+
try {
|
|
37143
|
+
globalThis.console?.debug?.("[TinyCloud]", debugEvent.event, debugEvent);
|
|
37144
|
+
} catch {
|
|
37145
|
+
}
|
|
37146
|
+
return debugEvent;
|
|
37147
|
+
}
|
|
37148
|
+
};
|
|
37149
|
+
var tinyCloudDebugLogger = new TinyCloudDebugLogger();
|
|
37150
|
+
function enableTinyCloudDebug(options) {
|
|
37151
|
+
tinyCloudDebugLogger.enable(options);
|
|
37152
|
+
return tinyCloudDebugLogger;
|
|
37153
|
+
}
|
|
37154
|
+
function disableTinyCloudDebug(options) {
|
|
37155
|
+
tinyCloudDebugLogger.disable(options);
|
|
37156
|
+
return tinyCloudDebugLogger;
|
|
37157
|
+
}
|
|
37158
|
+
function getTinyCloudDebugLogs() {
|
|
37159
|
+
return tinyCloudDebugLogger.getLogs();
|
|
37160
|
+
}
|
|
37161
|
+
function clearTinyCloudDebugLogs() {
|
|
37162
|
+
tinyCloudDebugLogger.clear();
|
|
37163
|
+
}
|
|
37164
|
+
function installTinyCloudDebugGlobals() {
|
|
37165
|
+
const global2 = getGlobal();
|
|
37166
|
+
global2.TinyCloudDebug = tinyCloudDebugLogger;
|
|
37167
|
+
global2.enableTinyCloudDebug = enableTinyCloudDebug;
|
|
37168
|
+
global2.disableTinyCloudDebug = disableTinyCloudDebug;
|
|
37169
|
+
global2.getTinyCloudDebugLogs = getTinyCloudDebugLogs;
|
|
37170
|
+
global2.clearTinyCloudDebugLogs = clearTinyCloudDebugLogs;
|
|
37171
|
+
}
|
|
37172
|
+
installTinyCloudDebugGlobals();
|
|
37173
|
+
var ServiceErrorSchema = external_exports.object({
|
|
37174
|
+
/** Error code for programmatic handling (e.g., 'KV_NOT_FOUND', 'AUTH_EXPIRED') */
|
|
37175
|
+
code: external_exports.string(),
|
|
37176
|
+
/** Human-readable error message */
|
|
37177
|
+
message: external_exports.string(),
|
|
37178
|
+
/** Service that produced the error (e.g., 'kv', 'sql') */
|
|
37179
|
+
service: external_exports.string(),
|
|
37180
|
+
/** Original error if this wraps another error - not validated since Error is a class */
|
|
37181
|
+
cause: external_exports.unknown().optional(),
|
|
37182
|
+
/** Additional metadata about the error - passthrough allows any object properties */
|
|
37183
|
+
meta: external_exports.object({}).passthrough().optional()
|
|
37184
|
+
});
|
|
37185
|
+
function createResultSchema(dataSchema, errorSchema = ServiceErrorSchema) {
|
|
37186
|
+
return external_exports.discriminatedUnion("ok", [
|
|
37187
|
+
external_exports.object({
|
|
37188
|
+
ok: external_exports.literal(true),
|
|
37189
|
+
data: dataSchema
|
|
37190
|
+
}),
|
|
37191
|
+
external_exports.object({
|
|
37192
|
+
ok: external_exports.literal(false),
|
|
37193
|
+
error: errorSchema
|
|
37194
|
+
})
|
|
37195
|
+
]);
|
|
37196
|
+
}
|
|
37197
|
+
var GenericResultSchema = createResultSchema(external_exports.unknown(), ServiceErrorSchema);
|
|
37198
|
+
var KVResponseHeadersSchema = external_exports.object({
|
|
37199
|
+
/** ETag for conditional requests */
|
|
37200
|
+
etag: external_exports.string().optional(),
|
|
37201
|
+
/** Content type of the stored value */
|
|
37202
|
+
contentType: external_exports.string().optional(),
|
|
37203
|
+
/** Last modification timestamp */
|
|
37204
|
+
lastModified: external_exports.string().optional(),
|
|
37205
|
+
/** Content length in bytes */
|
|
37206
|
+
contentLength: external_exports.number().optional()
|
|
37207
|
+
});
|
|
37208
|
+
function createKVResponseSchema(dataSchema) {
|
|
37209
|
+
return external_exports.object({
|
|
37210
|
+
/** The data payload */
|
|
37211
|
+
data: dataSchema,
|
|
37212
|
+
/** Response headers with metadata */
|
|
37213
|
+
headers: KVResponseHeadersSchema
|
|
37214
|
+
});
|
|
37215
|
+
}
|
|
37216
|
+
var GenericKVResponseSchema = createKVResponseSchema(external_exports.unknown());
|
|
37217
|
+
var KVListResponseSchema = external_exports.object({
|
|
37218
|
+
/** Array of keys matching the list criteria */
|
|
37219
|
+
keys: external_exports.array(external_exports.string())
|
|
37220
|
+
});
|
|
37221
|
+
var KVListResultSchema = createResultSchema(KVListResponseSchema);
|
|
37222
|
+
var ServiceRequestEventSchema = external_exports.object({
|
|
37223
|
+
service: external_exports.string(),
|
|
37224
|
+
action: external_exports.string(),
|
|
37225
|
+
span: external_exports.string().optional(),
|
|
37226
|
+
key: external_exports.string().optional(),
|
|
37227
|
+
timestamp: external_exports.number()
|
|
37228
|
+
});
|
|
36722
37229
|
var ServiceResponseEventSchema = external_exports.object({
|
|
36723
37230
|
service: external_exports.string(),
|
|
36724
37231
|
action: external_exports.string(),
|
|
@@ -37971,17 +38478,14 @@ var DatabaseHandle = class {
|
|
|
37971
38478
|
}
|
|
37972
38479
|
};
|
|
37973
38480
|
var SQLAction = {
|
|
37974
|
-
READ:
|
|
37975
|
-
WRITE:
|
|
37976
|
-
SCHEMA:
|
|
37977
|
-
ADMIN:
|
|
37978
|
-
SELECT:
|
|
37979
|
-
|
|
37980
|
-
|
|
37981
|
-
|
|
37982
|
-
EXECUTE: "tinycloud.sql/execute",
|
|
37983
|
-
EXPORT: "tinycloud.sql/export",
|
|
37984
|
-
ALL: "tinycloud.sql/*"
|
|
38481
|
+
READ: SQL.READ,
|
|
38482
|
+
WRITE: SQL.WRITE,
|
|
38483
|
+
SCHEMA: SQL.SCHEMA,
|
|
38484
|
+
ADMIN: SQL.ADMIN,
|
|
38485
|
+
SELECT: SQL.SELECT,
|
|
38486
|
+
EXECUTE: SQL.EXECUTE,
|
|
38487
|
+
EXPORT: SQL.EXPORT,
|
|
38488
|
+
ALL: SQL.ALL
|
|
37985
38489
|
};
|
|
37986
38490
|
var DDL_TOKENS = /* @__PURE__ */ new Set(["alter", "create", "drop"]);
|
|
37987
38491
|
var MIGRATIONS_TABLE = "__tinycloud_sql_migrations";
|
|
@@ -38450,14 +38954,14 @@ var DuckDbDatabaseHandle = class {
|
|
|
38450
38954
|
}
|
|
38451
38955
|
};
|
|
38452
38956
|
var DuckDbAction = {
|
|
38453
|
-
READ:
|
|
38454
|
-
WRITE:
|
|
38455
|
-
ADMIN:
|
|
38456
|
-
DESCRIBE:
|
|
38457
|
-
EXPORT:
|
|
38458
|
-
IMPORT:
|
|
38459
|
-
EXECUTE:
|
|
38460
|
-
ALL:
|
|
38957
|
+
READ: DUCKDB.READ,
|
|
38958
|
+
WRITE: DUCKDB.WRITE,
|
|
38959
|
+
ADMIN: DUCKDB.ADMIN,
|
|
38960
|
+
DESCRIBE: DUCKDB.DESCRIBE,
|
|
38961
|
+
EXPORT: DUCKDB.EXPORT,
|
|
38962
|
+
IMPORT: DUCKDB.IMPORT,
|
|
38963
|
+
EXECUTE: DUCKDB.EXECUTE,
|
|
38964
|
+
ALL: DUCKDB.ALL
|
|
38461
38965
|
};
|
|
38462
38966
|
var DuckDbService = class extends BaseService {
|
|
38463
38967
|
constructor(config = {}) {
|
|
@@ -41837,9 +42341,9 @@ var ManifestValidationError = class extends Error {
|
|
|
41837
42341
|
var DEFAULT_EXPIRY = "30d";
|
|
41838
42342
|
var DEFAULT_DEFAULTS = true;
|
|
41839
42343
|
var DEFAULT_MANIFEST_VERSION = 1;
|
|
41840
|
-
var
|
|
41841
|
-
var
|
|
41842
|
-
var
|
|
42344
|
+
var DEFAULT_MANIFEST_SPACE2 = "applications";
|
|
42345
|
+
var SECRETS_SPACE2 = "secrets";
|
|
42346
|
+
var VAULT_PERMISSION_SERVICE2 = "tinycloud.vault";
|
|
41843
42347
|
var SERVICE_SHORT_TO_LONG = Object.freeze({
|
|
41844
42348
|
kv: "tinycloud.kv",
|
|
41845
42349
|
sql: "tinycloud.sql",
|
|
@@ -41848,8 +42352,8 @@ var SERVICE_SHORT_TO_LONG = Object.freeze({
|
|
|
41848
42352
|
hooks: "tinycloud.hooks",
|
|
41849
42353
|
encryption: "tinycloud.encryption"
|
|
41850
42354
|
});
|
|
41851
|
-
var
|
|
41852
|
-
var
|
|
42355
|
+
var ENCRYPTION_PERMISSION_SERVICE2 = "tinycloud.encryption";
|
|
42356
|
+
var ENCRYPTION_MANIFEST_SPACE2 = "encryption";
|
|
41853
42357
|
var SERVICE_LONG_TO_SHORT = Object.freeze(
|
|
41854
42358
|
Object.fromEntries(
|
|
41855
42359
|
Object.entries(SERVICE_SHORT_TO_LONG).map(([s, l]) => [l, s])
|
|
@@ -41858,13 +42362,13 @@ var SERVICE_LONG_TO_SHORT = Object.freeze(
|
|
|
41858
42362
|
var DEFAULT_STANDARD_ENTRIES = [
|
|
41859
42363
|
{
|
|
41860
42364
|
service: "tinycloud.kv",
|
|
41861
|
-
space:
|
|
42365
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41862
42366
|
path: "/",
|
|
41863
42367
|
actions: ["get", "put", "del", "list", "metadata"]
|
|
41864
42368
|
},
|
|
41865
42369
|
{
|
|
41866
42370
|
service: "tinycloud.sql",
|
|
41867
|
-
space:
|
|
42371
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41868
42372
|
path: "/",
|
|
41869
42373
|
actions: ["read", "write"]
|
|
41870
42374
|
}
|
|
@@ -41872,13 +42376,13 @@ var DEFAULT_STANDARD_ENTRIES = [
|
|
|
41872
42376
|
var DEFAULT_ADMIN_ENTRIES = [
|
|
41873
42377
|
{
|
|
41874
42378
|
service: "tinycloud.kv",
|
|
41875
|
-
space:
|
|
42379
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41876
42380
|
path: "/",
|
|
41877
42381
|
actions: ["get", "put", "del", "list", "metadata"]
|
|
41878
42382
|
},
|
|
41879
42383
|
{
|
|
41880
42384
|
service: "tinycloud.sql",
|
|
41881
|
-
space:
|
|
42385
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41882
42386
|
path: "/",
|
|
41883
42387
|
actions: ["read", "write", "schema"]
|
|
41884
42388
|
}
|
|
@@ -41886,19 +42390,19 @@ var DEFAULT_ADMIN_ENTRIES = [
|
|
|
41886
42390
|
var DEFAULT_ALL_ENTRIES = [
|
|
41887
42391
|
{
|
|
41888
42392
|
service: "tinycloud.kv",
|
|
41889
|
-
space:
|
|
42393
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41890
42394
|
path: "/",
|
|
41891
42395
|
actions: ["get", "put", "del", "list", "metadata"]
|
|
41892
42396
|
},
|
|
41893
42397
|
{
|
|
41894
42398
|
service: "tinycloud.sql",
|
|
41895
|
-
space:
|
|
42399
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41896
42400
|
path: "/",
|
|
41897
42401
|
actions: ["read", "write", "schema"]
|
|
41898
42402
|
},
|
|
41899
42403
|
{
|
|
41900
42404
|
service: "tinycloud.duckdb",
|
|
41901
|
-
space:
|
|
42405
|
+
space: DEFAULT_MANIFEST_SPACE2,
|
|
41902
42406
|
path: "/",
|
|
41903
42407
|
actions: ["read", "write"]
|
|
41904
42408
|
}
|
|
@@ -41925,11 +42429,11 @@ function expandActionShortNames(service, actions) {
|
|
|
41925
42429
|
return `${service}/${a}`;
|
|
41926
42430
|
});
|
|
41927
42431
|
}
|
|
41928
|
-
function
|
|
41929
|
-
if (entry.service ===
|
|
42432
|
+
function expandPermissionEntry2(entry) {
|
|
42433
|
+
if (entry.service === ENCRYPTION_PERMISSION_SERVICE2) {
|
|
41930
42434
|
return expandEncryptionPermissionEntry(entry);
|
|
41931
42435
|
}
|
|
41932
|
-
if (entry.service !==
|
|
42436
|
+
if (entry.service !== VAULT_PERMISSION_SERVICE2) {
|
|
41933
42437
|
return [
|
|
41934
42438
|
{
|
|
41935
42439
|
...entry,
|
|
@@ -41978,8 +42482,8 @@ function expandEncryptionPermissionEntry(entry) {
|
|
|
41978
42482
|
}
|
|
41979
42483
|
return [
|
|
41980
42484
|
{
|
|
41981
|
-
service:
|
|
41982
|
-
space:
|
|
42485
|
+
service: ENCRYPTION_PERMISSION_SERVICE2,
|
|
42486
|
+
space: ENCRYPTION_MANIFEST_SPACE2,
|
|
41983
42487
|
path: entry.path,
|
|
41984
42488
|
actions: dedupedActions,
|
|
41985
42489
|
skipPrefix: true,
|
|
@@ -41988,7 +42492,7 @@ function expandEncryptionPermissionEntry(entry) {
|
|
|
41988
42492
|
}
|
|
41989
42493
|
];
|
|
41990
42494
|
}
|
|
41991
|
-
function
|
|
42495
|
+
function applyPrefix2(prefix, path, skipPrefix) {
|
|
41992
42496
|
if (skipPrefix) {
|
|
41993
42497
|
return path;
|
|
41994
42498
|
}
|
|
@@ -42137,7 +42641,7 @@ function validatePermissionEntry(p, path) {
|
|
|
42137
42641
|
`${path}.actions must contain non-empty strings`
|
|
42138
42642
|
);
|
|
42139
42643
|
}
|
|
42140
|
-
if (entry.service ===
|
|
42644
|
+
if (entry.service === VAULT_PERMISSION_SERVICE2) {
|
|
42141
42645
|
vaultActionExpansion(action);
|
|
42142
42646
|
}
|
|
42143
42647
|
}
|
|
@@ -42177,7 +42681,7 @@ function defaultEntriesForTier(tier) {
|
|
|
42177
42681
|
function resolveManifest(input) {
|
|
42178
42682
|
const manifest = validateManifest(input);
|
|
42179
42683
|
const prefix = manifest.prefix !== void 0 ? manifest.prefix : manifest.app_id;
|
|
42180
|
-
const space = manifest.space ??
|
|
42684
|
+
const space = manifest.space ?? DEFAULT_MANIFEST_SPACE2;
|
|
42181
42685
|
const expiryMs = parseExpiry(manifest.expiry ?? DEFAULT_EXPIRY);
|
|
42182
42686
|
const includePublicSpace = manifest.includePublicSpace ?? true;
|
|
42183
42687
|
const tier = normalizeDefaults(manifest.defaults);
|
|
@@ -42189,7 +42693,7 @@ function resolveManifest(input) {
|
|
|
42189
42693
|
...explicitEntries,
|
|
42190
42694
|
...secretEntries
|
|
42191
42695
|
];
|
|
42192
|
-
const resources =
|
|
42696
|
+
const resources = withCapabilitiesReadForSpaces2(
|
|
42193
42697
|
allEntries.flatMap((entry) => resolveEntry(entry, prefix, expiryMs, space))
|
|
42194
42698
|
);
|
|
42195
42699
|
const additionalDelegates = manifest.did === void 0 ? [] : [
|
|
@@ -42299,8 +42803,8 @@ function secretEntriesForManifest(secrets) {
|
|
|
42299
42803
|
);
|
|
42300
42804
|
const extra = spec !== true && typeof spec === "object" && !Array.isArray(spec) ? spec : {};
|
|
42301
42805
|
entries.push({
|
|
42302
|
-
service:
|
|
42303
|
-
space:
|
|
42806
|
+
service: VAULT_PERMISSION_SERVICE2,
|
|
42807
|
+
space: SECRETS_SPACE2,
|
|
42304
42808
|
path: secretPath.vaultKey,
|
|
42305
42809
|
actions: normalizeSecretActions(actions),
|
|
42306
42810
|
skipPrefix: true,
|
|
@@ -42311,10 +42815,10 @@ function secretEntriesForManifest(secrets) {
|
|
|
42311
42815
|
return entries;
|
|
42312
42816
|
}
|
|
42313
42817
|
function resolveEntry(entry, prefix, _inheritedExpiryMs, inheritedSpace) {
|
|
42314
|
-
const skipPrefixForEntry = entry.skipPrefix === true || entry.service ===
|
|
42315
|
-
const resolvedPath =
|
|
42818
|
+
const skipPrefixForEntry = entry.skipPrefix === true || entry.service === ENCRYPTION_PERMISSION_SERVICE2;
|
|
42819
|
+
const resolvedPath = applyPrefix2(prefix, entry.path, skipPrefixForEntry);
|
|
42316
42820
|
const entryExpiryMs = entry.expiry !== void 0 ? parseExpiry(entry.expiry) : void 0;
|
|
42317
|
-
return
|
|
42821
|
+
return expandPermissionEntry2({
|
|
42318
42822
|
...entry,
|
|
42319
42823
|
space: entry.space ?? inheritedSpace,
|
|
42320
42824
|
path: resolvedPath,
|
|
@@ -42376,8 +42880,8 @@ function vaultActionExpansion(action) {
|
|
|
42376
42880
|
);
|
|
42377
42881
|
}
|
|
42378
42882
|
function normalizeVaultAction(action) {
|
|
42379
|
-
if (action.startsWith(`${
|
|
42380
|
-
return action.slice(`${
|
|
42883
|
+
if (action.startsWith(`${VAULT_PERMISSION_SERVICE2}/`)) {
|
|
42884
|
+
return action.slice(`${VAULT_PERMISSION_SERVICE2}/`.length);
|
|
42381
42885
|
}
|
|
42382
42886
|
if (action.startsWith("tinycloud.kv/")) {
|
|
42383
42887
|
return action.slice("tinycloud.kv/".length);
|
|
@@ -42403,7 +42907,7 @@ function cloneResourceCapability(entry) {
|
|
|
42403
42907
|
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
42404
42908
|
};
|
|
42405
42909
|
}
|
|
42406
|
-
function
|
|
42910
|
+
function dedupeResources2(resources) {
|
|
42407
42911
|
const byKey = /* @__PURE__ */ new Map();
|
|
42408
42912
|
for (const resource of resources) {
|
|
42409
42913
|
const key2 = `${resource.service}\0${resource.space}\0${resource.path}\0${resource.expiryMs ?? ""}`;
|
|
@@ -42433,14 +42937,14 @@ function capabilitiesReadPermission(space) {
|
|
|
42433
42937
|
actions: ["tinycloud.capabilities/read"]
|
|
42434
42938
|
};
|
|
42435
42939
|
}
|
|
42436
|
-
function
|
|
42940
|
+
function withCapabilitiesReadForSpaces2(resources) {
|
|
42437
42941
|
if (resources.length === 0) {
|
|
42438
42942
|
return [];
|
|
42439
42943
|
}
|
|
42440
42944
|
const spaces = new Set(
|
|
42441
|
-
resources.filter((resource) => resource.service !==
|
|
42945
|
+
resources.filter((resource) => resource.service !== ENCRYPTION_PERMISSION_SERVICE2).map((resource) => resource.space)
|
|
42442
42946
|
);
|
|
42443
|
-
return
|
|
42947
|
+
return dedupeResources2([
|
|
42444
42948
|
...resources,
|
|
42445
42949
|
...[...spaces].map(capabilitiesReadPermission)
|
|
42446
42950
|
]);
|
|
@@ -42733,8 +43237,8 @@ async function secretPermissionsFromAppManifest(manifest, profile) {
|
|
|
42733
43237
|
);
|
|
42734
43238
|
if (needsDecrypt) {
|
|
42735
43239
|
permissions.push({
|
|
42736
|
-
service:
|
|
42737
|
-
space:
|
|
43240
|
+
service: ENCRYPTION_PERMISSION_SERVICE2,
|
|
43241
|
+
space: ENCRYPTION_MANIFEST_SPACE2,
|
|
42738
43242
|
path: await defaultSecretsNetworkId(profile),
|
|
42739
43243
|
actions: ["tinycloud.encryption/decrypt"],
|
|
42740
43244
|
skipPrefix: true
|
|
@@ -45304,7 +45808,7 @@ import { readFile as readFile6 } from "fs/promises";
|
|
|
45304
45808
|
import { writeFile as writeFile6 } from "fs/promises";
|
|
45305
45809
|
import { join as join5 } from "path";
|
|
45306
45810
|
import { homedir as homedir2 } from "os";
|
|
45307
|
-
var
|
|
45811
|
+
var SECRETS_SPACE3 = "secrets";
|
|
45308
45812
|
var SECRET_KV_ABILITIES = {
|
|
45309
45813
|
get: "tinycloud.kv/get",
|
|
45310
45814
|
put: "tinycloud.kv/put",
|
|
@@ -45481,7 +45985,7 @@ function hasPermissionAction(actions, action) {
|
|
|
45481
45985
|
(entry) => entry === action || entry.endsWith(`/${action.split("/").at(-1)}`) || entry === action.split("/").at(-1)
|
|
45482
45986
|
);
|
|
45483
45987
|
}
|
|
45484
|
-
function delegationCoversPath(permissions, path, space =
|
|
45988
|
+
function delegationCoversPath(permissions, path, space = SECRETS_SPACE3) {
|
|
45485
45989
|
return permissions.some((permission) => {
|
|
45486
45990
|
if (permission.service !== "tinycloud.kv") return false;
|
|
45487
45991
|
if (!permissionTargetsSpace(permission, space)) return false;
|
|
@@ -45625,7 +46129,7 @@ async function loadDelegationCandidates(source) {
|
|
|
45625
46129
|
);
|
|
45626
46130
|
}
|
|
45627
46131
|
}
|
|
45628
|
-
function selectDelegationCandidate(candidates, source, secretPath, space =
|
|
46132
|
+
function selectDelegationCandidate(candidates, source, secretPath, space = SECRETS_SPACE3) {
|
|
45629
46133
|
const liveCandidates = candidates.filter((candidate) => candidate.delegation.expiry.getTime() > Date.now());
|
|
45630
46134
|
if (liveCandidates.length === 0) {
|
|
45631
46135
|
throw new CLIError(
|
|
@@ -45656,7 +46160,7 @@ function selectDelegationCandidate(candidates, source, secretPath, space = SECRE
|
|
|
45656
46160
|
ExitCode.PERMISSION_DENIED
|
|
45657
46161
|
);
|
|
45658
46162
|
}
|
|
45659
|
-
async function resolveDelegatedSecretSource(source, secretPath, space =
|
|
46163
|
+
async function resolveDelegatedSecretSource(source, secretPath, space = SECRETS_SPACE3) {
|
|
45660
46164
|
const candidates = await loadDelegationCandidates(source);
|
|
45661
46165
|
if (candidates.length === 0) {
|
|
45662
46166
|
throw new CLIError(
|
|
@@ -45695,7 +46199,7 @@ function parseDecryptedSecretPayload(data, secretPath) {
|
|
|
45695
46199
|
return parsed.value;
|
|
45696
46200
|
}
|
|
45697
46201
|
async function readDelegatedSecretValue(params) {
|
|
45698
|
-
if (!delegationCoversPath(params.permissions, params.secretPath, params.space ??
|
|
46202
|
+
if (!delegationCoversPath(params.permissions, params.secretPath, params.space ?? SECRETS_SPACE3)) {
|
|
45699
46203
|
throw new CLIError(
|
|
45700
46204
|
"PERMISSION_DENIED",
|
|
45701
46205
|
`Delegation "${params.delegationCid}" does not cover secret "${params.secretPath}".`,
|
|
@@ -45805,13 +46309,13 @@ function secretPermissionEntries(params) {
|
|
|
45805
46309
|
const path = params.action === "list" ? resolveSecretListPrefix(params.options) : resolveSecretPath2(params.name ?? "", params.options).permissionPaths.vault;
|
|
45806
46310
|
const permissions = [{
|
|
45807
46311
|
service: "tinycloud.kv",
|
|
45808
|
-
space: params.space ??
|
|
46312
|
+
space: params.space ?? SECRETS_SPACE3,
|
|
45809
46313
|
path,
|
|
45810
46314
|
actions: [secretKvAbility(params.action)],
|
|
45811
46315
|
skipPrefix: true
|
|
45812
46316
|
}];
|
|
45813
46317
|
if (params.action === "get") {
|
|
45814
|
-
const networkId = "getEncryptionNetworkIdForSpace" in params.node && typeof params.node.getEncryptionNetworkIdForSpace === "function" ? params.node.getEncryptionNetworkIdForSpace(params.space ??
|
|
46318
|
+
const networkId = "getEncryptionNetworkIdForSpace" in params.node && typeof params.node.getEncryptionNetworkIdForSpace === "function" ? params.node.getEncryptionNetworkIdForSpace(params.space ?? SECRETS_SPACE3) : params.node.getDefaultEncryptionNetworkId();
|
|
45815
46319
|
permissions.push({
|
|
45816
46320
|
service: "tinycloud.encryption",
|
|
45817
46321
|
path: networkId,
|
|
@@ -46018,7 +46522,7 @@ function registerSecretsCommand(program2) {
|
|
|
46018
46522
|
const delegated = await resolveDelegatedSecretSource(
|
|
46019
46523
|
options.delegation,
|
|
46020
46524
|
secretPath,
|
|
46021
|
-
spaceUri ??
|
|
46525
|
+
spaceUri ?? SECRETS_SPACE3
|
|
46022
46526
|
);
|
|
46023
46527
|
const effectiveHost = globalOpts.host ?? delegated.delegation.host ?? ctx.host;
|
|
46024
46528
|
const delegatedCtx = { ...ctx, host: effectiveHost };
|
|
@@ -46031,7 +46535,7 @@ function registerSecretsCommand(program2) {
|
|
|
46031
46535
|
delegationCid: delegated.delegation.cid,
|
|
46032
46536
|
permissions: delegated.permissions,
|
|
46033
46537
|
secretPath,
|
|
46034
|
-
space: spaceUri ??
|
|
46538
|
+
space: spaceUri ?? SECRETS_SPACE3,
|
|
46035
46539
|
name: name2
|
|
46036
46540
|
})
|
|
46037
46541
|
);
|
|
@@ -46718,571 +47222,139 @@ function registerDuckdbCommand(program2) {
|
|
|
46718
47222
|
const { columns, rows, rowCount } = result.data;
|
|
46719
47223
|
if (shouldOutputJson()) {
|
|
46720
47224
|
outputJson({ columns, rows, rowCount });
|
|
46721
|
-
} else {
|
|
46722
|
-
if (rows.length === 0) {
|
|
46723
|
-
process.stdout.write(theme.muted("No rows returned.") + "\n");
|
|
46724
|
-
} else {
|
|
46725
|
-
const stringRows = rows.map(
|
|
46726
|
-
(row) => row.map((v) => v === null ? "NULL" : String(v))
|
|
46727
|
-
);
|
|
46728
|
-
process.stdout.write(formatTable(columns, stringRows) + "\n");
|
|
46729
|
-
process.stdout.write(theme.muted(`
|
|
46730
|
-
${rowCount} row${rowCount === 1 ? "" : "s"} returned`) + "\n");
|
|
46731
|
-
}
|
|
46732
|
-
}
|
|
46733
|
-
} catch (error) {
|
|
46734
|
-
handleError(error);
|
|
46735
|
-
}
|
|
46736
|
-
});
|
|
46737
|
-
duckdb.command("execute <sql>").description("Run INSERT/UPDATE/DELETE/DDL statement").option("--db <name>", "Database name", "default").option("--params <json>", "Bind parameters as JSON array").action(async (sqlStr, options, cmd) => {
|
|
46738
|
-
try {
|
|
46739
|
-
const globalOpts = cmd.optsWithGlobals();
|
|
46740
|
-
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
46741
|
-
const node = await ensureAuthenticated(ctx);
|
|
46742
|
-
const params = options.params ? JSON.parse(options.params) : void 0;
|
|
46743
|
-
const result = await withSpinner(
|
|
46744
|
-
"Executing statement...",
|
|
46745
|
-
() => node.duckdb.db(options.db).execute(sqlStr, params)
|
|
46746
|
-
);
|
|
46747
|
-
if (!result.ok) {
|
|
46748
|
-
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
46749
|
-
}
|
|
46750
|
-
outputJson({ changes: result.data.changes });
|
|
46751
|
-
} catch (error) {
|
|
46752
|
-
handleError(error);
|
|
46753
|
-
}
|
|
46754
|
-
});
|
|
46755
|
-
duckdb.command("describe").description("Show database schema (tables, columns, views)").option("--db <name>", "Database name", "default").action(async (options, cmd) => {
|
|
46756
|
-
try {
|
|
46757
|
-
const globalOpts = cmd.optsWithGlobals();
|
|
46758
|
-
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
46759
|
-
const node = await ensureAuthenticated(ctx);
|
|
46760
|
-
const result = await withSpinner(
|
|
46761
|
-
"Describing schema...",
|
|
46762
|
-
() => node.duckdb.db(options.db).describe()
|
|
46763
|
-
);
|
|
46764
|
-
if (!result.ok) {
|
|
46765
|
-
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
46766
|
-
}
|
|
46767
|
-
const schema = result.data;
|
|
46768
|
-
if (shouldOutputJson()) {
|
|
46769
|
-
outputJson(schema);
|
|
46770
|
-
} else {
|
|
46771
|
-
const { tables, views } = schema;
|
|
46772
|
-
if (tables.length === 0 && views.length === 0) {
|
|
46773
|
-
process.stdout.write(theme.muted("No tables or views found.") + "\n");
|
|
46774
|
-
return;
|
|
46775
|
-
}
|
|
46776
|
-
if (tables.length > 0) {
|
|
46777
|
-
process.stdout.write(theme.label("Tables:") + "\n\n");
|
|
46778
|
-
for (const table of tables) {
|
|
46779
|
-
process.stdout.write(` ${theme.value(table.name)}
|
|
46780
|
-
`);
|
|
46781
|
-
const colRows = table.columns.map((col) => [
|
|
46782
|
-
col.name,
|
|
46783
|
-
col.type,
|
|
46784
|
-
col.nullable ? "YES" : "NO"
|
|
46785
|
-
]);
|
|
46786
|
-
const colTable = formatTable(["Column", "Type", "Nullable"], colRows);
|
|
46787
|
-
process.stdout.write(colTable.split("\n").map((l) => " " + l).join("\n") + "\n\n");
|
|
46788
|
-
}
|
|
46789
|
-
}
|
|
46790
|
-
if (views.length > 0) {
|
|
46791
|
-
process.stdout.write(theme.label("Views:") + "\n\n");
|
|
46792
|
-
const viewRows = views.map((v) => [v.name, v.sql]);
|
|
46793
|
-
process.stdout.write(formatTable(["View", "SQL"], viewRows) + "\n");
|
|
46794
|
-
}
|
|
46795
|
-
}
|
|
46796
|
-
} catch (error) {
|
|
46797
|
-
handleError(error);
|
|
46798
|
-
}
|
|
46799
|
-
});
|
|
46800
|
-
duckdb.command("export").description("Export database as binary file").option("--db <name>", "Database name", "default").option("-o, --output <file>", "Output file path", "export.duckdb").action(async (options, cmd) => {
|
|
46801
|
-
try {
|
|
46802
|
-
const globalOpts = cmd.optsWithGlobals();
|
|
46803
|
-
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
46804
|
-
const node = await ensureAuthenticated(ctx);
|
|
46805
|
-
const result = await withSpinner(
|
|
46806
|
-
"Exporting database...",
|
|
46807
|
-
() => node.duckdb.db(options.db).export()
|
|
46808
|
-
);
|
|
46809
|
-
if (!result.ok) {
|
|
46810
|
-
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
46811
|
-
}
|
|
46812
|
-
const blob = result.data;
|
|
46813
|
-
const buffer = Buffer.from(await blob.arrayBuffer());
|
|
46814
|
-
const outputPath = resolve2(options.output);
|
|
46815
|
-
await writeFile9(outputPath, buffer);
|
|
46816
|
-
outputJson({
|
|
46817
|
-
file: outputPath,
|
|
46818
|
-
size: blob.size,
|
|
46819
|
-
sizeHuman: formatBytes(blob.size)
|
|
46820
|
-
});
|
|
46821
|
-
} catch (error) {
|
|
46822
|
-
handleError(error);
|
|
46823
|
-
}
|
|
46824
|
-
});
|
|
46825
|
-
duckdb.command("import <file>").description("Import a DuckDB database file").option("--db <name>", "Database name", "default").action(async (file, options, cmd) => {
|
|
46826
|
-
try {
|
|
46827
|
-
const globalOpts = cmd.optsWithGlobals();
|
|
46828
|
-
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
46829
|
-
const node = await ensureAuthenticated(ctx);
|
|
46830
|
-
const filePath = resolve2(file);
|
|
46831
|
-
const bytes = new Uint8Array(await readFile8(filePath));
|
|
46832
|
-
const result = await withSpinner(
|
|
46833
|
-
"Importing database...",
|
|
46834
|
-
() => node.duckdb.db(options.db).import(bytes)
|
|
46835
|
-
);
|
|
46836
|
-
if (!result.ok) {
|
|
46837
|
-
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
46838
|
-
}
|
|
46839
|
-
outputJson({
|
|
46840
|
-
file: filePath,
|
|
46841
|
-
size: bytes.byteLength,
|
|
46842
|
-
sizeHuman: formatBytes(bytes.byteLength),
|
|
46843
|
-
imported: true
|
|
46844
|
-
});
|
|
46845
|
-
} catch (error) {
|
|
46846
|
-
handleError(error);
|
|
46847
|
-
}
|
|
46848
|
-
});
|
|
46849
|
-
}
|
|
46850
|
-
|
|
46851
|
-
// ../sdk-core/dist/index.js
|
|
46852
|
-
var import_siwe = __toESM(require_siwe(), 1);
|
|
46853
|
-
var import_ms2 = __toESM(require_ms(), 1);
|
|
46854
|
-
|
|
46855
|
-
// ../bootstrap/dist/index.js
|
|
46856
|
-
var DEFAULT_MANIFEST_SPACE2 = "applications";
|
|
46857
|
-
var ACCOUNT_REGISTRY_SPACE = "account";
|
|
46858
|
-
var ACCOUNT_REGISTRY_PATH = "applications/";
|
|
46859
|
-
var SECRETS_SPACE3 = "secrets";
|
|
46860
|
-
var BOOTSTRAP_DEFAULT_SPACE = "default";
|
|
46861
|
-
var BOOTSTRAP_PUBLIC_SPACE = "public";
|
|
46862
|
-
var BOOTSTRAP_ENCRYPTION_NETWORK_NAME = "default";
|
|
46863
|
-
var BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE = `urn:tinycloud:encryption:{ownerDid}:${BOOTSTRAP_ENCRYPTION_NETWORK_NAME}`;
|
|
46864
|
-
var DEFAULT_EXPIRY_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
46865
|
-
var VAULT_PERMISSION_SERVICE2 = "tinycloud.vault";
|
|
46866
|
-
var ENCRYPTION_PERMISSION_SERVICE2 = "tinycloud.encryption";
|
|
46867
|
-
var ENCRYPTION_MANIFEST_SPACE2 = "encryption";
|
|
46868
|
-
var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
|
|
46869
|
-
var BOOTSTRAP_SPACE_NAMES = [
|
|
46870
|
-
BOOTSTRAP_DEFAULT_SPACE,
|
|
46871
|
-
DEFAULT_MANIFEST_SPACE2,
|
|
46872
|
-
ACCOUNT_REGISTRY_SPACE,
|
|
46873
|
-
SECRETS_SPACE3,
|
|
46874
|
-
BOOTSTRAP_PUBLIC_SPACE
|
|
46875
|
-
];
|
|
46876
|
-
var TINYCLOUD_DEFAULT_SPACE_MANIFEST = {
|
|
46877
|
-
app_id: "xyz.tinycloud.default",
|
|
46878
|
-
name: "TinyCloud Default Space",
|
|
46879
|
-
space: BOOTSTRAP_DEFAULT_SPACE,
|
|
46880
|
-
prefix: "",
|
|
46881
|
-
defaults: false,
|
|
46882
|
-
includePublicSpace: false,
|
|
46883
|
-
permissions: [
|
|
46884
|
-
{
|
|
46885
|
-
service: "tinycloud.kv",
|
|
46886
|
-
space: BOOTSTRAP_DEFAULT_SPACE,
|
|
46887
|
-
// Empty path = whole service on this space. Do NOT use "/": the recap
|
|
46888
|
-
// encoder joins it as `<space>/<service>//`, which the node's byte-prefix
|
|
46889
|
-
// resource matching can never extend (real paths start `<service>/x…`).
|
|
46890
|
-
path: "",
|
|
46891
|
-
actions: ["get", "put", "del", "list", "metadata"]
|
|
46892
|
-
},
|
|
46893
|
-
{
|
|
46894
|
-
service: "tinycloud.sql",
|
|
46895
|
-
space: BOOTSTRAP_DEFAULT_SPACE,
|
|
46896
|
-
path: "",
|
|
46897
|
-
actions: ["read", "write"]
|
|
46898
|
-
}
|
|
46899
|
-
]
|
|
46900
|
-
};
|
|
46901
|
-
var TINYCLOUD_APPLICATIONS_SPACE_MANIFEST = {
|
|
46902
|
-
app_id: "xyz.tinycloud.applications",
|
|
46903
|
-
name: "TinyCloud Applications Space",
|
|
46904
|
-
space: DEFAULT_MANIFEST_SPACE2,
|
|
46905
|
-
prefix: "",
|
|
46906
|
-
defaults: false,
|
|
46907
|
-
includePublicSpace: false,
|
|
46908
|
-
permissions: [
|
|
46909
|
-
{
|
|
46910
|
-
service: "tinycloud.kv",
|
|
46911
|
-
space: DEFAULT_MANIFEST_SPACE2,
|
|
46912
|
-
// Empty path = whole service on this space. Do NOT use "/": the recap
|
|
46913
|
-
// encoder joins it as `<space>/<service>//`, which the node's byte-prefix
|
|
46914
|
-
// resource matching can never extend (real paths start `<service>/x…`).
|
|
46915
|
-
path: "",
|
|
46916
|
-
actions: ["get", "put", "del", "list", "metadata"]
|
|
46917
|
-
},
|
|
46918
|
-
{
|
|
46919
|
-
service: "tinycloud.sql",
|
|
46920
|
-
space: DEFAULT_MANIFEST_SPACE2,
|
|
46921
|
-
path: "",
|
|
46922
|
-
actions: ["read", "write"]
|
|
46923
|
-
}
|
|
46924
|
-
]
|
|
46925
|
-
};
|
|
46926
|
-
var TINYCLOUD_ACCOUNT_SPACE_MANIFEST = {
|
|
46927
|
-
app_id: "xyz.tinycloud.account",
|
|
46928
|
-
name: "TinyCloud Account Registry",
|
|
46929
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
46930
|
-
prefix: "",
|
|
46931
|
-
defaults: false,
|
|
46932
|
-
includePublicSpace: false,
|
|
46933
|
-
permissions: [
|
|
46934
|
-
{
|
|
46935
|
-
service: "tinycloud.kv",
|
|
46936
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
46937
|
-
path: "applications/",
|
|
46938
|
-
actions: ["get", "put", "list"]
|
|
46939
|
-
},
|
|
46940
|
-
{
|
|
46941
|
-
service: "tinycloud.kv",
|
|
46942
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
46943
|
-
path: "spaces/",
|
|
46944
|
-
actions: ["get", "put", "list"]
|
|
46945
|
-
},
|
|
46946
|
-
{
|
|
46947
|
-
service: "tinycloud.sql",
|
|
46948
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
46949
|
-
path: "account",
|
|
46950
|
-
actions: ["read", "write", "schema"]
|
|
46951
|
-
}
|
|
46952
|
-
]
|
|
46953
|
-
};
|
|
46954
|
-
var TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST = {
|
|
46955
|
-
app_id: "xyz.tinycloud.secrets",
|
|
46956
|
-
name: "TinyCloud Secrets",
|
|
46957
|
-
space: SECRETS_SPACE3,
|
|
46958
|
-
prefix: "",
|
|
46959
|
-
defaults: false,
|
|
46960
|
-
includePublicSpace: false,
|
|
46961
|
-
permissions: [
|
|
46962
|
-
{
|
|
46963
|
-
service: "tinycloud.vault",
|
|
46964
|
-
space: SECRETS_SPACE3,
|
|
46965
|
-
path: "secrets/",
|
|
46966
|
-
actions: ["read"],
|
|
46967
|
-
skipPrefix: true
|
|
46968
|
-
},
|
|
46969
|
-
{
|
|
46970
|
-
service: "tinycloud.kv",
|
|
46971
|
-
space: SECRETS_SPACE3,
|
|
46972
|
-
path: "variables",
|
|
46973
|
-
actions: ["list", "metadata"],
|
|
46974
|
-
skipPrefix: true
|
|
46975
|
-
},
|
|
46976
|
-
{
|
|
46977
|
-
service: "tinycloud.kv",
|
|
46978
|
-
space: SECRETS_SPACE3,
|
|
46979
|
-
path: "variables/",
|
|
46980
|
-
actions: ["get", "put", "del", "list", "metadata"],
|
|
46981
|
-
skipPrefix: true
|
|
46982
|
-
},
|
|
46983
|
-
{
|
|
46984
|
-
service: "tinycloud.sql",
|
|
46985
|
-
space: SECRETS_SPACE3,
|
|
46986
|
-
path: "default",
|
|
46987
|
-
actions: ["read", "write", "schema"],
|
|
46988
|
-
skipPrefix: true
|
|
46989
|
-
},
|
|
46990
|
-
{
|
|
46991
|
-
service: "tinycloud.capabilities",
|
|
46992
|
-
space: SECRETS_SPACE3,
|
|
46993
|
-
path: "",
|
|
46994
|
-
actions: ["read"],
|
|
46995
|
-
skipPrefix: true
|
|
46996
|
-
}
|
|
46997
|
-
]
|
|
46998
|
-
};
|
|
46999
|
-
var TINYCLOUD_PUBLIC_SPACE_MANIFEST = {
|
|
47000
|
-
app_id: "xyz.tinycloud.public",
|
|
47001
|
-
name: "TinyCloud Public Space",
|
|
47002
|
-
space: BOOTSTRAP_PUBLIC_SPACE,
|
|
47003
|
-
prefix: "",
|
|
47004
|
-
defaults: false,
|
|
47005
|
-
includePublicSpace: false,
|
|
47006
|
-
permissions: [
|
|
47007
|
-
{
|
|
47008
|
-
service: "tinycloud.kv",
|
|
47009
|
-
space: BOOTSTRAP_PUBLIC_SPACE,
|
|
47010
|
-
path: "",
|
|
47011
|
-
actions: ["get", "list", "metadata"]
|
|
47012
|
-
}
|
|
47013
|
-
]
|
|
47014
|
-
};
|
|
47015
|
-
var BOOTSTRAP_SPACE_MANIFESTS = {
|
|
47016
|
-
[BOOTSTRAP_DEFAULT_SPACE]: TINYCLOUD_DEFAULT_SPACE_MANIFEST,
|
|
47017
|
-
[DEFAULT_MANIFEST_SPACE2]: TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
|
|
47018
|
-
[ACCOUNT_REGISTRY_SPACE]: TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
|
|
47019
|
-
[SECRETS_SPACE3]: TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
|
|
47020
|
-
[BOOTSTRAP_PUBLIC_SPACE]: TINYCLOUD_PUBLIC_SPACE_MANIFEST
|
|
47021
|
-
};
|
|
47022
|
-
var BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS = [
|
|
47023
|
-
TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST
|
|
47024
|
-
];
|
|
47025
|
-
var ACCOUNT_INDEX_SCHEMA = [
|
|
47026
|
-
`CREATE TABLE IF NOT EXISTS applications (
|
|
47027
|
-
app_id TEXT PRIMARY KEY,
|
|
47028
|
-
name TEXT,
|
|
47029
|
-
description TEXT,
|
|
47030
|
-
updated_at TEXT,
|
|
47031
|
-
manifest_json TEXT NOT NULL
|
|
47032
|
-
)`,
|
|
47033
|
-
`CREATE TABLE IF NOT EXISTS application_state (
|
|
47034
|
-
app_id TEXT PRIMARY KEY,
|
|
47035
|
-
manifest_hash TEXT NOT NULL,
|
|
47036
|
-
indexed_at TEXT NOT NULL
|
|
47037
|
-
)`,
|
|
47038
|
-
`CREATE TABLE IF NOT EXISTS spaces (
|
|
47039
|
-
space_id TEXT PRIMARY KEY,
|
|
47040
|
-
name TEXT NOT NULL,
|
|
47041
|
-
owner_did TEXT NOT NULL,
|
|
47042
|
-
type TEXT NOT NULL,
|
|
47043
|
-
permissions_json TEXT NOT NULL,
|
|
47044
|
-
status TEXT NOT NULL,
|
|
47045
|
-
registered_at TEXT,
|
|
47046
|
-
updated_at TEXT NOT NULL,
|
|
47047
|
-
expires_at TEXT
|
|
47048
|
-
)`,
|
|
47049
|
-
`CREATE TABLE IF NOT EXISTS delegations (
|
|
47050
|
-
cid TEXT PRIMARY KEY,
|
|
47051
|
-
direction TEXT NOT NULL,
|
|
47052
|
-
space_id TEXT NOT NULL,
|
|
47053
|
-
space_name TEXT,
|
|
47054
|
-
counterparty_did TEXT NOT NULL,
|
|
47055
|
-
delegate_did TEXT NOT NULL,
|
|
47056
|
-
delegator_did TEXT,
|
|
47057
|
-
path TEXT NOT NULL,
|
|
47058
|
-
actions_json TEXT NOT NULL,
|
|
47059
|
-
expiry TEXT NOT NULL,
|
|
47060
|
-
status TEXT NOT NULL,
|
|
47061
|
-
created_at TEXT,
|
|
47062
|
-
updated_at TEXT NOT NULL
|
|
47063
|
-
)`,
|
|
47064
|
-
`CREATE TABLE IF NOT EXISTS sync_state (
|
|
47065
|
-
source TEXT PRIMARY KEY,
|
|
47066
|
-
synced_at TEXT NOT NULL,
|
|
47067
|
-
count INTEGER NOT NULL
|
|
47068
|
-
)`,
|
|
47069
|
-
"CREATE INDEX IF NOT EXISTS idx_delegations_direction ON delegations(direction)",
|
|
47070
|
-
"CREATE INDEX IF NOT EXISTS idx_delegations_space ON delegations(space_id)",
|
|
47071
|
-
"CREATE INDEX IF NOT EXISTS idx_delegations_counterparty ON delegations(counterparty_did)",
|
|
47072
|
-
"CREATE INDEX IF NOT EXISTS idx_spaces_owner ON spaces(owner_did)",
|
|
47073
|
-
"CREATE INDEX IF NOT EXISTS idx_spaces_type ON spaces(type)"
|
|
47074
|
-
];
|
|
47075
|
-
var SECRET_RECORDS_SCHEMA = [
|
|
47076
|
-
`CREATE TABLE IF NOT EXISTS secret_records (
|
|
47077
|
-
scope TEXT NOT NULL,
|
|
47078
|
-
name TEXT NOT NULL,
|
|
47079
|
-
provider_id TEXT,
|
|
47080
|
-
custom_note TEXT,
|
|
47081
|
-
created_at TEXT NOT NULL,
|
|
47082
|
-
updated_at TEXT NOT NULL,
|
|
47083
|
-
last_tested TEXT,
|
|
47084
|
-
test_status TEXT,
|
|
47085
|
-
test_message TEXT,
|
|
47086
|
-
PRIMARY KEY(scope, name)
|
|
47087
|
-
)`
|
|
47088
|
-
];
|
|
47089
|
-
var BOOTSTRAP_MANIFEST = {
|
|
47090
|
-
spaces: BOOTSTRAP_SPACE_NAMES.map((name2) => ({
|
|
47091
|
-
name: name2,
|
|
47092
|
-
manifest: BOOTSTRAP_SPACE_MANIFESTS[name2],
|
|
47093
|
-
persistedAsApplication: name2 === SECRETS_SPACE3
|
|
47094
|
-
})),
|
|
47095
|
-
applications: BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS,
|
|
47096
|
-
accountIndexSchema: ACCOUNT_INDEX_SCHEMA,
|
|
47097
|
-
secretRecordsSchema: SECRET_RECORDS_SCHEMA,
|
|
47098
|
-
encryptionNetwork: {
|
|
47099
|
-
name: BOOTSTRAP_ENCRYPTION_NETWORK_NAME
|
|
47100
|
-
}
|
|
47101
|
-
};
|
|
47102
|
-
function cloneManifest(manifest) {
|
|
47103
|
-
return {
|
|
47104
|
-
...manifest,
|
|
47105
|
-
permissions: manifest.permissions?.map((permission) => ({
|
|
47106
|
-
...permission,
|
|
47107
|
-
actions: [...permission.actions]
|
|
47108
|
-
}))
|
|
47109
|
-
};
|
|
47110
|
-
}
|
|
47111
|
-
function actionUrn(service, action) {
|
|
47112
|
-
return action.includes("/") ? action : `${service}/${action}`;
|
|
47113
|
-
}
|
|
47114
|
-
function applyPrefix2(prefix, path, skipPrefix) {
|
|
47115
|
-
if (skipPrefix === true || prefix === "" || path === "") {
|
|
47116
|
-
return path;
|
|
47117
|
-
}
|
|
47118
|
-
if (path === "/") {
|
|
47119
|
-
return `${prefix}/`;
|
|
47120
|
-
}
|
|
47121
|
-
const trimmedPrefix = prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
47122
|
-
const trimmedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
47123
|
-
return `${trimmedPrefix}/${trimmedPath}`;
|
|
47124
|
-
}
|
|
47125
|
-
function expandVaultPermission(entry) {
|
|
47126
|
-
return entry.actions.map((action) => {
|
|
47127
|
-
const normalized = action.startsWith("tinycloud.vault/") ? action.slice("tinycloud.vault/".length) : action.startsWith("tinycloud.kv/") ? action.slice("tinycloud.kv/".length) : action;
|
|
47128
|
-
const mapped = normalized === "read" || normalized === "get" ? "tinycloud.kv/get" : normalized === "write" || normalized === "put" ? "tinycloud.kv/put" : normalized === "delete" || normalized === "del" ? "tinycloud.kv/del" : normalized === "list" ? "tinycloud.kv/list" : normalized === "metadata" ? "tinycloud.kv/metadata" : void 0;
|
|
47129
|
-
if (mapped === void 0) {
|
|
47130
|
-
throw new Error(`unknown vault action ${JSON.stringify(action)}`);
|
|
47225
|
+
} else {
|
|
47226
|
+
if (rows.length === 0) {
|
|
47227
|
+
process.stdout.write(theme.muted("No rows returned.") + "\n");
|
|
47228
|
+
} else {
|
|
47229
|
+
const stringRows = rows.map(
|
|
47230
|
+
(row) => row.map((v) => v === null ? "NULL" : String(v))
|
|
47231
|
+
);
|
|
47232
|
+
process.stdout.write(formatTable(columns, stringRows) + "\n");
|
|
47233
|
+
process.stdout.write(theme.muted(`
|
|
47234
|
+
${rowCount} row${rowCount === 1 ? "" : "s"} returned`) + "\n");
|
|
47235
|
+
}
|
|
47236
|
+
}
|
|
47237
|
+
} catch (error) {
|
|
47238
|
+
handleError(error);
|
|
47131
47239
|
}
|
|
47132
|
-
const normalizedPath = entry.path.startsWith("/") ? entry.path.slice(1) : entry.path;
|
|
47133
|
-
return {
|
|
47134
|
-
...entry,
|
|
47135
|
-
service: "tinycloud.kv",
|
|
47136
|
-
path: `vault/${normalizedPath}`,
|
|
47137
|
-
actions: [mapped],
|
|
47138
|
-
skipPrefix: true
|
|
47139
|
-
};
|
|
47140
47240
|
});
|
|
47141
|
-
|
|
47142
|
-
|
|
47143
|
-
|
|
47144
|
-
|
|
47145
|
-
|
|
47146
|
-
|
|
47147
|
-
|
|
47148
|
-
|
|
47149
|
-
|
|
47150
|
-
|
|
47151
|
-
|
|
47152
|
-
|
|
47153
|
-
|
|
47154
|
-
|
|
47155
|
-
|
|
47156
|
-
|
|
47157
|
-
];
|
|
47158
|
-
}
|
|
47159
|
-
function dedupeResources2(resources) {
|
|
47160
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
47161
|
-
for (const resource of resources) {
|
|
47162
|
-
const key2 = `${resource.service}\0${resource.space}\0${resource.path}`;
|
|
47163
|
-
const existing = byKey.get(key2);
|
|
47164
|
-
if (!existing) {
|
|
47165
|
-
byKey.set(key2, { ...resource, actions: [...resource.actions] });
|
|
47166
|
-
continue;
|
|
47241
|
+
duckdb.command("execute <sql>").description("Run INSERT/UPDATE/DELETE/DDL statement").option("--db <name>", "Database name", "default").option("--params <json>", "Bind parameters as JSON array").action(async (sqlStr, options, cmd) => {
|
|
47242
|
+
try {
|
|
47243
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
47244
|
+
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
47245
|
+
const node = await ensureAuthenticated(ctx);
|
|
47246
|
+
const params = options.params ? JSON.parse(options.params) : void 0;
|
|
47247
|
+
const result = await withSpinner(
|
|
47248
|
+
"Executing statement...",
|
|
47249
|
+
() => node.duckdb.db(options.db).execute(sqlStr, params)
|
|
47250
|
+
);
|
|
47251
|
+
if (!result.ok) {
|
|
47252
|
+
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
47253
|
+
}
|
|
47254
|
+
outputJson({ changes: result.data.changes });
|
|
47255
|
+
} catch (error) {
|
|
47256
|
+
handleError(error);
|
|
47167
47257
|
}
|
|
47168
|
-
|
|
47169
|
-
|
|
47170
|
-
|
|
47258
|
+
});
|
|
47259
|
+
duckdb.command("describe").description("Show database schema (tables, columns, views)").option("--db <name>", "Database name", "default").action(async (options, cmd) => {
|
|
47260
|
+
try {
|
|
47261
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
47262
|
+
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
47263
|
+
const node = await ensureAuthenticated(ctx);
|
|
47264
|
+
const result = await withSpinner(
|
|
47265
|
+
"Describing schema...",
|
|
47266
|
+
() => node.duckdb.db(options.db).describe()
|
|
47267
|
+
);
|
|
47268
|
+
if (!result.ok) {
|
|
47269
|
+
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
47270
|
+
}
|
|
47271
|
+
const schema = result.data;
|
|
47272
|
+
if (shouldOutputJson()) {
|
|
47273
|
+
outputJson(schema);
|
|
47274
|
+
} else {
|
|
47275
|
+
const { tables, views } = schema;
|
|
47276
|
+
if (tables.length === 0 && views.length === 0) {
|
|
47277
|
+
process.stdout.write(theme.muted("No tables or views found.") + "\n");
|
|
47278
|
+
return;
|
|
47279
|
+
}
|
|
47280
|
+
if (tables.length > 0) {
|
|
47281
|
+
process.stdout.write(theme.label("Tables:") + "\n\n");
|
|
47282
|
+
for (const table of tables) {
|
|
47283
|
+
process.stdout.write(` ${theme.value(table.name)}
|
|
47284
|
+
`);
|
|
47285
|
+
const colRows = table.columns.map((col) => [
|
|
47286
|
+
col.name,
|
|
47287
|
+
col.type,
|
|
47288
|
+
col.nullable ? "YES" : "NO"
|
|
47289
|
+
]);
|
|
47290
|
+
const colTable = formatTable(["Column", "Type", "Nullable"], colRows);
|
|
47291
|
+
process.stdout.write(colTable.split("\n").map((l) => " " + l).join("\n") + "\n\n");
|
|
47292
|
+
}
|
|
47293
|
+
}
|
|
47294
|
+
if (views.length > 0) {
|
|
47295
|
+
process.stdout.write(theme.label("Views:") + "\n\n");
|
|
47296
|
+
const viewRows = views.map((v) => [v.name, v.sql]);
|
|
47297
|
+
process.stdout.write(formatTable(["View", "SQL"], viewRows) + "\n");
|
|
47298
|
+
}
|
|
47171
47299
|
}
|
|
47300
|
+
} catch (error) {
|
|
47301
|
+
handleError(error);
|
|
47172
47302
|
}
|
|
47173
|
-
}
|
|
47174
|
-
|
|
47175
|
-
|
|
47176
|
-
|
|
47177
|
-
|
|
47178
|
-
|
|
47179
|
-
|
|
47180
|
-
|
|
47181
|
-
|
|
47182
|
-
|
|
47183
|
-
|
|
47184
|
-
|
|
47185
|
-
|
|
47186
|
-
|
|
47187
|
-
|
|
47188
|
-
|
|
47189
|
-
|
|
47190
|
-
|
|
47191
|
-
|
|
47192
|
-
|
|
47193
|
-
|
|
47194
|
-
|
|
47195
|
-
|
|
47196
|
-
|
|
47197
|
-
},
|
|
47198
|
-
{
|
|
47199
|
-
service: "tinycloud.kv",
|
|
47200
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
47201
|
-
path: "spaces/",
|
|
47202
|
-
actions: ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/list"]
|
|
47203
|
-
},
|
|
47204
|
-
{
|
|
47205
|
-
service: "tinycloud.sql",
|
|
47206
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
47207
|
-
path: "account",
|
|
47208
|
-
actions: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/schema"]
|
|
47303
|
+
});
|
|
47304
|
+
duckdb.command("export").description("Export database as binary file").option("--db <name>", "Database name", "default").option("-o, --output <file>", "Output file path", "export.duckdb").action(async (options, cmd) => {
|
|
47305
|
+
try {
|
|
47306
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
47307
|
+
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
47308
|
+
const node = await ensureAuthenticated(ctx);
|
|
47309
|
+
const result = await withSpinner(
|
|
47310
|
+
"Exporting database...",
|
|
47311
|
+
() => node.duckdb.db(options.db).export()
|
|
47312
|
+
);
|
|
47313
|
+
if (!result.ok) {
|
|
47314
|
+
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
47315
|
+
}
|
|
47316
|
+
const blob = result.data;
|
|
47317
|
+
const buffer = Buffer.from(await blob.arrayBuffer());
|
|
47318
|
+
const outputPath = resolve2(options.output);
|
|
47319
|
+
await writeFile9(outputPath, buffer);
|
|
47320
|
+
outputJson({
|
|
47321
|
+
file: outputPath,
|
|
47322
|
+
size: blob.size,
|
|
47323
|
+
sizeHuman: formatBytes(blob.size)
|
|
47324
|
+
});
|
|
47325
|
+
} catch (error) {
|
|
47326
|
+
handleError(error);
|
|
47209
47327
|
}
|
|
47210
|
-
];
|
|
47211
|
-
}
|
|
47212
|
-
function composeManifestRequest(inputs, options = {}) {
|
|
47213
|
-
if (!Array.isArray(inputs) || inputs.length === 0) {
|
|
47214
|
-
throw new Error("composeManifestRequest requires at least one manifest");
|
|
47215
|
-
}
|
|
47216
|
-
const includeAccountRegistryPermissions = options.includeAccountRegistryPermissions ?? true;
|
|
47217
|
-
const manifests = inputs.map(cloneManifest);
|
|
47218
|
-
const resources = manifests.flatMap((manifest) => {
|
|
47219
|
-
const prefix = manifest.prefix ?? manifest.app_id;
|
|
47220
|
-
const space = manifest.space ?? DEFAULT_MANIFEST_SPACE2;
|
|
47221
|
-
const explicit = manifest.permissions ?? [];
|
|
47222
|
-
return explicit.flatMap((entry) => expandPermissionEntry2(entry, prefix, space));
|
|
47223
47328
|
});
|
|
47224
|
-
|
|
47225
|
-
|
|
47226
|
-
|
|
47227
|
-
|
|
47228
|
-
|
|
47229
|
-
|
|
47230
|
-
|
|
47231
|
-
|
|
47232
|
-
|
|
47233
|
-
|
|
47234
|
-
|
|
47235
|
-
|
|
47236
|
-
|
|
47237
|
-
|
|
47238
|
-
|
|
47239
|
-
|
|
47240
|
-
|
|
47241
|
-
|
|
47242
|
-
|
|
47243
|
-
|
|
47244
|
-
|
|
47245
|
-
|
|
47246
|
-
|
|
47247
|
-
}
|
|
47248
|
-
function composeBootstrapSpaceManifest(space) {
|
|
47249
|
-
return composeManifestRequest([BOOTSTRAP_SPACE_MANIFESTS[space]], {
|
|
47250
|
-
includeAccountRegistryPermissions: false
|
|
47329
|
+
duckdb.command("import <file>").description("Import a DuckDB database file").option("--db <name>", "Database name", "default").action(async (file, options, cmd) => {
|
|
47330
|
+
try {
|
|
47331
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
47332
|
+
const ctx = await ProfileManager.resolveContext(globalOpts);
|
|
47333
|
+
const node = await ensureAuthenticated(ctx);
|
|
47334
|
+
const filePath = resolve2(file);
|
|
47335
|
+
const bytes = new Uint8Array(await readFile8(filePath));
|
|
47336
|
+
const result = await withSpinner(
|
|
47337
|
+
"Importing database...",
|
|
47338
|
+
() => node.duckdb.db(options.db).import(bytes)
|
|
47339
|
+
);
|
|
47340
|
+
if (!result.ok) {
|
|
47341
|
+
throw new CLIError(result.error.code, result.error.message, ExitCode.ERROR);
|
|
47342
|
+
}
|
|
47343
|
+
outputJson({
|
|
47344
|
+
file: filePath,
|
|
47345
|
+
size: bytes.byteLength,
|
|
47346
|
+
sizeHuman: formatBytes(bytes.byteLength),
|
|
47347
|
+
imported: true
|
|
47348
|
+
});
|
|
47349
|
+
} catch (error) {
|
|
47350
|
+
handleError(error);
|
|
47351
|
+
}
|
|
47251
47352
|
});
|
|
47252
47353
|
}
|
|
47253
|
-
|
|
47254
|
-
|
|
47255
|
-
|
|
47256
|
-
|
|
47257
|
-
composeBootstrapSpaceManifest(space)
|
|
47258
|
-
])
|
|
47259
|
-
)
|
|
47260
|
-
);
|
|
47261
|
-
var ACCOUNT_SESSION_RAW_ALLOWLIST = Object.freeze([
|
|
47262
|
-
{
|
|
47263
|
-
service: "tinycloud.encryption",
|
|
47264
|
-
resource: BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
|
|
47265
|
-
actions: [NETWORK_CREATE_ACTION]
|
|
47266
|
-
}
|
|
47267
|
-
]);
|
|
47268
|
-
var BOOTSTRAP_ALLOWLIST = Object.freeze(
|
|
47269
|
-
BOOTSTRAP_SPACE_NAMES.flatMap((space) => [
|
|
47270
|
-
{
|
|
47271
|
-
kind: "session",
|
|
47272
|
-
service: "tinycloud.session",
|
|
47273
|
-
space,
|
|
47274
|
-
actions: ["siwe"],
|
|
47275
|
-
resources: BOOTSTRAP_SESSION_REQUESTS[space].resources,
|
|
47276
|
-
...space === ACCOUNT_REGISTRY_SPACE ? { rawAbilities: ACCOUNT_SESSION_RAW_ALLOWLIST } : {}
|
|
47277
|
-
},
|
|
47278
|
-
{
|
|
47279
|
-
kind: "space/host",
|
|
47280
|
-
service: "tinycloud.space",
|
|
47281
|
-
space,
|
|
47282
|
-
actions: ["tinycloud.space/host"]
|
|
47283
|
-
}
|
|
47284
|
-
])
|
|
47285
|
-
);
|
|
47354
|
+
|
|
47355
|
+
// ../sdk-core/dist/index.js
|
|
47356
|
+
var import_siwe = __toESM(require_siwe(), 1);
|
|
47357
|
+
var import_ms2 = __toESM(require_ms(), 1);
|
|
47286
47358
|
|
|
47287
47359
|
// ../../node_modules/uint8arrays/dist/src/equals.js
|
|
47288
47360
|
function equals(a, b) {
|