@dcl/ecs 7.0.6-4177592674.commit-39cdc99 → 7.0.6-4183962432.commit-2fbe270

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.
Files changed (89) hide show
  1. package/dist/components/extended/Animator.d.ts +3 -2
  2. package/dist/components/extended/Material.d.ts +2 -2
  3. package/dist/components/extended/MeshCollider.d.ts +2 -2
  4. package/dist/components/extended/MeshRenderer.d.ts +2 -2
  5. package/dist/components/generated/Animator.gen.js +6 -0
  6. package/dist/components/generated/AudioSource.gen.js +6 -0
  7. package/dist/components/generated/AudioStream.gen.js +6 -0
  8. package/dist/components/generated/AvatarAttach.gen.js +6 -0
  9. package/dist/components/generated/AvatarModifierArea.gen.js +6 -0
  10. package/dist/components/generated/AvatarShape.gen.js +6 -0
  11. package/dist/components/generated/Billboard.gen.js +6 -0
  12. package/dist/components/generated/CameraMode.gen.js +6 -0
  13. package/dist/components/generated/CameraModeArea.gen.js +6 -0
  14. package/dist/components/generated/GltfContainer.gen.js +6 -0
  15. package/dist/components/generated/Material.gen.js +6 -0
  16. package/dist/components/generated/MeshCollider.gen.js +6 -0
  17. package/dist/components/generated/MeshRenderer.gen.js +6 -0
  18. package/dist/components/generated/NftShape.gen.js +6 -0
  19. package/dist/components/generated/PointerEvents.gen.js +6 -0
  20. package/dist/components/generated/PointerEventsResult.gen.js +6 -0
  21. package/dist/components/generated/PointerLock.gen.js +6 -0
  22. package/dist/components/generated/Raycast.gen.js +6 -0
  23. package/dist/components/generated/RaycastResult.gen.js +6 -0
  24. package/dist/components/generated/TextShape.gen.js +6 -0
  25. package/dist/components/generated/UiBackground.gen.js +6 -0
  26. package/dist/components/generated/UiDropdown.gen.js +6 -0
  27. package/dist/components/generated/UiDropdownResult.gen.js +6 -0
  28. package/dist/components/generated/UiInput.gen.js +6 -0
  29. package/dist/components/generated/UiInputResult.gen.js +6 -0
  30. package/dist/components/generated/UiText.gen.js +6 -0
  31. package/dist/components/generated/UiTransform.gen.js +6 -0
  32. package/dist/components/generated/VideoPlayer.gen.js +6 -0
  33. package/dist/components/generated/VisibilityComponent.gen.js +6 -0
  34. package/dist/components/generated/global.gen.d.ts +26 -26
  35. package/dist/components/generated/index.gen.d.ts +32 -31
  36. package/dist/components/generated/index.gen.js +4 -1
  37. package/dist/components/generated/pb/decentraland/sdk/components/pointer_events_result.gen.d.ts +1 -9
  38. package/dist/components/generated/pb/decentraland/sdk/components/pointer_events_result.gen.js +2 -36
  39. package/dist/components/index.d.ts +9 -9
  40. package/dist/components/index.js +1 -1
  41. package/dist/components/{legacy → manual}/Transform.d.ts +2 -2
  42. package/dist/components/{legacy → manual}/Transform.js +32 -0
  43. package/dist/components/types.d.ts +1 -1
  44. package/dist/engine/component.d.ts +74 -27
  45. package/dist/engine/component.js +7 -240
  46. package/dist/engine/grow-only-value-set-component-definition.d.ts +8 -0
  47. package/dist/engine/grow-only-value-set-component-definition.js +132 -0
  48. package/dist/engine/index.d.ts +1 -2
  49. package/dist/engine/index.js +18 -1
  50. package/dist/engine/input.d.ts +3 -3
  51. package/dist/engine/input.js +75 -68
  52. package/dist/engine/lww-element-set-component-definition.d.ts +6 -0
  53. package/dist/engine/lww-element-set-component-definition.js +229 -0
  54. package/dist/engine/readonly.d.ts +2 -2
  55. package/dist/engine/types.d.ts +20 -9
  56. package/dist/engine/types.js +1 -1
  57. package/dist/runtime/invariant.d.ts +1 -0
  58. package/dist/runtime/invariant.js +6 -1
  59. package/dist/runtime/types.d.ts +1 -2
  60. package/dist/runtime/types.js +0 -1
  61. package/dist/schemas/Array.js +5 -0
  62. package/dist/schemas/ISchema.d.ts +27 -2
  63. package/dist/schemas/Map.d.ts +0 -1
  64. package/dist/schemas/Map.js +9 -0
  65. package/dist/schemas/Optional.js +5 -0
  66. package/dist/schemas/basic/Boolean.js +4 -0
  67. package/dist/schemas/basic/Enum.js +27 -0
  68. package/dist/schemas/basic/Float.js +8 -0
  69. package/dist/schemas/basic/Integer.js +16 -0
  70. package/dist/schemas/basic/String.js +4 -0
  71. package/dist/schemas/buildSchema.d.ts +7 -0
  72. package/dist/schemas/buildSchema.js +63 -0
  73. package/dist/schemas/custom/Color3.js +9 -0
  74. package/dist/schemas/custom/Color4.js +10 -0
  75. package/dist/schemas/custom/Entity.js +4 -0
  76. package/dist/schemas/custom/Quaternion.js +10 -0
  77. package/dist/schemas/custom/Vector3.js +10 -0
  78. package/dist/schemas/index.d.ts +2 -2
  79. package/dist/serialization/crdt/appendValue.d.ts +1 -0
  80. package/dist/serialization/crdt/appendValue.js +49 -0
  81. package/dist/serialization/crdt/index.d.ts +1 -0
  82. package/dist/serialization/crdt/index.js +1 -0
  83. package/dist/serialization/crdt/message.js +4 -0
  84. package/dist/serialization/crdt/types.d.ts +24 -3
  85. package/dist/serialization/crdt/types.js +2 -1
  86. package/dist/systems/crdt/index.d.ts +1 -1
  87. package/dist/systems/crdt/index.js +21 -8
  88. package/dist/systems/events.d.ts +2 -2
  89. package/package.json +3 -3
