@dcl/ecs 7.29.1-36591934525.commit-48aa9b5 → 7.29.1-36625469671.commit-2d5ffac

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 (75) hide show
  1. package/dist/components/generated/component-names.gen.js +0 -1
  2. package/dist/components/generated/global.gen.d.ts +0 -2
  3. package/dist/components/generated/global.gen.js +0 -1
  4. package/dist/components/generated/index.gen.d.ts +0 -4
  5. package/dist/components/generated/index.gen.js +0 -7
  6. package/dist/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.d.ts +2 -4
  7. package/dist/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.js +1 -3
  8. package/dist/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.d.ts +3 -8
  9. package/dist/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.js +1 -10
  10. package/dist/components/index.d.ts +5 -0
  11. package/dist/components/index.js +5 -2
  12. package/dist/components/manual/CreatedBy.d.ts +9 -0
  13. package/dist/components/manual/CreatedBy.js +8 -0
  14. package/dist/components/manual/Transform.d.ts +9 -0
  15. package/dist/components/manual/Transform.js +3 -3
  16. package/dist/components/types.d.ts +1 -0
  17. package/dist/engine/component.d.ts +52 -1
  18. package/dist/engine/grow-only-value-set-component-definition.js +45 -2
  19. package/dist/engine/lww-element-set-component-definition.d.ts +3 -1
  20. package/dist/engine/lww-element-set-component-definition.js +68 -13
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +1 -0
  23. package/dist/serialization/crdt/authoritativePutComponent.d.ts +15 -0
  24. package/dist/serialization/crdt/authoritativePutComponent.js +47 -0
  25. package/dist/serialization/crdt/index.d.ts +1 -0
  26. package/dist/serialization/crdt/index.js +1 -0
  27. package/dist/serialization/crdt/types.d.ts +25 -3
  28. package/dist/serialization/crdt/types.js +3 -1
  29. package/dist/systems/crdt/index.d.ts +0 -1
  30. package/dist/systems/crdt/index.js +76 -143
  31. package/dist/systems/crdt/types.d.ts +10 -0
  32. package/dist-cjs/components/generated/component-names.gen.js +0 -1
  33. package/dist-cjs/components/generated/global.gen.d.ts +0 -2
  34. package/dist-cjs/components/generated/global.gen.js +2 -3
  35. package/dist-cjs/components/generated/index.gen.d.ts +0 -4
  36. package/dist-cjs/components/generated/index.gen.js +2 -10
  37. package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.d.ts +2 -4
  38. package/dist-cjs/components/generated/pb/decentraland/sdk/components/common/explorer_ui.gen.js +1 -3
  39. package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.d.ts +3 -8
  40. package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_ui_events_result.gen.js +1 -10
  41. package/dist-cjs/components/index.d.ts +5 -0
  42. package/dist-cjs/components/index.js +7 -3
  43. package/dist-cjs/components/manual/CreatedBy.d.ts +9 -0
  44. package/dist-cjs/components/manual/CreatedBy.js +10 -0
  45. package/dist-cjs/components/manual/Transform.d.ts +9 -0
  46. package/dist-cjs/components/manual/Transform.js +3 -3
  47. package/dist-cjs/components/types.d.ts +1 -0
  48. package/dist-cjs/engine/component.d.ts +52 -1
  49. package/dist-cjs/engine/grow-only-value-set-component-definition.js +44 -1
  50. package/dist-cjs/engine/lww-element-set-component-definition.d.ts +3 -1
  51. package/dist-cjs/engine/lww-element-set-component-definition.js +71 -14
  52. package/dist-cjs/index.d.ts +2 -1
  53. package/dist-cjs/index.js +2 -1
  54. package/dist-cjs/serialization/crdt/authoritativePutComponent.d.ts +15 -0
  55. package/dist-cjs/serialization/crdt/authoritativePutComponent.js +50 -0
  56. package/dist-cjs/serialization/crdt/index.d.ts +1 -0
  57. package/dist-cjs/serialization/crdt/index.js +1 -0
  58. package/dist-cjs/serialization/crdt/types.d.ts +25 -3
  59. package/dist-cjs/serialization/crdt/types.js +3 -1
  60. package/dist-cjs/systems/crdt/index.d.ts +0 -1
  61. package/dist-cjs/systems/crdt/index.js +76 -166
  62. package/dist-cjs/systems/crdt/types.d.ts +10 -0
  63. package/package.json +2 -2
  64. package/dist/components/generated/ExplorerItemPurchaseResult.gen.d.ts +0 -1
  65. package/dist/components/generated/ExplorerItemPurchaseResult.gen.js +0 -25
  66. package/dist/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.d.ts +0 -68
  67. package/dist/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.js +0 -184
  68. package/dist/serialization/crdt/network/utils.d.ts +0 -9
  69. package/dist/serialization/crdt/network/utils.js +0 -60
  70. package/dist-cjs/components/generated/ExplorerItemPurchaseResult.gen.d.ts +0 -1
  71. package/dist-cjs/components/generated/ExplorerItemPurchaseResult.gen.js +0 -28
  72. package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.d.ts +0 -68
  73. package/dist-cjs/components/generated/pb/decentraland/sdk/components/explorer_item_purchase_result.gen.js +0 -190
  74. package/dist-cjs/serialization/crdt/network/utils.d.ts +0 -9
  75. package/dist-cjs/serialization/crdt/network/utils.js +0 -67
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Identifies which explorer panel OpenExplorerUi targets. Panels are not all fullscreen.
2
+ * Identifies which fullscreen explorer panel OpenExplorerUi targets.
3
3
  * EU_SETTINGS holds 0 so an unset `ui` field defaults to the least-intrusive panel.
