@kubun/id 0.6.0 → 0.8.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/base.d.ts +6 -2
- package/lib/base.js +1 -1
- package/lib/cluster-model.d.ts +7 -0
- package/lib/cluster-model.js +1 -0
- package/lib/decode.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -1
- package/lib/plugin-node.d.ts +12 -0
- package/lib/plugin-node.js +1 -0
- package/package.json +3 -3
package/lib/base.d.ts
CHANGED
|
@@ -5,12 +5,16 @@ export declare enum AttachmentType {
|
|
|
5
5
|
export declare enum ModelType {
|
|
6
6
|
SCALAR = 10,
|
|
7
7
|
SHAPE = 11,
|
|
8
|
-
DOCUMENT = 20
|
|
8
|
+
DOCUMENT = 20,
|
|
9
|
+
CLUSTER = 21
|
|
9
10
|
}
|
|
10
11
|
export declare enum DocumentType {
|
|
11
12
|
MERGE_DOCUMENT = 30
|
|
12
13
|
}
|
|
13
|
-
export
|
|
14
|
+
export declare enum ExternalType {
|
|
15
|
+
PLUGIN_NODE = 40
|
|
16
|
+
}
|
|
17
|
+
export type KubunType = AttachmentType | ModelType | DocumentType | ExternalType;
|
|
14
18
|
export declare class KubunID<T extends KubunType = KubunType> {
|
|
15
19
|
#private;
|
|
16
20
|
constructor(type: T, dataBytes: Uint8Array);
|
package/lib/base.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t,e,s;import{base36 as
|
|
1
|
+
var t,e,s,r;import{base36 as i}from"multiformats/bases/base36";import{concat as n,equals as o}from"./bytes.js";import{encodeVarint as a}from"./utils.js";export const NAMESPACE_CODE=181;let y=a(181);export var AttachmentType=((t={})[t.BINARY=1]="BINARY",t);export var ModelType=((e={})[e.SCALAR=10]="SCALAR",e[e.SHAPE=11]="SHAPE",e[e.DOCUMENT=20]="DOCUMENT",e[e.CLUSTER=21]="CLUSTER",e);export var DocumentType=((s={})[s.MERGE_DOCUMENT=30]="MERGE_DOCUMENT",s);export var ExternalType=((r={})[r.PLUGIN_NODE=40]="PLUGIN_NODE",r);export class KubunID{#t;#e;#s;#r;constructor(t,e){this.#t=t,this.#e=e}get type(){return this.#t}get data(){return this.#e}get bytes(){return null==this.#s&&(this.#s=this.toBytes()),this.#s}equals(t){return t instanceof KubunID&&t.type===this.type&&o(t.data,this.data)}toBytes(){return n([y,a(this.#t),this.#e])}toString(){return null==this.#r&&(this.#r=i.encode(this.bytes)),this.#r}[Symbol.for("nodejs.util.inspect.custom")](){return`KubunID(${this.toString()})`}}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { KubunID, ModelType } from './base.js';
|
|
2
|
+
export declare class ClusterModelID extends KubunID<ModelType.CLUSTER> {
|
|
3
|
+
static fromDigest(digestBytes: Uint8Array): ClusterModelID;
|
|
4
|
+
static fromBytes(input: Uint8Array): ClusterModelID;
|
|
5
|
+
static fromString(input: string): ClusterModelID;
|
|
6
|
+
constructor(digestBytes: Uint8Array);
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{base36 as r}from"multiformats/bases/base36";import{KubunID as t,ModelType as e,NAMESPACE_CODE as s}from"./base.js";import{decodeVarint as o}from"./utils.js";export class ClusterModelID extends t{static fromDigest(r){return new ClusterModelID(r)}static fromBytes(r){let[t,i]=o(r);if(t!==s)throw Error("Invalid KubunID: namespace mismatch");let[m,l]=o(r,i);if(m!==e.CLUSTER)throw Error("Invalid KubunID: type mismatch");return new ClusterModelID(r.slice(i+l))}static fromString(t){return ClusterModelID.fromBytes(r.decode(t))}constructor(r){super(e.CLUSTER,r)}}
|
package/lib/decode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{base36 as r}from"multiformats/bases/base36";import{AttachmentID as
|
|
1
|
+
import{base36 as r}from"multiformats/bases/base36";import{AttachmentID as e}from"./attachment.js";import{AttachmentType as t,DocumentType as o,ExternalType as m,ModelType as s,NAMESPACE_CODE as n}from"./base.js";import{ClusterModelID as f}from"./cluster-model.js";import{DocumentID as a}from"./document.js";import{DocumentModelID as u,ScalarModelID as i,ShapeModelID as c}from"./model.js";import{PluginNodeID as p}from"./plugin-node.js";import{decodeVarint as d}from"./utils.js";export function decodeID(l){let y="string"==typeof l?r.decode(l):l,[E,B]=d(y);if(E!==n)throw Error("Invalid KubunID: namespace mismatch");let[j]=d(y,B);switch(j){case t.BINARY:return e.fromBytes(y);case s.SCALAR:return i.fromBytes(y);case s.SHAPE:return c.fromBytes(y);case s.DOCUMENT:return u.fromBytes(y);case s.CLUSTER:return f.fromBytes(y);case o.MERGE_DOCUMENT:return a.fromBytes(y);case m.PLUGIN_NODE:return p.fromBytes(y);default:throw Error(`Invalid KubunID: unknown type ${j}`)}}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { AttachmentID } from './attachment.js';
|
|
2
2
|
export { KubunID } from './base.js';
|
|
3
|
+
export { ClusterModelID } from './cluster-model.js';
|
|
3
4
|
export { decodeID } from './decode.js';
|
|
4
5
|
export { DocumentID } from './document.js';
|
|
5
6
|
export { DocumentModelID, ScalarModelID, ShapeModelID } from './model.js';
|
|
7
|
+
export { PluginNodeID } from './plugin-node.js';
|
|
6
8
|
export { digestBytes, digestJSON } from './utils.js';
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{AttachmentID}from"./attachment.js";export{KubunID}from"./base.js";export{decodeID}from"./decode.js";export{DocumentID}from"./document.js";export{DocumentModelID,ScalarModelID,ShapeModelID}from"./model.js";export{digestBytes,digestJSON}from"./utils.js";
|
|
1
|
+
export{AttachmentID}from"./attachment.js";export{KubunID}from"./base.js";export{ClusterModelID}from"./cluster-model.js";export{decodeID}from"./decode.js";export{DocumentID}from"./document.js";export{DocumentModelID,ScalarModelID,ShapeModelID}from"./model.js";export{PluginNodeID}from"./plugin-node.js";export{digestBytes,digestJSON}from"./utils.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExternalType, KubunID } from './base.js';
|
|
2
|
+
export declare class PluginNodeID extends KubunID<ExternalType.PLUGIN_NODE> {
|
|
3
|
+
#private;
|
|
4
|
+
static create(plugin: string, typeName: string, localID: string): PluginNodeID;
|
|
5
|
+
static fromBytes(input: Uint8Array): PluginNodeID;
|
|
6
|
+
static fromString(input: string): PluginNodeID;
|
|
7
|
+
static from(input: PluginNodeID | Uint8Array | string): PluginNodeID;
|
|
8
|
+
constructor(plugin: string, typeName: string, localID: string);
|
|
9
|
+
get plugin(): string;
|
|
10
|
+
get typeName(): string;
|
|
11
|
+
get localID(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fromUTF as t,toUTF as e}from"@enkaku/codec";import{base36 as r}from"multiformats/bases/base36";import{ExternalType as i,KubunID as n,NAMESPACE_CODE as o}from"./base.js";import{concat as s}from"./bytes.js";import{decodeVarint as l,encodeVarint as u}from"./utils.js";export class PluginNodeID extends n{static create(t,e,r){return new PluginNodeID(t,e,r)}static fromBytes(t){let r=0,[n,s]=l(t);if(n!==o)throw Error("Invalid KubunID: namespace mismatch");let[u,a]=l(t,r+=s);if(u!==i.PLUGIN_NODE)throw Error("Invalid KubunID: type mismatch");let[m,c]=l(t,r+=a);r+=c;let p=0===m?"":e(t.slice(r,r+m)),[f,g]=l(t,r+=m);r+=g;let I=0===f?"":e(t.slice(r,r+f)),[y,D]=l(t,r+=f);return r+=D,new PluginNodeID(p,I,0===y?"":e(t.slice(r,r+y)))}static fromString(t){return PluginNodeID.fromBytes(r.decode(t))}static from(t){if(t instanceof PluginNodeID)return t;if(t instanceof Uint8Array)return PluginNodeID.fromBytes(t);if("string"==typeof t)return PluginNodeID.fromString(t);throw Error("Unsupported input type")}#t;#e;#r;constructor(e,r,n){let o=t(e),l=t(r),a=t(n),m=s([u(o.byteLength),o,u(l.byteLength),l,u(a.byteLength),a]);super(i.PLUGIN_NODE,m),this.#t=e,this.#e=r,this.#r=n}get plugin(){return this.#t}get typeName(){return this.#e}get localID(){return this.#r}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/id",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@enkaku/codec": "^0.
|
|
19
|
-
"@noble/hashes": "^2.0
|
|
18
|
+
"@enkaku/codec": "^0.14.0",
|
|
19
|
+
"@noble/hashes": "^2.2.0",
|
|
20
20
|
"multiformats": "^13.4.2",
|
|
21
21
|
"varint": "^6.0.0"
|
|
22
22
|
},
|