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.
Files changed (146) hide show
  1. package/dist/src/_combine-signals.d.ts +9 -0
  2. package/dist/src/_combine-signals.d.ts.map +1 -0
  3. package/dist/src/_combine-signals.js +59 -0
  4. package/dist/src/_logger.d.ts +3 -0
  5. package/dist/src/_logger.d.ts.map +1 -0
  6. package/dist/src/_logger.js +3 -0
  7. package/dist/src/_merge-context.d.ts +4 -0
  8. package/dist/src/_merge-context.d.ts.map +1 -0
  9. package/dist/src/_merge-context.js +3 -0
  10. package/dist/src/_storage.d.ts +17 -0
  11. package/dist/src/_storage.d.ts.map +1 -0
  12. package/dist/src/_storage.js +84 -0
  13. package/dist/src/_to-value-stream.d.ts +12 -0
  14. package/dist/src/_to-value-stream.d.ts.map +1 -0
  15. package/dist/src/_to-value-stream.js +53 -0
  16. package/dist/src/_transformer.d.ts +12 -0
  17. package/dist/src/_transformer.d.ts.map +1 -0
  18. package/dist/src/_transformer.js +52 -0
  19. package/dist/src/_valibot.d.ts +13 -0
  20. package/dist/src/_valibot.d.ts.map +1 -0
  21. package/dist/src/_valibot.js +12 -0
  22. package/dist/src/context.types.d.ts +17 -0
  23. package/dist/src/context.types.d.ts.map +1 -0
  24. package/dist/src/errors.d.ts +108 -0
  25. package/dist/src/errors.d.ts.map +1 -0
  26. package/dist/src/errors.js +169 -0
  27. package/dist/src/index.d.ts +10 -0
  28. package/dist/src/index.d.ts.map +1 -0
  29. package/dist/src/index.js +3 -0
  30. package/dist/src/unikvs-config.d.ts +255 -0
  31. package/dist/src/unikvs-config.d.ts.map +1 -0
  32. package/dist/src/unikvs-config.js +105 -0
  33. package/dist/src/unikvs.d.ts +324 -0
  34. package/dist/src/unikvs.d.ts.map +1 -0
  35. package/dist/src/unikvs.js +693 -0
  36. package/dist/src/utils.types.d.ts +7 -0
  37. package/dist/src/utils.types.d.ts.map +1 -0
  38. package/dist/src/value-stream.types.d.ts +11 -0
  39. package/dist/src/value-stream.types.d.ts.map +1 -0
  40. package/package.json +22 -39
  41. package/src/_combine-signals.ts +67 -0
  42. package/src/_logger.ts +5 -0
  43. package/src/_merge-context.ts +10 -0
  44. package/src/_storage.ts +130 -0
  45. package/src/_to-value-stream.ts +59 -0
  46. package/src/_transformer.ts +75 -0
  47. package/src/_valibot.ts +30 -0
  48. package/src/context.types.ts +19 -0
  49. package/src/errors.ts +382 -0
  50. package/src/index.ts +52 -0
  51. package/src/unikvs-config.ts +429 -0
  52. package/src/unikvs.ts +1171 -0
  53. package/src/utils.types.ts +6 -0
  54. package/src/value-stream.types.ts +14 -0
  55. package/dist/src/core/_assign-context.d.ts +0 -3
  56. package/dist/src/core/_assign-context.d.ts.map +0 -1
  57. package/dist/src/core/_assign-context.js +0 -3
  58. package/dist/src/core/_combine-signals.d.ts +0 -3
  59. package/dist/src/core/_combine-signals.d.ts.map +0 -1
  60. package/dist/src/core/_combine-signals.js +0 -34
  61. package/dist/src/core/_is-iterable.d.ts +0 -2
  62. package/dist/src/core/_is-iterable.d.ts.map +0 -1
  63. package/dist/src/core/_is-iterable.js +0 -3
  64. package/dist/src/core/_is-plain-object.d.ts +0 -2
  65. package/dist/src/core/_is-plain-object.d.ts.map +0 -1
  66. package/dist/src/core/_is-plain-object.js +0 -7
  67. package/dist/src/core/_logger.d.ts +0 -3
  68. package/dist/src/core/_logger.d.ts.map +0 -1
  69. package/dist/src/core/_logger.js +0 -3
  70. package/dist/src/core/_merge-context.d.ts +0 -3
  71. package/dist/src/core/_merge-context.d.ts.map +0 -1
  72. package/dist/src/core/_merge-context.js +0 -4
  73. package/dist/src/core/_to-context.d.ts +0 -7
  74. package/dist/src/core/_to-context.d.ts.map +0 -1
  75. package/dist/src/core/_to-context.js +0 -42
  76. package/dist/src/core/_to-value-stream.d.ts +0 -4
  77. package/dist/src/core/_to-value-stream.d.ts.map +0 -1
  78. package/dist/src/core/_to-value-stream.js +0 -38
  79. package/dist/src/core/_with-readable-stream-from.d.ts +0 -6
  80. package/dist/src/core/_with-readable-stream-from.d.ts.map +0 -1
  81. package/dist/src/core/_with-readable-stream-from.js +0 -58
  82. package/dist/src/core/context.types.d.ts +0 -5
  83. package/dist/src/core/context.types.d.ts.map +0 -1
  84. package/dist/src/core/errors.d.ts +0 -13
  85. package/dist/src/core/errors.d.ts.map +0 -1
  86. package/dist/src/core/errors.js +0 -20
  87. package/dist/src/core/index.d.ts +0 -15
  88. package/dist/src/core/index.d.ts.map +0 -1
  89. package/dist/src/core/index.js +0 -4
  90. package/dist/src/core/plugin.types.d.ts +0 -8
  91. package/dist/src/core/plugin.types.d.ts.map +0 -1
  92. package/dist/src/core/plugin.types.js +0 -1
  93. package/dist/src/core/storage.types.d.ts +0 -22
  94. package/dist/src/core/storage.types.d.ts.map +0 -1
  95. package/dist/src/core/storage.types.js +0 -1
  96. package/dist/src/core/to-readable-stream.d.ts +0 -2
  97. package/dist/src/core/to-readable-stream.d.ts.map +0 -1
  98. package/dist/src/core/to-readable-stream.js +0 -4
  99. package/dist/src/core/transformer.types.d.ts +0 -18
  100. package/dist/src/core/transformer.types.d.ts.map +0 -1
  101. package/dist/src/core/transformer.types.js +0 -1
  102. package/dist/src/core/unikvs-config.d.ts +0 -82
  103. package/dist/src/core/unikvs-config.d.ts.map +0 -1
  104. package/dist/src/core/unikvs-config.js +0 -49
  105. package/dist/src/core/unikvs.d.ts +0 -73
  106. package/dist/src/core/unikvs.d.ts.map +0 -1
  107. package/dist/src/core/unikvs.js +0 -678
  108. package/dist/src/core/utils.types.d.ts +0 -3
  109. package/dist/src/core/utils.types.d.ts.map +0 -1
  110. package/dist/src/core/value-stream.types.d.ts +0 -4
  111. package/dist/src/core/value-stream.types.d.ts.map +0 -1
  112. package/dist/src/destinations/memory-storage.d.ts +0 -17
  113. package/dist/src/destinations/memory-storage.d.ts.map +0 -1
  114. package/dist/src/destinations/memory-storage.js +0 -113
  115. package/dist/src/types/storage.d.ts +0 -5
  116. package/dist/src/types/storage.d.ts.map +0 -1
  117. package/dist/src/types/storage.js +0 -1
  118. package/dist/src/types/transformer.d.ts +0 -5
  119. package/dist/src/types/transformer.d.ts.map +0 -1
  120. package/dist/src/types/transformer.js +0 -1
  121. package/src/core/_assign-context.ts +0 -5
  122. package/src/core/_combine-signals.ts +0 -40
  123. package/src/core/_is-iterable.ts +0 -3
  124. package/src/core/_is-plain-object.ts +0 -11
  125. package/src/core/_logger.ts +0 -5
  126. package/src/core/_merge-context.ts +0 -9
  127. package/src/core/_to-context.ts +0 -59
  128. package/src/core/_to-value-stream.ts +0 -41
  129. package/src/core/_with-readable-stream-from.ts +0 -70
  130. package/src/core/context.types.ts +0 -7
  131. package/src/core/errors.ts +0 -37
  132. package/src/core/index.ts +0 -23
  133. package/src/core/plugin.types.ts +0 -10
  134. package/src/core/storage.types.ts +0 -53
  135. package/src/core/to-readable-stream.ts +0 -7
  136. package/src/core/transformer.types.ts +0 -110
  137. package/src/core/unikvs-config.ts +0 -230
  138. package/src/core/unikvs.ts +0 -740
  139. package/src/core/utils.types.ts +0 -3
  140. package/src/core/value-stream.types.ts +0 -3
  141. package/src/destinations/memory-storage.ts +0 -160
  142. package/src/types/storage.ts +0 -5
  143. package/src/types/transformer.ts +0 -5
  144. /package/dist/src/{core/context.types.js → context.types.js} +0 -0
  145. /package/dist/src/{core/utils.types.js → utils.types.js} +0 -0
  146. /package/dist/src/{core/value-stream.types.js → value-stream.types.js} +0 -0
@@ -1,3 +0,0 @@
1
- export type ValueOf<T> = T[keyof T];
2
-
3
- export type MaybePromise<T> = T | PromiseLike<T>;
@@ -1,3 +0,0 @@
1
- export interface ValueStream<T> extends ReadableStream<T> {
2
- [Symbol.asyncIterator](): AsyncIteratorObject<T, undefined, unknown>;
3
- }
@@ -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
- }
@@ -1,5 +0,0 @@
1
- export type { Context } from "../core/context.types.js";
2
- export type { IPlugin } from "../core/plugin.types.js";
3
- export type { MaybePromise } from "../core/utils.types.js";
4
-
5
- export type * from "../core/storage.types.js";
@@ -1,5 +0,0 @@
1
- export type { Context } from "../core/context.types.js";
2
- export type { IPlugin } from "../core/plugin.types.js";
3
- export type { MaybePromise } from "../core/utils.types.js";
4
-
5
- export type * from "../core/transformer.types.js";