4
4
  */
5
5
  /**
@@ -12,7 +12,5 @@ export declare const enum ExplorerUi {
12
12
  EU_CAMERA_REEL = 3,
13
13
  EU_COMMUNITIES = 4,
14
14
  EU_PLACES = 5,
15
- EU_EVENTS = 6,
16
- /** EU_ITEM_PURCHASE - the item-purchase confirmation modal; see OpenExplorerUi for its parameters and result component */
17
- EU_ITEM_PURCHASE = 7
15
+ EU_EVENTS = 6
18
16
  }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ExplorerUi = void 0;
5
5
  const protobufPackageSarasa = "decentraland.sdk.components.common";
6
6
  /**
7
- * Identifies which explorer panel OpenExplorerUi targets. Panels are not all fullscreen.
7
+ * Identifies which fullscreen explorer panel OpenExplorerUi targets.
8
8
  * EU_SETTINGS holds 0 so an unset `ui` field defaults to the least-intrusive panel.
9
9
  */
10
10
  /**
@@ -19,6 +19,4 @@ var ExplorerUi;
19
19
  ExplorerUi[ExplorerUi["EU_COMMUNITIES"] = 4] = "EU_COMMUNITIES";
20
20
  ExplorerUi[ExplorerUi["EU_PLACES"] = 5] = "EU_PLACES";
21
21
  ExplorerUi[ExplorerUi["EU_EVENTS"] = 6] = "EU_EVENTS";
22
- /** EU_ITEM_PURCHASE - the item-purchase confirmation modal; see OpenExplorerUi for its parameters and result component */
23
- ExplorerUi[ExplorerUi["EU_ITEM_PURCHASE"] = 7] = "EU_ITEM_PURCHASE";
24
22
  })(ExplorerUi = exports.ExplorerUi || (exports.ExplorerUi = {}));
@@ -1,7 +1,7 @@
1
1
  import _m0 from "protobufjs/minimal";
2
2
  import { ExplorerUi } from "./common/explorer_ui.gen";
3
3
  /**
4
- * PBExplorerUiEventsResult transports the lifecycle events of explorer UI panels — a panel was
4
+ * PBExplorerUiEventsResult transports the lifecycle events of fullscreen explorer panels — a panel was
5
5
  * opened, a panel was closed. It is a grow only value set appended to the scene root entity, so every
6
6
  * event of a tick is delivered and none overwrites another.
7
7
  */
