-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathId.js
51 lines (38 loc) · 1.01 KB
/
Id.js
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
/**
* Copyright (c) 2013 Yahoo! Inc. All rights reserved.
*
* Copyrights licensed under the MIT License. See the accompanying LICENSE file
* for terms.
*/
var jute = require('./jute');
function Id(scheme, id) {
if (!scheme || typeof scheme !== 'string') {
throw new Error('scheme must be a non-empty string.');
}
if (typeof id !== 'string') {
throw new Error('id must be a string.');
}
this.scheme = scheme;
this.id = id;
}
Id.prototype.toRecord = function () {
return new jute.data.Id(
this.scheme,
this.id
);
};
var IDS = {
ANYONE_ID_UNSAFE : new Id('world', 'anyone'),
AUTH_IDS : new Id('auth', '')
};
function fromRecord(record) {
if (!(record instanceof jute.data.Id)) {
throw new Error('record must be an instace of jute.data.Id.');
}
return new Id(record.scheme, record.id);
}
module.exports = Id;
module.exports.fromRecord = fromRecord;
Object.keys(IDS).forEach(function (key) {
module.exports[key] = IDS[key];
});