axiodb 20.3.2 → 20.3.3
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/package.json +1 -1
- package/.graphifyignore +0 -12
- package/cli/VERSION +0 -1
- package/cli/cmd/auth_management.go +0 -68
- package/cli/cmd/collection.go +0 -169
- package/cli/cmd/connect.go +0 -597
- package/cli/cmd/db.go +0 -171
- package/cli/cmd/db_export.go +0 -66
- package/cli/cmd/db_import.go +0 -84
- package/cli/cmd/document.go +0 -409
- package/cli/cmd/health.go +0 -19
- package/cli/cmd/index.go +0 -101
- package/cli/cmd/ping.go +0 -36
- package/cli/cmd/root.go +0 -38
- package/cli/cmd/transaction.go +0 -191
- package/cli/cmd/version.go +0 -27
- package/cli/go.mod +0 -15
- package/cli/go.sum +0 -20
- package/cli/internal/config/config.go +0 -120
- package/cli/main.go +0 -7
- package/cli/pkg/commands/collection.go +0 -68
- package/cli/pkg/commands/db.go +0 -62
- package/cli/pkg/commands/document.go +0 -203
- package/cli/pkg/commands/health.go +0 -18
- package/cli/pkg/commands/index.go +0 -51
- package/cli/pkg/commands/transaction.go +0 -84
- package/cli/pkg/httpclient/client.go +0 -236
- package/cli/pkg/protocol/auth.go +0 -46
- package/cli/pkg/protocol/client.go +0 -174
- package/cli/pkg/protocol/message.go +0 -75
- package/lib/engine/cli/worker_process.d.ts +0 -6
- package/lib/engine/cli/worker_process.js +0 -63
- package/lib/engine/cli/worker_process.js.map +0 -1
- package/opencode.json +0 -9
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
package protocol
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"crypto/tls"
|
|
5
|
-
"crypto/x509"
|
|
6
|
-
"fmt"
|
|
7
|
-
"net"
|
|
8
|
-
"os"
|
|
9
|
-
"sync"
|
|
10
|
-
"time"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
type ClientConfig struct {
|
|
14
|
-
Host string
|
|
15
|
-
Port int
|
|
16
|
-
TLSEnabled bool
|
|
17
|
-
TLSCertPath string
|
|
18
|
-
TLSSkipVerify bool
|
|
19
|
-
Timeout time.Duration
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type pendingRequest struct {
|
|
23
|
-
ch chan *Response
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type Client struct {
|
|
27
|
-
config ClientConfig
|
|
28
|
-
conn net.Conn
|
|
29
|
-
pending map[string]*pendingRequest
|
|
30
|
-
mu sync.Mutex
|
|
31
|
-
done chan struct{}
|
|
32
|
-
closed bool
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
func NewClient(cfg ClientConfig) *Client {
|
|
36
|
-
if cfg.Timeout == 0 {
|
|
37
|
-
cfg.Timeout = 30 * time.Second
|
|
38
|
-
}
|
|
39
|
-
return &Client{
|
|
40
|
-
config: cfg,
|
|
41
|
-
pending: make(map[string]*pendingRequest),
|
|
42
|
-
done: make(chan struct{}),
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
func (c *Client) Connect() error {
|
|
47
|
-
addr := fmt.Sprintf("%s:%d", c.config.Host, c.config.Port)
|
|
48
|
-
|
|
49
|
-
if c.config.TLSEnabled {
|
|
50
|
-
tlsCfg := &tls.Config{
|
|
51
|
-
InsecureSkipVerify: c.config.TLSSkipVerify,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if c.config.TLSCertPath != "" {
|
|
55
|
-
cert, err := os.ReadFile(c.config.TLSCertPath)
|
|
56
|
-
if err != nil {
|
|
57
|
-
return fmt.Errorf("read TLS cert: %w", err)
|
|
58
|
-
}
|
|
59
|
-
pool := x509.NewCertPool()
|
|
60
|
-
if !pool.AppendCertsFromPEM(cert) {
|
|
61
|
-
return fmt.Errorf("failed to parse TLS certificate")
|
|
62
|
-
}
|
|
63
|
-
tlsCfg.RootCAs = pool
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
conn, err := tls.Dial("tcp", addr, tlsCfg)
|
|
67
|
-
if err != nil {
|
|
68
|
-
return fmt.Errorf("TLS connect: %w", err)
|
|
69
|
-
}
|
|
70
|
-
c.conn = conn
|
|
71
|
-
} else {
|
|
72
|
-
conn, err := net.DialTimeout("tcp", addr, c.config.Timeout)
|
|
73
|
-
if err != nil {
|
|
74
|
-
return fmt.Errorf("TCP connect: %w", err)
|
|
75
|
-
}
|
|
76
|
-
c.conn = conn
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
go c.readLoop()
|
|
80
|
-
return nil
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
func (c *Client) Send(command string, params map[string]interface{}) (*Response, error) {
|
|
84
|
-
req := NewRequest(command, params)
|
|
85
|
-
|
|
86
|
-
ch := make(chan *Response, 1)
|
|
87
|
-
c.mu.Lock()
|
|
88
|
-
c.pending[req.ID] = &pendingRequest{ch: ch}
|
|
89
|
-
c.mu.Unlock()
|
|
90
|
-
|
|
91
|
-
defer func() {
|
|
92
|
-
c.mu.Lock()
|
|
93
|
-
delete(c.pending, req.ID)
|
|
94
|
-
c.mu.Unlock()
|
|
95
|
-
}()
|
|
96
|
-
|
|
97
|
-
data, err := Encode(req)
|
|
98
|
-
if err != nil {
|
|
99
|
-
return nil, fmt.Errorf("encode request: %w", err)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if err := c.conn.SetWriteDeadline(time.Now().Add(c.config.Timeout)); err != nil {
|
|
103
|
-
return nil, fmt.Errorf("set write deadline: %w", err)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if _, err := c.conn.Write(data); err != nil {
|
|
107
|
-
return nil, fmt.Errorf("write request: %w", err)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
select {
|
|
111
|
-
case resp := <-ch:
|
|
112
|
-
return resp, nil
|
|
113
|
-
case <-time.After(c.config.Timeout):
|
|
114
|
-
return nil, fmt.Errorf("request timeout after %s", c.config.Timeout)
|
|
115
|
-
case <-c.done:
|
|
116
|
-
return nil, fmt.Errorf("connection closed")
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
func (c *Client) Disconnect() error {
|
|
121
|
-
c.mu.Lock()
|
|
122
|
-
if c.closed {
|
|
123
|
-
c.mu.Unlock()
|
|
124
|
-
return nil
|
|
125
|
-
}
|
|
126
|
-
c.closed = true
|
|
127
|
-
c.mu.Unlock()
|
|
128
|
-
|
|
129
|
-
_, _ = c.Send("DISCONNECT", nil)
|
|
130
|
-
|
|
131
|
-
close(c.done)
|
|
132
|
-
if c.conn != nil {
|
|
133
|
-
return c.conn.Close()
|
|
134
|
-
}
|
|
135
|
-
return nil
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
func (c *Client) Ping() error {
|
|
139
|
-
resp, err := c.Send("PING", nil)
|
|
140
|
-
if err != nil {
|
|
141
|
-
return err
|
|
142
|
-
}
|
|
143
|
-
if resp.StatusCode != 200 {
|
|
144
|
-
return fmt.Errorf("ping failed: %s", resp.Error)
|
|
145
|
-
}
|
|
146
|
-
return nil
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
func (c *Client) readLoop() {
|
|
150
|
-
for {
|
|
151
|
-
select {
|
|
152
|
-
case <-c.done:
|
|
153
|
-
return
|
|
154
|
-
default:
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
resp, err := Decode(c.conn)
|
|
158
|
-
if err != nil {
|
|
159
|
-
c.mu.Lock()
|
|
160
|
-
for id, p := range c.pending {
|
|
161
|
-
p.ch <- &Response{StatusCode: 500, Error: fmt.Sprintf("connection error: %v", err)}
|
|
162
|
-
delete(c.pending, id)
|
|
163
|
-
}
|
|
164
|
-
c.mu.Unlock()
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
c.mu.Lock()
|
|
169
|
-
if p, ok := c.pending[resp.ID]; ok {
|
|
170
|
-
p.ch <- resp
|
|
171
|
-
}
|
|
172
|
-
c.mu.Unlock()
|
|
173
|
-
}
|
|
174
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
package protocol
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"encoding/binary"
|
|
5
|
-
"encoding/json"
|
|
6
|
-
"fmt"
|
|
7
|
-
"io"
|
|
8
|
-
|
|
9
|
-
"github.com/google/uuid"
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
const MaxMessageSize = 50 * 1024 * 1024
|
|
13
|
-
|
|
14
|
-
type Request struct {
|
|
15
|
-
ID string `json:"id"`
|
|
16
|
-
Command string `json:"command"`
|
|
17
|
-
Params map[string]interface{} `json:"params"`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type Response struct {
|
|
21
|
-
ID string `json:"id"`
|
|
22
|
-
StatusCode int `json:"statusCode"`
|
|
23
|
-
Message string `json:"message"`
|
|
24
|
-
Data interface{} `json:"data,omitempty"`
|
|
25
|
-
Error string `json:"error,omitempty"`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
func NewRequest(command string, params map[string]interface{}) *Request {
|
|
29
|
-
return &Request{
|
|
30
|
-
ID: uuid.New().String(),
|
|
31
|
-
Command: command,
|
|
32
|
-
Params: params,
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func Encode(msg interface{}) ([]byte, error) {
|
|
37
|
-
payload, err := json.Marshal(msg)
|
|
38
|
-
if err != nil {
|
|
39
|
-
return nil, fmt.Errorf("json marshal: %w", err)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if len(payload) > MaxMessageSize {
|
|
43
|
-
return nil, fmt.Errorf("message size %d exceeds max %d", len(payload), MaxMessageSize)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
frame := make([]byte, 4+len(payload))
|
|
47
|
-
binary.BigEndian.PutUint32(frame[:4], uint32(len(payload)))
|
|
48
|
-
copy(frame[4:], payload)
|
|
49
|
-
|
|
50
|
-
return frame, nil
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
func Decode(reader io.Reader) (*Response, error) {
|
|
54
|
-
lengthBytes := make([]byte, 4)
|
|
55
|
-
if _, err := io.ReadFull(reader, lengthBytes); err != nil {
|
|
56
|
-
return nil, fmt.Errorf("read length: %w", err)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
length := binary.BigEndian.Uint32(lengthBytes)
|
|
60
|
-
if length > MaxMessageSize {
|
|
61
|
-
return nil, fmt.Errorf("message size %d exceeds max %d", length, MaxMessageSize)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
payload := make([]byte, length)
|
|
65
|
-
if _, err := io.ReadFull(reader, payload); err != nil {
|
|
66
|
-
return nil, fmt.Errorf("read payload: %w", err)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var resp Response
|
|
70
|
-
if err := json.Unmarshal(payload, &resp); err != nil {
|
|
71
|
-
return nil, fmt.Errorf("json unmarshal: %w", err)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return &resp, nil
|
|
75
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const child_process_1 = require("child_process");
|
|
13
|
-
const util_1 = require("util");
|
|
14
|
-
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
15
|
-
class WorkerProcess {
|
|
16
|
-
execCommand(command) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
try {
|
|
19
|
-
const { stdout } = yield execAsync(command);
|
|
20
|
-
return stdout;
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
throw new Error(`Failed to execute command: ${error}`);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/** Inherits stdio; rejects if the process exits with a non-zero code. */
|
|
28
|
-
spawnCommand(command_1) {
|
|
29
|
-
return __awaiter(this, arguments, void 0, function* (command, args = []) {
|
|
30
|
-
try {
|
|
31
|
-
const child = (0, child_process_1.spawn)(command, args, { stdio: "inherit" });
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
child.on("close", (code) => {
|
|
34
|
-
if (code !== 0) {
|
|
35
|
-
reject(new Error(`Command failed with exit code ${code}`));
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
resolve();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
throw new Error(`Failed to spawn command: ${error}`);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
static getOS() {
|
|
49
|
-
const platform = process.platform;
|
|
50
|
-
if (platform === "win32") {
|
|
51
|
-
return "windows";
|
|
52
|
-
}
|
|
53
|
-
if (platform === "darwin") {
|
|
54
|
-
return "macos";
|
|
55
|
-
}
|
|
56
|
-
if (platform === "linux") {
|
|
57
|
-
return "linux";
|
|
58
|
-
}
|
|
59
|
-
throw new Error(`Unsupported platform: ${platform}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.default = WorkerProcess;
|
|
63
|
-
//# sourceMappingURL=worker_process.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker_process.js","sourceRoot":"","sources":["../../../source/engine/cli/worker_process.ts"],"names":[],"mappings":";;;;;;;;;;;AA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