edgebase_core 0.1.4
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +77 -0
- data/lib/edgebase_core/context_manager.rb +23 -0
- data/lib/edgebase_core/errors.rb +41 -0
- data/lib/edgebase_core/field_ops.rb +21 -0
- data/lib/edgebase_core/generated/api_core.rb +915 -0
- data/lib/edgebase_core/generated/client_wrappers.rb +268 -0
- data/lib/edgebase_core/http_client.rb +219 -0
- data/lib/edgebase_core/storage.rb +161 -0
- data/lib/edgebase_core/table_ref.rb +472 -0
- data/lib/edgebase_core.rb +10 -0
- data/llms.txt +88 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 78a3ab9e340eb9af6f6c70dfd948ccb6d98fcc4c988e6ac93a000ed8ba710bd6
|
|
4
|
+
data.tar.gz: 3ee1516a0f6a6fb1d1f7a223651982b4d2a1637a44a59a2e57086a8a92517387
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8a8f7a3fac453938a11f8c23b00b2f65867fd206545e7f9d56e4776e21dda9e2c0f2b6ab68678be611e61fef98b132cab75cab9884c4204a3fc6d3c7972551e6
|
|
7
|
+
data.tar.gz: 0b790f1d2299d34614a74bcdb7ac6fb9766ae70f96acc3c2fe5c238d846c8ca64784a19e9b5f472b722fa7b7dd53d05c2c1cb2b9514d89c4c389eb97fcbaff09
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 melodysdreamj
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# edgebase_core
|
|
2
|
+
|
|
3
|
+
Shared low-level Ruby primitives for EdgeBase.
|
|
4
|
+
|
|
5
|
+
`edgebase_core` is the foundation used by `edgebase_admin`. It provides the HTTP client, table query builder, storage helpers, field operation markers, error types, DB references, and document references used by higher-level SDKs.
|
|
6
|
+
|
|
7
|
+
Most application code should install [`edgebase_admin`](https://rubygems.org/gems/edgebase_admin) instead. Use this package directly when you are building custom wrappers, generated bindings, or internal integrations.
|
|
8
|
+
|
|
9
|
+
## Documentation Map
|
|
10
|
+
|
|
11
|
+
Use this README for the fast overview, then jump into the docs when you need depth:
|
|
12
|
+
|
|
13
|
+
- [SDK Overview](https://edgebase.fun/docs/sdks)
|
|
14
|
+
Install commands and the public SDK matrix
|
|
15
|
+
- [Database Admin SDK](https://edgebase.fun/docs/database/admin-sdk)
|
|
16
|
+
Table queries, filters, pagination, batch writes, and raw SQL
|
|
17
|
+
- [Storage](https://edgebase.fun/docs/storage/upload-download)
|
|
18
|
+
Uploads, downloads, metadata, and signed URLs
|
|
19
|
+
- [Admin SDK Reference](https://edgebase.fun/docs/admin-sdk/reference)
|
|
20
|
+
Cross-language examples that sit on top of this core package
|
|
21
|
+
|
|
22
|
+
## For AI Coding Assistants
|
|
23
|
+
|
|
24
|
+
This package includes an `llms.txt` file for AI-assisted development.
|
|
25
|
+
|
|
26
|
+
Use it when you want an agent or code assistant to:
|
|
27
|
+
|
|
28
|
+
- keep Service Keys on the server
|
|
29
|
+
- use the actual Ruby class and method names
|
|
30
|
+
- avoid copying JavaScript promise-based examples into Ruby
|
|
31
|
+
- remember which surfaces are low-level helpers versus admin-only clients
|
|
32
|
+
|
|
33
|
+
You can find it:
|
|
34
|
+
|
|
35
|
+
- in this repository: [llms.txt](https://github.com/edge-base/edgebase/blob/main/packages/sdk/ruby/packages/core/llms.txt)
|
|
36
|
+
- in your environment after install, inside the `edgebase_core` package directory as `llms.txt`
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
If you are working inside this repository, reference the package directly through Bundler path dependencies.
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
require "edgebase_core"
|
|
46
|
+
|
|
47
|
+
client = EdgebaseCore::HttpClient.new(
|
|
48
|
+
"https://your-project.edgebase.fun",
|
|
49
|
+
service_key: ENV.fetch("EDGEBASE_SERVICE_KEY")
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
storage = EdgebaseCore::StorageClient.new(client)
|
|
53
|
+
bucket = storage.bucket("avatars")
|
|
54
|
+
bucket.upload("user-1.jpg", "binary-data", content_type: "image/jpeg")
|
|
55
|
+
|
|
56
|
+
marker = EdgebaseCore::FieldOps.increment(1)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Included Surfaces
|
|
60
|
+
|
|
61
|
+
- `EdgebaseCore::HttpClient`
|
|
62
|
+
- `EdgebaseCore::DbRef`, `EdgebaseCore::DocRef`, `EdgebaseCore::TableRef`
|
|
63
|
+
- `EdgebaseCore::StorageClient`, `EdgebaseCore::StorageBucket`
|
|
64
|
+
- `EdgebaseCore::FieldOps.increment()` and `EdgebaseCore::FieldOps.delete_field`
|
|
65
|
+
- `EdgebaseCore::ListResult`, `EdgebaseCore::BatchResult`, `EdgebaseCore::UpsertResult`
|
|
66
|
+
- `EdgebaseCore::EdgeBaseError`
|
|
67
|
+
|
|
68
|
+
## Choose The Right Package
|
|
69
|
+
|
|
70
|
+
| Package | Use it for |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `edgebase_core` | Low-level Ruby primitives for custom wrappers and internal integrations |
|
|
73
|
+
| `edgebase_admin` | Trusted server-side code with Service Key access |
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EdgebaseCore
|
|
4
|
+
# Thread-safe context storage for multi-tenancy.
|
|
5
|
+
class ContextManager
|
|
6
|
+
def initialize
|
|
7
|
+
@context = {}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def set_context(context)
|
|
11
|
+
# Filter out auth.id — server extracts from JWT only
|
|
12
|
+
@context = context.reject { |k, _| k == "auth.id" }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get_context
|
|
16
|
+
@context.dup
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def clear_context
|
|
20
|
+
@context = {}
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EdgebaseCore
|
|
4
|
+
# Base error for all EdgeBase API errors.
|
|
5
|
+
class EdgeBaseError < StandardError
|
|
6
|
+
attr_reader :status_code, :message, :details
|
|
7
|
+
|
|
8
|
+
def initialize(status_code, message, details: nil)
|
|
9
|
+
@status_code = status_code
|
|
10
|
+
@message = message
|
|
11
|
+
@details = details
|
|
12
|
+
super(to_s)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s
|
|
16
|
+
parts = ["EdgeBaseError(#{@status_code}): #{@message}"]
|
|
17
|
+
if @details
|
|
18
|
+
@details.each do |k, v|
|
|
19
|
+
parts << " #{k}: #{Array(v).join(', ')}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
parts.join("\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Create from API JSON response.
|
|
26
|
+
def self.from_json(data, status_code)
|
|
27
|
+
new(
|
|
28
|
+
status_code,
|
|
29
|
+
data["message"] || "Unknown error",
|
|
30
|
+
details: data["details"]
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Authentication-specific error.
|
|
36
|
+
class EdgeBaseAuthError < EdgeBaseError
|
|
37
|
+
def to_s
|
|
38
|
+
"EdgeBaseAuthError(#{@status_code}): #{@message}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EdgebaseCore
|
|
4
|
+
# Atomic field operation markers ($op pattern — mirrors JS SDK, server op-parser.ts).
|
|
5
|
+
module FieldOps
|
|
6
|
+
# Increment a numeric field atomically.
|
|
7
|
+
#
|
|
8
|
+
# doc_ref.update("views" => EdgebaseCore::FieldOps.increment(1))
|
|
9
|
+
# doc_ref.update("score" => EdgebaseCore::FieldOps.increment(-5))
|
|
10
|
+
def self.increment(value = 1)
|
|
11
|
+
{ "$op" => "increment", "value" => value }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Delete a field from a document.
|
|
15
|
+
#
|
|
16
|
+
# doc_ref.update("oldField" => EdgebaseCore::FieldOps.delete_field)
|
|
17
|
+
def self.delete_field
|
|
18
|
+
{ "$op" => "deleteField" }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|