@lifesi/genesis 0.1.1 → 0.1.3

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.
Files changed (44) hide show
  1. package/dist/beacons.d.ts +46 -0
  2. package/dist/beacons.js +20 -0
  3. package/dist/client.d.ts +7669 -1635
  4. package/dist/client.js +54 -5
  5. package/dist/dials.d.ts +171 -1
  6. package/dist/dials.js +40 -0
  7. package/dist/fleets.d.ts +109 -1
  8. package/dist/fleets.js +89 -1
  9. package/dist/flocks.d.ts +73 -0
  10. package/dist/flocks.js +22 -0
  11. package/dist/generated/operations.d.ts +7669 -1635
  12. package/dist/generated/operations.js +9193 -1691
  13. package/dist/generated/schema.d.ts +16979 -5698
  14. package/dist/genesis.d.ts +795 -13
  15. package/dist/genesis.js +21 -0
  16. package/dist/genesis.openapi.json +23483 -7599
  17. package/dist/henry.d.ts +7 -0
  18. package/dist/henry.js +23 -0
  19. package/dist/hives-cells.d.ts +127 -0
  20. package/dist/hives-cells.js +151 -0
  21. package/dist/hives-environment.d.ts +28 -0
  22. package/dist/hives-environment.js +58 -0
  23. package/dist/hives-functions.d.ts +1 -1
  24. package/dist/hives-functions.js +3 -1
  25. package/dist/hives-marketplace.d.ts +128 -0
  26. package/dist/hives-marketplace.js +187 -0
  27. package/dist/hives-node.js +2 -0
  28. package/dist/hives-operations.d.ts +304 -0
  29. package/dist/hives-operations.js +39 -0
  30. package/dist/hives-queues.d.ts +121 -0
  31. package/dist/hives-queues.js +106 -0
  32. package/dist/hives-resources-transport.d.ts +18 -0
  33. package/dist/hives-resources-transport.js +165 -0
  34. package/dist/hives-runtimes.d.ts +34 -0
  35. package/dist/hives-runtimes.js +32 -0
  36. package/dist/hives-volumes.d.ts +64 -0
  37. package/dist/hives-volumes.js +117 -0
  38. package/dist/index.d.ts +8 -1
  39. package/dist/index.js +3 -0
  40. package/dist/runner-grant.d.ts +10 -0
  41. package/dist/runner-grant.js +133 -0
  42. package/dist/runner.d.ts +16 -0
  43. package/dist/runner.js +4 -0
  44. package/package.json +6 -1
