@colyseus/schema 3.0.76 → 4.0.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/build/cjs/index.js +781 -434
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +779 -435
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +781 -434
- package/lib/Metadata.js +1 -5
- package/lib/Metadata.js.map +1 -1
- package/lib/Reflection.d.ts +50 -17
- package/lib/Reflection.js +151 -202
- package/lib/Reflection.js.map +1 -1
- package/lib/Schema.d.ts +13 -1
- package/lib/Schema.js +73 -9
- package/lib/Schema.js.map +1 -1
- package/lib/annotations.d.ts +6 -1
- package/lib/annotations.js +8 -34
- package/lib/annotations.js.map +1 -1
- package/lib/bench_encode.js +34 -1
- package/lib/bench_encode.js.map +1 -1
- package/lib/codegen/api.js +35 -2
- package/lib/codegen/api.js.map +1 -1
- package/lib/codegen/cli.js +4 -1
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/parser.js +35 -2
- package/lib/codegen/parser.js.map +1 -1
- package/lib/codegen/types.js +34 -1
- package/lib/codegen/types.js.map +1 -1
- package/lib/decoder/DecodeOperation.d.ts +2 -2
- package/lib/decoder/DecodeOperation.js +3 -3
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/decoder/Decoder.d.ts +3 -3
- package/lib/decoder/Decoder.js +2 -2
- package/lib/decoder/Decoder.js.map +1 -1
- package/lib/decoder/ReferenceTracker.d.ts +0 -1
- package/lib/decoder/ReferenceTracker.js +9 -7
- package/lib/decoder/ReferenceTracker.js.map +1 -1
- package/lib/decoder/strategy/Callbacks.d.ts +154 -0
- package/lib/decoder/strategy/Callbacks.js +340 -0
- package/lib/decoder/strategy/Callbacks.js.map +1 -0
- package/lib/decoder/strategy/{StateCallbacks.d.ts → getDecoderStateCallbacks.d.ts} +6 -0
- package/lib/decoder/strategy/{StateCallbacks.js → getDecoderStateCallbacks.js} +17 -10
- package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +1 -0
- package/lib/encoder/ChangeTree.d.ts +2 -2
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/EncodeOperation.d.ts +2 -2
- package/lib/encoder/EncodeOperation.js +3 -3
- package/lib/encoder/EncodeOperation.js.map +1 -1
- package/lib/encoder/Encoder.d.ts +6 -6
- package/lib/encoder/Encoder.js +19 -18
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoder/Root.js +17 -14
- package/lib/encoder/Root.js.map +1 -1
- package/lib/encoder/StateView.js +13 -12
- package/lib/encoder/StateView.js.map +1 -1
- package/lib/encoding/decode.d.ts +2 -2
- package/lib/encoding/encode.d.ts +3 -1
- package/lib/encoding/encode.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.js +7 -3
- package/lib/index.js.map +1 -1
- package/lib/types/HelperTypes.d.ts +7 -14
- package/lib/types/HelperTypes.js.map +1 -1
- package/lib/types/custom/ArraySchema.d.ts +2 -1
- package/lib/types/custom/ArraySchema.js.map +1 -1
- package/lib/types/custom/CollectionSchema.d.ts +2 -1
- package/lib/types/custom/CollectionSchema.js.map +1 -1
- package/lib/types/custom/MapSchema.d.ts +3 -2
- package/lib/types/custom/MapSchema.js.map +1 -1
- package/lib/types/custom/SetSchema.d.ts +2 -1
- package/lib/types/custom/SetSchema.js.map +1 -1
- package/lib/types/symbols.d.ts +1 -0
- package/lib/types/symbols.js +2 -1
- package/lib/types/symbols.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +12 -16
- package/src/Metadata.ts +1 -5
- package/src/Reflection.ts +185 -174
- package/src/Schema.ts +81 -13
- package/src/annotations.ts +14 -40
- package/src/codegen/parser.ts +1 -1
- package/src/decoder/DecodeOperation.ts +9 -9
- package/src/decoder/Decoder.ts +6 -6
- package/src/decoder/ReferenceTracker.ts +10 -8
- package/src/decoder/strategy/Callbacks.ts +547 -0
- package/src/decoder/strategy/{StateCallbacks.ts → getDecoderStateCallbacks.ts} +17 -11
- package/src/encoder/ChangeTree.ts +4 -7
- package/src/encoder/EncodeOperation.ts +9 -9
- package/src/encoder/Encoder.ts +26 -18
- package/src/encoder/Root.ts +20 -15
- package/src/encoder/StateView.ts +15 -13
- package/src/encoding/encode.ts +1 -1
- package/src/index.ts +3 -2
- package/src/types/HelperTypes.ts +13 -11
- package/src/types/custom/ArraySchema.ts +2 -1
- package/src/types/custom/CollectionSchema.ts +4 -2
- package/src/types/custom/MapSchema.ts +4 -2
- package/src/types/custom/SetSchema.ts +3 -1
- package/src/types/symbols.ts +1 -0
- package/src/utils.ts +2 -2
- package/lib/Decoder.d.ts +0 -16
- package/lib/Decoder.js +0 -182
- package/lib/Decoder.js.map +0 -1
- package/lib/Encoder.d.ts +0 -13
- package/lib/Encoder.js +0 -79
- package/lib/Encoder.js.map +0 -1
- package/lib/changes/ChangeSet.d.ts +0 -12
- package/lib/changes/ChangeSet.js +0 -35
- package/lib/changes/ChangeSet.js.map +0 -1
- package/lib/changes/ChangeTree.d.ts +0 -53
- package/lib/changes/ChangeTree.js +0 -202
- package/lib/changes/ChangeTree.js.map +0 -1
- package/lib/changes/DecodeOperation.d.ts +0 -15
- package/lib/changes/DecodeOperation.js +0 -186
- package/lib/changes/DecodeOperation.js.map +0 -1
- package/lib/changes/EncodeOperation.d.ts +0 -18
- package/lib/changes/EncodeOperation.js +0 -130
- package/lib/changes/EncodeOperation.js.map +0 -1
- package/lib/changes/ReferenceTracker.d.ts +0 -14
- package/lib/changes/ReferenceTracker.js +0 -83
- package/lib/changes/ReferenceTracker.js.map +0 -1
- package/lib/changes/consts.d.ts +0 -14
- package/lib/changes/consts.js +0 -18
- package/lib/changes/consts.js.map +0 -1
- package/lib/decoder/strategy/StateCallbacks.js.map +0 -1
- package/lib/decoding/decode.d.ts +0 -48
- package/lib/decoding/decode.js +0 -267
- package/lib/decoding/decode.js.map +0 -1
- package/lib/ecs.d.ts +0 -11
- package/lib/ecs.js +0 -160
- package/lib/ecs.js.map +0 -1
- package/lib/filters/index.d.ts +0 -8
- package/lib/filters/index.js +0 -24
- package/lib/filters/index.js.map +0 -1
- package/lib/spec.d.ts +0 -13
- package/lib/spec.js +0 -42
- package/lib/spec.js.map +0 -1
- package/lib/types/ArraySchema.d.ts +0 -238
- package/lib/types/ArraySchema.js +0 -555
- package/lib/types/ArraySchema.js.map +0 -1
- package/lib/types/CollectionSchema.d.ts +0 -35
- package/lib/types/CollectionSchema.js +0 -150
- package/lib/types/CollectionSchema.js.map +0 -1
- package/lib/types/MapSchema.d.ts +0 -38
- package/lib/types/MapSchema.js +0 -215
- package/lib/types/MapSchema.js.map +0 -1
- package/lib/types/SetSchema.d.ts +0 -32
- package/lib/types/SetSchema.js +0 -162
- package/lib/types/SetSchema.js.map +0 -1
- package/lib/types/typeRegistry.d.ts +0 -5
- package/lib/types/typeRegistry.js +0 -13
- package/lib/types/typeRegistry.js.map +0 -1
- package/lib/usage.d.ts +0 -1
- package/lib/usage.js +0 -22
- package/lib/usage.js.map +0 -1
- package/lib/v3.d.ts +0 -1
- package/lib/v3.js +0 -427
- package/lib/v3.js.map +0 -1
- package/lib/v3_experiment.d.ts +0 -1
- package/lib/v3_experiment.js +0 -407
- package/lib/v3_experiment.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StateCallbacks.js","sourceRoot":"","sources":["../../../src/decoder/strategy/StateCallbacks.ts"],"names":[],"mappings":";;AA8GA,4DAsUC;AA/aD,8CAAgD;AAChD,yCAAsC;AAwGtC,SAAgB,wBAAwB,CAAmB,OAAmB;IAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;IAElC,MAAM,UAAU,GAA+B,IAAI,OAAO,EAAE,CAAC;IAC7D,IAAI,oBAA0C,CAAC;IAE/C,OAAO,CAAC,cAAc,GAAG,UAAU,UAAwB;QACvD,MAAM,YAAY,GAAG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GAAG,CAAC,MAAM,EAAE,IAAI,IAAI,OAAO,MAAM,CAAC,IAA2B,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;gBAC/E,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;gBAClD,cAAc,CAAC,CAAC,EAAE,EAAE,IAAI,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;aAC5D,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,SAAS,CAAC,CAAI,QAAW;QACrB,OAAO,QAAQ,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,CAAgC,CAAC;IAC5E,CAAC;IAED,OAAO,CAAC,CAAC;AACb,CAAC","sourcesContent":["import { Metadata } from \"../../Metadata\";\nimport { Collection, NonFunctionNonPrimitivePropNames, NonFunctionPropNames } from \"../../types/HelperTypes\";\nimport { Ref } from \"../../encoder/ChangeTree\";\nimport { Decoder } from \"../Decoder\";\nimport { DataChange } from \"../DecodeOperation\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { Schema } from \"../../Schema\";\nimport type { DefinitionType } from \"../../annotations\";\nimport type { CollectionSchema } from \"../../types/custom/CollectionSchema\";\n\n//\n// Discussion: https://github.com/colyseus/schema/issues/155\n//\n// Main points:\n// - Decouple structures from their callbacks.\n// - Registering deep callbacks can be confusing.\n// - Avoid closures by allowing to pass a context. (https://github.com/colyseus/schema/issues/155#issuecomment-1804694081)\n//\n\n/**\n * TODO: define a schema interface, which even having duplicate definitions, it could be used to get the callback proxy.\n *\n * ```ts\n * export type SchemaCallbackProxy<RoomState> = (<T extends Schema>(instance: T) => CallbackProxy<T>);\n * ```\n */\nexport type SchemaCallbackProxy<RoomState> = (<T>(instance: T) => CallbackProxy<T>);\nexport type GetCallbackProxy = SchemaCallbackProxy<any>; // workaround for compatibility for < colyseus.js0.16.6. Remove me on next major release.\n\nexport type CallbackProxy<T> = unknown extends T // is \"any\"?\n ? SchemaCallback<T> & CollectionCallback<any, any>\n : T extends Collection<infer K, infer V, infer _>\n ? CollectionCallback<K, V>\n : SchemaCallback<T>;\n\nexport type SchemaCallback<T> = {\n /**\n * Trigger callback when value of a property changes.\n *\n * @param prop name of the property\n * @param callback callback to be triggered on property change\n * @param immediate trigger immediatelly if property has been already set.\n * @return callback to detach the listener\n */\n listen<K extends NonFunctionPropNames<T>>(\n prop: K,\n callback: (value: T[K], previousValue: T[K]) => void,\n immediate?: boolean,\n ): () => void;\n\n /**\n * Trigger callback whenever any property changed within this instance.\n *\n * @param prop name of the property\n * @param callback callback to be triggered on property change\n * @param immediate trigger immediatelly if property has been already set.\n * @return callback to detach the listener\n */\n onChange(callback: () => void): () => void;\n\n /**\n * Bind properties to another object. Changes on the properties will be reflected on the target object.\n *\n * @param targetObject object to bind properties to\n * @param properties list of properties to bind. If not provided, all properties will be bound.\n */\n bindTo(targetObject: any, properties?: Array<NonFunctionPropNames<T>>): void;\n} & {\n [K in NonFunctionNonPrimitivePropNames<T>]: CallbackProxy<T[K]>;\n}\n\nexport type CollectionCallback<K, V> = {\n /**\n * Trigger callback when an item has been added to the collection.\n *\n * @param callback\n * @param immediate\n * @return callback to detach the onAdd listener\n */\n onAdd(callback: (item: V, index: K) => void, immediate?: boolean): () => void;\n\n /**\n * Trigger callback when an item has been removed to the collection.\n *\n * @param callback\n * @return callback to detach the onRemove listener\n */\n onRemove(callback: (item: V, index: K) => void): () => void;\n\n /**\n * Trigger callback when the value on a key has changed.\n *\n * THIS METHOD IS NOT RECURSIVE!\n * If you want to listen to changes on individual items, you need to attach callbacks to the them directly inside the `onAdd` callback.\n *\n * @param callback\n * @return callback to detach the onChange listener\n */\n onChange(callback: (item: V, index: K) => void): () => void;\n};\n\ntype OnInstanceAvailableCallback = (callback: (ref: Ref, existing: boolean) => void) => void;\n\ntype CallContext = {\n instance?: any,\n parentInstance?: any,\n onInstanceAvailable?: OnInstanceAvailableCallback,\n}\n\n\nexport function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>): SchemaCallbackProxy<T> {\n const $root = decoder.root;\n const callbacks = $root.callbacks;\n\n const onAddCalls: WeakMap<Function, boolean> = new WeakMap();\n let currentOnAddCallback: Function | undefined;\n\n decoder.triggerChanges = function (allChanges: DataChange[]) {\n const uniqueRefIds = new Set<number>();\n\n for (let i = 0, l = allChanges.length; i < l; i++) {\n const change = allChanges[i];\n const refId = change.refId;\n const ref = change.ref;\n const $callbacks = callbacks[refId];\n\n if (!$callbacks) { continue; }\n\n //\n // trigger onRemove on child structure.\n //\n if (\n (change.op & OPERATION.DELETE) === OPERATION.DELETE &&\n change.previousValue instanceof Schema\n ) {\n const deleteCallbacks = callbacks[$root.refIds.get(change.previousValue)]?.[OPERATION.DELETE];\n for (let i = deleteCallbacks?.length - 1; i >= 0; i--) {\n deleteCallbacks[i]();\n }\n }\n\n if (ref instanceof Schema) {\n //\n // Handle schema instance\n //\n\n if (!uniqueRefIds.has(refId)) {\n // trigger onChange\n const replaceCallbacks = $callbacks?.[OPERATION.REPLACE];\n for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {\n replaceCallbacks[i]();\n // try {\n // } catch (e) {\n // console.error(e);\n // }\n }\n }\n\n if ($callbacks.hasOwnProperty(change.field)) {\n const fieldCallbacks = $callbacks[change.field];\n for (let i = fieldCallbacks?.length - 1; i >= 0; i--) {\n fieldCallbacks[i](change.value, change.previousValue);\n // try {\n // } catch (e) {\n // console.error(e);\n // }\n }\n }\n\n\n } else {\n //\n // Handle collection of items\n //\n\n if ((change.op & OPERATION.DELETE) === OPERATION.DELETE) {\n //\n // FIXME: `previousValue` should always be available.\n //\n if (change.previousValue !== undefined) {\n // triger onRemove\n const deleteCallbacks = $callbacks[OPERATION.DELETE];\n for (let i = deleteCallbacks?.length - 1; i >= 0; i--) {\n deleteCallbacks[i](change.previousValue, change.dynamicIndex ?? change.field);\n }\n }\n\n // Handle DELETE_AND_ADD operations\n if ((change.op & OPERATION.ADD) === OPERATION.ADD) {\n const addCallbacks = $callbacks[OPERATION.ADD];\n for (let i = addCallbacks?.length - 1; i >= 0; i--) {\n addCallbacks[i](change.value, change.dynamicIndex ?? change.field);\n }\n }\n\n } else if (\n (change.op & OPERATION.ADD) === OPERATION.ADD &&\n change.previousValue !== change.value\n ) {\n // triger onAdd\n const addCallbacks = $callbacks[OPERATION.ADD];\n for (let i = addCallbacks?.length - 1; i >= 0; i--) {\n addCallbacks[i](change.value, change.dynamicIndex ?? change.field);\n }\n }\n\n // trigger onChange\n if (\n change.value !== change.previousValue &&\n // FIXME: see \"should not encode item if added and removed at the same patch\" test case.\n // some \"ADD\" + \"DELETE\" operations on same patch are being encoded as \"DELETE\"\n (change.value !== undefined || change.previousValue !== undefined)\n ) {\n const replaceCallbacks = $callbacks[OPERATION.REPLACE];\n for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {\n replaceCallbacks[i](change.value, change.dynamicIndex ?? change.field);\n }\n }\n }\n\n uniqueRefIds.add(refId);\n }\n };\n\n function getProxy(\n metadataOrType: Metadata | DefinitionType,\n context: CallContext\n ) {\n let metadata: Metadata = context.instance?.constructor[Symbol.metadata] || metadataOrType;\n let isCollection = (\n (context.instance && typeof (context.instance['forEach']) === \"function\") ||\n (metadataOrType && typeof ((metadataOrType as typeof Schema)[Symbol.metadata]) === \"undefined\")\n );\n\n if (metadata && !isCollection) {\n\n const onAddListen = function (\n ref: Ref,\n prop: string,\n callback: (value: any, previousValue: any) => void, immediate: boolean\n ) {\n // immediate trigger\n if (\n immediate &&\n context.instance[prop] !== undefined &&\n !onAddCalls.has(currentOnAddCallback) // Workaround for https://github.com/colyseus/schema/issues/147\n ) {\n callback(context.instance[prop], undefined);\n }\n return $root.addCallback($root.refIds.get(ref), prop, callback);\n }\n\n /**\n * Schema instances\n */\n return new Proxy({\n listen: function listen(prop: string, callback: (value: any, previousValue: any) => void, immediate: boolean = true) {\n if (context.instance) {\n return onAddListen(context.instance, prop, callback, immediate);\n\n } else {\n // collection instance not received yet\n let detachCallback = () => {};\n\n context.onInstanceAvailable((ref: Ref, existing: boolean) => {\n detachCallback = onAddListen(ref, prop, callback, immediate && existing && !onAddCalls.has(currentOnAddCallback))\n });\n\n return () => detachCallback();\n }\n },\n\n onChange: function onChange(callback: () => void) {\n return $root.addCallback(\n $root.refIds.get(context.instance),\n OPERATION.REPLACE,\n callback\n );\n },\n\n //\n // TODO: refactor `bindTo()` implementation.\n // There is room for improvement.\n //\n bindTo: function bindTo(targetObject: any, properties?: string[]) {\n if (!properties) {\n properties = Object.keys(metadata).map((index) => metadata[index as any as number].name);\n }\n return $root.addCallback(\n $root.refIds.get(context.instance),\n OPERATION.REPLACE,\n () => {\n properties.forEach((prop) =>\n targetObject[prop] = context.instance[prop])\n }\n );\n }\n }, {\n get(target, prop: string) {\n const metadataField = metadata[metadata[prop]];\n if (metadataField) {\n const instance = context.instance?.[prop];\n const onInstanceAvailable: OnInstanceAvailableCallback = (\n (callback: (ref: Ref, existing: boolean) => void) => {\n const unbind = $(context.instance).listen(prop, (value, _) => {\n callback(value, false);\n\n // FIXME: by \"unbinding\" the callback here,\n // it will not support when the server\n // re-instantiates the instance.\n //\n unbind?.();\n }, false);\n\n // has existing value\n if ($root.refIds.get(instance) !== undefined) {\n callback(instance, true);\n }\n }\n );\n\n return getProxy(metadataField.type, {\n // make sure refId is available, otherwise need to wait for the instance to be available.\n instance: ($root.refIds.get(instance) && instance),\n parentInstance: context.instance,\n onInstanceAvailable,\n });\n\n } else {\n // accessing the function\n return target[prop as keyof typeof target];\n }\n },\n has(target, prop: string) { return metadata[prop] !== undefined; },\n set(_, _1, _2) { throw new Error(\"not allowed\"); },\n deleteProperty(_, _1) { throw new Error(\"not allowed\"); },\n });\n\n } else {\n /**\n * Collection instances\n */\n\n const onAdd = function (ref: Ref, callback: (value: any, key: any) => void, immediate: boolean) {\n // Trigger callback on existing items\n if (immediate) {\n (ref as CollectionSchema).forEach((v, k) => callback(v, k));\n }\n\n return $root.addCallback($root.refIds.get(ref), OPERATION.ADD, (value: any, key: any) => {\n onAddCalls.set(callback, true);\n currentOnAddCallback = callback;\n callback(value, key);\n onAddCalls.delete(callback)\n currentOnAddCallback = undefined;\n });\n };\n\n const onRemove = function (ref: Ref, callback: (value: any, key: any) => void) {\n return $root.addCallback($root.refIds.get(ref), OPERATION.DELETE, callback);\n };\n\n const onChange = function (ref: Ref, callback: (value: any, key: any) => void) {\n return $root.addCallback($root.refIds.get(ref), OPERATION.REPLACE, callback);\n };\n\n return new Proxy({\n onAdd: function(callback: (value: any, key: any) => void, immediate: boolean = true) {\n //\n // https://github.com/colyseus/schema/issues/147\n // If parent instance has \"onAdd\" registered, avoid triggering immediate callback.\n //\n\n if (context.instance) {\n return onAdd(context.instance, callback, immediate && !onAddCalls.has(currentOnAddCallback));\n\n } else if (context.onInstanceAvailable) {\n // collection instance not received yet\n let detachCallback = () => {};\n\n context.onInstanceAvailable((ref: Ref, existing: boolean) => {\n detachCallback = onAdd(ref, callback, immediate && existing && !onAddCalls.has(currentOnAddCallback));\n });\n\n return () => detachCallback();\n }\n },\n onRemove: function(callback: (value: any, key: any) => void) {\n if (context.instance) {\n return onRemove(context.instance, callback);\n\n } else if (context.onInstanceAvailable) {\n // collection instance not received yet\n let detachCallback = () => {};\n\n context.onInstanceAvailable((ref: Ref) => {\n detachCallback = onRemove(ref, callback)\n });\n\n return () => detachCallback();\n }\n },\n onChange: function(callback: (value: any, key: any) => void) {\n if (context.instance) {\n return onChange(context.instance, callback);\n\n } else if (context.onInstanceAvailable) {\n // collection instance not received yet\n let detachCallback = () => {};\n\n context.onInstanceAvailable((ref: Ref) => {\n detachCallback = onChange(ref, callback)\n });\n\n return () => detachCallback();\n }\n },\n }, {\n get(target, prop: string) {\n if (!target[prop as keyof typeof target]) {\n throw new Error(`Can't access '${prop}' through callback proxy. access the instance directly.`);\n }\n return target[prop as keyof typeof target];\n },\n has(target, prop) { return target[prop as keyof typeof target] !== undefined; },\n set(_, _1, _2) { throw new Error(\"not allowed\"); },\n deleteProperty(_, _1) { throw new Error(\"not allowed\"); },\n });\n }\n }\n\n function $<T>(instance: T): CallbackProxy<T> {\n return getProxy(undefined, { instance }) as unknown as CallbackProxy<T>;\n }\n\n return $;\n}\n"]}
|
package/lib/decoding/decode.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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;
|
package/lib/decoding/decode.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2018 Endel Dreyer
|
|
4
|
-
* Copyright (c) 2014 Ion Drive Software Ltd.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.switchStructureCheck = exports.arrayCheck = exports.numberCheck = exports.number = exports.stringCheck = exports.string = exports.boolean = exports.readFloat64 = exports.readFloat32 = exports.uint64 = exports.int64 = exports.float64 = exports.float32 = exports.uint32 = exports.int32 = exports.uint16 = exports.int16 = exports.uint8 = exports.int8 = void 0;
|
|
26
|
-
const spec_1 = require("../spec");
|
|
27
|
-
function utf8Read(bytes, offset, length) {
|
|
28
|
-
var string = '', chr = 0;
|
|
29
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
30
|
-
var byte = bytes[i];
|
|
31
|
-
if ((byte & 0x80) === 0x00) {
|
|
32
|
-
string += String.fromCharCode(byte);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if ((byte & 0xe0) === 0xc0) {
|
|
36
|
-
string += String.fromCharCode(((byte & 0x1f) << 6) |
|
|
37
|
-
(bytes[++i] & 0x3f));
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if ((byte & 0xf0) === 0xe0) {
|
|
41
|
-
string += String.fromCharCode(((byte & 0x0f) << 12) |
|
|
42
|
-
((bytes[++i] & 0x3f) << 6) |
|
|
43
|
-
((bytes[++i] & 0x3f) << 0));
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if ((byte & 0xf8) === 0xf0) {
|
|
47
|
-
chr = ((byte & 0x07) << 18) |
|
|
48
|
-
((bytes[++i] & 0x3f) << 12) |
|
|
49
|
-
((bytes[++i] & 0x3f) << 6) |
|
|
50
|
-
((bytes[++i] & 0x3f) << 0);
|
|
51
|
-
if (chr >= 0x010000) { // surrogate pair
|
|
52
|
-
chr -= 0x010000;
|
|
53
|
-
string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
string += String.fromCharCode(chr);
|
|
57
|
-
}
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
console.error('Invalid byte ' + byte.toString(16));
|
|
61
|
-
// (do not throw error to avoid server/client from crashing due to hack attemps)
|
|
62
|
-
// throw new Error('Invalid byte ' + byte.toString(16));
|
|
63
|
-
}
|
|
64
|
-
return string;
|
|
65
|
-
}
|
|
66
|
-
function int8(bytes, it) {
|
|
67
|
-
return uint8(bytes, it) << 24 >> 24;
|
|
68
|
-
}
|
|
69
|
-
exports.int8 = int8;
|
|
70
|
-
;
|
|
71
|
-
function uint8(bytes, it) {
|
|
72
|
-
return bytes[it.offset++];
|
|
73
|
-
}
|
|
74
|
-
exports.uint8 = uint8;
|
|
75
|
-
;
|
|
76
|
-
function int16(bytes, it) {
|
|
77
|
-
return uint16(bytes, it) << 16 >> 16;
|
|
78
|
-
}
|
|
79
|
-
exports.int16 = int16;
|
|
80
|
-
;
|
|
81
|
-
function uint16(bytes, it) {
|
|
82
|
-
return bytes[it.offset++] | bytes[it.offset++] << 8;
|
|
83
|
-
}
|
|
84
|
-
exports.uint16 = uint16;
|
|
85
|
-
;
|
|
86
|
-
function int32(bytes, it) {
|
|
87
|
-
return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;
|
|
88
|
-
}
|
|
89
|
-
exports.int32 = int32;
|
|
90
|
-
;
|
|
91
|
-
function uint32(bytes, it) {
|
|
92
|
-
return int32(bytes, it) >>> 0;
|
|
93
|
-
}
|
|
94
|
-
exports.uint32 = uint32;
|
|
95
|
-
;
|
|
96
|
-
function float32(bytes, it) {
|
|
97
|
-
return readFloat32(bytes, it);
|
|
98
|
-
}
|
|
99
|
-
exports.float32 = float32;
|
|
100
|
-
function float64(bytes, it) {
|
|
101
|
-
return readFloat64(bytes, it);
|
|
102
|
-
}
|
|
103
|
-
exports.float64 = float64;
|
|
104
|
-
function int64(bytes, it) {
|
|
105
|
-
const low = uint32(bytes, it);
|
|
106
|
-
const high = int32(bytes, it) * Math.pow(2, 32);
|
|
107
|
-
return high + low;
|
|
108
|
-
}
|
|
109
|
-
exports.int64 = int64;
|
|
110
|
-
;
|
|
111
|
-
function uint64(bytes, it) {
|
|
112
|
-
const low = uint32(bytes, it);
|
|
113
|
-
const high = uint32(bytes, it) * Math.pow(2, 32);
|
|
114
|
-
return high + low;
|
|
115
|
-
}
|
|
116
|
-
exports.uint64 = uint64;
|
|
117
|
-
;
|
|
118
|
-
// force little endian to facilitate decoding on multiple implementations
|
|
119
|
-
const _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
|
|
120
|
-
const _int32 = new Int32Array(2);
|
|
121
|
-
const _float32 = new Float32Array(_int32.buffer);
|
|
122
|
-
const _float64 = new Float64Array(_int32.buffer);
|
|
123
|
-
function readFloat32(bytes, it) {
|
|
124
|
-
_int32[0] = int32(bytes, it);
|
|
125
|
-
return _float32[0];
|
|
126
|
-
}
|
|
127
|
-
exports.readFloat32 = readFloat32;
|
|
128
|
-
;
|
|
129
|
-
function readFloat64(bytes, it) {
|
|
130
|
-
_int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);
|
|
131
|
-
_int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);
|
|
132
|
-
return _float64[0];
|
|
133
|
-
}
|
|
134
|
-
exports.readFloat64 = readFloat64;
|
|
135
|
-
;
|
|
136
|
-
function boolean(bytes, it) {
|
|
137
|
-
return uint8(bytes, it) > 0;
|
|
138
|
-
}
|
|
139
|
-
exports.boolean = boolean;
|
|
140
|
-
;
|
|
141
|
-
function string(bytes, it) {
|
|
142
|
-
const prefix = bytes[it.offset++];
|
|
143
|
-
let length;
|
|
144
|
-
if (prefix < 0xc0) {
|
|
145
|
-
// fixstr
|
|
146
|
-
length = prefix & 0x1f;
|
|
147
|
-
}
|
|
148
|
-
else if (prefix === 0xd9) {
|
|
149
|
-
length = uint8(bytes, it);
|
|
150
|
-
}
|
|
151
|
-
else if (prefix === 0xda) {
|
|
152
|
-
length = uint16(bytes, it);
|
|
153
|
-
}
|
|
154
|
-
else if (prefix === 0xdb) {
|
|
155
|
-
length = uint32(bytes, it);
|
|
156
|
-
}
|
|
157
|
-
const value = utf8Read(bytes, it.offset, length);
|
|
158
|
-
it.offset += length;
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
exports.string = string;
|
|
162
|
-
function stringCheck(bytes, it) {
|
|
163
|
-
const prefix = bytes[it.offset];
|
|
164
|
-
return (
|
|
165
|
-
// fixstr
|
|
166
|
-
(prefix < 0xc0 && prefix > 0xa0) ||
|
|
167
|
-
// str 8
|
|
168
|
-
prefix === 0xd9 ||
|
|
169
|
-
// str 16
|
|
170
|
-
prefix === 0xda ||
|
|
171
|
-
// str 32
|
|
172
|
-
prefix === 0xdb);
|
|
173
|
-
}
|
|
174
|
-
exports.stringCheck = stringCheck;
|
|
175
|
-
function number(bytes, it) {
|
|
176
|
-
const prefix = bytes[it.offset++];
|
|
177
|
-
if (prefix < 0x80) {
|
|
178
|
-
// positive fixint
|
|
179
|
-
return prefix;
|
|
180
|
-
}
|
|
181
|
-
else if (prefix === 0xca) {
|
|
182
|
-
// float 32
|
|
183
|
-
return readFloat32(bytes, it);
|
|
184
|
-
}
|
|
185
|
-
else if (prefix === 0xcb) {
|
|
186
|
-
// float 64
|
|
187
|
-
return readFloat64(bytes, it);
|
|
188
|
-
}
|
|
189
|
-
else if (prefix === 0xcc) {
|
|
190
|
-
// uint 8
|
|
191
|
-
return uint8(bytes, it);
|
|
192
|
-
}
|
|
193
|
-
else if (prefix === 0xcd) {
|
|
194
|
-
// uint 16
|
|
195
|
-
return uint16(bytes, it);
|
|
196
|
-
}
|
|
197
|
-
else if (prefix === 0xce) {
|
|
198
|
-
// uint 32
|
|
199
|
-
return uint32(bytes, it);
|
|
200
|
-
}
|
|
201
|
-
else if (prefix === 0xcf) {
|
|
202
|
-
// uint 64
|
|
203
|
-
return uint64(bytes, it);
|
|
204
|
-
}
|
|
205
|
-
else if (prefix === 0xd0) {
|
|
206
|
-
// int 8
|
|
207
|
-
return int8(bytes, it);
|
|
208
|
-
}
|
|
209
|
-
else if (prefix === 0xd1) {
|
|
210
|
-
// int 16
|
|
211
|
-
return int16(bytes, it);
|
|
212
|
-
}
|
|
213
|
-
else if (prefix === 0xd2) {
|
|
214
|
-
// int 32
|
|
215
|
-
return int32(bytes, it);
|
|
216
|
-
}
|
|
217
|
-
else if (prefix === 0xd3) {
|
|
218
|
-
// int 64
|
|
219
|
-
return int64(bytes, it);
|
|
220
|
-
}
|
|
221
|
-
else if (prefix > 0xdf) {
|
|
222
|
-
// negative fixint
|
|
223
|
-
return (0xff - prefix + 1) * -1;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.number = number;
|
|
227
|
-
;
|
|
228
|
-
function numberCheck(bytes, it) {
|
|
229
|
-
const prefix = bytes[it.offset];
|
|
230
|
-
// positive fixint - 0x00 - 0x7f
|
|
231
|
-
// float 32 - 0xca
|
|
232
|
-
// float 64 - 0xcb
|
|
233
|
-
// uint 8 - 0xcc
|
|
234
|
-
// uint 16 - 0xcd
|
|
235
|
-
// uint 32 - 0xce
|
|
236
|
-
// uint 64 - 0xcf
|
|
237
|
-
// int 8 - 0xd0
|
|
238
|
-
// int 16 - 0xd1
|
|
239
|
-
// int 32 - 0xd2
|
|
240
|
-
// int 64 - 0xd3
|
|
241
|
-
return (prefix < 0x80 ||
|
|
242
|
-
(prefix >= 0xca && prefix <= 0xd3));
|
|
243
|
-
}
|
|
244
|
-
exports.numberCheck = numberCheck;
|
|
245
|
-
function arrayCheck(bytes, it) {
|
|
246
|
-
return bytes[it.offset] < 0xa0;
|
|
247
|
-
// const prefix = bytes[it.offset] ;
|
|
248
|
-
// if (prefix < 0xa0) {
|
|
249
|
-
// return prefix;
|
|
250
|
-
// // array
|
|
251
|
-
// } else if (prefix === 0xdc) {
|
|
252
|
-
// it.offset += 2;
|
|
253
|
-
// } else if (0xdd) {
|
|
254
|
-
// it.offset += 4;
|
|
255
|
-
// }
|
|
256
|
-
// return prefix;
|
|
257
|
-
}
|
|
258
|
-
exports.arrayCheck = arrayCheck;
|
|
259
|
-
function switchStructureCheck(bytes, it) {
|
|
260
|
-
return (
|
|
261
|
-
// previous byte should be `SWITCH_TO_STRUCTURE`
|
|
262
|
-
bytes[it.offset - 1] === spec_1.SWITCH_TO_STRUCTURE &&
|
|
263
|
-
// next byte should be a number
|
|
264
|
-
(bytes[it.offset] < 0x80 || (bytes[it.offset] >= 0xca && bytes[it.offset] <= 0xd3)));
|
|
265
|
-
}
|
|
266
|
-
exports.switchStructureCheck = switchStructureCheck;
|
|
267
|
-
//# sourceMappingURL=decode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/decoding/decode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,kCAA8C;AAS9C,SAAS,QAAQ,CAAC,KAAK,EAAE,MA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,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,CACtF,CAAC;AACJ,CAAC;AAPD,oDAOC","sourcesContent":["/**\n * Copyright (c) 2018 Endel Dreyer\n * Copyright (c) 2014 Ion Drive Software Ltd.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE\n */\n\nimport { SWITCH_TO_STRUCTURE } from \"../spec\";\n\n/**\n * msgpack implementation highly based on notepack.io\n * https://github.com/darrachequesne/notepack\n */\n\nexport interface Iterator { offset: number; }\n\nfunction utf8Read(bytes, offset, length) {\n var string = '', chr = 0;\n for (var i = offset, end = offset + length; i < end; i++) {\n var byte = bytes[i];\n if ((byte & 0x80) === 0x00) {\n string += String.fromCharCode(byte);\n continue;\n }\n if ((byte & 0xe0) === 0xc0) {\n string += String.fromCharCode(\n ((byte & 0x1f) << 6) |\n (bytes[++i] & 0x3f)\n );\n continue;\n }\n if ((byte & 0xf0) === 0xe0) {\n string += String.fromCharCode(\n ((byte & 0x0f) << 12) |\n ((bytes[++i] & 0x3f) << 6) |\n ((bytes[++i] & 0x3f) << 0)\n );\n continue;\n }\n if ((byte & 0xf8) === 0xf0) {\n chr = ((byte & 0x07) << 18) |\n ((bytes[++i] & 0x3f) << 12) |\n ((bytes[++i] & 0x3f) << 6) |\n ((bytes[++i] & 0x3f) << 0);\n if (chr >= 0x010000) { // surrogate pair\n chr -= 0x010000;\n string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00);\n } else {\n string += String.fromCharCode(chr);\n }\n continue;\n }\n\n console.error('Invalid byte ' + byte.toString(16));\n // (do not throw error to avoid server/client from crashing due to hack attemps)\n // throw new Error('Invalid byte ' + byte.toString(16));\n }\n return string;\n}\n\nexport function int8 (bytes: number[], it: Iterator) {\n return uint8(bytes, it) << 24 >> 24;\n};\n\nexport function uint8 (bytes: number[], it: Iterator) {\n return bytes[it.offset++];\n};\n\nexport function int16 (bytes: number[], it: Iterator) {\n return uint16(bytes, it) << 16 >> 16;\n};\n\nexport function uint16 (bytes: number[], it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8;\n};\n\nexport function int32 (bytes: number[], it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;\n};\n\nexport function uint32 (bytes: number[], it: Iterator) {\n return int32(bytes, it) >>> 0;\n};\n\nexport function float32(bytes: number[], it: Iterator) {\n return readFloat32(bytes, it);\n}\n\nexport function float64(bytes: number[], it: Iterator) {\n return readFloat64(bytes, it);\n}\n\nexport function int64(bytes: number[], it: Iterator) {\n const low = uint32(bytes, it);\n const high = int32(bytes, it) * Math.pow(2, 32);\n return high + low;\n};\n\nexport function uint64(bytes: number[], it: Iterator) {\n const low = uint32(bytes, it);\n const high = uint32(bytes, it) * Math.pow(2, 32);\n return high + low;\n};\n\n// force little endian to facilitate decoding on multiple implementations\nconst _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;\nconst _int32 = new Int32Array(2);\nconst _float32 = new Float32Array(_int32.buffer);\nconst _float64 = new Float64Array(_int32.buffer);\n\nexport function readFloat32 (bytes: number[], it: Iterator) {\n _int32[0] = int32(bytes, it);\n return _float32[0];\n};\n\nexport function readFloat64 (bytes: number[], it: Iterator) {\n _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);\n _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);\n return _float64[0];\n};\n\nexport function boolean (bytes: number[], it: Iterator) {\n return uint8(bytes, it) > 0;\n};\n\nexport function string (bytes, it: Iterator) {\n const prefix = bytes[it.offset++];\n let length: number;\n\n if (prefix < 0xc0) {\n // fixstr\n length = prefix & 0x1f;\n\n } else if (prefix === 0xd9) {\n length = uint8(bytes, it);\n\n } else if (prefix === 0xda) {\n length = uint16(bytes, it);\n\n } else if (prefix === 0xdb) {\n length = uint32(bytes, it);\n }\n\n const value = utf8Read(bytes, it.offset, length);\n it.offset += length;\n\n return value;\n}\n\nexport function stringCheck(bytes, it: Iterator) {\n const prefix = bytes[it.offset];\n return (\n // fixstr\n (prefix < 0xc0 && prefix > 0xa0) ||\n // str 8\n prefix === 0xd9 ||\n // str 16\n prefix === 0xda ||\n // str 32\n prefix === 0xdb\n );\n}\n\nexport function number (bytes, it: Iterator) {\n const prefix = bytes[it.offset++];\n\n if (prefix < 0x80) {\n // positive fixint\n return prefix;\n\n } else if (prefix === 0xca) {\n // float 32\n return readFloat32(bytes, it);\n\n } else if (prefix === 0xcb) {\n // float 64\n return readFloat64(bytes, it);\n\n } else if (prefix === 0xcc) {\n // uint 8\n return uint8(bytes, it);\n\n } else if (prefix === 0xcd) {\n // uint 16\n return uint16(bytes, it);\n\n } else if (prefix === 0xce) {\n // uint 32\n return uint32(bytes, it);\n\n } else if (prefix === 0xcf) {\n // uint 64\n return uint64(bytes, it);\n\n } else if (prefix === 0xd0) {\n // int 8\n return int8(bytes, it);\n\n } else if (prefix === 0xd1) {\n // int 16\n return int16(bytes, it);\n\n } else if (prefix === 0xd2) {\n // int 32\n return int32(bytes, it);\n\n } else if (prefix === 0xd3) {\n // int 64\n return int64(bytes, it);\n\n } else if (prefix > 0xdf) {\n // negative fixint\n return (0xff - prefix + 1) * -1\n }\n};\n\nexport function numberCheck (bytes, it: Iterator) {\n const prefix = bytes[it.offset];\n // positive fixint - 0x00 - 0x7f\n // float 32 - 0xca\n // float 64 - 0xcb\n // uint 8 - 0xcc\n // uint 16 - 0xcd\n // uint 32 - 0xce\n // uint 64 - 0xcf\n // int 8 - 0xd0\n // int 16 - 0xd1\n // int 32 - 0xd2\n // int 64 - 0xd3\n return (\n prefix < 0x80 ||\n (prefix >= 0xca && prefix <= 0xd3)\n );\n}\n\nexport function arrayCheck (bytes, it: Iterator) {\n return bytes[it.offset] < 0xa0;\n\n // const prefix = bytes[it.offset] ;\n\n // if (prefix < 0xa0) {\n // return prefix;\n\n // // array\n // } else if (prefix === 0xdc) {\n // it.offset += 2;\n\n // } else if (0xdd) {\n // it.offset += 4;\n // }\n\n // return prefix;\n}\n\nexport function switchStructureCheck(bytes, it: Iterator) {\n return (\n // previous byte should be `SWITCH_TO_STRUCTURE`\n bytes[it.offset - 1] === SWITCH_TO_STRUCTURE &&\n // next byte should be a number\n (bytes[it.offset] < 0x80 || (bytes[it.offset] >= 0xca && bytes[it.offset] <= 0xd3))\n );\n}"]}
|
package/lib/ecs.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { System } from '@lastolivegames/becsy';
|
|
2
|
-
export declare class VelocityInputController extends System {
|
|
3
|
-
private readonly movables;
|
|
4
|
-
private readonly keysPressed;
|
|
5
|
-
initialize(): void;
|
|
6
|
-
execute(): void;
|
|
7
|
-
}
|
|
8
|
-
export declare class Movement extends System {
|
|
9
|
-
private readonly movables;
|
|
10
|
-
execute(): void;
|
|
11
|
-
}
|
package/lib/ecs.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Movement = exports.VelocityInputController = void 0;
|
|
10
|
-
const becsy_1 = require("@lastolivegames/becsy");
|
|
11
|
-
const readline_1 = require("readline");
|
|
12
|
-
const symbols_1 = require("./types/symbols");
|
|
13
|
-
const EncodeOperation_1 = require("./encoder/EncodeOperation");
|
|
14
|
-
const DecodeOperation_1 = require("./decoder/DecodeOperation");
|
|
15
|
-
const spec_1 = require("./encoding/spec");
|
|
16
|
-
const Metadata_1 = require("./Metadata");
|
|
17
|
-
let Position = class Position {
|
|
18
|
-
};
|
|
19
|
-
__decorate([
|
|
20
|
-
becsy_1.field.float64
|
|
21
|
-
], Position.prototype, "x", void 0);
|
|
22
|
-
__decorate([
|
|
23
|
-
becsy_1.field.float64
|
|
24
|
-
], Position.prototype, "y", void 0);
|
|
25
|
-
Position = __decorate([
|
|
26
|
-
becsy_1.component
|
|
27
|
-
], Position);
|
|
28
|
-
let Velocity = class Velocity {
|
|
29
|
-
};
|
|
30
|
-
__decorate([
|
|
31
|
-
becsy_1.field.float64
|
|
32
|
-
], Velocity.prototype, "vx", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
becsy_1.field.float64
|
|
35
|
-
], Velocity.prototype, "vy", void 0);
|
|
36
|
-
Velocity = __decorate([
|
|
37
|
-
becsy_1.component
|
|
38
|
-
], Velocity);
|
|
39
|
-
let VelocityInputController = class VelocityInputController extends becsy_1.System {
|
|
40
|
-
constructor() {
|
|
41
|
-
super(...arguments);
|
|
42
|
-
// Every system can define any number of queries whose results will be available in the `execute`
|
|
43
|
-
// method. In this case, we're asking for all entities that currently have a Velocity component,
|
|
44
|
-
// and declare that we'll be writing to those components.
|
|
45
|
-
this.movables = this.query(q => q.current.with(Velocity).write);
|
|
46
|
-
// Here we'll store all keys that are currently pressed. This is not specific to ECS but it's a
|
|
47
|
-
// common pattern to glue together event-driven (DOM) and timing-driven (ECS) processes.
|
|
48
|
-
this.keysPressed = new Set();
|
|
49
|
-
}
|
|
50
|
-
// Every system can provide an `initialize` method that will be called once as the world is being
|
|
51
|
-
// set up. We'll use it to register our DOM event handlers.
|
|
52
|
-
initialize() {
|
|
53
|
-
// Listen for keypress events
|
|
54
|
-
const timeouts = {};
|
|
55
|
-
process.stdin.on('keypress', (str, key) => {
|
|
56
|
-
if (key.ctrl && key.name === 'c') {
|
|
57
|
-
// If Ctrl+C is pressed, exit the program
|
|
58
|
-
rl.close();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
// Print the key pressed
|
|
62
|
-
this.keysPressed.add(key.name);
|
|
63
|
-
if (timeouts[key.name]) {
|
|
64
|
-
clearTimeout(timeouts[key.name]);
|
|
65
|
-
}
|
|
66
|
-
timeouts[key.name] = setTimeout(() => {
|
|
67
|
-
this.keysPressed.delete(key.name);
|
|
68
|
-
delete timeouts[key.name];
|
|
69
|
-
}, 100);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
// Every system can (and probably should) provide an `execute` method that implements its logic.
|
|
74
|
-
// It will be invoked once per frame in our demo, so at 60fps it's called 60 times per second.
|
|
75
|
-
execute() {
|
|
76
|
-
// We loop through the query results of the movables query we defined above.
|
|
77
|
-
for (const movable of this.movables.current) {
|
|
78
|
-
// This is how we access the data stored in the Velocity component of our movable entity.
|
|
79
|
-
// We must specify whether we intend to only `read` the data or also to `write` it. We'll
|
|
80
|
-
// only be allowed to `write` to component types that we reserved as such in our queries.
|
|
81
|
-
const velocity = movable.write(Velocity);
|
|
82
|
-
if (this.keysPressed.has('up'))
|
|
83
|
-
velocity.vy = -100; // in pixels per second
|
|
84
|
-
else if (this.keysPressed.has('down'))
|
|
85
|
-
velocity.vy = 100;
|
|
86
|
-
else
|
|
87
|
-
velocity.vy = 0;
|
|
88
|
-
if (this.keysPressed.has('left'))
|
|
89
|
-
velocity.vx = -100;
|
|
90
|
-
else if (this.keysPressed.has('right'))
|
|
91
|
-
velocity.vx = 100;
|
|
92
|
-
else
|
|
93
|
-
velocity.vx = 0;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
exports.VelocityInputController = VelocityInputController;
|
|
98
|
-
exports.VelocityInputController = VelocityInputController = __decorate([
|
|
99
|
-
becsy_1.system
|
|
100
|
-
], VelocityInputController);
|
|
101
|
-
let Movement = class Movement extends becsy_1.System {
|
|
102
|
-
constructor() {
|
|
103
|
-
super(...arguments);
|
|
104
|
-
this.movables = this.query(q => q.current.with(Velocity).and.with(Position).write);
|
|
105
|
-
}
|
|
106
|
-
execute() {
|
|
107
|
-
for (const movable of this.movables.current) {
|
|
108
|
-
// We retrive both velocity (to read) and position (to write) from our entities.
|
|
109
|
-
const velocity = movable.read(Velocity);
|
|
110
|
-
const position = movable.write(Position);
|
|
111
|
-
// In the execute method, a system has access to `this.delta`, which is the delta time between
|
|
112
|
-
// the current frame and the previous one. This allows us to calculate a stable movement
|
|
113
|
-
// regardless of the intervals between our frames. For more on that see
|
|
114
|
-
// https://drewcampbell92.medium.com/understanding-delta-time-b53bf4781a03.
|
|
115
|
-
position.x += this.delta * velocity.vx;
|
|
116
|
-
position.y += this.delta * velocity.vy;
|
|
117
|
-
console.log("x:", position.x, "y:", position.y);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
exports.Movement = Movement;
|
|
122
|
-
exports.Movement = Movement = __decorate([
|
|
123
|
-
becsy_1.system
|
|
124
|
-
], Movement);
|
|
125
|
-
Metadata_1.Metadata.setFields(becsy_1.World, {
|
|
126
|
-
x: "number",
|
|
127
|
-
y: "number",
|
|
128
|
-
z: "number",
|
|
129
|
-
});
|
|
130
|
-
becsy_1.World[symbols_1.$encoder] = EncodeOperation_1.encodeSchemaOperation;
|
|
131
|
-
becsy_1.World[symbols_1.$decoder] = DecodeOperation_1.decodeSchemaOperation;
|
|
132
|
-
becsy_1.World[symbols_1.$track] = function (changeTree, index, operation = spec_1.OPERATION.ADD) {
|
|
133
|
-
changeTree.change(index, operation);
|
|
134
|
-
};
|
|
135
|
-
async function main() {
|
|
136
|
-
// We can now create the world that all our entities and their components will live in. All system
|
|
137
|
-
// and component classes tagged with `@system` and `@component` will be automatically added to the
|
|
138
|
-
// world's `defs`, and in this case we don't need to add any other types manually.
|
|
139
|
-
const world = await becsy_1.World.create();
|
|
140
|
-
// Now we create the entity that will represent our object and add the components it will need.
|
|
141
|
-
// Each component type can be optionally followed by an object with initial field values.
|
|
142
|
-
world.createEntity(Position, Velocity);
|
|
143
|
-
// Finally, we set up our game loop. The `run` function will be executed once per frame.
|
|
144
|
-
async function run() {
|
|
145
|
-
// Execute the world, which will call the `execute` method of all systems in sequence. The call
|
|
146
|
-
// is asynchronous and we _must_ await its result, otherwise errors won't be reported properly.
|
|
147
|
-
await world.execute();
|
|
148
|
-
}
|
|
149
|
-
setInterval(() => run(), 1000 / 30);
|
|
150
|
-
}
|
|
151
|
-
main();
|
|
152
|
-
// Create an interface for reading input
|
|
153
|
-
const rl = readline_1.default.createInterface({
|
|
154
|
-
input: process.stdin,
|
|
155
|
-
output: process.stdout
|
|
156
|
-
});
|
|
157
|
-
// Start listening for input
|
|
158
|
-
process.stdin.setRawMode(true);
|
|
159
|
-
process.stdin.resume();
|
|
160
|
-
//# sourceMappingURL=ecs.js.map
|
package/lib/ecs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ecs.js","sourceRoot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G,uCAAqB,CAAC;AACxC,aAAK,CAAC,kBAAQ,CAAC,GAAG,uCAAqB,CAAC;AACxC,aAAK,CAAC,gBAAM,CAAC,GAAG,UACZ,UAAsB,EACtB,KAAa,EACb,YAAuB,gBAAS,CAAC,GAAG;IAEpC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI;IACf,mGAAmG;IACnG,kGAAkG;IAClG,kFAAkF;IAClF,MAAM,KAAK,GAAG,MAAM,aAAK,CAAC,MAAM,EAAE,CAAC;IAEnC,+FAA+F;IAC/F,yFAAyF;IACzF,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEvC,yFAAyF;IACzF,KAAK,UAAU,GAAG;QACd,gGAAgG;QAChG,+FAA+F;QAC/F,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;IAED,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AACxC,CAAC;AAED,IAAI,EAAE,CAAC;AAEP,wCAAwC;AACxC,MAAM,EAAE,GAAG,kBAAQ,CAAC,eAAe,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACzB,CAAC,CAAC;AAEH,4BAA4B;AAC5B,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAC/B,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC","sourcesContent":["import { component, field, system, System, World } from '@lastolivegames/becsy';\nimport readline from \"readline\";\nimport { Readable } from 'stream';\nimport { $decoder, $encoder, $track } from './types/symbols';\nimport { encodeSchemaOperation } from './encoder/EncodeOperation';\nimport { decodeSchemaOperation } from './decoder/DecodeOperation';\nimport { ChangeTree } from './encoder/ChangeTree';\nimport { OPERATION } from './encoding/spec';\nimport { Metadata } from './Metadata';\n\n@component class Position {\n @field.float64 declare x: number;\n @field.float64 declare y: number;\n}\n\n@component class Velocity {\n @field.float64 declare vx: number;\n @field.float64 declare vy: number;\n}\n\n@system export class VelocityInputController extends System {\n // Every system can define any number of queries whose results will be available in the `execute`\n // method. In this case, we're asking for all entities that currently have a Velocity component,\n // and declare that we'll be writing to those components.\n private readonly movables = this.query(q => q.current.with(Velocity).write);\n\n // Here we'll store all keys that are currently pressed. This is not specific to ECS but it's a\n // common pattern to glue together event-driven (DOM) and timing-driven (ECS) processes.\n private readonly keysPressed = new Set<string>();\n\n // Every system can provide an `initialize` method that will be called once as the world is being\n // set up. We'll use it to register our DOM event handlers.\n initialize(): void {\n // Listen for keypress events\n const timeouts: {[key: string]: NodeJS.Timeout} = {};\n\n process.stdin.on('keypress', (str, key) => {\n if (key.ctrl && key.name === 'c') {\n // If Ctrl+C is pressed, exit the program\n rl.close();\n\n } else {\n // Print the key pressed\n this.keysPressed.add(key.name);\n\n if (timeouts[key.name]) {\n clearTimeout(timeouts[key.name]);\n }\n\n timeouts[key.name] = setTimeout(() => {\n this.keysPressed.delete(key.name);\n delete timeouts[key.name];\n }, 100);\n }\n });\n }\n\n // Every system can (and probably should) provide an `execute` method that implements its logic.\n // It will be invoked once per frame in our demo, so at 60fps it's called 60 times per second.\n execute(): void {\n // We loop through the query results of the movables query we defined above.\n for (const movable of this.movables.current) {\n // This is how we access the data stored in the Velocity component of our movable entity.\n // We must specify whether we intend to only `read` the data or also to `write` it. We'll\n // only be allowed to `write` to component types that we reserved as such in our queries.\n const velocity = movable.write(Velocity);\n\n if (this.keysPressed.has('up')) velocity.vy = -100; // in pixels per second\n else if (this.keysPressed.has('down')) velocity.vy = 100;\n else velocity.vy = 0;\n\n if (this.keysPressed.has('left')) velocity.vx = -100;\n else if (this.keysPressed.has('right')) velocity.vx = 100;\n else velocity.vx = 0;\n }\n }\n}\n\n@system export class Movement extends System {\n private readonly movables =\n this.query(q => q.current.with(Velocity).and.with(Position).write);\n\n execute(): void {\n for (const movable of this.movables.current) {\n // We retrive both velocity (to read) and position (to write) from our entities.\n const velocity = movable.read(Velocity);\n const position = movable.write(Position);\n // In the execute method, a system has access to `this.delta`, which is the delta time between\n // the current frame and the previous one. This allows us to calculate a stable movement\n // regardless of the intervals between our frames. For more on that see\n // https://drewcampbell92.medium.com/understanding-delta-time-b53bf4781a03.\n position.x += this.delta * velocity.vx;\n position.y += this.delta * velocity.vy;\n console.log(\"x:\", position.x, \"y:\", position.y);\n }\n }\n}\n\nMetadata.setFields(World, {\n x: \"number\",\n y: \"number\",\n z: \"number\",\n});\n\nWorld[$encoder] = encodeSchemaOperation;\nWorld[$decoder] = decodeSchemaOperation;\nWorld[$track] = function (\n changeTree: ChangeTree,\n index: number,\n operation: OPERATION = OPERATION.ADD\n) {\n changeTree.change(index, operation);\n};\n\nasync function main() {\n // We can now create the world that all our entities and their components will live in. All system\n // and component classes tagged with `@system` and `@component` will be automatically added to the\n // world's `defs`, and in this case we don't need to add any other types manually.\n const world = await World.create();\n\n // Now we create the entity that will represent our object and add the components it will need.\n // Each component type can be optionally followed by an object with initial field values.\n world.createEntity(Position, Velocity);\n\n // Finally, we set up our game loop. The `run` function will be executed once per frame.\n async function run() {\n // Execute the world, which will call the `execute` method of all systems in sequence. The call\n // is asynchronous and we _must_ await its result, otherwise errors won't be reported properly.\n await world.execute();\n }\n\n setInterval(() => run(), 1000 / 30);\n}\n\nmain();\n\n// Create an interface for reading input\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\n// Start listening for input\nprocess.stdin.setRawMode(true);\nprocess.stdin.resume();"]}
|
package/lib/filters/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ChangeTree } from "../changes/ChangeTree";
|
|
2
|
-
import { ClientWithSessionId } from "../annotations";
|
|
3
|
-
export declare class ClientState {
|
|
4
|
-
refIds: WeakSet<ChangeTree>;
|
|
5
|
-
containerIndexes: WeakMap<ChangeTree, Set<number>>;
|
|
6
|
-
addRefId(changeTree: ChangeTree): void;
|
|
7
|
-
static get(client: ClientWithSessionId): ClientState;
|
|
8
|
-
}
|
package/lib/filters/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientState = void 0;
|
|
4
|
-
class ClientState {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.refIds = new WeakSet();
|
|
7
|
-
this.containerIndexes = new WeakMap();
|
|
8
|
-
}
|
|
9
|
-
// containerIndexes = new Map<ChangeTree, Set<number>>();
|
|
10
|
-
addRefId(changeTree) {
|
|
11
|
-
if (!this.refIds.has(changeTree)) {
|
|
12
|
-
this.refIds.add(changeTree);
|
|
13
|
-
this.containerIndexes.set(changeTree, new Set());
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
static get(client) {
|
|
17
|
-
if (client.$filterState === undefined) {
|
|
18
|
-
client.$filterState = new ClientState();
|
|
19
|
-
}
|
|
20
|
-
return client.$filterState;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.ClientState = ClientState;
|
|
24
|
-
//# sourceMappingURL=index.js.map
|