@farcaster/snap 1.7.0 → 1.7.1
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/dataStore.d.ts +1 -4
- package/dist/dataStore.js +4 -17
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/dataStore.ts +5 -29
- package/src/index.ts +0 -1
package/dist/dataStore.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export type DataStoreValue = string | number | boolean | null | DataStoreValue[] | {
|
|
2
2
|
[key: string]: DataStoreValue;
|
|
3
3
|
};
|
|
4
|
-
export type
|
|
4
|
+
export type SnapDataStore = {
|
|
5
5
|
get(key: string): Promise<DataStoreValue | null>;
|
|
6
6
|
set(key: string, value: DataStoreValue): Promise<void>;
|
|
7
7
|
};
|
|
8
|
-
export type SnapDataStore = SnapDataStoreOperations & {
|
|
9
|
-
withLock<T>(fn: (store: SnapDataStoreOperations) => Promise<T>): Promise<T>;
|
|
10
|
-
};
|
|
11
8
|
export declare function createDefaultDataStore(): SnapDataStore;
|
|
12
9
|
export declare function createInMemoryDataStore(): SnapDataStore;
|
package/dist/dataStore.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function createDefaultDataStore() {
|
|
2
|
-
const err = new Error("Data store is not configured. Use
|
|
2
|
+
const err = new Error("Data store is not configured. Use withTursoServerless() from @farcaster/snap-turso or provide a data store implementation.");
|
|
3
3
|
return {
|
|
4
4
|
get(_key) {
|
|
5
5
|
return Promise.reject(err);
|
|
@@ -7,29 +7,16 @@ export function createDefaultDataStore() {
|
|
|
7
7
|
set(_key, _value) {
|
|
8
8
|
return Promise.reject(err);
|
|
9
9
|
},
|
|
10
|
-
withLock(_fn) {
|
|
11
|
-
return Promise.reject(err);
|
|
12
|
-
},
|
|
13
10
|
};
|
|
14
11
|
}
|
|
15
12
|
export function createInMemoryDataStore() {
|
|
16
13
|
const data = new Map();
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
return {
|
|
15
|
+
async get(key) {
|
|
19
16
|
return data.get(key) ?? null;
|
|
20
17
|
},
|
|
21
|
-
|
|
18
|
+
async set(key, value) {
|
|
22
19
|
data.set(key, value);
|
|
23
20
|
},
|
|
24
21
|
};
|
|
25
|
-
/** Serializes `withLock` callbacks so async work does not interleave across callers. */
|
|
26
|
-
let lockChain = Promise.resolve();
|
|
27
|
-
return {
|
|
28
|
-
...ops,
|
|
29
|
-
withLock(fn) {
|
|
30
|
-
const run = lockChain.then(() => fn(ops));
|
|
31
|
-
lockChain = run.then(() => undefined, () => undefined);
|
|
32
|
-
return run;
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { SPEC_VERSION, MEDIA_TYPE, EFFECT_VALUES, } from "./constants.js";
|
|
|
3
3
|
export { DEFAULT_THEME_ACCENT, PALETTE_COLOR, PALETTE_COLOR_ACCENT, PALETTE_COLOR_VALUES, PALETTE_LIGHT_HEX, PALETTE_DARK_HEX, type PaletteColor, } from "./colors.js";
|
|
4
4
|
export { ACTION_TYPE_GET, ACTION_TYPE_POST, snapResponseSchema, payloadSchema, type SnapAction, type SnapContext, type SnapResponse, type SnapHandlerResult, type SnapFunction, type SnapPayload, } from "./schemas.js";
|
|
5
5
|
export { validateSnapResponse, type ValidationResult, } from "./validator.js";
|
|
6
|
-
export { type DataStoreValue, type SnapDataStore,
|
|
6
|
+
export { type DataStoreValue, type SnapDataStore, createDefaultDataStore, createInMemoryDataStore, } from "./dataStore.js";
|
|
7
7
|
export { type Middleware, useMiddleware } from "./middleware.js";
|
package/package.json
CHANGED
package/src/dataStore.ts
CHANGED
|
@@ -6,18 +6,14 @@ export type DataStoreValue =
|
|
|
6
6
|
| DataStoreValue[]
|
|
7
7
|
| { [key: string]: DataStoreValue };
|
|
8
8
|
|
|
9
|
-
export type
|
|
9
|
+
export type SnapDataStore = {
|
|
10
10
|
get(key: string): Promise<DataStoreValue | null>;
|
|
11
11
|
set(key: string, value: DataStoreValue): Promise<void>;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export type SnapDataStore = SnapDataStoreOperations & {
|
|
15
|
-
withLock<T>(fn: (store: SnapDataStoreOperations) => Promise<T>): Promise<T>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
14
|
export function createDefaultDataStore(): SnapDataStore {
|
|
19
15
|
const err = new Error(
|
|
20
|
-
"Data store is not configured. Use
|
|
16
|
+
"Data store is not configured. Use withTursoServerless() from @farcaster/snap-turso or provide a data store implementation.",
|
|
21
17
|
);
|
|
22
18
|
return {
|
|
23
19
|
get(_key: string): Promise<never> {
|
|
@@ -26,37 +22,17 @@ export function createDefaultDataStore(): SnapDataStore {
|
|
|
26
22
|
set(_key: string, _value: DataStoreValue): Promise<never> {
|
|
27
23
|
return Promise.reject(err);
|
|
28
24
|
},
|
|
29
|
-
withLock<T>(
|
|
30
|
-
_fn: (store: SnapDataStoreOperations) => Promise<T>,
|
|
31
|
-
): Promise<never> {
|
|
32
|
-
return Promise.reject(err);
|
|
33
|
-
},
|
|
34
25
|
};
|
|
35
26
|
}
|
|
36
27
|
|
|
37
28
|
export function createInMemoryDataStore(): SnapDataStore {
|
|
38
29
|
const data = new Map<string, DataStoreValue>();
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
return {
|
|
31
|
+
async get(key: string): Promise<DataStoreValue | null> {
|
|
41
32
|
return data.get(key) ?? null;
|
|
42
33
|
},
|
|
43
|
-
|
|
34
|
+
async set(key: string, value: DataStoreValue): Promise<void> {
|
|
44
35
|
data.set(key, value);
|
|
45
36
|
},
|
|
46
37
|
};
|
|
47
|
-
/** Serializes `withLock` callbacks so async work does not interleave across callers. */
|
|
48
|
-
let lockChain: Promise<unknown> = Promise.resolve();
|
|
49
|
-
return {
|
|
50
|
-
...ops,
|
|
51
|
-
withLock<T>(
|
|
52
|
-
fn: (store: SnapDataStoreOperations) => Promise<T>,
|
|
53
|
-
): Promise<T> {
|
|
54
|
-
const run = lockChain.then(() => fn(ops));
|
|
55
|
-
lockChain = run.then(
|
|
56
|
-
() => undefined,
|
|
57
|
-
() => undefined,
|
|
58
|
-
);
|
|
59
|
-
return run;
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
38
|
}
|