@ceramicnetwork/streamid 1.3.8 → 2.0.0-alpha.1
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 +5 -4
- package/lib/commit-id.d.ts.map +1 -1
- package/lib/commit-id.js +40 -48
- package/lib/commit-id.js.map +1 -1
- package/lib/constants.d.ts +0 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +1 -5
- 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.d.ts +1 -1
- package/lib/reading-bytes.d.ts.map +1 -1
- package/lib/reading-bytes.js +9 -17
- package/lib/reading-bytes.js.map +1 -1
- package/lib/stream-id.d.ts +2 -4
- package/lib/stream-id.d.ts.map +1 -1
- package/lib/stream-id.js +31 -41
- package/lib/stream-id.js.map +1 -1
- package/lib/stream-ref.d.ts +3 -4
- 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.d.ts +0 -0
- package/lib/stream-type.d.ts.map +0 -0
- package/lib/stream-type.js +1 -5
- package/lib/stream-type.js.map +1 -1
- package/package.json +17 -17
- package/CHANGELOG.md +0 -608
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
|
-
import CID from '
|
|
2
|
-
import { StreamID } from './stream-id';
|
|
3
|
-
import { StreamRef } from './stream-ref';
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
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,GAAG,
|
|
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,22 +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 constants_1 = require("./constants");
|
|
36
|
-
const reading_bytes_1 = require("./reading-bytes");
|
|
37
|
-
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';
|
|
38
31
|
function fromBytes(bytes) {
|
|
39
32
|
const result = fromBytesNoThrow(bytes);
|
|
40
33
|
if (result instanceof Error) {
|
|
@@ -43,11 +36,11 @@ function fromBytes(bytes) {
|
|
|
43
36
|
return result;
|
|
44
37
|
}
|
|
45
38
|
function fromBytesNoThrow(bytes) {
|
|
46
|
-
const [streamCodec, streamCodecRemainder] =
|
|
47
|
-
if (streamCodec !==
|
|
39
|
+
const [streamCodec, streamCodecRemainder] = readVarint(bytes);
|
|
40
|
+
if (streamCodec !== STREAMID_CODEC)
|
|
48
41
|
return new Error('fromBytes: invalid streamid, does not include streamid codec');
|
|
49
|
-
const [type, streamtypeRemainder] =
|
|
50
|
-
const cidResult =
|
|
42
|
+
const [type, streamtypeRemainder] = readVarint(streamCodecRemainder);
|
|
43
|
+
const cidResult = readCid(streamtypeRemainder);
|
|
51
44
|
if (cidResult instanceof Error) {
|
|
52
45
|
return cidResult;
|
|
53
46
|
}
|
|
@@ -59,15 +52,15 @@ function fromBytesNoThrow(bytes) {
|
|
|
59
52
|
return new CommitID(type, base, baseRemainder[0]);
|
|
60
53
|
}
|
|
61
54
|
else {
|
|
62
|
-
const [commit] =
|
|
55
|
+
const [commit] = readCid(baseRemainder);
|
|
63
56
|
return new CommitID(type, base, commit);
|
|
64
57
|
}
|
|
65
58
|
}
|
|
66
59
|
function parseCID(input) {
|
|
67
60
|
try {
|
|
68
|
-
return
|
|
61
|
+
return typeof input === 'string' ? CID.parse(input) : CID.asCID(input);
|
|
69
62
|
}
|
|
70
|
-
catch
|
|
63
|
+
catch {
|
|
71
64
|
return undefined;
|
|
72
65
|
}
|
|
73
66
|
}
|
|
@@ -102,14 +95,17 @@ function fromStringNoThrow(input) {
|
|
|
102
95
|
if (protocolFree.includes('commit')) {
|
|
103
96
|
const commit = protocolFree.split('?')[1].split('=')[1];
|
|
104
97
|
const base = protocolFree.split('?')[0];
|
|
105
|
-
return
|
|
98
|
+
return make(StreamID.fromString(base), commit);
|
|
106
99
|
}
|
|
107
100
|
else {
|
|
108
|
-
return fromBytesNoThrow(
|
|
101
|
+
return fromBytesNoThrow(base36.decode(protocolFree));
|
|
109
102
|
}
|
|
110
103
|
}
|
|
111
104
|
const TAG = Symbol.for('@ceramicnetwork/streamid/CommitID');
|
|
112
|
-
|
|
105
|
+
function make(stream, commit) {
|
|
106
|
+
return new CommitID(stream.type, stream.cid, commit);
|
|
107
|
+
}
|
|
108
|
+
export class CommitID {
|
|
113
109
|
constructor(type, cid, commit = null) {
|
|
114
110
|
this._tag = TAG;
|
|
115
111
|
_CommitID_type.set(this, void 0);
|
|
@@ -119,21 +115,21 @@ class CommitID {
|
|
|
119
115
|
throw new Error('constructor: type required');
|
|
120
116
|
if (!cid)
|
|
121
117
|
throw new Error('constructor: cid required');
|
|
122
|
-
__classPrivateFieldSet(this, _CommitID_type, typeof type === 'string' ?
|
|
123
|
-
__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");
|
|
124
120
|
__classPrivateFieldSet(this, _CommitID_commit, parseCommit(__classPrivateFieldGet(this, _CommitID_cid, "f"), commit), "f");
|
|
125
121
|
}
|
|
126
122
|
static isInstance(instance) {
|
|
127
123
|
return typeof instance === 'object' && '_tag' in instance && instance._tag === TAG;
|
|
128
124
|
}
|
|
129
125
|
get baseID() {
|
|
130
|
-
return new
|
|
126
|
+
return new StreamID(__classPrivateFieldGet(this, _CommitID_type, "f"), __classPrivateFieldGet(this, _CommitID_cid, "f"));
|
|
131
127
|
}
|
|
132
128
|
get type() {
|
|
133
129
|
return __classPrivateFieldGet(this, _CommitID_type, "f");
|
|
134
130
|
}
|
|
135
131
|
get typeName() {
|
|
136
|
-
return
|
|
132
|
+
return StreamType.nameByCode(__classPrivateFieldGet(this, _CommitID_type, "f"));
|
|
137
133
|
}
|
|
138
134
|
get cid() {
|
|
139
135
|
return __classPrivateFieldGet(this, _CommitID_cid, "f");
|
|
@@ -142,20 +138,16 @@ class CommitID {
|
|
|
142
138
|
return __classPrivateFieldGet(this, _CommitID_commit, "f") || __classPrivateFieldGet(this, _CommitID_cid, "f");
|
|
143
139
|
}
|
|
144
140
|
get bytes() {
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
return concat_1.default([codec, type, this.cid.bytes, commitBytes]);
|
|
150
|
-
}
|
|
151
|
-
atCommit(commit) {
|
|
152
|
-
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]);
|
|
153
145
|
}
|
|
154
146
|
equals(other) {
|
|
155
147
|
return (this.type === other.type && this.cid.equals(other.cid) && this.commit.equals(other.commit));
|
|
156
148
|
}
|
|
157
149
|
toString() {
|
|
158
|
-
return
|
|
150
|
+
return base36.encode(this.bytes);
|
|
159
151
|
}
|
|
160
152
|
toUrl() {
|
|
161
153
|
return `ceramic://${this.toString()}`;
|
|
@@ -171,37 +163,37 @@ CommitID.fromBytes = fromBytes;
|
|
|
171
163
|
CommitID.fromBytesNoThrow = fromBytesNoThrow;
|
|
172
164
|
CommitID.fromString = fromString;
|
|
173
165
|
CommitID.fromStringNoThrow = fromStringNoThrow;
|
|
166
|
+
CommitID.make = make;
|
|
174
167
|
__decorate([
|
|
175
|
-
|
|
176
|
-
__metadata("design:type",
|
|
168
|
+
Memoize(),
|
|
169
|
+
__metadata("design:type", StreamID),
|
|
177
170
|
__metadata("design:paramtypes", [])
|
|
178
171
|
], CommitID.prototype, "baseID", null);
|
|
179
172
|
__decorate([
|
|
180
|
-
|
|
173
|
+
Memoize(),
|
|
181
174
|
__metadata("design:type", String),
|
|
182
175
|
__metadata("design:paramtypes", [])
|
|
183
176
|
], CommitID.prototype, "typeName", null);
|
|
184
177
|
__decorate([
|
|
185
|
-
|
|
186
|
-
__metadata("design:type",
|
|
178
|
+
Memoize(),
|
|
179
|
+
__metadata("design:type", CID),
|
|
187
180
|
__metadata("design:paramtypes", [])
|
|
188
181
|
], CommitID.prototype, "commit", null);
|
|
189
182
|
__decorate([
|
|
190
|
-
|
|
183
|
+
Memoize(),
|
|
191
184
|
__metadata("design:type", Uint8Array),
|
|
192
185
|
__metadata("design:paramtypes", [])
|
|
193
186
|
], CommitID.prototype, "bytes", null);
|
|
194
187
|
__decorate([
|
|
195
|
-
|
|
188
|
+
Memoize(),
|
|
196
189
|
__metadata("design:type", Function),
|
|
197
190
|
__metadata("design:paramtypes", []),
|
|
198
191
|
__metadata("design:returntype", String)
|
|
199
192
|
], CommitID.prototype, "toString", null);
|
|
200
193
|
__decorate([
|
|
201
|
-
|
|
194
|
+
Memoize(),
|
|
202
195
|
__metadata("design:type", Function),
|
|
203
196
|
__metadata("design:paramtypes", []),
|
|
204
197
|
__metadata("design:returntype", String)
|
|
205
198
|
], CommitID.prototype, "toUrl", null);
|
|
206
|
-
exports.CommitID = CommitID;
|
|
207
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,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AA;AAgClB;IADC,OAAO,EAAE;8BACI,QAAQ;;sCAErB;AAaD;IADC,OAAO,EAAE;;;wCAGT;AAaD;IADC,OAAO,EAAE;8BACI,GAAG;;sCAEhB;AAMD;IADC,OAAO,EAAE;8BACG,UAAU;;qCAMtB;AAeD;IADC,OAAO,EAAE;;;;wCAGT;AAMD;IADC,OAAO,EAAE;;;;qCAGT"}
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,MAAM,CAAA
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,MAAM,CAAA"}
|
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_BASE = exports.STREAMID_CODEC = void 0;
|
|
4
|
-
exports.STREAMID_CODEC = 206;
|
|
5
|
-
exports.DEFAULT_BASE = 'base36';
|
|
1
|
+
export const STREAMID_CODEC = 206;
|
|
6
2
|
//# sourceMappingURL=constants.js.map
|
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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import CID from '
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
2
|
export declare function readVarint(bytes: Uint8Array): [number, Uint8Array, number];
|
|
3
3
|
export declare function readCid(bytes: Uint8Array): [CID, Uint8Array];
|
|
4
4
|
export declare function readCidNoThrow(bytes: Uint8Array): [CID, Uint8Array] | Error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reading-bytes.d.ts","sourceRoot":"","sources":["../src/reading-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"reading-bytes.d.ts","sourceRoot":"","sources":["../src/reading-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAItC,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAK1E;AAMD,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAM5D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,KAAK,CAW3E"}
|
package/lib/reading-bytes.js
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const cids_1 = __importDefault(require("cids"));
|
|
8
|
-
const varint_1 = __importDefault(require("varint"));
|
|
9
|
-
function readVarint(bytes) {
|
|
10
|
-
const value = varint_1.default.decode(bytes);
|
|
11
|
-
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;
|
|
12
7
|
const remainder = bytes.slice(readLength);
|
|
13
8
|
return [value, remainder, readLength];
|
|
14
9
|
}
|
|
15
|
-
exports.readVarint = readVarint;
|
|
16
10
|
function isCidVersion(input) {
|
|
17
11
|
return input === 0 || input === 1;
|
|
18
12
|
}
|
|
19
|
-
function readCid(bytes) {
|
|
13
|
+
export function readCid(bytes) {
|
|
20
14
|
const result = readCidNoThrow(bytes);
|
|
21
15
|
if (result instanceof Error) {
|
|
22
16
|
throw result;
|
|
23
17
|
}
|
|
24
18
|
return result;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
function readCidNoThrow(bytes) {
|
|
20
|
+
export function readCidNoThrow(bytes) {
|
|
28
21
|
const [cidVersion, cidVersionRemainder] = readVarint(bytes);
|
|
29
22
|
if (!isCidVersion(cidVersion)) {
|
|
30
23
|
return new Error(`Unknown CID version ${cidVersion}`);
|
|
@@ -34,7 +27,6 @@ function readCidNoThrow(bytes) {
|
|
|
34
27
|
const [mhLength, , mhLengthLength] = readVarint(mhCodecRemainder);
|
|
35
28
|
const multihashBytes = codecRemainder.slice(0, mhCodecLength + mhLengthLength + mhLength);
|
|
36
29
|
const multihashBytesRemainder = codecRemainder.slice(mhCodecLength + mhLengthLength + mhLength);
|
|
37
|
-
return [
|
|
30
|
+
return [CID.create(cidVersion, codec, decodeMultiHash(multihashBytes)), multihashBytesRemainder];
|
|
38
31
|
}
|
|
39
|
-
exports.readCidNoThrow = readCidNoThrow;
|
|
40
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
|
-
import CID from '
|
|
2
|
-
import {
|
|
3
|
-
import { StreamRef } from './stream-ref';
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
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,
|
|
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,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,23 +18,18 @@ 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 _StreamID_type, _StreamID_cid;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const commit_id_1 = require("./commit-id");
|
|
38
|
-
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';
|
|
39
33
|
function fromBytes(bytes) {
|
|
40
34
|
const result = fromBytesNoThrow(bytes);
|
|
41
35
|
if (result instanceof Error) {
|
|
@@ -44,11 +38,11 @@ function fromBytes(bytes) {
|
|
|
44
38
|
return result;
|
|
45
39
|
}
|
|
46
40
|
function fromBytesNoThrow(bytes) {
|
|
47
|
-
const [streamCodec, streamCodecRemainder] =
|
|
48
|
-
if (streamCodec !==
|
|
41
|
+
const [streamCodec, streamCodecRemainder] = readVarint(bytes);
|
|
42
|
+
if (streamCodec !== STREAMID_CODEC)
|
|
49
43
|
return new Error('fromBytes: invalid streamid, does not include streamid codec');
|
|
50
|
-
const [type, streamTypeRemainder] =
|
|
51
|
-
const cidResult =
|
|
44
|
+
const [type, streamTypeRemainder] = readVarint(streamCodecRemainder);
|
|
45
|
+
const cidResult = readCidNoThrow(streamTypeRemainder);
|
|
52
46
|
if (cidResult instanceof Error) {
|
|
53
47
|
return cidResult;
|
|
54
48
|
}
|
|
@@ -68,11 +62,11 @@ function fromString(input) {
|
|
|
68
62
|
function fromStringNoThrow(input) {
|
|
69
63
|
const protocolFree = input.replace('ceramic://', '').replace('/ceramic/', '');
|
|
70
64
|
const commitFree = protocolFree.includes('commit') ? protocolFree.split('?')[0] : protocolFree;
|
|
71
|
-
const bytes =
|
|
65
|
+
const bytes = base36.decode(commitFree);
|
|
72
66
|
return fromBytesNoThrow(bytes);
|
|
73
67
|
}
|
|
74
68
|
const TAG = Symbol.for('@ceramicnetwork/streamid/StreamID');
|
|
75
|
-
class StreamID {
|
|
69
|
+
export class StreamID {
|
|
76
70
|
constructor(type, cid) {
|
|
77
71
|
this._tag = TAG;
|
|
78
72
|
_StreamID_type.set(this, void 0);
|
|
@@ -81,36 +75,33 @@ class StreamID {
|
|
|
81
75
|
throw new Error('constructor: type required');
|
|
82
76
|
if (!cid)
|
|
83
77
|
throw new Error('constructor: cid required');
|
|
84
|
-
__classPrivateFieldSet(this, _StreamID_type, typeof type === 'string' ?
|
|
85
|
-
__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");
|
|
86
80
|
}
|
|
87
81
|
static isInstance(instance) {
|
|
88
82
|
return typeof instance === 'object' && '_tag' in instance && instance._tag === TAG;
|
|
89
83
|
}
|
|
90
84
|
static async fromGenesis(type, genesis) {
|
|
91
|
-
const
|
|
92
|
-
return new StreamID(type, cid);
|
|
85
|
+
const block = await Block.encode({ value: genesis, codec, hasher });
|
|
86
|
+
return new StreamID(type, block.cid);
|
|
93
87
|
}
|
|
94
88
|
get type() {
|
|
95
89
|
return __classPrivateFieldGet(this, _StreamID_type, "f");
|
|
96
90
|
}
|
|
97
91
|
get typeName() {
|
|
98
|
-
return
|
|
92
|
+
return StreamType.nameByCode(__classPrivateFieldGet(this, _StreamID_type, "f"));
|
|
99
93
|
}
|
|
100
94
|
get cid() {
|
|
101
95
|
return __classPrivateFieldGet(this, _StreamID_cid, "f");
|
|
102
96
|
}
|
|
103
97
|
get bytes() {
|
|
104
|
-
const codec =
|
|
105
|
-
const type =
|
|
106
|
-
return
|
|
98
|
+
const codec = varint.encode(STREAMID_CODEC);
|
|
99
|
+
const type = varint.encode(this.type);
|
|
100
|
+
return uint8ArrayConcat([codec, type, this.cid.bytes]);
|
|
107
101
|
}
|
|
108
102
|
get baseID() {
|
|
109
103
|
return new StreamID(__classPrivateFieldGet(this, _StreamID_type, "f"), __classPrivateFieldGet(this, _StreamID_cid, "f"));
|
|
110
104
|
}
|
|
111
|
-
atCommit(commit) {
|
|
112
|
-
return new commit_id_1.CommitID(__classPrivateFieldGet(this, _StreamID_type, "f"), __classPrivateFieldGet(this, _StreamID_cid, "f"), commit);
|
|
113
|
-
}
|
|
114
105
|
equals(other) {
|
|
115
106
|
if (StreamID.isInstance(other)) {
|
|
116
107
|
return this.type === other.type && this.cid.equals(other.cid);
|
|
@@ -120,7 +111,7 @@ class StreamID {
|
|
|
120
111
|
}
|
|
121
112
|
}
|
|
122
113
|
toString() {
|
|
123
|
-
return
|
|
114
|
+
return base36.encode(this.bytes);
|
|
124
115
|
}
|
|
125
116
|
toUrl() {
|
|
126
117
|
return `ceramic://${this.toString()}`;
|
|
@@ -137,31 +128,30 @@ StreamID.fromBytesNoThrow = fromBytesNoThrow;
|
|
|
137
128
|
StreamID.fromString = fromString;
|
|
138
129
|
StreamID.fromStringNoThrow = fromStringNoThrow;
|
|
139
130
|
__decorate([
|
|
140
|
-
|
|
131
|
+
Memoize(),
|
|
141
132
|
__metadata("design:type", String),
|
|
142
133
|
__metadata("design:paramtypes", [])
|
|
143
134
|
], StreamID.prototype, "typeName", null);
|
|
144
135
|
__decorate([
|
|
145
|
-
|
|
136
|
+
Memoize(),
|
|
146
137
|
__metadata("design:type", Uint8Array),
|
|
147
138
|
__metadata("design:paramtypes", [])
|
|
148
139
|
], StreamID.prototype, "bytes", null);
|
|
149
140
|
__decorate([
|
|
150
|
-
|
|
141
|
+
Memoize(),
|
|
151
142
|
__metadata("design:type", StreamID),
|
|
152
143
|
__metadata("design:paramtypes", [])
|
|
153
144
|
], StreamID.prototype, "baseID", null);
|
|
154
145
|
__decorate([
|
|
155
|
-
|
|
146
|
+
Memoize(),
|
|
156
147
|
__metadata("design:type", Function),
|
|
157
148
|
__metadata("design:paramtypes", []),
|
|
158
149
|
__metadata("design:returntype", String)
|
|
159
150
|
], StreamID.prototype, "toString", null);
|
|
160
151
|
__decorate([
|
|
161
|
-
|
|
152
|
+
Memoize(),
|
|
162
153
|
__metadata("design:type", Function),
|
|
163
154
|
__metadata("design:paramtypes", []),
|
|
164
155
|
__metadata("design:returntype", String)
|
|
165
156
|
], StreamID.prototype, "toUrl", null);
|
|
166
|
-
exports.StreamID = StreamID;
|
|
167
157
|
//# sourceMappingURL=stream-id.js.map
|