@@ -1,25 +1,22 @@
1
1
  import type { ISchema } from '../schemas/ISchema';
2
2
  import { MapResult, Spec } from '../schemas/Map';
3
3
  import { Transport } from '../systems/crdt/types';
4
- import { ComponentDefinition } from './component';
4
+ import { ComponentDefinition, GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition } from './component';
5
5
  import { Entity, EntityState } from './entity';
6
+ import { ValueSetOptions } from './grow-only-value-set-component-definition';
6
7
  import { ReadonlyComponentSchema } from './readonly';
7
8
  import { SystemFn } from './systems';
9
+ export * from './component';
10
+ export { ValueSetOptions };
8
11
  /**
9
12
  * @public
10
13
  */
11
14
  export type Unpacked<T> = T extends (infer U)[] ? U : T;
12
- /**
13
- * @public
14
- */
15
- export type ComponentSchema<T extends [ComponentDefinition<any>, ...ComponentDefinition<any>[]]> = {
16
- [K in keyof T]: T[K] extends ComponentDefinition<any> ? ReturnType<T[K]['getMutable']> : never;
17
- };
18
15
  /**
19
16
  * @public
20
17
  * Overrides component definition to support partial default values
21
18
  */
22
- export interface MapComponentDefinition<T> extends ComponentDefinition<T> {
19
+ export interface MapComponentDefinition<T> extends LastWriteWinElementSetComponentDefinition<T> {
23
20
  /**
24
21
  * Add the current component to an entity, throw an error if the component already exists (use `createOrReplace` instead).
25
22
  * - Internal comment: This method adds the &lt;entity,component&gt; to the list to be reviewed next frame
@@ -128,7 +125,21 @@ export interface IEngine {
128
125
  * const StateComponent = engine.defineComponentFromSchema("my-lib::VisibleComponent", Schemas.Bool)
129
126
  * ```
130
127
  */
131
- defineComponentFromSchema<T>(componentName: string, spec: ISchema<T>): ComponentDefinition<T>;
128
+ defineComponentFromSchema<T>(componentName: string, spec: ISchema<T>): LastWriteWinElementSetComponentDefinition<T>;
129
+ /**
130
+ * @public
131
+ * Defines a value set component.
132
+ * @param componentName - unique name to identify the component, a hash is calculated for it, it will fail if the hash has collisions.
133
+ * @param spec - An object with schema fields
134
+ * @returns The component definition
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const StateComponentId = 10023
139
+ * const StateComponent = engine.defineValueSetComponentFromSchema("my-lib::VisibleComponent", Schemas.Int)
140
+ * ```
141
+ */
142
+ defineValueSetComponentFromSchema<T>(componentName: string, spec: ISchema<T>, options: ValueSetOptions<T>): GrowOnlyValueSetComponentDefinition<T>;
132
143
  /**
133
144
  * @public
134
145
  * Get the component definition from the component id.
@@ -1 +1 @@
1
- export {};
1
+ export * from './component';
@@ -1,3 +1,4 @@
1
1
  type K = unknown | Promise<unknown>;
2
+ export declare const __DEV__: boolean;
2
3
  export declare function checkNotThenable<T extends K>(t: T, error: string): T;
3
4
  export {};
@@ -1,5 +1,10 @@
1
+ /* istanbul ignore file */
2
+ export const __DEV__ = (typeof DEBUG === 'boolean' && DEBUG) ||
3
+ (typeof process === 'object' &&
4
+ (process.env?.NODE_ENV !== 'production' || process.env?.NODE_ENV === 'development')) ||
5
+ false;
1
6
  export function checkNotThenable(t, error) {
2
- if (globalThis.DEBUG) {
7
+ if (__DEV__) {
3
8
  if (t && typeof t === 'object' && typeof t.then === 'function') {
4
9
  throw new Error(error);
5
10
  }
@@ -1,7 +1,6 @@
1
1
  export type { SystemFn } from '../engine/systems';
2
2
  export type { TransportMessage, ReceiveMessage, Transport } from '../systems/crdt/types';
3
- export { TransformType, TransformComponent } from '../components/legacy/Transform';
3
+ export { TransformType, TransformComponent } from '../components/manual/Transform';
4
4
  export * from '../engine/component';
5
5
  export * from '../schemas/typing';
6
6
  export type { MapResult, Spec } from '../schemas/Map';
7
- export * from '../engine/component';
@@ -1,3 +1,2 @@
1
1
  export * from '../engine/component';
2
2
  export * from '../schemas/typing';
3
- export * from '../engine/component';
@@ -19,6 +19,11 @@ export const IArray = (type) => {
19
19
  },
20
20
  create() {
21
21
  return [];
22
+ },
23
+ jsonSchema: {
24
+ type: 'array',
25
+ items: type.jsonSchema,
26
+ serializationType: 'array'
22
27
  }
23
28
  };
24
29
  };
@@ -1,10 +1,35 @@
1
+ import { DeepReadonly } from '../engine/readonly';
1
2
  import { ByteBuffer } from '../serialization/ByteBuffer';
3
+ /**
4
+ * @public
5
+ */
6
+ export type JsonPrimitive = string | number | boolean | null;
7
+ /**
8
+ * @public
9
+ */
10
+ export type JsonMap = {
11
+ [key: string]: JsonPrimitive | JsonMap | JsonArray;
12
+ };
13
+ /**
14
+ * @public
15
+ */
16
+ export type JsonArray = Array<JsonPrimitive | JsonMap | JsonArray>;
17
+ /**
18
+ * JsonSchemaExtended must specify the type, and it can has more primitives params.
19
+ * Functions are not allowed.
20
+ * @public
21
+ */
22
+ export type JsonSchemaExtended = {
23
+ type: 'object' | 'number' | 'integer' | 'string' | 'array' | 'boolean';
24
+ serializationType: 'boolean' | 'enum-int' | 'enum-string' | 'int8' | 'int16' | 'int32' | 'int64' | 'float32' | 'float64' | 'vector3' | 'color3' | 'quaternion' | 'color4' | 'map' | 'optional' | 'entity' | 'array' | 'utf8-string' | 'protocol-buffer' | 'transform' | 'unknown';
25
+ } & JsonMap;
2
26
  /**
3
27
  * @public
4
28
  */
5
29
  export interface ISchema<T = any> {
6
- serialize(value: T, builder: ByteBuffer): void;
30
+ serialize(value: DeepReadonly<T>, builder: ByteBuffer): void;
7
31
  deserialize(reader: ByteBuffer): T;
8
32
  create(): T;
9
- extend?: (base?: T) => T;
33
+ extend?: (base: Partial<DeepReadonly<T>> | undefined) => T;
34
+ jsonSchema: JsonSchemaExtended;
10
35
  }
@@ -18,4 +18,3 @@ export type MapResult<T extends Spec> = ToOptional<{
18
18
  export type MapResultWithOptional<T extends Spec> = ToOptional<{
19
19
  [K in keyof T]?: T[K] extends ISchema ? ReturnType<T[K]['deserialize']> : T[K] extends Spec ? MapResult<T[K]> : never;
20
20
  }>;
21
- export type MapSchemaType<T extends Spec> = ISchema<MapResult<T>>;
@@ -2,6 +2,10 @@
2
2
  * @internal
3
3
  */
4
4
  export const IMap = (spec, defaultValue) => {
5
+ const specReflection = Object.keys(spec).reduce((specReflection, currentKey) => {
6
+ specReflection[currentKey] = spec[currentKey].jsonSchema;
7
+ return specReflection;
8
+ }, {});
5
9
  return {
6
10
  serialize(value, builder) {
7
11
  for (const key in spec) {
@@ -31,6 +35,11 @@ export const IMap = (spec, defaultValue) => {
31
35
  newValue[key] = spec[key].create();
32
36
  }
33
37
  return { ...newValue, ...defaultValue, ...base };
38
+ },
39
+ jsonSchema: {
40
+ type: 'object',
41
+ properties: specReflection,
42
+ serializationType: 'map'
34
43
  }
35
44
  };
36
45
  };
@@ -20,6 +20,11 @@ export const IOptional = (spec) => {
20
20
  },
21
21
  create() {
22
22
  return undefined;
23
+ },
24
+ jsonSchema: {
25
+ type: spec.jsonSchema.type,
26
+ serializationType: 'optional',
27
+ optionalJsonSchema: spec.jsonSchema
23
28
  }
24
29
  };
25
30
  };
@@ -10,5 +10,9 @@ export const Bool = {
10
10
  },
11
11
  create() {
12
12
  return false;
13
+ },
14
+ jsonSchema: {
15
+ type: 'boolean',
16
+ serializationType: 'boolean'
13
17
  }
14
18
  };
@@ -33,6 +33,10 @@ function validateMemberValuesAreStrings(enumValue) {
33
33
  }
34
34
  }
35
35
  }
