@dxos/protocols 0.8.4-main.e8ec1fe → 0.8.4-main.ef1bc66f44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/FeedProtocol.d.ts +528 -0
- package/dist/src/FeedProtocol.d.ts.map +1 -0
- package/dist/src/FeedProtocol.js +237 -0
- package/dist/src/FeedProtocol.js.map +1 -0
- package/dist/src/FunctionProtocol.d.ts +8 -2
- package/dist/src/FunctionProtocol.d.ts.map +1 -1
- package/dist/src/buf/proto/gen/dxos/client/queue_pb.d.ts +189 -0
- package/dist/src/buf/proto/gen/dxos/client/queue_pb.d.ts.map +1 -0
- package/dist/src/buf/proto/gen/dxos/client/queue_pb.js +39 -0
- package/dist/src/buf/proto/gen/dxos/client/queue_pb.js.map +1 -0
- package/dist/src/buf/proto/gen/dxos/client/services_pb.d.ts +5 -1
- package/dist/src/buf/proto/gen/dxos/client/services_pb.d.ts.map +1 -1
- package/dist/src/buf/proto/gen/dxos/client/services_pb.js +5 -1
- package/dist/src/buf/proto/gen/dxos/client/services_pb.js.map +1 -1
- package/dist/src/buf/proto/gen/dxos/config_pb.d.ts +4 -0
- package/dist/src/buf/proto/gen/dxos/config_pb.d.ts.map +1 -1
- package/dist/src/buf/proto/gen/dxos/config_pb.js +1 -1
- package/dist/src/buf/proto/gen/dxos/config_pb.js.map +1 -1
- package/dist/src/buf/proto/gen/dxos/echo/query_pb.d.ts +12 -2
- package/dist/src/buf/proto/gen/dxos/echo/query_pb.d.ts.map +1 -1
- package/dist/src/buf/proto/gen/dxos/echo/query_pb.js +1 -1
- package/dist/src/buf/proto/gen/dxos/echo/query_pb.js.map +1 -1
- package/dist/src/buf/proto/gen/dxos/echo/service_pb.d.ts +55 -9
- package/dist/src/buf/proto/gen/dxos/echo/service_pb.d.ts.map +1 -1
- package/dist/src/buf/proto/gen/dxos/echo/service_pb.js +15 -5
- package/dist/src/buf/proto/gen/dxos/echo/service_pb.js.map +1 -1
- package/dist/src/buf/proto/gen/dxos/google_pb.js +1 -1
- package/dist/src/buf/proto/gen/dxos/google_pb.js.map +1 -1
- package/dist/src/buf/proto/gen/dxos/iframe_pb.d.ts +1 -0
- package/dist/src/buf/proto/gen/dxos/iframe_pb.d.ts.map +1 -1
- package/dist/src/buf/proto/gen/dxos/iframe_pb.js.map +1 -1
- package/dist/src/buf/proto/gen/dxos/tracing_pb.js +1 -1
- package/dist/src/buf/proto/gen/dxos/tracing_pb.js.map +1 -1
- package/dist/src/codec.test.js +1 -1
- package/dist/src/edge/EdgeFunctionEnv.d.ts +120 -0
- package/dist/src/edge/EdgeFunctionEnv.d.ts.map +1 -0
- package/dist/src/edge/EdgeFunctionEnv.js +4 -0
- package/dist/src/edge/EdgeFunctionEnv.js.map +1 -0
- package/dist/src/{edge.d.ts → edge/edge.d.ts} +46 -26
- package/dist/src/edge/edge.d.ts.map +1 -0
- package/dist/src/{edge.js → edge/edge.js} +28 -14
- package/dist/src/edge/edge.js.map +1 -0
- package/dist/src/{edge-error.d.ts → edge/errors.d.ts} +6 -7
- package/dist/src/edge/errors.d.ts.map +1 -0
- package/dist/src/{edge-error.js → edge/errors.js} +14 -15
- package/dist/src/edge/errors.js.map +1 -0
- package/dist/src/edge/index.d.ts +4 -0
- package/dist/src/edge/index.d.ts.map +1 -0
- package/dist/src/edge/index.js +7 -0
- package/dist/src/edge/index.js.map +1 -0
- package/dist/src/errors/base-errors.d.ts +86 -8
- package/dist/src/errors/base-errors.d.ts.map +1 -1
- package/dist/src/errors/base-errors.js +4 -20
- package/dist/src/errors/base-errors.js.map +1 -1
- package/dist/src/errors/encoding.d.ts +2 -2
- package/dist/src/errors/encoding.d.ts.map +1 -1
- package/dist/src/errors/encoding.js +1 -1
- package/dist/src/errors/errors.d.ts +619 -42
- package/dist/src/errors/errors.d.ts.map +1 -1
- package/dist/src/errors/errors.js +50 -104
- package/dist/src/errors/errors.js.map +1 -1
- package/dist/src/errors/errors.test.js +2 -2
- package/dist/src/errors/errors.test.js.map +1 -1
- package/dist/src/errors/helpers.d.ts +9 -5
- package/dist/src/errors/helpers.d.ts.map +1 -1
- package/dist/src/errors/helpers.js +3 -3
- package/dist/src/errors/helpers.js.map +1 -1
- package/dist/src/errors/index.d.ts +5 -5
- package/dist/src/errors/index.js +5 -5
- package/dist/src/feed-replication.d.ts.map +1 -1
- package/dist/src/index.d.ts +12 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/indexing.test.js +1 -1
- package/dist/src/messenger.d.ts +16 -0
- package/dist/src/messenger.d.ts.map +1 -0
- package/dist/src/messenger.js +4 -0
- package/dist/src/messenger.js.map +1 -0
- package/dist/src/proto/gen/dxos/client/services.d.ts +105 -1
- package/dist/src/proto/gen/dxos/client/services.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/client/services.js +1 -0
- package/dist/src/proto/gen/dxos/client/services.js.map +1 -1
- package/dist/src/proto/gen/dxos/config.d.ts +5 -0
- package/dist/src/proto/gen/dxos/config.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/config.js.map +1 -1
- package/dist/src/proto/gen/dxos/echo/query.d.ts +17 -1
- package/dist/src/proto/gen/dxos/echo/query.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/echo/query.js.map +1 -1
- package/dist/src/proto/gen/dxos/echo/service.d.ts +34 -8
- package/dist/src/proto/gen/dxos/echo/service.d.ts.map +1 -1
- package/dist/src/proto/gen/index.d.ts +8 -0
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/src/proto/index.d.ts +2 -2
- package/dist/src/proto/index.js +1 -1
- package/dist/src/proto/types.d.ts +1 -1
- package/dist/src/types.d.ts +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -15
- package/src/FeedProtocol.ts +319 -0
- package/src/FunctionProtocol.ts +8 -4
- package/src/buf/proto/gen/dxos/agent/dashboard_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/agent/echo-proxy_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/agent/epoch_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/agent/functions_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/bot_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/client/invitation_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/client/logging_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/client/queue_pb.ts +231 -0
- package/src/buf/proto/gen/dxos/client/services_pb.ts +7 -2
- package/src/buf/proto/gen/dxos/config_pb.ts +7 -2
- package/src/buf/proto/gen/dxos/devtools/diagnostics_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/devtools/host_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/devtools/swarm_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/blob_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/feed_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/filter_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/indexing_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/metadata_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/model/document_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/model/messenger_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/model/text_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/object_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/query_pb.ts +16 -4
- package/src/buf/proto/gen/dxos/echo/service_pb.ts +68 -16
- package/src/buf/proto/gen/dxos/echo/snapshot_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/echo/timeframe_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/edge/calls_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/edge/messenger_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/edge/signal_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/error_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/field_options_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/google_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/gravity_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/credentials/auth_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/credentials/greet_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/credentials/identity_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/credentials_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/invitations_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/keyring_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/keys_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/halo/signed_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/iframe_pb.ts +2 -1
- package/src/buf/proto/gen/dxos/keys_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/bridge_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/broadcast_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/messaging_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/muxer_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/presence_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/protocol_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/replicator_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/signal_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/swarm_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/admission-discovery_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/auth_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/automerge_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/blobsync_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/control_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/gossip_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/notarization_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/mesh/teleport/replicator_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/registry_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/rpc_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/service/agentmanager_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/service/publisher_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/service/supervisor_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/service/tunnel_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/tracing_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/type_pb.ts +1 -1
- package/src/buf/proto/gen/dxos/value_pb.ts +1 -1
- package/src/buf/proto/gen/example/testing/data_pb.ts +1 -1
- package/src/buf/proto/gen/example/testing/rpc_pb.ts +1 -1
- package/src/codec.test.ts +1 -1
- package/src/edge/EdgeFunctionEnv.ts +193 -0
- package/src/{edge.ts → edge/edge.ts} +55 -39
- package/src/{edge-error.ts → edge/errors.ts} +15 -16
- package/src/edge/index.ts +7 -0
- package/src/errors/base-errors.ts +4 -22
- package/src/errors/encoding.ts +2 -2
- package/src/errors/errors.test.ts +2 -2
- package/src/errors/errors.ts +57 -123
- package/src/errors/helpers.ts +6 -7
- package/src/errors/index.ts +5 -5
- package/src/feed-replication.ts +1 -0
- package/src/index.ts +12 -13
- package/src/indexing.test.ts +1 -1
- package/src/messenger.ts +22 -0
- package/src/proto/dxos/client/queue.proto +67 -0
- package/src/proto/dxos/client/services.proto +1 -0
- package/src/proto/dxos/config.proto +2 -0
- package/src/proto/dxos/echo/query.proto +4 -1
- package/src/proto/dxos/echo/service.proto +27 -6
- package/src/proto/dxos/iframe.proto +1 -0
- package/src/proto/gen/dxos/client/services.ts +105 -1
- package/src/proto/gen/dxos/config.ts +5 -0
- package/src/proto/gen/dxos/echo/query.ts +17 -1
- package/src/proto/gen/dxos/echo/service.ts +33 -8
- package/src/proto/gen/index.ts +9 -1
- package/src/proto/index.ts +2 -2
- package/src/proto/types.ts +1 -1
- package/src/types.ts +2 -2
- package/dist/src/edge-error.d.ts.map +0 -1
- package/dist/src/edge-error.js.map +0 -1
- package/dist/src/edge.d.ts.map +0 -1
- package/dist/src/edge.js.map +0 -1
- package/dist/src/query.d.ts +0 -5
- package/dist/src/query.d.ts.map +0 -1
- package/dist/src/query.js +0 -8
- package/dist/src/query.js.map +0 -1
- package/dist/src/queue.d.ts +0 -37
- package/dist/src/queue.d.ts.map +0 -1
- package/dist/src/queue.js +0 -8
- package/dist/src/queue.js.map +0 -1
- package/src/query.ts +0 -8
- package/src/queue.ts +0 -51
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
// @generated by protoc-gen-es v2.
|
|
5
|
+
// @generated by protoc-gen-es v2.11.0 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
|
|
package/src/codec.test.ts
CHANGED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type SpaceId } from '@dxos/keys';
|
|
6
|
+
|
|
7
|
+
import { type QueryResult, type QueueQuery } from '../FeedProtocol';
|
|
8
|
+
import { type CreateDocumentRequest, type CreateDocumentResponse } from '../proto/gen/dxos/echo/service';
|
|
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;
|
|
@@ -12,7 +12,16 @@ import { SpaceId } from '@dxos/keys';
|
|
|
12
12
|
// If we would rename it, we need to be careful to not break composer production.
|
|
13
13
|
export enum EdgeService {
|
|
14
14
|
AUTOMERGE_REPLICATOR = 'automerge-replicator',
|
|
15
|
+
/**
|
|
16
|
+
* Control feed replicator (hypercore append only logs) for the space.
|
|
17
|
+
*/
|
|
18
|
+
// TODO(mykola): Remove once we migrate to keyhive for access control.
|
|
15
19
|
FEED_REPLICATOR = 'feed-replicator',
|
|
20
|
+
/**
|
|
21
|
+
* Feed replicator (ordered data list) for the space.
|
|
22
|
+
*/
|
|
23
|
+
// TODO(mykola): Rename to FEED_REPLICATOR when we migrate to keyhive for access control.
|
|
24
|
+
QUEUE_REPLICATOR = 'queue-replicator',
|
|
16
25
|
SWARM = 'swarm',
|
|
17
26
|
SIGNAL = 'signal',
|
|
18
27
|
STATUS = 'status',
|
|
@@ -23,13 +32,15 @@ export type EdgeSuccess<T> = {
|
|
|
23
32
|
data: T;
|
|
24
33
|
};
|
|
25
34
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
message
|
|
29
|
-
context
|
|
30
|
-
stack
|
|
31
|
-
cause
|
|
32
|
-
};
|
|
35
|
+
const _SerializedError = Schema.Struct({
|
|
36
|
+
name: Schema.optional(Schema.String),
|
|
37
|
+
message: Schema.optional(Schema.String),
|
|
38
|
+
context: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
39
|
+
stack: Schema.optional(Schema.String),
|
|
40
|
+
cause: Schema.optional(Schema.suspend(() => SerializedError)),
|
|
41
|
+
});
|
|
42
|
+
export interface SerializedError extends Schema.Schema.Type<typeof _SerializedError> {}
|
|
43
|
+
export const SerializedError: Schema.Schema<SerializedError, SerializedError, never> = _SerializedError;
|
|
33
44
|
|
|
34
45
|
export type EdgeErrorData = { type: string } & Record<string, any>;
|
|
35
46
|
|
|
@@ -37,11 +48,6 @@ export type EdgeErrorData = { type: string } & Record<string, any>;
|
|
|
37
48
|
* This is the shape of the error response from the Edge service,
|
|
38
49
|
* when the error is gracefully handled, the Response will be an object with this shape and have status code 200.
|
|
39
50
|
*/
|
|
40
|
-
// TODO(dmaretskyi): Refactor this type to just be { success: false, error: SerializedError }
|
|
41
|
-
// reason -> error.message
|
|
42
|
-
// cause -> error.cause
|
|
43
|
-
// errorData.type -> error.code
|
|
44
|
-
// ...errorData -> error.context
|
|
45
51
|
export type EdgeFailure = {
|
|
46
52
|
/**
|
|
47
53
|
* Branded Type.
|
|
@@ -50,11 +56,11 @@ export type EdgeFailure = {
|
|
|
50
56
|
/**
|
|
51
57
|
* An explanation of why the call failed. Used mostly for logging and monitoring.
|
|
52
58
|
*/
|
|
53
|
-
|
|
59
|
+
message: string;
|
|
54
60
|
/**
|
|
55
61
|
* Cause Error captured on the EDGE service to aid debugging on the client.
|
|
56
62
|
*/
|
|
57
|
-
|
|
63
|
+
error?: SerializedError;
|
|
58
64
|
/**
|
|
59
65
|
* Information that can be used to retry the request such that it will succeed, for example:
|
|
60
66
|
* 1. { type: 'auth_required', challenge: string }
|
|
@@ -62,16 +68,16 @@ export type EdgeFailure = {
|
|
|
62
68
|
* 2. { type: 'user_confirmation_required', dialog: { title: string, message: string, confirmation_payload: string } }
|
|
63
69
|
* Requires showing a confirmation dialog to a user and retrying the request with confirmation_payload included
|
|
64
70
|
* if the user confirms.
|
|
65
|
-
* When
|
|
66
|
-
* EdgeHttpClient should parse well-known
|
|
71
|
+
* When data is returned simply retrying the request won't have any effect.
|
|
72
|
+
* EdgeHttpClient should parse well-known data into Error types and throw.
|
|
67
73
|
*/
|
|
68
|
-
|
|
74
|
+
data?: EdgeErrorData;
|
|
69
75
|
};
|
|
70
76
|
|
|
71
77
|
/**
|
|
72
78
|
* Represents a body response from the Edge service.
|
|
73
79
|
*/
|
|
74
|
-
export type
|
|
80
|
+
export type EdgeEnvelope<T> = EdgeSuccess<T> | EdgeFailure;
|
|
75
81
|
|
|
76
82
|
/**
|
|
77
83
|
* Use this to create a response from the Edge service.
|
|
@@ -92,21 +98,32 @@ export const EdgeResponse = Object.freeze({
|
|
|
92
98
|
);
|
|
93
99
|
},
|
|
94
100
|
failure: ({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
message,
|
|
102
|
+
error,
|
|
103
|
+
errorEncoded,
|
|
104
|
+
data,
|
|
98
105
|
shouldRetryAfter,
|
|
99
106
|
status = 500,
|
|
100
107
|
}: {
|
|
101
108
|
/**
|
|
102
109
|
* An explanation of why the call failed. Used mostly for logging and monitoring.
|
|
103
110
|
*/
|
|
104
|
-
|
|
111
|
+
message: string;
|
|
105
112
|
/**
|
|
106
113
|
* Error that caused the failure.
|
|
107
114
|
* Useful for debugging.
|
|
115
|
+
*
|
|
116
|
+
* Use only one of the fields `error` or `errorEncoded`.s
|
|
108
117
|
*/
|
|
109
|
-
|
|
118
|
+
error?: Error;
|
|
119
|
+
/**
|
|
120
|
+
* Encoded Error that caused the failure.
|
|
121
|
+
* Useful for debugging.
|
|
122
|
+
*
|
|
123
|
+
* Use only one of the fields `error` or `errorEncoded`.
|
|
124
|
+
*/
|
|
125
|
+
errorEncoded?: SerializedError;
|
|
126
|
+
|
|
110
127
|
/**
|
|
111
128
|
* Information that can be used to retry the request such that it will succeed, for example:
|
|
112
129
|
* 1. { type: 'auth_required', challenge: string }
|
|
@@ -114,10 +131,10 @@ export const EdgeResponse = Object.freeze({
|
|
|
114
131
|
* 2. { type: 'user_confirmation_required', dialog: { title: string, message: string, confirmation_payload: string } }
|
|
115
132
|
* Requires showing a confirmation dialog to a user and retrying the request with confirmation_payload included
|
|
116
133
|
* if the user confirms.
|
|
117
|
-
* When
|
|
118
|
-
* EdgeHttpClient should parse well-known
|
|
134
|
+
* When data is returned simply retrying the request won't have any effect.
|
|
135
|
+
* EdgeHttpClient should parse well-known data into Error types and throw.
|
|
119
136
|
*/
|
|
120
|
-
|
|
137
|
+
data?: EdgeErrorData;
|
|
121
138
|
/**
|
|
122
139
|
* If provided, this request will be marked as retryable and the client will wait for the specified number of milliseconds before retrying.
|
|
123
140
|
* If not provided, the client will not retry the request.
|
|
@@ -138,9 +155,9 @@ export const EdgeResponse = Object.freeze({
|
|
|
138
155
|
return new Response(
|
|
139
156
|
JSON.stringify({
|
|
140
157
|
success: false,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
158
|
+
message,
|
|
159
|
+
data,
|
|
160
|
+
error: error ? ErrorCodec.encode(error) : errorEncoded,
|
|
144
161
|
} satisfies EdgeFailure),
|
|
145
162
|
{
|
|
146
163
|
status,
|
|
@@ -232,20 +249,19 @@ export type UploadFunctionRequest = {
|
|
|
232
249
|
* Runtime cannot be changed once the function was deployed.
|
|
233
250
|
* @default Runtime.WORKERS_FOR_PLATFORMS
|
|
234
251
|
*/
|
|
235
|
-
runtime?:
|
|
252
|
+
runtime?: FunctionRuntimeKind;
|
|
236
253
|
};
|
|
237
254
|
|
|
238
255
|
/**
|
|
239
256
|
* Note: Do not change the values of these enums, this values are stored in the FunctionVersions database.
|
|
240
257
|
*/
|
|
241
|
-
export
|
|
258
|
+
export const FunctionRuntimeKind = Schema.Enums({
|
|
242
259
|
// https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/
|
|
243
|
-
WORKERS_FOR_PLATFORMS
|
|
260
|
+
WORKERS_FOR_PLATFORMS: 'WORKERS_FOR_PLATFORMS',
|
|
244
261
|
// https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/
|
|
245
|
-
WORKER_LOADER
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
262
|
+
WORKER_LOADER: 'WORKER_LOADER',
|
|
263
|
+
});
|
|
264
|
+
export type FunctionRuntimeKind = Schema.Schema.Type<typeof FunctionRuntimeKind>;
|
|
249
265
|
|
|
250
266
|
export type UploadFunctionResponseBody = {
|
|
251
267
|
functionId: string;
|
|
@@ -408,15 +424,15 @@ const MAX_ERROR_DEPTH = 3;
|
|
|
408
424
|
*/
|
|
409
425
|
export const ErrorCodec = Object.freeze({
|
|
410
426
|
encode: (err: Error, depth: number = 0): SerializedError => ({
|
|
411
|
-
|
|
427
|
+
name: 'name' in err ? err.name : (err as any).code || 'Error',
|
|
412
428
|
message: err.message,
|
|
413
429
|
stack: err.stack,
|
|
414
430
|
cause: err.cause instanceof Error && depth < MAX_ERROR_DEPTH ? ErrorCodec.encode(err.cause, depth + 1) : undefined,
|
|
415
431
|
}),
|
|
416
432
|
decode: (serializedError: SerializedError, depth: number = 0): Error => {
|
|
417
433
|
let err: Error;
|
|
418
|
-
if (typeof serializedError.
|
|
419
|
-
err = new BaseError(serializedError.
|
|
434
|
+
if (typeof serializedError.name === 'string') {
|
|
435
|
+
err = new BaseError(serializedError.name, {
|
|
420
436
|
message: serializedError.message ?? 'Unknown error',
|
|
421
437
|
cause:
|
|
422
438
|
serializedError.cause && depth < MAX_ERROR_DEPTH
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type EdgeErrorData, type EdgeFailure, EdgeHttpErrorCodec, ErrorCodec } from './edge.
|
|
5
|
+
import { type EdgeErrorData, type EdgeFailure, EdgeHttpErrorCodec, ErrorCodec } from './edge.ts';
|
|
6
6
|
|
|
7
7
|
// TODO(burdon): Reconcile with @dxos/errors.
|
|
8
8
|
/**
|
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
isRetryable: body.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
40
|
+
message: 'Error processing request.',
|
|
41
41
|
isRetryable: true,
|
|
42
42
|
cause,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
readonly
|
|
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
|
-
|
|
51
|
+
message: string;
|
|
53
52
|
isRetryable?: boolean;
|
|
54
|
-
|
|
53
|
+
data?: EdgeErrorData;
|
|
55
54
|
retryAfterMs?: number;
|
|
56
55
|
cause?: Error;
|
|
57
56
|
}) {
|
|
58
|
-
super(args.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
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
|
-
|
|
68
|
+
data: EdgeErrorData,
|
|
70
69
|
) {
|
|
71
|
-
super({
|
|
70
|
+
super({ message: 'Auth challenge.', data, isRetryable: false });
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
|
|
@@ -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
|
-
|
|
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
|
-
|
|
44
|
-
export class DatabaseError extends BaseError {}
|
|
26
|
+
export class DatabaseError extends BaseError.extend('DatabaseError') {}
|
package/src/errors/encoding.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Error as SerializedErrorProto } from '../proto/gen/dxos/error.
|
|
5
|
+
import { type Error as SerializedErrorProto } from '../proto/gen/dxos/error.ts';
|
|
6
6
|
|
|
7
|
-
import { reconstructError } from './helpers.
|
|
7
|
+
import { reconstructError } from './helpers.ts';
|
|
8
8
|
|
|
9
9
|
export const encodeError = (err: any): SerializedErrorProto => {
|
|
10
10
|
if (typeof err === 'object' && err?.message) {
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { ApiError } from './base-errors.
|
|
7
|
+
import { ApiError } from './base-errors.ts';
|
|
8
8
|
|
|
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');
|