@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.
- package/dist/src/FunctionProtocol.d.ts +82 -0
- package/dist/src/FunctionProtocol.d.ts.map +1 -0
- package/dist/src/FunctionProtocol.js +4 -0
- package/dist/src/FunctionProtocol.js.map +1 -0
- 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/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/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} +47 -20
- package/dist/src/edge/edge.d.ts.map +1 -0
- package/dist/src/{edge.js → edge/edge.js} +24 -7
- package/dist/src/edge/edge.js.map +1 -0
- package/dist/src/{edge-error.d.ts → edge/errors.d.ts} +5 -6
- package/dist/src/edge/errors.d.ts.map +1 -0
- package/dist/src/{edge-error.js → edge/errors.js} +13 -14
- 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 +1 -1
- package/dist/src/errors/encoding.d.ts.map +1 -1
- package/dist/src/errors/errors.d.ts +618 -41
- package/dist/src/errors/errors.d.ts.map +1 -1
- package/dist/src/errors/errors.js +49 -103
- package/dist/src/errors/errors.js.map +1 -1
- package/dist/src/errors/errors.test.js +1 -1
- package/dist/src/errors/errors.test.js.map +1 -1
- package/dist/src/errors/helpers.d.ts +8 -4
- 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/feed-replication.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/index.js.map +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 +103 -0
- package/dist/src/proto/gen/dxos/client/services.d.ts.map +1 -1
- 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/queue.d.ts +1 -26
- package/dist/src/queue.d.ts.map +1 -1
- package/dist/src/queue.js +1 -4
- package/dist/src/queue.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -15
- package/src/FunctionProtocol.ts +104 -0
- 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 +1 -1
- 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/edge/EdgeFunctionEnv.ts +193 -0
- package/src/{edge.ts → edge/edge.ts} +57 -27
- package/src/{edge-error.ts → edge/errors.ts} +14 -15
- package/src/edge/index.ts +7 -0
- package/src/errors/base-errors.ts +4 -22
- package/src/errors/errors.test.ts +1 -1
- package/src/errors/errors.ts +55 -121
- package/src/errors/helpers.ts +5 -6
- package/src/feed-replication.ts +1 -0
- package/src/index.ts +5 -3
- package/src/messenger.ts +22 -0
- package/src/proto/dxos/client/queue.proto +67 -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 +103 -0
- 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/queue.ts +9 -33
- 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/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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
message
|
|
29
|
-
context
|
|
30
|
-
stack
|
|
31
|
-
cause
|
|
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
|
-
|
|
50
|
+
message: string;
|
|
49
51
|
/**
|
|
50
52
|
* Cause Error captured on the EDGE service to aid debugging on the client.
|
|
51
53
|
*/
|
|
52
|
-
|
|
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
|
|
61
|
-
* EdgeHttpClient should parse well-known
|
|
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
|
-
|
|
65
|
+
data?: EdgeErrorData;
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* Represents a body response from the Edge service.
|
|
68
70
|
*/
|
|
69
|
-
export type
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
113
|
-
* EdgeHttpClient should parse well-known
|
|
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
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
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.
|
|
396
|
-
err = new BaseError(serializedError.
|
|
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
|
-
|
|
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') {}
|
|
@@ -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');
|