unikvs 0.0.3 → 0.0.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.
- package/dist/src/_combine-signals.d.ts +9 -0
- package/dist/src/_combine-signals.d.ts.map +1 -0
- package/dist/src/_combine-signals.js +59 -0
- package/dist/src/_logger.d.ts +3 -0
- package/dist/src/_logger.d.ts.map +1 -0
- package/dist/src/_logger.js +3 -0
- package/dist/src/_merge-context.d.ts +4 -0
- package/dist/src/_merge-context.d.ts.map +1 -0
- package/dist/src/_merge-context.js +3 -0
- package/dist/src/_storage.d.ts +17 -0
- package/dist/src/_storage.d.ts.map +1 -0
- package/dist/src/_storage.js +84 -0
- package/dist/src/_to-value-stream.d.ts +12 -0
- package/dist/src/_to-value-stream.d.ts.map +1 -0
- package/dist/src/_to-value-stream.js +53 -0
- package/dist/src/_transformer.d.ts +12 -0
- package/dist/src/_transformer.d.ts.map +1 -0
- package/dist/src/_transformer.js +52 -0
- package/dist/src/_valibot.d.ts +13 -0
- package/dist/src/_valibot.d.ts.map +1 -0
- package/dist/src/_valibot.js +12 -0
- package/dist/src/context.types.d.ts +17 -0
- package/dist/src/context.types.d.ts.map +1 -0
- package/dist/src/errors.d.ts +108 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +169 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/unikvs-config.d.ts +255 -0
- package/dist/src/unikvs-config.d.ts.map +1 -0
- package/dist/src/unikvs-config.js +105 -0
- package/dist/src/unikvs.d.ts +324 -0
- package/dist/src/unikvs.d.ts.map +1 -0
- package/dist/src/unikvs.js +693 -0
- package/dist/src/utils.types.d.ts +7 -0
- package/dist/src/utils.types.d.ts.map +1 -0
- package/dist/src/value-stream.types.d.ts +11 -0
- package/dist/src/value-stream.types.d.ts.map +1 -0
- package/package.json +22 -39
- package/src/_combine-signals.ts +67 -0
- package/src/_logger.ts +5 -0
- package/src/_merge-context.ts +10 -0
- package/src/_storage.ts +130 -0
- package/src/_to-value-stream.ts +59 -0
- package/src/_transformer.ts +75 -0
- package/src/_valibot.ts +30 -0
- package/src/context.types.ts +19 -0
- package/src/errors.ts +382 -0
- package/src/index.ts +52 -0
- package/src/unikvs-config.ts +429 -0
- package/src/unikvs.ts +1171 -0
- package/src/utils.types.ts +6 -0
- package/src/value-stream.types.ts +14 -0
- package/dist/src/core/_assign-context.d.ts +0 -3
- package/dist/src/core/_assign-context.d.ts.map +0 -1
- package/dist/src/core/_assign-context.js +0 -3
- package/dist/src/core/_combine-signals.d.ts +0 -3
- package/dist/src/core/_combine-signals.d.ts.map +0 -1
- package/dist/src/core/_combine-signals.js +0 -34
- package/dist/src/core/_is-iterable.d.ts +0 -2
- package/dist/src/core/_is-iterable.d.ts.map +0 -1
- package/dist/src/core/_is-iterable.js +0 -3
- package/dist/src/core/_is-plain-object.d.ts +0 -2
- package/dist/src/core/_is-plain-object.d.ts.map +0 -1
- package/dist/src/core/_is-plain-object.js +0 -7
- package/dist/src/core/_logger.d.ts +0 -3
- package/dist/src/core/_logger.d.ts.map +0 -1
- package/dist/src/core/_logger.js +0 -3
- package/dist/src/core/_merge-context.d.ts +0 -3
- package/dist/src/core/_merge-context.d.ts.map +0 -1
- package/dist/src/core/_merge-context.js +0 -4
- package/dist/src/core/_to-context.d.ts +0 -7
- package/dist/src/core/_to-context.d.ts.map +0 -1
- package/dist/src/core/_to-context.js +0 -42
- package/dist/src/core/_to-value-stream.d.ts +0 -4
- package/dist/src/core/_to-value-stream.d.ts.map +0 -1
- package/dist/src/core/_to-value-stream.js +0 -38
- package/dist/src/core/_with-readable-stream-from.d.ts +0 -6
- package/dist/src/core/_with-readable-stream-from.d.ts.map +0 -1
- package/dist/src/core/_with-readable-stream-from.js +0 -58
- package/dist/src/core/context.types.d.ts +0 -5
- package/dist/src/core/context.types.d.ts.map +0 -1
- package/dist/src/core/errors.d.ts +0 -13
- package/dist/src/core/errors.d.ts.map +0 -1
- package/dist/src/core/errors.js +0 -20
- package/dist/src/core/index.d.ts +0 -15
- package/dist/src/core/index.d.ts.map +0 -1
- package/dist/src/core/index.js +0 -4
- package/dist/src/core/plugin.types.d.ts +0 -8
- package/dist/src/core/plugin.types.d.ts.map +0 -1
- package/dist/src/core/plugin.types.js +0 -1
- package/dist/src/core/storage.types.d.ts +0 -22
- package/dist/src/core/storage.types.d.ts.map +0 -1
- package/dist/src/core/storage.types.js +0 -1
- package/dist/src/core/to-readable-stream.d.ts +0 -2
- package/dist/src/core/to-readable-stream.d.ts.map +0 -1
- package/dist/src/core/to-readable-stream.js +0 -4
- package/dist/src/core/transformer.types.d.ts +0 -18
- package/dist/src/core/transformer.types.d.ts.map +0 -1
- package/dist/src/core/transformer.types.js +0 -1
- package/dist/src/core/unikvs-config.d.ts +0 -82
- package/dist/src/core/unikvs-config.d.ts.map +0 -1
- package/dist/src/core/unikvs-config.js +0 -49
- package/dist/src/core/unikvs.d.ts +0 -73
- package/dist/src/core/unikvs.d.ts.map +0 -1
- package/dist/src/core/unikvs.js +0 -678
- package/dist/src/core/utils.types.d.ts +0 -3
- package/dist/src/core/utils.types.d.ts.map +0 -1
- package/dist/src/core/value-stream.types.d.ts +0 -4
- package/dist/src/core/value-stream.types.d.ts.map +0 -1
- package/dist/src/destinations/memory-storage.d.ts +0 -17
- package/dist/src/destinations/memory-storage.d.ts.map +0 -1
- package/dist/src/destinations/memory-storage.js +0 -113
- package/dist/src/types/storage.d.ts +0 -5
- package/dist/src/types/storage.d.ts.map +0 -1
- package/dist/src/types/storage.js +0 -1
- package/dist/src/types/transformer.d.ts +0 -5
- package/dist/src/types/transformer.d.ts.map +0 -1
- package/dist/src/types/transformer.js +0 -1
- package/src/core/_assign-context.ts +0 -5
- package/src/core/_combine-signals.ts +0 -40
- package/src/core/_is-iterable.ts +0 -3
- package/src/core/_is-plain-object.ts +0 -11
- package/src/core/_logger.ts +0 -5
- package/src/core/_merge-context.ts +0 -9
- package/src/core/_to-context.ts +0 -59
- package/src/core/_to-value-stream.ts +0 -41
- package/src/core/_with-readable-stream-from.ts +0 -70
- package/src/core/context.types.ts +0 -7
- package/src/core/errors.ts +0 -37
- package/src/core/index.ts +0 -23
- package/src/core/plugin.types.ts +0 -10
- package/src/core/storage.types.ts +0 -53
- package/src/core/to-readable-stream.ts +0 -7
- package/src/core/transformer.types.ts +0 -110
- package/src/core/unikvs-config.ts +0 -230
- package/src/core/unikvs.ts +0 -740
- package/src/core/utils.types.ts +0 -3
- package/src/core/value-stream.types.ts +0 -3
- package/src/destinations/memory-storage.ts +0 -160
- package/src/types/storage.ts +0 -5
- package/src/types/transformer.ts +0 -5
- /package/dist/src/{core/context.types.js → context.types.js} +0 -0
- /package/dist/src/{core/utils.types.js → utils.types.js} +0 -0
- /package/dist/src/{core/value-stream.types.js → value-stream.types.js} +0 -0
package/src/core/utils.types.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import getType from "type-name";
|
|
2
|
-
|
|
3
|
-
import { TypeError } from "../core/errors.js";
|
|
4
|
-
import type { IStorage, Key } from "../core/storage.types.js";
|
|
5
|
-
|
|
6
|
-
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray_%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88
|
|
7
|
-
type TypedArray =
|
|
8
|
-
| Int8Array
|
|
9
|
-
| Uint8Array
|
|
10
|
-
| Uint8ClampedArray
|
|
11
|
-
| Int16Array
|
|
12
|
-
| Uint16Array
|
|
13
|
-
| Int32Array
|
|
14
|
-
| Uint32Array
|
|
15
|
-
| Float32Array
|
|
16
|
-
| Float64Array
|
|
17
|
-
| BigInt64Array
|
|
18
|
-
| BigUint64Array;
|
|
19
|
-
|
|
20
|
-
type Chunk = ArrayBuffer | TypedArray;
|
|
21
|
-
|
|
22
|
-
class Chunks extends Array<Chunk> {}
|
|
23
|
-
|
|
24
|
-
function isTypedArray(x: unknown): x is TypedArray {
|
|
25
|
-
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isArrayBuffer(x: unknown): x is ArrayBuffer {
|
|
29
|
-
return x instanceof ArrayBuffer;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default class MemoryStorage implements IStorage {
|
|
33
|
-
public readonly isOpen: boolean = true;
|
|
34
|
-
|
|
35
|
-
private store: Map<Key, any>;
|
|
36
|
-
|
|
37
|
-
public constructor() {
|
|
38
|
-
this.store = new Map();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public write(key: Key, data: any): void {
|
|
42
|
-
this.store.set(key, data);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public getWritable(key: Key): WritableStream<Chunk> {
|
|
46
|
-
const chunks = new Chunks();
|
|
47
|
-
let firstChunk: Chunk | null = null;
|
|
48
|
-
|
|
49
|
-
return new WritableStream({
|
|
50
|
-
write: (chunk) => {
|
|
51
|
-
if (!isTypedArray(chunk) && !isArrayBuffer(chunk)) {
|
|
52
|
-
throw new TypeError({
|
|
53
|
-
actualValue: chunk satisfies never,
|
|
54
|
-
expectedType: "ArrayBuffer | TypedArray",
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (firstChunk === null) {
|
|
59
|
-
firstChunk = chunk;
|
|
60
|
-
} else if (!(chunk instanceof firstChunk.constructor)) {
|
|
61
|
-
throw new TypeError({
|
|
62
|
-
actualValue: chunk,
|
|
63
|
-
expectedType: getType(firstChunk),
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
chunks.push(chunk);
|
|
68
|
-
},
|
|
69
|
-
close: () => {
|
|
70
|
-
this.store.set(key, chunks);
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public read(key: Key): any {
|
|
76
|
-
const data = this.store.get(key);
|
|
77
|
-
|
|
78
|
-
if (data instanceof Chunks) {
|
|
79
|
-
if (data.length === 0) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const firstChunk = data[0]!;
|
|
84
|
-
|
|
85
|
-
if (isTypedArray(firstChunk)) {
|
|
86
|
-
const chunks = data as TypedArray[];
|
|
87
|
-
|
|
88
|
-
const Constructor = firstChunk.constructor as { new (n: number): TypedArray };
|
|
89
|
-
const totalLength = chunks.reduce((len, chunk) => len + chunk.length, 0);
|
|
90
|
-
const mergedArray = new Constructor(totalLength);
|
|
91
|
-
|
|
92
|
-
let offset = 0;
|
|
93
|
-
for (const chunk of chunks) {
|
|
94
|
-
mergedArray.set(chunk as any, offset);
|
|
95
|
-
offset += chunk.length;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return mergedArray;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (isArrayBuffer(firstChunk)) {
|
|
102
|
-
const chunks = data as ArrayBuffer[];
|
|
103
|
-
|
|
104
|
-
const totalLength = data.reduce((len, chunk) => len + chunk.byteLength, 0);
|
|
105
|
-
const mergedArray = new Uint8Array(totalLength);
|
|
106
|
-
|
|
107
|
-
let offset = 0;
|
|
108
|
-
for (const chunk of chunks) {
|
|
109
|
-
mergedArray.set(new Uint8Array(chunk), offset);
|
|
110
|
-
offset += chunk.byteLength;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return mergedArray.buffer;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
throw new TypeError({
|
|
117
|
-
actualValue: firstChunk satisfies never,
|
|
118
|
-
expectedType: "ArrayBuffer | TypedArray",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return data;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public getReadable(key: Key): ReadableStream {
|
|
126
|
-
const data = this.store.get(key);
|
|
127
|
-
|
|
128
|
-
return new ReadableStream({
|
|
129
|
-
start(controller) {
|
|
130
|
-
if (data !== undefined) {
|
|
131
|
-
if (data instanceof Chunks) {
|
|
132
|
-
for (const chunk of data) {
|
|
133
|
-
controller.enqueue(chunk);
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
controller.enqueue(data);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
controller.close();
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public exists(key: Key): boolean {
|
|
146
|
-
return this.store.has(key);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// public keys(): Iterable<Key> {
|
|
150
|
-
// return this.store.keys();
|
|
151
|
-
// }
|
|
152
|
-
|
|
153
|
-
public delete(key: Key): void {
|
|
154
|
-
this.store.delete(key);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public clear(): void {
|
|
158
|
-
this.store.clear();
|
|
159
|
-
}
|
|
160
|
-
}
|
package/src/types/storage.ts
DELETED
package/src/types/transformer.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|