@@ -0,0 +1,121 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { type HivesResourceOptions } from './hives-resources-transport.js';
3
+ export interface HivesQueueConfig {
4
+ retentionPeriod: number;
5
+ visibilityTimeout: number;
6
+ maxReceiveCount: number;
7
+ deadLetterQueueId?: string | null;
8
+ }
9
+ export interface HivesQueue extends HivesQueueConfig {
10
+ id: string;
11
+ projectId: string;
12
+ name: string;
13
+ type: 'standard' | 'dead_letter' | 'fifo';
14
+ status: 'active' | 'paused';
15
+ deliveryAvailable: boolean;
16
+ maxMessageSize: number;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ messageCount: number;
20
+ messagesProcessing: number;
21
+ delayedMessages: number;
22
+ retainedMessages: number;
23
+ retainedPayloadBytes: number;
24
+ consumerCount: null;
25
+ throughputPerSecond: null;
26
+ avgProcessingTimeMs: null;
27
+ }
28
+ export interface HivesQueueCreate {
29
+ name: string;
30
+ type?: 'standard' | 'dead_letter';
31
+ retentionPeriod?: number;
32
+ visibilityTimeout?: number;
33
+ maxReceiveCount?: number;
34
+ deadLetterQueueId?: string | null;
35
+ }
36
+ export interface HivesQueueSend {
37
+ body?: unknown;
38
+ body_base64?: string;
39
+ attributes?: Record<string, string>;
40
+ }
41
+ export interface HivesQueueDelivery {
42
+ id: string;
43
+ body_base64: string;
44
+ attributes: Record<string, string>;
45
+ receive_count: number;
46
+ receipt_handle: string;
47
+ lease_expires_at: string;
48
+ created_at: string;
49
+ }
50
+ export interface HivesDeadLetter {
51
+ id: string;
52
+ queue_id: string;
53
+ original_queue_id: string | null;
54
+ original_message_id: string | null;
55
+ body_base64: string;
56
+ attributes: Record<string, string>;
57
+ receive_count: number;
58
+ reason: string | null;
59
+ moved_at: string | null;
60
+ }
61
+ export interface HivesDeadLetterStats {
62
+ total_messages: number;
63
+ oldest_message_at: string | null;
64
+ newest_message_at: string | null;
65
+ average_receive_count: number | null;
66
+ retained_payload_bytes: number;
67
+ }
68
+ export declare function hivesQueueBody(encoded: string): Uint8Array;
69
+ export declare function hivesQueues(client: GenesisClient): {
70
+ list(project: string, options?: HivesResourceOptions): Promise<{
71
+ data: HivesQueue[];
72
+ engine_available: true;
73
+ }>;
74
+ get(project: string, id: string, options?: HivesResourceOptions): Promise<HivesQueue>;
75
+ create(project: string, body: HivesQueueCreate, options?: HivesResourceOptions): Promise<HivesQueue>;
76
+ configure(project: string, id: string, body: HivesQueueConfig, options?: HivesResourceOptions): Promise<HivesQueue>;
77
+ remove(project: string, id: string, options?: HivesResourceOptions): Promise<{
78
+ deleted: true;
79
+ }>;
80
+ stats(project: string, id: string, options?: HivesResourceOptions): Promise<HivesQueue>;
81
+ consumers: (project: string, id: string, options?: HivesResourceOptions) => Promise<never>;
82
+ pause(project: string, id: string, options?: HivesResourceOptions): Promise<HivesQueue>;
83
+ resume(project: string, id: string, options?: HivesResourceOptions): Promise<HivesQueue>;
84
+ purge(project: string, id: string, options?: HivesResourceOptions): Promise<{
85
+ purged: number;
86
+ }>;
87
+ send(project: string, id: string, body: HivesQueueSend, options?: HivesResourceOptions): Promise<{
88
+ message_id: string;
89
+ }>;
90
+ receive(project: string, id: string, body?: {
91
+ maxMessages?: number;
92
+ waitSeconds?: number;
93
+ }, options?: HivesResourceOptions): Promise<{
94
+ messages: HivesQueueDelivery[];
95
+ }>;
96
+ ack: (project: string, id: string, message: string, receipt: string, options?: HivesResourceOptions) => Promise<{
97
+ acknowledged: boolean;
98
+ released: boolean;
99
+ }>;
100
+ nack: (project: string, id: string, message: string, receipt: string, options?: HivesResourceOptions) => Promise<{
101
+ acknowledged: boolean;
102
+ released: boolean;
103
+ }>;
104
+ deadLetters: (project: string, id: string, query?: {
105
+ limit?: number;
106
+ offset?: number;
107
+ }, options?: HivesResourceOptions) => Promise<{
108
+ messages: HivesDeadLetter[];
109
+ }>;
110
+ deadLetterStats: (project: string, id: string, options?: HivesResourceOptions) => Promise<HivesDeadLetterStats>;
111
+ replay(project: string, id: string, message: string, options?: HivesResourceOptions): Promise<{
112
+ message_id: string;
113
+ replayed: 1;
114
+ }>;
115
+ deleteDeadLetter(project: string, id: string, message: string, options?: HivesResourceOptions): Promise<{
116
+ deleted: true;
117
+ }>;
118
+ purgeDeadLetters(project: string, id: string, options?: HivesResourceOptions): Promise<{
119
+ purged: number;
120
+ }>;
121
+ };
@@ -0,0 +1,106 @@
1
+ import { HIVES_QUEUE_BYTES, hivesResourceCall, hivesResourceId, resourceError } from './hives-resources-transport.js';
2
+ export function hivesQueueBody(encoded) {
3
+ if (typeof encoded !== 'string' || encoded.length > Math.ceil(HIVES_QUEUE_BYTES / 3) * 4 || encoded.length % 4 || !/^[A-Za-z0-9+/]*={0,2}$/.test(encoded))
4
+ throw resourceError(0);
5
+ try {
6
+ const bytes = atob(encoded);
7
+ if (btoa(bytes) !== encoded || bytes.length > HIVES_QUEUE_BYTES)
8
+ throw resourceError(0);
9
+ return Uint8Array.from(bytes, c => c.charCodeAt(0));
10
+ }
11
+ catch {
12
+ throw resourceError(0);
13
+ }
14
+ }
15
+ function config(body, required = false) {
16
+ const ranges = [{ key: 'retentionPeriod', min: 3600, max: 336 * 3600, divisor: 3600 }, { key: 'visibilityTimeout', min: 1, max: 43200 }, { key: 'maxReceiveCount', min: 1, max: 1000 }];
17
+ for (const r of ranges) {
18
+ const value = body[r.key];
19
+ if (value === undefined && !required)
20
+ continue;
21
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < r.min || value > r.max || r.divisor && value % r.divisor)
22
+ throw resourceError(0);
23
+ }
24
+ if (body.deadLetterQueueId != null)
25
+ hivesResourceId(body.deadLetterQueueId);
26
+ }
27
+ function queue(value, project, id) {
28
+ if (!value || value.projectId !== project || typeof value.id !== 'string' || id !== undefined && value.id !== id || !['standard', 'dead_letter', 'fifo'].includes(value.type) || !['active', 'paused'].includes(value.status) || typeof value.deliveryAvailable !== 'boolean' || value.type === 'fifo' && value.deliveryAvailable !== false)
29
+ throw resourceError(0);
30
+ const counts = [value.messageCount, value.messagesProcessing, value.delayedMessages, value.retainedMessages, value.retainedPayloadBytes];
31
+ if (counts.some(v => !Number.isSafeInteger(v) || v < 0) || value.consumerCount !== null || value.throughputPerSecond !== null || value.avgProcessingTimeMs !== null)
32
+ throw resourceError(0);
33
+ return Object.fromEntries(['id', 'projectId', 'name', 'type', 'status', 'deliveryAvailable', 'retentionPeriod', 'visibilityTimeout', 'maxReceiveCount', 'deadLetterQueueId', 'maxMessageSize', 'createdAt', 'updatedAt', 'messageCount', 'messagesProcessing', 'delayedMessages', 'retainedMessages', 'retainedPayloadBytes', 'consumerCount', 'throughputPerSecond', 'avgProcessingTimeMs'].map(k => [k, value[k]]));
34
+ }
35
+ function send(body) {
36
+ if (!body || typeof body !== 'object' || Object.keys(body).some(k => !['body', 'body_base64', 'attributes'].includes(k)) || (body.body != null) === (body.body_base64 != null))
37
+ throw resourceError(0);
38
+ if (body.body_base64 != null)
39
+ hivesQueueBody(body.body_base64);
40
+ else {
41
+ let value;
42
+ try {
43
+ value = typeof body.body === 'string' ? body.body : JSON.stringify(body.body);
44
+ }
45
+ catch {
46
+ throw resourceError(0);
47
+ }
48
+ if (value === undefined || new TextEncoder().encode(value).length > HIVES_QUEUE_BYTES)
49
+ throw resourceError(0);
50
+ }
51
+ if (body.attributes !== undefined) {
52
+ if (!body.attributes || typeof body.attributes !== 'object' || Array.isArray(body.attributes) || Object.keys(body.attributes).length > 64 || Object.entries(body.attributes).some(([k, v]) => !k || new TextEncoder().encode(k).length > 128 || k.startsWith('buzz.') || typeof v !== 'string') || new TextEncoder().encode(JSON.stringify(body.attributes)).length > 8192)
53
+ throw resourceError(0);
54
+ }
55
+ }
56
+ export function hivesQueues(client) {
57
+ const ids = (project_id, queue_id) => ({ project_id: hivesResourceId(project_id), ...(queue_id === undefined ? {} : { queue_id: hivesResourceId(queue_id) }) });
58
+ const call = (operation, input, options, limit = 2 * 1024 * 1024) => hivesResourceCall(client, operation, input, options, 'json', limit, 20_000);
59
+ const ack = async (project, id, message, receipt, release, options) => {
60
+ if (typeof receipt !== 'string' || !/^rh_[a-f0-9]{32}$/.test(receipt))
61
+ throw resourceError(0);
62
+ const result = await call(release ? 'hives_nack_native_queue' : 'hives_ack_native_queue', { ...ids(project, id), message_id: hivesResourceId(message), body: { receiptHandle: receipt } }, options);
63
+ if (!result || result.acknowledged !== !release || result.released !== release)
64
+ throw resourceError(0);
65
+ return result;
66
+ };
67
+ return {
68
+ async list(project, options) { const result = await call('hives_list_native_queue', ids(project), options); if (!result || !Array.isArray(result.data) || result.engine_available !== true)
69
+ throw resourceError(0); return { ...result, data: result.data.map(row => queue(row, project)) }; },
70
+ async get(project, id, options) { return queue(await call('hives_inspect_native_queue', ids(project, id), options), project, id); },
71
+ async create(project, body, options) { if (!body || !/^[A-Za-z0-9_-]{1,128}$/.test(body.name) || body.type !== undefined && !['standard', 'dead_letter'].includes(body.type) || Object.keys(body).some(k => !['name', 'type', 'retentionPeriod', 'visibilityTimeout', 'maxReceiveCount', 'deadLetterQueueId'].includes(k)))
72
+ throw resourceError(0); config(body); return queue(await call('hives_create_native_queue', { ...ids(project), body }, options), project); },
73
+ async configure(project, id, body, options) { if (!body || Object.keys(body).some(k => !['retentionPeriod', 'visibilityTimeout', 'maxReceiveCount', 'deadLetterQueueId'].includes(k)))
74
+ throw resourceError(0); config(body, true); return queue(await call('hives_configure_native_queue', { ...ids(project, id), body }, options), project, id); },
75
+ async remove(project, id, options) { const result = await call('hives_delete_native_queue', ids(project, id), options); if (result?.deleted !== true)
76
+ throw resourceError(0); return result; },
77
+ async stats(project, id, options) { return queue(await call('hives_stats_native_queue', ids(project, id), options), project, id); },
78
+ consumers: (project, id, options) => call('hives_consumers_native_queue', ids(project, id), options),
79
+ async pause(project, id, options) { return queue(await call('hives_pause_native_queue', ids(project, id), options), project, id); },
80
+ async resume(project, id, options) { return queue(await call('hives_resume_native_queue', ids(project, id), options), project, id); },
81
+ async purge(project, id, options) { const result = await call('hives_purge_native_queue', ids(project, id), options); if (!Number.isSafeInteger(result?.purged) || result.purged < 0)
82
+ throw resourceError(0); return result; },
83
+ async send(project, id, body, options) { send(body); const result = await call('hives_send_native_queue', { ...ids(project, id), body }, options); hivesResourceId(result?.message_id); return result; },
84
+ async receive(project, id, body = {}, options) { if (Object.keys(body).some(k => !['maxMessages', 'waitSeconds'].includes(k)) || body.maxMessages !== undefined && (!Number.isInteger(body.maxMessages) || body.maxMessages < 1 || body.maxMessages > 10) || body.waitSeconds !== undefined && (!Number.isInteger(body.waitSeconds) || body.waitSeconds < 0 || body.waitSeconds > 10))
85
+ throw resourceError(0); const result = await call('hives_receive_native_queue', { ...ids(project, id), body }, options, 4 * 1024 * 1024); if (!result || !Array.isArray(result.messages) || result.messages.length > (body.maxMessages ?? 1))
86
+ throw resourceError(0); for (const row of result.messages) {
87
+ hivesResourceId(row.id);
88
+ hivesQueueBody(row.body_base64);
89
+ if (!/^rh_[a-f0-9]{32}$/.test(row.receipt_handle))
90
+ throw resourceError(0);
91
+ } return result; },
92
+ ack: (project, id, message, receipt, options) => ack(project, id, message, receipt, false, options),
93
+ nack: (project, id, message, receipt, options) => ack(project, id, message, receipt, true, options),
94
+ deadLetters: async (project, id, query = {}, options) => { if (query.limit !== undefined && (!Number.isInteger(query.limit) || query.limit < 1 || query.limit > 10) || query.offset !== undefined && (!Number.isInteger(query.offset) || query.offset < 0 || query.offset > 8192))
95
+ throw resourceError(0); const result = await call('hives_dead_letters_native_queue', { ...query, ...ids(project, id) }, options, 4 * 1024 * 1024); if (!result || !Array.isArray(result.messages) || result.messages.length > (query.limit ?? 10))
96
+ throw resourceError(0); for (const row of result.messages)
97
+ hivesQueueBody(row.body_base64); return result; },
98
+ deadLetterStats: (project, id, options) => call('hives_dlq_stats_native_queue', ids(project, id), options),
99
+ async replay(project, id, message, options) { const result = await call('hives_replay_native_queue', { ...ids(project, id), body: { message_id: hivesResourceId(message) } }, options); if (result?.replayed !== 1)
100
+ throw resourceError(0); hivesResourceId(result.message_id); return result; },
101
+ async deleteDeadLetter(project, id, message, options) { const result = await call('hives_delete_dlq_native_queue', { ...ids(project, id), message_id: hivesResourceId(message) }, options); if (result?.deleted !== true)
102
+ throw resourceError(0); return result; },
103
+ async purgeDeadLetters(project, id, options) { const result = await call('hives_purge_dlq_native_queue', ids(project, id), options); if (!Number.isSafeInteger(result?.purged) || result.purged < 0)
104
+ throw resourceError(0); return result; },
105
+ };
106
+ }
@@ -0,0 +1,18 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { GenesisError } from './errors.js';
3
+ export declare const HIVES_OBJECT_BYTES: number;
4
+ export declare const HIVES_QUEUE_BYTES: number;
5
+ export declare const HIVES_RESOURCE_JSON_BYTES: number;
6
+ export interface HivesResourceOptions {
7
+ signal?: AbortSignal;
8
+ }
9
+ export declare function hivesResourceId(value: string): string;
10
+ export declare function resourceError(status: number, id?: string): GenesisError;
11
+ export declare const isHivesResourceOperation: (id: string) => boolean;
12
+ export declare const isHivesObjectUpload: (id: string) => id is "hives_upload_object_by_key" | "hives_upload_object";
13
+ /** Shared-client hook proposal: snapshot only the two real raw Cells upload operations. */
14
+ export declare function hivesObjectBody(value: unknown): Promise<ArrayBuffer>;
15
+ export declare function hivesContentType(value?: string): string;
16
+ export declare function hivesResourceBytes(response: Response, limit: number, signal?: AbortSignal): Promise<Uint8Array>;
17
+ /** Whole operation budget includes credential/fetch and incremental body read. No retries or redirects. */
18
+ export declare function hivesResourceCall<T>(client: GenesisClient, id: string, input: Record<string, unknown>, options?: HivesResourceOptions, mode?: 'json' | 'empty' | 'binary', limit?: number, budget?: number): Promise<T>;
@@ -0,0 +1,165 @@
1
+ import { GenesisError } from './errors.js';
2
+ export const HIVES_OBJECT_BYTES = 10 * 1024 * 1024;
3
+ export const HIVES_QUEUE_BYTES = 256 * 1024;
4
+ export const HIVES_RESOURCE_JSON_BYTES = 2 * 1024 * 1024;
5
+ export function hivesResourceId(value) {
6
+ if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(value))
7
+ throw resourceError(0);
8
+ return value;
9
+ }
10
+ export function resourceError(status, id) {
11
+ return new GenesisError({ status, type: status ? `http_${status}` : 'invalid_request', operationId: id,
12
+ message: status === 404 ? 'Hives resource not found in the authenticated organization and project.'
13
+ : status === 409 ? 'Hives resource state conflicted. Read persisted state before another mutation.'
14
+ : status === 503 ? 'Hives outcome is unavailable. Read persisted state or reconcile before another mutation.'
15
+ : 'Hives resource request failed. Check the request and persisted state; no automatic retry was made.' });
16
+ }
17
+ export const isHivesResourceOperation = (id) => /^(?:hives_marketplace_(?:categories|featured|installed|get_installation|uninstall|reconcile|list_packages|publish|get_package|install|update|list_versions)|hives_.*_native_queue|hives_(?:(?:list_volumes|create_volume|get_volume|delete_volume|mount_volume|unmount_volume)|list_buckets|create_bucket|get_bucket|delete_bucket|list_objects|upload_object(?:_by_key)?|delete_object(?:_by_key)?|download_object_by_key|get_cors_config|set_cors_config|generate_presigned_url|reconcile|list_runtimes|get_runtime|select_runtime|list_project_runtimes))$/.test(id);
18
+ export const isHivesObjectUpload = (id) => id === 'hives_upload_object_by_key' || id === 'hives_upload_object';
19
+ /** Shared-client hook proposal: snapshot only the two real raw Cells upload operations. */
20
+ export async function hivesObjectBody(value) {
21
+ let bytes;
22
+ if (value instanceof Blob) {
23
+ if (value.size > HIVES_OBJECT_BYTES)
24
+ throw resourceError(0);
25
+ bytes = new Uint8Array(await value.arrayBuffer());
26
+ }
27
+ else if (value instanceof ArrayBuffer)
28
+ bytes = new Uint8Array(value);
29
+ else if (ArrayBuffer.isView(value))
30
+ bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
31
+ else
32
+ throw resourceError(0);
33
+ if (bytes.byteLength > HIVES_OBJECT_BYTES)
34
+ throw resourceError(0);
35
+ return Uint8Array.from(bytes).buffer;
36
+ }
37
+ export function hivesContentType(value = 'application/octet-stream') {
38
+ if (typeof value !== 'string' || !value.length || new TextEncoder().encode(value).length > 512 || /[\u0000-\u001f\u007f]/.test(value))
39
+ throw resourceError(0);
40
+ return value;
41
+ }
42
+ export async function hivesResourceBytes(response, limit, signal) {
43
+ const chunks = [];
44
+ let length = 0;
45
+ const reader = response.body?.getReader();
46
+ if (!reader)
47
+ return new Uint8Array();
48
+ const cancel = () => { void reader.cancel().catch(() => { }); };
49
+ signal?.addEventListener('abort', cancel, { once: true });
50
+ if (signal?.aborted)
51
+ cancel();
52
+ try {
53
+ for (;;) {
54
+ const next = await reader.read();
55
+ if (signal?.aborted)
56
+ throw resourceError(0);
57
+ if (next.done)
58
+ break;
59
+ length += next.value.byteLength;
60
+ if (length > limit) {
61
+ await reader.cancel();
62
+ throw resourceError(0);
63
+ }
64
+ chunks.push(next.value);
65
+ }
66
+ }
67
+ finally {
68
+ signal?.removeEventListener('abort', cancel);
69
+ reader.releaseLock();
70
+ }
71
+ const bytes = new Uint8Array(length);
72
+ let offset = 0;
73
+ for (const part of chunks) {
74
+ bytes.set(part, offset);
75
+ offset += part.byteLength;
76
+ }
77
+ return bytes;
78
+ }
79
+ /** Whole operation budget includes credential/fetch and incremental body read. No retries or redirects. */
80
+ export async function hivesResourceCall(client, id, input, options = {}, mode = 'json', limit = HIVES_RESOURCE_JSON_BYTES, budget = 20_000) {
81
+ let snapshot;
82
+ try {
83
+ if (input.body instanceof ArrayBuffer)
84
+ snapshot = { ...input, body: input.body.slice(0) };
85
+ else {
86
+ const value = JSON.stringify(input);
87
+ if (new TextEncoder().encode(value).length > 512 * 1024)
88
+ throw resourceError(0);
89
+ snapshot = JSON.parse(value);
90
+ }
91
+ }
92
+ catch {
93
+ throw resourceError(0, id);
94
+ }
95
+ const controller = new AbortController();
96
+ const abort = () => controller.abort();
97
+ let rejectAbort = () => { };
98
+ const failure = new Promise((_, reject) => { rejectAbort = reject; });
99
+ void failure.catch(() => { });
100
+ const aborted = () => rejectAbort(resourceError(0, id));
101
+ controller.signal.addEventListener('abort', aborted, { once: true });
102
+ options.signal?.addEventListener('abort', abort, { once: true });
103
+ const timer = setTimeout(abort, budget);
104
+ if (typeof timer === 'object' && 'unref' in timer)
105
+ timer.unref();
106
+ let response;
107
+ let completed = false;
108
+ const operation = (async () => {
109
+ if (options.signal?.aborted)
110
+ abort();
111
+ if (controller.signal.aborted)
112
+ throw resourceError(0, id);
113
+ response = await client.raw(id, snapshot, { signal: controller.signal });
114
+ if (controller.signal.aborted) {
115
+ await response.body?.cancel();
116
+ throw resourceError(0, id);
117
+ }
118
+ if (response.status < 200 || response.status >= 300) {
119
+ await response.body?.cancel();
120
+ throw resourceError(response.status, id);
121
+ }
122
+ if (mode === 'empty' && ![200, 204].includes(response.status))
123
+ throw resourceError(0, id);
124
+ const bytes = await hivesResourceBytes(response, mode === 'empty' ? 0 : limit, controller.signal);
125
+ if (controller.signal.aborted)
126
+ throw resourceError(0, id);
127
+ if (mode === 'empty')
128
+ return undefined;
129
+ if (mode === 'binary') {
130
+ if (response.status !== 200)
131
+ throw resourceError(0, id);
132
+ const headers = new Headers({ 'content-type': hivesContentType(response.headers.get('content-type') ?? undefined), 'cache-control': 'no-store', 'content-disposition': 'attachment' });
133
+ return new Response(Uint8Array.from(bytes).buffer, { status: 200, headers });
134
+ }
135
+ if (!response.headers.get('content-type')?.toLowerCase().includes('application/json'))
136
+ throw resourceError(0, id);
137
+ try {
138
+ return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
139
+ }
140
+ catch {
141
+ throw resourceError(0, id);
142
+ }
143
+ })();
144
+ void operation.then(() => { if (controller.signal.aborted)
145
+ void response?.body?.cancel().catch(() => { }); }, () => { });
146
+ try {
147
+ const result = await Promise.race([operation, failure]);
148
+ completed = true;
149
+ return result;
150
+ }
151
+ catch (error) {
152
+ if (error instanceof GenesisError)
153
+ throw resourceError(error.status, id);
154
+ throw resourceError(0, id);
155
+ }
156
+ finally {
157
+ clearTimeout(timer);
158
+ options.signal?.removeEventListener('abort', abort);
159
+ controller.signal.removeEventListener('abort', aborted);
160
+ if (!completed) {
161
+ controller.abort();
162
+ void response?.body?.cancel().catch(() => { });
163
+ }
164
+ }
165
+ }
@@ -0,0 +1,34 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { type HivesResourceOptions } from './hives-resources-transport.js';
3
+ export interface HivesRuntime {
4
+ name: string;
5
+ version: string;
6
+ wasiVersions: string[];
7
+ runners: string[];
8
+ artifactKinds: string[];
9
+ compiledFeatures: string[];
10
+ capabilityScope: 'compiled_serving_implementation';
11
+ features: string[];
12
+ useCases: string[];
13
+ }
14
+ export interface HivesRuntimeSelection {
15
+ selected: string;
16
+ reason: string;
17
+ wasi: string;
18
+ runner: string;
19
+ artifact: string;
20
+ }
21
+ export declare function hivesRuntimes(client: GenesisClient): {
22
+ list: (options?: HivesResourceOptions) => Promise<{
23
+ runtimes: HivesRuntime[];
24
+ }>;
25
+ project: (project_id: string, options?: HivesResourceOptions) => Promise<{
26
+ runtimes: HivesRuntime[];
27
+ }>;
28
+ get: (name: string, options?: HivesResourceOptions) => Promise<HivesRuntime>;
29
+ select: (input: {
30
+ wasi: string;
31
+ runner: string;
32
+ artifact: string;
33
+ }, options?: HivesResourceOptions) => Promise<HivesRuntimeSelection>;
34
+ };
@@ -0,0 +1,32 @@
1
+ import { hivesResourceCall, hivesResourceId, resourceError } from './hives-resources-transport.js';
2
+ function runtime(value) {
3
+ if (!value || typeof value !== 'object')
4
+ throw resourceError(0);
5
+ const row = value;
6
+ if (typeof row.name !== 'string' || typeof row.version !== 'string' || row.capabilityScope !== 'compiled_serving_implementation'
7
+ || ['wasiVersions', 'runners', 'artifactKinds', 'compiledFeatures', 'features', 'useCases'].some(k => !Array.isArray(row[k]) || !row[k].every(v => typeof v === 'string'))
8
+ || !row.wasiVersions.length || !row.runners.length || !row.artifactKinds.length)
9
+ throw resourceError(0);
10
+ return { name: row.name, version: row.version, wasiVersions: [...row.wasiVersions], runners: [...row.runners], artifactKinds: [...row.artifactKinds], compiledFeatures: [...row.compiledFeatures], capabilityScope: row.capabilityScope, features: [...row.features], useCases: [...row.useCases] };
11
+ }
12
+ export function hivesRuntimes(client) {
13
+ const list = async (id, input, options) => {
14
+ const result = await hivesResourceCall(client, id, input, options);
15
+ if (!result || !Array.isArray(result.runtimes))
16
+ throw resourceError(0);
17
+ return { runtimes: result.runtimes.map(runtime) };
18
+ };
19
+ return {
20
+ list: (options) => list('hives_list_runtimes', {}, options),
21
+ project: (project_id, options) => list('hives_list_project_runtimes', { project_id: hivesResourceId(project_id) }, options),
22
+ get: async (name, options) => runtime(await hivesResourceCall(client, 'hives_get_runtime', { name: hivesResourceId(name) }, options)),
23
+ select: async (input, options) => {
24
+ if (Object.keys(input).some(k => !['wasi', 'runner', 'artifact'].includes(k)) || Object.values(input).some(v => typeof v !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(v)))
25
+ throw resourceError(0);
26
+ const result = await hivesResourceCall(client, 'hives_select_runtime', { ...input }, options);
27
+ if (!result || typeof result.selected !== 'string' || typeof result.reason !== 'string' || result.wasi !== input.wasi || result.runner !== input.runner || result.artifact !== input.artifact)
28
+ throw resourceError(0);
29
+ return result;
30
+ },
31
+ };
32
+ }
@@ -0,0 +1,64 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { type HivesResourceOptions } from './hives-resources-transport.js';
3
+ declare const states: readonly ["creating", "available", "attaching", "attached", "detaching", "deleting", "failed"];
4
+ export interface HivesVolume {
5
+ id: string;
6
+ project_id: string;
7
+ name: string;
8
+ size_gib: number;
9
+ backing_bytes: number;
10
+ capacity_bytes: number | null;
11
+ used_bytes: number | null;
12
+ storage_class: 'local';
13
+ access_mode: 'read_write_once';
14
+ state: typeof states[number];
15
+ operation_pending: boolean;
16
+ generation: number;
17
+ mount_path: string | null;
18
+ attached_to: string | null;
19
+ read_only: boolean | null;
20
+ created_at: string;
21
+ updated_at: string;
22
+ }
23
+ export type HivesVolumeCreate = {
24
+ name: string;
25
+ storage_class?: 'local';
26
+ access_mode?: 'read_write_once';
27
+ } & ({
28
+ size_mib: number;
29
+ size_gib?: never;
30
+ } | {
31
+ size_gib: 1;
32
+ size_mib?: never;
33
+ });
34
+ export interface HivesVolumeMount {
35
+ target_id: string;
36
+ mount_path: string;
37
+ read_only: boolean;
38
+ }
39
+ export interface HivesVolumePage {
40
+ volumes: HivesVolume[];
41
+ pagination: {
42
+ page: number;
43
+ per_page: number;
44
+ total: number;
45
+ total_pages: number;
46
+ };
47
+ }
48
+ /** Persisted project storage. A failed acknowledgement never triggers an automatic write retry. */
49
+ export declare function hivesVolumes(client: GenesisClient): {
50
+ list(project: string, query?: {
51
+ page?: number;
52
+ per_page?: number;
53
+ }, options?: HivesResourceOptions): Promise<HivesVolumePage>;
54
+ get(project: string, id: string, options?: HivesResourceOptions): Promise<HivesVolume>;
55
+ create(project: string, input: HivesVolumeCreate, options?: HivesResourceOptions): Promise<HivesVolume>;
56
+ mount(project: string, id: string, input: HivesVolumeMount, options?: HivesResourceOptions): Promise<HivesVolume>;
57
+ unmount(project: string, id: string, options?: HivesResourceOptions): Promise<HivesVolume>;
58
+ remove(project: string, id: string, options?: HivesResourceOptions): Promise<{
59
+ success: true;
60
+ id: string;
61
+ message: string;
62
+ }>;
63
+ };
64
+ export {};