@chaincraft/core 1.4.0 → 1.6.0
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/README.md +3 -3
- package/dist/consensusPoa.d.ts +26 -0
- package/dist/consensusPoa.js +129 -0
- package/dist/features.d.ts +2 -2
- package/dist/features.js +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/storage.d.ts +10 -1
- package/dist/storage.js +142 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
TypeScript implementation of the Chaincraft wire protocol, object semantics, and
|
|
4
4
|
Level 2 stack (consensus, ledgers, BitTorrent, channels). Same observable
|
|
5
5
|
behaviour as the Python `chaincraft` package and the Rust `chaincraft` crate.
|
|
6
|
-
Release **[1.
|
|
7
|
-
1.
|
|
8
|
-
|
|
6
|
+
Release **[1.6.0](https://www.npmjs.com/package/@chaincraft/core)** on npm.
|
|
7
|
+
1.6.0 adds `consensus.poa` (Proof of Authority with rotation by height).
|
|
8
|
+
45 of 46 registry features implemented plus the UDP framing exemption.
|
|
9
9
|
|
|
10
10
|
Open-source toolkit for peer-to-peer protocols like blockchains, chat rooms,
|
|
11
11
|
BitTorrent swarms, and content-addressed stores.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Proof-of-authority object — SPEC/features/consensus-poa.md. */
|
|
2
|
+
import type { JsonValue } from './canonical.ts';
|
|
3
|
+
import { StateMemento } from './memento.ts';
|
|
4
|
+
import { BaseSharedObject } from './object.ts';
|
|
5
|
+
export declare function proposerFor(height: number, authorities: readonly string[]): string;
|
|
6
|
+
export declare function blockId(height: number, parent: string, payload: string, proposer: string): string;
|
|
7
|
+
export declare class ProofOfAuthority extends BaseSharedObject {
|
|
8
|
+
readonly authorities: readonly string[];
|
|
9
|
+
private readonly blocks;
|
|
10
|
+
private readonly order;
|
|
11
|
+
constructor(authorities: readonly string[]);
|
|
12
|
+
isValid(message: JsonValue): boolean;
|
|
13
|
+
addMessage(message: JsonValue, _frontierState?: StateMemento | undefined): StateMemento | undefined;
|
|
14
|
+
emitStateMemento(): StateMemento;
|
|
15
|
+
getStateDigests(): string[];
|
|
16
|
+
isMerkelized(): boolean;
|
|
17
|
+
state(): {
|
|
18
|
+
blocks: string[];
|
|
19
|
+
canonical: string[];
|
|
20
|
+
height: number;
|
|
21
|
+
tip: string;
|
|
22
|
+
};
|
|
23
|
+
private canonical;
|
|
24
|
+
private tip;
|
|
25
|
+
private parse;
|
|
26
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** Proof-of-authority object — SPEC/features/consensus-poa.md. */
|
|
2
|
+
import { StateMemento } from "./memento.js";
|
|
3
|
+
import { BaseSharedObject, merkleDigest } from "./object.js";
|
|
4
|
+
function isInt(value) {
|
|
5
|
+
return typeof value === 'number' && Number.isSafeInteger(value);
|
|
6
|
+
}
|
|
7
|
+
function asRecord(message) {
|
|
8
|
+
if (message === null || typeof message !== 'object' || Array.isArray(message)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
export function proposerFor(height, authorities) {
|
|
14
|
+
const index = (height - 1) % authorities.length;
|
|
15
|
+
const proposer = authorities[index];
|
|
16
|
+
if (proposer === undefined) {
|
|
17
|
+
throw new RangeError('authorities must be non-empty');
|
|
18
|
+
}
|
|
19
|
+
return proposer;
|
|
20
|
+
}
|
|
21
|
+
export function blockId(height, parent, payload, proposer) {
|
|
22
|
+
return merkleDigest({ height, parent, payload, proposer });
|
|
23
|
+
}
|
|
24
|
+
export class ProofOfAuthority extends BaseSharedObject {
|
|
25
|
+
authorities;
|
|
26
|
+
blocks = new Map();
|
|
27
|
+
order = [];
|
|
28
|
+
constructor(authorities) {
|
|
29
|
+
super();
|
|
30
|
+
if (authorities.length === 0) {
|
|
31
|
+
throw new RangeError('authorities must be non-empty');
|
|
32
|
+
}
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
for (const authority of authorities) {
|
|
35
|
+
if (typeof authority !== 'string' || authority.length === 0) {
|
|
36
|
+
throw new RangeError('each authority must be a non-empty string');
|
|
37
|
+
}
|
|
38
|
+
if (seen.has(authority)) {
|
|
39
|
+
throw new RangeError('authorities must be distinct');
|
|
40
|
+
}
|
|
41
|
+
seen.add(authority);
|
|
42
|
+
}
|
|
43
|
+
this.authorities = [...authorities];
|
|
44
|
+
}
|
|
45
|
+
isValid(message) {
|
|
46
|
+
return this.parse(message) !== undefined;
|
|
47
|
+
}
|
|
48
|
+
addMessage(message, _frontierState) {
|
|
49
|
+
const parsed = this.parse(message);
|
|
50
|
+
if (parsed === undefined)
|
|
51
|
+
return this.emitStateMemento();
|
|
52
|
+
this.blocks.set(parsed.digest, parsed.record);
|
|
53
|
+
this.order.push(parsed.digest);
|
|
54
|
+
return this.emitStateMemento();
|
|
55
|
+
}
|
|
56
|
+
emitStateMemento() {
|
|
57
|
+
const tip = this.tip();
|
|
58
|
+
return StateMemento.normalize(merkleDigest({ height: tip.height, tip: tip.id, v: 1 }), []);
|
|
59
|
+
}
|
|
60
|
+
getStateDigests() {
|
|
61
|
+
const tip = this.tip();
|
|
62
|
+
return tip.id ? [tip.id] : [];
|
|
63
|
+
}
|
|
64
|
+
isMerkelized() {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
state() {
|
|
68
|
+
const tip = this.tip();
|
|
69
|
+
return {
|
|
70
|
+
blocks: [...this.order],
|
|
71
|
+
canonical: this.canonical(tip.id),
|
|
72
|
+
height: tip.height,
|
|
73
|
+
tip: tip.id,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
canonical(tip) {
|
|
77
|
+
const chain = [];
|
|
78
|
+
let cursor = tip;
|
|
79
|
+
while (cursor !== '') {
|
|
80
|
+
chain.push(cursor);
|
|
81
|
+
cursor = this.blocks.get(cursor)?.parent ?? '';
|
|
82
|
+
}
|
|
83
|
+
chain.reverse();
|
|
84
|
+
return chain;
|
|
85
|
+
}
|
|
86
|
+
tip() {
|
|
87
|
+
let id = '';
|
|
88
|
+
let height = 0;
|
|
89
|
+
for (const [digest, record] of this.blocks) {
|
|
90
|
+
if (record.height > height || (record.height === height && digest < id)) {
|
|
91
|
+
id = digest;
|
|
92
|
+
height = record.height;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { id, height };
|
|
96
|
+
}
|
|
97
|
+
parse(message) {
|
|
98
|
+
const record = asRecord(message);
|
|
99
|
+
if (record === undefined || record['consensus'] !== 'poa')
|
|
100
|
+
return undefined;
|
|
101
|
+
const height = record['height'];
|
|
102
|
+
const proposer = record['proposer'];
|
|
103
|
+
const parent = record['parent'];
|
|
104
|
+
const payload = record['payload'];
|
|
105
|
+
if (!isInt(height) || height < 1)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (typeof proposer !== 'string' || proposer.length === 0)
|
|
108
|
+
return undefined;
|
|
109
|
+
if (typeof parent !== 'string')
|
|
110
|
+
return undefined;
|
|
111
|
+
if (typeof payload !== 'string' || payload.length === 0)
|
|
112
|
+
return undefined;
|
|
113
|
+
if (proposer !== proposerFor(height, this.authorities))
|
|
114
|
+
return undefined;
|
|
115
|
+
if (parent === '') {
|
|
116
|
+
if (height !== 1)
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const prior = this.blocks.get(parent);
|
|
121
|
+
if (prior === undefined || height !== prior.height + 1)
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
const digest = blockId(height, parent, payload, proposer);
|
|
125
|
+
if (this.blocks.has(digest))
|
|
126
|
+
return undefined;
|
|
127
|
+
return { digest, record: { height, parent, payload, proposer } };
|
|
128
|
+
}
|
|
129
|
+
}
|
package/dist/features.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Add an ID here only when the feature is implemented and its vectors pass.
|
|
9
9
|
*/
|
|
10
|
-
export declare const VERSION = "1.
|
|
10
|
+
export declare const VERSION = "1.6.0";
|
|
11
11
|
export declare const WIRE_VERSION = 1;
|
|
12
|
-
export declare const IMPL = "ts-chaincraft/1.
|
|
12
|
+
export declare const IMPL = "ts-chaincraft/1.6.0";
|
|
13
13
|
export declare const LANGUAGE = "typescript";
|
|
14
14
|
export declare const FEATURES: readonly string[];
|
|
15
15
|
export interface Manifest {
|
package/dist/features.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Add an ID here only when the feature is implemented and its vectors pass.
|
|
9
9
|
*/
|
|
10
|
-
export const VERSION = '1.
|
|
10
|
+
export const VERSION = '1.6.0';
|
|
11
11
|
export const WIRE_VERSION = 1;
|
|
12
12
|
export const IMPL = `ts-chaincraft/${VERSION}`;
|
|
13
13
|
export const LANGUAGE = 'typescript';
|
|
@@ -41,12 +41,14 @@ export const FEATURES = [
|
|
|
41
41
|
'consensus.pow',
|
|
42
42
|
'consensus.pos',
|
|
43
43
|
'consensus.pbft',
|
|
44
|
+
'consensus.poa',
|
|
44
45
|
'consensus.avalanche',
|
|
45
46
|
'ledger.balance',
|
|
46
47
|
'ledger.utxo',
|
|
47
48
|
'mempool.basic',
|
|
48
49
|
'fees.policy',
|
|
49
50
|
'storage.persistent',
|
|
51
|
+
'storage.index',
|
|
50
52
|
'cli.node',
|
|
51
53
|
'bittorrent.swarm',
|
|
52
54
|
'wire.channel',
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export { type ApplyResult, ObjectRegistry } from './pipeline.ts';
|
|
|
17
17
|
export { Avalanche, DEFAULT_ALPHA as AVALANCHE_DEFAULT_ALPHA, DEFAULT_BETA as AVALANCHE_DEFAULT_BETA, DEFAULT_K as AVALANCHE_DEFAULT_K, } from './consensusAvalanche.ts';
|
|
18
18
|
export { PBFT, DEFAULT_REPLICAS as PBFT_DEFAULT_REPLICAS } from './consensusPbft.ts';
|
|
19
19
|
export { ProofOfStake, DEFAULT_SEED, DEFAULT_VALIDATORS, proposerFor } from './consensusPos.ts';
|
|
20
|
+
export { ProofOfAuthority, blockId as poaBlockId, proposerFor as poaProposerFor } from './consensusPoa.ts';
|
|
20
21
|
export { ProofOfWork, DEFAULT_DIFFICULTY, blockId, meetsWork } from './consensusPow.ts';
|
|
21
22
|
export { BalanceLedger, DEFAULT_ALLOCATIONS as BALANCE_DEFAULT_ALLOCATIONS } from './ledgerBalance.ts';
|
|
22
23
|
export { CrdtKv, MAX_KEYS as CRDT_MAX_KEYS, MAX_VALUE as CRDT_MAX_VALUE } from './crdt.ts';
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export { ObjectRegistry } from "./pipeline.js";
|
|
|
17
17
|
export { Avalanche, DEFAULT_ALPHA as AVALANCHE_DEFAULT_ALPHA, DEFAULT_BETA as AVALANCHE_DEFAULT_BETA, DEFAULT_K as AVALANCHE_DEFAULT_K, } from "./consensusAvalanche.js";
|
|
18
18
|
export { PBFT, DEFAULT_REPLICAS as PBFT_DEFAULT_REPLICAS } from "./consensusPbft.js";
|
|
19
19
|
export { ProofOfStake, DEFAULT_SEED, DEFAULT_VALIDATORS, proposerFor } from "./consensusPos.js";
|
|
20
|
+
export { ProofOfAuthority, blockId as poaBlockId, proposerFor as poaProposerFor } from "./consensusPoa.js";
|
|
20
21
|
export { ProofOfWork, DEFAULT_DIFFICULTY, blockId, meetsWork } from "./consensusPow.js";
|
|
21
22
|
export { BalanceLedger, DEFAULT_ALLOCATIONS as BALANCE_DEFAULT_ALLOCATIONS } from "./ledgerBalance.js";
|
|
22
23
|
export { CrdtKv, MAX_KEYS as CRDT_MAX_KEYS, MAX_VALUE as CRDT_MAX_VALUE } from "./crdt.js";
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
/** Persistent message store — SPEC/features/storage-persistent.md. */
|
|
1
|
+
/** Persistent message store — SPEC/features/storage-persistent.md, storage-index.md. */
|
|
2
|
+
import { type JsonValue } from './canonical.ts';
|
|
2
3
|
export declare const DEFAULT_CAPACITY = 8;
|
|
3
4
|
export declare function isValidId(value: string): boolean;
|
|
4
5
|
export declare class MessageStore {
|
|
5
6
|
readonly capacity: number;
|
|
6
7
|
private readonly entries;
|
|
8
|
+
private readonly registrations;
|
|
9
|
+
private readonly postings;
|
|
10
|
+
private readonly idKeys;
|
|
7
11
|
constructor(capacity?: number);
|
|
8
12
|
get size(): number;
|
|
9
13
|
ids(): string[];
|
|
14
|
+
register(type: string, field: string): boolean;
|
|
15
|
+
query(type: string, field: string, value: JsonValue): string[];
|
|
10
16
|
put(id: string, body: string): boolean;
|
|
11
17
|
get(id: string): {
|
|
12
18
|
body: string;
|
|
@@ -21,4 +27,7 @@ export declare class MessageStore {
|
|
|
21
27
|
v: number;
|
|
22
28
|
};
|
|
23
29
|
load(snapshot: unknown): boolean;
|
|
30
|
+
private rebuildIndex;
|
|
31
|
+
private unindexId;
|
|
32
|
+
private indexBody;
|
|
24
33
|
}
|
package/dist/storage.js
CHANGED
|
@@ -1,18 +1,69 @@
|
|
|
1
|
-
/** Persistent message store — SPEC/features/storage-persistent.md. */
|
|
1
|
+
/** Persistent message store — SPEC/features/storage-persistent.md, storage-index.md. */
|
|
2
|
+
import { MAX_SAFE_INT, MIN_SAFE_INT } from "./canonical.js";
|
|
3
|
+
import { Envelope } from "./envelope.js";
|
|
4
|
+
import { ProtocolError } from "./errors.js";
|
|
2
5
|
export const DEFAULT_CAPACITY = 8;
|
|
6
|
+
const MAX_REGISTRATIONS = 8;
|
|
3
7
|
const HEX64 = /^[0-9a-f]{64}$/;
|
|
8
|
+
const TYPE_RE = /^[a-z0-9._-]{1,64}$/;
|
|
9
|
+
const FIELD_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
4
10
|
export function isValidId(value) {
|
|
5
11
|
return HEX64.test(value);
|
|
6
12
|
}
|
|
13
|
+
function regKey(type, field) {
|
|
14
|
+
return `${type}\0${field}`;
|
|
15
|
+
}
|
|
16
|
+
function indexKey(type, field, encoded) {
|
|
17
|
+
return `${type}\0${field}\0${encoded}`;
|
|
18
|
+
}
|
|
19
|
+
function isWireInt(value) {
|
|
20
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= MIN_SAFE_INT && value <= MAX_SAFE_INT;
|
|
21
|
+
}
|
|
22
|
+
function encodeValue(value) {
|
|
23
|
+
if (typeof value === 'string')
|
|
24
|
+
return `s:${value}`;
|
|
25
|
+
if (typeof value === 'boolean')
|
|
26
|
+
return `b:${value ? 1 : 0}`;
|
|
27
|
+
if (isWireInt(value))
|
|
28
|
+
return `i:${value}`;
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function indexValues(raw) {
|
|
32
|
+
if (typeof raw === 'string' || typeof raw === 'boolean')
|
|
33
|
+
return [raw];
|
|
34
|
+
if (isWireInt(raw))
|
|
35
|
+
return [raw];
|
|
36
|
+
if (Array.isArray(raw)) {
|
|
37
|
+
const out = [];
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
for (const item of raw) {
|
|
40
|
+
const enc = encodeValue(item);
|
|
41
|
+
if (enc === undefined)
|
|
42
|
+
continue;
|
|
43
|
+
if (seen.has(enc))
|
|
44
|
+
continue;
|
|
45
|
+
seen.add(enc);
|
|
46
|
+
out.push(item);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
7
52
|
export class MessageStore {
|
|
8
53
|
capacity;
|
|
9
54
|
entries;
|
|
55
|
+
registrations;
|
|
56
|
+
postings;
|
|
57
|
+
idKeys;
|
|
10
58
|
constructor(capacity = DEFAULT_CAPACITY) {
|
|
11
59
|
if (!Number.isSafeInteger(capacity) || capacity < 1) {
|
|
12
60
|
throw new RangeError('capacity must be >= 1');
|
|
13
61
|
}
|
|
14
62
|
this.capacity = capacity;
|
|
15
63
|
this.entries = new Map();
|
|
64
|
+
this.registrations = new Set();
|
|
65
|
+
this.postings = new Map();
|
|
66
|
+
this.idKeys = new Map();
|
|
16
67
|
}
|
|
17
68
|
get size() {
|
|
18
69
|
return this.entries.size;
|
|
@@ -20,19 +71,43 @@ export class MessageStore {
|
|
|
20
71
|
ids() {
|
|
21
72
|
return [...this.entries.keys()];
|
|
22
73
|
}
|
|
74
|
+
register(type, field) {
|
|
75
|
+
if (!TYPE_RE.test(type) || !FIELD_RE.test(field))
|
|
76
|
+
return false;
|
|
77
|
+
const key = regKey(type, field);
|
|
78
|
+
if (this.registrations.has(key))
|
|
79
|
+
return true;
|
|
80
|
+
if (this.registrations.size >= MAX_REGISTRATIONS)
|
|
81
|
+
return false;
|
|
82
|
+
this.registrations.add(key);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
query(type, field, value) {
|
|
86
|
+
const enc = encodeValue(value);
|
|
87
|
+
if (enc === undefined)
|
|
88
|
+
return [];
|
|
89
|
+
if (!this.registrations.has(regKey(type, field)))
|
|
90
|
+
return [];
|
|
91
|
+
return [...(this.postings.get(indexKey(type, field, enc)) ?? [])];
|
|
92
|
+
}
|
|
23
93
|
put(id, body) {
|
|
24
94
|
if (!isValidId(id) || body.length === 0)
|
|
25
95
|
return false;
|
|
26
96
|
if (this.entries.has(id)) {
|
|
97
|
+
this.unindexId(id);
|
|
27
98
|
this.entries.set(id, body);
|
|
99
|
+
this.indexBody(id, body);
|
|
28
100
|
return false;
|
|
29
101
|
}
|
|
30
102
|
if (this.entries.size >= this.capacity) {
|
|
31
103
|
const oldest = this.entries.keys().next().value;
|
|
32
|
-
if (oldest !== undefined)
|
|
104
|
+
if (oldest !== undefined) {
|
|
105
|
+
this.unindexId(oldest);
|
|
33
106
|
this.entries.delete(oldest);
|
|
107
|
+
}
|
|
34
108
|
}
|
|
35
109
|
this.entries.set(id, body);
|
|
110
|
+
this.indexBody(id, body);
|
|
36
111
|
return true;
|
|
37
112
|
}
|
|
38
113
|
get(id) {
|
|
@@ -42,7 +117,10 @@ export class MessageStore {
|
|
|
42
117
|
return { body, found: true };
|
|
43
118
|
}
|
|
44
119
|
remove(id) {
|
|
45
|
-
|
|
120
|
+
if (!this.entries.delete(id))
|
|
121
|
+
return false;
|
|
122
|
+
this.unindexId(id);
|
|
123
|
+
return true;
|
|
46
124
|
}
|
|
47
125
|
dump() {
|
|
48
126
|
const entries = [];
|
|
@@ -57,8 +135,69 @@ export class MessageStore {
|
|
|
57
135
|
this.entries.clear();
|
|
58
136
|
for (const [id, body] of parsed)
|
|
59
137
|
this.entries.set(id, body);
|
|
138
|
+
this.rebuildIndex();
|
|
60
139
|
return true;
|
|
61
140
|
}
|
|
141
|
+
rebuildIndex() {
|
|
142
|
+
this.postings.clear();
|
|
143
|
+
this.idKeys.clear();
|
|
144
|
+
for (const [id, body] of this.entries)
|
|
145
|
+
this.indexBody(id, body);
|
|
146
|
+
}
|
|
147
|
+
unindexId(id) {
|
|
148
|
+
const keys = this.idKeys.get(id);
|
|
149
|
+
if (keys === undefined)
|
|
150
|
+
return;
|
|
151
|
+
this.idKeys.delete(id);
|
|
152
|
+
for (const key of keys) {
|
|
153
|
+
const bucket = this.postings.get(key);
|
|
154
|
+
if (bucket === undefined)
|
|
155
|
+
continue;
|
|
156
|
+
const next = bucket.filter((entry) => entry !== id);
|
|
157
|
+
if (next.length === 0)
|
|
158
|
+
this.postings.delete(key);
|
|
159
|
+
else
|
|
160
|
+
this.postings.set(key, next);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
indexBody(id, body) {
|
|
164
|
+
let env;
|
|
165
|
+
try {
|
|
166
|
+
env = Envelope.parse(body);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
if (e instanceof ProtocolError)
|
|
170
|
+
return;
|
|
171
|
+
throw e;
|
|
172
|
+
}
|
|
173
|
+
if (env.data === null || typeof env.data !== 'object' || Array.isArray(env.data))
|
|
174
|
+
return;
|
|
175
|
+
const data = env.data;
|
|
176
|
+
const keysForId = new Set();
|
|
177
|
+
for (const reg of this.registrations) {
|
|
178
|
+
const [type, field] = reg.split('\0');
|
|
179
|
+
if (type === undefined || field === undefined)
|
|
180
|
+
continue;
|
|
181
|
+
if (env.type !== type)
|
|
182
|
+
continue;
|
|
183
|
+
const raw = data[field];
|
|
184
|
+
if (raw === undefined)
|
|
185
|
+
continue;
|
|
186
|
+
for (const value of indexValues(raw)) {
|
|
187
|
+
const enc = encodeValue(value);
|
|
188
|
+
if (enc === undefined)
|
|
189
|
+
continue;
|
|
190
|
+
const idx = indexKey(type, field, enc);
|
|
191
|
+
keysForId.add(idx);
|
|
192
|
+
const bucket = this.postings.get(idx) ?? [];
|
|
193
|
+
if (!bucket.includes(id))
|
|
194
|
+
bucket.push(id);
|
|
195
|
+
this.postings.set(idx, bucket);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (keysForId.size > 0)
|
|
199
|
+
this.idKeys.set(id, keysForId);
|
|
200
|
+
}
|
|
62
201
|
}
|
|
63
202
|
function parseSnapshot(snapshot, capacity) {
|
|
64
203
|
if (snapshot === null || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
|