@peerbit/document-interface 6.0.7-a9206a8 → 6.0.7-cccc078

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/document-interface",
3
- "version": "6.0.7-a9206a8",
3
+ "version": "6.0.7-cccc078",
4
4
  "description": "Document store interface",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "eslintConfig": {
38
- "extends": "ipfs",
38
+ "extends": "peerbit",
39
39
  "parserOptions": {
40
40
  "project": true,
41
41
  "sourceType": "module"
@@ -52,12 +52,14 @@
52
52
  "scripts": {
53
53
  "clean": "aegir clean",
54
54
  "build": "aegir build --no-bundle",
55
- "test": "aegir test"
55
+ "test": "",
56
+ "lint": "aegir lint"
56
57
  },
57
58
  "author": "dao.xyz",
58
59
  "license": "MIT",
59
60
  "dependencies": {
60
- "@dao-xyz/borsh": "^5.2.2",
61
- "@peerbit/crypto": "2.2.0-a9206a8"
61
+ "@dao-xyz/borsh": "^5.2.3",
62
+ "@peerbit/crypto": "2.2.0-cccc078",
63
+ "@peerbit/indexer-interface": "0.0.1-cccc078"
62
64
  }
63
65
  }
package/src/index.ts CHANGED
@@ -1,5 +1,2 @@
1
- export * from "./id.js";
2
1
  export * from "./query.js";
3
- export * from "./index-engine.js";
4
2
  export * from "./store.js";
5
- export * from "./utils.js";
package/src/query.ts CHANGED
@@ -2,328 +2,13 @@ import {
2
2
  type AbstractType,
3
3
  deserialize,
4
4
  field,
5
- fixedArray,
6
- serialize,
7
5
  variant,
8
- vec
6
+ vec,
9
7
  } from "@dao-xyz/borsh";
10
8
 
11
- import { randomBytes, sha256Base64Sync, toBase64 } from "@peerbit/crypto";
12
- import {
13
- BigUnsignedIntegerValue,
14
- IntegerValue,
15
- UnsignedIntegerValue
16
- } from "./id.js";
17
-
18
- export enum Compare {
19
- Equal = 0,
20
- Greater = 1,
21
- GreaterOrEqual = 2,
22
- Less = 3,
23
- LessOrEqual = 4
24
- }
25
- export const compare = (
26
- test: bigint | number,
27
- compare: Compare,
28
- value: bigint | number
29
- ) => {
30
- switch (compare) {
31
- case Compare.Equal:
32
- return test == value; // == because with want bigint == number at some cases
33
- case Compare.Greater:
34
- return test > value;
35
- case Compare.GreaterOrEqual:
36
- return test >= value;
37
- case Compare.Less:
38
- return test < value;
39
- case Compare.LessOrEqual:
40
- return test <= value;
41
- default:
42
- console.warn("Unexpected compare");
43
- return false;
44
- }
45
- };
46
-
47
- /// ----- QUERY -----
48
-
49
- export abstract class Query {
50
- clone() {
51
- return deserialize(serialize(this), this.constructor) as this;
52
- }
53
- }
54
-
55
- export enum SortDirection {
56
- ASC = 0,
57
- DESC = 1
58
- }
59
-
60
- @variant(0)
61
- export class Sort {
62
- @field({ type: vec("string") })
63
- key: string[];
64
-
65
- @field({ type: "u8" })
66
- direction: SortDirection;
67
-
68
- constructor(properties: {
69
- key: string[] | string;
70
- direction?: SortDirection;
71
- }) {
72
- this.key = Array.isArray(properties.key)
73
- ? properties.key
74
- : [properties.key];
75
- this.direction = properties.direction || SortDirection.ASC;
76
- }
77
- }
78
-
79
- export abstract class AbstractSearchRequest { }
80
-
81
- /**
82
- * Search with query and collect with sort conditionss
83
- */
84
-
85
- const toArray = <T>(arr: T | T[] | undefined) =>
86
- (arr ? (Array.isArray(arr) ? arr : [arr]) : undefined) || [];
87
-
88
- @variant(0)
89
- export class SearchRequest extends AbstractSearchRequest {
90
- @field({ type: fixedArray("u8", 32) })
91
- id: Uint8Array; // Session id
92
-
93
- @field({ type: vec(Query) })
94
- query: Query[];
95
-
96
- @field({ type: vec(Sort) })
97
- sort: Sort[];
98
-
99
- @field({ type: "u32" })
100
- fetch: number;
101
-
102
- constructor(props?: { query?: Query[] | Query; sort?: Sort[] | Sort }) {
103
- super();
104
- this.id = randomBytes(32);
105
- this.query = toArray(props?.query);
106
- this.sort = toArray(props?.sort);
107
- this.fetch = 1;
108
- }
109
-
110
- private _idString: string;
111
- get idString(): string {
112
- return this._idString || (this._idString = sha256Base64Sync(this.id));
113
- }
114
- }
115
-
116
- /**
117
- * Collect documents from peers using 'collect' session ids. This is used for distributed sorting internally
118
- */
119
- @variant(2)
120
- export class CollectNextRequest extends AbstractSearchRequest {
121
- @field({ type: fixedArray("u8", 32) })
122
- id: Uint8Array; // collect with id
123
-
124
- @field({ type: "u32" })
125
- amount: number; // number of documents to ask for
126
-
127
- constructor(properties: { id: Uint8Array; amount: number }) {
128
- super();
129
- this.id = properties.id;
130
- this.amount = properties.amount;
131
- }
132
-
133
- private _idString: string;
134
- get idString(): string {
135
- return this._idString || (this._idString = sha256Base64Sync(this.id));
136
- }
137
- }
138
-
139
- @variant(3)
140
- export class CloseIteratorRequest extends AbstractSearchRequest {
141
- @field({ type: fixedArray("u8", 32) })
142
- id: Uint8Array; // collect with id
143
-
144
- constructor(properties: { id: Uint8Array }) {
145
- super();
146
- this.id = properties.id;
147
- }
148
-
149
- private _idString: string;
150
- get idString(): string {
151
- return this._idString || (this._idString = sha256Base64Sync(this.id));
152
- }
153
- }
154
-
155
- @variant(1)
156
- export abstract class LogicalQuery extends Query { }
157
-
158
- @variant(0)
159
- export class And extends LogicalQuery {
160
- @field({ type: vec(Query) })
161
- and: Query[];
162
-
163
- constructor(and: Query[]) {
164
- super();
165
- this.and = and;
166
- }
167
- }
168
-
169
- @variant(1)
170
- export class Or extends LogicalQuery {
171
- @field({ type: vec(Query) })
172
- or: Query[];
173
-
174
- constructor(or: Query[]) {
175
- super();
176
- this.or = or;
177
- }
178
- }
179
-
180
- @variant(2)
181
- export abstract class StateQuery extends Query { }
182
-
183
- @variant(1)
184
- export class StateFieldQuery extends StateQuery {
185
- @field({ type: vec("string") })
186
- key: string[];
187
-
188
- constructor(props: { key: string[] | string }) {
189
- super();
190
- this.key = Array.isArray(props.key) ? props.key : [props.key];
191
- }
192
- }
193
-
194
- @variant(1)
195
- export class ByteMatchQuery extends StateFieldQuery {
196
- @field({ type: Uint8Array })
197
- value: Uint8Array;
198
-
199
- @field({ type: "u8" })
200
- // @ts-ignore: unused
201
- private _reserved: number; // Replcate MemoryCompare query with this?
202
-
203
- constructor(props: { key: string[] | string; value: Uint8Array }) {
204
- super(props);
205
- this.value = props.value;
206
- this._reserved = 0;
207
- }
208
-
209
- _valueString: string;
210
- /**
211
- * value `asString`
212
- */
213
- get valueString() {
214
- return this._valueString ?? (this._valueString = toBase64(this.value));
215
- }
216
- }
217
-
218
- export enum StringMatchMethod {
219
- "exact" = 0,
220
- "prefix" = 1,
221
- "contains" = 2
222
- }
223
-
224
- @variant(2)
225
- export class StringMatch extends StateFieldQuery {
226
- @field({ type: "string" })
227
- value: string;
228
-
229
- @field({ type: "u8" })
230
- method: StringMatchMethod;
231
-
232
- @field({ type: "bool" })
233
- caseInsensitive: boolean;
234
-
235
- constructor(props: {
236
- key: string[] | string;
237
- value: string;
238
- method?: StringMatchMethod;
239
- caseInsensitive?: boolean;
240
- }) {
241
- super(props);
242
- this.value = props.value;
243
- this.method = props.method ?? StringMatchMethod.exact;
244
- this.caseInsensitive = props.caseInsensitive ?? false;
245
- }
246
- }
247
-
248
- @variant(3)
249
- export class IntegerCompare extends StateFieldQuery {
250
- @field({ type: "u8" })
251
- compare: Compare;
252
-
253
- @field({ type: IntegerValue })
254
- value: IntegerValue;
255
-
256
- constructor(props: {
257
- key: string[] | string;
258
- value: bigint | number | IntegerValue;
259
- compare: Compare;
260
- }) {
261
- super(props);
262
- if (props.value instanceof IntegerValue) {
263
- this.value = props.value;
264
- } else {
265
- if (typeof props.value === "bigint") {
266
- this.value = new BigUnsignedIntegerValue(props.value);
267
- } else {
268
- this.value = new UnsignedIntegerValue(props.value);
269
- }
270
- }
271
-
272
- this.compare = props.compare;
273
- }
274
- }
275
-
276
- @variant(4)
277
- export class MissingField extends StateFieldQuery {
278
- constructor(props: { key: string[] | string }) {
279
- super(props);
280
- }
281
- }
282
-
283
- @variant(5)
284
- export class BoolQuery extends StateFieldQuery {
285
- @field({ type: "bool" })
286
- value: boolean;
287
-
288
- constructor(props: { key: string[] | string; value: boolean }) {
289
- super(props);
290
- this.value = props.value;
291
- }
292
- }
293
-
294
- // TODO MemoryCompareQuery can be replaces with ByteMatchQuery? Or Nesteed Queries + ByteMatchQuery?
295
- /* @variant(0)
296
- export class MemoryCompare {
297
- @field({ type: Uint8Array })
298
- bytes: Uint8Array;
299
-
300
- @field({ type: "u64" })
301
- offset: bigint;
302
-
303
- constructor(opts?: { bytes: Uint8Array; offset: bigint }) {
304
- if (opts) {
305
- this.bytes = opts.bytes;
306
- this.offset = opts.offset;
307
- }
308
- }
309
- }
310
-
311
- @variant(4)
312
- export class MemoryCompareQuery extends Query {
313
- @field({ type: vec(MemoryCompare) })
314
- compares: MemoryCompare[];
315
-
316
- constructor(opts?: { compares: MemoryCompare[] }) {
317
- super();
318
- if (opts) {
319
- this.compares = opts.compares;
320
- }
321
- }
322
- } */
323
-
324
9
  /// ----- RESULTS -----
325
10
 
326
- export abstract class Result { }
11
+ export abstract class Result {}
327
12
 
328
13
  @variant(0)
329
14
  export class Context {
@@ -339,16 +24,21 @@ export class Context {
339
24
  @field({ type: "string" })
340
25
  gid: string;
341
26
 
27
+ @field({ type: "u32" })
28
+ size: number; // bytes
29
+
342
30
  constructor(properties: {
343
31
  created: bigint;
344
32
  modified: bigint;
345
33
  head: string;
346
34
  gid: string;
35
+ size: number;
347
36
  }) {
348
37
  this.created = properties.created;
349
38
  this.modified = properties.modified;
350
39
  this.head = properties.head;
351
40
  this.gid = properties.gid;
41
+ this.size = properties.size;
352
42
  }
353
43
  }
354
44
 
@@ -390,10 +80,12 @@ export class ResultWithSource<T> extends Result {
390
80
  return this._value;
391
81
  }
392
82
 
83
+ // we never send this over the wire since we can always reconstruct it from value
393
84
  indexed?: Record<string, any>;
394
85
  }
395
86
 
396
- export abstract class AbstractSearchResult<T> { }
87
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
88
+ export abstract class AbstractSearchResult<T> {}
397
89
 
398
90
  @variant(0)
399
91
  export class Results<T> extends AbstractSearchResult<T> {
@@ -411,7 +103,7 @@ export class Results<T> extends AbstractSearchResult<T> {
411
103
  }
412
104
 
413
105
  @variant(1)
414
- export class NoAccess extends AbstractSearchResult<any> { }
106
+ export class NoAccess extends AbstractSearchResult<any> {}
415
107
 
416
108
  /* @variant(5)
417
109
  export class LogQuery extends Query { } */
package/src/store.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { SearchRequest } from "./query.js";
2
-
3
1
  export type IDocumentStore<T> = {
4
- index: { search: (query: SearchRequest) => Promise<T[]> };
2
+ index: { search: (query: any) => Promise<T[]> };
5
3
  };
package/dist/src/id.d.ts DELETED
@@ -1,47 +0,0 @@
1
- export declare abstract class PrimitiveValue {
2
- }
3
- export declare class StringValue extends PrimitiveValue {
4
- string: string;
5
- constructor(string: string);
6
- }
7
- export declare abstract class NumberValue extends PrimitiveValue {
8
- abstract get value(): number | bigint;
9
- }
10
- export declare abstract class IntegerValue extends NumberValue {
11
- }
12
- export declare class UnsignedIntegerValue extends IntegerValue {
13
- number: number;
14
- constructor(number: number);
15
- get value(): number;
16
- }
17
- export declare class BigUnsignedIntegerValue extends IntegerValue {
18
- number: bigint;
19
- constructor(number: bigint);
20
- get value(): bigint;
21
- }
22
- export type IdPrimitive = string | number | bigint;
23
- export declare abstract class IdKey {
24
- abstract get key(): string | bigint | number | Uint8Array;
25
- abstract get primitive(): IdPrimitive;
26
- }
27
- export declare class StringKey extends IdKey {
28
- key: string;
29
- constructor(key: string);
30
- get primitive(): string;
31
- }
32
- export declare class Uint8ArrayKey extends IdKey {
33
- key: Uint8Array;
34
- constructor(key: Uint8Array);
35
- private _keyString;
36
- get primitive(): string;
37
- }
38
- export declare class IntegerKey extends IdKey {
39
- key: number;
40
- constructor(key: number);
41
- get primitive(): number;
42
- }
43
- export type Ideable = string | number | bigint | Uint8Array;
44
- export declare const toId: (obj: Ideable) => IdKey;
45
- export declare const toIdeable: (key: IdKey | Ideable) => string | number | bigint;
46
- export declare const checkId: (obj: Ideable) => void;
47
- //# sourceMappingURL=id.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":"AAQA,8BAAsB,cAAc;CAAI;AAExC,qBACa,WAAY,SAAQ,cAAc;IAE9C,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM;CAI1B;AAED,8BACsB,WAAY,SAAQ,cAAc;IACvD,QAAQ,KAAK,KAAK,IAAI,MAAM,GAAG,MAAM,CAAC;CACtC;AAED,8BACsB,YAAa,SAAQ,WAAW;CAAI;AAE1D,qBACa,oBAAqB,SAAQ,YAAY;IAErD,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM;IAY1B,IAAI,KAAK,WAER;CACD;AAED,qBACa,uBAAwB,SAAQ,YAAY;IAExD,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM;IAO1B,IAAI,KAAK,WAER;CACD;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnD,8BAAsB,KAAK;IAC1B,QAAQ,KAAK,GAAG,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;IAC1D,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC;CACtC;AAED,qBACa,SAAU,SAAQ,KAAK;IAEnC,GAAG,EAAE,MAAM,CAAC;gBAEA,GAAG,EAAE,MAAM;IAIvB,IAAI,SAAS,WAEZ;CACD;AAED,qBACa,aAAc,SAAQ,KAAK;IAEvC,GAAG,EAAE,UAAU,CAAC;gBAEJ,GAAG,EAAE,UAAU;IAK3B,OAAO,CAAC,UAAU,CAAS;IAC3B,IAAI,SAAS,IAAI,MAAM,CAEtB;CACD;AAgBD,qBACa,UAAW,SAAQ,KAAK;IAEpC,GAAG,EAAE,MAAM,CAAC;gBAEA,GAAG,EAAE,MAAM;IAKvB,IAAI,SAAS,WAEZ;CACD;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAI5D,eAAO,MAAM,IAAI,QAAS,OAAO,KAAG,KAuBnC,CAAC;AAEF,eAAO,MAAM,SAAS,QAAS,KAAK,GAAG,OAAO,KAAG,MAAM,GAAG,MAAM,GAAG,MAsBlE,CAAC;AAEF,eAAO,MAAM,OAAO,QAAS,OAAO,SAqBnC,CAAC"}
package/dist/src/id.js DELETED
@@ -1,217 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { field, variant } from "@dao-xyz/borsh";
11
- import { toBase64 } from "@peerbit/crypto";
12
- import { decodeUint8Array, encodeUint8Array, encodingLength } from "uint8-varint";
13
- export class PrimitiveValue {
14
- }
15
- let StringValue = class StringValue extends PrimitiveValue {
16
- string;
17
- constructor(string) {
18
- super();
19
- this.string = string;
20
- }
21
- };
22
- __decorate([
23
- field({ type: "string" }),
24
- __metadata("design:type", String)
25
- ], StringValue.prototype, "string", void 0);
26
- StringValue = __decorate([
27
- variant(0),
28
- __metadata("design:paramtypes", [String])
29
- ], StringValue);
30
- export { StringValue };
31
- let NumberValue = class NumberValue extends PrimitiveValue {
32
- };
33
- NumberValue = __decorate([
34
- variant(1)
35
- ], NumberValue);
36
- export { NumberValue };
37
- let IntegerValue = class IntegerValue extends NumberValue {
38
- };
39
- IntegerValue = __decorate([
40
- variant(0)
41
- ], IntegerValue);
42
- export { IntegerValue };
43
- let UnsignedIntegerValue = class UnsignedIntegerValue extends IntegerValue {
44
- number;
45
- constructor(number) {
46
- super();
47
- if (Number.isInteger(number) === false ||
48
- number > 4294967295 ||
49
- number < 0) {
50
- throw new Error("Number is not u32");
51
- }
52
- this.number = number;
53
- }
54
- get value() {
55
- return this.number;
56
- }
57
- };
58
- __decorate([
59
- field({ type: "u32" }),
60
- __metadata("design:type", Number)
61
- ], UnsignedIntegerValue.prototype, "number", void 0);
62
- UnsignedIntegerValue = __decorate([
63
- variant(0),
64
- __metadata("design:paramtypes", [Number])
65
- ], UnsignedIntegerValue);
66
- export { UnsignedIntegerValue };
67
- let BigUnsignedIntegerValue = class BigUnsignedIntegerValue extends IntegerValue {
68
- number;
69
- constructor(number) {
70
- super();
71
- if (number > 18446744073709551615n || number < 0) {
72
- throw new Error("Number is not u32");
73
- }
74
- this.number = number;
75
- }
76
- get value() {
77
- return this.number;
78
- }
79
- };
80
- __decorate([
81
- field({ type: "u64" }),
82
- __metadata("design:type", BigInt)
83
- ], BigUnsignedIntegerValue.prototype, "number", void 0);
84
- BigUnsignedIntegerValue = __decorate([
85
- variant(1),
86
- __metadata("design:paramtypes", [BigInt])
87
- ], BigUnsignedIntegerValue);
88
- export { BigUnsignedIntegerValue };
89
- export class IdKey {
90
- }
91
- let StringKey = class StringKey extends IdKey {
92
- key;
93
- constructor(key) {
94
- super();
95
- this.key = key;
96
- }
97
- get primitive() {
98
- return this.key;
99
- }
100
- };
101
- __decorate([
102
- field({ type: "string" }),
103
- __metadata("design:type", String)
104
- ], StringKey.prototype, "key", void 0);
105
- StringKey = __decorate([
106
- variant(0),
107
- __metadata("design:paramtypes", [String])
108
- ], StringKey);
109
- export { StringKey };
110
- let Uint8ArrayKey = class Uint8ArrayKey extends IdKey {
111
- key;
112
- constructor(key) {
113
- super();
114
- this.key = key;
115
- }
116
- _keyString;
117
- get primitive() {
118
- return this._keyString || (this._keyString = toBase64(this.key));
119
- }
120
- };
121
- __decorate([
122
- field({ type: Uint8Array }),
123
- __metadata("design:type", Uint8Array)
124
- ], Uint8ArrayKey.prototype, "key", void 0);
125
- Uint8ArrayKey = __decorate([
126
- variant(1),
127
- __metadata("design:paramtypes", [Uint8Array])
128
- ], Uint8ArrayKey);
129
- export { Uint8ArrayKey };
130
- const varint53 = {
131
- deserialize: (reader) => {
132
- const number = decodeUint8Array(reader._buf, reader._offset);
133
- const len = encodingLength(number);
134
- reader._offset += len;
135
- return number;
136
- },
137
- serialize: (value, writer) => {
138
- const offset = writer.totalSize;
139
- writer["_writes"] = writer["_writes"].next = () => encodeUint8Array(value, writer["_buf"], offset);
140
- writer.totalSize += encodingLength(value);
141
- }
142
- };
143
- let IntegerKey = class IntegerKey extends IdKey {
144
- key;
145
- constructor(key) {
146
- super();
147
- this.key = key;
148
- }
149
- get primitive() {
150
- return this.key;
151
- }
152
- };
153
- __decorate([
154
- field(varint53) // max value is 2^53 - 1 (9007199254740991)
155
- ,
156
- __metadata("design:type", Number)
157
- ], IntegerKey.prototype, "key", void 0);
158
- IntegerKey = __decorate([
159
- variant(2),
160
- __metadata("design:paramtypes", [Number])
161
- ], IntegerKey);
162
- export { IntegerKey };
163
- const idKeyTypes = new Set(["string", "number", "bigint"]);
164
- export const toId = (obj) => {
165
- if (typeof obj === "string") {
166
- return new StringKey(obj);
167
- }
168
- if (typeof obj === "number") {
169
- return new IntegerKey(obj);
170
- }
171
- if (typeof obj === "bigint") {
172
- if (obj <= Number.MAX_SAFE_INTEGER && obj >= 0) {
173
- return new IntegerKey(Number(obj));
174
- }
175
- throw new Error("BigInt is not less than 2^53. Max value is 9007199254740991");
176
- }
177
- if (obj instanceof Uint8Array) {
178
- return new Uint8ArrayKey(obj);
179
- }
180
- throw new Error("Unexpected index key: " +
181
- typeof obj +
182
- ", expected: string, number, bigint or Uint8Array");
183
- };
184
- export const toIdeable = (key) => {
185
- if (key instanceof IdKey) {
186
- return key.primitive;
187
- }
188
- if (typeof key === "string") {
189
- return key;
190
- }
191
- if (typeof key === "number") {
192
- return key;
193
- }
194
- if (typeof key === "bigint") {
195
- return key;
196
- }
197
- if (key instanceof Uint8Array) {
198
- return toBase64(key);
199
- }
200
- throw new Error("Unexpected index key: " + typeof key);
201
- };
202
- export const checkId = (obj) => {
203
- if (obj == null) {
204
- throw new Error(`The provided key value is null or undefined, expecting string, number, bigint, or Uint8array`);
205
- }
206
- const type = typeof obj;
207
- if (type === "number") {
208
- if (Number.isInteger(obj) === false) {
209
- throw new Error(`The provided key number value is not an integer`);
210
- }
211
- }
212
- if (idKeyTypes.has(type) || obj instanceof Uint8Array) {
213
- return;
214
- }
215
- throw new Error(`Key is not ${[...idKeyTypes]}, provided key value type: ${typeof obj}`);
216
- };
217
- //# sourceMappingURL=id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/id.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,MAAM,cAAc,CAAC;AAEtB,MAAM,OAAgB,cAAc;CAAI;AAGjC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,cAAc;IAE9C,MAAM,CAAS;IAEf,YAAY,MAAc;QACzB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD,CAAA;AANA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;2CACX;AAFH,WAAW;IADvB,OAAO,CAAC,CAAC,CAAC;;GACE,WAAW,CAQvB;;AAGM,IAAe,WAAW,GAA1B,MAAe,WAAY,SAAQ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