@dxos/protocols 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (192) hide show
  1. package/dist/src/FunctionProtocol.d.ts +82 -0
  2. package/dist/src/FunctionProtocol.d.ts.map +1 -0
  3. package/dist/src/FunctionProtocol.js +4 -0
  4. package/dist/src/FunctionProtocol.js.map +1 -0
  5. package/dist/src/buf/proto/gen/dxos/client/queue_pb.d.ts +189 -0
  6. package/dist/src/buf/proto/gen/dxos/client/queue_pb.d.ts.map +1 -0
  7. package/dist/src/buf/proto/gen/dxos/client/queue_pb.js +39 -0
  8. package/dist/src/buf/proto/gen/dxos/client/queue_pb.js.map +1 -0
  9. package/dist/src/buf/proto/gen/dxos/config_pb.d.ts +4 -0
  10. package/dist/src/buf/proto/gen/dxos/config_pb.d.ts.map +1 -1
  11. package/dist/src/buf/proto/gen/dxos/config_pb.js +1 -1
  12. package/dist/src/buf/proto/gen/dxos/config_pb.js.map +1 -1
  13. package/dist/src/buf/proto/gen/dxos/echo/query_pb.d.ts +12 -2
  14. package/dist/src/buf/proto/gen/dxos/echo/query_pb.d.ts.map +1 -1
  15. package/dist/src/buf/proto/gen/dxos/echo/query_pb.js +1 -1
  16. package/dist/src/buf/proto/gen/dxos/echo/query_pb.js.map +1 -1
  17. package/dist/src/buf/proto/gen/dxos/echo/service_pb.d.ts +55 -9
  18. package/dist/src/buf/proto/gen/dxos/echo/service_pb.d.ts.map +1 -1
  19. package/dist/src/buf/proto/gen/dxos/echo/service_pb.js +15 -5
  20. package/dist/src/buf/proto/gen/dxos/echo/service_pb.js.map +1 -1
  21. package/dist/src/buf/proto/gen/dxos/google_pb.js +1 -1
  22. package/dist/src/buf/proto/gen/dxos/google_pb.js.map +1 -1
  23. package/dist/src/buf/proto/gen/dxos/iframe_pb.d.ts +1 -0
  24. package/dist/src/buf/proto/gen/dxos/iframe_pb.d.ts.map +1 -1
  25. package/dist/src/buf/proto/gen/dxos/iframe_pb.js.map +1 -1
  26. package/dist/src/buf/proto/gen/dxos/tracing_pb.js +1 -1
  27. package/dist/src/buf/proto/gen/dxos/tracing_pb.js.map +1 -1
  28. package/dist/src/edge/EdgeFunctionEnv.d.ts +120 -0
  29. package/dist/src/edge/EdgeFunctionEnv.d.ts.map +1 -0
  30. package/dist/src/edge/EdgeFunctionEnv.js +4 -0
  31. package/dist/src/edge/EdgeFunctionEnv.js.map +1 -0
  32. package/dist/src/{edge.d.ts → edge/edge.d.ts} +47 -20
  33. package/dist/src/edge/edge.d.ts.map +1 -0
  34. package/dist/src/{edge.js → edge/edge.js} +24 -7
  35. package/dist/src/edge/edge.js.map +1 -0
  36. package/dist/src/{edge-error.d.ts → edge/errors.d.ts} +5 -6
  37. package/dist/src/edge/errors.d.ts.map +1 -0
  38. package/dist/src/{edge-error.js → edge/errors.js} +13 -14
  39. package/dist/src/edge/errors.js.map +1 -0
  40. package/dist/src/edge/index.d.ts +4 -0
  41. package/dist/src/edge/index.d.ts.map +1 -0
  42. package/dist/src/edge/index.js +7 -0
  43. package/dist/src/edge/index.js.map +1 -0
  44. package/dist/src/errors/base-errors.d.ts +86 -8
  45. package/dist/src/errors/base-errors.d.ts.map +1 -1
  46. package/dist/src/errors/base-errors.js +4 -20
  47. package/dist/src/errors/base-errors.js.map +1 -1
  48. package/dist/src/errors/encoding.d.ts +1 -1
  49. package/dist/src/errors/encoding.d.ts.map +1 -1
  50. package/dist/src/errors/errors.d.ts +618 -41
  51. package/dist/src/errors/errors.d.ts.map +1 -1
  52. package/dist/src/errors/errors.js +49 -103
  53. package/dist/src/errors/errors.js.map +1 -1
  54. package/dist/src/errors/errors.test.js +1 -1
  55. package/dist/src/errors/errors.test.js.map +1 -1
  56. package/dist/src/errors/helpers.d.ts +8 -4
  57. package/dist/src/errors/helpers.d.ts.map +1 -1
  58. package/dist/src/errors/helpers.js +3 -3
  59. package/dist/src/errors/helpers.js.map +1 -1
  60. package/dist/src/feed-replication.d.ts.map +1 -1
  61. package/dist/src/index.d.ts +3 -3
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js +4 -3
  64. package/dist/src/index.js.map +1 -1
  65. package/dist/src/messenger.d.ts +16 -0
  66. package/dist/src/messenger.d.ts.map +1 -0
  67. package/dist/src/messenger.js +4 -0
  68. package/dist/src/messenger.js.map +1 -0
  69. package/dist/src/proto/gen/dxos/client/services.d.ts +103 -0
  70. package/dist/src/proto/gen/dxos/client/services.d.ts.map +1 -1
  71. package/dist/src/proto/gen/dxos/client/services.js.map +1 -1
  72. package/dist/src/proto/gen/dxos/config.d.ts +5 -0
  73. package/dist/src/proto/gen/dxos/config.d.ts.map +1 -1
  74. package/dist/src/proto/gen/dxos/config.js.map +1 -1
  75. package/dist/src/proto/gen/dxos/echo/query.d.ts +17 -1
  76. package/dist/src/proto/gen/dxos/echo/query.d.ts.map +1 -1
  77. package/dist/src/proto/gen/dxos/echo/query.js.map +1 -1
  78. package/dist/src/proto/gen/dxos/echo/service.d.ts +34 -8
  79. package/dist/src/proto/gen/dxos/echo/service.d.ts.map +1 -1
  80. package/dist/src/proto/gen/index.d.ts +8 -0
  81. package/dist/src/proto/gen/index.d.ts.map +1 -1
  82. package/dist/src/proto/gen/index.js +1 -1
  83. package/dist/src/proto/gen/index.js.map +1 -1
  84. package/dist/src/queue.d.ts +1 -26
  85. package/dist/src/queue.d.ts.map +1 -1
  86. package/dist/src/queue.js +1 -4
  87. package/dist/src/queue.js.map +1 -1
  88. package/dist/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +19 -15
  90. package/src/FunctionProtocol.ts +104 -0
  91. package/src/buf/proto/gen/dxos/agent/dashboard_pb.ts +1 -1
  92. package/src/buf/proto/gen/dxos/agent/echo-proxy_pb.ts +1 -1
  93. package/src/buf/proto/gen/dxos/agent/epoch_pb.ts +1 -1
  94. package/src/buf/proto/gen/dxos/agent/functions_pb.ts +1 -1
  95. package/src/buf/proto/gen/dxos/bot_pb.ts +1 -1
  96. package/src/buf/proto/gen/dxos/client/invitation_pb.ts +1 -1
  97. package/src/buf/proto/gen/dxos/client/logging_pb.ts +1 -1
  98. package/src/buf/proto/gen/dxos/client/queue_pb.ts +231 -0
  99. package/src/buf/proto/gen/dxos/client/services_pb.ts +1 -1
  100. package/src/buf/proto/gen/dxos/config_pb.ts +7 -2
  101. package/src/buf/proto/gen/dxos/devtools/diagnostics_pb.ts +1 -1
  102. package/src/buf/proto/gen/dxos/devtools/host_pb.ts +1 -1
  103. package/src/buf/proto/gen/dxos/devtools/swarm_pb.ts +1 -1
  104. package/src/buf/proto/gen/dxos/echo/blob_pb.ts +1 -1
  105. package/src/buf/proto/gen/dxos/echo/feed_pb.ts +1 -1
  106. package/src/buf/proto/gen/dxos/echo/filter_pb.ts +1 -1
  107. package/src/buf/proto/gen/dxos/echo/indexing_pb.ts +1 -1
  108. package/src/buf/proto/gen/dxos/echo/metadata_pb.ts +1 -1
  109. package/src/buf/proto/gen/dxos/echo/model/document_pb.ts +1 -1
  110. package/src/buf/proto/gen/dxos/echo/model/messenger_pb.ts +1 -1
  111. package/src/buf/proto/gen/dxos/echo/model/text_pb.ts +1 -1
  112. package/src/buf/proto/gen/dxos/echo/object_pb.ts +1 -1
  113. package/src/buf/proto/gen/dxos/echo/query_pb.ts +16 -4
  114. package/src/buf/proto/gen/dxos/echo/service_pb.ts +68 -16
  115. package/src/buf/proto/gen/dxos/echo/snapshot_pb.ts +1 -1
  116. package/src/buf/proto/gen/dxos/echo/timeframe_pb.ts +1 -1
  117. package/src/buf/proto/gen/dxos/edge/calls_pb.ts +1 -1
  118. package/src/buf/proto/gen/dxos/edge/messenger_pb.ts +1 -1
  119. package/src/buf/proto/gen/dxos/edge/signal_pb.ts +1 -1
  120. package/src/buf/proto/gen/dxos/error_pb.ts +1 -1
  121. package/src/buf/proto/gen/dxos/field_options_pb.ts +1 -1
  122. package/src/buf/proto/gen/dxos/google_pb.ts +1 -1
  123. package/src/buf/proto/gen/dxos/gravity_pb.ts +1 -1
  124. package/src/buf/proto/gen/dxos/halo/credentials/auth_pb.ts +1 -1
  125. package/src/buf/proto/gen/dxos/halo/credentials/greet_pb.ts +1 -1
  126. package/src/buf/proto/gen/dxos/halo/credentials/identity_pb.ts +1 -1
  127. package/src/buf/proto/gen/dxos/halo/credentials_pb.ts +1 -1
  128. package/src/buf/proto/gen/dxos/halo/invitations_pb.ts +1 -1
  129. package/src/buf/proto/gen/dxos/halo/keyring_pb.ts +1 -1
  130. package/src/buf/proto/gen/dxos/halo/keys_pb.ts +1 -1
  131. package/src/buf/proto/gen/dxos/halo/signed_pb.ts +1 -1
  132. package/src/buf/proto/gen/dxos/iframe_pb.ts +2 -1
  133. package/src/buf/proto/gen/dxos/keys_pb.ts +1 -1
  134. package/src/buf/proto/gen/dxos/mesh/bridge_pb.ts +1 -1
  135. package/src/buf/proto/gen/dxos/mesh/broadcast_pb.ts +1 -1
  136. package/src/buf/proto/gen/dxos/mesh/messaging_pb.ts +1 -1
  137. package/src/buf/proto/gen/dxos/mesh/muxer_pb.ts +1 -1
  138. package/src/buf/proto/gen/dxos/mesh/presence_pb.ts +1 -1
  139. package/src/buf/proto/gen/dxos/mesh/protocol_pb.ts +1 -1
  140. package/src/buf/proto/gen/dxos/mesh/replicator_pb.ts +1 -1
  141. package/src/buf/proto/gen/dxos/mesh/signal_pb.ts +1 -1
  142. package/src/buf/proto/gen/dxos/mesh/swarm_pb.ts +1 -1
  143. package/src/buf/proto/gen/dxos/mesh/teleport/admission-discovery_pb.ts +1 -1
  144. package/src/buf/proto/gen/dxos/mesh/teleport/auth_pb.ts +1 -1
  145. package/src/buf/proto/gen/dxos/mesh/teleport/automerge_pb.ts +1 -1
  146. package/src/buf/proto/gen/dxos/mesh/teleport/blobsync_pb.ts +1 -1
  147. package/src/buf/proto/gen/dxos/mesh/teleport/control_pb.ts +1 -1
  148. package/src/buf/proto/gen/dxos/mesh/teleport/gossip_pb.ts +1 -1
  149. package/src/buf/proto/gen/dxos/mesh/teleport/notarization_pb.ts +1 -1
  150. package/src/buf/proto/gen/dxos/mesh/teleport/replicator_pb.ts +1 -1
  151. package/src/buf/proto/gen/dxos/registry_pb.ts +1 -1
  152. package/src/buf/proto/gen/dxos/rpc_pb.ts +1 -1
  153. package/src/buf/proto/gen/dxos/service/agentmanager_pb.ts +1 -1
  154. package/src/buf/proto/gen/dxos/service/publisher_pb.ts +1 -1
  155. package/src/buf/proto/gen/dxos/service/supervisor_pb.ts +1 -1
  156. package/src/buf/proto/gen/dxos/service/tunnel_pb.ts +1 -1
  157. package/src/buf/proto/gen/dxos/tracing_pb.ts +1 -1
  158. package/src/buf/proto/gen/dxos/type_pb.ts +1 -1
  159. package/src/buf/proto/gen/dxos/value_pb.ts +1 -1
  160. package/src/buf/proto/gen/example/testing/data_pb.ts +1 -1
  161. package/src/buf/proto/gen/example/testing/rpc_pb.ts +1 -1
  162. package/src/edge/EdgeFunctionEnv.ts +193 -0
  163. package/src/{edge.ts → edge/edge.ts} +57 -27
  164. package/src/{edge-error.ts → edge/errors.ts} +14 -15
  165. package/src/edge/index.ts +7 -0
  166. package/src/errors/base-errors.ts +4 -22
  167. package/src/errors/errors.test.ts +1 -1
  168. package/src/errors/errors.ts +55 -121
  169. package/src/errors/helpers.ts +5 -6
  170. package/src/feed-replication.ts +1 -0
  171. package/src/index.ts +5 -3
  172. package/src/messenger.ts +22 -0
  173. package/src/proto/dxos/client/queue.proto +67 -0
  174. package/src/proto/dxos/config.proto +2 -0
  175. package/src/proto/dxos/echo/query.proto +4 -1
  176. package/src/proto/dxos/echo/service.proto +27 -6
  177. package/src/proto/dxos/iframe.proto +1 -0
  178. package/src/proto/gen/dxos/client/services.ts +103 -0
  179. package/src/proto/gen/dxos/config.ts +5 -0
  180. package/src/proto/gen/dxos/echo/query.ts +17 -1
  181. package/src/proto/gen/dxos/echo/service.ts +33 -8
  182. package/src/proto/gen/index.ts +9 -1
  183. package/src/queue.ts +9 -33
  184. package/dist/src/edge-error.d.ts.map +0 -1
  185. package/dist/src/edge-error.js.map +0 -1
  186. package/dist/src/edge.d.ts.map +0 -1
  187. package/dist/src/edge.js.map +0 -1
  188. package/dist/src/query.d.ts +0 -5
  189. package/dist/src/query.d.ts.map +0 -1
  190. package/dist/src/query.js +0 -8
  191. package/dist/src/query.js.map +0 -1
  192. package/src/query.ts +0 -8
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file dxos/service/publisher.proto (package dxos.service.publisher, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file dxos/service/supervisor.proto (package dxos.service.supervisor, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file dxos/service/tunnel.proto (package dxos.service.tunnel, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -1,4 +1,4 @@
1
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
1
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
2
2
  // @generated from file dxos/tracing.proto (package dxos.tracing, syntax proto3)
3
3
  /* eslint-disable */
4
4
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file dxos/type.proto (package dxos.type, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file dxos/value.proto (package dxos.value, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file example/testing/data.proto (package example.testing.data, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- // @generated by protoc-gen-es v2.9.0 with parameter "target=ts,import_extension=js"
5
+ // @generated by protoc-gen-es v2.10.1 with parameter "target=ts,import_extension=js"
6
6
  // @generated from file example/testing/rpc.proto (package example.testing.rpc, syntax proto3)
7
7
  /* eslint-disable */
8
8
 
@@ -0,0 +1,193 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type SpaceId } from '@dxos/keys';
6
+
7
+ import { type CreateDocumentRequest, type CreateDocumentResponse } from '../proto/gen/dxos/echo/service';
8
+ import { type QueryResult, type QueueQuery } from '../queue';
9
+
10
+ /*
11
+
12
+ API for the edge functions service.
13
+ A function module should be a valid cloudflare worker module.
14
+
15
+ # Fetching metadata (done on deploy)
16
+
17
+ GET http://functions.dxos.internal/
18
+ X-DXOS-Function-Route: meta
19
+
20
+ Expected to return `FunctionMetadata` in JSON:
21
+
22
+ {
23
+ key: string;
24
+ name?: string;
25
+ description?: string;
26
+ inputSchema?: JsonSchemaType;
27
+ outputSchema?: JsonSchemaType;
28
+ }
29
+
30
+ # Invoking the function
31
+
32
+ POST http://functions.dxos.internal/
33
+ Content-Type: application/json
34
+ X-Trace-Queue-Dxn: dxn:queue:trace:AAAAAA:BBBBBB
35
+ X-Invocation-Id: XXXXXXX
36
+ X-Edge-Env: production
37
+
38
+ {input_data}
39
+
40
+ Expected to return `EdgeEnvelope` with the output data:
41
+
42
+ {
43
+ success: true,
44
+ data: unknown
45
+ }
46
+
47
+ On Error returns `EdgeEnvelope` with error:
48
+
49
+ {
50
+ success: false,
51
+ message: string
52
+ error: EncodedError
53
+ }
54
+
55
+ */
56
+
57
+ /**
58
+ * Environment available to the function running on Cloudflare.
59
+ */
60
+ export interface Env {
61
+ QUEUE_SERVICE: QueueService;
62
+ DATA_SERVICE: DataService;
63
+ FUNCTIONS_AI_SERVICE: FunctionsAiService;
64
+ }
65
+
66
+ /**
67
+ * Use to trace the execution across multiple services.
68
+ *
69
+ * NOTE: Currently unused in functions.
70
+ */
71
+ export interface ExecutionContext {}
72
+
73
+ /**
74
+ * Database API for other CF services like functions.
75
+ */
76
+ export interface DataService {
77
+ getSpaceMeta(ctx: ExecutionContext, spaceId: SpaceId): Promise<RpcResult<SpaceMeta | undefined>>;
78
+ getDocument(ctx: ExecutionContext, spaceId: SpaceId, documentId: string): Promise<RpcResult<RawDocument | undefined>>;
79
+
80
+ query(ctx: ExecutionContext, request: QueryRequest): Promise<RpcResult<QueryResponse>>;
81
+ queryDocuments(ctx: ExecutionContext, request: QueryRequest): Promise<RpcResult<QueryDocumentsResponse>>;
82
+ queryReferences(ctx: ExecutionContext, request: QueryReferencesRequest): Promise<RpcResult<QueryReferencesResponse>>;
83
+
84
+ createDocument(ctx: ExecutionContext, request: CreateDocumentRequest): Promise<RpcResult<CreateDocumentResponse>>;
85
+
86
+ // TODO(burdon): Update? Return DocumentEntry?
87
+ changeDocument(ctx: ExecutionContext, spaceId: SpaceId, documentId: string, changes: Uint8Array): Promise<void>;
88
+ }
89
+
90
+ export interface QueueService {
91
+ query(ctx: ExecutionContext, queueDXN: string, query: Omit<QueueQuery, 'queueId'>): Promise<RpcResult<QueryResult>>;
92
+ append(ctx: ExecutionContext, queueDXN: string, objects: unknown[]): Promise<void>;
93
+ }
94
+
95
+ /**
96
+ * FunctionsAiService API for other CF services like functions.
97
+ */
98
+ export interface FunctionsAiService {
99
+ /**
100
+ * Enables proxying HTTP requests to the AI service from other workers.
101
+ */
102
+ fetch(request: Request): Promise<RpcResult<Response>>;
103
+ }
104
+
105
+ export type ObjectDocumentJson = {
106
+ type?: string;
107
+ objectId: string;
108
+ documentId: string;
109
+ /** Base64 encoding of a document. */
110
+ document: string;
111
+ };
112
+
113
+ export type SpaceMeta = {
114
+ spaceKey: string;
115
+ rootDocumentId: string;
116
+ };
117
+
118
+ export type QueryRequest = {
119
+ spaceId: string;
120
+ type?: string;
121
+ where?: Record<string, any>;
122
+ objectIds?: string[];
123
+ cursor?: string;
124
+ limit?: number;
125
+ };
126
+
127
+ export type QueryResponse = {
128
+ results: ObjectSnapshot[];
129
+ cursor?: string;
130
+ };
131
+
132
+ /**
133
+ * TODO(yaroslav): make Indexer return EchoObject after create() can properly reconstruct an object
134
+ * from this structure (meta, id and type aren't handled properly)
135
+ */
136
+ export type ObjectSnapshot = {
137
+ type?: string;
138
+ documentId: string;
139
+ objectId: string;
140
+ // TODO(mykola): Use ObjectStructure from @dxos/echo-protocol.
141
+ object: unknown;
142
+ };
143
+
144
+ export type ObjectReference = {
145
+ fromId: string;
146
+ toId: string;
147
+ fieldName: string;
148
+ };
149
+
150
+ export type QueryDocumentsResponse = {
151
+ results: RawObject[];
152
+ cursor?: string;
153
+ };
154
+
155
+ export type RawDocument = {
156
+ documentId: string;
157
+ data: Uint8Array;
158
+ };
159
+
160
+ export type RawObject = {
161
+ type?: string;
162
+ objectId: string;
163
+ document: RawDocument;
164
+ };
165
+
166
+ export type QueryReferencesRequest = {
167
+ spaceId: string;
168
+ objectId: string;
169
+ referenceType: 'from' | 'to';
170
+ };
171
+
172
+ export type QueryReferencesResponse = {
173
+ references: ObjectReference[];
174
+ };
175
+
176
+ /**
177
+ * Cloudflare Workers RPC returns objects/arrays/stubs that may need to be explicitly disposed.
178
+ *
179
+ * See: https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
180
+ */
181
+ export interface RpcDisposable {
182
+ /**
183
+ * Disposes the RPC stub / returned value and releases any server-side resources it references.
184
+ */
185
+ [Symbol.dispose](): void;
186
+ }
187
+
188
+ /**
189
+ * Wraps a return type so that any non-primitive value is marked as disposable.
190
+ *
191
+ * This models Workers RPC behavior where any returned object (including arrays) gets a disposer added.
192
+ */
193
+ export type RpcResult<T> = T extends object ? T & RpcDisposable : T;
@@ -23,13 +23,15 @@ export type EdgeSuccess<T> = {
23
23
  data: T;
24
24
  };
25
25
 
26
- export type SerializedError = {
27
- code?: string;
28
- message?: string;
29
- context?: Record<string, unknown>;
30
- stack?: string;
31
- cause?: SerializedError;
32
- };
26
+ const _SerializedError = Schema.Struct({
27
+ name: Schema.optional(Schema.String),
28
+ message: Schema.optional(Schema.String),
29
+ context: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
30
+ stack: Schema.optional(Schema.String),
31
+ cause: Schema.optional(Schema.suspend(() => SerializedError)),
32
+ });
33
+ export interface SerializedError extends Schema.Schema.Type<typeof _SerializedError> {}
34
+ export const SerializedError: Schema.Schema<SerializedError, SerializedError, never> = _SerializedError;
33
35
 
34
36
  export type EdgeErrorData = { type: string } & Record<string, any>;
35
37
 
@@ -45,11 +47,11 @@ export type EdgeFailure = {
45
47
  /**
46
48
  * An explanation of why the call failed. Used mostly for logging and monitoring.
47
49
  */
48
- reason: string;
50
+ message: string;
49
51
  /**
50
52
  * Cause Error captured on the EDGE service to aid debugging on the client.
51
53
  */
52
- cause?: SerializedError;
54
+ error?: SerializedError;
53
55
  /**
54
56
  * Information that can be used to retry the request such that it will succeed, for example:
55
57
  * 1. { type: 'auth_required', challenge: string }
@@ -57,16 +59,16 @@ export type EdgeFailure = {
57
59
  * 2. { type: 'user_confirmation_required', dialog: { title: string, message: string, confirmation_payload: string } }
58
60
  * Requires showing a confirmation dialog to a user and retrying the request with confirmation_payload included
59
61
  * if the user confirms.
60
- * When errorData is returned simply retrying the request won't have any effect.
61
- * EdgeHttpClient should parse well-known errorData into Error types and throw.
62
+ * When data is returned simply retrying the request won't have any effect.
63
+ * EdgeHttpClient should parse well-known data into Error types and throw.
62
64
  */
63
- errorData?: EdgeErrorData;
65
+ data?: EdgeErrorData;
64
66
  };
65
67
 
66
68
  /**
67
69
  * Represents a body response from the Edge service.
68
70
  */
69
- export type EdgeBody<T> = EdgeSuccess<T> | EdgeFailure;
71
+ export type EdgeEnvelope<T> = EdgeSuccess<T> | EdgeFailure;
70
72
 
71
73
  /**
72
74
  * Use this to create a response from the Edge service.
@@ -87,21 +89,32 @@ export const EdgeResponse = Object.freeze({
87
89
  );
88
90
  },
89
91
  failure: ({
90
- reason,
91
- cause,
92
- errorData,
92
+ message,
93
+ error,
94
+ errorEncoded,
95
+ data,
93
96
  shouldRetryAfter,
94
97
  status = 500,
95
98
  }: {
96
99
  /**
97
100
  * An explanation of why the call failed. Used mostly for logging and monitoring.
98
101
  */
99
- reason: string;
102
+ message: string;
100
103
  /**
101
104
  * Error that caused the failure.
102
105
  * Useful for debugging.
106
+ *
107
+ * Use only one of the fields `error` or `errorEncoded`.s
103
108
  */
104
- cause?: Error;
109
+ error?: Error;
110
+ /**
111
+ * Encoded Error that caused the failure.
112
+ * Useful for debugging.
113
+ *
114
+ * Use only one of the fields `error` or `errorEncoded`.
115
+ */
116
+ errorEncoded?: SerializedError;
117
+
105
118
  /**
106
119
  * Information that can be used to retry the request such that it will succeed, for example:
107
120
  * 1. { type: 'auth_required', challenge: string }
@@ -109,10 +122,10 @@ export const EdgeResponse = Object.freeze({
109
122
  * 2. { type: 'user_confirmation_required', dialog: { title: string, message: string, confirmation_payload: string } }
110
123
  * Requires showing a confirmation dialog to a user and retrying the request with confirmation_payload included
111
124
  * if the user confirms.
112
- * When errorData is returned simply retrying the request won't have any effect.
113
- * EdgeHttpClient should parse well-known errorData into Error types and throw.
125
+ * When data is returned simply retrying the request won't have any effect.
126
+ * EdgeHttpClient should parse well-known data into Error types and throw.
114
127
  */
115
- errorData?: EdgeErrorData;
128
+ data?: EdgeErrorData;
116
129
  /**
117
130
  * If provided, this request will be marked as retryable and the client will wait for the specified number of milliseconds before retrying.
118
131
  * If not provided, the client will not retry the request.
@@ -133,9 +146,9 @@ export const EdgeResponse = Object.freeze({
133
146
  return new Response(
134
147
  JSON.stringify({
135
148
  success: false,
136
- reason,
137
- errorData,
138
- cause: cause ? ErrorCodec.encode(cause) : undefined,
149
+ message,
150
+ data,
151
+ error: error ? ErrorCodec.encode(error) : errorEncoded,
139
152
  } satisfies EdgeFailure),
140
153
  {
141
154
  status,
@@ -222,8 +235,25 @@ export type UploadFunctionRequest = {
222
235
  ownerPublicKey: string;
223
236
  entryPoint: string;
224
237
  assets: Record<string, Uint8Array>;
238
+ /**
239
+ * Runtime in Edge that will be used to run the function.
240
+ * Runtime cannot be changed once the function was deployed.
241
+ * @default Runtime.WORKERS_FOR_PLATFORMS
242
+ */
243
+ runtime?: FunctionRuntimeKind;
225
244
  };
226
245
 
246
+ /**
247
+ * Note: Do not change the values of these enums, this values are stored in the FunctionVersions database.
248
+ */
249
+ export const FunctionRuntimeKind = Schema.Enums({
250
+ // https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
251
+ WORKERS_FOR_PLATFORMS: 'WORKERS_FOR_PLATFORMS',
252
+ // https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/
253
+ WORKER_LOADER: 'WORKER_LOADER',
254
+ });
255
+ export type FunctionRuntimeKind = Schema.Schema.Type<typeof FunctionRuntimeKind>;
256
+
227
257
  export type UploadFunctionResponseBody = {
228
258
  functionId: string;
229
259
  version: string;
@@ -385,15 +415,15 @@ const MAX_ERROR_DEPTH = 3;
385
415
  */
386
416
  export const ErrorCodec = Object.freeze({
387
417
  encode: (err: Error, depth: number = 0): SerializedError => ({
388
- code: 'code' in err ? (err as any).code : undefined,
418
+ name: 'name' in err ? err.name : (err as any).code || 'Error',
389
419
  message: err.message,
390
420
  stack: err.stack,
391
421
  cause: err.cause instanceof Error && depth < MAX_ERROR_DEPTH ? ErrorCodec.encode(err.cause, depth + 1) : undefined,
392
422
  }),
393
423
  decode: (serializedError: SerializedError, depth: number = 0): Error => {
394
424
  let err: Error;
395
- if (typeof serializedError.code === 'string') {
396
- err = new BaseError(serializedError.code, {
425
+ if (typeof serializedError.name === 'string') {
426
+ err = new BaseError(serializedError.name, {
397
427
  message: serializedError.message ?? 'Unknown error',
398
428
  cause:
399
429
  serializedError.cause && depth < MAX_ERROR_DEPTH
@@ -16,11 +16,11 @@ import { type EdgeErrorData, type EdgeFailure, EdgeHttpErrorCodec, ErrorCodec }
16
16
  export class EdgeCallFailedError extends Error {
17
17
  public static fromUnsuccessfulResponse(response: Response, body: EdgeFailure): EdgeCallFailedError {
18
18
  const error = new EdgeCallFailedError({
19
- reason: body.reason,
20
- errorData: body.errorData,
21
- isRetryable: body.errorData == null && response.headers.has('Retry-After'),
19
+ message: body.message,
20
+ data: body.data,
21
+ isRetryable: body.data == null && response.headers.has('Retry-After'),
22
22
  retryAfterMs: getRetryAfterMillis(response),
23
- cause: body.cause ? ErrorCodec.decode(body.cause) : undefined,
23
+ cause: body.error ? ErrorCodec.decode(body.error) : undefined,
24
24
  });
25
25
 
26
26
  return error;
@@ -28,7 +28,7 @@ export class EdgeCallFailedError extends Error {
28
28
 
29
29
  public static async fromHttpFailure(response: Response): Promise<EdgeCallFailedError> {
30
30
  return new EdgeCallFailedError({
31
- reason: `HTTP code ${response.status}: ${response.statusText}.`,
31
+ message: `HTTP code ${response.status}: ${response.statusText}.`,
32
32
  isRetryable: isRetryableCode(response.status),
33
33
  retryAfterMs: getRetryAfterMillis(response),
34
34
  cause: await EdgeHttpErrorCodec.decode(response),
@@ -37,27 +37,26 @@ export class EdgeCallFailedError extends Error {
37
37
 
38
38
  public static fromProcessingFailureCause(cause: Error): EdgeCallFailedError {
39
39
  return new EdgeCallFailedError({
40
- reason: 'Error processing request.',
40
+ message: 'Error processing request.',
41
41
  isRetryable: true,
42
42
  cause,
43
43
  });
44
44
  }
45
45
 
46
- readonly reason: string;
47
- readonly errorData?: EdgeErrorData;
46
+ readonly data?: EdgeErrorData;
48
47
  readonly isRetryable?: boolean;
49
48
  readonly retryAfterMs?: number;
50
49
 
51
50
  constructor(args: {
52
- reason: string;
51
+ message: string;
53
52
  isRetryable?: boolean;
54
- errorData?: EdgeErrorData;
53
+ data?: EdgeErrorData;
55
54
  retryAfterMs?: number;
56
55
  cause?: Error;
57
56
  }) {
58
- super(args.reason, { cause: args.cause });
59
- this.reason = args.reason;
60
- this.errorData = args.errorData;
57
+ super(args.message, { cause: args.cause });
58
+ this.message = args.message;
59
+ this.data = args.data;
61
60
  this.retryAfterMs = args.retryAfterMs;
62
61
  this.isRetryable = Boolean(args.isRetryable);
63
62
  }
@@ -66,9 +65,9 @@ export class EdgeCallFailedError extends Error {
66
65
  export class EdgeAuthChallengeError extends EdgeCallFailedError {
67
66
  constructor(
68
67
  public readonly challenge: string,
69
- errorData: EdgeErrorData,
68
+ data: EdgeErrorData,
70
69
  ) {
71
- super({ reason: 'Auth challenge.', errorData, isRetryable: false });
70
+ super({ message: 'Auth challenge.', data, isRetryable: false });
72
71
  }
73
72
  }
74
73
 
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './edge.js';
6
+ export * as EdgeFunctionEnv from './EdgeFunctionEnv.js';
7
+ export * from './errors.js';
@@ -2,43 +2,25 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- // TODO(dmaretskyi): Reconcile with @dxos/errors
6
-
7
5
  /**
8
6
  * NOTE: Messages should be sentences (Start with a capital letter and end with a period).
9
7
  * Errors can optionally include a JSON context object.
10
8
  */
11
- export class BaseError extends Error {
12
- constructor(
13
- readonly code: string,
14
- message?: string,
15
- readonly context?: Record<string, any>,
16
- ) {
17
- // TODO(dmaretskyi): Error.cause.
18
- super(message ?? code);
19
- this.name = code;
20
- // NOTE: Restores prototype chain (https://stackoverflow.com/a/48342359).
21
- Object.setPrototypeOf(this, new.target.prototype);
22
- }
23
- }
24
-
25
- // TODO(dmaretskyi): Consider common error classes with error codes:
26
- // throw new SystemError(ERROR_CODE_OUT_OF_MEMORY, 'Out of memory', { a: 1, b: 2 });
9
+ import { BaseError } from '@dxos/errors';
27
10
 
28
11
  /**
29
12
  * User facing API Errors.
30
13
  * E.g., something was misconfigured.
31
14
  */
32
- export class ApiError extends BaseError {}
15
+ export class ApiError extends BaseError.extend('ApiError') {}
33
16
 
34
17
  /**
35
18
  * Internal system errors.
36
19
  * E.g., unexpected/unrecoverable runtime error.
37
20
  */
38
- export class SystemError extends BaseError {}
21
+ export class SystemError extends BaseError.extend('SystemError') {}
39
22
 
40
23
  /**
41
24
  * Database errors.
42
25
  */
43
- // TODO(wittjosiah): Same as ApiError?
44
- export class DatabaseError extends BaseError {}
26
+ export class DatabaseError extends BaseError.extend('DatabaseError') {}
@@ -9,7 +9,7 @@ import { ApiError } from './base-errors.js';
9
9
  describe('Errors', () => {
10
10
  test('test', async () => {
11
11
  const runTest = async () => {
12
- throw new ApiError('Test error');
12
+ throw new ApiError({ message: 'Test error' });
13
13
  };
14
14
 
15
15
  await expect(runTest()).rejects.toThrowError('Test error');