36
+ /**
37
+ * @internal
38
+ */
39
+ export const IntEnumReflectionType = 'enum-int';
36
40
  /**
37
41
  * @internal
38
42
  */
@@ -47,14 +51,28 @@ export const IntEnum = (enumObject, defaultValue) => {
47
51
  },
48
52
  create() {
49
53
  return defaultValue;
54
+ },
55
+ jsonSchema: {
56
+ // JSON-schema
57
+ type: 'integer',
58
+ enum: Object.values(enumObject).filter((item) => Number.isInteger(item)),
59
+ default: defaultValue,
60
+ // @dcl/ecs Schema Spec
61
+ serializationType: IntEnumReflectionType,
62
+ enumObject
50
63
  }
51
64
  };
52
65
  };
66
+ /**
67
+ * @internal
68
+ */
69
+ export const StringEnumReflectionType = 'enum-string';
53
70
  /**
54
71
  * @internal
55
72
  */
56
73
  export const StringEnum = (enumObject, defaultValue) => {
57
74
  validateMemberValuesAreStrings(enumObject);
75
+ // String enum has the exact mapping from key (our reference in code) to values
58
76
  return {
59
77
  serialize(value, builder) {
60
78
  FlatString.serialize(value, builder);
@@ -64,6 +82,15 @@ export const StringEnum = (enumObject, defaultValue) => {
64
82
  },
65
83
  create() {
66
84
  return defaultValue;
85
+ },
86
+ jsonSchema: {
87
+ // JSON-schema
88
+ type: 'string',
89
+ enum: Object.values(enumObject),
90
+ default: defaultValue,
91
+ // @dcl/ecs Schema Spec
92
+ serializationType: StringEnumReflectionType,
93
+ enumObject
67
94
  }
68
95
  };
69
96
  };
@@ -10,6 +10,10 @@ export const Float32 = {
10
10
  },
11
11
  create() {
12
12
  return 0.0;
13
+ },
14
+ jsonSchema: {
15
+ type: 'number',
16
+ serializationType: 'float32'
13
17
  }
14
18
  };
