@tsonic/core 10.0.10 → 10.0.12

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.
package/lang.d.ts CHANGED
@@ -337,6 +337,203 @@ export type Rewrap<TReceiver, TNewShape> =
337
337
  : TNewShape extends void ? void
338
338
  : TNewShape & __TsonicExtCarrier<TReceiver> & __TsonicApplyAllAppliers<TReceiver, TNewShape>;
339
339
 
340
+
341
+
342
+ // ============================================================================
343
+ // Attribute Intrinsics
344
+ // ============================================================================
345
+
346
+ /* eslint-disable @typescript-eslint/no-explicit-any */
347
+
348
+ /**
349
+ * Compiler-only attribute API for Tsonic.
350
+ *
351
+ * Design goals:
352
+ * - Clean, consistent, "compiler-grade" surface area.
353
+ * - Fully type-safe selection of targets (type / ctor / method / property).
354
+ * - Attributes are represented as:
355
+ * - A constructor reference (e.g., ObsoleteAttribute)
356
+ * - Optional ctor args (typed via ConstructorParameters)
357
+ * - Optional helper `A.attr(...)` to build an attribute descriptor (also typed).
358
+ *
359
+ * Runtime note:
360
+ * This module is expected to be erased/ignored by the compiler pipeline.
361
+ */
362
+
363
+ /** A class constructor type. */
364
+ export type Ctor<T = unknown, Args extends readonly any[] = readonly any[]> = new (
365
+ ...args: Args
366
+ ) => T;
367
+
368
+ /** Any attribute class constructor. */
369
+ export type AttributeCtor = Ctor<object, readonly any[]>;
370
+
371
+ /**
372
+ * Extract constructor parameters across multiple overloads.
373
+ *
374
+ * TypeScript's built-in ConstructorParameters<C> collapses overloads to the
375
+ * last signature, which makes attribute ctor typing unusably strict for many
376
+ * .NET attributes.
377
+ */
378
+ export type OverloadedConstructorParameters<C extends AttributeCtor> =
379
+ C extends {
380
+ new (...args: infer A1): any;
381
+ new (...args: infer A2): any;
382
+ new (...args: infer A3): any;
383
+ new (...args: infer A4): any;
384
+ new (...args: infer A5): any;
385
+ }
386
+ ? A1 | A2 | A3 | A4 | A5
387
+ : C extends {
388
+ new (...args: infer A1): any;
389
+ new (...args: infer A2): any;
390
+ new (...args: infer A3): any;
391
+ new (...args: infer A4): any;
392
+ }
393
+ ? A1 | A2 | A3 | A4
394
+ : C extends {
395
+ new (...args: infer A1): any;
396
+ new (...args: infer A2): any;
397
+ new (...args: infer A3): any;
398
+ }
399
+ ? A1 | A2 | A3
400
+ : C extends { new (...args: infer A1): any; new (...args: infer A2): any }
401
+ ? A1 | A2
402
+ : C extends { new (...args: infer A): any }
403
+ ? A
404
+ : never;
405
+
406
+ /** Attribute application (constructor + ctor arguments). */
407
+ export interface AttributeDescriptor<C extends AttributeCtor = AttributeCtor> {
408
+ readonly kind: "attribute";
409
+ readonly ctor: C;
410
+ readonly args: readonly OverloadedConstructorParameters<C>;
411
+ }
412
+
413
+ /** Extract instance type of a constructor. */
414
+ export type InstanceOf<C extends Ctor<any, any>> = C extends Ctor<infer I, any>
415
+ ? I
416
+ : never;
417
+
418
+ /** Keys of T whose values are callable. */
419
+ export type MethodKeys<T> = {
420
+ [K in keyof T]-?: T[K] extends (...args: any[]) => any ? K : never;
421
+ }[keyof T];
422
+
423
+ /** Keys of T whose values are NOT callable (i.e., "properties"). */
424
+ export type PropertyKeys<T> = {
425
+ [K in keyof T]-?: T[K] extends (...args: any[]) => any ? never : K;
426
+ }[keyof T];
427
+
428
+ /**
429
+ * Inferred "method value type" from a method selector.
430
+ * The selector must resolve to a function-valued member on T.
431
+ */
432
+ export type SelectedMethodValue<T> = (...args: any[]) => any;
433
+
434
+ /**
435
+ * Fluent builder returned from A.on(Foo).
436
+ * Allows attaching attributes to:
437
+ * - the type itself
438
+ * - the constructor
439
+ * - a method
440
+ * - a property
441
+ */
442
+ export interface OnBuilder<T> {
443
+ /** Attach attributes to the type declaration (C# class/interface). */
444
+ type: AttributeTargetBuilder;
445
+
446
+ /** Attach attributes to the constructor. */
447
+ ctor: AttributeTargetBuilder;
448
+
449
+ /**
450
+ * Select a method to annotate.
451
+ *
452
+ * The selector must be a simple member access in practice (enforced by compiler),
453
+ * but is typed here as: (t: T) => T[K] where K is a method key.
454
+ *
455
+ * Example:
456
+ * A.on(User).method(u => u.save).add(TransactionAttribute);
457
+ */
458
+ method<K extends MethodKeys<T>>(
459
+ selector: (t: T) => T[K]
460
+ ): AttributeTargetBuilder;
461
+
462
+ /**
463
+ * Select a property to annotate.
464
+ *
465
+ * Example:
466
+ * A.on(User).prop(u => u.name).add(JsonPropertyNameAttribute, "name");
467
+ */
468
+ prop<K extends PropertyKeys<T>>(
469
+ selector: (t: T) => T[K]
470
+ ): AttributeTargetBuilder;
471
+ }
472
+
473
+ /**
474
+ * Target builder that supports adding attributes.
475
+ * Supports two canonical forms:
476
+ * - add(AttrCtor, ...args)
477
+ * - add(A.attr(AttrCtor, ...args))
478
+ */
479
+ export interface AttributeTargetBuilder {
480
+ /**
481
+ * Add an attribute by constructor + arguments.
482
+ *
483
+ * Example:
484
+ * A.on(Config).type.add(ObsoleteAttribute, "Will be removed in v2");
485
+ */
486
+ add<C extends AttributeCtor>(
487
+ ctor: C,
488
+ ...args: OverloadedConstructorParameters<C>
489
+ ): void;
490
+
491
+ /**
492
+ * Add an attribute descriptor produced by A.attr(...).
493
+ *
494
+ * Example:
495
+ * A.on(Config).type.add(A.attr(ObsoleteAttribute, "Will be removed in v2"));
496
+ */
497
+ add<C extends AttributeCtor>(descriptor: AttributeDescriptor<C>): void;
498
+ }
499
+
500
+ /**
501
+ * The main entrypoint.
502
+ *
503
+ * Usage:
504
+ * import { attributes as A } from "@tsonic/core/lang.js";
505
+ *
506
+ * class Config {}
507
+ * A.on(Config).type.add(SerializableAttribute);
508
+ * A.on(Config).type.add(ObsoleteAttribute, "Will be removed in v2");
509
+ *
510
+ * Emits:
511
+ * [System.SerializableAttribute]
512
+ * [System.ObsoleteAttribute("Will be removed in v2")]
513
+ */
514
+ export interface AttributesApi {
515
+ /**
516
+ * Begin targeting a type by passing its constructor.
517
+ */
518
+ on<C extends Ctor<any, any>>(ctor: C): OnBuilder<InstanceOf<C>>;
519
+
520
+ /**
521
+ * Build an attribute descriptor (compiler-known "attribute instance").
522
+ *
523
+ * Example:
524
+ * A.on(Config).type.add(A.attr(ObsoleteAttribute, "Will be removed in v2"));
525
+ */
526
+ attr<C extends AttributeCtor>(
527
+ ctor: C,
528
+ ...args: OverloadedConstructorParameters<C>
529
+ ): AttributeDescriptor<C>;
530
+ }
531
+
532
+ /**
533
+ * Named export used by consumers.
534
+ */
535
+ export declare const attributes: AttributesApi;
536
+
340
537
  // ============================================================================
341
538
  // Span type (for stackalloc return type)
342
539
  // ============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsonic/core",
3
- "version": "10.0.10",
3
+ "version": "10.0.12",
4
4
  "description": "Core type definitions for Tsonic (versioned by .NET major)",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -25,6 +25,6 @@
25
25
  },
26
26
  "homepage": "https://github.com/tsoniclang/core#readme",
27
27
  "peerDependencies": {
28
- "@tsonic/dotnet": "^10.0.1"
28
+ "@tsonic/dotnet": "10.0.12"
29
29
  }
30
30
  }