@@ -13,8 +13,6 @@ export interface PBExplorerUiEventsResult {
13
13
  ui: ExplorerUi;
14
14
  /** The scene tick when the event occurred */
15
15
  timestamp: number;
16
- /** The OpenExplorerUiRequest.request_id that caused this event; 0 when the request carried none */
17
- requestId: number;
18
16
  event?: {
19
17
  $case: "opened";
20
18
  opened: PBExplorerUiEventsResult_UiOpened;
@@ -23,16 +21,13 @@ export interface PBExplorerUiEventsResult {
23
21
  closed: PBExplorerUiEventsResult_UiClosed;
24
22
  } | undefined;
25
23
  }
26
- /**
27
- * Emitted when an explorer panel is opened. The OpenExplorerUi response carries the same fact,
28
- * but it reaches only the caller; this channel is scene wide.
29
- */
24
+ /** Emitted when a fullscreen explorer panel is opened. */
30
25
  /**
31
26
  * @public
32
27
  */
33
28
  export interface PBExplorerUiEventsResult_UiOpened {
34
29
  }
35
- /** Emitted when an explorer panel is closed. */
30
+ /** Emitted when a fullscreen explorer panel is closed. */
36
31
  /**
37
32
  * @public
38
33
  */
@@ -8,7 +8,7 @@ exports.PBExplorerUiEventsResult_UiClosed = exports.PBExplorerUiEventsResult_UiO
8
8
  const minimal_1 = __importDefault(require("protobufjs/minimal"));
9
9
  const protobufPackageSarasa = "decentraland.sdk.components";
10
10
  function createBasePBExplorerUiEventsResult() {
11
- return { ui: 0, timestamp: 0, requestId: 0, event: undefined };
11
+ return { ui: 0, timestamp: 0, event: undefined };
12
12
  }
13
13
  /**
14
14
  * @public
@@ -22,9 +22,6 @@ var PBExplorerUiEventsResult;
22
22
  if (message.timestamp !== 0) {
23
23
  writer.uint32(16).uint32(message.timestamp);
24
24
  }
25
- if (message.requestId !== 0) {
26
- writer.uint32(24).uint32(message.requestId);
27
- }
28
25
  switch (message.event?.$case) {
29
26
  case "opened":
30
27
  PBExplorerUiEventsResult_UiOpened.encode(message.event.opened, writer.uint32(82).fork()).ldelim();
@@ -55,12 +52,6 @@ var PBExplorerUiEventsResult;
55
52
  }
56
53
  message.timestamp = reader.uint32();
57
54
  continue;
58
- case 3:
59
- if (tag !== 24) {
60
- break;
61
- }
62
- message.requestId = reader.uint32();
63
- continue;
64
55
  case 10:
65
56
  if (tag !== 82) {
66
57
  break;
@@ -23,6 +23,7 @@ import { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea';
23
23
  import { ParticleSystemComponentDefinitionExtended } from './extended/ParticleSystem';
24
24
  import { TouchScreenControlsComponentDefinitionExtended } from './extended/TouchScreenControls';
25
25
  import { TagsComponentDefinitionExtended } from './manual/Tags';
26
+ import { ICreatedByType } from './manual/CreatedBy';
26
27
  export * from './generated/index.gen';
27
28
  export type { GrowOnlyValueSetComponentDefinition, LastWriteWinElementSetComponentDefinition, LwwComponentGetter, GSetComponentGetter };
28
29
  export declare const Transform: LwwComponentGetter<TransformComponentExtended>;
@@ -57,5 +58,9 @@ export declare const NetworkEntity: (engine: Pick<IEngine, 'defineComponent'>) =
57
58
  * @alpha
58
59
  */
59
60
  export declare const NetworkParent: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<INetowrkParentType>;
61
+ /**
62
+ * @public
63
+ */
64
+ export declare const CreatedBy: (engine: Pick<IEngine, 'defineComponent'>) => LastWriteWinElementSetComponentDefinition<ICreatedByType>;
60
65
  export { MediaState };
61
66
  export type { AudioAnalysisView };
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MediaState = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TouchScreenControls = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
20
+ exports.MediaState = exports.CreatedBy = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.Tags = exports.Name = exports.TouchScreenControls = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.MeshCollider = exports.MeshRenderer = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Material = exports.Transform = void 0;
21
21
  const Animator_1 = require("./extended/Animator");
22
22
  const AudioSource_1 = require("./extended/AudioSource");
23
23
  const AudioAnalysis_1 = require("./extended/AudioAnalysis");
@@ -40,6 +40,7 @@ const TriggerArea_1 = require("./extended/TriggerArea");
40
40
  const ParticleSystem_1 = require("./extended/ParticleSystem");
41
41
  const TouchScreenControls_1 = require("./extended/TouchScreenControls");
42
42
  const Tags_1 = __importDefault(require("./manual/Tags"));
43
+ const CreatedBy_1 = __importDefault(require("./manual/CreatedBy"));
43
44
  __exportStar(require("./generated/index.gen"), exports);
44
45
  /* @__PURE__ */
45
46
  const Transform = (engine) => (0, Transform_1.defineTransformComponent)(engine);
@@ -104,12 +105,15 @@ exports.SyncComponents = SyncComponents;
104
105
  /**
105
106
  * @alpha
106
107
  */
107
- /* @__PURE__ */
108
108
  const NetworkEntity = (engine) => (0, NetworkEntity_1.default)(engine);
109
109
  exports.NetworkEntity = NetworkEntity;
110
110
  /**
111
111
  * @alpha
112
112
  */
113
- /* @__PURE__ */
114
113
  const NetworkParent = (engine) => (0, NetworkParent_1.default)(engine);
115
114
  exports.NetworkParent = NetworkParent;
115
+ /**
116
+ * @public
117
+ */
118
+ const CreatedBy = (engine) => (0, CreatedBy_1.default)(engine);
119
+ exports.CreatedBy = CreatedBy;
@@ -0,0 +1,9 @@
1
+ import { IEngine, LastWriteWinElementSetComponentDefinition } from '../../engine/types';
2
+ export interface ICreatedByType {
3
+ address: string;
4
+ }
5
+ export type ICreatedBy = LastWriteWinElementSetComponentDefinition<ICreatedByType>;
6
+ declare function defineCreatedBy(engine: Pick<IEngine, 'defineComponent'>): import("../../engine/types").MapComponentDefinition<import("../..").MapResult<{
7
+ address: import("../../schemas").ISchema<string>;
8
+ }>>;
9
+ export default defineCreatedBy;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schemas_1 = require("../../schemas");
4
+ function defineCreatedBy(engine) {
5
+ const CreatedBy = engine.defineComponent('core-schema::Created-By', {
6
+ address: schemas_1.Schemas.String
7
+ });
8
+ return CreatedBy;
9
+ }
10
+ exports.default = defineCreatedBy;
@@ -1,5 +1,6 @@
1
1
  import { LastWriteWinElementSetComponentDefinition, IEngine } from '../../engine';
2
2
  import { Entity } from '../../engine/entity';
3
+ import type { ISchema } from '../../schemas/ISchema';
3
4
  import type { Vector3Type } from '../../schemas/custom/Vector3';
4
5
  /**
5
6
  * @public
@@ -24,6 +25,10 @@ export interface TransformComponentExtended extends TransformComponent {
24
25
  */
25
26
  localToWorldDirection(entity: Entity, localDirection: Vector3Type): Vector3Type;
26
27
  }
