Skip to content

Commit 52dd6b3

Browse files
Merge pull request #8 from Con-JS-Development/development
Development - Release 1.2
2 parents 51262d2 + ec5714d commit 52dd6b3

10 files changed

Lines changed: 1030 additions & 228 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ New version of JsonDatabase is based on dynamic properties.
33
This database supports all possible [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) class operations from ECMAScript.
44
- [Starting Using Con-Databases](./docs/HOW_TO_SETUP.md)
55
- [Basic API documentation](./docs/API-Documentation.md)
6+
- [Using DynamicTables](./docs/Using-DynamicTable.md)
67

78
### Inherited from Map
89
- size: number of properties
@@ -66,9 +67,9 @@ Each key is unique to its player because key include players id, so database key
6667
Code
6768
```js
6869
import {world} from "@minecraft/server";
69-
import {WorldDatabase} from "databases.js";
70+
import { JsonDatabase } from "databases.js";
7071

71-
const stats = new WorldDatabase("playerStats");
72+
const stats = new JsonDatabase("playerStats");
7273

7374
world.afterEvents.entityDie.subscribe(({deadEntity})=>
7475
setDeaths(deadEntity,getDeaths(deadEntity) + 1);

con-database.d.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { World, Entity } from "@minecraft/server";
2+
3+
class DynamicSource {
4+
readonly source: World | Entity;
5+
constructor(source: World | Entity)
6+
getIds(): string[]
7+
get(key: string): any
8+
set(key: string, value: any): void
9+
delete(key): boolean | undefined
10+
isValid():boolean
11+
}
12+
class DynamicDatabase extends Map{
13+
constructor(source: DynamicSource, id: string, kind: string, parser: {stringify(object: any): string, parse(raw: string): any})
14+
isValid(): boolean
15+
dispose(): void
16+
readonly isDisposed: boolean
17+
}
18+
class JsonDatabase extends DynamicDatabase{ constructor(id: string, source?: World | Entity ); }
19+
interface DynamicProxyConstructor{
20+
new (id: string, source?: World | Entity): {[k: string]: any | undefined}
21+
}
22+
const DynamicProxy: DynamicProxyConstructor;
23+
enum SerializableKinds {
24+
Boolean="c0211201-0001-4002-8001-4f90af596647",
25+
Number="c0211201-0001-4002-8002-4f90af596647",
26+
String="c0211201-0001-4002-8003-4f90af596647",
27+
Object="c0211201-0001-4002-8004-4f90af596647",
28+
DynamicTable="c0211201-0001-4002-8101-4f90af596647"
29+
}
30+
interface Deserializer<T> extends Generator<T,void,unknown>{
31+
continue(): T,
32+
readonly source: DynamicSource;
33+
readonly length: number;
34+
readonly rootKey: string;
35+
readonly kind: string;
36+
}
37+
38+
namespace Serializer {
39+
function isSerializable(object: any): boolean
40+
function getSerializerKind(object: any): string | undefined
41+
function isRegistredKind(kind: string): boolean
42+
function setSerializableKind(object: object, kind: string): boolean
43+
function registrySerializer<K extends string>(kind: K, serializer: (object: any)=>Generator<string>, deserializer: (source: Deserializer<string>)=>void): K;
44+
function getSerializer(kind: string): null | ((object: any)=>Generator<string>)
45+
function getDeserializer(kind: string): ((source: Deserializer<string>)=>void) | null
46+
function setSerializableClass(construct: new (...any: any[])=>any, kind: string, serializer: (object: any)=>Generator<string>, deserializer: (source: Deserializer<string>)=>void): void
47+
function getKindFromClass(construct: new (...any: any[])=>any): string | null;
48+
function getSerializerKinds(): IterableIterator<string>
49+
function getSerializers(kind: string): {serializer: (object: any)=>Generator<string>, deserializer: (source: Deserializer<string>)=>void}
50+
function overrideSerializers<K extends string>(kind: K, serializer: (object: any)=>Generator<string>, deserializer: (source: Deserializer<string>)=>void): K;
51+
}
52+
53+
class DynamicTable extends Map<string, any>{
54+
static readonly KIND: string;
55+
static OpenCreate(id: string): DynamicTable;
56+
static ClearAll(): void;
57+
static getTableIds(): IterableIterator<string>;
58+
static DeleteTable(id: string): boolean;
59+
60+
readonly tableId: string;
61+
private constructor();
62+
isValid(): boolean;
63+
}
64+
class DataCoruptionError extends ReferenceError{
65+
constructor(source: DynamicSource, rootKey: string, message: string);
66+
remove(): void
67+
}
68+
69+
export {JsonDatabase, DynamicProxy, DynamicTable, Serializer, DataCoruptionError, SerializableKinds};
70+
/**
71+
* resitry basic serializations for API classes, based on compatibility but doesn't breaks in older or newer versions, each feature is available based on your module version used
72+
* - BlockType class
73+
* - EntityType class
74+
* - ItemType class
75+
* - BlockPermutation class --> requires BlockType class feature
76+
* - ItemStack class
77+
* - typeId
78+
* - amount
79+
* - nameTag
80+
* - keepOnDeath
81+
* - lockMode
82+
* - lore
83+
* - canDestroy
84+
* - canPlaceOn
85+
* - dynamic Properties
86+
* - enchantable component
87+
* - durability component
88+
* - Vector class
89+
*
90+
* Example of API serializers
91+
* ```js
92+
* const dt = DynamicTable.OpenCreate("test");
93+
* dt.set("item", new ItemStack("iron_sword"));
94+
* const canPlaceOn = dt.get("item").getCanPlaceOn();
95+
* ```
96+
*/
97+
export const registryAPISerializers: ()=>void
98+
export enum APISerializableKinds {
99+
BlockType = "c0211201-0001-4002-8201-4f90af596647",
100+
EntityType = "c0211201-0001-4002-8202-4f90af596647",
101+
ItemType = "c0211201-0001-4002-8203-4f90af596647",
102+
BlockPermutation = "c0211201-0001-4002-8204-4f90af596647",
103+
ItemStack = "c0211201-0001-4002-8205-4f90af596647",
104+
Vector = "c0211201-0001-4002-8206-4f90af596647",
105+
}

0 commit comments

Comments
 (0)