@colyseus/schema 5.0.8 → 5.0.9

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.
@@ -103,6 +103,14 @@ export declare function getPropertyDescriptor(fieldName: string, fieldIndex: num
103
103
  * The previous `@type()` annotation should remain along with this one.
104
104
  */
105
105
  export declare function deprecated(throws?: boolean): PropertyDecorator;
106
+ /**
107
+ * Adds synchronizable fields to an existing `Schema` subclass — the pre-5.0
108
+ * helper for plain JavaScript users.
109
+ *
110
+ * @deprecated Use `schema()` with `t.*` field builders instead:
111
+ * https://docs.colyseus.io/state/schema
112
+ */
113
+ export declare function defineTypes(target: typeof Schema, fields: Definition, options?: TypeOptions): typeof Schema;
106
114
  type ExtractInitProps<T> = T extends {
107
115
  initialize: (...args: infer P) => void;
108
116
  } ? P extends readonly [] ? never : P extends readonly [infer First] ? First extends object ? First : P : P : BuilderInitProps<T>;
@@ -209,6 +209,7 @@ function getInheritanceTree(klass, allClasses, includeSelf = true) {
209
209
  let currentStructure;
210
210
  let currentProperty;
211
211
  let globalContext;
212
+ let defineTypesWarned = false;
212
213
  const BUILDER_COLLECTION_KINDS = new Set(["array", "map", "set", "collection"]);
213
214
  /**
214
215
  * For a t.*().chain().calls() expression, walk down to the base `t.X(...)`
@@ -419,6 +420,34 @@ function inspectNode(node, context, decoratorName) {
419
420
  defineProperty(property, prop.initializer);
420
421
  }
421
422
  }
423
+ else if (node.getText() === "defineTypes" &&
424
+ (node.parent.kind === ts__namespace.SyntaxKind.CallExpression ||
425
+ node.parent.kind === ts__namespace.SyntaxKind.PropertyAccessExpression)) {
426
+ /**
427
+ * JavaScript source file (`.js`)
428
+ * Using `defineTypes()` (deprecated)
429
+ */
430
+ const callExpression = (node.parent.kind === ts__namespace.SyntaxKind.PropertyAccessExpression)
431
+ ? node.parent.parent
432
+ : node.parent;
433
+ if (callExpression.kind !== ts__namespace.SyntaxKind.CallExpression) {
434
+ break;
435
+ }
436
+ if (!defineTypesWarned) {
437
+ defineTypesWarned = true;
438
+ console.warn("schema-codegen: defineTypes() is deprecated and will be removed in a future release. Use schema() with t.* field builders instead → https://docs.colyseus.io/state/schema");
439
+ }
440
+ const className = callExpression.arguments[0].getText();
441
+ currentStructure.name = className;
442
+ const types = callExpression.arguments[1];
443
+ for (let i = 0; i < types.properties.length; i++) {
444
+ const prop = types.properties[i];
445
+ const property = currentProperty || new Property();
446
+ property.name = prop.name.escapedText;
447
+ currentStructure.addProperty(property);
448
+ defineProperty(property, prop.initializer);
449
+ }
450
+ }
422
451
  if (node.parent.kind === ts__namespace.SyntaxKind.ClassDeclaration) {
423
452
  currentStructure.name = node.getText();
424
453
  }