Skip to content

Commit c197c6f

Browse files
Jake ChampionJakeChampion
authored andcommitted
Implement ObjectStore and ObjectStoreEntry classes for interacting with Fastly ObjectStore
The interfaces for these new classes is as follows: ``` declare class ObjectStore { constructor(name: string); lookup(key: string): Promise<ObjectStoreEntry | null>; put(key: string, value: BodyInit): Promise<undefined>; } declare class ObjectStoreEntry { get body(): ReadableStream; get bodyUsed(): boolean; text(): Promise<string>; json(): Promise<object>; arrayBuffer(): Promise<ArrayBuffer>; // And eventually formData and blob once we support them on Request and Response, too. } ``` ObjectStore is a class we expose to application code for interacting with Fastly ObjectStores and ObjectStoreEntry is not exposed to application code. ObjectStoreEntry is only used as the return result from ObjectStore.lookup for successful lookups. ObjectStoreEntry has an interface very similar to Response, which is intentional as this is an interface JavaScript developers are familar with and it also can be used as a stream via ObjectStoreEntry.body(), which is useful for applications which want to improve their performance and reduce meory usage. Below is an example js application which uses the new feature: ```js addEventListener("fetch", event => { event.respondWith(app(event)) }) async function app(event) { const store = new ObjectStore('example-store') await store.put('hello', 'world') let hello = await store.lookup('hello') let hellotext = await hello.text() return new Response(hellotext) } ```
1 parent 627a6a5 commit c197c6f

File tree

12 files changed

+2392
-40
lines changed

12 files changed

+2392
-40
lines changed

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@
7474
"typeinfo": "cpp",
7575
"unordered_map": "cpp",
7676
"utility": "cpp",
77-
"*.msg": "cpp"
77+
"*.idl": "cpp",
78+
"*.inc": "cpp",
79+
"*.msg": "cpp",
80+
"map": "cpp",
81+
"set": "cpp",
82+
"unordered_set": "cpp"
7883
},
7984
"git.ignoreLimitWarning": true
8085
}

c-dependencies/js-compute-runtime/builtin.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
\
4444
bool check_receiver(JSContext *cx, JS::HandleValue receiver, const char *method_name) { \
4545
if (!is_instance(receiver)) { \
46-
JS_ReportErrorUTF8(cx, "Method %s called on receiver that's not an instance of %s\n", \
47-
method_name, class_.name); \
46+
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_INSTANCE, \
47+
method_name, class_.name); \
4848
return false; \
4949
} \
5050
return true; \
@@ -154,8 +154,8 @@ template <typename Impl> class BuiltinImpl {
154154

155155
static bool check_receiver(JSContext *cx, JS::HandleValue receiver, const char *method_name) {
156156
if (!Impl::is_instance(receiver)) {
157-
JS_ReportErrorUTF8(cx, "Method %s called on receiver that's not an instance of %s\n",
158-
method_name, Impl::class_.name);
157+
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_INSTANCE,
158+
method_name, Impl::class_.name);
159159
return false;
160160
}
161161

0 commit comments

Comments
 (0)