28
+ /**
29
+ * @public
30
+ */
31
+ export declare const COMPONENT_ID = 1;
27
32
  /**
28
33
  * @public
29
34
  */
@@ -46,6 +51,10 @@ export type TransformType = {
46
51
  };
47
52
  parent?: Entity;
48
53
  };
54
+ /** @public */
55
+ export declare const TRANSFORM_LENGTH = 44;
56
+ /** @public */
57
+ export declare const TransformSchema: ISchema<TransformType>;
49
58
  /**
50
59
  * @public
51
60
  */
@@ -29,12 +29,12 @@ exports.defineTransformComponent = exports.TransformSchema = exports.TRANSFORM_L
29
29
  // getters via __importStar in CJS), so by the time methods are called all exports are available.
30
30
  const treeHelpers = __importStar(require("../../runtime/helpers/tree"));
31
31
  /**
32
- * @internal
32
+ * @public
33
33
  */
34
34
  exports.COMPONENT_ID = 1;
35
- /** @internal */
35
+ /** @public */
36
36
  exports.TRANSFORM_LENGTH = 44;
37
- /** @internal */
37
+ /** @public */
38
38
  exports.TransformSchema = {
39
39
  serialize(value, builder) {
40
40
  const ptr = builder.incrementWriteOffset(exports.TRANSFORM_LENGTH);
@@ -13,6 +13,7 @@ export type { TagsComponentDefinitionExtended, TagsType } from './manual/Tags';
13
13
  export type { ISyncComponents, ISyncComponentsType } from './manual/SyncComponents';
14
14
  export type { INetowrkEntity, INetowrkEntityType } from './manual/NetworkEntity';
15
15
  export type { INetowrkParent, INetowrkParentType } from './manual/NetworkParent';
16
+ export type { ICreatedBy, ICreatedByType } from './manual/CreatedBy';
16
17
  export type { InputModifierHelper, InputModifierComponentDefinitionExtended } from './extended/InputModifier';
17
18
  export type { LightSourceHelper, LightSourceComponentDefinitionExtended } from './extended/LightSource';
18
19
  export type { TriggerAreaComponentDefinitionExtended } from './extended/TriggerArea';
@@ -1,6 +1,6 @@
1
1
  import { ISchema } from '../schemas';
2
2
  import { ByteBuffer } from '../serialization/ByteBuffer';
3
- import { CrdtMessageBody, DeleteComponentMessageBody, PutComponentMessageBody } from '../serialization/crdt';
3
+ import { CrdtMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, PutComponentMessageBody } from '../serialization/crdt';
4
4
  import { Entity } from './entity';
5
5
  import { DeepReadonly, DeepReadonlySet } from './readonly';
6
6
  /**
@@ -70,7 +70,58 @@ export interface BaseComponent<T> {
70
70
  * If the value is undefined, the component was deleted.
71
71
  */
72
72
  onChange(entity: Entity, cb: (value: T | undefined) => void): void;
73
+ /**
74
+ * @public
75
+ *
76
+ */
77
+ validateBeforeChange(entity: Entity, cb: ValidateCallback<T>): void;
78
+ validateBeforeChange(cb: ValidateCallback<T>): void;
79
+ /**
80
+ * Get the CRDT state for an entity (serialized data and timestamp)
81
+ * @param entity - Entity to get the CRDT state for
82
+ * @returns Object with serialized data and timestamp, or null if entity doesn't have the component
83
+ * @public
84
+ */
85
+ getCrdtState(entity: Entity): {
86
+ data: Uint8Array;
87
+ timestamp: number;
88
+ } | null;
89
+ }
90
+ /**
91
+ * Internal component interface that exposes all internal methods for SDK use
92
+ * This is not exposed to users, only for internal SDK operations
93
+ */
94
+ export interface InternalBaseComponent<T> extends BaseComponent<T> {
95
+ /**
96
+ * @public
97
+ * Dry run update to check if a CRDT message would be accepted without actually applying it
98
+ */
99
+ __dry_run_updateFromCrdt(body: CrdtMessageBody): ProcessMessageResultType;
100
+ /**
101
+ * @public
102
+ * Get the iterator to every entity has the component
103
+ */
104
+ iterator(): Iterable<[Entity, any]>;
105
+ /**
106
+ * @public
107
+ */
108
+ dirtyIterator(): Iterable<Entity>;
109
+ /**
110
+ * @public
111
+ */
112
+ __onChangeCallbacks(entity: Entity, value: T): void;
113
+ /**
114
+ * @public
115
+ */
116
+ __run_validateBeforeChange(entity: Entity, newValue: T | undefined, senderAddress: string, createdBy: string): boolean;
73
117
  }
118
+ export type ValidateCallback<T> = (value: {
119
+ entity: Entity;
120
+ currentValue: T | undefined;
121
+ newValue: T | undefined;
122
+ senderAddress: string;
123
+ createdBy: string;
124
+ }) => boolean;
74
125
  /**
75
126
  * @public
76
127
  */
@@ -5,6 +5,7 @@ const ByteBuffer_1 = require("../serialization/ByteBuffer");
5
5
  const crdt_1 = require("../serialization/crdt");
6
6
  const invariant_1 = require("../runtime/invariant");
7
7
  const emptyReadonlySet = freezeSet(new Set());
8
+ const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
8
9
  function frozenError() {
9
10
  throw new Error('The set is frozen');
10
11
  }
@@ -25,6 +26,7 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
25
26
  const dirtyIterator = new Set();
26
27
  const queuedCommands = [];
27
28
  const onChangeCallbacks = new Map();
29
+ const validateCallbacks = new Map();
28
30
  // only sort the array if the latest (N) element has a timestamp <= N-1
29
31
  function shouldSort(row) {
30
32
  const len = row.raw.length;
@@ -83,8 +85,11 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
83
85
  has(entity) {
84
86
  return data.has(entity);
85
87
  },
86
- entityDeleted(entity) {
88
+ entityDeleted(entity, markAsDirty) {
87
89
  data.delete(entity);
90
+ if (markAsDirty) {
91
+ // For grow-only sets, we don't need to mark as dirty since deletion doesn't generate CRDT messages
92
+ }
88
93
  },
89
94
  get(entity) {
90
95
  const values = data.get(entity);
@@ -155,6 +160,44 @@ function createValueSetComponentDefinitionFromSchema(componentName, componentId,
155
160
  for (const cb of cbs) {
156
161
  cb(value);
157
162
  }
163
+ },
164
+ __dry_run_updateFromCrdt(_body) {
165
+ return crdt_1.ProcessMessageResultType.StateUpdatedData;
166
+ },
167
+ validateBeforeChange(entityOrCb, cb) {
168
+ if (arguments.length === 1) {
169
+ // Second overload: just callback (global validation)
170
+ validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
171
+ }
172
+ else {
173
+ if (cb) {
174
+ validateCallbacks.set(entityOrCb, cb);
175
+ }
176
+ }
177
+ },
178
+ __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
179
+ const cb = entity && validateCallbacks.get(entity);
180
+ const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
181
+ const currentValue = [...this.get(entity).values()];
182
+ const value = { entity, currentValue: currentValue, newValue, senderAddress, createdBy };
183
+ const globalResult = globalCb?.(value) ?? true;
184
+ const entityResult = (globalResult && cb?.(value)) ?? true;
185
+ return globalResult && entityResult;
186
+ },
187
+ getCrdtState(entity) {
188
+ const row = data.get(entity);
189
+ if (!row || row.raw.length === 0) {
190
+ return null;
191
+ }
192
+ // For GrowOnlySet, we need to return the complete CRDT messages for all values
193
+ // This is complex because GrowOnlySet uses APPEND messages, not a single PUT
194
+ // For now, return null to indicate this component type doesn't support simple corrections
195
+ return null;
196
+ },
197
+ __forceUpdateFromCrdt(_msg) {
198
+ // GrowOnlySet doesn't support authoritative corrections in the same way as LWW
199
+ // since it uses APPEND_VALUE messages instead of PUT_COMPONENT messages
200
+ return [null, undefined];
158
201
  }
159
202
  };
160
203
  return ret;
@@ -1,8 +1,10 @@
1
1
  import { ISchema } from '../schemas';
2
2
  import { ByteBuffer } from '../serialization/ByteBuffer';
3
- import { PutComponentMessageBody, DeleteComponentMessageBody, CrdtMessageBody } from '../serialization/crdt';
3
+ import { PutComponentMessageBody, DeleteComponentMessageBody, ProcessMessageResultType, CrdtMessageBody, PutNetworkComponentMessageBody, DeleteComponentNetworkMessageBody, AuthoritativePutComponentMessageBody } from '../serialization/crdt';
4
4
  import { Entity } from './entity';
5
5
  export declare function incrementTimestamp(entity: Entity, timestamps: Map<Entity, number>): number;
6
6
  export declare function createDumpLwwFunctionFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (buffer: ByteBuffer, filterEntity?: ((entity: Entity) => boolean) | undefined) => void;
7
+ export declare function createCrdtRuleValidator(timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): (message: PutComponentMessageBody | DeleteComponentMessageBody | PutNetworkComponentMessageBody | DeleteComponentNetworkMessageBody) => ProcessMessageResultType;
8
+ export declare function createForceUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>): (msg: AuthoritativePutComponentMessageBody) => [null, any];
7
9
  export declare function createUpdateLwwFromCrdt(componentId: number, timestamps: Map<Entity, number>, schema: Pick<ISchema<any>, 'serialize' | 'deserialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): (msg: CrdtMessageBody) => [null | PutComponentMessageBody | DeleteComponentMessageBody, any];
8
10
  export declare function createGetCrdtMessagesForLww(componentId: number, timestamps: Map<Entity, number>, dirtyIterator: Set<Entity>, schema: Pick<ISchema<any>, 'serialize'>, data: Map<Entity, unknown>, lastSentData: Map<Entity, Uint8Array>): () => Generator<PutComponentMessageBody | DeleteComponentMessageBody, void, unknown>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createComponentDefinitionFromSchema = exports.createGetCrdtMessagesForLww = exports.createUpdateLwwFromCrdt = exports.createDumpLwwFunctionFromCrdt = exports.incrementTimestamp = void 0;
3
+ exports.createComponentDefinitionFromSchema = exports.createGetCrdtMessagesForLww = exports.createUpdateLwwFromCrdt = exports.createForceUpdateLwwFromCrdt = exports.createCrdtRuleValidator = exports.createDumpLwwFunctionFromCrdt = exports.incrementTimestamp = void 0;
4
4
  const ByteBuffer_1 = require("../serialization/ByteBuffer");
5
5
  const crdt_1 = require("../serialization/crdt");
6
6
  const utils_1 = require("../systems/crdt/utils");
@@ -35,16 +35,12 @@ function createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data) {
35
35
  };
36
36
  }
