@colyseus/schema 3.0.69 → 3.0.71
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/build/cjs/index.js +3 -5
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +3 -5
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +3 -5
- package/lib/Decoder.d.ts +16 -0
- package/lib/Decoder.js +182 -0
- package/lib/Decoder.js.map +1 -0
- package/lib/Encoder.d.ts +13 -0
- package/lib/Encoder.js +79 -0
- package/lib/Encoder.js.map +1 -0
- package/lib/annotations.js +4 -2
- package/lib/annotations.js.map +1 -1
- package/lib/bench_encode.d.ts +1 -0
- package/lib/bench_encode.js +93 -0
- package/lib/bench_encode.js.map +1 -0
- package/lib/changes/ChangeSet.d.ts +12 -0
- package/lib/changes/ChangeSet.js +35 -0
- package/lib/changes/ChangeSet.js.map +1 -0
- package/lib/changes/ChangeTree.d.ts +53 -0
- package/lib/changes/ChangeTree.js +202 -0
- package/lib/changes/ChangeTree.js.map +1 -0
- package/lib/changes/DecodeOperation.d.ts +15 -0
- package/lib/changes/DecodeOperation.js +186 -0
- package/lib/changes/DecodeOperation.js.map +1 -0
- package/lib/changes/EncodeOperation.d.ts +18 -0
- package/lib/changes/EncodeOperation.js +130 -0
- package/lib/changes/EncodeOperation.js.map +1 -0
- package/lib/changes/ReferenceTracker.d.ts +14 -0
- package/lib/changes/ReferenceTracker.js +83 -0
- package/lib/changes/ReferenceTracker.js.map +1 -0
- package/lib/changes/consts.d.ts +14 -0
- package/lib/changes/consts.js +18 -0
- package/lib/changes/consts.js.map +1 -0
- package/lib/codegen/parser.js +2 -2
- package/lib/codegen/parser.js.map +1 -1
- package/lib/decoding/decode.d.ts +48 -0
- package/lib/decoding/decode.js +267 -0
- package/lib/decoding/decode.js.map +1 -0
- package/lib/ecs.d.ts +11 -0
- package/lib/ecs.js +160 -0
- package/lib/ecs.js.map +1 -0
- package/lib/filters/index.d.ts +8 -0
- package/lib/filters/index.js +24 -0
- package/lib/filters/index.js.map +1 -0
- package/lib/spec.d.ts +13 -0
- package/lib/spec.js +42 -0
- package/lib/spec.js.map +1 -0
- package/lib/types/ArraySchema.d.ts +238 -0
- package/lib/types/ArraySchema.js +555 -0
- package/lib/types/ArraySchema.js.map +1 -0
- package/lib/types/CollectionSchema.d.ts +35 -0
- package/lib/types/CollectionSchema.js +150 -0
- package/lib/types/CollectionSchema.js.map +1 -0
- package/lib/types/MapSchema.d.ts +38 -0
- package/lib/types/MapSchema.js +215 -0
- package/lib/types/MapSchema.js.map +1 -0
- package/lib/types/SetSchema.d.ts +32 -0
- package/lib/types/SetSchema.js +162 -0
- package/lib/types/SetSchema.js.map +1 -0
- package/lib/types/typeRegistry.d.ts +5 -0
- package/lib/types/typeRegistry.js +13 -0
- package/lib/types/typeRegistry.js.map +1 -0
- package/lib/usage.d.ts +1 -0
- package/lib/usage.js +22 -0
- package/lib/usage.js.map +1 -0
- package/lib/v3.d.ts +1 -0
- package/lib/v3.js +427 -0
- package/lib/v3.js.map +1 -0
- package/lib/v3_experiment.d.ts +1 -0
- package/lib/v3_experiment.js +407 -0
- package/lib/v3_experiment.js.map +1 -0
- package/package.json +1 -1
- package/src/annotations.ts +4 -2
- package/src/bench_encode.ts +64 -0
- package/src/codegen/parser.ts +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecodeOperation.js","sourceRoot":"","sources":["../../src/changes/DecodeOperation.ts"],"names":[],"mappings":";;;AAAA,kCAAoC;AAEpC,sCAAuE;AAGvE,6CAA6C;AAC7C,wDAAgD;AAChD,qCAAmE;AACnE,0BAAyE;AAEzE,IAAY,WAEX;AAFD,WAAY,WAAW;IACnB,2EAAuB,CAAA;AAC3B,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB;AAUD,SAAgB,WAAW,CAAC,OAAgB,EAAE,SAAoB,EAAE,GAAQ,EAAE,KAAa,EAAE,IAAS,EAAE,KAAe,EA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K,EAAE,KAAK,CAAC,CAAC;QAElC,CAAC;aAAM,IAAI,GAAG,YAAY,aAAS,EAAE,CAAC;YAClC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC7B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;gBAClB,GAAG,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;QACL,CAAC;IACL,CAAC;IAED,aAAa;IACb,IAAI,aAAa,KAAK,KAAK,EAAE,CAAC;QAC1B,UAAU,CAAC,IAAI,CAAC;YACZ,KAAK,EAAE,OAAO,CAAC,YAAY;YAC3B,EAAE,EAAE,SAAS;YACb,KAAK,EAAE,EAAE,EAAE,qBAAqB;YAChC,YAAY;YACZ,KAAK;YACL,aAAa;SAChB,CAAC,CAAC;IACP,CAAC;AACL,CAAC,CAAA;AAtFY,QAAA,uBAAuB,2BAsFnC","sourcesContent":["import { OPERATION } from \"../spec\";\nimport { Metadata } from \"../Metadata\";\nimport { DataChange, Schema, SchemaDecoderCallbacks } from \"../Schema\";\nimport type { Ref } from \"./ChangeTree\";\nimport type { Decoder } from \"../Decoder\";\nimport * as decode from \"../encoding/decode\";\nimport { getType } from \"../types/typeRegistry\";\nimport { $childType, $deleteByIndex, $getByIndex } from \"./consts\";\nimport { ArraySchema, CollectionSchema, MapSchema, SetSchema } from \"..\";\n\nexport enum DecodeState {\n DEFINITION_MISMATCH = 0,\n}\n\nexport type DecodeOperation<T extends Schema = any> = (\n decoder: Decoder<T>,\n bytes: number[],\n it: decode.Iterator,\n ref: Ref,\n allChanges: DataChange[],\n) => void;\n\nexport function decodeValue(decoder: Decoder, operation: OPERATION, ref: Ref, index: number, type: any, bytes: number[], it: decode.Iterator, allChanges: DataChange[]) {\n const $root = decoder.refs;\n const previousValue = ref[$getByIndex](index);\n\n let value: any;\n\n if ((operation & OPERATION.DELETE) === OPERATION.DELETE)\n {\n //\n // Delete operations\n //\n if (operation !== OPERATION.DELETE_AND_ADD) {\n ref[$deleteByIndex](index);\n }\n\n // Flag `refId` for garbage collection.\n const previousRefId = $root.refIds.get(previousValue);\n if (previousRefId) {\n $root.removeRef(previousRefId);\n }\n\n value = null;\n\n } else if (Schema.is(type)) {\n const refId = decode.number(bytes, it);\n value = $root.refs.get(refId);\n\n if (operation !== OPERATION.REPLACE) {\n const childType = decoder.getInstanceType(bytes, it, type);\n\n if (!value) {\n value = decoder.createInstanceOfType(childType);\n\n if (previousValue) {\n // value.$callbacks = previousValue.$callbacks;\n // value.$listeners = previousValue.$listeners;\n const previousRefId = $root.refIds.get(previousValue);\n if (previousRefId && refId !== previousRefId) {\n $root.removeRef(previousRefId);\n }\n }\n }\n\n // console.log(\"ADD REF!\", refId, value, \", TYPE =>\", Metadata.getFor(childType));\n $root.addRef(refId, value, (value !== previousValue));\n }\n\n } else if (typeof(type) === \"string\") {\n //\n // primitive value (number, string, boolean, etc)\n //\n value = decode[type as string](bytes, it);\n\n } else {\n const typeDef = getType(Object.keys(type)[0]);\n const refId = decode.number(bytes, it);\n\n const valueRef: SchemaDecoderCallbacks = ($root.refs.has(refId))\n ? previousValue || $root.refs.get(refId)\n : new typeDef.constructor();\n\n value = valueRef.clone(true);\n value[$childType] = Object.values(type)[0]; // cache childType for ArraySchema and MapSchema\n\n // preserve schema callbacks\n if (previousValue) {\n // value['$callbacks'] = previousValue['$callbacks'];\n const previousRefId = $root.refIds.get(previousValue);\n\n if (previousRefId && refId !== previousRefId) {\n $root.removeRef(previousRefId);\n\n //\n // Trigger onRemove if structure has been replaced.\n //\n const entries: IterableIterator<[any, any]> = previousValue.entries();\n let iter: IteratorResult<[any, any]>;\n while ((iter = entries.next()) && !iter.done) {\n const [key, value] = iter.value;\n allChanges.push({\n refId,\n op: OPERATION.DELETE,\n field: key,\n value: undefined,\n previousValue: value,\n });\n }\n\n }\n }\n\n // console.log(\"ADD REF!\", { refId, value });\n $root.addRef(refId, value, (valueRef !== previousValue));\n }\n\n return { value, previousValue };\n}\n\nexport const decodeSchemaOperation: DecodeOperation = function (\n decoder: Decoder<any>,\n bytes: number[],\n it: decode.Iterator,\n ref: Ref,\n allChanges: DataChange[]\n) {\n const first_byte = bytes[it.offset++];\n const metadata: Metadata = ref['constructor'][Symbol.metadata];\n\n // \"compressed\" index + operation\n const operation = (first_byte >> 6) << 6\n const index = first_byte % (operation || 255);\n\n // skip early if field is not defined\n const field = metadata[index];\n if (field === undefined) {\n return DecodeState.DEFINITION_MISMATCH;\n }\n\n const { value, previousValue } = decodeValue(\n decoder,\n operation,\n ref,\n index,\n metadata[field].type,\n bytes,\n it,\n allChanges\n );\n\n if (value !== null && value !== undefined) {\n ref[field] = value;\n }\n\n // add change\n if (previousValue !== value) {\n allChanges.push({\n refId: decoder.currentRefId,\n op: operation,\n field: field,\n value,\n previousValue,\n });\n }\n}\n\nexport const decodeKeyValueOperation: DecodeOperation = function (\n decoder: Decoder<any>,\n bytes: number[],\n it: decode.Iterator,\n ref: Ref,\n allChanges: DataChange[]\n) {\n const first_byte = bytes[it.offset++];\n\n // \"uncompressed\" index + operation (array/map items)\n const operation = first_byte;\n\n if (operation === OPERATION.CLEAR) {\n //\n // TODO: refactor me!\n // The `.clear()` method is calling `$root.removeRef(refId)` for\n // each item inside this collection\n //\n (ref as SchemaDecoderCallbacks).clear(allChanges);\n return;\n }\n\n const index = decode.number(bytes, it);\n const type = ref[$childType];\n\n let dynamicIndex: number | string;\n\n if ((operation & OPERATION.ADD) === OPERATION.ADD) { // ADD or DELETE_AND_ADD\n dynamicIndex = (ref instanceof MapSchema)\n ? decode.string(bytes, it)\n : index;\n ref['setIndex'](index, dynamicIndex);\n\n } else {\n // here\n dynamicIndex = ref['getIndex'](index);\n }\n\n const { value, previousValue } = decodeValue(\n decoder,\n operation,\n ref,\n dynamicIndex as number,\n type,\n bytes,\n it,\n allChanges\n );\n\n if (value !== null && value !== undefined) {\n if (ref instanceof MapSchema) {\n // const key = ref['$indexes'].get(field);\n const key = dynamicIndex as string;\n\n // ref.set(key, value);\n ref['$items'].set(key, value);\n\n } else if (ref instanceof ArraySchema) {\n // const key = ref['$indexes'][field];\n // console.log(\"SETTING FOR ArraySchema =>\", { field, key, value });\n // ref[key] = value;\n ref.setAt(index, value);\n\n } else if (ref instanceof CollectionSchema) {\n const index = ref.add(value);\n ref['setIndex'](index, index);\n\n } else if (ref instanceof SetSchema) {\n const index = ref.add(value);\n if (index !== false) {\n ref['setIndex'](index, index);\n }\n }\n }\n\n // add change\n if (previousValue !== value) {\n allChanges.push({\n refId: decoder.currentRefId,\n op: operation,\n field: \"\", // FIXME: remove this\n dynamicIndex,\n value,\n previousValue,\n });\n }\n}"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OPERATION } from "../spec";
|
|
2
|
+
import type { ChangeTracker, Ref } from "./ChangeTree";
|
|
3
|
+
import type { Encoder } from "../Encoder";
|
|
4
|
+
import type { Schema } from "../Schema";
|
|
5
|
+
import type { PrimitiveType } from "../annotations";
|
|
6
|
+
export type EncodeOperation<T extends Ref = any> = (encoder: Encoder, bytes: number[], changeTree: ChangeTracker<T>, index: number, operation: OPERATION) => void;
|
|
7
|
+
export declare function encodePrimitiveType(type: PrimitiveType, bytes: number[], value: any, klass: Schema, field: string | number): void;
|
|
8
|
+
export declare function encodeValue(encoder: Encoder, bytes: number[], ref: Schema, type: any, value: any, field: string | number, operation: OPERATION): void;
|
|
9
|
+
/**
|
|
10
|
+
* Used for Schema instances.
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
export declare const encodeSchemaOperation: EncodeOperation;
|
|
14
|
+
/**
|
|
15
|
+
* Used for collections (MapSchema, ArraySchema, etc.)
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare const encodeKeyValueOperation: EncodeOperation;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeKeyValueOperation = exports.encodeSchemaOperation = exports.encodeValue = exports.encodePrimitiveType = void 0;
|
|
4
|
+
const spec_1 = require("../spec");
|
|
5
|
+
const consts_1 = require("./consts");
|
|
6
|
+
const typeRegistry_1 = require("../types/typeRegistry");
|
|
7
|
+
const encode = require("../encoding/encode");
|
|
8
|
+
const assert_1 = require("../encoding/assert");
|
|
9
|
+
const MapSchema_1 = require("../types/MapSchema");
|
|
10
|
+
function encodePrimitiveType(type, bytes, value, klass, field) {
|
|
11
|
+
(0, assert_1.assertType)(value, type, klass, field);
|
|
12
|
+
const encodeFunc = encode[type];
|
|
13
|
+
if (encodeFunc) {
|
|
14
|
+
encodeFunc(bytes, value);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
throw new assert_1.EncodeSchemaError(`a '${type}' was expected, but ${value} was provided in ${klass.constructor.name}#${field}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.encodePrimitiveType = encodePrimitiveType;
|
|
21
|
+
function encodeValue(encoder, bytes, ref, type, value, field, operation) {
|
|
22
|
+
if (type[Symbol.metadata] !== undefined) {
|
|
23
|
+
(0, assert_1.assertInstanceType)(value, type, ref, field);
|
|
24
|
+
//
|
|
25
|
+
// Encode refId for this instance.
|
|
26
|
+
// The actual instance is going to be encoded on next `changeTree` iteration.
|
|
27
|
+
//
|
|
28
|
+
encode.number(bytes, value[consts_1.$changes].refId);
|
|
29
|
+
// Try to encode inherited TYPE_ID if it's an ADD operation.
|
|
30
|
+
if ((operation & spec_1.OPERATION.ADD) === spec_1.OPERATION.ADD) {
|
|
31
|
+
encoder.tryEncodeTypeId(bytes, type, value.constructor);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (typeof (type) === "string") {
|
|
35
|
+
//
|
|
36
|
+
// Primitive values
|
|
37
|
+
//
|
|
38
|
+
encodePrimitiveType(type, bytes, value, ref, field);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
//
|
|
42
|
+
// Custom type (MapSchema, ArraySchema, etc)
|
|
43
|
+
//
|
|
44
|
+
const definition = (0, typeRegistry_1.getType)(Object.keys(type)[0]);
|
|
45
|
+
//
|
|
46
|
+
// ensure a ArraySchema has been provided
|
|
47
|
+
//
|
|
48
|
+
(0, assert_1.assertInstanceType)(ref[field], definition.constructor, ref, field);
|
|
49
|
+
//
|
|
50
|
+
// Encode refId for this instance.
|
|
51
|
+
// The actual instance is going to be encoded on next `changeTree` iteration.
|
|
52
|
+
//
|
|
53
|
+
encode.number(bytes, value[consts_1.$changes].refId);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.encodeValue = encodeValue;
|
|
57
|
+
/**
|
|
58
|
+
* Used for Schema instances.
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
const encodeSchemaOperation = function (encoder, bytes, changeTree, index, operation) {
|
|
62
|
+
const ref = changeTree.ref;
|
|
63
|
+
const metadata = ref['constructor'][Symbol.metadata];
|
|
64
|
+
const field = metadata[index];
|
|
65
|
+
const type = metadata[field].type;
|
|
66
|
+
const value = ref[field];
|
|
67
|
+
// "compress" field index + operation
|
|
68
|
+
encode.uint8(bytes, (index | operation));
|
|
69
|
+
// ensure refId for the value
|
|
70
|
+
if (value && value[consts_1.$changes]) {
|
|
71
|
+
value[consts_1.$changes].ensureRefId();
|
|
72
|
+
}
|
|
73
|
+
if (operation === spec_1.OPERATION.TOUCH) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// TODO: inline this function call small performance gain
|
|
77
|
+
encodeValue(encoder, bytes, ref, type, value, field, operation);
|
|
78
|
+
};
|
|
79
|
+
exports.encodeSchemaOperation = encodeSchemaOperation;
|
|
80
|
+
/**
|
|
81
|
+
* Used for collections (MapSchema, ArraySchema, etc.)
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
const encodeKeyValueOperation = function (encoder, bytes, changeTree, field, operation) {
|
|
85
|
+
const ref = changeTree.ref;
|
|
86
|
+
// encode field index + operation
|
|
87
|
+
if (operation !== spec_1.OPERATION.TOUCH) {
|
|
88
|
+
encode.uint8(bytes, operation);
|
|
89
|
+
// custom operations
|
|
90
|
+
if (operation === spec_1.OPERATION.CLEAR) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// indexed operations
|
|
94
|
+
encode.number(bytes, field);
|
|
95
|
+
}
|
|
96
|
+
//
|
|
97
|
+
// encode "alias" for dynamic fields (maps)
|
|
98
|
+
//
|
|
99
|
+
if ((operation & spec_1.OPERATION.ADD) == spec_1.OPERATION.ADD) { // ADD or DELETE_AND_ADD
|
|
100
|
+
if (ref instanceof MapSchema_1.MapSchema) {
|
|
101
|
+
//
|
|
102
|
+
// MapSchema dynamic key
|
|
103
|
+
//
|
|
104
|
+
const dynamicIndex = changeTree.ref['$indexes'].get(field);
|
|
105
|
+
encode.string(bytes, dynamicIndex);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (operation === spec_1.OPERATION.DELETE) {
|
|
109
|
+
//
|
|
110
|
+
// TODO: delete from filter cache data.
|
|
111
|
+
//
|
|
112
|
+
// if (useFilters) {
|
|
113
|
+
// delete changeTree.caches[fieldIndex];
|
|
114
|
+
// }
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const type = changeTree.getType(field);
|
|
118
|
+
const value = changeTree.getValue(field);
|
|
119
|
+
// ensure refId for the value
|
|
120
|
+
if (value && value[consts_1.$changes]) {
|
|
121
|
+
value[consts_1.$changes].ensureRefId();
|
|
122
|
+
}
|
|
123
|
+
if (operation === spec_1.OPERATION.TOUCH) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// TODO: inline this function call small performance gain
|
|
127
|
+
encodeValue(encoder, bytes, ref, type, value, field, operation);
|
|
128
|
+
};
|
|
129
|
+
exports.encodeKeyValueOperation = encodeKeyValueOperation;
|
|
130
|
+
//# sourceMappingURL=EncodeOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Enc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AAY,CAAC,CAAC;QACvC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,KAAK,gBAAS,CAAC,MAAM,EAAE,CAAC;QACjC,EAAE;QACF,uCAAuC;QACvC,EAAE;QACF,oBAAoB;QACpB,4CAA4C;QAC5C,IAAI;QACJ,OAAO;IACX,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEzC,6BAA6B;IAC7B,IAAI,KAAK,IAAI,KAAK,CAAC,iBAAQ,CAAC,EAAE,CAAC;QAC3B,KAAK,CAAC,iBAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC;IAED,IAAI,SAAS,KAAK,gBAAS,CAAC,KAAK,EAAE,CAAC;QAChC,OAAO;IACX,CAAC;IAED,yDAAyD;IACzD,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACpE,CAAC,CAAA;AA3DY,QAAA,uBAAuB,2BA2DnC","sourcesContent":["import { OPERATION } from \"../spec\";\nimport { $changes } from \"./consts\";\nimport { getType } from \"../types/typeRegistry\";\n\nimport * as encode from \"../encoding/encode\";\nimport { EncodeSchemaError, assertInstanceType, assertType } from \"../encoding/assert\";\n\nimport type { ChangeTracker, Ref } from \"./ChangeTree\";\nimport type { Encoder } from \"../Encoder\";\nimport type { Schema } from \"../Schema\";\nimport type { PrimitiveType } from \"../annotations\";\n\nimport { MapSchema } from \"../types/MapSchema\";\n\nexport type EncodeOperation<T extends Ref = any> = (\n encoder: Encoder,\n bytes: number[],\n changeTree: ChangeTracker<T>,\n index: number,\n operation: OPERATION,\n) => void;\n\nexport function encodePrimitiveType(\n type: PrimitiveType,\n bytes: number[],\n value: any,\n klass: Schema,\n field: string | number,\n) {\n assertType(value, type as string, klass, field);\n\n const encodeFunc = encode[type as string];\n\n if (encodeFunc) {\n encodeFunc(bytes, value);\n\n } else {\n throw new EncodeSchemaError(`a '${type}' was expected, but ${value} was provided in ${klass.constructor.name}#${field}`);\n }\n}\n\nexport function encodeValue(\n encoder: Encoder,\n bytes: number[],\n ref: Schema,\n type: any,\n value: any,\n field: string | number,\n operation: OPERATION\n) {\n if (type[Symbol.metadata] !== undefined) {\n assertInstanceType(value, type as typeof Schema, ref as Schema, field);\n\n //\n // Encode refId for this instance.\n // The actual instance is going to be encoded on next `changeTree` iteration.\n //\n encode.number(bytes, value[$changes].refId);\n\n // Try to encode inherited TYPE_ID if it's an ADD operation.\n if ((operation & OPERATION.ADD) === OPERATION.ADD) {\n encoder.tryEncodeTypeId(bytes, type as typeof Schema, value.constructor as typeof Schema);\n }\n\n } else if (typeof (type) === \"string\") {\n //\n // Primitive values\n //\n encodePrimitiveType(type as PrimitiveType, bytes, value, ref as Schema, field);\n\n } else {\n //\n // Custom type (MapSchema, ArraySchema, etc)\n //\n const definition = getType(Object.keys(type)[0]);\n\n //\n // ensure a ArraySchema has been provided\n //\n assertInstanceType(ref[field], definition.constructor, ref as Schema, field);\n\n //\n // Encode refId for this instance.\n // The actual instance is going to be encoded on next `changeTree` iteration.\n //\n encode.number(bytes, value[$changes].refId);\n }\n}\n\n/**\n * Used for Schema instances.\n * @private\n */\nexport const encodeSchemaOperation: EncodeOperation = function (\n encoder: Encoder,\n bytes: number[],\n changeTree: ChangeTracker,\n index: number,\n operation: OPERATION,\n) {\n const ref = changeTree.ref;\n const metadata = ref['constructor'][Symbol.metadata];\n\n const field = metadata[index];\n const type = metadata[field].type;\n const value = ref[field];\n\n // \"compress\" field index + operation\n encode.uint8(bytes, (index | operation));\n\n // ensure refId for the value\n if (value && value[$changes]) {\n value[$changes].ensureRefId();\n }\n\n if (operation === OPERATION.TOUCH) {\n return;\n }\n\n // TODO: inline this function call small performance gain\n encodeValue(encoder, bytes, ref, type, value, field, operation);\n}\n\n/**\n * Used for collections (MapSchema, ArraySchema, etc.)\n * @private\n */\nexport const encodeKeyValueOperation: EncodeOperation = function (\n encoder: Encoder,\n bytes: number[],\n changeTree: ChangeTracker,\n field: number,\n operation: OPERATION,\n) {\n const ref = changeTree.ref;\n\n // encode field index + operation\n if (operation !== OPERATION.TOUCH) {\n encode.uint8(bytes, operation);\n\n // custom operations\n if (operation === OPERATION.CLEAR) {\n return;\n }\n\n // indexed operations\n encode.number(bytes, field);\n }\n\n //\n // encode \"alias\" for dynamic fields (maps)\n //\n if ((operation & OPERATION.ADD) == OPERATION.ADD) { // ADD or DELETE_AND_ADD\n if (ref instanceof MapSchema) {\n //\n // MapSchema dynamic key\n //\n const dynamicIndex = changeTree.ref['$indexes'].get(field);\n encode.string(bytes, dynamicIndex);\n }\n }\n\n if (operation === OPERATION.DELETE) {\n //\n // TODO: delete from filter cache data.\n //\n // if (useFilters) {\n // delete changeTree.caches[fieldIndex];\n // }\n return;\n }\n\n const type = changeTree.getType(field);\n const value = changeTree.getValue(field);\n\n // ensure refId for the value\n if (value && value[$changes]) {\n value[$changes].ensureRefId();\n }\n\n if (operation === OPERATION.TOUCH) {\n return;\n }\n\n // TODO: inline this function call small performance gain\n encodeValue(encoder, bytes, ref, type, value, field, operation);\n}"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Ref } from "./ChangeTree";
|
|
2
|
+
export declare class ReferenceTracker {
|
|
3
|
+
refs: Map<number, Ref>;
|
|
4
|
+
refCounts: {
|
|
5
|
+
[refId: number]: number;
|
|
6
|
+
};
|
|
7
|
+
deletedRefs: Set<number>;
|
|
8
|
+
protected nextUniqueId: number;
|
|
9
|
+
getNextUniqueId(): number;
|
|
10
|
+
addRef(refId: number, ref: Ref, incrementCount?: boolean): void;
|
|
11
|
+
removeRef(refId: number): void;
|
|
12
|
+
clearRefs(): void;
|
|
13
|
+
garbageCollectDeletedRefs(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReferenceTracker = void 0;
|
|
4
|
+
const Schema_1 = require("../Schema");
|
|
5
|
+
class ReferenceTracker {
|
|
6
|
+
constructor() {
|
|
7
|
+
//
|
|
8
|
+
// Relation of refId => Schema structure
|
|
9
|
+
// For direct access of structures during decoding time.
|
|
10
|
+
//
|
|
11
|
+
this.refs = new Map();
|
|
12
|
+
this.refCounts = {};
|
|
13
|
+
this.deletedRefs = new Set();
|
|
14
|
+
this.nextUniqueId = 0;
|
|
15
|
+
}
|
|
16
|
+
getNextUniqueId() {
|
|
17
|
+
return this.nextUniqueId++;
|
|
18
|
+
}
|
|
19
|
+
// for decoding
|
|
20
|
+
addRef(refId, ref, incrementCount = true) {
|
|
21
|
+
this.refs.set(refId, ref);
|
|
22
|
+
if (incrementCount) {
|
|
23
|
+
this.refCounts[refId] = (this.refCounts[refId] || 0) + 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// for decoding
|
|
27
|
+
removeRef(refId) {
|
|
28
|
+
const refCount = this.refCounts[refId];
|
|
29
|
+
if (refCount === undefined) {
|
|
30
|
+
console.warn(`trying to remove reference ${refId} that doesn't exist`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (refCount === 0) {
|
|
34
|
+
console.warn(`trying to remove reference ${refId} with 0 refCount`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.refCounts[refId] = refCount - 1;
|
|
38
|
+
this.deletedRefs.add(refId);
|
|
39
|
+
}
|
|
40
|
+
clearRefs() {
|
|
41
|
+
this.refs.clear();
|
|
42
|
+
this.deletedRefs.clear();
|
|
43
|
+
this.refCounts = {};
|
|
44
|
+
}
|
|
45
|
+
// for decoding
|
|
46
|
+
garbageCollectDeletedRefs() {
|
|
47
|
+
this.deletedRefs.forEach((refId) => {
|
|
48
|
+
//
|
|
49
|
+
// Skip active references.
|
|
50
|
+
//
|
|
51
|
+
if (this.refCounts[refId] > 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const ref = this.refs.get(refId);
|
|
55
|
+
//
|
|
56
|
+
// Ensure child schema instances have their references removed as well.
|
|
57
|
+
//
|
|
58
|
+
if (ref instanceof Schema_1.Schema) {
|
|
59
|
+
for (const fieldName in ref['_definition'].schema) {
|
|
60
|
+
if (typeof (ref['_definition'].schema[fieldName]) !== "string" &&
|
|
61
|
+
ref[fieldName] &&
|
|
62
|
+
ref[fieldName]['$changes']) {
|
|
63
|
+
this.removeRef(ref[fieldName]['$changes'].refId);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const definition = ref['$changes'].parent._definition;
|
|
69
|
+
const type = definition.schema[definition.fieldsByIndex[ref['$changes'].parentIndex]];
|
|
70
|
+
if (typeof (Object.values(type)[0]) === "function") {
|
|
71
|
+
Array.from(ref.values())
|
|
72
|
+
.forEach((child) => this.removeRef(child['$changes'].refId));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
this.refs.delete(refId);
|
|
76
|
+
delete this.refCounts[refId];
|
|
77
|
+
});
|
|
78
|
+
// clear deleted refs.
|
|
79
|
+
this.deletedRefs.clear();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ReferenceTracker = ReferenceTracker;
|
|
83
|
+
//# sourceMappingURL=ReferenceTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferenceTracker.js","sourceRoot":"","sources":["../../src/changes/ReferenceTracker.ts"],"names":[],"mappings":";;;AAAA,sCAAmC;AAInC,MAAa,gBAAgB;IAA7B;QACI,EAAE;QACF,wCAAwC;QACxC,wDAAwD;QACxD,EAAE;QACK,SAAI,GAAG,IAAI,GAAG,EAAe,CAAC;QAC9B,cAAS,GAAiC,EAAE,CAAC;QAC7C,gBAAW,GAAG,IAAI,GAAG,EAAU,CAAC;QAE7B,iBAAY,GAAW,CAAC,CAA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AAC;YACxB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,sBAAsB;QACtB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CAEJ;AAtFD,4CAsFC","sourcesContent":["import { Schema } from \"../Schema\";\nimport { Ref } from \"./ChangeTree\";\nimport type { SchemaDefinition } from \"../annotations\";\n\nexport class ReferenceTracker {\n //\n // Relation of refId => Schema structure\n // For direct access of structures during decoding time.\n //\n public refs = new Map<number, Ref>();\n public refCounts: { [refId: number]: number; } = {};\n public deletedRefs = new Set<number>();\n\n protected nextUniqueId: number = 0;\n\n getNextUniqueId() {\n return this.nextUniqueId++;\n }\n\n // for decoding\n addRef(refId: number, ref: Ref, incrementCount: boolean = true) {\n this.refs.set(refId, ref);\n\n if (incrementCount) {\n this.refCounts[refId] = (this.refCounts[refId] || 0) + 1;\n }\n }\n\n // for decoding\n removeRef(refId: number) {\n const refCount = this.refCounts[refId];\n if (refCount === undefined) {\n console.warn(`trying to remove reference ${refId} that doesn't exist`);\n return;\n }\n if (refCount === 0) {\n console.warn(`trying to remove reference ${refId} with 0 refCount`);\n return;\n }\n\n this.refCounts[refId] = refCount - 1;\n this.deletedRefs.add(refId);\n }\n\n clearRefs() {\n this.refs.clear();\n this.deletedRefs.clear();\n this.refCounts = {};\n }\n\n // for decoding\n garbageCollectDeletedRefs() {\n this.deletedRefs.forEach((refId) => {\n //\n // Skip active references.\n //\n if (this.refCounts[refId] > 0) { return; }\n\n const ref = this.refs.get(refId);\n\n //\n // Ensure child schema instances have their references removed as well.\n //\n if (ref instanceof Schema) {\n for (const fieldName in ref['_definition'].schema) {\n if (typeof (ref['_definition'].schema[fieldName]) !== \"string\" &&\n ref[fieldName] &&\n ref[fieldName]['$changes']) {\n this.removeRef(ref[fieldName]['$changes'].refId);\n }\n }\n\n } else {\n const definition: SchemaDefinition = ref['$changes'].parent._definition;\n const type = definition.schema[definition.fieldsByIndex[ref['$changes'].parentIndex]];\n\n if (typeof (Object.values(type)[0]) === \"function\") {\n Array.from(ref.values())\n .forEach((child) => this.removeRef(child['$changes'].refId));\n }\n }\n\n this.refs.delete(refId);\n delete this.refCounts[refId];\n });\n\n // clear deleted refs.\n this.deletedRefs.clear();\n }\n\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const $track: unique symbol;
|
|
2
|
+
export declare const $encoder: unique symbol;
|
|
3
|
+
export declare const $decoder: unique symbol;
|
|
4
|
+
export declare const $getByIndex: unique symbol;
|
|
5
|
+
export declare const $deleteByIndex: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Used to hold ChangeTree instances whitin the structures
|
|
8
|
+
*/
|
|
9
|
+
export declare const $changes: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* Used to keep track of the type of the child elements of a collection
|
|
12
|
+
* (MapSchema, ArraySchema, etc.)
|
|
13
|
+
*/
|
|
14
|
+
export declare const $childType: unique symbol;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$childType = exports.$changes = exports.$deleteByIndex = exports.$getByIndex = exports.$decoder = exports.$encoder = exports.$track = void 0;
|
|
4
|
+
exports.$track = Symbol("$track");
|
|
5
|
+
exports.$encoder = Symbol("$encoder");
|
|
6
|
+
exports.$decoder = Symbol("$decoder");
|
|
7
|
+
exports.$getByIndex = Symbol("$getByIndex");
|
|
8
|
+
exports.$deleteByIndex = Symbol("$deleteByIndex");
|
|
9
|
+
/**
|
|
10
|
+
* Used to hold ChangeTree instances whitin the structures
|
|
11
|
+
*/
|
|
12
|
+
exports.$changes = Symbol('$changes');
|
|
13
|
+
/**
|
|
14
|
+
* Used to keep track of the type of the child elements of a collection
|
|
15
|
+
* (MapSchema, ArraySchema, etc.)
|
|
16
|
+
*/
|
|
17
|
+
exports.$childType = Symbol('$childType');
|
|
18
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/changes/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1B,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE9B,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AACpC,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD;;GAEG;AACU,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE3C;;;GAGG;AACU,QAAA,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC","sourcesContent":["export const $track = Symbol(\"$track\");\nexport const $encoder = Symbol(\"$encoder\");\nexport const $decoder = Symbol(\"$decoder\");\n\nexport const $getByIndex = Symbol(\"$getByIndex\");\nexport const $deleteByIndex = Symbol(\"$deleteByIndex\");\n\n/**\n * Used to hold ChangeTree instances whitin the structures\n */\nexport const $changes = Symbol('$changes');\n\n/**\n * Used to keep track of the type of the child elements of a collection\n * (MapSchema, ArraySchema, etc.)\n */\nexport const $childType = Symbol('$childType');"]}
|
package/lib/codegen/parser.js
CHANGED
|
@@ -154,7 +154,7 @@ function inspectNode(node, context, decoratorName) {
|
|
|
154
154
|
if (!className) {
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
|
-
if (currentStructure
|
|
157
|
+
if (currentStructure?.name !== className) {
|
|
158
158
|
currentStructure = new types_1.Class();
|
|
159
159
|
}
|
|
160
160
|
context.addStructure(currentStructure);
|
|
@@ -218,7 +218,7 @@ function inspectNode(node, context, decoratorName) {
|
|
|
218
218
|
if (!className) {
|
|
219
219
|
break;
|
|
220
220
|
}
|
|
221
|
-
if (currentStructure
|
|
221
|
+
if (currentStructure?.name !== className) {
|
|
222
222
|
currentStructure = new types_1.Class();
|
|
223
223
|
context.addStructure(currentStructure);
|
|
224
224
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/codegen/parser.ts"],"names":[],"mappings":";;AA6UA,gCA4DC;AAOD,sCAiBC;AAjaD,iCAAiC;AACjC,6BAA6B;AAC7B,2BAAgC;AAChC,mCAA8E;AAE9E,IAAI,gBAA4B,CAAC;AACjC,IAAI,eAAyB,CAAC;AAE9B,IAAI,aAAsB,CAAC;AAE3B,SAAS,cAAc,CAAC,QAAkB,EAAE,WAAgB;IACxD,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC;QACtB,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC;IAE1C,CAAC;SAAM,IAAI,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,uBAAuB,EAAE,CAAC;QACnE,QAAQ,CAAC,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACpD,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;IAEpE,CAAC;SAAM,IAAI,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,sBAAsB,EAAE,CAAC;QAClE,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC;QACxB,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEtD,CAAC;SAAM,CAAC;QACJ,QAAQ,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IACrC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,IAAa,EAAE,OAAgB,EAAE,aAAqB;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AI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAED,aAAa;IACb,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import * as ts from \"typescript\";\nimport * as path from \"path\";\nimport {readFileSync} from \"fs\";\nimport {IStructure, Class, Interface, Property, Context, Enum} from \"./types\";\n\nlet currentStructure: IStructure;\nlet currentProperty: Property;\n\nlet globalContext: Context;\n\nfunction defineProperty(property: Property, initializer: any) {\n if (ts.isIdentifier(initializer)) {\n property.type = \"ref\";\n property.childType = initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n property.type = initializer.properties[0].name.text;\n property.childType = initializer.properties[0].initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n property.type = \"array\";\n property.childType = initializer.elements[0].text;\n\n } else {\n property.type = initializer.text;\n }\n}\n\nfunction inspectNode(node: ts.Node, context: Context, decoratorName: string) {\n switch (node.kind) {\n case ts.SyntaxKind.ImportClause:\n const specifier = (node.parent as any).moduleSpecifier;\n if (specifier && (specifier.text as string).startsWith('.')) {\n const currentDir = path.dirname(node.getSourceFile().fileName);\n const pathToImport = path.resolve(currentDir, specifier.text);\n parseFiles([pathToImport], decoratorName, globalContext);\n }\n break;\n\n case ts.SyntaxKind.ClassDeclaration:\n currentStructure = new Class();\n\n const heritageClauses = (node as ts.ClassLikeDeclarationBase).heritageClauses;\n if (heritageClauses && heritageClauses.length > 0) {\n (currentStructure as Class).extends = heritageClauses[0].types[0].expression.getText();\n }\n\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.InterfaceDeclaration:\n //\n // Only generate Interfaces if it has \"Message\" on its name.\n // Example: MyMessage\n //\n const interfaceName = (node as ts.TypeParameterDeclaration).name.escapedText.toString();\n if (interfaceName.indexOf(\"Message\") !== -1) {\n currentStructure = new Interface();\n currentStructure.name = interfaceName;\n\n context.addStructure(currentStructure);\n }\n break;\n\n case ts.SyntaxKind.EnumDeclaration:\n const enumName = (\n node as ts.EnumDeclaration\n ).name.escapedText.toString();\n currentStructure = new Enum();\n currentStructure.name = enumName;\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.ExtendsKeyword:\n // console.log(node.getText());\n break;\n\n case ts.SyntaxKind.PropertySignature:\n if (currentStructure instanceof Interface) {\n const interfaceDeclaration = node.parent;\n\n if (\n currentStructure.name !== (interfaceDeclaration as ts.TypeParameterDeclaration).name.escapedText.toString()\n ) {\n // skip if property if for a another interface than the one we're interested in.\n break;\n }\n\n // define a property of an interface\n const property = new Property();\n property.name = (node as any).name.escapedText.toString();\n property.type = (node as any).type.getText();\n currentStructure.addProperty(property);\n }\n break;\n\n case ts.SyntaxKind.Identifier:\n if (\n node.getText() === \"deprecated\" &&\n node.parent.kind !== ts.SyntaxKind.ImportSpecifier\n ) {\n currentProperty = new Property();\n currentProperty.deprecated = true;\n break;\n }\n\n if (node.getText() === decoratorName) {\n const prop: any = node.parent?.parent?.parent;\n const propDecorator = getDecorators(prop);\n const hasExpression = prop?.expression?.arguments;\n const hasDecorator = (propDecorator?.length > 0);\n\n /**\n * neither a `@type()` decorator or `type()` call. skip.\n */\n if (!hasDecorator && !hasExpression) {\n break;\n }\n\n // using as decorator\n if (propDecorator) {\n /**\n * Calling `@type()` as decorator\n */\n const typeDecorator: any = propDecorator.find((decorator => {\n return (decorator.expression as any).expression.escapedText === decoratorName;\n })).expression;\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n const typeArgument = typeDecorator.arguments[0];\n defineProperty(property, typeArgument);\n\n } else if (\n prop.expression.arguments?.[1] &&\n prop.expression.expression.arguments?.[0]\n ) {\n /**\n * Calling `type()` as a regular method\n */\n const property = currentProperty || new Property();\n property.name = prop.expression.arguments[1].text;\n currentStructure.addProperty(property);\n\n const typeArgument = prop.expression.expression.arguments[0];\n defineProperty(property, typeArgument);\n }\n\n } else if (\n node.getText() === \"setFields\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * Metadata.setFields(klassName, { ... })\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n /**\n * Skip if @codegen-ignore comment is found before the call expression\n * TODO: currently, if @codegen-ignore is on the file, it will skip all the setFields calls.\n */\n const sourceFile = node.getSourceFile();\n const fullText = sourceFile.getFullText();\n const nodeStart = callExpression.getFullStart();\n const textBeforeNode = fullText.substring(0, nodeStart);\n if (textBeforeNode.includes('@codegen-ignore')) {\n break;\n }\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const classNameNode = callExpression.arguments[0];\n const className = ts.isClassExpression(classNameNode)\n ? classNameNode.name?.escapedText.toString()\n : classNameNode.getText();\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure.name !== className) {\n currentStructure = new Class();\n }\n context.addStructure(currentStructure);\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n\n } else if (\n node.getText() === \"defineTypes\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * JavaScript source file (`.js`)\n * Using `defineTypes()`\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const className = callExpression.arguments[0].getText()\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n defineProperty(property, prop.initializer);\n }\n\n }\n\n if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {\n currentStructure.name = node.getText();\n }\n\n currentProperty = undefined;\n\n break;\n\n case ts.SyntaxKind.CallExpression:\n /**\n * Defining schema via `schema.schema({ ... })`\n * - schema.schema({})\n * - schema({})\n * - ClassName.extends({})\n */\n if (\n (\n (\n (node as ts.CallExpression).expression?.getText() === \"schema.schema\" ||\n (node as ts.CallExpression).expression?.getText() === \"schema\"\n ) ||\n (\n (node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1\n )\n ) &&\n (node as ts.CallExpression).arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression\n ) {\n const callExpression = node as ts.CallExpression;\n\n let className = callExpression.arguments[1]?.getText();\n\n if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {\n className = (callExpression.parent as ts.VariableDeclaration).name?.getText();\n }\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure.name !== className) {\n currentStructure = new Class();\n context.addStructure(currentStructure);\n }\n\n if ((node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1) {\n // if it's using `.extends({})`\n const extendsClass = (node as any).expression?.expression?.escapedText;\n\n // skip if no extendsClass is provided\n if (!extendsClass) { break; }\n (currentStructure as Class).extends = extendsClass;\n\n } else {\n // if it's using `schema({})`\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n }\n\n currentStructure.name = className;\n\n const types = callExpression.arguments[0] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n }\n\n break;\n\n case ts.SyntaxKind.EnumMember:\n if (currentStructure instanceof Enum) {\n const initializer = (node as any).initializer?.text;\n const name = node.getFirstToken().getText();\n const property = currentProperty || new Property();\n property.name = name;\n if (initializer !== undefined) {\n property.type = initializer;\n }\n currentStructure.addProperty(property);\n currentProperty = undefined;\n }\n break;\n }\n\n ts.forEachChild(node, (n) => inspectNode(n, context, decoratorName));\n}\n\nlet parsedFiles: { [filename: string]: boolean };\n\nexport function parseFiles(\n fileNames: string[],\n decoratorName: string = \"type\",\n context: Context = new Context()\n) {\n /**\n * Re-set globalContext for each test case\n */\n if (globalContext !== context) {\n parsedFiles = {};\n globalContext = context;\n }\n\n fileNames.forEach((fileName) => {\n let sourceFile: ts.Node;\n let sourceFileName: string;\n\n const fileNameAlternatives = [];\n\n if (\n !fileName.endsWith(\".ts\") &&\n !fileName.endsWith(\".js\") &&\n !fileName.endsWith(\".mjs\")\n ) {\n fileNameAlternatives.push(`${fileName}.ts`);\n fileNameAlternatives.push(`${fileName}/index.ts`);\n\n } else {\n fileNameAlternatives.push(fileName);\n }\n\n for (let i = 0; i < fileNameAlternatives.length; i++) {\n try {\n sourceFileName = path.resolve(fileNameAlternatives[i]);\n\n if (parsedFiles[sourceFileName]) {\n break;\n }\n\n sourceFile = ts.createSourceFile(\n sourceFileName,\n readFileSync(sourceFileName).toString(),\n ts.ScriptTarget.Latest,\n true\n );\n\n parsedFiles[sourceFileName] = true;\n\n break;\n } catch (e) {\n // console.log(`${fileNameAlternatives[i]} => ${e.message}`);\n }\n }\n\n if (sourceFile) {\n inspectNode(sourceFile, context, decoratorName);\n }\n });\n\n return context.getStructures();\n}\n\n/**\n * TypeScript 4.8+ has introduced a change on how to access decorators.\n * - https://github.com/microsoft/TypeScript/pull/49089\n * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees\n */\nexport function getDecorators(node: ts.Node | null | undefined,): undefined | ts.Decorator[] {\n if (node == undefined) { return undefined; }\n\n // TypeScript 4.7 and below\n // @ts-ignore\n if (node.decorators) { return node.decorators; }\n\n // TypeScript 4.8 and above\n // @ts-ignore\n if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {\n // @ts-ignore\n const decorators = ts.getDecorators(node);\n return decorators ? Array.from(decorators) : undefined;\n }\n\n // @ts-ignore\n return node.modifiers?.filter(ts.isDecorator);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/codegen/parser.ts"],"names":[],"mappings":";;AA6UA,gCA4DC;AAOD,sCAiBC;AAjaD,iCAAiC;AACjC,6BAA6B;AAC7B,2BAAgC;AAChC,mCAA8E;AAE9E,IAAI,gBAA4B,CAAC;AACjC,IAAI,eAAyB,CAAC;AAE9B,IAAI,aAAsB,CAAC;AAE3B,SAAS,cAAc,CAAC,QAAkB,EAAE,WAAgB;IACxD,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC;QACtB,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC;IAE1C,CAAC;SAAM,IAAI,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,uBAAuB,EAAE,CAAC;QACnE,QAAQ,CAAC,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACpD,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;IAEpE,CAAC;SAAM,IAAI,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,sBAAsB,EAAE,CAAC;QAClE,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC;QACxB,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEtD,CAAC;SAAM,CAAC;QACJ,QAAQ,CAAC,IAA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AAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAED,aAAa;IACb,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import * as ts from \"typescript\";\nimport * as path from \"path\";\nimport {readFileSync} from \"fs\";\nimport {IStructure, Class, Interface, Property, Context, Enum} from \"./types\";\n\nlet currentStructure: IStructure;\nlet currentProperty: Property;\n\nlet globalContext: Context;\n\nfunction defineProperty(property: Property, initializer: any) {\n if (ts.isIdentifier(initializer)) {\n property.type = \"ref\";\n property.childType = initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n property.type = initializer.properties[0].name.text;\n property.childType = initializer.properties[0].initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n property.type = \"array\";\n property.childType = initializer.elements[0].text;\n\n } else {\n property.type = initializer.text;\n }\n}\n\nfunction inspectNode(node: ts.Node, context: Context, decoratorName: string) {\n switch (node.kind) {\n case ts.SyntaxKind.ImportClause:\n const specifier = (node.parent as any).moduleSpecifier;\n if (specifier && (specifier.text as string).startsWith('.')) {\n const currentDir = path.dirname(node.getSourceFile().fileName);\n const pathToImport = path.resolve(currentDir, specifier.text);\n parseFiles([pathToImport], decoratorName, globalContext);\n }\n break;\n\n case ts.SyntaxKind.ClassDeclaration:\n currentStructure = new Class();\n\n const heritageClauses = (node as ts.ClassLikeDeclarationBase).heritageClauses;\n if (heritageClauses && heritageClauses.length > 0) {\n (currentStructure as Class).extends = heritageClauses[0].types[0].expression.getText();\n }\n\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.InterfaceDeclaration:\n //\n // Only generate Interfaces if it has \"Message\" on its name.\n // Example: MyMessage\n //\n const interfaceName = (node as ts.TypeParameterDeclaration).name.escapedText.toString();\n if (interfaceName.indexOf(\"Message\") !== -1) {\n currentStructure = new Interface();\n currentStructure.name = interfaceName;\n\n context.addStructure(currentStructure);\n }\n break;\n\n case ts.SyntaxKind.EnumDeclaration:\n const enumName = (\n node as ts.EnumDeclaration\n ).name.escapedText.toString();\n currentStructure = new Enum();\n currentStructure.name = enumName;\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.ExtendsKeyword:\n // console.log(node.getText());\n break;\n\n case ts.SyntaxKind.PropertySignature:\n if (currentStructure instanceof Interface) {\n const interfaceDeclaration = node.parent;\n\n if (\n currentStructure.name !== (interfaceDeclaration as ts.TypeParameterDeclaration).name.escapedText.toString()\n ) {\n // skip if property if for a another interface than the one we're interested in.\n break;\n }\n\n // define a property of an interface\n const property = new Property();\n property.name = (node as any).name.escapedText.toString();\n property.type = (node as any).type.getText();\n currentStructure.addProperty(property);\n }\n break;\n\n case ts.SyntaxKind.Identifier:\n if (\n node.getText() === \"deprecated\" &&\n node.parent.kind !== ts.SyntaxKind.ImportSpecifier\n ) {\n currentProperty = new Property();\n currentProperty.deprecated = true;\n break;\n }\n\n if (node.getText() === decoratorName) {\n const prop: any = node.parent?.parent?.parent;\n const propDecorator = getDecorators(prop);\n const hasExpression = prop?.expression?.arguments;\n const hasDecorator = (propDecorator?.length > 0);\n\n /**\n * neither a `@type()` decorator or `type()` call. skip.\n */\n if (!hasDecorator && !hasExpression) {\n break;\n }\n\n // using as decorator\n if (propDecorator) {\n /**\n * Calling `@type()` as decorator\n */\n const typeDecorator: any = propDecorator.find((decorator => {\n return (decorator.expression as any).expression.escapedText === decoratorName;\n })).expression;\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n const typeArgument = typeDecorator.arguments[0];\n defineProperty(property, typeArgument);\n\n } else if (\n prop.expression.arguments?.[1] &&\n prop.expression.expression.arguments?.[0]\n ) {\n /**\n * Calling `type()` as a regular method\n */\n const property = currentProperty || new Property();\n property.name = prop.expression.arguments[1].text;\n currentStructure.addProperty(property);\n\n const typeArgument = prop.expression.expression.arguments[0];\n defineProperty(property, typeArgument);\n }\n\n } else if (\n node.getText() === \"setFields\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * Metadata.setFields(klassName, { ... })\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n /**\n * Skip if @codegen-ignore comment is found before the call expression\n * TODO: currently, if @codegen-ignore is on the file, it will skip all the setFields calls.\n */\n const sourceFile = node.getSourceFile();\n const fullText = sourceFile.getFullText();\n const nodeStart = callExpression.getFullStart();\n const textBeforeNode = fullText.substring(0, nodeStart);\n if (textBeforeNode.includes('@codegen-ignore')) {\n break;\n }\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const classNameNode = callExpression.arguments[0];\n const className = ts.isClassExpression(classNameNode)\n ? classNameNode.name?.escapedText.toString()\n : classNameNode.getText();\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure?.name !== className) {\n currentStructure = new Class();\n }\n context.addStructure(currentStructure);\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n\n } else if (\n node.getText() === \"defineTypes\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * JavaScript source file (`.js`)\n * Using `defineTypes()`\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const className = callExpression.arguments[0].getText()\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n defineProperty(property, prop.initializer);\n }\n\n }\n\n if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {\n currentStructure.name = node.getText();\n }\n\n currentProperty = undefined;\n\n break;\n\n case ts.SyntaxKind.CallExpression:\n /**\n * Defining schema via `schema.schema({ ... })`\n * - schema.schema({})\n * - schema({})\n * - ClassName.extends({})\n */\n if (\n (\n (\n (node as ts.CallExpression).expression?.getText() === \"schema.schema\" ||\n (node as ts.CallExpression).expression?.getText() === \"schema\"\n ) ||\n (\n (node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1\n )\n ) &&\n (node as ts.CallExpression).arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression\n ) {\n const callExpression = node as ts.CallExpression;\n\n let className = callExpression.arguments[1]?.getText();\n\n if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {\n className = (callExpression.parent as ts.VariableDeclaration).name?.getText();\n }\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure?.name !== className) {\n currentStructure = new Class();\n context.addStructure(currentStructure);\n }\n\n if ((node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1) {\n // if it's using `.extends({})`\n const extendsClass = (node as any).expression?.expression?.escapedText;\n\n // skip if no extendsClass is provided\n if (!extendsClass) { break; }\n (currentStructure as Class).extends = extendsClass;\n\n } else {\n // if it's using `schema({})`\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n }\n\n currentStructure.name = className;\n\n const types = callExpression.arguments[0] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n }\n\n break;\n\n case ts.SyntaxKind.EnumMember:\n if (currentStructure instanceof Enum) {\n const initializer = (node as any).initializer?.text;\n const name = node.getFirstToken().getText();\n const property = currentProperty || new Property();\n property.name = name;\n if (initializer !== undefined) {\n property.type = initializer;\n }\n currentStructure.addProperty(property);\n currentProperty = undefined;\n }\n break;\n }\n\n ts.forEachChild(node, (n) => inspectNode(n, context, decoratorName));\n}\n\nlet parsedFiles: { [filename: string]: boolean };\n\nexport function parseFiles(\n fileNames: string[],\n decoratorName: string = \"type\",\n context: Context = new Context()\n) {\n /**\n * Re-set globalContext for each test case\n */\n if (globalContext !== context) {\n parsedFiles = {};\n globalContext = context;\n }\n\n fileNames.forEach((fileName) => {\n let sourceFile: ts.Node;\n let sourceFileName: string;\n\n const fileNameAlternatives = [];\n\n if (\n !fileName.endsWith(\".ts\") &&\n !fileName.endsWith(\".js\") &&\n !fileName.endsWith(\".mjs\")\n ) {\n fileNameAlternatives.push(`${fileName}.ts`);\n fileNameAlternatives.push(`${fileName}/index.ts`);\n\n } else {\n fileNameAlternatives.push(fileName);\n }\n\n for (let i = 0; i < fileNameAlternatives.length; i++) {\n try {\n sourceFileName = path.resolve(fileNameAlternatives[i]);\n\n if (parsedFiles[sourceFileName]) {\n break;\n }\n\n sourceFile = ts.createSourceFile(\n sourceFileName,\n readFileSync(sourceFileName).toString(),\n ts.ScriptTarget.Latest,\n true\n );\n\n parsedFiles[sourceFileName] = true;\n\n break;\n } catch (e) {\n // console.log(`${fileNameAlternatives[i]} => ${e.message}`);\n }\n }\n\n if (sourceFile) {\n inspectNode(sourceFile, context, decoratorName);\n }\n });\n\n return context.getStructures();\n}\n\n/**\n * TypeScript 4.8+ has introduced a change on how to access decorators.\n * - https://github.com/microsoft/TypeScript/pull/49089\n * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees\n */\nexport function getDecorators(node: ts.Node | null | undefined,): undefined | ts.Decorator[] {\n if (node == undefined) { return undefined; }\n\n // TypeScript 4.7 and below\n // @ts-ignore\n if (node.decorators) { return node.decorators; }\n\n // TypeScript 4.8 and above\n // @ts-ignore\n if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {\n // @ts-ignore\n const decorators = ts.getDecorators(node);\n return decorators ? Array.from(decorators) : undefined;\n }\n\n // @ts-ignore\n return node.modifiers?.filter(ts.isDecorator);\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2018 Endel Dreyer
|
|
3
|
+
* Copyright (c) 2014 Ion Drive Software Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* msgpack implementation highly based on notepack.io
|
|
25
|
+
* https://github.com/darrachequesne/notepack
|
|
26
|
+
*/
|
|
27
|
+
export interface Iterator {
|
|
28
|
+
offset: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function int8(bytes: number[], it: Iterator): number;
|
|
31
|
+
export declare function uint8(bytes: number[], it: Iterator): number;
|
|
32
|
+
export declare function int16(bytes: number[], it: Iterator): number;
|
|
33
|
+
export declare function uint16(bytes: number[], it: Iterator): number;
|
|
34
|
+
export declare function int32(bytes: number[], it: Iterator): number;
|
|
35
|
+
export declare function uint32(bytes: number[], it: Iterator): number;
|
|
36
|
+
export declare function float32(bytes: number[], it: Iterator): number;
|
|
37
|
+
export declare function float64(bytes: number[], it: Iterator): number;
|
|
38
|
+
export declare function int64(bytes: number[], it: Iterator): number;
|
|
39
|
+
export declare function uint64(bytes: number[], it: Iterator): number;
|
|
40
|
+
export declare function readFloat32(bytes: number[], it: Iterator): number;
|
|
41
|
+
export declare function readFloat64(bytes: number[], it: Iterator): number;
|
|
42
|
+
export declare function boolean(bytes: number[], it: Iterator): boolean;
|
|
43
|
+
export declare function string(bytes: any, it: Iterator): string;
|
|
44
|
+
export declare function stringCheck(bytes: any, it: Iterator): boolean;
|
|
45
|
+
export declare function number(bytes: any, it: Iterator): any;
|
|
46
|
+
export declare function numberCheck(bytes: any, it: Iterator): boolean;
|
|
47
|
+
export declare function arrayCheck(bytes: any, it: Iterator): boolean;
|
|
48
|
+
export declare function switchStructureCheck(bytes: any, it: Iterator): boolean;
|