@madebyentropy/tnl 0.0.0-stage → 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 (198) hide show
  1. package/LICENSE +28 -0
  2. package/NOTICE +5 -0
  3. package/THIRD_PARTY_LICENSES.txt +3297 -0
  4. package/dist/adapters/ioredis.d.ts +7 -0
  5. package/dist/adapters/ioredis.js +87 -0
  6. package/dist/adapters/node-postgres.d.ts +8 -0
  7. package/dist/adapters/node-postgres.js +41 -0
  8. package/dist/adapters/postgres-js.d.ts +7 -0
  9. package/dist/adapters/postgres-js.js +55 -0
  10. package/dist/bin/tnl.d.ts +2 -0
  11. package/dist/bin/tnl.js +16 -0
  12. package/dist/browser.d.ts +18 -0
  13. package/dist/browser.js +43 -0
  14. package/dist/bun.d.ts +9 -0
  15. package/dist/bun.js +6 -0
  16. package/dist/cloudflare.d.ts +9 -0
  17. package/dist/cloudflare.js +16 -0
  18. package/dist/config.d.ts +107 -0
  19. package/dist/config.gen.d.ts +1185 -0
  20. package/dist/config.gen.js +2 -0
  21. package/dist/config.js +3 -0
  22. package/dist/control.d.ts +5 -0
  23. package/dist/control.js +9 -0
  24. package/dist/durable-object.d.ts +51 -0
  25. package/dist/durable-object.js +374 -0
  26. package/dist/durable-object.worker.d.ts +5 -0
  27. package/dist/durable-object.worker.js +11 -0
  28. package/dist/errors.d.ts +17 -0
  29. package/dist/errors.js +230 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +2 -0
  32. package/dist/internal/connector/cancellation.d.ts +7 -0
  33. package/dist/internal/connector/cancellation.js +30 -0
  34. package/dist/internal/connector/client.d.ts +62 -0
  35. package/dist/internal/connector/client.js +504 -0
  36. package/dist/internal/connector/client_factory.d.ts +6 -0
  37. package/dist/internal/connector/client_factory.js +123 -0
  38. package/dist/internal/connector/connection.d.ts +39 -0
  39. package/dist/internal/connector/connection.js +739 -0
  40. package/dist/internal/connector/connection_ipc.d.ts +12 -0
  41. package/dist/internal/connector/connection_ipc.js +198 -0
  42. package/dist/internal/connector/context.d.ts +28 -0
  43. package/dist/internal/connector/context.js +19 -0
  44. package/dist/internal/connector/contract.d.ts +392 -0
  45. package/dist/internal/connector/contract.js +56 -0
  46. package/dist/internal/connector/deployment_types.d.ts +27 -0
  47. package/dist/internal/connector/deployment_types.js +1 -0
  48. package/dist/internal/connector/driver_socket.d.ts +21 -0
  49. package/dist/internal/connector/driver_socket.js +129 -0
  50. package/dist/internal/connector/management.d.ts +29 -0
  51. package/dist/internal/connector/management.js +118 -0
  52. package/dist/internal/connector/native_operations.d.ts +16 -0
  53. package/dist/internal/connector/native_operations.js +30 -0
  54. package/dist/internal/connector/native_stream.d.ts +7 -0
  55. package/dist/internal/connector/native_stream.js +219 -0
  56. package/dist/internal/connector/operation_handles.d.ts +9 -0
  57. package/dist/internal/connector/operation_handles.js +18 -0
  58. package/dist/internal/connector/portable_operations.d.ts +13 -0
  59. package/dist/internal/connector/portable_operations.js +25 -0
  60. package/dist/internal/connector/snapshot.d.ts +183 -0
  61. package/dist/internal/connector/snapshot.js +47 -0
  62. package/dist/internal/connector/wasm_abi.d.ts +76 -0
  63. package/dist/internal/connector/wasm_abi.js +5 -0
  64. package/dist/internal/connector/wasm_client.d.ts +58 -0
  65. package/dist/internal/connector/wasm_client.js +545 -0
  66. package/dist/internal/connector/wasm_loader.d.ts +15 -0
  67. package/dist/internal/connector/wasm_loader.js +99 -0
  68. package/dist/internal/connector/wasm_stream.d.ts +4 -0
  69. package/dist/internal/connector/wasm_stream.js +177 -0
  70. package/dist/internal/connector/workload/contract.d.ts +54 -0
  71. package/dist/internal/connector/workload/contract.js +14 -0
  72. package/dist/internal/connector/workload/provider.d.ts +24 -0
  73. package/dist/internal/connector/workload/provider.js +130 -0
  74. package/dist/internal/enrollment_source.d.ts +4 -0
  75. package/dist/internal/enrollment_source.js +34 -0
  76. package/dist/internal/management/client/client.gen.d.ts +2 -0
  77. package/dist/internal/management/client/client.gen.js +216 -0
  78. package/dist/internal/management/client/index.d.ts +10 -0
  79. package/dist/internal/management/client/index.js +6 -0
  80. package/dist/internal/management/client/types.gen.d.ts +120 -0
  81. package/dist/internal/management/client/types.gen.js +2 -0
  82. package/dist/internal/management/client/utils.gen.d.ts +37 -0
  83. package/dist/internal/management/client/utils.gen.js +228 -0
  84. package/dist/internal/management/client.gen.d.ts +12 -0
  85. package/dist/internal/management/client.gen.js +3 -0
  86. package/dist/internal/management/core/auth.gen.d.ts +25 -0
  87. package/dist/internal/management/core/auth.gen.js +14 -0
  88. package/dist/internal/management/core/bodySerializer.gen.d.ts +25 -0
  89. package/dist/internal/management/core/bodySerializer.gen.js +57 -0
  90. package/dist/internal/management/core/params.gen.d.ts +43 -0
  91. package/dist/internal/management/core/params.gen.js +109 -0
  92. package/dist/internal/management/core/pathSerializer.gen.d.ts +33 -0
  93. package/dist/internal/management/core/pathSerializer.gen.js +106 -0
  94. package/dist/internal/management/core/queryKeySerializer.gen.d.ts +18 -0
  95. package/dist/internal/management/core/queryKeySerializer.gen.js +92 -0
  96. package/dist/internal/management/core/serverSentEvents.gen.d.ts +71 -0
  97. package/dist/internal/management/core/serverSentEvents.gen.js +132 -0
  98. package/dist/internal/management/core/types.gen.d.ts +83 -0
  99. package/dist/internal/management/core/types.gen.js +2 -0
  100. package/dist/internal/management/core/utils.gen.d.ts +19 -0
  101. package/dist/internal/management/core/utils.gen.js +87 -0
  102. package/dist/internal/management/index.d.ts +2 -0
  103. package/dist/internal/management/index.js +2 -0
  104. package/dist/internal/management/sdk.gen.d.ts +73 -0
  105. package/dist/internal/management/sdk.gen.js +191 -0
  106. package/dist/internal/management/types.gen.d.ts +464 -0
  107. package/dist/internal/management/types.gen.js +2 -0
  108. package/dist/internal/management/zod.gen.d.ts +850 -0
  109. package/dist/internal/management/zod.gen.js +252 -0
  110. package/dist/internal/native/launcher.d.ts +8 -0
  111. package/dist/internal/native/launcher.js +75 -0
  112. package/dist/internal/native/native-targets.d.ts +9 -0
  113. package/dist/internal/native/native-targets.js +8 -0
  114. package/dist/internal/portable/cloudflare-publisher-client.d.ts +54 -0
  115. package/dist/internal/portable/cloudflare-publisher-client.js +91 -0
  116. package/dist/internal/portable/cloudflare-publisher.d.ts +19 -0
  117. package/dist/internal/portable/cloudflare-publisher.js +210 -0
  118. package/dist/internal/portable/durable-deployment.d.ts +10 -0
  119. package/dist/internal/portable/durable-deployment.js +22 -0
  120. package/dist/internal/portable/enrollment.d.ts +26 -0
  121. package/dist/internal/portable/enrollment.js +196 -0
  122. package/dist/internal/portable/publication.d.ts +54 -0
  123. package/dist/internal/portable/publication.js +304 -0
  124. package/dist/internal/portable/request.d.ts +1 -0
  125. package/dist/internal/portable/request.js +20 -0
  126. package/dist/internal/portable/storage-browser.d.ts +9 -0
  127. package/dist/internal/portable/storage-browser.js +115 -0
  128. package/dist/internal/portable/storage-durable-object.d.ts +11 -0
  129. package/dist/internal/portable/storage-durable-object.js +110 -0
  130. package/dist/internal/portable/storage-host.d.ts +8 -0
  131. package/dist/internal/portable/storage-host.js +142 -0
  132. package/dist/internal/portable/storage.d.ts +15 -0
  133. package/dist/internal/portable/storage.js +29 -0
  134. package/dist/internal/project/native_runtime.d.ts +24 -0
  135. package/dist/internal/project/native_runtime.js +23 -0
  136. package/dist/internal/project/runtime.d.ts +467 -0
  137. package/dist/internal/project/runtime.js +183 -0
  138. package/dist/internal/project/service_metadata.d.ts +3 -0
  139. package/dist/internal/project/service_metadata.js +12 -0
  140. package/dist/internal/publication_certificate.d.ts +28 -0
  141. package/dist/internal/publication_certificate.js +32 -0
  142. package/dist/internal/publication_run.d.ts +8 -0
  143. package/dist/internal/publication_run.js +19 -0
  144. package/dist/internal/publisher/app.d.ts +33 -0
  145. package/dist/internal/publisher/app.js +317 -0
  146. package/dist/internal/publisher/fetch.d.ts +6 -0
  147. package/dist/internal/publisher/fetch.js +135 -0
  148. package/dist/internal/publisher/fetch_types.d.ts +1 -0
  149. package/dist/internal/publisher/fetch_types.js +1 -0
  150. package/dist/internal/publisher/framework.d.ts +27 -0
  151. package/dist/internal/publisher/framework.js +82 -0
  152. package/dist/internal/publisher/local.d.ts +39 -0
  153. package/dist/internal/publisher/local.js +312 -0
  154. package/dist/internal/publisher/native_publisher.d.ts +25 -0
  155. package/dist/internal/publisher/native_publisher.js +228 -0
  156. package/dist/internal/publisher/port.d.ts +2 -0
  157. package/dist/internal/publisher/port.js +15 -0
  158. package/dist/internal/publisher/publication.d.ts +88 -0
  159. package/dist/internal/publisher/publication.js +627 -0
  160. package/dist/internal/publisher/register.d.ts +31 -0
  161. package/dist/internal/publisher/register.js +136 -0
  162. package/dist/internal/publisher/registration.d.ts +385 -0
  163. package/dist/internal/publisher/registration.js +223 -0
  164. package/dist/internal/publisher/status.d.ts +47 -0
  165. package/dist/internal/publisher/status.js +137 -0
  166. package/dist/internal/publisher/target.d.ts +6 -0
  167. package/dist/internal/publisher/target.js +44 -0
  168. package/dist/internal/runtime_resources.d.ts +38 -0
  169. package/dist/internal/runtime_resources.js +52 -0
  170. package/dist/internal/tracing.d.ts +10 -0
  171. package/dist/internal/tracing.js +78 -0
  172. package/dist/internal/validation.d.ts +3 -0
  173. package/dist/internal/validation.js +9 -0
  174. package/dist/internal/values.d.ts +27 -0
  175. package/dist/internal/values.js +54 -0
  176. package/dist/next.d.ts +12 -0
  177. package/dist/next.js +82 -0
  178. package/dist/node.d.ts +9 -0
  179. package/dist/node.js +6 -0
  180. package/dist/project.d.ts +173 -0
  181. package/dist/project.js +1 -0
  182. package/dist/response.d.ts +1 -0
  183. package/dist/response.js +34 -0
  184. package/dist/third-party-licenses.txt +1537 -0
  185. package/dist/vite.d.ts +5 -0
  186. package/dist/vite.js +200 -0
  187. package/dist/wasm/build.json +16 -0
  188. package/dist/wasm/connector.wasm +0 -0
  189. package/dist/wasm/go-license.txt +27 -0
  190. package/dist/wasm/publisher.wasm +0 -0
  191. package/dist/wasm/third-party-licenses.txt +3297 -0
  192. package/dist/wasm/wasm_exec.d.ts +1 -0
  193. package/dist/wasm/wasm_exec.js +575 -0
  194. package/dist/workload.d.ts +11 -0
  195. package/dist/workload.js +4 -0
  196. package/package.json +159 -4
  197. package/readme.md +13 -0
  198. package/README.md +0 -3
