@onesi/genesis 0.0.1-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/auto.d.ts +1010 -0
- package/dist/auto.js +125 -0
- package/dist/beacons.d.ts +145 -0
- package/dist/beacons.js +148 -0
- package/dist/blinds-owner-enrollment.d.ts +280 -0
- package/dist/blinds-owner-enrollment.js +169 -0
- package/dist/client.d.ts +52 -0
- package/dist/client.js +384 -0
- package/dist/context.d.ts +50 -0
- package/dist/context.js +153 -0
- package/dist/dials.d.ts +299 -0
- package/dist/dials.js +100 -0
- package/dist/errors.d.ts +35 -0
- package/dist/errors.js +66 -0
- package/dist/flares.d.ts +202 -0
- package/dist/flares.js +61 -0
- package/dist/fleets.d.ts +218 -0
- package/dist/fleets.js +189 -0
- package/dist/flocks.d.ts +439 -0
- package/dist/flocks.js +98 -0
- package/dist/foundry-billing.d.ts +97 -0
- package/dist/foundry-billing.js +107 -0
- package/dist/foundry.d.ts +424 -0
- package/dist/foundry.js +133 -0
- package/dist/garden.d.ts +754 -0
- package/dist/garden.js +76 -0
- package/dist/gateway.d.ts +365 -0
- package/dist/gateway.js +82 -0
- package/dist/gears.d.ts +226 -0
- package/dist/gears.js +42 -0
- package/dist/generated/operations.d.ts +4 -0
- package/dist/generated/operations.js +65134 -0
- package/dist/generated/schema.d.ts +87658 -0
- package/dist/generated/schema.js +1 -0
- package/dist/genesis.d.ts +9574 -0
- package/dist/genesis.js +271 -0
- package/dist/genesis.openapi.json +128522 -0
- package/dist/henry.d.ts +369 -0
- package/dist/henry.js +268 -0
- package/dist/hives-cells.d.ts +127 -0
- package/dist/hives-cells.js +151 -0
- package/dist/hives-environment.d.ts +37 -0
- package/dist/hives-environment.js +80 -0
- package/dist/hives-functions.d.ts +36 -0
- package/dist/hives-functions.js +185 -0
- package/dist/hives-marketplace.d.ts +128 -0
- package/dist/hives-marketplace.js +187 -0
- package/dist/hives-node.d.ts +9 -0
- package/dist/hives-node.js +155 -0
- package/dist/hives-operations.d.ts +451 -0
- package/dist/hives-operations.js +43 -0
- package/dist/hives-platform.d.ts +149 -0
- package/dist/hives-platform.js +183 -0
- package/dist/hives-queue-consumer.d.ts +56 -0
- package/dist/hives-queue-consumer.js +95 -0
- package/dist/hives-queue-funding.d.ts +28 -0
- package/dist/hives-queue-funding.js +81 -0
- package/dist/hives-queues.d.ts +137 -0
- package/dist/hives-queues.js +143 -0
- package/dist/hives-resources-transport.d.ts +23 -0
- package/dist/hives-resources-transport.js +204 -0
- package/dist/hives-response.d.ts +2 -0
- package/dist/hives-response.js +32 -0
- package/dist/hives-runtimes.d.ts +34 -0
- package/dist/hives-runtimes.js +32 -0
- package/dist/hives-sse.d.ts +24 -0
- package/dist/hives-sse.js +111 -0
- package/dist/hives-topics.d.ts +51 -0
- package/dist/hives-topics.js +79 -0
- package/dist/hives-upload.d.ts +9 -0
- package/dist/hives-upload.js +23 -0
- package/dist/hives-volumes.d.ts +64 -0
- package/dist/hives-volumes.js +117 -0
- package/dist/iam-directory.d.ts +8 -0
- package/dist/iam-directory.js +23 -0
- package/dist/iam.d.ts +391 -0
- package/dist/iam.js +92 -0
- package/dist/idempotency.d.ts +7 -0
- package/dist/idempotency.js +39 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +37 -0
- package/dist/instances.d.ts +200 -0
- package/dist/instances.js +43 -0
- package/dist/lanes.d.ts +267 -0
- package/dist/lanes.js +41 -0
- package/dist/minds-agent.d.ts +88 -0
- package/dist/minds-agent.js +233 -0
- package/dist/minds-engine.d.ts +394 -0
- package/dist/minds-engine.js +555 -0
- package/dist/minds-owner.d.ts +110 -0
- package/dist/minds-owner.js +226 -0
- package/dist/minds.d.ts +377 -0
- package/dist/minds.js +228 -0
- package/dist/orgs.d.ts +405 -0
- package/dist/orgs.js +63 -0
- package/dist/relays-enrollment.d.ts +33 -0
- package/dist/relays-enrollment.js +115 -0
- package/dist/runner-grant.d.ts +10 -0
- package/dist/runner-grant.js +133 -0
- package/dist/runner.d.ts +72 -0
- package/dist/runner.js +117 -0
- package/dist/scopes.d.ts +310 -0
- package/dist/scopes.js +40 -0
- package/dist/taps.d.ts +118 -0
- package/dist/taps.js +45 -0
- package/dist/traces.d.ts +574 -0
- package/dist/traces.js +97 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.js +1 -0
- package/dist/urls.d.ts +6 -0
- package/dist/urls.js +31 -0
- package/package.json +49 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { GenesisClient } from './client.js';
|
|
2
|
+
import { type HivesResourceOptions } from './hives-resources-transport.js';
|
|
3
|
+
export interface HivesMarketplacePackage {
|
|
4
|
+
id: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
author_name: string;
|
|
9
|
+
visibility: 'public' | 'private' | 'unlisted';
|
|
10
|
+
categories: string[];
|
|
11
|
+
keywords: string[];
|
|
12
|
+
license: string;
|
|
13
|
+
installs: number;
|
|
14
|
+
stars: number;
|
|
15
|
+
verified: boolean;
|
|
16
|
+
featured: boolean;
|
|
17
|
+
free: boolean;
|
|
18
|
+
latest_version: string;
|
|
19
|
+
version_count: number;
|
|
20
|
+
owned: boolean;
|
|
21
|
+
created_at: string;
|
|
22
|
+
updated_at: string;
|
|
23
|
+
}
|
|
24
|
+
export interface HivesMarketplaceVersion {
|
|
25
|
+
id: string;
|
|
26
|
+
package_id: string;
|
|
27
|
+
version: string;
|
|
28
|
+
module_hash: string;
|
|
29
|
+
size_bytes: number;
|
|
30
|
+
readme: string;
|
|
31
|
+
changelog: string;
|
|
32
|
+
required_env: string[];
|
|
33
|
+
downloads: number;
|
|
34
|
+
deprecated: boolean;
|
|
35
|
+
published_at: string;
|
|
36
|
+
}
|
|
37
|
+
export interface HivesMarketplaceInstallation {
|
|
38
|
+
id: string;
|
|
39
|
+
package_id: string;
|
|
40
|
+
slug: string;
|
|
41
|
+
name: string;
|
|
42
|
+
project_id: string;
|
|
43
|
+
version: string | null;
|
|
44
|
+
deployment_id: string | null;
|
|
45
|
+
deployment_status: string | null;
|
|
46
|
+
pending_version: string | null;
|
|
47
|
+
pending_deployment_id: string | null;
|
|
48
|
+
pending_deployment_status: string | null;
|
|
49
|
+
operation: 'install' | 'update' | 'cleanup' | 'uninstall' | null;
|
|
50
|
+
status: 'active' | 'updating' | 'failed' | 'uninstalled';
|
|
51
|
+
latest_version: string | null;
|
|
52
|
+
installed_at: string;
|
|
53
|
+
}
|
|
54
|
+
export interface HivesMarketplaceCategory {
|
|
55
|
+
id: string;
|
|
56
|
+
slug: string;
|
|
57
|
+
name: string;
|
|
58
|
+
description: string | null;
|
|
59
|
+
icon_url: string | null;
|
|
60
|
+
package_count: number;
|
|
61
|
+
sort_order: number;
|
|
62
|
+
}
|
|
63
|
+
export interface HivesMarketplacePage<T> {
|
|
64
|
+
data: T[];
|
|
65
|
+
pagination: {
|
|
66
|
+
page: number;
|
|
67
|
+
page_size: number;
|
|
68
|
+
total: number;
|
|
69
|
+
total_pages: number;
|
|
70
|
+
has_next: boolean;
|
|
71
|
+
has_prev: boolean;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export interface HivesMarketplacePublish {
|
|
75
|
+
slug: string;
|
|
76
|
+
name: string;
|
|
77
|
+
module_hash: string;
|
|
78
|
+
version: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
visibility?: HivesMarketplacePackage['visibility'];
|
|
81
|
+
categories?: string[];
|
|
82
|
+
keywords?: string[];
|
|
83
|
+
readme?: string;
|
|
84
|
+
changelog?: string;
|
|
85
|
+
required_env?: string[];
|
|
86
|
+
license?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface HivesMarketplaceInstall {
|
|
89
|
+
version?: string | null;
|
|
90
|
+
env_overrides?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
export interface HivesMarketplaceSearch {
|
|
93
|
+
q?: string | null;
|
|
94
|
+
category?: string | null;
|
|
95
|
+
free_only?: boolean;
|
|
96
|
+
verified_only?: boolean;
|
|
97
|
+
sort?: 'name' | 'installs' | 'stars' | 'created' | 'updated';
|
|
98
|
+
order?: 'asc' | 'desc';
|
|
99
|
+
page?: number;
|
|
100
|
+
page_size?: number;
|
|
101
|
+
}
|
|
102
|
+
export type HivesMarketplaceDetail = HivesMarketplacePackage & {
|
|
103
|
+
versions: HivesMarketplaceVersion[];
|
|
104
|
+
};
|
|
105
|
+
/** Native Marketplace reuses verified project ownership and persisted deployment lifecycle.
|
|
106
|
+
* Writes are sent once. Read/reconcile saved state after an uncertain acknowledgement. */
|
|
107
|
+
export declare function hivesMarketplace(client: GenesisClient): {
|
|
108
|
+
list(project: string, query?: HivesMarketplaceSearch, options?: HivesResourceOptions): Promise<HivesMarketplacePage<HivesMarketplacePackage>>;
|
|
109
|
+
get(project: string, packageSlug: string, query?: {
|
|
110
|
+
version?: string | null;
|
|
111
|
+
}, options?: HivesResourceOptions): Promise<HivesMarketplaceDetail>;
|
|
112
|
+
versions(project: string, packageSlug: string, query?: {
|
|
113
|
+
page?: number;
|
|
114
|
+
page_size?: number;
|
|
115
|
+
}, options?: HivesResourceOptions): Promise<HivesMarketplacePage<HivesMarketplaceVersion>>;
|
|
116
|
+
featured(project: string, options?: HivesResourceOptions): Promise<HivesMarketplacePage<HivesMarketplacePackage>>;
|
|
117
|
+
categories(project: string, options?: HivesResourceOptions): Promise<HivesMarketplaceCategory[]>;
|
|
118
|
+
publish(project: string, input: HivesMarketplacePublish, options?: HivesResourceOptions): Promise<HivesMarketplaceDetail>;
|
|
119
|
+
install(project: string, packageSlug: string, input?: HivesMarketplaceInstall, options?: HivesResourceOptions): Promise<HivesMarketplaceInstallation>;
|
|
120
|
+
update(project: string, packageSlug: string, input?: HivesMarketplaceInstall, options?: HivesResourceOptions): Promise<HivesMarketplaceInstallation>;
|
|
121
|
+
installed(project: string, query?: {
|
|
122
|
+
page?: number;
|
|
123
|
+
page_size?: number;
|
|
124
|
+
}, options?: HivesResourceOptions): Promise<HivesMarketplacePage<HivesMarketplaceInstallation>>;
|
|
125
|
+
getInstallation(project: string, id: string, options?: HivesResourceOptions): Promise<HivesMarketplaceInstallation>;
|
|
126
|
+
reconcile(project: string, id: string, options?: HivesResourceOptions): Promise<HivesMarketplaceInstallation>;
|
|
127
|
+
uninstall(project: string, id: string, options?: HivesResourceOptions): Promise<HivesMarketplaceInstallation>;
|
|
128
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { hivesResourceCall, hivesResourceId, resourceError } from './hives-resources-transport.js';
|
|
2
|
+
function invalid() { throw resourceError(0); }
|
|
3
|
+
function record(value) { if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
4
|
+
invalid(); return value; }
|
|
5
|
+
function keys(value, allowed) { if (Object.keys(value).some(key => !allowed.includes(key)))
|
|
6
|
+
invalid(); }
|
|
7
|
+
function text(value, max) { if (typeof value !== 'string' || new TextEncoder().encode(value).length > max)
|
|
8
|
+
invalid(); return value; }
|
|
9
|
+
function uuid(value) { const result = text(value, 36); if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(result))
|
|
10
|
+
invalid(); return result.toLowerCase(); }
|
|
11
|
+
function slug(value) { const result = text(value, 64); if (!/^[a-z][a-z0-9-]*[a-z0-9]$/.test(result))
|
|
12
|
+
invalid(); return result; }
|
|
13
|
+
function semver(value, maxCore = 18446744073709551615n) {
|
|
14
|
+
const result = text(value, 64);
|
|
15
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(result);
|
|
16
|
+
if (!match || match.slice(1, 4).some(part => BigInt(part) > maxCore)
|
|
17
|
+
|| match[4]?.split('.').some(part => /^\d+$/.test(part) && part.length > 1 && part.startsWith('0')))
|
|
18
|
+
invalid();
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function count(value, min = 0, max = Number.MAX_SAFE_INTEGER) { if (!Number.isSafeInteger(value) || value < min || value > max)
|
|
22
|
+
invalid(); return value; }
|
|
23
|
+
function bool(value) { if (typeof value !== 'boolean')
|
|
24
|
+
invalid(); return value; }
|
|
25
|
+
function strings(value, limit, max) { if (!Array.isArray(value) || value.length > limit)
|
|
26
|
+
invalid(); return value.map(item => text(item, max)); }
|
|
27
|
+
function date(value) { const result = text(value, 64); if (!Number.isFinite(Date.parse(result)))
|
|
28
|
+
invalid(); return result; }
|
|
29
|
+
function nullable(value, parse) { return value === null ? null : parse(value); }
|
|
30
|
+
function deployment(value) { const id = text(value, 64); if (!/^dpl_[A-Za-z0-9_-]+$/.test(id))
|
|
31
|
+
invalid(); return id; }
|
|
32
|
+
function packageRow(value) {
|
|
33
|
+
const r = record(value);
|
|
34
|
+
if (!['public', 'private', 'unlisted'].includes(String(r.visibility)) || r.visibility === 'private' && r.owned !== true)
|
|
35
|
+
invalid();
|
|
36
|
+
return { id: uuid(r.id), slug: slug(r.slug), name: text(r.name, 128), description: text(r.description, 500), author_name: text(r.author_name, 1000),
|
|
37
|
+
visibility: r.visibility, categories: strings(r.categories, 5, 64), keywords: strings(r.keywords, 20, 64), license: text(r.license, 64),
|
|
38
|
+
installs: count(r.installs), stars: count(r.stars), verified: bool(r.verified), featured: bool(r.featured), free: bool(r.free),
|
|
39
|
+
latest_version: semver(r.latest_version), version_count: count(r.version_count, 1), owned: bool(r.owned), created_at: date(r.created_at), updated_at: date(r.updated_at) };
|
|
40
|
+
}
|
|
41
|
+
function versionRow(value, expectedPackage) {
|
|
42
|
+
const r = record(value);
|
|
43
|
+
const packageId = uuid(r.package_id);
|
|
44
|
+
const hash = text(r.module_hash, 64);
|
|
45
|
+
if (expectedPackage && packageId !== expectedPackage || !/^[a-f0-9]{64}$/.test(hash))
|
|
46
|
+
invalid();
|
|
47
|
+
return { id: uuid(r.id), package_id: packageId, version: semver(r.version), module_hash: hash, size_bytes: count(r.size_bytes, 1, 10 * 1024 * 1024),
|
|
48
|
+
readme: text(r.readme, 50_000), changelog: text(r.changelog, 2000), required_env: strings(r.required_env, 50, 128), downloads: count(r.downloads), deprecated: bool(r.deprecated), published_at: date(r.published_at) };
|
|
49
|
+
}
|
|
50
|
+
function installationRow(value, project, expectedId) {
|
|
51
|
+
const r = record(value);
|
|
52
|
+
if (r.project_id !== project || expectedId && uuid(r.id) !== uuid(expectedId) || !['active', 'updating', 'failed', 'uninstalled'].includes(String(r.status))
|
|
53
|
+
|| !(r.operation === null || ['install', 'update', 'cleanup', 'uninstall'].includes(String(r.operation))))
|
|
54
|
+
invalid();
|
|
55
|
+
const result = { id: uuid(r.id), package_id: uuid(r.package_id), slug: slug(r.slug), name: text(r.name, 128), project_id: project,
|
|
56
|
+
version: nullable(r.version, semver), deployment_id: nullable(r.deployment_id, deployment), deployment_status: nullable(r.deployment_status, v => text(v, 32)),
|
|
57
|
+
pending_version: nullable(r.pending_version, semver), pending_deployment_id: nullable(r.pending_deployment_id, deployment), pending_deployment_status: nullable(r.pending_deployment_status, v => text(v, 32)),
|
|
58
|
+
operation: r.operation, status: r.status,
|
|
59
|
+
latest_version: nullable(r.latest_version, semver), installed_at: date(r.installed_at) };
|
|
60
|
+
if (result.status === 'uninstalled' && (result.operation || result.deployment_id || result.pending_deployment_id))
|
|
61
|
+
invalid();
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function page(value, pageNumber, pageSize, parse) {
|
|
65
|
+
const r = record(value);
|
|
66
|
+
const p = record(r.pagination);
|
|
67
|
+
const total = count(p.total);
|
|
68
|
+
const pages = Math.ceil(total / pageSize);
|
|
69
|
+
if (p.page !== pageNumber || p.page_size !== pageSize || p.total_pages !== pages || p.has_next !== (pageNumber < pages) || p.has_prev !== (pageNumber > 1)
|
|
70
|
+
|| !Array.isArray(r.data) || r.data.length > pageSize)
|
|
71
|
+
invalid();
|
|
72
|
+
const data = r.data.map(parse);
|
|
73
|
+
if (new Set(data.map(row => row.id)).size !== data.length)
|
|
74
|
+
invalid();
|
|
75
|
+
return { data, pagination: { page: pageNumber, page_size: pageSize, total, total_pages: pages, has_next: pageNumber < pages, has_prev: pageNumber > 1 } };
|
|
76
|
+
}
|
|
77
|
+
function details(value, expectedSlug, exactVersion) {
|
|
78
|
+
const r = record(value);
|
|
79
|
+
const pkg = packageRow(r);
|
|
80
|
+
if (pkg.slug !== expectedSlug || !Array.isArray(r.versions) || r.versions.length > 5 || r.versions.length === 0)
|
|
81
|
+
invalid();
|
|
82
|
+
const versions = r.versions.map(row => versionRow(row, pkg.id));
|
|
83
|
+
if (new Set(versions.map(row => row.id)).size !== versions.length || exactVersion && versions.some(row => row.version !== exactVersion))
|
|
84
|
+
invalid();
|
|
85
|
+
return { ...pkg, versions };
|
|
86
|
+
}
|
|
87
|
+
function pagination(query, max) {
|
|
88
|
+
keys(record(query), ['page', 'page_size']);
|
|
89
|
+
return { page: count(query.page ?? 1, 1, 100_000), page_size: count(query.page_size ?? max, 1, max) };
|
|
90
|
+
}
|
|
91
|
+
function installInput(input) {
|
|
92
|
+
const r = record(input);
|
|
93
|
+
keys(r, ['version', 'env_overrides']);
|
|
94
|
+
const env = record(r.env_overrides ?? {});
|
|
95
|
+
if (Object.keys(env).length > 50)
|
|
96
|
+
invalid();
|
|
97
|
+
const entries = Object.entries(env).map(([key, value]) => [text(key, 128), text(value, 4096)]);
|
|
98
|
+
return { ...(r.version == null ? {} : { version: semver(r.version) }), env_overrides: Object.fromEntries(entries) };
|
|
99
|
+
}
|
|
100
|
+
function publishInput(input) {
|
|
101
|
+
const r = record(input);
|
|
102
|
+
keys(r, ['slug', 'name', 'module_hash', 'version', 'description', 'visibility', 'categories', 'keywords', 'readme', 'changelog', 'required_env', 'license']);
|
|
103
|
+
const name = text(r.name, 128);
|
|
104
|
+
const hash = text(r.module_hash, 64);
|
|
105
|
+
const visibility = r.visibility ?? 'public';
|
|
106
|
+
if (!name.trim() || !/^[a-f0-9]{64}$/.test(hash) || !['public', 'private', 'unlisted'].includes(String(visibility)))
|
|
107
|
+
invalid();
|
|
108
|
+
const required = strings(r.required_env ?? [], 50, 128);
|
|
109
|
+
if (new Set(required).size !== required.length || required.some(key => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)))
|
|
110
|
+
invalid();
|
|
111
|
+
return { slug: slug(r.slug), name, module_hash: hash, version: semver(r.version, 2147483647n), description: text(r.description ?? '', 500),
|
|
112
|
+
visibility: visibility, categories: strings(r.categories ?? [], 5, 64), keywords: strings(r.keywords ?? [], 20, 64),
|
|
113
|
+
readme: text(r.readme ?? '', 50_000), changelog: text(r.changelog ?? '', 2000), required_env: required, license: text(r.license ?? '', 64) };
|
|
114
|
+
}
|
|
115
|
+
/** Native Marketplace reuses verified project ownership and persisted deployment lifecycle.
|
|
116
|
+
* Writes are sent once. Read/reconcile saved state after an uncertain acknowledgement. */
|
|
117
|
+
export function hivesMarketplace(client) {
|
|
118
|
+
const projectInput = (project) => ({ project_id: hivesResourceId(project) });
|
|
119
|
+
const call = (operation, input, options) => hivesResourceCall(client, `hives_marketplace_${operation}`, input, options);
|
|
120
|
+
const mutate = async (operation, project, packageSlug, input, options) => {
|
|
121
|
+
const body = installInput(input);
|
|
122
|
+
const result = installationRow(await call(operation, { ...projectInput(project), slug: slug(packageSlug), body }, options), project);
|
|
123
|
+
if (result.slug !== packageSlug || result.status === 'uninstalled' || body.version && result.version !== body.version && result.pending_version !== body.version)
|
|
124
|
+
invalid();
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
async list(project, query = {}, options) {
|
|
129
|
+
keys(record(query), ['q', 'category', 'free_only', 'verified_only', 'sort', 'order', 'page', 'page_size']);
|
|
130
|
+
const p = { page: count(query.page ?? 1, 1, 100_000), page_size: count(query.page_size ?? 20, 1, 100) };
|
|
131
|
+
const sort = query.sort ?? 'installs';
|
|
132
|
+
const order = query.order ?? 'desc';
|
|
133
|
+
if (!['name', 'installs', 'stars', 'created', 'updated'].includes(sort) || !['asc', 'desc'].includes(order))
|
|
134
|
+
invalid();
|
|
135
|
+
const input = { ...projectInput(project), ...p, sort, order, free_only: bool(query.free_only ?? false), verified_only: bool(query.verified_only ?? false),
|
|
136
|
+
...(query.q == null ? {} : { q: text(query.q, 200) }), ...(query.category == null ? {} : { category: text(query.category, 64) }) };
|
|
137
|
+
return page(await call('list_packages', input, options), p.page, p.page_size, packageRow);
|
|
138
|
+
},
|
|
139
|
+
async get(project, packageSlug, query = {}, options) {
|
|
140
|
+
keys(record(query), ['version']);
|
|
141
|
+
const version = query.version == null ? undefined : semver(query.version);
|
|
142
|
+
return details(await call('get_package', { ...projectInput(project), slug: slug(packageSlug), ...(version === undefined ? {} : { version }) }, options), packageSlug, version);
|
|
143
|
+
},
|
|
144
|
+
async versions(project, packageSlug, query = {}, options) {
|
|
145
|
+
const p = pagination(query, 5);
|
|
146
|
+
const result = page(await call('list_versions', { ...projectInput(project), slug: slug(packageSlug), ...p }, options), p.page, p.page_size, row => versionRow(row));
|
|
147
|
+
if (new Set(result.data.map(row => row.package_id)).size > 1)
|
|
148
|
+
invalid();
|
|
149
|
+
return result;
|
|
150
|
+
},
|
|
151
|
+
async featured(project, options) { return page(await call('featured', projectInput(project), options), 1, 20, packageRow); },
|
|
152
|
+
async categories(project, options) {
|
|
153
|
+
const result = await call('categories', projectInput(project), options);
|
|
154
|
+
if (!Array.isArray(result) || result.length > 100)
|
|
155
|
+
invalid();
|
|
156
|
+
const data = result.map(value => {
|
|
157
|
+
const r = record(value);
|
|
158
|
+
return { id: uuid(r.id), slug: slug(r.slug), name: text(r.name, 128),
|
|
159
|
+
description: nullable(r.description, v => text(v, 1000)), icon_url: nullable(r.icon_url, v => text(v, 2048)), package_count: count(r.package_count), sort_order: count(r.sort_order, -2147483648, 2147483647) };
|
|
160
|
+
});
|
|
161
|
+
if (new Set(data.map(row => row.id)).size !== data.length)
|
|
162
|
+
invalid();
|
|
163
|
+
return data;
|
|
164
|
+
},
|
|
165
|
+
async publish(project, input, options) {
|
|
166
|
+
const body = publishInput(input);
|
|
167
|
+
const result = details(await call('publish', { ...projectInput(project), body }, options), body.slug);
|
|
168
|
+
if (!result.owned || !result.versions.some(v => v.version === body.version && v.module_hash === body.module_hash))
|
|
169
|
+
invalid();
|
|
170
|
+
return result;
|
|
171
|
+
},
|
|
172
|
+
async install(project, packageSlug, input = {}, options) { return mutate('install', project, packageSlug, input, options); },
|
|
173
|
+
async update(project, packageSlug, input = {}, options) { return mutate('update', project, packageSlug, input, options); },
|
|
174
|
+
async installed(project, query = {}, options) {
|
|
175
|
+
const p = pagination(query, 20);
|
|
176
|
+
return page(await call('installed', { ...projectInput(project), ...p }, options), p.page, p.page_size, row => installationRow(row, project));
|
|
177
|
+
},
|
|
178
|
+
async getInstallation(project, id, options) { return installationRow(await call('get_installation', { ...projectInput(project), installation_id: uuid(id) }, options), project, id); },
|
|
179
|
+
async reconcile(project, id, options) { return installationRow(await call('reconcile', { ...projectInput(project), installation_id: uuid(id) }, options), project, id); },
|
|
180
|
+
async uninstall(project, id, options) {
|
|
181
|
+
const result = installationRow(await call('uninstall', { ...projectInput(project), installation_id: uuid(id) }, options), project, id);
|
|
182
|
+
if (result.status !== 'uninstalled' || result.operation || result.deployment_id || result.pending_deployment_id)
|
|
183
|
+
invalid();
|
|
184
|
+
return result;
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Genesis } from './genesis.js';
|
|
2
|
+
import type { GenesisOptions } from './client.js';
|
|
3
|
+
export declare function closeHivesNodeTransport(): Promise<void>;
|
|
4
|
+
export declare function hivesOperationBudget(id: string): number;
|
|
5
|
+
/** Hives leaf transport. Caller fetch overrides stay authoritative; only native
|
|
6
|
+
* global fetch gets our Agent. Every operation retains an overall body deadline. */
|
|
7
|
+
export declare function createHivesNodeTransport(opts?: GenesisOptions, callerSignal?: AbortSignal): typeof fetch;
|
|
8
|
+
/** Node opt-in for Hives calls. Other services retain the caller transport. */
|
|
9
|
+
export declare function createHivesNodeClient(opts?: GenesisOptions, callerSignal?: AbortSignal): Genesis;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Agent } from 'undici';
|
|
2
|
+
import { Genesis } from './genesis.js';
|
|
3
|
+
import { operationTable } from './generated/operations.js';
|
|
4
|
+
// Node's native fetch accepts a compatible per-request dispatcher. Never change
|
|
5
|
+
// the global dispatcher or the portable SDK: other products retain their transport.
|
|
6
|
+
const agentOptions = { headersTimeout: 340_000, bodyTimeout: 340_000, connect: { timeout: 5_000 }, connections: 4, pipelining: 1 };
|
|
7
|
+
let agent;
|
|
8
|
+
const nativeAgent = () => agent ??= new Agent(agentOptions);
|
|
9
|
+
export async function closeHivesNodeTransport() {
|
|
10
|
+
const current = agent;
|
|
11
|
+
agent = undefined;
|
|
12
|
+
await current?.destroy();
|
|
13
|
+
}
|
|
14
|
+
export function hivesOperationBudget(id) {
|
|
15
|
+
if (['hives_list_buckets', 'hives_create_bucket', 'hives_get_bucket', 'hives_delete_bucket', 'hives_list_objects', 'hives_upload_object', 'hives_upload_object_by_key', 'hives_delete_object', 'hives_delete_object_by_key', 'hives_download_object_by_key', 'hives_get_cors_config', 'hives_set_cors_config', 'hives_generate_presigned_url', 'hives_reconcile'].includes(id))
|
|
16
|
+
return 100_000;
|
|
17
|
+
if (id === 'hives_cancel_deployment' || id === 'hives_delete_deployment' || id === 'hives_stop_deployment')
|
|
18
|
+
return 330_000;
|
|
19
|
+
// A live SSE subscription is bounded by its caller's window or --follow limit (at most 300 s).
|
|
20
|
+
if (id === 'hives_stream_logs')
|
|
21
|
+
return 330_000;
|
|
22
|
+
if (['hives_create_deployment', 'hives_upload_deployment', 'hives_invoke_deployment', 'hives_invoke_function', 'hives_invoke_function_async'].includes(id))
|
|
23
|
+
return 40_000;
|
|
24
|
+
if (['hives_create_function', 'hives_update_function', 'hives_delete_function'].includes(id))
|
|
25
|
+
return 100_000;
|
|
26
|
+
return 20_000;
|
|
27
|
+
}
|
|
28
|
+
const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
29
|
+
const templatePattern = (value) => new RegExp('^' + value.split(/(\{[^}]+\})/).map((part) => part.startsWith('{') ? '[^/]+' : escape(part)).join('') + '$');
|
|
30
|
+
/** Hives leaf transport. Caller fetch overrides stay authoritative; only native
|
|
31
|
+
* global fetch gets our Agent. Every operation retains an overall body deadline. */
|
|
32
|
+
export function createHivesNodeTransport(opts = {}, callerSignal) {
|
|
33
|
+
const supplied = opts.fetch ?? globalThis.fetch;
|
|
34
|
+
const underlying = supplied.bind(globalThis);
|
|
35
|
+
const useNative = supplied === globalThis.fetch;
|
|
36
|
+
const resolver = new Genesis(opts);
|
|
37
|
+
const routes = Object.entries(operationTable)
|
|
38
|
+
.filter(([, op]) => op.service === 'hives' && !op.internal)
|
|
39
|
+
.flatMap(([id, op]) => {
|
|
40
|
+
const direct = resolver.routing === 'direct';
|
|
41
|
+
let base;
|
|
42
|
+
try {
|
|
43
|
+
base = new URL(direct ? (opts.upstreams?.hives ?? op.upstream.base) : resolver.baseUrl);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new Error('Invalid Hives service address.');
|
|
47
|
+
}
|
|
48
|
+
const path = direct ? op.upstream.path : op.path;
|
|
49
|
+
const prefix = base.pathname.replace(/\/+$/, '');
|
|
50
|
+
const paths = [path];
|
|
51
|
+
if (!direct && path.startsWith('/v1/hives/'))
|
|
52
|
+
paths.push(path.replace('/v1/hives/', '/hives/v1/'));
|
|
53
|
+
return paths.map((p) => ({ id, origin: base.origin, method: direct ? op.upstream.method : op.method, pattern: templatePattern(prefix + p) }));
|
|
54
|
+
});
|
|
55
|
+
return (async (input, init = {}) => {
|
|
56
|
+
let url;
|
|
57
|
+
try {
|
|
58
|
+
url = new URL(input instanceof Request ? input.url : String(input));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new Error('Invalid Hives request address.');
|
|
62
|
+
}
|
|
63
|
+
const method = (init.method ?? (input instanceof Request ? input.method : 'GET')).toUpperCase();
|
|
64
|
+
const route = routes.find((entry) => entry.origin === url.origin && entry.method === method && entry.pattern.test(url.pathname));
|
|
65
|
+
if (!route)
|
|
66
|
+
return underlying(input, init);
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
let message = 'Hives transport failed. Refresh the resource and retry.';
|
|
69
|
+
const safeError = () => new Error(message);
|
|
70
|
+
const signals = [...new Set([callerSignal, init.signal, input instanceof Request ? input.signal : undefined].filter((signal) => !!signal))];
|
|
71
|
+
const canceled = () => {
|
|
72
|
+
message = 'Hives request canceled before completion. Refresh the resource before retrying.';
|
|
73
|
+
controller.abort();
|
|
74
|
+
};
|
|
75
|
+
for (const signal of signals)
|
|
76
|
+
signal.addEventListener('abort', canceled, { once: true });
|
|
77
|
+
const timer = setTimeout(() => {
|
|
78
|
+
message = 'Hives request deadline exceeded. Refresh the resource before retrying.';
|
|
79
|
+
controller.abort();
|
|
80
|
+
}, hivesOperationBudget(route.id));
|
|
81
|
+
timer.unref();
|
|
82
|
+
let abortReject = () => { };
|
|
83
|
+
let reader;
|
|
84
|
+
let bodyController;
|
|
85
|
+
const aborted = () => {
|
|
86
|
+
abortReject(safeError());
|
|
87
|
+
bodyController?.error(safeError());
|
|
88
|
+
void reader?.cancel().catch(() => { });
|
|
89
|
+
cleanup();
|
|
90
|
+
};
|
|
91
|
+
controller.signal.addEventListener('abort', aborted, { once: true });
|
|
92
|
+
const abortPromise = new Promise((_, reject) => { abortReject = reject; });
|
|
93
|
+
void abortPromise.catch(() => { });
|
|
94
|
+
const cleanup = () => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
for (const signal of signals)
|
|
97
|
+
signal.removeEventListener('abort', canceled);
|
|
98
|
+
controller.signal.removeEventListener('abort', aborted);
|
|
99
|
+
};
|
|
100
|
+
if (signals.some((signal) => signal.aborted))
|
|
101
|
+
canceled();
|
|
102
|
+
try {
|
|
103
|
+
if (controller.signal.aborted)
|
|
104
|
+
throw safeError();
|
|
105
|
+
const requestInit = {
|
|
106
|
+
...init, signal: controller.signal, cache: 'no-store',
|
|
107
|
+
redirect: init.redirect === 'manual' ? 'manual' : 'error',
|
|
108
|
+
...(useNative ? { dispatcher: nativeAgent() } : {}),
|
|
109
|
+
};
|
|
110
|
+
const pending = underlying(input, requestInit);
|
|
111
|
+
// A caller transport may ignore AbortSignal. Reject on our budget anyway,
|
|
112
|
+
// and discard any late response rather than presenting an acknowledgement.
|
|
113
|
+
void pending.then((response) => { if (controller.signal.aborted)
|
|
114
|
+
void response.body?.cancel().catch(() => { }); }, () => { });
|
|
115
|
+
const response = await Promise.race([pending, abortPromise]);
|
|
116
|
+
if (controller.signal.aborted)
|
|
117
|
+
throw safeError();
|
|
118
|
+
if (!response.body) {
|
|
119
|
+
cleanup();
|
|
120
|
+
return response;
|
|
121
|
+
}
|
|
122
|
+
reader = response.body.getReader();
|
|
123
|
+
const body = new ReadableStream({
|
|
124
|
+
start(value) { bodyController = value; },
|
|
125
|
+
async pull(value) {
|
|
126
|
+
try {
|
|
127
|
+
const next = await reader.read();
|
|
128
|
+
if (controller.signal.aborted)
|
|
129
|
+
return;
|
|
130
|
+
if (next.done) {
|
|
131
|
+
cleanup();
|
|
132
|
+
value.close();
|
|
133
|
+
}
|
|
134
|
+
else
|
|
135
|
+
value.enqueue(next.value);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
cleanup();
|
|
139
|
+
value.error(safeError());
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
async cancel() { cleanup(); await reader.cancel().catch(() => { }); },
|
|
143
|
+
});
|
|
144
|
+
return new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
cleanup();
|
|
148
|
+
throw safeError();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** Node opt-in for Hives calls. Other services retain the caller transport. */
|
|
153
|
+
export function createHivesNodeClient(opts = {}, callerSignal) {
|
|
154
|
+
return new Genesis({ ...opts, fetch: createHivesNodeTransport(opts, callerSignal) });
|
|
155
|
+
}
|