@dcl/ecs 7.1.4-4601317654.commit-d2ae6e4 → 7.1.4-4608901735.commit-37cc11b

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.
@@ -5,7 +5,7 @@ import { IEngine, LastWriteWinElementSetComponentDefinition } from '../engine/ty
5
5
  * @deprecated composite is not being supported so far, please do not use this feature
6
6
  */
7
7
  export type CompositeRootType = {
8
- id: string;
8
+ src: string;
9
9
  entities: {
10
10
  src: Entity;
11
11
  dest: Entity;
@@ -9,7 +9,7 @@ export function getCompositeRootComponent(engine) {
9
9
  return component;
10
10
  }
11
11
  return engine.defineComponent('composite::root', {
12
- id: Schemas.String,
12
+ src: Schemas.String,
13
13
  entities: Schemas.Array(Schemas.Map({
14
14
  src: Schemas.Entity,
15
15
  dest: Schemas.Entity
@@ -1,9 +1,9 @@
1
1
  import { IEngine } from '../engine';
2
2
  import { CompositeRootType, getCompositeRootComponent } from './components';
3
- import { CompositeProvider, EntityMappingMode, InstanceCompositeOptions } from './instance';
3
+ import { CompositeProvider, CompositeResource, EntityMappingMode, InstanceCompositeOptions } from './instance';
4
4
  import type { ComponentData, CompositeComponent, CompositeComponent_DataEntry } from './proto/gen/composite.gen';
5
5
  import { CompositeDefinition } from './proto/gen/composite.gen';
6
- export type { CompositeDefinition, ComponentData, CompositeComponent, CompositeComponent_DataEntry, InstanceCompositeOptions, CompositeProvider, CompositeRootType };
6
+ export type { CompositeDefinition, ComponentData, CompositeComponent, CompositeComponent_DataEntry, InstanceCompositeOptions, CompositeProvider, CompositeRootType, CompositeResource };
7
7
  export { EntityMappingMode };
8
8
  export { getCompositeRootComponent };
9
9
  /**
@@ -17,17 +17,19 @@ export type Composite = CompositeDefinition;
17
17
  */
18
18
  export declare namespace Composite {
19
19
  /** @public */
20
- type Type = CompositeDefinition;
20
+ type Definition = CompositeDefinition;
21
+ /** @public */
22
+ type Resource = CompositeResource;
21
23
  /** @public */
22
24
  type Provider = CompositeProvider;
23
25
  /** @public */
24
- function fromJson(object: any): Composite.Type;
26
+ function fromJson(object: any): Composite.Definition;
25
27
  /** @public */
26
- function fromBinary(buffer: Uint8Array): Composite.Type;
28
+ function fromBinary(buffer: Uint8Array): Composite.Definition;
27
29
  /** @public */
28
- function toJson(composite: Composite.Type): any;
30
+ function toJson(composite: Composite.Definition): any;
29
31
  /** @public */
30
- function toBinary(composite: Composite.Type): Uint8Array;
32
+ function toBinary(composite: Composite.Definition): Uint8Array;
31
33
  /**
32
34
  * Instance a composite and returns its root entity
33
35
  * @param compositeData - state serialized by the CRDT protocol
@@ -36,5 +38,14 @@ export declare namespace Composite {
36
38
  *
37
39
  * @public
38
40
  */
39
- function instance(engine: IEngine, compositeData: Composite.Type, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): void;
41
+ function instance(engine: IEngine, compositeData: Composite.Resource, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): void;
42
+ /**
43
+ * Resolve and normalize a composite path
44
+ * @param src - the source path
45
+ * @param cwd - the directory from the resolve should start to resolve
46
+ *
47
+ * @returns the absolute resolved path without slash at the beginning
48
+ * @public
49
+ */
50
+ function resolveAndNormalizePath(src: string, cwd?: string): string;
40
51
  }
@@ -1,5 +1,6 @@
1
1
  import { getCompositeRootComponent } from './components';
2
2
  import { EntityMappingMode, instanceComposite } from './instance';
3
+ import { resolveComposite } from './path';
3
4
  import { CompositeDefinition } from './proto/gen/composite.gen';
4
5
  export { EntityMappingMode };
5
6
  export { getCompositeRootComponent };
@@ -41,4 +42,16 @@ export var Composite;
41
42
  instanceComposite(engine, compositeData, compositeProvider, options);
42
43
  }
43
44
  Composite.instance = instance;
45
+ /**
46
+ * Resolve and normalize a composite path
47
+ * @param src - the source path
48
+ * @param cwd - the directory from the resolve should start to resolve
49
+ *
50
+ * @returns the absolute resolved path without slash at the beginning
51
+ * @public
52
+ */
53
+ /*#__PURE__*/ function resolveAndNormalizePath(src, cwd = '/') {
54
+ return resolveComposite(src, cwd);
55
+ }
56
+ Composite.resolveAndNormalizePath = resolveAndNormalizePath;
44
57
  })(Composite || (Composite = {}));
@@ -3,8 +3,16 @@ import { CompositeDefinition } from './proto/gen/composite.gen';
3
3
  /**
4
4
  * @public
5
5
  */
6
+ export type CompositeResource = {
7
+ src: string;
8
+ composite: CompositeDefinition;
9
+ };
10
+ /**
11
+ * @param src - the source path of the composite
12
+ * @public
13
+ */
6
14
  export type CompositeProvider = {
7
- getCompositeOrNull(id: string): CompositeDefinition | null;
15
+ getCompositeOrNull(src: string): CompositeResource | null;
8
16
  };
9
17
  /** @public */
10
18
  export declare enum EntityMappingMode {
@@ -22,5 +30,5 @@ export type InstanceCompositeOptions = {
22
30
  getCompositeEntity: (compositeEntity: Entity | number) => Entity;
23
31
  };
24
32
  rootEntity?: Entity;
25
- alreadyRequestedId?: Set<string>;
33
+ alreadyRequestedSrc?: Set<string>;
26
34
  };
@@ -3,6 +3,7 @@ import { componentNumberFromName } from '../components/component-number';
3
3
  import { Schemas } from '../schemas';
4
4
  import { ReadWriteByteBuffer } from '../serialization/ByteBuffer';
5
5
  import { getCompositeRootComponent } from './components';
6
+ import * as path from './path';
6
7
  /** @public */
7
8
  /* @__PURE__ */
8
9
  export var EntityMappingMode;
@@ -77,9 +78,10 @@ export function getEntityMapping(engine, compositeEntity, mappedEntities, { enti
77
78
  * @internal
78
79
  */
79
80
  /* @__PURE__ */
80
- export function instanceComposite(engine, compositeData, compositeProvider, options) {
81
- const { rootEntity, alreadyRequestedId: optionalAlreadyRequestedId, entityMapping } = options;
82
- const alreadyRequestedId = optionalAlreadyRequestedId || new Set();
81
+ export function instanceComposite(engine, compositeResource, compositeProvider, options) {
82
+ const { rootEntity, alreadyRequestedSrc: optionalAlreadyRequestedSrc, entityMapping } = options;
83
+ const alreadyRequestedSrc = optionalAlreadyRequestedSrc || new Set();
84
+ const compositeDirectoryPath = path.dirname(path.resolve(compositeResource.src));
83
85
  const TransformComponentNumber = componentNumberFromName('core::Transform');
84
86
  const CompositeRootComponent = getCompositeRootComponent(engine);
85
87
  // Key => EntityNumber from the composite
@@ -97,19 +99,21 @@ export function instanceComposite(engine, compositeData, compositeProvider, opti
97
99
  // If there are more composite inside this one, we instance first.
98
100
  // => This is not only a copy, we need to instance. Otherwise, we'd be missing that branches
99
101
  // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
100
- const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
102
+ const childrenComposite = compositeResource.composite.components.find((item) => item.name === CompositeRootComponent.componentName);
101
103
  if (childrenComposite) {
102
- for (const [compositeEntity, childComposite] of childrenComposite.data) {
103
- const compositeRoot = getComponentValue(CompositeRootComponent, childComposite);
104
- const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
105
- const targetEntity = getCompositeEntity(compositeEntity);
106
- if (composite) {
107
- if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
108
- throw new Error(`Composite ${compositeRoot.id} has a recursive instanciation while try to instance ${compositeData.id}. Previous instances: ${alreadyRequestedId.toString()}`);
104
+ for (const [childCompositeEntity, compositeRawData] of childrenComposite.data) {
105
+ const childComposite = getComponentValue(CompositeRootComponent, compositeRawData);
106
+ const childCompositePath = path.resolveComposite(childComposite.src, compositeDirectoryPath);
107
+ const childCompositeResource = compositeProvider.getCompositeOrNull(childCompositePath);
108
+ const targetEntity = getCompositeEntity(childCompositeEntity);
109
+ if (childCompositeResource) {
110
+ if (alreadyRequestedSrc.has(childCompositeResource.src) ||
111
+ childCompositeResource.src === compositeResource.src) {
112
+ throw new Error(`Composite ${compositeResource.src} has a recursive instanciation while try to instance ${childCompositeResource.src}. Previous instances: ${alreadyRequestedSrc.toString()}`);
109
113
  }
110
- instanceComposite(engine, composite, compositeProvider, {
114
+ instanceComposite(engine, childCompositeResource, compositeProvider, {
111
115
  rootEntity: targetEntity,
112
- alreadyRequestedId: new Set(alreadyRequestedId).add(compositeData.id),
116
+ alreadyRequestedSrc: new Set(alreadyRequestedSrc).add(childCompositeResource.src),
113
117
  entityMapping: entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
114
118
  });
115
119
  }
@@ -117,7 +121,7 @@ export function instanceComposite(engine, compositeData, compositeProvider, opti
117
121
  }
118
122
  // ## 3 ##
119
123
  // Then, we copy the all rest of the components (skipping the Composite ones)
120
- for (const component of compositeData.components) {
124
+ for (const component of compositeResource.composite.components) {
121
125
  // We already instanced the composite
122
126
  if (component.name === CompositeRootComponent.componentName)
123
127
  continue;
@@ -152,6 +156,6 @@ export function instanceComposite(engine, compositeData, compositeProvider, opti
152
156
  dest: targetEntity
153
157
  });
154
158
  }
155
- composite.id = compositeData.id;
159
+ composite.src = compositeResource.src;
156
160
  return compositeRootEntity;
157
161
  }
@@ -0,0 +1,3 @@
1
+ export declare function resolve(...args: string[]): string;
2
+ export declare function dirname(path: string): string;
3
+ export declare function resolveComposite(path: string, cwd: string): string;
@@ -0,0 +1,148 @@
1
+ const currentWorkingDir = '/';
2
+ /**
3
+ * The functions `normalizeStringPosix`, `dirname` and `resolve`
4
+ * were extracted from package @browserify/path
5
+ */
6
+ /* istanbul ignore next */
7
+ function normalizeStringPosix(path, allowAboveRoot = false) {
8
+ let res = '';
9
+ let lastSegmentLength = 0;
10
+ let lastSlash = -1;
11
+ let dots = 0;
12
+ let code;
13
+ for (let i = 0; i <= path.length; ++i) {
14
+ if (i < path.length)
15
+ code = path.charCodeAt(i);
16
+ else if (code === 47 /*/*/)
17
+ break;
18
+ else
19
+ code = 47; /*/*/
20
+ if (code === 47 /*/*/) {
21
+ if (lastSlash === i - 1 || dots === 1) {
22
+ // NOOP
23
+ }
24
+ else if (lastSlash !== i - 1 && dots === 2) {
25
+ if (res.length < 2 ||
26
+ lastSegmentLength !== 2 ||
27
+ res.charCodeAt(res.length - 1) !== 46 /*.*/ ||
28
+ res.charCodeAt(res.length - 2) !== 46 /*.*/) {
29
+ if (res.length > 2) {
30
+ const lastSlashIndex = res.lastIndexOf('/');
31
+ if (lastSlashIndex !== res.length - 1) {
32
+ if (lastSlashIndex === -1) {
33
+ res = '';
34
+ lastSegmentLength = 0;
35
+ }
36
+ else {
37
+ res = res.slice(0, lastSlashIndex);
38
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
39
+ }
40
+ lastSlash = i;
41
+ dots = 0;
42
+ continue;
43
+ }
44
+ }
45
+ else if (res.length === 2 || res.length === 1) {
46
+ res = '';
47
+ lastSegmentLength = 0;
48
+ lastSlash = i;
49
+ dots = 0;
50
+ continue;
51
+ }
52
+ }
53
+ if (allowAboveRoot) {
54
+ if (res.length > 0)
55
+ res += '/..';
56
+ else
57
+ res = '..';
58
+ lastSegmentLength = 2;
59
+ }
60
+ }
61
+ else {
62
+ if (res.length > 0)
63
+ res += '/' + path.slice(lastSlash + 1, i);
64
+ else
65
+ res = path.slice(lastSlash + 1, i);
66
+ lastSegmentLength = i - lastSlash - 1;
67
+ }
68
+ lastSlash = i;
69
+ dots = 0;
70
+ }
71
+ else if (code === 46 /*.*/ && dots !== -1) {
72
+ ++dots;
73
+ }
74
+ else {
75
+ dots = -1;
76
+ }
77
+ }
78
+ return res;
79
+ }
80
+ /* istanbul ignore next */
81
+ export function resolve(...args) {
82
+ let resolvedPath = '';
83
+ let resolvedAbsolute = false;
84
+ let cwd;
85
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
86
+ let path;
87
+ if (i >= 0)
88
+ path = args[i];
89
+ else {
90
+ if (cwd === undefined)
91
+ cwd = currentWorkingDir;
92
+ path = cwd;
93
+ }
94
+ // Skip empty entries
95
+ if (path.length === 0) {
96
+ continue;
97
+ }
98
+ resolvedPath = path + '/' + resolvedPath;
99
+ resolvedAbsolute = path.charCodeAt(0) === 47; /*/*/
100
+ }
101
+ // At this point the path should be resolved to a full absolute path, but
102
+ // handle relative paths to be safe (might happen when process.cwd() fails)
103
+ // Normalize the path
104
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
105
+ if (resolvedAbsolute) {
106
+ if (resolvedPath.length > 0)
107
+ return '/' + resolvedPath;
108
+ else
109
+ return '/';
110
+ }
111
+ else if (resolvedPath.length > 0) {
112
+ return resolvedPath;
113
+ }
114
+ else {
115
+ return '.';
116
+ }
117
+ }
118
+ /* istanbul ignore next */
119
+ export function dirname(path) {
120
+ if (path.length === 0)
121
+ return '.';
122
+ let code = path.charCodeAt(0);
123
+ const hasRoot = code === 47; /*/*/
124
+ let end = -1;
125
+ let matchedSlash = true;
126
+ for (let i = path.length - 1; i >= 1; --i) {
127
+ code = path.charCodeAt(i);
128
+ if (code === 47 /*/*/) {
129
+ if (!matchedSlash) {
130
+ end = i;
131
+ break;
132
+ }
133
+ }
134
+ else {
135
+ // We saw the first non-path separator
136
+ matchedSlash = false;
137
+ }
138
+ }
139
+ if (end === -1)
140
+ return hasRoot ? '/' : '.';
141
+ if (hasRoot && end === 1)
142
+ return '//';
143
+ return path.slice(0, end);
144
+ }
145
+ export function resolveComposite(path, cwd) {
146
+ const absolutePath = path.startsWith('.') ? resolve(cwd, path) : resolve(path);
147
+ return absolutePath.substring(1);
148
+ }
@@ -29,6 +29,6 @@ export interface CompositeComponent_DataEntry {
29
29
  * @public
30
30
  */
31
31
  export interface CompositeDefinition {
32
- id: string;
32
+ version: number;
33
33
  components: CompositeComponent[];
34
34
  }
@@ -184,7 +184,7 @@ export const CompositeComponent_DataEntry = {
184
184
  },
185
185
  };
186
186
  function createBaseCompositeDefinition() {
187
- return { id: "", components: [] };
187
+ return { version: 0, components: [] };
188
188
  }
189
189
  /**
190
190
  * @public
@@ -194,8 +194,8 @@ function createBaseCompositeDefinition() {
194
194
  */
195
195
  export const CompositeDefinition = {
196
196
  encode(message, writer = _m0.Writer.create()) {
197
- if (message.id !== "") {
198
- writer.uint32(10).string(message.id);
197
+ if (message.version !== 0) {
198
+ writer.uint32(8).int32(message.version);
199
199
  }
200
200
  for (const v of message.components) {
201
201
  CompositeComponent.encode(v, writer.uint32(18).fork()).ldelim();
@@ -210,7 +210,7 @@ export const CompositeDefinition = {
210
210
  const tag = reader.uint32();
211
211
  switch (tag >>> 3) {
212
212
  case 1:
213
- message.id = reader.string();
213
+ message.version = reader.int32();
214
214
  break;
215
215
  case 2:
216
216
  message.components.push(CompositeComponent.decode(reader, reader.uint32()));
@@ -224,7 +224,7 @@ export const CompositeDefinition = {
224
224
  },
225
225
  fromJSON(object) {
226
226
  return {
227
- id: isSet(object.id) ? String(object.id) : "",
227
+ version: isSet(object.version) ? Number(object.version) : 0,
228
228
  components: Array.isArray(object?.components)
229
229
  ? object.components.map((e) => CompositeComponent.fromJSON(e))
230
230
  : [],
@@ -232,7 +232,7 @@ export const CompositeDefinition = {
232
232
  },
233
233
  toJSON(message) {
234
234
  const obj = {};
235
- message.id !== undefined && (obj.id = message.id);
235
+ message.version !== undefined && (obj.version = Math.round(message.version));
236
236
  if (message.components) {
237
237
  obj.components = message.components.map((e) => e ? CompositeComponent.toJSON(e) : undefined);
238
238
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.1.4-4601317654.commit-d2ae6e4",
4
+ "version": "7.1.4-4608901735.commit-37cc11b",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "dependencies": {
8
- "@dcl/js-runtime": "7.1.4-4601317654.commit-d2ae6e4"
8
+ "@dcl/js-runtime": "7.1.4-4608901735.commit-37cc11b"
9
9
  },
10
10
  "devDependencies": {
11
11
  "ts-proto": "^1.122.0"
@@ -34,5 +34,5 @@
34
34
  },
35
35
  "types": "./dist/index.d.ts",
36
36
  "typings": "./dist/index.d.ts",
37
- "commit": "d2ae6e4e772dd0c26524700bdb34e0272baa0fe6"
37
+ "commit": "37cc11b3938c4420eaeb2fb38af3625e3dec7951"
38
38
  }