15
19
  /**
@@ -24,5 +28,9 @@ export const Float64 = {
24
28
  },
25
29
  create() {
26
30
  return 0.0;
31
+ },
32
+ jsonSchema: {
33
+ type: 'number',
34
+ serializationType: 'float64'
27
35
  }
28
36
  };
@@ -10,6 +10,10 @@ export const Int64 = {
10
10
  },
11
11
  create() {
12
12
  return 0;
13
+ },
14
+ jsonSchema: {
15
+ type: 'integer',
16
+ serializationType: 'int64'
13
17
  }
14
18
  };
15
19
  /**
@@ -24,6 +28,10 @@ export const Int32 = {
24
28
  },
25
29
  create() {
26
30
  return 0;
31
+ },
32
+ jsonSchema: {
33
+ type: 'integer',
34
+ serializationType: 'int32'
27
35
  }
28
36
  };
29
37
  /**
@@ -38,6 +46,10 @@ export const Int16 = {
38
46
  },
39
47
  create() {
40
48
  return 0;
49
+ },
50
+ jsonSchema: {
51
+ type: 'integer',
52
+ serializationType: 'int16'
41
53
  }
42
54
  };
43
55
  /**
@@ -52,5 +64,9 @@ export const Int8 = {
52
64
  },
53
65
  create() {
54
66
  return 0;
67
+ },
68
+ jsonSchema: {
69
+ type: 'integer',
70
+ serializationType: 'int8'
55
71
  }
56
72
  };
@@ -10,6 +10,10 @@ export const FlatString = {
10
10
  },
11
11
  create() {
12
12
  return '';
13
+ },
14
+ jsonSchema: {
15
+ type: 'string',
16
+ serializationType: 'utf8-string'
13
17
  }
14
18
  };
15
19
  /**
@@ -0,0 +1,7 @@
1
+ import { ISchema, JsonSchemaExtended } from './ISchema';
2
+ /**
3
+ * Create an ISchema object from the json-schema
4
+ * @param jsonSchema
5
+ * @returns a ISchema or fail for unsupported json-schema
6
+ */
7
+ export declare function jsonSchemaToSchema(jsonSchema: JsonSchemaExtended): ISchema<any>;
@@ -0,0 +1,63 @@
1
+ import { IArray } from './Array';
2
+ import { Bool } from './basic/Boolean';
3
+ import { IntEnum, StringEnum } from './basic/Enum';
4
+ import { Float32, Float64 } from './basic/Float';
5
+ import { Int16, Int32, Int64, Int8 } from './basic/Integer';
6
+ import { EcsString } from './basic/String';
7
+ import { Color3Schema } from './custom/Color3';
8
+ import { Color4Schema } from './custom/Color4';
9
+ import { EntitySchema } from './custom/Entity';
10
+ import { QuaternionSchema } from './custom/Quaternion';
11
+ import { Vector3Schema } from './custom/Vector3';
12
+ import { IMap } from './Map';
13
+ import { IOptional } from './Optional';
14
+ const primitiveSchemas = {
15
+ [Bool.jsonSchema.serializationType]: Bool,
16
+ [EcsString.jsonSchema.serializationType]: EcsString,
17
+ [Float32.jsonSchema.serializationType]: Float32,
18
+ [Float64.jsonSchema.serializationType]: Float64,
19
+ [Int8.jsonSchema.serializationType]: Int8,
20
+ [Int16.jsonSchema.serializationType]: Int16,
21
+ [Int32.jsonSchema.serializationType]: Int32,
22
+ [Int64.jsonSchema.serializationType]: Int64,
23
+ [Vector3Schema.jsonSchema.serializationType]: Vector3Schema,
24
+ [QuaternionSchema.jsonSchema.serializationType]: QuaternionSchema,
25
+ [Color3Schema.jsonSchema.serializationType]: Color3Schema,
26
+ [Color4Schema.jsonSchema.serializationType]: Color4Schema,
27
+ [EntitySchema.jsonSchema.serializationType]: EntitySchema
28
+ };
29
+ /**
30
+ * Create an ISchema object from the json-schema
31
+ * @param jsonSchema
32
+ * @returns a ISchema or fail for unsupported json-schema
33
+ */
34
+ export function jsonSchemaToSchema(jsonSchema) {
35
+ if (primitiveSchemas[jsonSchema.serializationType]) {
36
+ return primitiveSchemas[jsonSchema.serializationType];
37
+ }
38
+ if (jsonSchema.serializationType === 'map') {
39
+ const mapJsonSchema = jsonSchema;
40
+ const spec = {};
41
+ for (const key in mapJsonSchema.properties) {
42
+ spec[key] = jsonSchemaToSchema(mapJsonSchema.properties[key]);
43
+ }
44
+ return IMap(spec);
45
+ }
46
+ if (jsonSchema.serializationType === 'optional') {
47
+ const withItemsJsonSchema = jsonSchema;
48
+ return IOptional(jsonSchemaToSchema(withItemsJsonSchema.optionalJsonSchema));
49
+ }
50
+ if (jsonSchema.serializationType === 'array') {
51
+ const withItemsJsonSchema = jsonSchema;
52
+ return IArray(jsonSchemaToSchema(withItemsJsonSchema.items));
53
+ }
54
+ if (jsonSchema.serializationType === 'enum-int') {
55
+ const enumJsonSchema = jsonSchema;
56
+ return IntEnum(enumJsonSchema.enumObject, enumJsonSchema.default);
57
+ }
58
+ if (jsonSchema.serializationType === 'enum-string') {
59
+ const enumJsonSchema = jsonSchema;
60
+ return StringEnum(enumJsonSchema.enumObject, enumJsonSchema.default);
61
+ }
62
+ throw new Error(`${jsonSchema.serializationType} is not supported as reverse schema generation.`);
63
+ }
@@ -16,5 +16,14 @@ export const Color3Schema = {
16
16
  },
