@dcl/ecs 7.0.6-4180146485.commit-9a7dde9 → 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 (48) hide show
  1. package/dist/components/generated/Animator.gen.js +6 -0
  2. package/dist/components/generated/AudioSource.gen.js +6 -0
  3. package/dist/components/generated/AudioStream.gen.js +6 -0
  4. package/dist/components/generated/AvatarAttach.gen.js +6 -0
  5. package/dist/components/generated/AvatarModifierArea.gen.js +6 -0
  6. package/dist/components/generated/AvatarShape.gen.js +6 -0
  7. package/dist/components/generated/Billboard.gen.js +6 -0
  8. package/dist/components/generated/CameraMode.gen.js +6 -0
  9. package/dist/components/generated/CameraModeArea.gen.js +6 -0
  10. package/dist/components/generated/GltfContainer.gen.js +6 -0
  11. package/dist/components/generated/Material.gen.js +6 -0
  12. package/dist/components/generated/MeshCollider.gen.js +6 -0
  13. package/dist/components/generated/MeshRenderer.gen.js +6 -0
  14. package/dist/components/generated/NftShape.gen.js +6 -0
  15. package/dist/components/generated/PointerEvents.gen.js +6 -0
  16. package/dist/components/generated/PointerEventsResult.gen.js +6 -0
  17. package/dist/components/generated/PointerLock.gen.js +6 -0
  18. package/dist/components/generated/Raycast.gen.js +6 -0
  19. package/dist/components/generated/RaycastResult.gen.js +6 -0
  20. package/dist/components/generated/TextShape.gen.js +6 -0
  21. package/dist/components/generated/UiBackground.gen.js +6 -0
  22. package/dist/components/generated/UiDropdown.gen.js +6 -0
  23. package/dist/components/generated/UiDropdownResult.gen.js +6 -0
  24. package/dist/components/generated/UiInput.gen.js +6 -0
  25. package/dist/components/generated/UiInputResult.gen.js +6 -0
  26. package/dist/components/generated/UiText.gen.js +6 -0
  27. package/dist/components/generated/UiTransform.gen.js +6 -0
  28. package/dist/components/generated/VideoPlayer.gen.js +6 -0
  29. package/dist/components/generated/VisibilityComponent.gen.js +6 -0
  30. package/dist/components/manual/Transform.js +32 -0
  31. package/dist/schemas/Array.js +5 -0
  32. package/dist/schemas/ISchema.d.ts +24 -0
  33. package/dist/schemas/Map.js +9 -0
  34. package/dist/schemas/Optional.js +5 -0
  35. package/dist/schemas/basic/Boolean.js +4 -0
  36. package/dist/schemas/basic/Enum.js +27 -0
  37. package/dist/schemas/basic/Float.js +8 -0
  38. package/dist/schemas/basic/Integer.js +16 -0
  39. package/dist/schemas/basic/String.js +4 -0
  40. package/dist/schemas/buildSchema.d.ts +7 -0
  41. package/dist/schemas/buildSchema.js +63 -0
  42. package/dist/schemas/custom/Color3.js +9 -0
  43. package/dist/schemas/custom/Color4.js +10 -0
  44. package/dist/schemas/custom/Entity.js +4 -0
  45. package/dist/schemas/custom/Quaternion.js +10 -0
  46. package/dist/schemas/custom/Vector3.js +10 -0
  47. package/dist/schemas/index.d.ts +2 -2
  48. package/package.json +2 -2
