@ceramicnetwork/streamid 2.0.0-alpha.0 → 2.0.0-alpha.3
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 +8 -2
- package/lib/commit-id.d.ts +4 -3
- package/lib/commit-id.d.ts.map +1 -1
- package/lib/commit-id.js +40 -47
- package/lib/commit-id.js.map +1 -1
- package/lib/constants.js +1 -4
- package/lib/constants.js.map +1 -1
- package/lib/index.d.ts +4 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -22
- package/lib/index.js.map +1 -1
- package/lib/reading-bytes.js +9 -18
- package/lib/reading-bytes.js.map +1 -1
- package/lib/stream-id.d.ts +1 -3
- package/lib/stream-id.d.ts.map +1 -1
- package/lib/stream-id.js +30 -60
- package/lib/stream-id.js.map +1 -1
- package/lib/stream-ref.d.ts +2 -3
- package/lib/stream-ref.d.ts.map +1 -1
- package/lib/stream-ref.js +11 -14
- package/lib/stream-ref.js.map +1 -1
- package/lib/stream-type.js +1 -5
- package/lib/stream-type.js.map +1 -1
- package/package.json +18 -17
- package/CHANGELOG.md +0 -583
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
# Ceramic StreamID
|
|
2
|
+

|
|
3
|
+
[](https://lbesson.mit-license.org/)
|
|
4
|
+
[](https://discord.gg/6VRZpGP)
|
|
5
|
+
[](https://twitter.com/ceramicnetwork)
|
|
2
6
|
|
|
3
7
|
> This package contains Ceramic StreamID and CommitID implementation.
|
|
4
8
|
|
|
@@ -29,11 +33,13 @@ $ npm install @ceramicnetwork/streamid
|
|
|
29
33
|
|
|
30
34
|
### Usage
|
|
31
35
|
|
|
36
|
+
See the [ceramic developer site](https://developers.ceramic.network/) for more details about how to use this package.
|
|
37
|
+
|
|
38
|
+
|
|
32
39
|
To reference a stream as a whole, use `StreamID`. You can create an instance from the parts. stream type string or integer and CID instance or string are required.
|
|
33
40
|
|
|
34
41
|
```typescript
|
|
35
|
-
import StreamID from '@ceramicnetwork/streamid';
|
|
36
|
-
// alternatively: import { StreamID } from '@ceramicnetwork/streamid'
|
|
42
|
+
import { StreamID } from '@ceramicnetwork/streamid';
|
|
37
43
|
|
|
38
44
|
const streamid = new StreamID('tile', 'bagcqcerakszw2vsov...');
|
|
39
45
|
|
package/lib/commit-id.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
|
-
import { StreamID } from './stream-id';
|
|
3
|
-
import { StreamRef } from './stream-ref';
|
|
2
|
+
import { StreamID } from './stream-id.js';
|
|
3
|
+
import { StreamRef } from './stream-ref.js';
|
|
4
4
|
declare function fromBytes(bytes: Uint8Array): CommitID;
|
|
5
5
|
declare function fromBytesNoThrow(bytes: Uint8Array): CommitID | Error;
|
|
6
6
|
declare function fromString(input: string): CommitID;
|
|
7
7
|
declare function fromStringNoThrow(input: string): CommitID | Error;
|
|
8
|
+
declare function make(stream: StreamID, commit: CID | string | number): CommitID;
|
|
8
9
|
export declare class CommitID implements StreamRef {
|
|
9
10
|
#private;
|
|
10
11
|
protected readonly _tag: symbol;
|
|
@@ -12,6 +13,7 @@ export declare class CommitID implements StreamRef {
|
|
|
12
13
|
static fromBytesNoThrow: typeof fromBytesNoThrow;
|
|
13
14
|
static fromString: typeof fromString;
|
|
14
15
|
static fromStringNoThrow: typeof fromStringNoThrow;
|
|
16
|
+
static make: typeof make;
|
|
15
17
|
static isInstance(instance: any): instance is CommitID;
|
|
16
18
|
constructor(type: string | number, cid: CID | string, commit?: CID | string | number);
|
|
17
19
|
get baseID(): StreamID;
|
|
@@ -20,7 +22,6 @@ export declare class CommitID implements StreamRef {
|
|
|
20
22
|
get cid(): CID;
|
|
21
23
|
get commit(): CID;
|
|
22
24
|
get bytes(): Uint8Array;
|
|
23
|
-
atCommit(commit: CID | string | number): CommitID;
|
|
24
25
|
equals(other: CommitID): boolean;
|
|
25
26
|
toString(): string;
|
|
26
27
|
toUrl(): string;
|
package/lib/commit-id.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-id.d.ts","sourceRoot":"","sources":["../src/commit-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAQtC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"commit-id.d.ts","sourceRoot":"","sources":["../src/commit-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAQtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAS3C,iBAAS,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAM9C;AASD,iBAAS,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,GAAG,KAAK,CAoB7D;AAqDD,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAM3C;AASD,iBAAS,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAS1D;AAOD,iBAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAEvE;AASD,qBAAa,QAAS,YAAW,SAAS;;IACxC,SAAS,CAAC,QAAQ,CAAC,IAAI,SAAM;IAM7B,MAAM,CAAC,SAAS,mBAAY;IAC5B,MAAM,CAAC,gBAAgB,0BAAmB;IAC1C,MAAM,CAAC,UAAU,oBAAa;IAC9B,MAAM,CAAC,iBAAiB,2BAAoB;IAC5C,MAAM,CAAC,IAAI,cAAO;IAKlB,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,GAAG,QAAQ,IAAI,QAAQ;gBAe1C,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,MAAM,GAAE,GAAG,GAAG,MAAM,GAAG,MAAa;IAW1F,IACI,MAAM,IAAI,QAAQ,CAErB;IAKD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAKD,IACI,QAAQ,IAAI,MAAM,CAErB;IAKD,IAAI,GAAG,IAAI,GAAG,CAEb;IAKD,IACI,MAAM,IAAI,GAAG,CAEhB;IAKD,IACI,KAAK,IAAI,UAAU,CAMtB;IAKD,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAUhC,QAAQ,IAAI,MAAM;IAQlB,KAAK,IAAI,MAAM;IAoBf,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,GAAG,UAAU;CAG5C"}
|
package/lib/commit-id.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -19,21 +18,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
20
|
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
21
|
var _CommitID_type, _CommitID_cid, _CommitID_commit;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const reading_bytes_1 = require("./reading-bytes");
|
|
36
|
-
const stream_id_1 = require("./stream-id");
|
|
22
|
+
import { CID } from 'multiformats/cid';
|
|
23
|
+
import { base36 } from 'multiformats/bases/base36';
|
|
24
|
+
import { StreamType } from './stream-type.js';
|
|
25
|
+
import varint from 'varint';
|
|
26
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays';
|
|
27
|
+
import { Memoize } from 'typescript-memoize';
|
|
28
|
+
import { STREAMID_CODEC } from './constants.js';
|
|
29
|
+
import { readCid, readVarint } from './reading-bytes.js';
|
|
30
|
+
import { StreamID } from './stream-id.js';
|
|
37
31
|
function fromBytes(bytes) {
|
|
38
32
|
const result = fromBytesNoThrow(bytes);
|
|
39
33
|
if (result instanceof Error) {
|
|
@@ -42,11 +36,11 @@ function fromBytes(bytes) {
|
|
|
42
36
|
return result;
|
|
43
37
|
}
|
|
44
38
|
function fromBytesNoThrow(bytes) {
|
|
45
|
-
const [streamCodec, streamCodecRemainder] =
|
|
46
|
-
if (streamCodec !==
|
|
39
|
+
const [streamCodec, streamCodecRemainder] = readVarint(bytes);
|
|
40
|
+
if (streamCodec !== STREAMID_CODEC)
|
|
47
41
|
return new Error('fromBytes: invalid streamid, does not include streamid codec');
|
|
48
|
-
const [type, streamtypeRemainder] =
|
|
49
|
-
const cidResult =
|
|
42
|
+
const [type, streamtypeRemainder] = readVarint(streamCodecRemainder);
|
|
43
|
+
const cidResult = readCid(streamtypeRemainder);
|
|
50
44
|
if (cidResult instanceof Error) {
|
|
51
45
|
return cidResult;
|
|
52
46
|
}
|
|
@@ -58,15 +52,15 @@ function fromBytesNoThrow(bytes) {
|
|
|
58
52
|
return new CommitID(type, base, baseRemainder[0]);
|
|
59
53
|
}
|
|
60
54
|
else {
|
|
61
|
-
const [commit] =
|
|
55
|
+
const [commit] = readCid(baseRemainder);
|
|
62
56
|
return new CommitID(type, base, commit);
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
59
|
function parseCID(input) {
|
|
66
60
|
try {
|
|
67
|
-
return typeof input === 'string' ?
|
|
61
|
+
return typeof input === 'string' ? CID.parse(input) : CID.asCID(input);
|
|
68
62
|
}
|
|
69
|
-
catch
|
|
63
|
+
catch {
|
|
70
64
|
return undefined;
|
|
71
65
|
}
|
|
72
66
|
}
|
|
@@ -101,14 +95,17 @@ function fromStringNoThrow(input) {
|
|
|
101
95
|
if (protocolFree.includes('commit')) {
|
|
102
96
|
const commit = protocolFree.split('?')[1].split('=')[1];
|
|
103
97
|
const base = protocolFree.split('?')[0];
|
|
104
|
-
return
|
|
98
|
+
return make(StreamID.fromString(base), commit);
|
|
105
99
|
}
|
|
106
100
|
else {
|
|
107
|
-
return fromBytesNoThrow(
|
|
101
|
+
return fromBytesNoThrow(base36.decode(protocolFree));
|
|
108
102
|
}
|
|
109
103
|
}
|
|
110
104
|
const TAG = Symbol.for('@ceramicnetwork/streamid/CommitID');
|
|
111
|
-
|
|
105
|
+
function make(stream, commit) {
|
|
106
|
+
return new CommitID(stream.type, stream.cid, commit);
|
|
107
|
+
}
|
|
108
|
+
export class CommitID {
|
|
112
109
|
constructor(type, cid, commit = null) {
|
|
113
110
|
this._tag = TAG;
|
|
114
111
|
_CommitID_type.set(this, void 0);
|
|
@@ -118,21 +115,21 @@ class CommitID {
|
|
|
118
115
|
throw new Error('constructor: type required');
|
|
119
116
|
if (!cid)
|
|
120
117
|
throw new Error('constructor: cid required');
|
|
121
|
-
__classPrivateFieldSet(this, _CommitID_type, typeof type === 'string' ?
|
|
122
|
-
__classPrivateFieldSet(this, _CommitID_cid, typeof cid === 'string' ?
|
|
118
|
+
__classPrivateFieldSet(this, _CommitID_type, typeof type === 'string' ? StreamType.codeByName(type) : type, "f");
|
|
119
|
+
__classPrivateFieldSet(this, _CommitID_cid, typeof cid === 'string' ? CID.parse(cid) : cid, "f");
|
|
123
120
|
__classPrivateFieldSet(this, _CommitID_commit, parseCommit(__classPrivateFieldGet(this, _CommitID_cid, "f"), commit), "f");
|
|
124
121
|
}
|
|
125
122
|
static isInstance(instance) {
|
|
126
123
|
return typeof instance === 'object' && '_tag' in instance && instance._tag === TAG;
|
|
127
124
|
}
|
|
128
125
|
get baseID() {
|
|
129
|
-
return new
|
|
126
|
+
return new StreamID(__classPrivateFieldGet(this, _CommitID_type, "f"), __classPrivateFieldGet(this, _CommitID_cid, "f"));
|
|
130
127
|
}
|
|
131
128
|
get type() {
|
|
132
129
|
return __classPrivateFieldGet(this, _CommitID_type, "f");
|
|
133
130
|
}
|
|
134
131
|
get typeName() {
|
|
135
|
-
return
|
|
132
|
+
return StreamType.nameByCode(__classPrivateFieldGet(this, _CommitID_type, "f"));
|
|
136
133
|
}
|
|
137
134
|
get cid() {
|
|
138
135
|
return __classPrivateFieldGet(this, _CommitID_cid, "f");
|
|
@@ -141,20 +138,16 @@ class CommitID {
|
|
|
141
138
|
return __classPrivateFieldGet(this, _CommitID_commit, "f") || __classPrivateFieldGet(this, _CommitID_cid, "f");
|
|
142
139
|
}
|
|
143
140
|
get bytes() {
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
return uint8arrays_1.concat([codec, type, this.cid.bytes, commitBytes]);
|
|
149
|
-
}
|
|
150
|
-
atCommit(commit) {
|
|
151
|
-
return new CommitID(__classPrivateFieldGet(this, _CommitID_type, "f"), __classPrivateFieldGet(this, _CommitID_cid, "f"), commit);
|
|
141
|
+
const codec = varint.encode(STREAMID_CODEC);
|
|
142
|
+
const type = varint.encode(this.type);
|
|
143
|
+
const commitBytes = __classPrivateFieldGet(this, _CommitID_commit, "f")?.bytes || new Uint8Array([0]);
|
|
144
|
+
return uint8ArrayConcat([codec, type, this.cid.bytes, commitBytes]);
|
|
152
145
|
}
|
|
153
146
|
equals(other) {
|
|
154
147
|
return (this.type === other.type && this.cid.equals(other.cid) && this.commit.equals(other.commit));
|
|
155
148
|
}
|
|
156
149
|
toString() {
|
|
157
|
-
return
|
|
150
|
+
return base36.encode(this.bytes);
|
|
158
151
|
}
|
|
159
152
|
toUrl() {
|
|
160
153
|
return `ceramic://${this.toString()}`;
|
|
@@ -170,37 +163,37 @@ CommitID.fromBytes = fromBytes;
|
|
|
170
163
|
CommitID.fromBytesNoThrow = fromBytesNoThrow;
|
|
171
164
|
CommitID.fromString = fromString;
|
|
172
165
|
CommitID.fromStringNoThrow = fromStringNoThrow;
|
|
166
|
+
CommitID.make = make;
|
|
173
167
|
__decorate([
|
|
174
|
-
|
|
175
|
-
__metadata("design:type",
|
|
168
|
+
Memoize(),
|
|
169
|
+
__metadata("design:type", StreamID),
|
|
176
170
|
__metadata("design:paramtypes", [])
|
|
177
171
|
], CommitID.prototype, "baseID", null);
|
|
178
172
|
__decorate([
|
|
179
|
-
|
|
173
|
+
Memoize(),
|
|
180
174
|
__metadata("design:type", String),
|
|
181
175
|
__metadata("design:paramtypes", [])
|
|
182
176
|
], CommitID.prototype, "typeName", null);
|
|
183
177
|
__decorate([
|
|
184
|
-
|
|
185
|
-
__metadata("design:type",
|
|
178
|
+
Memoize(),
|
|
179
|
+
__metadata("design:type", CID),
|
|
186
180
|
__metadata("design:paramtypes", [])
|
|
187
181
|
], CommitID.prototype, "commit", null);
|
|
188
182
|
__decorate([
|
|
189
|
-
|
|
183
|
+
Memoize(),
|
|
190
184
|
__metadata("design:type", Uint8Array),
|
|
191
185
|
__metadata("design:paramtypes", [])
|
|
192
186
|
], CommitID.prototype, "bytes", null);
|
|
193
187
|
__decorate([
|
|
194
|
-
|
|
188
|
+
Memoize(),
|
|
195
189
|
__metadata("design:type", Function),
|
|
196
190
|
__metadata("design:paramtypes", []),
|
|
197
191
|
__metadata("design:returntype", String)
|
|
198
192
|
], CommitID.prototype, "toString", null);
|
|
199
193
|
__decorate([
|
|
200
|
-
|
|
194
|
+
Memoize(),
|
|
201
195
|
__metadata("design:type", Function),
|
|
202
196
|
__metadata("design:paramtypes", []),
|
|
203
197
|
__metadata("design:returntype", String)
|
|
204
198
|
], CommitID.prototype, "toUrl", null);
|
|
205
|
-
exports.CommitID = CommitID;
|
|
206
199
|
//# sourceMappingURL=commit-id.js.map
|
package/lib/commit-id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-id.js","sourceRoot":"","sources":["../src/commit-id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commit-id.js","sourceRoot":"","sources":["../src/commit-id.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAUzC,SAAS,SAAS,CAAC,KAAiB;IAClC,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACtC,IAAI,MAAM,YAAY,KAAK,EAAE;QAC3B,MAAM,MAAM,CAAA;KACb;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AASD,SAAS,gBAAgB,CAAC,KAAiB;IACzC,MAAM,CAAC,WAAW,EAAE,oBAAoB,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;IAC7D,IAAI,WAAW,KAAK,cAAc;QAChC,OAAO,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAA;IAClF,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACpE,MAAM,SAAS,GAAG,OAAO,CA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,GAAG;;sCAEhB;AAMD;IADC,OAAO,EAAE;8BACG,UAAU;;qCAMtB;AAeD;IADC,OAAO,EAAE;;;;wCAGT;AAMD;IADC,OAAO,EAAE;;;;qCAGT"}
|
package/lib/constants.js
CHANGED
package/lib/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export * from './stream-type';
|
|
6
|
-
export default StreamID;
|
|
1
|
+
export { CommitID } from './commit-id.js';
|
|
2
|
+
export { StreamID } from './stream-id.js';
|
|
3
|
+
export { StreamRef } from './stream-ref.js';
|
|
4
|
+
export * from './stream-type.js';
|
|
7
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,cAAc,kBAAkB,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.StreamRef = exports.StreamID = exports.CommitID = void 0;
|
|
14
|
-
const stream_id_1 = require("./stream-id");
|
|
15
|
-
var commit_id_1 = require("./commit-id");
|
|
16
|
-
Object.defineProperty(exports, "CommitID", { enumerable: true, get: function () { return commit_id_1.CommitID; } });
|
|
17
|
-
var stream_id_2 = require("./stream-id");
|
|
18
|
-
Object.defineProperty(exports, "StreamID", { enumerable: true, get: function () { return stream_id_2.StreamID; } });
|
|
19
|
-
var stream_ref_1 = require("./stream-ref");
|
|
20
|
-
Object.defineProperty(exports, "StreamRef", { enumerable: true, get: function () { return stream_ref_1.StreamRef; } });
|
|
21
|
-
__exportStar(require("./stream-type"), exports);
|
|
22
|
-
exports.default = stream_id_1.StreamID;
|
|
1
|
+
export { CommitID } from './commit-id.js';
|
|
2
|
+
export { StreamID } from './stream-id.js';
|
|
3
|
+
export { StreamRef } from './stream-ref.js';
|
|
4
|
+
export * from './stream-type.js';
|
|
23
5
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,cAAc,kBAAkB,CAAA"}
|
package/lib/reading-bytes.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const cid_1 = require("multiformats/cid");
|
|
8
|
-
const varint_1 = __importDefault(require("varint"));
|
|
9
|
-
const digest_1 = require("multiformats/hashes/digest");
|
|
10
|
-
function readVarint(bytes) {
|
|
11
|
-
const value = varint_1.default.decode(bytes);
|
|
12
|
-
const readLength = varint_1.default.decode.bytes;
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
|
+
import varint from 'varint';
|
|
3
|
+
import { decode as decodeMultiHash } from 'multiformats/hashes/digest';
|
|
4
|
+
export function readVarint(bytes) {
|
|
5
|
+
const value = varint.decode(bytes);
|
|
6
|
+
const readLength = varint.decode.bytes;
|
|
13
7
|
const remainder = bytes.slice(readLength);
|
|
14
8
|
return [value, remainder, readLength];
|
|
15
9
|
}
|
|
16
|
-
exports.readVarint = readVarint;
|
|
17
10
|
function isCidVersion(input) {
|
|
18
11
|
return input === 0 || input === 1;
|
|
19
12
|
}
|
|
20
|
-
function readCid(bytes) {
|
|
13
|
+
export function readCid(bytes) {
|
|
21
14
|
const result = readCidNoThrow(bytes);
|
|
22
15
|
if (result instanceof Error) {
|
|
23
16
|
throw result;
|
|
24
17
|
}
|
|
25
18
|
return result;
|
|
26
19
|
}
|
|
27
|
-
|
|
28
|
-
function readCidNoThrow(bytes) {
|
|
20
|
+
export function readCidNoThrow(bytes) {
|
|
29
21
|
const [cidVersion, cidVersionRemainder] = readVarint(bytes);
|
|
30
22
|
if (!isCidVersion(cidVersion)) {
|
|
31
23
|
return new Error(`Unknown CID version ${cidVersion}`);
|
|
@@ -35,7 +27,6 @@ function readCidNoThrow(bytes) {
|
|
|
35
27
|
const [mhLength, , mhLengthLength] = readVarint(mhCodecRemainder);
|
|
36
28
|
const multihashBytes = codecRemainder.slice(0, mhCodecLength + mhLengthLength + mhLength);
|
|
37
29
|
const multihashBytesRemainder = codecRemainder.slice(mhCodecLength + mhLengthLength + mhLength);
|
|
38
|
-
return [
|
|
30
|
+
return [CID.create(cidVersion, codec, decodeMultiHash(multihashBytes)), multihashBytesRemainder];
|
|
39
31
|
}
|
|
40
|
-
exports.readCidNoThrow = readCidNoThrow;
|
|
41
32
|
//# sourceMappingURL=reading-bytes.js.map
|
package/lib/reading-bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reading-bytes.js","sourceRoot":"","sources":["../src/reading-bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reading-bytes.js","sourceRoot":"","sources":["../src/reading-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAEtE,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAA;IACtC,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACzC,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,KAAiB;IACvC,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;IACpC,IAAI,MAAM,YAAY,KAAK,EAAE;QAC3B,MAAM,MAAM,CAAA;KACb;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,MAAM,CAAC,UAAU,EAAE,mBAAmB,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;IAC3D,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,IAAI,KAAK,CAAC,uBAAuB,UAAU,EAAE,CAAC,CAAA;KACtD;IACD,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAA;IAC/D,MAAM,CAAC,EAAE,gBAAgB,EAAE,aAAa,CAAC,GAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IACtE,MAAM,CAAC,QAAQ,EAAE,AAAD,EAAG,cAAc,CAAC,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAA;IACjE,MAAM,cAAc,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAA;IACzF,MAAM,uBAAuB,GAAG,cAAc,CAAC,KAAK,CAAC,aAAa,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAA;IAC/F,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,eAAe,CAAC,cAAc,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAA;AAClG,CAAC"}
|
package/lib/stream-id.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
|
-
import {
|
|
3
|
-
import { StreamRef } from './stream-ref';
|
|
2
|
+
import { StreamRef } from './stream-ref.js';
|
|
4
3
|
declare function fromBytes(bytes: Uint8Array): StreamID;
|
|
5
4
|
declare function fromBytesNoThrow(bytes: Uint8Array): StreamID | Error;
|
|
6
5
|
declare function fromString(input: string): StreamID;
|
|
@@ -20,7 +19,6 @@ export declare class StreamID implements StreamRef {
|
|
|
20
19
|
get cid(): CID;
|
|
21
20
|
get bytes(): Uint8Array;
|
|
22
21
|
get baseID(): StreamID;
|
|
23
|
-
atCommit(commit: CID | string | number): CommitID;
|
|
24
22
|
equals(other: StreamID): boolean;
|
|
25
23
|
toString(): string;
|
|
26
24
|
toUrl(): string;
|
package/lib/stream-id.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-id.d.ts","sourceRoot":"","sources":["../src/stream-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAUtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stream-id.d.ts","sourceRoot":"","sources":["../src/stream-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAUtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAU3C,iBAAS,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAM9C;AASD,iBAAS,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,GAAG,KAAK,CAc7D;AASD,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAM3C;AASD,iBAAS,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAK1D;AAaD,qBAAa,QAAS,YAAW,SAAS;;IACxC,SAAS,CAAC,QAAQ,CAAC,IAAI,SAAM;IAK7B,MAAM,CAAC,SAAS,mBAAY;IAC5B,MAAM,CAAC,gBAAgB,0BAAmB;IAC1C,MAAM,CAAC,UAAU,oBAAa;IAC9B,MAAM,CAAC,iBAAiB,2BAAoB;IAK5C,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,GAAG,QAAQ,IAAI,QAAQ;gBAiB1C,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM;WAwBvC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQhG,IAAI,IAAI,IAAI,MAAM,CAEjB;IAKD,IACI,QAAQ,IAAI,MAAM,CAErB;IAKD,IAAI,GAAG,IAAI,GAAG,CAEb;IAKD,IACI,KAAK,IAAI,UAAU,CAKtB;IAMD,IACI,MAAM,IAAI,QAAQ,CAErB;IAKD,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAYhC,QAAQ,IAAI,MAAM;IAQlB,KAAK,IAAI,MAAM;IAcf,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM;CAG/B"}
|
package/lib/stream-id.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
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;
|
|
18
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
6
|
};
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
-
if (mod && mod.__esModule) return mod;
|
|
22
|
-
var result = {};
|
|
23
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
-
__setModuleDefault(result, mod);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
28
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
29
9
|
};
|
|
@@ -38,24 +18,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
38
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
39
19
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
40
20
|
};
|
|
41
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
-
};
|
|
44
21
|
var _StreamID_type, _StreamID_cid;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const typescript_memoize_1 = require("typescript-memoize");
|
|
57
|
-
const commit_id_1 = require("./commit-id");
|
|
58
|
-
const stream_type_1 = require("./stream-type");
|
|
22
|
+
import { CID } from 'multiformats/cid';
|
|
23
|
+
import * as Block from 'multiformats/block';
|
|
24
|
+
import { base36 } from 'multiformats/bases/base36';
|
|
25
|
+
import { sha256 as hasher } from 'multiformats/hashes/sha2';
|
|
26
|
+
import varint from 'varint';
|
|
27
|
+
import * as codec from '@ipld/dag-cbor';
|
|
28
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays';
|
|
29
|
+
import { STREAMID_CODEC } from './constants.js';
|
|
30
|
+
import { readCidNoThrow, readVarint } from './reading-bytes.js';
|
|
31
|
+
import { Memoize } from 'typescript-memoize';
|
|
32
|
+
import { StreamType } from './stream-type.js';
|
|
59
33
|
function fromBytes(bytes) {
|
|
60
34
|
const result = fromBytesNoThrow(bytes);
|
|
61
35
|
if (result instanceof Error) {
|
|
@@ -64,11 +38,11 @@ function fromBytes(bytes) {
|
|
|
64
38
|
return result;
|
|
65
39
|
}
|
|
66
40
|
function fromBytesNoThrow(bytes) {
|
|
67
|
-
const [streamCodec, streamCodecRemainder] =
|
|
68
|
-
if (streamCodec !==
|
|
41
|
+
const [streamCodec, streamCodecRemainder] = readVarint(bytes);
|
|
42
|
+
if (streamCodec !== STREAMID_CODEC)
|
|
69
43
|
return new Error('fromBytes: invalid streamid, does not include streamid codec');
|
|
70
|
-
const [type, streamTypeRemainder] =
|
|
71
|
-
const cidResult =
|
|
44
|
+
const [type, streamTypeRemainder] = readVarint(streamCodecRemainder);
|
|
45
|
+
const cidResult = readCidNoThrow(streamTypeRemainder);
|
|
72
46
|
if (cidResult instanceof Error) {
|
|
73
47
|
return cidResult;
|
|
74
48
|
}
|
|
@@ -88,11 +62,11 @@ function fromString(input) {
|
|
|
88
62
|
function fromStringNoThrow(input) {
|
|
89
63
|
const protocolFree = input.replace('ceramic://', '').replace('/ceramic/', '');
|
|
90
64
|
const commitFree = protocolFree.includes('commit') ? protocolFree.split('?')[0] : protocolFree;
|
|
91
|
-
const bytes =
|
|
65
|
+
const bytes = base36.decode(commitFree);
|
|
92
66
|
return fromBytesNoThrow(bytes);
|
|
93
67
|
}
|
|
94
68
|
const TAG = Symbol.for('@ceramicnetwork/streamid/StreamID');
|
|
95
|
-
class StreamID {
|
|
69
|
+
export class StreamID {
|
|
96
70
|
constructor(type, cid) {
|
|
97
71
|
this._tag = TAG;
|
|
98
72
|
_StreamID_type.set(this, void 0);
|
|
@@ -101,36 +75,33 @@ class StreamID {
|
|
|
101
75
|
throw new Error('constructor: type required');
|
|
102
76
|
if (!cid)
|
|
103
77
|
throw new Error('constructor: cid required');
|
|
104
|
-
__classPrivateFieldSet(this, _StreamID_type, typeof type === 'string' ?
|
|
105
|
-
__classPrivateFieldSet(this, _StreamID_cid, typeof cid === 'string' ?
|
|
78
|
+
__classPrivateFieldSet(this, _StreamID_type, typeof type === 'string' ? StreamType.codeByName(type) : type, "f");
|
|
79
|
+
__classPrivateFieldSet(this, _StreamID_cid, typeof cid === 'string' ? CID.parse(cid) : cid, "f");
|
|
106
80
|
}
|
|
107
81
|
static isInstance(instance) {
|
|
108
82
|
return typeof instance === 'object' && '_tag' in instance && instance._tag === TAG;
|
|
109
83
|
}
|
|
110
84
|
static async fromGenesis(type, genesis) {
|
|
111
|
-
const block = await Block.encode({ value: genesis, codec, hasher
|
|
85
|
+
const block = await Block.encode({ value: genesis, codec, hasher });
|
|
112
86
|
return new StreamID(type, block.cid);
|
|
113
87
|
}
|
|
114
88
|
get type() {
|
|
115
89
|
return __classPrivateFieldGet(this, _StreamID_type, "f");
|
|
116
90
|
}
|
|
117
91
|
get typeName() {
|
|
118
|
-
return
|
|
92
|
+
return StreamType.nameByCode(__classPrivateFieldGet(this, _StreamID_type, "f"));
|
|
119
93
|
}
|
|
120
94
|
get cid() {
|
|
121
95
|
return __classPrivateFieldGet(this, _StreamID_cid, "f");
|
|
122
96
|
}
|
|
123
97
|
get bytes() {
|
|
124
|
-
const codec =
|
|
125
|
-
const type =
|
|
126
|
-
return
|
|
98
|
+
const codec = varint.encode(STREAMID_CODEC);
|
|
99
|
+
const type = varint.encode(this.type);
|
|
100
|
+
return uint8ArrayConcat([codec, type, this.cid.bytes]);
|
|
127
101
|
}
|
|
128
102
|
get baseID() {
|
|
129
103
|
return new StreamID(__classPrivateFieldGet(this, _StreamID_type, "f"), __classPrivateFieldGet(this, _StreamID_cid, "f"));
|
|
130
104
|
}
|
|
131
|
-
atCommit(commit) {
|
|
132
|
-
return new commit_id_1.CommitID(__classPrivateFieldGet(this, _StreamID_type, "f"), __classPrivateFieldGet(this, _StreamID_cid, "f"), commit);
|
|
133
|
-
}
|
|
134
105
|
equals(other) {
|
|
135
106
|
if (StreamID.isInstance(other)) {
|
|
136
107
|
return this.type === other.type && this.cid.equals(other.cid);
|
|
@@ -140,7 +111,7 @@ class StreamID {
|
|
|
140
111
|
}
|
|
141
112
|
}
|
|
142
113
|
toString() {
|
|
143
|
-
return
|
|
114
|
+
return base36.encode(this.bytes);
|
|
144
115
|
}
|
|
145
116
|
toUrl() {
|
|
146
117
|
return `ceramic://${this.toString()}`;
|
|
@@ -157,31 +128,30 @@ StreamID.fromBytesNoThrow = fromBytesNoThrow;
|
|
|
157
128
|
StreamID.fromString = fromString;
|
|
158
129
|
StreamID.fromStringNoThrow = fromStringNoThrow;
|
|
159
130
|
__decorate([
|
|
160
|
-
|
|
131
|
+
Memoize(),
|
|
161
132
|
__metadata("design:type", String),
|
|
162
133
|
__metadata("design:paramtypes", [])
|
|
163
134
|
], StreamID.prototype, "typeName", null);
|
|
164
135
|
__decorate([
|
|
165
|
-
|
|
136
|
+
Memoize(),
|
|
166
137
|
__metadata("design:type", Uint8Array),
|
|
167
138
|
__metadata("design:paramtypes", [])
|
|
168
139
|
], StreamID.prototype, "bytes", null);
|
|
169
140
|
__decorate([
|
|
170
|
-
|
|
141
|
+
Memoize(),
|
|
171
142
|
__metadata("design:type", StreamID),
|
|
172
143
|
__metadata("design:paramtypes", [])
|
|
173
144
|
], StreamID.prototype, "baseID", null);
|
|
174
145
|
__decorate([
|
|
175
|
-
|
|
146
|
+
Memoize(),
|
|
176
147
|
__metadata("design:type", Function),
|
|
177
148
|
__metadata("design:paramtypes", []),
|
|
178
149
|
__metadata("design:returntype", String)
|
|
179
150
|
], StreamID.prototype, "toString", null);
|
|
180
151
|
__decorate([
|
|
181
|
-
|
|
152
|
+
Memoize(),
|
|
182
153
|
__metadata("design:type", Function),
|
|
183
154
|
__metadata("design:paramtypes", []),
|
|
184
155
|
__metadata("design:returntype", String)
|
|
185
156
|
], StreamID.prototype, "toUrl", null);
|
|
186
|
-
exports.StreamID = StreamID;
|
|
187
157
|
//# sourceMappingURL=stream-id.js.map
|