@kubun/id 0.11.0 → 0.13.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/lib/attachment.d.ts +2 -2
- package/lib/attachment.js +3 -3
- package/lib/base.d.ts +24 -16
- package/lib/base.js +17 -24
- package/lib/bytes.d.ts +1 -1
- package/lib/cluster-model.d.ts +2 -2
- package/lib/cluster-model.js +3 -3
- package/lib/credential.d.ts +34 -0
- package/lib/credential.js +110 -0
- package/lib/decode.js +13 -8
- package/lib/document.d.ts +2 -2
- package/lib/document.js +3 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/model.d.ts +4 -4
- package/lib/model.js +7 -7
- package/lib/plugin-node.d.ts +2 -2
- package/lib/plugin-node.js +3 -3
- package/package.json +14 -11
package/lib/attachment.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class AttachmentID extends KubunID<
|
|
1
|
+
import { ATTACHMENT_BINARY, KubunID } from './base.js';
|
|
2
|
+
export declare class AttachmentID extends KubunID<typeof ATTACHMENT_BINARY> {
|
|
3
3
|
#private;
|
|
4
4
|
static create(value: Uint8Array, mimeType?: string): AttachmentID;
|
|
5
5
|
static fromBytes(input: Uint8Array): AttachmentID;
|
package/lib/attachment.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromUTF, toUTF } from '@sozai/codec';
|
|
2
2
|
import { base36 } from 'multiformats/bases/base36';
|
|
3
|
-
import {
|
|
3
|
+
import { ATTACHMENT_BINARY, KubunID, NAMESPACE_CODE } from './base.js';
|
|
4
4
|
import { concat } from './bytes.js';
|
|
5
5
|
import { decodeVarint, digestBytes, encodeVarint } from './utils.js';
|
|
6
6
|
const DEFAULT_MIME_TYPE = 'application/octet-stream';
|
|
@@ -18,7 +18,7 @@ export class AttachmentID extends KubunID {
|
|
|
18
18
|
offset += namespaceLength;
|
|
19
19
|
// Check type matches
|
|
20
20
|
const [type, typeLength] = decodeVarint(input, offset);
|
|
21
|
-
if (type !==
|
|
21
|
+
if (type !== ATTACHMENT_BINARY) {
|
|
22
22
|
throw new Error('Invalid KubunID: type mismatch');
|
|
23
23
|
}
|
|
24
24
|
offset += typeLength;
|
|
@@ -79,7 +79,7 @@ export class AttachmentID extends KubunID {
|
|
|
79
79
|
typeBytes
|
|
80
80
|
]);
|
|
81
81
|
}
|
|
82
|
-
super(
|
|
82
|
+
super(ATTACHMENT_BINARY, data);
|
|
83
83
|
this.#contentLength = contentLength;
|
|
84
84
|
this.#digest = digest;
|
|
85
85
|
this.#mimeType = mimeType;
|
package/lib/base.d.ts
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
export declare const NAMESPACE_CODE = 181;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export
|
|
2
|
+
/**
|
|
3
|
+
* Immutable references
|
|
4
|
+
*/
|
|
5
|
+
export declare const ATTACHMENT_BINARY = 1;
|
|
6
|
+
export type AttachmentType = typeof ATTACHMENT_BINARY;
|
|
7
|
+
export declare const MODEL_SCALAR = 10;
|
|
8
|
+
export declare const MODEL_SHAPE = 11;
|
|
9
|
+
export declare const MODEL_DOCUMENT = 20;
|
|
10
|
+
export declare const MODEL_CLUSTER = 21;
|
|
11
|
+
export type ModelType = typeof MODEL_SCALAR | typeof MODEL_SHAPE | typeof MODEL_DOCUMENT | typeof MODEL_CLUSTER;
|
|
12
|
+
/**
|
|
13
|
+
* Mutable references
|
|
14
|
+
*/
|
|
15
|
+
export declare const DOCUMENT_MERGE = 30;
|
|
16
|
+
export type DocumentType = typeof DOCUMENT_MERGE;
|
|
17
|
+
export declare const CREDENTIAL_KEY = 31;
|
|
18
|
+
export declare const CREDENTIAL_ENTRY = 32;
|
|
19
|
+
export type CredentialType = typeof CREDENTIAL_KEY | typeof CREDENTIAL_ENTRY;
|
|
20
|
+
/**
|
|
21
|
+
* External references
|
|
22
|
+
*/
|
|
23
|
+
export declare const EXTERNAL_PLUGIN_NODE = 40;
|
|
24
|
+
export type ExternalType = typeof EXTERNAL_PLUGIN_NODE;
|
|
25
|
+
export type KubunType = AttachmentType | ModelType | DocumentType | CredentialType | ExternalType;
|
|
18
26
|
export declare class KubunID<T extends KubunType = KubunType> {
|
|
19
27
|
#private;
|
|
20
28
|
constructor(type: T, dataBytes: Uint8Array);
|
package/lib/base.js
CHANGED
|
@@ -3,30 +3,23 @@ import { concat, equals } from './bytes.js';
|
|
|
3
3
|
import { encodeVarint } from './utils.js';
|
|
4
4
|
export const NAMESPACE_CODE = 0xb5;
|
|
5
5
|
const NAMESPACE_BYTES = encodeVarint(NAMESPACE_CODE);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return DocumentType;
|
|
24
|
-
}({});
|
|
25
|
-
// External
|
|
26
|
-
export var ExternalType = /*#__PURE__*/ function(ExternalType) {
|
|
27
|
-
ExternalType[ExternalType["PLUGIN_NODE"] = 40] = "PLUGIN_NODE";
|
|
28
|
-
return ExternalType;
|
|
29
|
-
}({});
|
|
6
|
+
/**
|
|
7
|
+
* Immutable references
|
|
8
|
+
*/ export const ATTACHMENT_BINARY = 1;
|
|
9
|
+
// DAG-only
|
|
10
|
+
export const MODEL_SCALAR = 10;
|
|
11
|
+
export const MODEL_SHAPE = 11;
|
|
12
|
+
// Circular
|
|
13
|
+
export const MODEL_DOCUMENT = 20;
|
|
14
|
+
export const MODEL_CLUSTER = 21;
|
|
15
|
+
/**
|
|
16
|
+
* Mutable references
|
|
17
|
+
*/ export const DOCUMENT_MERGE = 30;
|
|
18
|
+
export const CREDENTIAL_KEY = 31;
|
|
19
|
+
export const CREDENTIAL_ENTRY = 32;
|
|
20
|
+
/**
|
|
21
|
+
* External references
|
|
22
|
+
*/ export const EXTERNAL_PLUGIN_NODE = 40;
|
|
30
23
|
export class KubunID {
|
|
31
24
|
#type;
|
|
32
25
|
#dataBytes;
|
package/lib/bytes.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function concat(arrays: Uint8Array
|
|
1
|
+
export declare function concat(arrays: Array<Uint8Array>, providedLength?: number): Uint8Array;
|
|
2
2
|
export declare function equals(a: Uint8Array, b: Uint8Array): boolean;
|
package/lib/cluster-model.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KubunID,
|
|
2
|
-
export declare class ClusterModelID extends KubunID<
|
|
1
|
+
import { KubunID, MODEL_CLUSTER } from './base.js';
|
|
2
|
+
export declare class ClusterModelID extends KubunID<typeof MODEL_CLUSTER> {
|
|
3
3
|
static fromDigest(digestBytes: Uint8Array): ClusterModelID;
|
|
4
4
|
static fromBytes(input: Uint8Array): ClusterModelID;
|
|
5
5
|
static fromString(input: string): ClusterModelID;
|
package/lib/cluster-model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base36 } from 'multiformats/bases/base36';
|
|
2
|
-
import { KubunID,
|
|
2
|
+
import { KubunID, MODEL_CLUSTER, NAMESPACE_CODE } from './base.js';
|
|
3
3
|
import { decodeVarint } from './utils.js';
|
|
4
4
|
export class ClusterModelID extends KubunID {
|
|
5
5
|
static fromDigest(digestBytes) {
|
|
@@ -11,7 +11,7 @@ export class ClusterModelID extends KubunID {
|
|
|
11
11
|
throw new Error('Invalid KubunID: namespace mismatch');
|
|
12
12
|
}
|
|
13
13
|
const [type, typeLength] = decodeVarint(input, namespaceLength);
|
|
14
|
-
if (type !==
|
|
14
|
+
if (type !== MODEL_CLUSTER) {
|
|
15
15
|
throw new Error('Invalid KubunID: type mismatch');
|
|
16
16
|
}
|
|
17
17
|
const digestBytes = input.slice(namespaceLength + typeLength);
|
|
@@ -21,6 +21,6 @@ export class ClusterModelID extends KubunID {
|
|
|
21
21
|
return ClusterModelID.fromBytes(base36.decode(input));
|
|
22
22
|
}
|
|
23
23
|
constructor(digestBytes){
|
|
24
|
-
super(
|
|
24
|
+
super(MODEL_CLUSTER, digestBytes);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CREDENTIAL_ENTRY, CREDENTIAL_KEY, KubunID } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* A credential key: the unit a wrapping addresses, a grant shares and a rotation
|
|
4
|
+
* bumps.
|
|
5
|
+
*
|
|
6
|
+
* Not content-addressed. Rotation preserves the id and moves `version`, so a
|
|
7
|
+
* document referencing a key keeps referencing it across rotations — which is
|
|
8
|
+
* the whole reason rotation does not mint a new id.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CredentialKeyID extends KubunID<typeof CREDENTIAL_KEY> {
|
|
11
|
+
#private;
|
|
12
|
+
static create(owner: string | Uint8Array, unique: Uint8Array): CredentialKeyID;
|
|
13
|
+
static fromBytes(input: Uint8Array): CredentialKeyID;
|
|
14
|
+
static fromString(input: string): CredentialKeyID;
|
|
15
|
+
static from(input: CredentialKeyID | Uint8Array | string): CredentialKeyID;
|
|
16
|
+
constructor(digest: Uint8Array);
|
|
17
|
+
get digest(): Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A credential entry: one encrypted value under a key.
|
|
21
|
+
*
|
|
22
|
+
* Does not embed its key's id. An entry can be re-keyed without every document
|
|
23
|
+
* that references it changing, and its value changes — a refreshed OAuth token —
|
|
24
|
+
* without the reference changing either.
|
|
25
|
+
*/
|
|
26
|
+
export declare class CredentialEntryID extends KubunID<typeof CREDENTIAL_ENTRY> {
|
|
27
|
+
#private;
|
|
28
|
+
static create(owner: string | Uint8Array, unique: Uint8Array): CredentialEntryID;
|
|
29
|
+
static fromBytes(input: Uint8Array): CredentialEntryID;
|
|
30
|
+
static fromString(input: string): CredentialEntryID;
|
|
31
|
+
static from(input: CredentialEntryID | Uint8Array | string): CredentialEntryID;
|
|
32
|
+
constructor(digest: Uint8Array);
|
|
33
|
+
get digest(): Uint8Array;
|
|
34
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { fromUTF } from '@sozai/codec';
|
|
2
|
+
import { base36 } from 'multiformats/bases/base36';
|
|
3
|
+
import { CREDENTIAL_ENTRY, CREDENTIAL_KEY, KubunID, NAMESPACE_CODE } from './base.js';
|
|
4
|
+
import { concat } from './bytes.js';
|
|
5
|
+
import { decodeVarint, digestBytes, encodeVarint } from './utils.js';
|
|
6
|
+
function encodeData(digest) {
|
|
7
|
+
return concat([
|
|
8
|
+
encodeVarint(digest.byteLength),
|
|
9
|
+
digest
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
function decodeDigest(input, expected) {
|
|
13
|
+
let offset = 0;
|
|
14
|
+
// Check namespace = is it a KubunID?
|
|
15
|
+
const [namespace, namespaceLength] = decodeVarint(input);
|
|
16
|
+
if (namespace !== NAMESPACE_CODE) {
|
|
17
|
+
throw new Error('Invalid KubunID: namespace mismatch');
|
|
18
|
+
}
|
|
19
|
+
offset += namespaceLength;
|
|
20
|
+
// Check type matches
|
|
21
|
+
const [type, typeLength] = decodeVarint(input, offset);
|
|
22
|
+
if (type !== expected) {
|
|
23
|
+
throw new Error('Invalid KubunID: type mismatch');
|
|
24
|
+
}
|
|
25
|
+
offset += typeLength;
|
|
26
|
+
const [digestLength, digestVarintLength] = decodeVarint(input, offset);
|
|
27
|
+
offset += digestVarintLength;
|
|
28
|
+
return input.slice(offset, offset + digestLength);
|
|
29
|
+
}
|
|
30
|
+
function createDigest(owner, unique) {
|
|
31
|
+
return digestBytes(concat([
|
|
32
|
+
typeof owner === 'string' ? fromUTF(owner) : owner,
|
|
33
|
+
unique
|
|
34
|
+
]));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A credential key: the unit a wrapping addresses, a grant shares and a rotation
|
|
38
|
+
* bumps.
|
|
39
|
+
*
|
|
40
|
+
* Not content-addressed. Rotation preserves the id and moves `version`, so a
|
|
41
|
+
* document referencing a key keeps referencing it across rotations — which is
|
|
42
|
+
* the whole reason rotation does not mint a new id.
|
|
43
|
+
*/ export class CredentialKeyID extends KubunID {
|
|
44
|
+
static create(owner, unique) {
|
|
45
|
+
return new CredentialKeyID(createDigest(owner, unique));
|
|
46
|
+
}
|
|
47
|
+
static fromBytes(input) {
|
|
48
|
+
return new CredentialKeyID(decodeDigest(input, CREDENTIAL_KEY));
|
|
49
|
+
}
|
|
50
|
+
static fromString(input) {
|
|
51
|
+
return CredentialKeyID.fromBytes(base36.decode(input));
|
|
52
|
+
}
|
|
53
|
+
static from(input) {
|
|
54
|
+
if (input instanceof CredentialKeyID) {
|
|
55
|
+
return input;
|
|
56
|
+
}
|
|
57
|
+
if (input instanceof Uint8Array) {
|
|
58
|
+
return CredentialKeyID.fromBytes(input);
|
|
59
|
+
}
|
|
60
|
+
if (typeof input === 'string') {
|
|
61
|
+
return CredentialKeyID.fromString(input);
|
|
62
|
+
}
|
|
63
|
+
throw new Error('Unsupported input type');
|
|
64
|
+
}
|
|
65
|
+
#digest;
|
|
66
|
+
constructor(digest){
|
|
67
|
+
super(CREDENTIAL_KEY, encodeData(digest));
|
|
68
|
+
this.#digest = digest;
|
|
69
|
+
}
|
|
70
|
+
get digest() {
|
|
71
|
+
return this.#digest;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A credential entry: one encrypted value under a key.
|
|
76
|
+
*
|
|
77
|
+
* Does not embed its key's id. An entry can be re-keyed without every document
|
|
78
|
+
* that references it changing, and its value changes — a refreshed OAuth token —
|
|
79
|
+
* without the reference changing either.
|
|
80
|
+
*/ export class CredentialEntryID extends KubunID {
|
|
81
|
+
static create(owner, unique) {
|
|
82
|
+
return new CredentialEntryID(createDigest(owner, unique));
|
|
83
|
+
}
|
|
84
|
+
static fromBytes(input) {
|
|
85
|
+
return new CredentialEntryID(decodeDigest(input, CREDENTIAL_ENTRY));
|
|
86
|
+
}
|
|
87
|
+
static fromString(input) {
|
|
88
|
+
return CredentialEntryID.fromBytes(base36.decode(input));
|
|
89
|
+
}
|
|
90
|
+
static from(input) {
|
|
91
|
+
if (input instanceof CredentialEntryID) {
|
|
92
|
+
return input;
|
|
93
|
+
}
|
|
94
|
+
if (input instanceof Uint8Array) {
|
|
95
|
+
return CredentialEntryID.fromBytes(input);
|
|
96
|
+
}
|
|
97
|
+
if (typeof input === 'string') {
|
|
98
|
+
return CredentialEntryID.fromString(input);
|
|
99
|
+
}
|
|
100
|
+
throw new Error('Unsupported input type');
|
|
101
|
+
}
|
|
102
|
+
#digest;
|
|
103
|
+
constructor(digest){
|
|
104
|
+
super(CREDENTIAL_ENTRY, encodeData(digest));
|
|
105
|
+
this.#digest = digest;
|
|
106
|
+
}
|
|
107
|
+
get digest() {
|
|
108
|
+
return this.#digest;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/lib/decode.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { base36 } from 'multiformats/bases/base36';
|
|
2
2
|
import { AttachmentID } from './attachment.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ATTACHMENT_BINARY, CREDENTIAL_ENTRY, CREDENTIAL_KEY, DOCUMENT_MERGE, EXTERNAL_PLUGIN_NODE, MODEL_CLUSTER, MODEL_DOCUMENT, MODEL_SCALAR, MODEL_SHAPE, NAMESPACE_CODE } from './base.js';
|
|
4
4
|
import { ClusterModelID } from './cluster-model.js';
|
|
5
|
+
import { CredentialEntryID, CredentialKeyID } from './credential.js';
|
|
5
6
|
import { DocumentID } from './document.js';
|
|
6
7
|
import { DocumentModelID, ScalarModelID, ShapeModelID } from './model.js';
|
|
7
8
|
import { PluginNodeID } from './plugin-node.js';
|
|
@@ -14,19 +15,23 @@ export function decodeID(input) {
|
|
|
14
15
|
}
|
|
15
16
|
const [type] = decodeVarint(bytes, namespaceLength);
|
|
16
17
|
switch(type){
|
|
17
|
-
case
|
|
18
|
+
case ATTACHMENT_BINARY:
|
|
18
19
|
return AttachmentID.fromBytes(bytes);
|
|
19
|
-
case
|
|
20
|
+
case MODEL_SCALAR:
|
|
20
21
|
return ScalarModelID.fromBytes(bytes);
|
|
21
|
-
case
|
|
22
|
+
case MODEL_SHAPE:
|
|
22
23
|
return ShapeModelID.fromBytes(bytes);
|
|
23
|
-
case
|
|
24
|
+
case MODEL_DOCUMENT:
|
|
24
25
|
return DocumentModelID.fromBytes(bytes);
|
|
25
|
-
case
|
|
26
|
+
case MODEL_CLUSTER:
|
|
26
27
|
return ClusterModelID.fromBytes(bytes);
|
|
27
|
-
case
|
|
28
|
+
case DOCUMENT_MERGE:
|
|
28
29
|
return DocumentID.fromBytes(bytes);
|
|
29
|
-
case
|
|
30
|
+
case CREDENTIAL_KEY:
|
|
31
|
+
return CredentialKeyID.fromBytes(bytes);
|
|
32
|
+
case CREDENTIAL_ENTRY:
|
|
33
|
+
return CredentialEntryID.fromBytes(bytes);
|
|
34
|
+
case EXTERNAL_PLUGIN_NODE:
|
|
30
35
|
return PluginNodeID.fromBytes(bytes);
|
|
31
36
|
default:
|
|
32
37
|
throw new Error(`Invalid KubunID: unknown type ${type}`);
|
package/lib/document.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DOCUMENT_MERGE, KubunID } from './base.js';
|
|
2
2
|
import { DocumentModelID } from './model.js';
|
|
3
|
-
export declare class DocumentID extends KubunID<
|
|
3
|
+
export declare class DocumentID extends KubunID<typeof DOCUMENT_MERGE> {
|
|
4
4
|
#private;
|
|
5
5
|
static create(model: DocumentModelID | Uint8Array | string, owner: string | Uint8Array, unique: Uint8Array): DocumentID;
|
|
6
6
|
static fromBytes(input: Uint8Array): DocumentID;
|
package/lib/document.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromUTF } from '@sozai/codec';
|
|
2
2
|
import { base36 } from 'multiformats/bases/base36';
|
|
3
|
-
import {
|
|
3
|
+
import { DOCUMENT_MERGE, KubunID, NAMESPACE_CODE } from './base.js';
|
|
4
4
|
import { concat } from './bytes.js';
|
|
5
5
|
import { DocumentModelID } from './model.js';
|
|
6
6
|
import { decodeVarint, digestBytes, encodeVarint } from './utils.js';
|
|
@@ -22,7 +22,7 @@ export class DocumentID extends KubunID {
|
|
|
22
22
|
offset += namespaceLength;
|
|
23
23
|
// Check type matches
|
|
24
24
|
const [type, typeLength] = decodeVarint(input, offset);
|
|
25
|
-
if (type !==
|
|
25
|
+
if (type !== DOCUMENT_MERGE) {
|
|
26
26
|
throw new Error('Invalid KubunID: type mismatch');
|
|
27
27
|
}
|
|
28
28
|
offset += typeLength;
|
|
@@ -68,7 +68,7 @@ export class DocumentID extends KubunID {
|
|
|
68
68
|
encodeVarint(contentDigestBytes.byteLength),
|
|
69
69
|
contentDigestBytes
|
|
70
70
|
]);
|
|
71
|
-
super(
|
|
71
|
+
super(DOCUMENT_MERGE, data);
|
|
72
72
|
this.#model = model;
|
|
73
73
|
this.#content = contentDigestBytes;
|
|
74
74
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { AttachmentID } from './attachment.js';
|
|
2
2
|
export { KubunID } from './base.js';
|
|
3
3
|
export { ClusterModelID } from './cluster-model.js';
|
|
4
|
+
export { CredentialEntryID, CredentialKeyID } from './credential.js';
|
|
4
5
|
export { decodeID } from './decode.js';
|
|
5
6
|
export { DocumentID } from './document.js';
|
|
6
7
|
export { DocumentModelID, ScalarModelID, ShapeModelID } from './model.js';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { AttachmentID } from './attachment.js';
|
|
2
2
|
export { KubunID } from './base.js';
|
|
3
3
|
export { ClusterModelID } from './cluster-model.js';
|
|
4
|
+
export { CredentialEntryID, CredentialKeyID } from './credential.js';
|
|
4
5
|
export { decodeID } from './decode.js';
|
|
5
6
|
export { DocumentID } from './document.js';
|
|
6
7
|
export { DocumentModelID, ScalarModelID, ShapeModelID } from './model.js';
|
package/lib/model.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { KubunID,
|
|
2
|
-
export declare class ScalarModelID extends KubunID<
|
|
1
|
+
import { KubunID, MODEL_DOCUMENT, MODEL_SCALAR, MODEL_SHAPE } from './base.js';
|
|
2
|
+
export declare class ScalarModelID extends KubunID<typeof MODEL_SCALAR> {
|
|
3
3
|
static create(value: unknown): ScalarModelID;
|
|
4
4
|
static fromBytes(input: Uint8Array): ScalarModelID;
|
|
5
5
|
static fromString(input: string): ScalarModelID;
|
|
6
6
|
constructor(digestBytes: Uint8Array);
|
|
7
7
|
}
|
|
8
|
-
export declare class ShapeModelID extends KubunID<
|
|
8
|
+
export declare class ShapeModelID extends KubunID<typeof MODEL_SHAPE> {
|
|
9
9
|
static create(value: unknown): ShapeModelID;
|
|
10
10
|
static fromBytes(input: Uint8Array): ShapeModelID;
|
|
11
11
|
static fromString(input: string): ShapeModelID;
|
|
12
12
|
constructor(digestBytes: Uint8Array);
|
|
13
13
|
}
|
|
14
|
-
export declare class DocumentModelID extends KubunID<
|
|
14
|
+
export declare class DocumentModelID extends KubunID<typeof MODEL_DOCUMENT> {
|
|
15
15
|
#private;
|
|
16
16
|
static fromBytes(input: Uint8Array): DocumentModelID;
|
|
17
17
|
static fromString(input: string): DocumentModelID;
|
package/lib/model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base36 } from 'multiformats/bases/base36';
|
|
2
|
-
import { KubunID,
|
|
2
|
+
import { KubunID, MODEL_DOCUMENT, MODEL_SCALAR, MODEL_SHAPE, NAMESPACE_CODE } from './base.js';
|
|
3
3
|
import { concat } from './bytes.js';
|
|
4
4
|
import { decodeVarint, digestJSON, encodeVarint } from './utils.js';
|
|
5
5
|
export class ScalarModelID extends KubunID {
|
|
@@ -12,7 +12,7 @@ export class ScalarModelID extends KubunID {
|
|
|
12
12
|
throw new Error('Invalid KubunID: namespace mismatch');
|
|
13
13
|
}
|
|
14
14
|
const [type, typeLength] = decodeVarint(input, namespaceLength);
|
|
15
|
-
if (type !==
|
|
15
|
+
if (type !== MODEL_SCALAR) {
|
|
16
16
|
throw new Error('Invalid KubunID: type mismatch');
|
|
17
17
|
}
|
|
18
18
|
const digestBytes = input.slice(namespaceLength + typeLength);
|
|
@@ -22,7 +22,7 @@ export class ScalarModelID extends KubunID {
|
|
|
22
22
|
return ScalarModelID.fromBytes(base36.decode(input));
|
|
23
23
|
}
|
|
24
24
|
constructor(digestBytes){
|
|
25
|
-
super(
|
|
25
|
+
super(MODEL_SCALAR, digestBytes);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
export class ShapeModelID extends KubunID {
|
|
@@ -35,7 +35,7 @@ export class ShapeModelID extends KubunID {
|
|
|
35
35
|
throw new Error('Invalid KubunID: namespace mismatch');
|
|
36
36
|
}
|
|
37
37
|
const [type, typeLength] = decodeVarint(input, namespaceLength);
|
|
38
|
-
if (type !==
|
|
38
|
+
if (type !== MODEL_SHAPE) {
|
|
39
39
|
throw new Error('Invalid KubunID: type mismatch');
|
|
40
40
|
}
|
|
41
41
|
const digestBytes = input.slice(namespaceLength + typeLength);
|
|
@@ -45,7 +45,7 @@ export class ShapeModelID extends KubunID {
|
|
|
45
45
|
return ShapeModelID.fromBytes(base36.decode(input));
|
|
46
46
|
}
|
|
47
47
|
constructor(digestBytes){
|
|
48
|
-
super(
|
|
48
|
+
super(MODEL_SHAPE, digestBytes);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
const MAX_INDEX = 127;
|
|
@@ -56,7 +56,7 @@ export class DocumentModelID extends KubunID {
|
|
|
56
56
|
throw new Error('Invalid KubunID: namespace mismatch');
|
|
57
57
|
}
|
|
58
58
|
const [type, typeLength] = decodeVarint(input, namespaceLength);
|
|
59
|
-
if (type !==
|
|
59
|
+
if (type !== MODEL_DOCUMENT) {
|
|
60
60
|
throw new Error('Invalid KubunID: type mismatch');
|
|
61
61
|
}
|
|
62
62
|
const digestBytes = input.slice(namespaceLength + typeLength, input.byteLength - 1);
|
|
@@ -88,7 +88,7 @@ export class DocumentModelID extends KubunID {
|
|
|
88
88
|
// index should be encoded in a single byte
|
|
89
89
|
throw new RangeError(`Index ${index} exceeds maximum of ${MAX_INDEX}`);
|
|
90
90
|
}
|
|
91
|
-
super(
|
|
91
|
+
super(MODEL_DOCUMENT, digestBytes);
|
|
92
92
|
this.#index = index;
|
|
93
93
|
this.#isLocal = digestBytes.length === 0;
|
|
94
94
|
}
|
package/lib/plugin-node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class PluginNodeID extends KubunID<
|
|
1
|
+
import { EXTERNAL_PLUGIN_NODE, KubunID } from './base.js';
|
|
2
|
+
export declare class PluginNodeID extends KubunID<typeof EXTERNAL_PLUGIN_NODE> {
|
|
3
3
|
#private;
|
|
4
4
|
static create(plugin: string, typeName: string, localID: string): PluginNodeID;
|
|
5
5
|
static fromBytes(input: Uint8Array): PluginNodeID;
|
package/lib/plugin-node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromUTF, toUTF } from '@sozai/codec';
|
|
2
2
|
import { base36 } from 'multiformats/bases/base36';
|
|
3
|
-
import {
|
|
3
|
+
import { EXTERNAL_PLUGIN_NODE, KubunID, NAMESPACE_CODE } from './base.js';
|
|
4
4
|
import { concat } from './bytes.js';
|
|
5
5
|
import { decodeVarint, encodeVarint } from './utils.js';
|
|
6
6
|
export class PluginNodeID extends KubunID {
|
|
@@ -17,7 +17,7 @@ export class PluginNodeID extends KubunID {
|
|
|
17
17
|
offset += namespaceLength;
|
|
18
18
|
// Check type matches
|
|
19
19
|
const [type, typeLength] = decodeVarint(input, offset);
|
|
20
|
-
if (type !==
|
|
20
|
+
if (type !== EXTERNAL_PLUGIN_NODE) {
|
|
21
21
|
throw new Error('Invalid KubunID: type mismatch');
|
|
22
22
|
}
|
|
23
23
|
offset += typeLength;
|
|
@@ -67,7 +67,7 @@ export class PluginNodeID extends KubunID {
|
|
|
67
67
|
encodeVarint(localIDBytes.byteLength),
|
|
68
68
|
localIDBytes
|
|
69
69
|
]);
|
|
70
|
-
super(
|
|
70
|
+
super(EXTERNAL_PLUGIN_NODE, data);
|
|
71
71
|
this.#plugin = plugin;
|
|
72
72
|
this.#typeName = typeName;
|
|
73
73
|
this.#localID = localID;
|
package/package.json
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/id",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"license": "see LICENSE.md",
|
|
3
|
+
"version": "0.13.0",
|
|
5
4
|
"keywords": [],
|
|
5
|
+
"license": "see LICENSE.md",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"type": "module",
|
|
7
|
-
"main": "lib/index.js",
|
|
8
|
-
"types": "lib/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": "./lib/index.js"
|
|
11
10
|
},
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"types": "lib/index.d.ts",
|
|
12
13
|
"files": [
|
|
13
14
|
"lib/*",
|
|
14
15
|
"LICENSE.md"
|
|
15
16
|
],
|
|
16
|
-
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"multiformats": "^14.0.
|
|
18
|
+
"@noble/hashes": "^2.3.0",
|
|
19
|
+
"@sozai/codec": "^0.4.0",
|
|
20
|
+
"multiformats": "^14.0.5",
|
|
21
21
|
"varint": "^6.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/varint": "^6.0.3"
|
|
25
25
|
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
26
29
|
"scripts": {
|
|
30
|
+
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
27
31
|
"build:clean": "del lib",
|
|
28
32
|
"build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
29
33
|
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
30
34
|
"build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
|
|
31
|
-
"
|
|
35
|
+
"test": "pnpm run test:types && pnpm run test:unit",
|
|
32
36
|
"test:types": "tsc --noEmit",
|
|
33
|
-
"test:unit": "vitest run"
|
|
34
|
-
"test": "pnpm run test:types && pnpm run test:unit"
|
|
37
|
+
"test:unit": "vitest run"
|
|
35
38
|
}
|
|
36
39
|
}
|