@@ -0,0 +1,142 @@
1
+ import { PublisherStorageError, storageBytes, storageKey, throwIfStorageAborted, } from "./storage.js";
2
+ // adapt one atomic private-record store to go's certificate-storage host abi.
3
+ // scope is part of both record and lock identity, never an authorization grant.
4
+ export function createPublisherStorageHost(storage) {
5
+ if (storage === undefined ||
6
+ storage === null ||
7
+ ![storage.get, storage.put, storage.sync, storage.withLock].every((method) => typeof method === "function"))
8
+ throw new PublisherStorageError();
9
+ const scopedKey = async (scopeJSON, key) => {
10
+ storageKey(key);
11
+ let scope;
12
+ try {
13
+ scope = JSON.parse(scopeJSON);
14
+ }
15
+ catch {
16
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
17
+ }
18
+ if (typeof scope !== "object" || scope === null || Array.isArray(scope))
19
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
20
+ const count = Object.keys(scope).length;
21
+ let canonical;
22
+ if (count === 1 &&
23
+ "publisher_slot" in scope &&
24
+ typeof scope.publisher_slot === "string" &&
25
+ /^[a-z][a-z0-9-]{0,62}$/.test(scope.publisher_slot)) {
26
+ canonical = JSON.stringify(["enrollment", scope.publisher_slot, key]);
27
+ }
28
+ else if (count === 3 &&
29
+ "control_url" in scope &&
30
+ scopeText(scope.control_url) &&
31
+ "team_id" in scope &&
32
+ scopeText(scope.team_id, true) &&
33
+ "publisher_identity_id" in scope &&
34
+ scopeText(scope.publisher_identity_id)) {
35
+ canonical = JSON.stringify([
36
+ scope.control_url,
37
+ scope.team_id,
38
+ scope.publisher_identity_id,
39
+ key,
40
+ ]);
41
+ }
42
+ else {
43
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
44
+ }
45
+ try {
46
+ const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)));
47
+ return `scope:${Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
48
+ }
49
+ catch {
50
+ throw new PublisherStorageError();
51
+ }
52
+ };
53
+ return Object.freeze({
54
+ async read(scopeJSON, key, limit, signal) {
55
+ throwIfStorageAborted(signal);
56
+ if (!Number.isSafeInteger(limit) || limit < 0 || limit > 16 * 1024 * 1024)
57
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
58
+ const name = await scopedKey(scopeJSON, key);
59
+ const record = await protect(async () => {
60
+ const value = await storage.get(name);
61
+ if (value === undefined)
62
+ return null;
63
+ if (value.byteLength > limit)
64
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
65
+ return storageBytes(value);
66
+ }, signal);
67
+ throwIfStorageAborted(signal);
68
+ return record;
69
+ },
70
+ async write(scopeJSON, key, bytes, signal) {
71
+ throwIfStorageAborted(signal);
72
+ const record = storageBytes(bytes);
73
+ const name = await scopedKey(scopeJSON, key);
74
+ await protect(async () => {
75
+ await storage.put(name, record);
76
+ // go's Write requires durable success. join sync even if cancellation
77
+ // arrived during put; a later standalone Sync must not repair this write.
78
+ await storage.sync(name);
79
+ }, signal);
80
+ throwIfStorageAborted(signal);
81
+ },
82
+ async sync(scopeJSON, key, signal) {
83
+ throwIfStorageAborted(signal);
84
+ const name = await scopedKey(scopeJSON, key);
85
+ await protect(() => storage.sync(name), signal);
86
+ throwIfStorageAborted(signal);
87
+ },
88
+ async lock(scopeJSON, key, signal) {
89
+ throwIfStorageAborted(signal);
90
+ const name = await scopedKey(scopeJSON, key);
91
+ let acquired;
92
+ let failed;
93
+ const result = new Promise((resolve, reject) => {
94
+ acquired = resolve;
95
+ failed = reject;
96
+ });
97
+ let release;
98
+ const held = new Promise((resolve) => {
99
+ release = resolve;
100
+ });
101
+ const ownership = Promise.resolve().then(() => storage.withLock(name, async () => {
102
+ acquired(async () => {
103
+ release();
104
+ await protect(() => ownership);
105
+ });
106
+ await held;
107
+ }, signal));
108
+ void ownership.catch((error) => failed(safeStorageError(error, signal)));
109
+ return result;
110
+ },
111
+ });
112
+ }
113
+ async function protect(operation, signal) {
114
+ throwIfStorageAborted(signal);
115
+ try {
116
+ return await operation();
117
+ }
118
+ catch (error) {
119
+ throw safeStorageError(error, signal);
120
+ }
121
+ }
122
+ function safeStorageError(error, signal) {
123
+ const canceled = signal?.aborted
124
+ ? new DOMException("publisher storage operation was aborted", "AbortError")
125
+ : undefined;
126
+ if (canceled !== undefined && error instanceof DOMException && error.name === "AbortError")
127
+ return canceled;
128
+ const failure = new PublisherStorageError(error instanceof PublisherStorageError && error.code === "sdk.publisher_storage_invalid"
129
+ ? "sdk.publisher_storage_invalid"
130
+ : "sdk.publisher_storage_unavailable");
131
+ // cancellation is not proof that a concurrent storage operation succeeded.
132
+ // retain both facts, but never retain the provider's private error or cause.
133
+ return canceled === undefined
134
+ ? failure
135
+ : new AggregateError([failure, canceled], "publisher storage failed during cancellation");
136
+ }
137
+ function scopeText(value, allowEmpty = false) {
138
+ return (typeof value === "string" &&
139
+ (allowEmpty || value.length > 0) &&
140
+ value.length <= 4096 &&
141
+ !value.includes("\0"));
142
+ }
@@ -0,0 +1,15 @@
1
+ export interface PublisherStorage {
2
+ get(key: string): Promise<Uint8Array | undefined>;
3
+ put(key: string, value: Uint8Array): Promise<void>;
4
+ delete(key: string): Promise<void>;
5
+ sync(key: string): Promise<void>;
6
+ withLock<T>(name: string, operation: () => Promise<T>, signal?: AbortSignal): Promise<T>;
7
+ }
8
+ export type PublisherStorageErrorCode = "sdk.publisher_storage_unavailable" | "sdk.publisher_storage_invalid";
9
+ export declare class PublisherStorageError extends Error {
10
+ readonly code: PublisherStorageErrorCode;
11
+ constructor(code?: PublisherStorageErrorCode);
12
+ }
13
+ export declare function storageKey(value: string): string;
14
+ export declare function storageBytes(value: unknown): Uint8Array<ArrayBuffer>;
15
+ export declare function throwIfStorageAborted(signal?: AbortSignal): void;
@@ -0,0 +1,29 @@
1
+ // storage engines may include private record values in their exceptions. never
2
+ // retain those exceptions as public causes or interpolate a key or value here.
3
+ export class PublisherStorageError extends Error {
4
+ code;
5
+ constructor(code = "sdk.publisher_storage_unavailable") {
6
+ super(code === "sdk.publisher_storage_unavailable"
7
+ ? "publisher storage or exclusive locking is unavailable; provide durable private storage before publishing"
8
+ : "publisher storage contains an invalid record; repair the selected private storage before publishing");
9
+ this.name = "PublisherStorageError";
10
+ this.code = code;
11
+ }
12
+ }
13
+ export function storageKey(value) {
14
+ if (typeof value !== "string" ||
15
+ value.length === 0 ||
16
+ value.length > 1024 ||
17
+ value.includes("\0"))
18
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
19
+ return value;
20
+ }
21
+ export function storageBytes(value) {
22
+ if (!(value instanceof Uint8Array) || value.byteLength > 16 * 1024 * 1024)
23
+ throw new PublisherStorageError("sdk.publisher_storage_invalid");
24
+ return Uint8Array.from(value);
25
+ }
26
+ export function throwIfStorageAborted(signal) {
27
+ if (signal?.aborted)
28
+ throw new DOMException("publisher storage lock was aborted", "AbortError");
29
+ }
@@ -0,0 +1,24 @@
1
+ import { type ProjectMetadata } from "./runtime.js";
2
+ import type { PrepareOptions, PreparedService } from "../publisher/app.js";
3
+ import type { TnlProjectConfig } from "../../index.js";
4
+ import type { TnlProjectFromConfig, TnlResolvedConfig, TnlService, TnlProtocolRegistry } from "../../project.js";
5
+ export type { PrepareOptions, PreparedService } from "../publisher/app.js";
6
+ type Config = TnlProjectConfig extends {
7
+ config: infer Input;
8
+ } ? TnlResolvedConfig<Input> : {
9
+ services: Record<string, {
10
+ protocol: keyof TnlProtocolRegistry;
11
+ }>;
12
+ };
13
+ type RegisteredTnlProject = keyof TnlProjectConfig extends never ? {
14
+ services: Readonly<Record<string, TnlService<{
15
+ protocol: keyof TnlProtocolRegistry;
16
+ }> | undefined>>;
17
+ } : TnlProjectFromConfig<Config>;
18
+ export type TnlRuntime = Readonly<Partial<Omit<ProjectMetadata, "services">> & Partial<Omit<RegisteredTnlProject, "workloads" | "services">> & {
19
+ services: RegisteredTnlProject["services"];
20
+ readonly port: number;
21
+ readonly dev: boolean;
22
+ prepare(options?: PrepareOptions): Promise<PreparedService>;
23
+ }>;
24
+ export declare const tnl: TnlRuntime;
@@ -0,0 +1,23 @@
1
+ import { developmentPort } from "../publisher/port.js";
2
+ import { serviceMetadata } from "./service_metadata.js";
3
+ import { parseRuntimePayload } from "./runtime.js";
4
+ import { TnlError } from "../../errors.js";
5
+ const serializedRuntime = typeof process === "undefined" ? undefined : process.env?.TNL_PROJECT_RUNTIME;
6
+ /** Server port and optional browser-safe project metadata for this process. */
7
+ // the parser validates the runtime shape; generated project declarations supply
8
+ // project-specific service names and literals unavailable to this shared module.
9
+ const runtime = parseRuntimePayload(serializedRuntime);
10
+ export const tnl = Object.freeze({
11
+ ...runtime,
12
+ get services() {
13
+ return serviceMetadata(runtime);
14
+ },
15
+ port: developmentPort(typeof process === "undefined" ? {} : (process.env ?? {}), "Bun" in globalThis),
16
+ dev: runtime?.dev ?? false,
17
+ async prepare(options = {}) {
18
+ if (typeof process === "undefined")
19
+ throw new TnlError("sdk.configuration_invalid");
20
+ const { prepareService } = await import("../publisher/app.js");
21
+ return prepareService(options, "Bun" in globalThis ? "bun" : "node");
22
+ },
23
+ });