@oliphaunt/wasix-ts 0.1.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.
Files changed (169) hide show
  1. package/ARCHITECTURE.md +655 -0
  2. package/CHANGELOG.md +33 -0
  3. package/LICENSE +21 -0
  4. package/README.md +404 -0
  5. package/THIRD_PARTY_NOTICES.md +20 -0
  6. package/lib/archive.d.ts +21 -0
  7. package/lib/archive.js +336 -0
  8. package/lib/asset-source.d.ts +4 -0
  9. package/lib/asset-source.js +15 -0
  10. package/lib/byte-channel.d.ts +27 -0
  11. package/lib/byte-channel.js +170 -0
  12. package/lib/client-common.d.ts +6 -0
  13. package/lib/client-common.js +36 -0
  14. package/lib/client.d.ts +7 -0
  15. package/lib/client.js +24 -0
  16. package/lib/database-root.d.ts +19 -0
  17. package/lib/database-root.js +139 -0
  18. package/lib/database.d.ts +135 -0
  19. package/lib/database.js +1039 -0
  20. package/lib/descriptor-validation.d.ts +10 -0
  21. package/lib/descriptor-validation.js +75 -0
  22. package/lib/direct-client-common.d.ts +50 -0
  23. package/lib/direct-client-common.js +717 -0
  24. package/lib/direct-client.d.ts +4 -0
  25. package/lib/direct-client.js +13 -0
  26. package/lib/direct.node.d.ts +2 -0
  27. package/lib/direct.node.js +2 -0
  28. package/lib/errors.d.ts +25 -0
  29. package/lib/errors.js +34 -0
  30. package/lib/extension-descriptor.d.ts +14 -0
  31. package/lib/extension-descriptor.js +419 -0
  32. package/lib/extensions.d.ts +68 -0
  33. package/lib/extensions.js +769 -0
  34. package/lib/host/LICENSE +21 -0
  35. package/lib/host/index.d.mts +123 -0
  36. package/lib/host/index.mjs +11 -0
  37. package/lib/host/provenance.json +16 -0
  38. package/lib/host/wasmer_js_bg.wasm +0 -0
  39. package/lib/host/worker.mjs +11 -0
  40. package/lib/host-runtime.d.ts +5 -0
  41. package/lib/host-runtime.js +13 -0
  42. package/lib/icu-descriptor.d.ts +3 -0
  43. package/lib/icu-descriptor.js +92 -0
  44. package/lib/index.bun.d.ts +2 -0
  45. package/lib/index.bun.js +2 -0
  46. package/lib/index.d.ts +2 -0
  47. package/lib/index.deno.d.ts +2 -0
  48. package/lib/index.deno.js +2 -0
  49. package/lib/index.js +2 -0
  50. package/lib/index.node.d.ts +2 -0
  51. package/lib/index.node.js +2 -0
  52. package/lib/internal-common.d.ts +12 -0
  53. package/lib/internal-common.js +274 -0
  54. package/lib/internal.d.ts +5 -0
  55. package/lib/internal.js +42 -0
  56. package/lib/internal.node.d.ts +5 -0
  57. package/lib/internal.node.js +8 -0
  58. package/lib/native-addon.d.ts +111 -0
  59. package/lib/native-addon.js +223 -0
  60. package/lib/native-server.d.ts +21 -0
  61. package/lib/native-server.js +109 -0
  62. package/lib/native-session.d.ts +60 -0
  63. package/lib/native-session.js +565 -0
  64. package/lib/node-actor.d.ts +7 -0
  65. package/lib/node-actor.js +10 -0
  66. package/lib/node-client-common.d.ts +9 -0
  67. package/lib/node-client-common.js +35 -0
  68. package/lib/node-client.d.ts +4 -0
  69. package/lib/node-client.js +13 -0
  70. package/lib/node-direct.d.ts +7 -0
  71. package/lib/node-direct.js +10 -0
  72. package/lib/node-worker-options.d.ts +5 -0
  73. package/lib/node-worker-options.js +65 -0
  74. package/lib/node-worker-port.d.ts +4 -0
  75. package/lib/node-worker-port.js +116 -0
  76. package/lib/node-worker.d.ts +1 -0
  77. package/lib/node-worker.js +38 -0
  78. package/lib/pgwire-connection.d.ts +60 -0
  79. package/lib/pgwire-connection.js +528 -0
  80. package/lib/pgwire.d.ts +3 -0
  81. package/lib/pgwire.js +105 -0
  82. package/lib/physical-archive.d.ts +29 -0
  83. package/lib/physical-archive.js +527 -0
  84. package/lib/protocol.d.ts +1 -0
  85. package/lib/protocol.js +1 -0
  86. package/lib/public.d.ts +4 -0
  87. package/lib/public.js +3 -0
  88. package/lib/query.d.ts +1 -0
  89. package/lib/query.js +1 -0
  90. package/lib/rpc.d.ts +203 -0
  91. package/lib/rpc.js +84 -0
  92. package/lib/runtime-descriptor.d.ts +3 -0
  93. package/lib/runtime-descriptor.js +79 -0
  94. package/lib/server.node.d.ts +1 -0
  95. package/lib/server.node.js +1 -0
  96. package/lib/startup-config.d.ts +2 -0
  97. package/lib/startup-config.js +19 -0
  98. package/lib/storage/bun.d.ts +6 -0
  99. package/lib/storage/bun.js +6 -0
  100. package/lib/storage/deno.d.ts +7 -0
  101. package/lib/storage/deno.js +7 -0
  102. package/lib/storage/incremental-storage.d.ts +25 -0
  103. package/lib/storage/incremental-storage.js +154 -0
  104. package/lib/storage/indexed-db-provider.d.ts +40 -0
  105. package/lib/storage/indexed-db-provider.js +259 -0
  106. package/lib/storage/indexed-db.d.ts +9 -0
  107. package/lib/storage/indexed-db.js +11 -0
  108. package/lib/storage/node.d.ts +10 -0
  109. package/lib/storage/node.js +13 -0
  110. package/lib/storage/opfs-pool.d.ts +31 -0
  111. package/lib/storage/opfs-pool.js +1271 -0
  112. package/lib/storage/opfs-provider.d.ts +4 -0
  113. package/lib/storage/opfs-provider.js +257 -0
  114. package/lib/storage/opfs.d.ts +8 -0
  115. package/lib/storage/opfs.js +10 -0
  116. package/lib/storage/restore-cleanup.d.ts +4 -0
  117. package/lib/storage/restore-cleanup.js +22 -0
  118. package/lib/storage/web-lock.d.ts +2 -0
  119. package/lib/storage/web-lock.js +64 -0
  120. package/lib/storage-provider.d.ts +47 -0
  121. package/lib/storage-provider.js +141 -0
  122. package/lib/storage-snapshot.d.ts +44 -0
  123. package/lib/storage-snapshot.js +274 -0
  124. package/lib/storage.d.ts +46 -0
  125. package/lib/storage.js +83 -0
  126. package/lib/tool-runtime.d.ts +43 -0
  127. package/lib/tool-runtime.js +93 -0
  128. package/lib/tool-worker-common.d.ts +48 -0
  129. package/lib/tool-worker-common.js +97 -0
  130. package/lib/tool-worker.d.ts +1 -0
  131. package/lib/tool-worker.js +10 -0
  132. package/lib/types.d.ts +230 -0
  133. package/lib/types.js +1 -0
  134. package/lib/wasix-runtime.d.ts +24 -0
  135. package/lib/wasix-runtime.js +186 -0
  136. package/lib/worker-client.d.ts +4 -0
  137. package/lib/worker-client.js +45 -0
  138. package/lib/worker-dispatch.d.ts +11 -0
  139. package/lib/worker-dispatch.js +174 -0
  140. package/lib/worker-entry.bun.d.ts +2 -0
  141. package/lib/worker-entry.bun.js +2 -0
  142. package/lib/worker-entry.d.ts +2 -0
  143. package/lib/worker-entry.deno.d.ts +2 -0
  144. package/lib/worker-entry.deno.js +2 -0
  145. package/lib/worker-entry.js +2 -0
  146. package/lib/worker-entry.node.d.ts +2 -0
  147. package/lib/worker-entry.node.js +2 -0
  148. package/lib/worker-node-client.d.ts +4 -0
  149. package/lib/worker-node-client.js +55 -0
  150. package/lib/worker-rpc.d.ts +36 -0
  151. package/lib/worker-rpc.js +422 -0
  152. package/lib/worker-transfer.d.ts +6 -0
  153. package/lib/worker-transfer.js +11 -0
  154. package/lib/worker.d.ts +1 -0
  155. package/lib/worker.js +21 -0
  156. package/lib/zstd.d.ts +4 -0
  157. package/lib/zstd.js +12 -0
  158. package/node_modules/@oliphaunt/js-core/README.md +7 -0
  159. package/node_modules/@oliphaunt/js-core/dist/commonjs/protocol.d.ts +1 -0
  160. package/node_modules/@oliphaunt/js-core/dist/commonjs/protocol.js +22 -0
  161. package/node_modules/@oliphaunt/js-core/dist/commonjs/query.d.ts +255 -0
  162. package/node_modules/@oliphaunt/js-core/dist/commonjs/query.js +2068 -0
  163. package/node_modules/@oliphaunt/js-core/dist/module/package.json +3 -0
  164. package/node_modules/@oliphaunt/js-core/dist/module/protocol.d.ts +1 -0
  165. package/node_modules/@oliphaunt/js-core/dist/module/protocol.js +19 -0
  166. package/node_modules/@oliphaunt/js-core/dist/module/query.d.ts +255 -0
  167. package/node_modules/@oliphaunt/js-core/dist/module/query.js +2039 -0
  168. package/node_modules/@oliphaunt/js-core/package.json +21 -0
  169. package/package.json +122 -0
