@ceramicnetwork/streamid 1.3.4-rc.0 → 2.0.0-alpha.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/CHANGELOG.md +27 -0
- package/lib/commit-id.d.ts +5 -1
- package/lib/commit-id.d.ts.map +1 -1
- package/lib/commit-id.js +32 -13
- 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 -2
- package/lib/constants.js.map +1 -1
- package/lib/reading-bytes.d.ts +2 -1
- package/lib/reading-bytes.d.ts.map +1 -1
- package/lib/reading-bytes.js +14 -5
- package/lib/reading-bytes.js.map +1 -1
- package/lib/stream-id.d.ts +5 -1
- package/lib/stream-id.d.ts.map +1 -1
- package/lib/stream-id.js +55 -15
- package/lib/stream-id.js.map +1 -1
- package/lib/stream-ref.d.ts +1 -1
- package/lib/stream-ref.d.ts.map +1 -1
- package/lib/stream-ref.js +10 -29
- package/lib/stream-ref.js.map +1 -1
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.0.0-alpha.0](https://github.com/ceramicnetwork/js-ceramic/compare/@ceramicnetwork/streamid@1.3.5-rc.0...@ceramicnetwork/streamid@2.0.0-alpha.0) (2021-12-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ceramicnetwork/streamid
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.3.5-rc.0](https://github.com/ceramicnetwork/js-ceramic/compare/@ceramicnetwork/streamid@1.3.4...@ceramicnetwork/streamid@1.3.5-rc.0) (2021-11-17)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* resolve merge conflicts during merge from `main` ([#1848](https://github.com/ceramicnetwork/js-ceramic/issues/1848)) ([6772fc6](https://github.com/ceramicnetwork/js-ceramic/commit/6772fc6c61bc9daadfd3f6d6ecf3de2bb100450d))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [1.3.4](https://github.com/ceramicnetwork/js-ceramic/compare/@ceramicnetwork/streamid@1.3.4-rc.0...@ceramicnetwork/streamid@1.3.4) (2021-11-17)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @ceramicnetwork/streamid
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
## [1.3.4-rc.0](https://github.com/ceramicnetwork/js-ceramic/compare/@ceramicnetwork/streamid@1.3.3...@ceramicnetwork/streamid@1.3.4-rc.0) (2021-11-12)
|
|
7
34
|
|
|
8
35
|
**Note:** Version bump only for package @ceramicnetwork/streamid
|
package/lib/commit-id.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import CID from '
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
2
|
import { StreamID } from './stream-id';
|
|
3
3
|
import { StreamRef } from './stream-ref';
|
|
4
4
|
declare function fromBytes(bytes: Uint8Array): CommitID;
|
|
5
|
+
declare function fromBytesNoThrow(bytes: Uint8Array): CommitID | Error;
|
|
5
6
|
declare function fromString(input: string): CommitID;
|
|
7
|
+
declare function fromStringNoThrow(input: string): CommitID | Error;
|
|
6
8
|
export declare class CommitID implements StreamRef {
|
|
7
9
|
#private;
|
|
8
10
|
protected readonly _tag: symbol;
|
|
9
11
|
static fromBytes: typeof fromBytes;
|
|
12
|
+
static fromBytesNoThrow: typeof fromBytesNoThrow;
|
|
10
13
|
static fromString: typeof fromString;
|
|
14
|
+
static fromStringNoThrow: typeof fromStringNoThrow;
|
|
11
15
|
static isInstance(instance: any): instance is CommitID;
|
|
12
16
|
constructor(type: string | number, cid: CID | string, commit?: CID | string | number);
|
|
13
17
|
get baseID(): StreamID;
|
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,aAAa,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AASxC,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;AAWD,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;IAK5C,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,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ;IAOjD,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
|
@@ -25,24 +25,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
var _CommitID_type, _CommitID_cid, _CommitID_commit;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.CommitID = void 0;
|
|
28
|
-
const
|
|
29
|
-
const
|
|
28
|
+
const cid_1 = require("multiformats/cid");
|
|
29
|
+
const base36_1 = require("multiformats/bases/base36");
|
|
30
30
|
const stream_type_1 = require("./stream-type");
|
|
31
31
|
const varint_1 = __importDefault(require("varint"));
|
|
32
|
-
const
|
|
33
|
-
const to_string_1 = __importDefault(require("uint8arrays/to-string"));
|
|
32
|
+
const uint8arrays_1 = require("uint8arrays");
|
|
34
33
|
const typescript_memoize_1 = require("typescript-memoize");
|
|
35
34
|
const constants_1 = require("./constants");
|
|
36
35
|
const reading_bytes_1 = require("./reading-bytes");
|
|
37
36
|
const stream_id_1 = require("./stream-id");
|
|
38
37
|
function fromBytes(bytes) {
|
|
38
|
+
const result = fromBytesNoThrow(bytes);
|
|
39
|
+
if (result instanceof Error) {
|
|
40
|
+
throw result;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
function fromBytesNoThrow(bytes) {
|
|
39
45
|
const [streamCodec, streamCodecRemainder] = reading_bytes_1.readVarint(bytes);
|
|
40
46
|
if (streamCodec !== constants_1.STREAMID_CODEC)
|
|
41
|
-
|
|
47
|
+
return new Error('fromBytes: invalid streamid, does not include streamid codec');
|
|
42
48
|
const [type, streamtypeRemainder] = reading_bytes_1.readVarint(streamCodecRemainder);
|
|
43
|
-
const
|
|
49
|
+
const cidResult = reading_bytes_1.readCid(streamtypeRemainder);
|
|
50
|
+
if (cidResult instanceof Error) {
|
|
51
|
+
return cidResult;
|
|
52
|
+
}
|
|
53
|
+
const [base, baseRemainder] = cidResult;
|
|
44
54
|
if (baseRemainder.length === 0) {
|
|
45
|
-
|
|
55
|
+
return new Error(`No commit information provided`);
|
|
46
56
|
}
|
|
47
57
|
else if (baseRemainder.length === 1) {
|
|
48
58
|
return new CommitID(type, base, baseRemainder[0]);
|
|
@@ -54,7 +64,7 @@ function fromBytes(bytes) {
|
|
|
54
64
|
}
|
|
55
65
|
function parseCID(input) {
|
|
56
66
|
try {
|
|
57
|
-
return
|
|
67
|
+
return typeof input === 'string' ? cid_1.CID.parse(input) : cid_1.CID.asCID(input);
|
|
58
68
|
}
|
|
59
69
|
catch (_a) {
|
|
60
70
|
return undefined;
|
|
@@ -80,6 +90,13 @@ function parseCommit(genesis, commit = null) {
|
|
|
80
90
|
}
|
|
81
91
|
}
|
|
82
92
|
function fromString(input) {
|
|
93
|
+
const result = fromStringNoThrow(input);
|
|
94
|
+
if (result instanceof Error) {
|
|
95
|
+
throw result;
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
function fromStringNoThrow(input) {
|
|
83
100
|
const protocolFree = input.replace('ceramic://', '').replace('/ceramic/', '');
|
|
84
101
|
if (protocolFree.includes('commit')) {
|
|
85
102
|
const commit = protocolFree.split('?')[1].split('=')[1];
|
|
@@ -87,7 +104,7 @@ function fromString(input) {
|
|
|
87
104
|
return stream_id_1.StreamID.fromString(base).atCommit(commit);
|
|
88
105
|
}
|
|
89
106
|
else {
|
|
90
|
-
return
|
|
107
|
+
return fromBytesNoThrow(base36_1.base36.decode(protocolFree));
|
|
91
108
|
}
|
|
92
109
|
}
|
|
93
110
|
const TAG = Symbol.for('@ceramicnetwork/streamid/CommitID');
|
|
@@ -102,7 +119,7 @@ class CommitID {
|
|
|
102
119
|
if (!cid)
|
|
103
120
|
throw new Error('constructor: cid required');
|
|
104
121
|
__classPrivateFieldSet(this, _CommitID_type, typeof type === 'string' ? stream_type_1.StreamType.codeByName(type) : type, "f");
|
|
105
|
-
__classPrivateFieldSet(this, _CommitID_cid, typeof cid === 'string' ?
|
|
122
|
+
__classPrivateFieldSet(this, _CommitID_cid, typeof cid === 'string' ? cid_1.CID.parse(cid) : cid, "f");
|
|
106
123
|
__classPrivateFieldSet(this, _CommitID_commit, parseCommit(__classPrivateFieldGet(this, _CommitID_cid, "f"), commit), "f");
|
|
107
124
|
}
|
|
108
125
|
static isInstance(instance) {
|
|
@@ -128,7 +145,7 @@ class CommitID {
|
|
|
128
145
|
const codec = varint_1.default.encode(constants_1.STREAMID_CODEC);
|
|
129
146
|
const type = varint_1.default.encode(this.type);
|
|
130
147
|
const commitBytes = ((_a = __classPrivateFieldGet(this, _CommitID_commit, "f")) === null || _a === void 0 ? void 0 : _a.bytes) || new Uint8Array([0]);
|
|
131
|
-
return
|
|
148
|
+
return uint8arrays_1.concat([codec, type, this.cid.bytes, commitBytes]);
|
|
132
149
|
}
|
|
133
150
|
atCommit(commit) {
|
|
134
151
|
return new CommitID(__classPrivateFieldGet(this, _CommitID_type, "f"), __classPrivateFieldGet(this, _CommitID_cid, "f"), commit);
|
|
@@ -137,7 +154,7 @@ class CommitID {
|
|
|
137
154
|
return (this.type === other.type && this.cid.equals(other.cid) && this.commit.equals(other.commit));
|
|
138
155
|
}
|
|
139
156
|
toString() {
|
|
140
|
-
return
|
|
157
|
+
return base36_1.base36.encode(this.bytes);
|
|
141
158
|
}
|
|
142
159
|
toUrl() {
|
|
143
160
|
return `ceramic://${this.toString()}`;
|
|
@@ -150,7 +167,9 @@ class CommitID {
|
|
|
150
167
|
}
|
|
151
168
|
}
|
|
152
169
|
CommitID.fromBytes = fromBytes;
|
|
170
|
+
CommitID.fromBytesNoThrow = fromBytesNoThrow;
|
|
153
171
|
CommitID.fromString = fromString;
|
|
172
|
+
CommitID.fromStringNoThrow = fromStringNoThrow;
|
|
154
173
|
__decorate([
|
|
155
174
|
typescript_memoize_1.Memoize(),
|
|
156
175
|
__metadata("design:type", stream_id_1.StreamID),
|
|
@@ -163,7 +182,7 @@ __decorate([
|
|
|
163
182
|
], CommitID.prototype, "typeName", null);
|
|
164
183
|
__decorate([
|
|
165
184
|
typescript_memoize_1.Memoize(),
|
|
166
|
-
__metadata("design:type",
|
|
185
|
+
__metadata("design:type", cid_1.CID),
|
|
167
186
|
__metadata("design:paramtypes", [])
|
|
168
187
|
], CommitID.prototype, "commit", null);
|
|
169
188
|
__decorate([
|
package/lib/commit-id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit-id.js","sourceRoot":"","sources":["../src/commit-id.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"commit-id.js","sourceRoot":"","sources":["../src/commit-id.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAsC;AACtC,sDAAkD;AAClD,+CAA0C;AAC1C,oDAA2B;AAC3B,6CAAwD;AACxD,2DAA4C;AAC5C,2CAA4C;AAC5C,mDAAqD;AACrD,2CAAsC;AAUtC,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,0BAAU,CAAC,KAAK,CAAC,CAAA;IAC7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ACnC,mBAAU,GAAG,UAAU,CAAA;AACvB,0BAAiB,GAAG,iBAAiB,CAAA;AAgC5C;IADC,4BAAO,EAAE;8BACI,oBAAQ;;sCAErB;AAaD;IADC,4BAAO,EAAE;;;wCAGT;AAaD;IADC,4BAAO,EAAE;8BACI,SAAG;;sCAEhB;AAMD;IADC,4BAAO,EAAE;8BACG,UAAU;;qCAMtB;AAsBD;IADC,4BAAO,EAAE;;;;wCAGT;AAMD;IADC,4BAAO,EAAE;;;;qCAGT;AAtHH,4BA2IC"}
|
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,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.STREAMID_CODEC = void 0;
|
|
4
4
|
exports.STREAMID_CODEC = 206;
|
|
5
|
-
exports.DEFAULT_BASE = 'base36';
|
|
6
5
|
//# 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":";;;AAAa,QAAA,cAAc,GAAG,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,GAAG,CAAA"}
|
package/lib/reading-bytes.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
|
+
export declare function readCidNoThrow(bytes: Uint8Array): [CID, Uint8Array] | Error;
|
|
4
5
|
//# sourceMappingURL=reading-bytes.d.ts.map
|
|
@@ -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
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readCid = exports.readVarint = void 0;
|
|
7
|
-
const
|
|
6
|
+
exports.readCidNoThrow = exports.readCid = exports.readVarint = void 0;
|
|
7
|
+
const cid_1 = require("multiformats/cid");
|
|
8
8
|
const varint_1 = __importDefault(require("varint"));
|
|
9
|
+
const digest_1 = require("multiformats/hashes/digest");
|
|
9
10
|
function readVarint(bytes) {
|
|
10
11
|
const value = varint_1.default.decode(bytes);
|
|
11
12
|
const readLength = varint_1.default.decode.bytes;
|
|
@@ -17,16 +18,24 @@ function isCidVersion(input) {
|
|
|
17
18
|
return input === 0 || input === 1;
|
|
18
19
|
}
|
|
19
20
|
function readCid(bytes) {
|
|
21
|
+
const result = readCidNoThrow(bytes);
|
|
22
|
+
if (result instanceof Error) {
|
|
23
|
+
throw result;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
exports.readCid = readCid;
|
|
28
|
+
function readCidNoThrow(bytes) {
|
|
20
29
|
const [cidVersion, cidVersionRemainder] = readVarint(bytes);
|
|
21
30
|
if (!isCidVersion(cidVersion)) {
|
|
22
|
-
|
|
31
|
+
return new Error(`Unknown CID version ${cidVersion}`);
|
|
23
32
|
}
|
|
24
33
|
const [codec, codecRemainder] = readVarint(cidVersionRemainder);
|
|
25
34
|
const [, mhCodecRemainder, mhCodecLength] = readVarint(codecRemainder);
|
|
26
35
|
const [mhLength, , mhLengthLength] = readVarint(mhCodecRemainder);
|
|
27
36
|
const multihashBytes = codecRemainder.slice(0, mhCodecLength + mhLengthLength + mhLength);
|
|
28
37
|
const multihashBytesRemainder = codecRemainder.slice(mhCodecLength + mhLengthLength + mhLength);
|
|
29
|
-
return [
|
|
38
|
+
return [cid_1.CID.create(cidVersion, codec, digest_1.decode(multihashBytes)), multihashBytesRemainder];
|
|
30
39
|
}
|
|
31
|
-
exports.
|
|
40
|
+
exports.readCidNoThrow = readCidNoThrow;
|
|
32
41
|
//# 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":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"reading-bytes.js","sourceRoot":"","sources":["../src/reading-bytes.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAsC;AACtC,oDAA2B;AAC3B,uDAAsE;AAEtE,SAAgB,UAA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AK,CAAC,aAAa,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAA;IAC/F,OAAO,CAAC,SAAG,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,eAAe,CAAC,cAAc,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAA;AAClG,CAAC;AAXD,wCAWC"}
|
package/lib/stream-id.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import CID from '
|
|
1
|
+
import { CID } from 'multiformats/cid';
|
|
2
2
|
import { CommitID } from './commit-id';
|
|
3
3
|
import { StreamRef } from './stream-ref';
|
|
4
4
|
declare function fromBytes(bytes: Uint8Array): StreamID;
|
|
5
|
+
declare function fromBytesNoThrow(bytes: Uint8Array): StreamID | Error;
|
|
5
6
|
declare function fromString(input: string): StreamID;
|
|
7
|
+
declare function fromStringNoThrow(input: string): StreamID | Error;
|
|
6
8
|
export declare class StreamID implements StreamRef {
|
|
7
9
|
#private;
|
|
8
10
|
protected readonly _tag: symbol;
|
|
9
11
|
static fromBytes: typeof fromBytes;
|
|
12
|
+
static fromBytesNoThrow: typeof fromBytesNoThrow;
|
|
10
13
|
static fromString: typeof fromString;
|
|
14
|
+
static fromStringNoThrow: typeof fromStringNoThrow;
|
|
11
15
|
static isInstance(instance: any): instance is StreamID;
|
|
12
16
|
constructor(type: string | number, cid: CID | string);
|
|
13
17
|
static fromGenesis(type: string | number, genesis: Record<string, any>): Promise<StreamID>;
|
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,GAAG,
|
|
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,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OA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AG/B"}
|
package/lib/stream-id.js
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
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
|
+
});
|
|
2
14
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
17
|
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;
|
|
6
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
19
|
};
|
|
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
|
+
};
|
|
8
27
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
28
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
29
|
};
|
|
@@ -25,33 +44,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
44
|
var _StreamID_type, _StreamID_cid;
|
|
26
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
46
|
exports.StreamID = void 0;
|
|
28
|
-
const
|
|
29
|
-
const
|
|
47
|
+
const cid_1 = require("multiformats/cid");
|
|
48
|
+
const Block = __importStar(require("multiformats/block"));
|
|
49
|
+
const base36_1 = require("multiformats/bases/base36");
|
|
50
|
+
const sha2_1 = require("multiformats/hashes/sha2");
|
|
30
51
|
const varint_1 = __importDefault(require("varint"));
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const to_string_1 = __importDefault(require("uint8arrays/to-string"));
|
|
52
|
+
const codec = __importStar(require("@ipld/dag-cbor"));
|
|
53
|
+
const uint8arrays_1 = require("uint8arrays");
|
|
34
54
|
const constants_1 = require("./constants");
|
|
35
55
|
const reading_bytes_1 = require("./reading-bytes");
|
|
36
56
|
const typescript_memoize_1 = require("typescript-memoize");
|
|
37
57
|
const commit_id_1 = require("./commit-id");
|
|
38
58
|
const stream_type_1 = require("./stream-type");
|
|
39
59
|
function fromBytes(bytes) {
|
|
60
|
+
const result = fromBytesNoThrow(bytes);
|
|
61
|
+
if (result instanceof Error) {
|
|
62
|
+
throw result;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function fromBytesNoThrow(bytes) {
|
|
40
67
|
const [streamCodec, streamCodecRemainder] = reading_bytes_1.readVarint(bytes);
|
|
41
68
|
if (streamCodec !== constants_1.STREAMID_CODEC)
|
|
42
|
-
|
|
69
|
+
return new Error('fromBytes: invalid streamid, does not include streamid codec');
|
|
43
70
|
const [type, streamTypeRemainder] = reading_bytes_1.readVarint(streamCodecRemainder);
|
|
44
|
-
const
|
|
71
|
+
const cidResult = reading_bytes_1.readCidNoThrow(streamTypeRemainder);
|
|
72
|
+
if (cidResult instanceof Error) {
|
|
73
|
+
return cidResult;
|
|
74
|
+
}
|
|
75
|
+
const [cid, cidRemainder] = cidResult;
|
|
45
76
|
if (cidRemainder.length > 0) {
|
|
46
|
-
|
|
77
|
+
return new Error(`Invalid StreamID: contains commit`);
|
|
47
78
|
}
|
|
48
79
|
return new StreamID(type, cid);
|
|
49
80
|
}
|
|
50
81
|
function fromString(input) {
|
|
82
|
+
const result = fromStringNoThrow(input);
|
|
83
|
+
if (result instanceof Error) {
|
|
84
|
+
throw result;
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
function fromStringNoThrow(input) {
|
|
51
89
|
const protocolFree = input.replace('ceramic://', '').replace('/ceramic/', '');
|
|
52
90
|
const commitFree = protocolFree.includes('commit') ? protocolFree.split('?')[0] : protocolFree;
|
|
53
|
-
const bytes =
|
|
54
|
-
return
|
|
91
|
+
const bytes = base36_1.base36.decode(commitFree);
|
|
92
|
+
return fromBytesNoThrow(bytes);
|
|
55
93
|
}
|
|
56
94
|
const TAG = Symbol.for('@ceramicnetwork/streamid/StreamID');
|
|
57
95
|
class StreamID {
|
|
@@ -64,14 +102,14 @@ class StreamID {
|
|
|
64
102
|
if (!cid)
|
|
65
103
|
throw new Error('constructor: cid required');
|
|
66
104
|
__classPrivateFieldSet(this, _StreamID_type, typeof type === 'string' ? stream_type_1.StreamType.codeByName(type) : type, "f");
|
|
67
|
-
__classPrivateFieldSet(this, _StreamID_cid, typeof cid === 'string' ?
|
|
105
|
+
__classPrivateFieldSet(this, _StreamID_cid, typeof cid === 'string' ? cid_1.CID.parse(cid) : cid, "f");
|
|
68
106
|
}
|
|
69
107
|
static isInstance(instance) {
|
|
70
108
|
return typeof instance === 'object' && '_tag' in instance && instance._tag === TAG;
|
|
71
109
|
}
|
|
72
110
|
static async fromGenesis(type, genesis) {
|
|
73
|
-
const
|
|
74
|
-
return new StreamID(type, cid);
|
|
111
|
+
const block = await Block.encode({ value: genesis, codec, hasher: sha2_1.sha256 });
|
|
112
|
+
return new StreamID(type, block.cid);
|
|
75
113
|
}
|
|
76
114
|
get type() {
|
|
77
115
|
return __classPrivateFieldGet(this, _StreamID_type, "f");
|
|
@@ -85,7 +123,7 @@ class StreamID {
|
|
|
85
123
|
get bytes() {
|
|
86
124
|
const codec = varint_1.default.encode(constants_1.STREAMID_CODEC);
|
|
87
125
|
const type = varint_1.default.encode(this.type);
|
|
88
|
-
return
|
|
126
|
+
return uint8arrays_1.concat([codec, type, this.cid.bytes]);
|
|
89
127
|
}
|
|
90
128
|
get baseID() {
|
|
91
129
|
return new StreamID(__classPrivateFieldGet(this, _StreamID_type, "f"), __classPrivateFieldGet(this, _StreamID_cid, "f"));
|
|
@@ -102,7 +140,7 @@ class StreamID {
|
|
|
102
140
|
}
|
|
103
141
|
}
|
|
104
142
|
toString() {
|
|
105
|
-
return
|
|
143
|
+
return base36_1.base36.encode(this.bytes);
|
|
106
144
|
}
|
|
107
145
|
toUrl() {
|
|
108
146
|
return `ceramic://${this.toString()}`;
|
|
@@ -115,7 +153,9 @@ class StreamID {
|
|
|
115
153
|
}
|
|
116
154
|
}
|
|
117
155
|
StreamID.fromBytes = fromBytes;
|
|
156
|
+
StreamID.fromBytesNoThrow = fromBytesNoThrow;
|
|
118
157
|
StreamID.fromString = fromString;
|
|
158
|
+
StreamID.fromStringNoThrow = fromStringNoThrow;
|
|
119
159
|
__decorate([
|
|
120
160
|
typescript_memoize_1.Memoize(),
|
|
121
161
|
__metadata("design:type", String),
|
package/lib/stream-id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-id.js","sourceRoot":"","sources":["../src/stream-id.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-id.js","sourceRoot":"","sources":["../src/stream-id.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAsC;AACtC,0DAA2C;AAC3C,sDAAkD;AAClD,mDAA2D;AAC3D,oDAA2B;AAC3B,sDAAuC;AAC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,CAAC;IAMD,QAAQ;QACN,OAAO,eAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClC,CAAC;IAMD,KAAK;QACH,OAAO,aAAa,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAA;IACvC,CAAC;IAKD,iEAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAAC;QACxC,OAAO,YAAY,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAA;IACvC,CAAC;IAKD,CAAC,MAAM,CAAC,WAAW,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;IACxB,CAAC;;AA9IM,kBAAS,GAAG,SAAS,CAAA;AACrB,yBAAgB,GAAG,gBAAgB,CAAA;AACnC,mBAAU,GAAG,UAAU,CAAA;AACvB,0BAAiB,GAAG,iBAAiB,CAAA;AA8D5C;IADC,4BAAO,EAAE;;;wCAGT;AAaD;IADC,4BAAO,EAAE;8BACG,UAAU;;qCAKtB;AAOD;IADC,4BAAO,EAAE;8BACI,QAAQ;;sCAErB;AAwBD;IADC,4BAAO,EAAE;;;;wCAGT;AAMD;IADC,4BAAO,EAAE;;;;qCAGT;AAtIH,4BAqJC"}
|
package/lib/stream-ref.d.ts
CHANGED
package/lib/stream-ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-ref.d.ts","sourceRoot":"","sources":["../src/stream-ref.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"stream-ref.d.ts","sourceRoot":"","sources":["../src/stream-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAKtC,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;IACjB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;IACjD,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,CAAA;IAC5B,QAAQ,IAAI,MAAM,CAAA;IAClB,KAAK,IAAI,MAAM,CAAA;CAChB;AAcD,yBAAiB,SAAS,CAAC;IAKzB,SAAgB,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAsB1F;CACF"}
|
package/lib/stream-ref.js
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
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
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
3
|
exports.StreamRef = void 0;
|
|
23
4
|
const stream_id_1 = require("./stream-id");
|
|
24
5
|
const commit_id_1 = require("./commit-id");
|
|
25
|
-
const uint8arrays = __importStar(require("uint8arrays"));
|
|
26
6
|
function tryCatch(f) {
|
|
27
7
|
try {
|
|
28
8
|
return f();
|
|
@@ -31,9 +11,6 @@ function tryCatch(f) {
|
|
|
31
11
|
return null;
|
|
32
12
|
}
|
|
33
13
|
}
|
|
34
|
-
function complain(message) {
|
|
35
|
-
throw new Error(message);
|
|
36
|
-
}
|
|
37
14
|
var StreamRef;
|
|
38
15
|
(function (StreamRef) {
|
|
39
16
|
function from(input) {
|
|
@@ -44,14 +21,18 @@ var StreamRef;
|
|
|
44
21
|
return input;
|
|
45
22
|
}
|
|
46
23
|
else if (input instanceof Uint8Array) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
const commitId = commit_id_1.CommitID.fromBytesNoThrow(input);
|
|
25
|
+
if (commitId instanceof Error) {
|
|
26
|
+
return stream_id_1.StreamID.fromBytes(input);
|
|
27
|
+
}
|
|
28
|
+
return commitId;
|
|
50
29
|
}
|
|
51
30
|
else if (typeof input === 'string') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
31
|
+
const commitId = commit_id_1.CommitID.fromStringNoThrow(input);
|
|
32
|
+
if (commitId instanceof Error) {
|
|
33
|
+
return stream_id_1.StreamID.fromString(input);
|
|
34
|
+
}
|
|
35
|
+
return commitId;
|
|
55
36
|
}
|
|
56
37
|
else {
|
|
57
38
|
throw new Error(`Can not build CommitID or StreamID`);
|
package/lib/stream-ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-ref.js","sourceRoot":"","sources":["../src/stream-ref.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-ref.js","sourceRoot":"","sources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-alpha.0",
|
|
4
4
|
"description": "Ceramic Stream Ids",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ceramic",
|
|
@@ -25,11 +25,10 @@
|
|
|
25
25
|
"lib": "lib"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"uint8arrays": "^2.0.5",
|
|
28
|
+
"@ipld/dag-cbor": "^6.0.13",
|
|
29
|
+
"multiformats": "^9.4.10",
|
|
30
|
+
"typescript-memoize": "^1.1.0",
|
|
31
|
+
"uint8arrays": "^3.0.0",
|
|
33
32
|
"varint": "^6.0.0"
|
|
34
33
|
},
|
|
35
34
|
"publishConfig": {
|
|
@@ -39,5 +38,5 @@
|
|
|
39
38
|
"testEnvironment": "node",
|
|
40
39
|
"resolver": "jest-resolver-enhanced"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "f432b554a4b134db45f24b2555bfda176feac505"
|
|
43
42
|
}
|