17
17
  create() {
18
18
  return { r: 0, g: 0, b: 0 };
19
+ },
20
+ jsonSchema: {
21
+ type: 'object',
22
+ properties: {
23
+ r: { type: 'number' },
24
+ g: { type: 'number' },
25
+ b: { type: 'number' }
26
+ },
27
+ serializationType: 'color3'
19
28
  }
20
29
  };
@@ -18,5 +18,15 @@ export const Color4Schema = {
18
18
  },
19
19
  create() {
20
20
  return { r: 0, g: 0, b: 0, a: 0 };
21
+ },
22
+ jsonSchema: {
23
+ type: 'object',
24
+ properties: {
25
+ r: { type: 'number' },
26
+ g: { type: 'number' },
27
+ b: { type: 'number' },
28
+ a: { type: 'number' }
29
+ },
30
+ serializationType: 'color4'
21
31
  }
22
32
  };
@@ -10,5 +10,9 @@ export const EntitySchema = {
10
10
  },
11
11
  create() {
12
12
  return 0;
13
+ },
14
+ jsonSchema: {
15
+ type: 'integer',
16
+ serializationType: 'entity'
13
17
  }
14
18
  };
@@ -18,5 +18,15 @@ export const QuaternionSchema = {
18
18
  },
19
19
  create() {
20
20
  return { x: 0, y: 0, z: 0, w: 0 };
21
+ },
22
+ jsonSchema: {
23
+ type: 'object',
24
+ properties: {
25
+ x: { type: 'number' },
26
+ y: { type: 'number' },
27
+ z: { type: 'number' },
28
+ w: { type: 'number' }
29
+ },
30
+ serializationType: 'quaternion'
21
31
  }
