lenix 1.7.8 → 1.7.9
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/client/client.ts +20 -10
- package/package.json +1 -1
package/client/client.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { repeat } from '../shared/repeat.ts'
|
|
2
2
|
import type { Vec3, Vec4 } from '../shared/types.ts'
|
|
3
3
|
|
|
4
|
+
type JsonPrimitive = string | number | boolean | null
|
|
5
|
+
type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
|
|
6
|
+
|
|
4
7
|
export const client = {
|
|
5
8
|
entity: {
|
|
6
9
|
/**
|
|
@@ -154,24 +157,31 @@ export const client = {
|
|
|
154
157
|
},
|
|
155
158
|
|
|
156
159
|
/* */
|
|
157
|
-
/* TODO: support booleans and numbers, and maybe even json */
|
|
158
160
|
storage: {
|
|
159
161
|
set: <Storage>(
|
|
160
162
|
...[key, value]: {
|
|
161
|
-
[K in keyof Storage]:
|
|
163
|
+
[K in keyof Storage]: Storage[K] extends JsonValue
|
|
164
|
+
? [key: Extract<K, string>, value: Storage[K]]
|
|
165
|
+
: never
|
|
162
166
|
}[keyof Storage]
|
|
163
|
-
) => SetResourceKvp(key, value),
|
|
167
|
+
) => SetResourceKvp(key, JSON.stringify(value)),
|
|
164
168
|
|
|
165
169
|
get: <Storage, K extends Extract<keyof Storage, string>>(
|
|
166
170
|
key: K,
|
|
167
|
-
init?:
|
|
168
|
-
): Storage[K] extends
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
init?: Storage[K] extends JsonValue ? Storage[K] : never
|
|
172
|
+
): Storage[K] extends JsonValue ? Storage[K] : never => {
|
|
173
|
+
const value = GetResourceKvpString(key)
|
|
174
|
+
|
|
175
|
+
if (value === null) {
|
|
176
|
+
if (init === undefined) {
|
|
177
|
+
throw new Error(`Storage<${key}> was never assigned`)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
SetResourceKvp(key, JSON.stringify(init))
|
|
181
|
+
return init as Storage[K] extends JsonValue ? Storage[K] : never
|
|
173
182
|
}
|
|
174
|
-
|
|
183
|
+
|
|
184
|
+
return JSON.parse(value) as Storage[K] extends JsonValue ? Storage[K] : never
|
|
175
185
|
},
|
|
176
186
|
|
|
177
187
|
delete: <Storage>(
|