37
37
  exports.createDumpLwwFunctionFromCrdt = createDumpLwwFunctionFromCrdt;
38
- function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData) {
38
+ const __GLOBAL_ENTITY = '__GLOBAL_ENTITY';
39
+ function createCrdtRuleValidator(timestamps, schema, data, lastSentData) {
39
40
  /**
40
- * Process the received message only if the lamport number recieved is higher
41
- * than the stored one. If its lower, we spread it to the network to correct the peer.
42
- * If they are equal, the bigger raw data wins.
43
-
44
- * Returns the recieved data if the lamport number was bigger than ours.
45
- * If it was an outdated message, then we return void
46
- * @public
47
- */
41
+ * Shared CRDT conflict resolution logic
42
+ * @public
43
+ */
48
44
  function crdtRuleForCurrentState(message) {
49
45
  const { entityId, timestamp } = message;
50
46
  const currentTimestamp = timestamps.get(entityId);
@@ -54,7 +50,6 @@ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSent
54
50
  }
55
51
  // Outdated Message. Resend our state message through the wire.
56
52
  if (currentTimestamp > timestamp) {
57
- // console.log('2', currentTimestamp, timestamp)
58
53
  return crdt_1.ProcessMessageResultType.StateOutdatedTimestamp;
59
54
  }
60
55
  // Deletes are idempotent
@@ -71,7 +66,6 @@ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSent
71
66
  currentDataGreater = (0, utils_1.dataCompare)(null, message.data);
72
67
  }
73
68
  // Same data, same timestamp. Weirdo echo message.
74
- // console.log('3', currentDataGreater, writeBuffer.toBinary(), (message as any).data || null)
75
69
  if (currentDataGreater === 0) {
76
70
  return crdt_1.ProcessMessageResultType.NoChanges;
77
71
  }
@@ -80,10 +74,37 @@ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSent
80
74
  return crdt_1.ProcessMessageResultType.StateOutdatedData;
81
75
  }