@@ -15,5 +15,11 @@ export const AnimatorSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBAnimator.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBAnimator"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const AudioSourceSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBAudioSource.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBAudioSource"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const AudioStreamSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBAudioStream.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBAudioStream"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const AvatarAttachSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBAvatarAttach.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBAvatarAttach"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const AvatarModifierAreaSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBAvatarModifierArea.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBAvatarModifierArea"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const AvatarShapeSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBAvatarShape.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBAvatarShape"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const BillboardSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBBillboard.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBBillboard"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const CameraModeSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBCameraMode.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBCameraMode"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const CameraModeAreaSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBCameraModeArea.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBCameraModeArea"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const GltfContainerSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBGltfContainer.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBGltfContainer"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const MaterialSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBMaterial.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBMaterial"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const MeshColliderSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBMeshCollider.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBMeshCollider"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const MeshRendererSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBMeshRenderer.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBMeshRenderer"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const NftShapeSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBNftShape.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBNftShape"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const PointerEventsSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBPointerEvents.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBPointerEvents"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const PointerEventsResultSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBPointerEventsResult.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBPointerEventsResult"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const PointerLockSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBPointerLock.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBPointerLock"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const RaycastSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBRaycast.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBRaycast"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const RaycastResultSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBRaycastResult.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBRaycastResult"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const TextShapeSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBTextShape.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBTextShape"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiBackgroundSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiBackground.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiBackground"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiDropdownSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiDropdown.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiDropdown"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiDropdownResultSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiDropdownResult.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiDropdownResult"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiInputSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiInput.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiInput"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiInputResultSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiInputResult.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiInputResult"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiTextSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiText.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiText"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const UiTransformSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBUiTransform.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBUiTransform"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const VideoPlayerSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBVideoPlayer.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBVideoPlayer"
18
24
  }
19
25
  };
@@ -15,5 +15,11 @@ export const VisibilityComponentSchema = {
15
15
  create() {
16
16
  // TODO: this is a hack.
17
17
  return PBVisibilityComponent.decode(new Uint8Array());
18
+ },
19
+ jsonSchema: {
20
+ type: "object",
21
+ properties: {},
22
+ serializationType: "protocol-buffer",
23
+ protocolBuffer: "PBVisibilityComponent"
18
24
  }
19
25
  };
@@ -58,6 +58,38 @@ export const TransformSchema = {
58
58
  parent: 0,
59
59
  ...value
60
60
  };
61
+ },
62
+ jsonSchema: {
63
+ type: 'object',
64
+ properties: {
65
+ position: {
66
+ type: 'object',
67
+ properties: {
68
+ x: { type: 'number' },
69
+ y: { type: 'number' },
70
+ z: { type: 'number' }
71
+ }
72
+ },
73
+ scale: {
74
+ type: 'object',
75
+ properties: {
76
+ x: { type: 'number' },
77
+ y: { type: 'number' },
78
+ z: { type: 'number' }
79
+ }
80
+ },
81
+ rotation: {
82
+ type: 'object',
83
+ properties: {
84
+ x: { type: 'number' },
85
+ y: { type: 'number' },
86
+ z: { type: 'number' },
87
+ w: { type: 'number' }
88
+ }
89
+ },
90
+ parent: { type: 'integer' }
91
+ },
92
+ serializationType: 'transform'
61
93
  }
62
94
  };
63
95
  export function defineTransformComponent(engine) {
@@ -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,5 +1,28 @@
1
1
  import { DeepReadonly } from '../engine/readonly';
2
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;
3
26
  /**
4
27
  * @public
5
28
  */
@@ -8,4 +31,5 @@ export interface ISchema<T = any> {
8
31
  deserialize(reader: ByteBuffer): T;
9
32
  create(): T;
10
33
  extend?: (base: Partial<DeepReadonly<T>> | undefined) => T;
34
+ jsonSchema: JsonSchemaExtended;
11
35
  }
@@ -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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
- "version": "7.0.6-4180146485.commit-9a7dde9",
3
+ "version": "7.0.6-4183962432.commit-2fbe270",
4
4
  "description": "Decentraland ECS",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -40,5 +40,5 @@
40
40
  "displayName": "ECS",
41
41
  "tsconfig": "./tsconfig.json"
42
42
  },
43
- "commit": "9a7dde903f381c1778ec3c7519e4f312ab9b2ee3"
43
+ "commit": "2fbe270d3909a3f1cb2a1794544288e5e5d602aa"
44
44
  }