22
32
  };
@@ -16,5 +16,15 @@ export const Vector3Schema = {
16
16
  },
17
17
  create() {
18
18
  return { x: 0, y: 0, z: 0 };
19
+ },
20
+ jsonSchema: {
21
+ type: 'object',
22
+ properties: {
23
+ x: { type: 'number' },
24
+ y: { type: 'number' },
25
+ z: { type: 'number' },
26
+ w: { type: 'number' }
27
+ },
28
+ serializationType: 'vector3'
19
29
  }
20
30
  };
@@ -3,8 +3,8 @@ import { Color3Type } from './custom/Color3';
3
3
  import { Color4Type } from './custom/Color4';
4
4
  import { QuaternionType } from './custom/Quaternion';
5
5
  import { Vector3Type } from './custom/Vector3';
6
- import { ISchema } from './ISchema';
7
- export { QuaternionType, Vector3Type, ISchema, Color3Type, Color4Type };
6
+ import { ISchema, JsonSchemaExtended, JsonArray, JsonMap, JsonPrimitive } from './ISchema';
7
+ export { QuaternionType, Vector3Type, ISchema, Color3Type, Color4Type, JsonSchemaExtended, JsonArray, JsonMap, JsonPrimitive };
8
8
  /**
9
9
  * @public
10
10
  */
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import { CrdtMessageProtocol } from './crdtMessageProtocol';
2
+ import { CrdtMessageType, CRDT_MESSAGE_HEADER_LENGTH } from './types';
3
+ /**
4
+ * @internal
5
+ */
6
+ export var AppendValueOperation;
7
+ (function (AppendValueOperation) {
8
+ AppendValueOperation.MESSAGE_HEADER_LENGTH = 16;
9
+ /**
10
+ * Call this function for an optimal writing data passing the ByteBuffer
11
+ * already allocated
12
+ */
13
+ function write(entity, timestamp, componentId, data, buf) {
14
+ // reserve the beginning
15
+ const startMessageOffset = buf.incrementWriteOffset(CRDT_MESSAGE_HEADER_LENGTH + AppendValueOperation.MESSAGE_HEADER_LENGTH);
16
+ // write body
17
+ buf.writeBuffer(data, false);
18
+ const messageLength = buf.currentWriteOffset() - startMessageOffset;
19
+ // Write CrdtMessage header
20
+ buf.setUint32(startMessageOffset, messageLength);
21
+ buf.setUint32(startMessageOffset + 4, CrdtMessageType.APPEND_VALUE);
22
+ // Write ComponentOperation header
23
+ buf.setUint32(startMessageOffset + 8, entity);
24
+ buf.setUint32(startMessageOffset + 12, componentId);
25
+ buf.setUint32(startMessageOffset + 16, timestamp);
26
+ const newLocal = messageLength - AppendValueOperation.MESSAGE_HEADER_LENGTH - CRDT_MESSAGE_HEADER_LENGTH;
27
+ buf.setUint32(startMessageOffset + 20, newLocal);
28
+ }
29
+ AppendValueOperation.write = write;
30
+ function read(buf) {
31
+ const header = CrdtMessageProtocol.readHeader(buf);
32
+ /* istanbul ignore if */
33
+ if (!header) {
34
+ return null;
35
+ }
36
+ /* istanbul ignore if */
37
+ if (header.type !== CrdtMessageType.APPEND_VALUE) {
38
+ throw new Error('AppendValueOperation tried to read another message type.');
39
+ }
40
+ return {
41
+ ...header,
42
+ entityId: buf.readUint32(),
43
+ componentId: buf.readUint32(),
44
+ timestamp: buf.readUint32(),
45
+ data: buf.readBuffer()
46
+ };
47
+ }
48
+ AppendValueOperation.read = read;
49
+ })(AppendValueOperation || (AppendValueOperation = {}));
@@ -1,4 +1,5 @@
1
1
  export * from './deleteComponent';