82
76
  else {
83
- // Curent data is lower
77
+ // Current data is lower
84
78
  return crdt_1.ProcessMessageResultType.StateUpdatedData;
85
79
  }
86
80
  }
81
+ return crdtRuleForCurrentState;
82
+ }
83
+ exports.createCrdtRuleValidator = createCrdtRuleValidator;
84
+ function createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data) {
85
+ /**
86
+ * Force update component state regardless of timestamp - used for server authoritative messages
87
+ */
88
+ return (msg) => {
89
+ const buffer = new ByteBuffer_1.ReadWriteByteBuffer(msg.data);
90
+ const deserializedValue = schema.deserialize(buffer);
91
+ data.set(msg.entityId, deserializedValue);
92
+ timestamps.set(msg.entityId, msg.timestamp);
93
+ return [null, deserializedValue];
94
+ };
95
+ }
96
+ exports.createForceUpdateLwwFromCrdt = createForceUpdateLwwFromCrdt;
97
+ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData) {
98
+ /**
99
+ * Process the received message only if the lamport number recieved is higher
100
+ * than the stored one. If its lower, we spread it to the network to correct the peer.
101
+ * If they are equal, the bigger raw data wins.
102
+
103
+ * Returns the recieved data if the lamport number was bigger than ours.
104
+ * If it was an outdated message, then we return void
105
+ * @public
106
+ */
107
+ const crdtRuleForCurrentState = createCrdtRuleValidator(timestamps, schema, data, lastSentData);
87
108
  return (msg) => {
88
109
  /* istanbul ignore next */
89
110
  if (msg.type !== crdt_1.CrdtMessageType.PUT_COMPONENT &&
@@ -101,7 +122,10 @@ function createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSent
101
122
  if (msg.type === crdt_1.CrdtMessageType.PUT_COMPONENT || msg.type === crdt_1.CrdtMessageType.PUT_COMPONENT_NETWORK) {
102
123
  const buf = new ByteBuffer_1.ReadWriteByteBuffer(msg.data);
103
124
  data.set(entity, schema.deserialize(buf));
104
- lastSentData.set(entity, new Uint8Array(msg.data));
125
+ // do NOT seed lastSentData from an INCOMING message!!!!
126
+ // seeding it from received bytes makes the engine
127
+ // believe it already sent this state, which kills valid re-broadcasting 🧨
128
+ lastSentData.delete(entity);
105
129
  }
106
130
  else {
107
131
  data.delete(entity);
@@ -192,6 +216,7 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
192
216
  const timestamps = new Map();
193
217
  const lastSentData = new Map();
194
218
  const onChangeCallbacks = new Map();
219
+ const validateCallbacks = new Map();
195
220
  return {
196
221
  get componentId() {
197
222
  return componentId;
@@ -292,7 +317,39 @@ function createComponentDefinitionFromSchema(componentName, componentId, schema)
292
317
  },
293
318
  getCrdtUpdates: createGetCrdtMessagesForLww(componentId, timestamps, dirtyIterator, schema, data, lastSentData),
294
319
  updateFromCrdt: createUpdateLwwFromCrdt(componentId, timestamps, schema, data, lastSentData),
320
+ __forceUpdateFromCrdt: createForceUpdateLwwFromCrdt(componentId, timestamps, schema, data),
321
+ __dry_run_updateFromCrdt: createCrdtRuleValidator(timestamps, schema, data, lastSentData),
295
322
  dumpCrdtStateToBuffer: createDumpLwwFunctionFromCrdt(componentId, timestamps, schema, data),
323
+ validateBeforeChange(entityOrCb, cb) {
324
+ if (arguments.length === 1) {
325
+ // Second overload: just callback (global validation)
326
+ validateCallbacks.set(__GLOBAL_ENTITY, entityOrCb);
327
+ }
328
+ else {
329
+ if (cb) {
330
+ validateCallbacks.set(entityOrCb, cb);
331
+ }
332
+ }
333
+ },
334
+ __run_validateBeforeChange(entity, newValue, senderAddress, createdBy) {
335
+ const cb = entity && validateCallbacks.get(entity);
336
+ const globalCb = validateCallbacks.get(__GLOBAL_ENTITY);
337
+ const currentValue = data.get(entity);
338
+ const value = { entity, currentValue, newValue, senderAddress, createdBy };
339
+ const globalResult = globalCb?.(value) ?? true;
340
+ const entityResult = (globalResult && cb?.(value)) ?? true;
341
+ return globalResult && entityResult;
342
+ },
343
+ getCrdtState(entity) {
344
+ const componentData = data.get(entity);
345
+ const timestamp = timestamps.get(entity);
346
+ if (componentData && timestamp !== undefined) {
347
+ const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
348
+ schema.serialize((0, readonly_1.deepReadonly)(componentData), buffer);
349
+ return { data: buffer.toBinary(), timestamp };
350
+ }
351
+ return null;
352
+ },
296
353
  onChange(entity, cb) {
297
354
  const cbs = onChangeCallbacks.get(entity) ?? [];
298
355
  cbs.push(cb);
@@ -16,7 +16,7 @@ export * from './systems/triggerArea';
16
16
  export * from './systems/physics';
17
17
  export * from './engine/entity';
18
18
  export * from './components/types';
19
- import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioAnalysisComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ParticleSystemComponentDefinitionExtended, TouchScreenControlsComponentDefinitionExtended } from './components/types';
19
+ import { MaterialComponentDefinitionExtended, MeshColliderComponentDefinitionExtended, MeshRendererComponentDefinitionExtended, TransformComponentExtended, AnimatorComponentDefinitionExtended, AudioSourceComponentDefinitionExtended, AudioAnalysisComponentDefinitionExtended, AudioStreamComponentDefinitionExtended, ISyncComponents, TweenComponentDefinitionExtended, INetowrkEntity, INetowrkParent, VirtualCameraComponentDefinitionExtended, InputModifierComponentDefinitionExtended, LightSourceComponentDefinitionExtended, TriggerAreaComponentDefinitionExtended, ParticleSystemComponentDefinitionExtended, ICreatedBy, TouchScreenControlsComponentDefinitionExtended } from './components/types';
20
20
  import { NameComponent } from './components/manual/Name';
21
21
  import { TagsComponentDefinitionExtended } from './components/manual/Tags';
22
22
  export declare const Transform: TransformComponentExtended;
@@ -52,6 +52,7 @@ export declare const NetworkEntity: INetowrkEntity;
52
52
  * Tag a entity to be syncronized through comms
53
53
  */
54
54
  export declare const NetworkParent: INetowrkParent;
55
+ export declare const CreatedBy: ICreatedBy;
55
56
  export * from './components/generated/global.gen';
56
57
  export * from './components/generated/types.gen';
57
58
  export * from './serialization/crdt';
package/dist-cjs/index.js CHANGED
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.TouchScreenControls = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
29
+ exports.CreatedBy = exports.NetworkParent = exports.NetworkEntity = exports.SyncComponents = exports.TouchScreenControls = exports.ParticleSystem = exports.TriggerArea = exports.LightSource = exports.InputModifier = exports.VirtualCamera = exports.Tween = exports.Tags = exports.Name = exports.MeshCollider = exports.MeshRenderer = exports.Material = exports.AudioStream = exports.AudioAnalysis = exports.AudioSource = exports.Animator = exports.Transform = exports.components = exports.cyclicParentingChecker = void 0;
30
30
  // The order of the following imports matters. Please do not auto-sort
31
31
  __exportStar(require("./engine"), exports);
32
32
  __exportStar(require("./schemas"), exports);
@@ -87,6 +87,7 @@ exports.NetworkEntity = components.NetworkEntity(initialization_1.engine);
87
87
  * Tag a entity to be syncronized through comms
88
88
  */
89
89
  exports.NetworkParent = components.NetworkParent(initialization_1.engine);
90
+ exports.CreatedBy = components.CreatedBy(initialization_1.engine);
90
91
  // export components for global engine
91
92
  __exportStar(require("./components/generated/global.gen"), exports);
92
93
  __exportStar(require("./components/generated/types.gen"), exports);
@@ -0,0 +1,15 @@
1
+ import { Entity } from '../../engine/entity';
2
+ import { ByteBuffer } from '../ByteBuffer';
3
+ import { AuthoritativePutComponentMessage } from './types';
4
+ /**
5
+ * @public
6
+ */
7
+ export declare namespace AuthoritativePutComponentOperation {
8
+ const 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: Entity, timestamp: number, componentId: number, data: Uint8Array, buf: ByteBuffer): void;
14
+ function read(buf: ByteBuffer): AuthoritativePutComponentMessage | null;
15
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthoritativePutComponentOperation = void 0;
4
+ const crdtMessageProtocol_1 = require("./crdtMessageProtocol");
5
+ const types_1 = require("./types");
6
+ /**
7
+ * @public
8
+ */
9
+ var AuthoritativePutComponentOperation;
10
+ (function (AuthoritativePutComponentOperation) {
11
+ AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH = 16;
12
+ /**
13
+ * Call this function for an optimal writing data passing the ByteBuffer
14
+ * already allocated
15
+ */
16
+ function write(entity, timestamp, componentId, data, buf) {
17
+ // reserve the beginning
18
+ const startMessageOffset = buf.incrementWriteOffset(types_1.CRDT_MESSAGE_HEADER_LENGTH + AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH);
19
+ // write body
20
+ buf.writeBuffer(data, false);
21
+ const messageLength = buf.currentWriteOffset() - startMessageOffset;
22
+ // Write CrdtMessage header
23
+ buf.setUint32(startMessageOffset, messageLength);
24
+ buf.setUint32(startMessageOffset + 4, types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT);
25
+ // Write ComponentOperation header
26
+ buf.setUint32(startMessageOffset + 8, entity);
27
+ buf.setUint32(startMessageOffset + 12, componentId);
28
+ buf.setUint32(startMessageOffset + 16, timestamp);
29
+ const newLocal = messageLength - AuthoritativePutComponentOperation.MESSAGE_HEADER_LENGTH - types_1.CRDT_MESSAGE_HEADER_LENGTH;
30
+ buf.setUint32(startMessageOffset + 20, newLocal);
31
+ }
32
+ AuthoritativePutComponentOperation.write = write;
33
+ function read(buf) {
34
+ const header = crdtMessageProtocol_1.CrdtMessageProtocol.readHeader(buf);
35
+ if (!header) {
36
+ return null;
37
+ }
38
+ if (header.type !== types_1.CrdtMessageType.AUTHORITATIVE_PUT_COMPONENT) {
39
+ throw new Error('AuthoritativePutComponentOperation tried to read another message type.');
40
+ }
41
+ return {
42
+ ...header,
43
+ entityId: buf.readUint32(),
44
+ componentId: buf.readUint32(),
45
+ timestamp: buf.readUint32(),
46
+ data: buf.readBuffer()
47
+ };
48
+ }
49
+ AuthoritativePutComponentOperation.read = read;
50
+ })(AuthoritativePutComponentOperation = exports.AuthoritativePutComponentOperation || (exports.AuthoritativePutComponentOperation = {}));
@@ -7,3 +7,4 @@ export * from './network/deleteComponentNetwork';
7
7
  export * from './network/deleteEntityNetwork';
8
8
  export * from './types';
9
9
  export * from './crdtMessageProtocol';
10
+ export * from './authoritativePutComponent';
@@ -23,3 +23,4 @@ __exportStar(require("./network/deleteComponentNetwork"), exports);
23
23
  __exportStar(require("./network/deleteEntityNetwork"), exports);
24
24
  __exportStar(require("./types"), exports);
25
25
  __exportStar(require("./crdtMessageProtocol"), exports);
26
+ __exportStar(require("./authoritativePutComponent"), exports);