forked from cruncher/music-json-spec
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodule.js
More file actions
58 lines (43 loc) · 1.24 KB
/
Copy pathmodule.js
File metadata and controls
58 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Event from './modules/event.js';
import Sequence from './modules/sequence.js';
import { VERSION } from './modules/record/serialise.js';
import { toRecord, toATProtoRecord, fromRecord } from './modules/record.js';
const assign = Object.assign;
/**
Sequence.version
Version number for the revision of the sequence spec this Sequence object
implements.
**/
/**
Sequence.fromRecord(record);
**/
/**
Sequence.toRecord(sequence);
**/
// The Sequence() constructor delegates to Sequence.from() to recursively
// instantiate nested sequences, so Sequence.from() must be overridden to
// provide deserialisation of nested records' events.
const fromData = Sequence.from;
Sequence.from = function from(data) {
// events is a Uint8Array
return data.events && data.events instanceof Uint8Array ? fromRecord(data) :
// events is an ATProto bytes object
data.events && typeof data.events.$bytes === 'string' ? fromRecord(data) :
// events is something else
fromData(data) ;
};
assign(Sequence, {
version: VERSION,
toRecord,
toATProtoRecord,
fromRecord
});
/**
.toRecord()
**/
assign(Sequence.prototype, {
toRecord: function() {
return toRecord(this);
}
});
export { Event, Sequence };