@@ -0,0 +1,10 @@
1
+ import type { SerializedAssetSource } from './rpc.js';
2
+ import type { WasixAssetSource } from './types.js';
3
+ export declare function requireExactObject(value: unknown, fields: readonly string[], label: string): Record<string, unknown>;
4
+ export declare function requireString(value: unknown, label: string): string;
5
+ export declare function requireVersion(value: unknown, label: string): string;
6
+ export declare function requireSha256(value: unknown, label: string): string;
7
+ export declare function requireSize(value: unknown, label: string): number;
8
+ export declare function requireAssetSource(value: unknown, label: string, size: number, sizeKind?: 'asset' | 'carrier'): WasixAssetSource;
9
+ export declare function serializeAssetSource(source: WasixAssetSource): SerializedAssetSource;
10
+ export declare function requireSafeRelativeAssetPath(value: unknown, label: string): string;
@@ -0,0 +1,75 @@
1
+ const SHA256 = /^[a-f0-9]{64}$/;
2
+ const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
3
+ export function requireExactObject(value, fields, label) {
4
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
5
+ throw new Error(`${label} must be an object`);
6
+ }
7
+ const actual = Object.keys(value).sort();
8
+ if (actual.length !== fields.length || actual.some((field, index) => field !== fields[index])) {
9
+ throw new Error(`${label} fields must be exactly ${fields.join(', ')}`);
10
+ }
11
+ return value;
12
+ }
13
+ export function requireString(value, label) {
14
+ if (typeof value !== 'string' || value.length === 0 || value.includes('\0')) {
15
+ throw new Error(`${label} must be a non-empty string without NUL bytes`);
16
+ }
17
+ return value;
18
+ }
19
+ export function requireVersion(value, label) {
20
+ const version = requireString(value, label);
21
+ if (!SEMVER.test(version)) {
22
+ throw new Error(`${label} must be a SemVer version`);
23
+ }
24
+ return version;
25
+ }
26
+ export function requireSha256(value, label) {
27
+ const sha256 = requireString(value, label);
28
+ if (!SHA256.test(sha256)) {
29
+ throw new Error(`${label} must be 64 lowercase hexadecimal characters`);
30
+ }
31
+ return sha256;
32
+ }
33
+ export function requireSize(value, label) {
34
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {
35
+ throw new Error(`${label} must be a positive safe integer`);
36
+ }
37
+ return value;
38
+ }
39
+ export function requireAssetSource(value, label, size, sizeKind = 'asset') {
40
+ if (typeof value === 'string') {
41
+ return requireString(value, label);
42
+ }
43
+ if (value instanceof URL) {
44
+ return value;
45
+ }
46
+ if (value instanceof Uint8Array || value instanceof ArrayBuffer) {
47
+ if (value.byteLength !== size) {
48
+ throw new Error(`${label} byte length must match declared ${sizeKind} size ${size}`);
49
+ }
50
+ return value;
51
+ }
52
+ throw new Error(`${label} must be a URL, string, ArrayBuffer, or Uint8Array`);
53
+ }
54
+ export function serializeAssetSource(source) {
55
+ if (typeof source === 'string') {
56
+ return source;
57
+ }
58
+ if (source instanceof URL) {
59
+ return source.href;
60
+ }
61
+ if (source instanceof Uint8Array) {
62
+ return source.slice();
63
+ }
64
+ return new Uint8Array(source.slice(0));
65
+ }
66
+ export function requireSafeRelativeAssetPath(value, label) {
67
+ const path = requireString(value, label);
68
+ const segments = path.split('/');
69
+ if (path.startsWith('/') ||
70
+ path.includes('\\') ||
71
+ segments.some((segment) => segment.length === 0 || segment === '.' || segment === '..')) {
72
+ throw new Error(`${label} must be a safe relative asset path`);
73
+ }
74
+ return path;
75
+ }
@@ -0,0 +1,50 @@
1
+ import { type WasixDatabaseIdentity, type WasixDatabaseSession, type WasixPersistenceMode, type WasixProtocolStreamOutcome, type WasixProtocolConnectionMode } from './database.js';
2
+ import { type PreparedWasixRuntime } from './extensions.js';
3
+ import type { Directory, OliphauntDirectInstance, OliphauntPreparedTool, OliphauntToolOutput, RunWasixOptions, WasmerInitOptions } from './host/index.mjs';
4
+ import type { SerializedOpenOptions } from './rpc.js';
5
+ import { type WasixClusterSeedLoader, type WasixStorageLease, type WasixStorageSyncBoundary } from './storage-provider.js';
6
+ import type { OliphauntDatabase } from './types.js';
7
+ import { type WasixProtocolConnection } from './pgwire-connection.js';
8
+ import { type WasixPgDumpProcessOptions, type WasixToolProcessResult } from './tool-runtime.js';
9
+ /** @internal Narrow caller-realm host contract. */
10
+ export type DirectWasixHost = Readonly<{
11
+ Directory: typeof Directory;
12
+ init(options?: WasmerInitOptions): Promise<unknown>;
13
+ instantiateOliphauntDirect(module: WebAssembly.Module, moduleBytes: Uint8Array, options: RunWasixOptions): Promise<OliphauntDirectInstance>;
14
+ prepareOliphauntTool?(module: WebAssembly.Module, moduleBytes: Uint8Array): OliphauntPreparedTool;
15
+ runOliphauntToolDirect?(prepared: OliphauntPreparedTool, options: RunWasixOptions, protocolRead: (maximumBytes: number) => Uint8Array,
16
+ /** Borrowed bytes: synchronously copy; never mutate or retain this view. */
17
+ protocolWrite: (chunk: Uint8Array) => void): Promise<OliphauntToolOutput>;
18
+ }>;
19
+ /** @internal Dependency seam for deterministic direct-lifecycle qualification. */
20
+ export type DirectWasixDependencies = Readonly<{
21
+ prepareRuntime(options: SerializedOpenOptions): Promise<PreparedWasixRuntime>;
22
+ acquireStorage(storage: SerializedOpenOptions['storage'], loadClusterSeed: WasixClusterSeedLoader, identity: PreparedWasixRuntime['physicalIdentity']): Promise<WasixStorageLease>;
23
+ compileModule(module: Uint8Array, sha256: string): Promise<WebAssembly.Module>;
24
+ }>;
25
+ export type DirectWasixEnvironment = 'browser-main' | 'browser-worker' | 'node';
26
+ /** @internal Open PostgreSQL in the caller realm; guest calls are synchronous after setup. */
27
+ export declare function openWasixDirect(options: SerializedOpenOptions, host: DirectWasixHost, environment?: DirectWasixEnvironment): Promise<OliphauntDatabase>;
28
+ /** @internal Open a direct-memory session inside the dedicated browser worker realm. */
29
+ export declare function openBrowserWorkerSession(options: SerializedOpenOptions, host: DirectWasixHost): Promise<DirectWasixSession>;
30
+ /**
31
+ * Owns the caller-realm guest, its mounted PGDATA, and one terminal teardown.
32
+ * A rejected close still retires the session after attempting provider and
33
+ * allocation release; destroyed guest state is never advertised as reusable.
34
+ */
35
+ /** @internal */
36
+ export declare class DirectWasixSession implements WasixDatabaseSession {
37
+ #private;
38
+ readonly identity: WasixDatabaseIdentity;
39
+ private constructor();
40
+ static open(options: SerializedOpenOptions, host: DirectWasixHost, dependencies?: DirectWasixDependencies, environment?: DirectWasixEnvironment): Promise<DirectWasixSession>;
41
+ exec(input: Uint8Array, persistence?: WasixPersistenceMode): Promise<Uint8Array>;
42
+ execStream(input: Uint8Array, onChunk: (chunk: Uint8Array) => void, persistence?: WasixPersistenceMode): Promise<WasixProtocolStreamOutcome>;
43
+ runPgDump(options: WasixPgDumpProcessOptions): Promise<WasixToolProcessResult>;
44
+ serve(connection: WasixProtocolConnection, mode: WasixProtocolConnectionMode): Promise<void>;
45
+ sync(boundary: WasixStorageSyncBoundary): Promise<void>;
46
+ backup(): Promise<Uint8Array>;
47
+ close(): Promise<void>;
48
+ }
49
+ /** @internal Cache verified runtime materialization without caching transient failures. */
50
+ export declare function prepareRuntimeCached(options: SerializedOpenOptions, prepare?: (options: SerializedOpenOptions) => Promise<PreparedWasixRuntime>): Promise<PreparedWasixRuntime>;