2
+ export * from './appendValue';
2
3
  export * from './deleteEntity';
3
4
  export * from './putComponent';
4
5
  export * from './types';
@@ -1,4 +1,5 @@
1
1
  export * from './deleteComponent';
2
+ export * from './appendValue';
2
3
  export * from './deleteEntity';
3
4
  export * from './putComponent';
4
5
  export * from './types';
@@ -3,6 +3,7 @@ import { CrdtMessageType } from './types';
3
3
  import { PutComponentOperation } from './putComponent';
4
4
  import { DeleteComponent } from './deleteComponent';
5
5
  import { DeleteEntity } from './deleteEntity';
6
+ import { AppendValueOperation } from './appendValue';
6
7
  export function readMessage(buf) {
7
8
  const header = CrdtMessageProtocol.getHeader(buf);
8
9
  if (!header)
@@ -13,6 +14,9 @@ export function readMessage(buf) {
13
14
  else if (header.type === CrdtMessageType.DELETE_COMPONENT) {
14
15
  return DeleteComponent.read(buf);
15
16
  }
17
+ else if (header.type === CrdtMessageType.APPEND_VALUE) {
18
+ return AppendValueOperation.read(buf);
19
+ }
16
20
  else if (header.type === CrdtMessageType.DELETE_ENTITY) {
17
21
  return DeleteEntity.read(buf);
18
22
  }
@@ -7,7 +7,8 @@ export declare enum CrdtMessageType {
7
7
  PUT_COMPONENT = 1,
8
8
  DELETE_COMPONENT = 2,
9
9
  DELETE_ENTITY = 3,
10
- MAX_MESSAGE_TYPE = 4
10
+ APPEND_VALUE = 4,
11
+ MAX_MESSAGE_TYPE = 5
11
12
  }
12
13
  /**
13
14
  * Min length = 8 bytes
@@ -40,6 +41,22 @@ export type PutComponentMessageBody = {
40
41
  timestamp: number;
41
42
  data: Uint8Array;
42
43
  };
44
+ /**
45
+ * Min. length = header (8 bytes) + 16 bytes = 24 bytes
46
+ *
47
+ * @param entity - Uint32 number of the entity
48
+ * @param componentId - Uint32 number of id
49
+ * @param timestamp - Uint32 timestamp
50
+ * @param data - Uint8[] data of component => length(4 bytes) + block of bytes[0..length-1]
51
+ * @public
52
+ */
53
+ export type AppendValueMessageBody = {
54
+ type: CrdtMessageType.APPEND_VALUE;
55
+ entityId: Entity;
56
+ componentId: number;
57
+ timestamp: number;
58
+ data: Uint8Array;
59
+ };
43
60
  /**
44
61
  * @param entity - Uint32 number of the entity
45
62
  * @param componentId - Uint32 number of id
@@ -60,6 +77,10 @@ export type DeleteEntityMessageBody = {
60
77
  type: CrdtMessageType.DELETE_ENTITY;
61
78
  entityId: Entity;
62
79
  };
80
+ /**
81
+ * @public
82
+ */
83
+ export type AppendValueMessage = CrdtMessageHeader & AppendValueMessageBody;
63
84
  /**
64
85
  * @public
65
86
  */
@@ -75,11 +96,11 @@ export type DeleteEntityMessage = CrdtMessageHeader & DeleteEntityMessageBody;
75
96
  /**
76
97
  * @public
77
98
  */
78
- export type CrdtMessage = PutComponentMessage | DeleteComponentMessage | DeleteEntityMessage;
99
+ export type CrdtMessage = PutComponentMessage | DeleteComponentMessage | DeleteEntityMessage | AppendValueMessage;
79
100
  /**
80
101
  * @public
81
102
  */
82
- export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody;
103
+ export type CrdtMessageBody = PutComponentMessageBody | DeleteComponentMessageBody | DeleteEntityMessageBody | AppendValueMessageBody;
83
104
  export declare enum ProcessMessageResultType {
84
105
  /**
85
106
  * Typical message and new state set.
@@ -8,7 +8,8 @@ export var CrdtMessageType;
8
8
  CrdtMessageType[CrdtMessageType["PUT_COMPONENT"] = 1] = "PUT_COMPONENT";
9
9
  CrdtMessageType[CrdtMessageType["DELETE_COMPONENT"] = 2] = "DELETE_COMPONENT";
10
10
  CrdtMessageType[CrdtMessageType["DELETE_ENTITY"] = 3] = "DELETE_ENTITY";
11
- CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 4] = "MAX_MESSAGE_TYPE";
11
+ CrdtMessageType[CrdtMessageType["APPEND_VALUE"] = 4] = "APPEND_VALUE";
12
+ CrdtMessageType[CrdtMessageType["MAX_MESSAGE_TYPE"] = 5] = "MAX_MESSAGE_TYPE";
12
13
  })(CrdtMessageType || (CrdtMessageType = {}));
13
14
  /**
14
15
  * @public
@@ -4,4 +4,4 @@ import { CrdtMessageType } from '../../serialization/crdt/types';
4
4
  /**
5
5
  * @public
6
6
  */
7
- export type OnChangeFunction = (entity: Entity, operation: CrdtMessageType, component?: ComponentDefinition<any>) => void;
7
+ export type OnChangeFunction = (entity: Entity, operation: CrdtMessageType, component?: ComponentDefinition<any>, componentValue?: any) => void;