@noormdev/sdk 1.0.0-alpha.24 → 1.0.0-alpha.25

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/dist/index.d.ts CHANGED
@@ -1971,6 +1971,38 @@ export interface ImportOptions {
1971
1971
  /** Truncate target table before import. Default: false. */
1972
1972
  truncate?: boolean;
1973
1973
  }
1974
+ /**
1975
+ * Extract the args type from a proc/func/tvf entry.
1976
+ *
1977
+ * Supports tuple form `[Args, Return]` and plain `void`.
1978
+ * Non-tuple entries pass through as-is for backward compat.
1979
+ *
1980
+ * @example
1981
+ * ```typescript
1982
+ * ExtractArgs<[{ id: number }, User]> // { id: number }
1983
+ * ExtractArgs<void> // void
1984
+ * ```
1985
+ */
1986
+ export type ExtractArgs<E> = E extends [
1987
+ infer A,
1988
+ unknown
1989
+ ] ? A : E;
1990
+ /**
1991
+ * Extract the return type from a proc/func/tvf entry.
1992
+ *
1993
+ * Returns the second element of a `[Args, Return]` tuple.
1994
+ * Falls back to `unknown` for `void` or non-tuple entries.
1995
+ *
1996
+ * @example
1997
+ * ```typescript
1998
+ * ExtractReturn<[{ id: number }, User]> // User
1999
+ * ExtractReturn<void> // unknown
2000
+ * ```
2001
+ */
2002
+ export type ExtractReturn<E> = E extends [
2003
+ unknown,
2004
+ infer R
2005
+ ] ? R : unknown;
1974
2006
  export interface ContextState {
1975
2007
  connection: ConnectionResult | null;
1976
2008
  config: Config;
@@ -3698,19 +3730,19 @@ export declare class NoormOps {
3698
3730
  */
3699
3731
  export interface ImpersonatedScope<DB = unknown, Procs = object, Funcs = object, Tvfs = object> {
3700
3732
  kysely: Kysely<DB>;
3701
- proc: <T = unknown, N extends keyof Procs & string = keyof Procs & string>(name: N, ...args: Procs[N] extends void ? [
3733
+ proc: <N extends keyof Procs & string = keyof Procs & string, T = ExtractReturn<Procs[N]>>(name: N, ...args: ExtractArgs<Procs[N]> extends void ? [
3702
3734
  ] : [
3703
- params: Procs[N]
3735
+ params: ExtractArgs<Procs[N]>
3704
3736
  ]) => Promise<T[]>;
3705
- func: <T = unknown, N extends keyof Funcs & string = keyof Funcs & string>(name: N, ...args: Funcs[N] extends void ? [
3737
+ func: <N extends keyof Funcs & string = keyof Funcs & string, T = ExtractReturn<Funcs[N]>>(name: N, ...args: ExtractArgs<Funcs[N]> extends void ? [
3706
3738
  column: string
3707
3739
  ] : [
3708
- params: Funcs[N],
3740
+ params: ExtractArgs<Funcs[N]>,
3709
3741
  column: string
3710
3742
  ]) => Promise<T>;
3711
- tvf: <T = unknown, N extends keyof Tvfs & string = keyof Tvfs & string>(name: N, ...args: Tvfs[N] extends void ? [
3743
+ tvf: <N extends keyof Tvfs & string = keyof Tvfs & string, T = ExtractReturn<Tvfs[N]>>(name: N, ...args: ExtractArgs<Tvfs[N]> extends void ? [
3712
3744
  ] : [
3713
- params: Tvfs[N]
3745
+ params: ExtractArgs<Tvfs[N]>
3714
3746
  ]) => Promise<T[]>;
3715
3747
  transaction: <T>(fn: (trx: Transaction<DB>) => Promise<T>) => Promise<T>;
3716
3748
  revert: () => Promise<void>;
@@ -3801,8 +3833,11 @@ export declare class Context<DB = unknown, Procs = object, Funcs = object, Tvfs
3801
3833
  *
3802
3834
  * @example
3803
3835
  * ```typescript
3804
- * // Named params
3805
- * const users = await ctx.proc<User>('get_users', { department_id: 1 });
3836
+ * // Return type inferred from tuple definition
3837
+ * const users = await ctx.proc('get_users', { department_id: 1 });
3838
+ *
3839
+ * // Explicit return type override
3840
+ * const users = await ctx.proc<'get_users', SpecialUser>('get_users', { department_id: 1 });
3806
3841
  *
3807
3842
  * // Positional params
3808
3843
  * await ctx.proc('simple_proc', [42, 'hello']);
@@ -3811,9 +3846,9 @@ export declare class Context<DB = unknown, Procs = object, Funcs = object, Tvfs
3811
3846
  * await ctx.proc('refresh_cache');
3812
3847
  * ```
3813
3848
  */
3814
- proc<T = unknown, N extends keyof Procs & string = keyof Procs & string>(name: N, ...args: Procs[N] extends void ? [
3849
+ proc<N extends keyof Procs & string = keyof Procs & string, T = ExtractReturn<Procs[N]>>(name: N, ...args: ExtractArgs<Procs[N]> extends void ? [
3815
3850
  ] : [
3816
- params: Procs[N]
3851
+ params: ExtractArgs<Procs[N]>
3817
3852
  ]): Promise<T[]>;
3818
3853
  /**
3819
3854
  * Call a database function and return the scalar result.
@@ -3823,20 +3858,20 @@ export declare class Context<DB = unknown, Procs = object, Funcs = object, Tvfs
3823
3858
  *
3824
3859
  * @example
3825
3860
  * ```typescript
3826
- * // Named params + column alias
3827
- * const result = await ctx.func<{ total: number }>('calc_total', { order_id: 42 }, 'total');
3861
+ * // Return type inferred from tuple definition
3862
+ * const result = await ctx.func('calc_total', { order_id: 42 }, 'total');
3828
3863
  *
3829
- * // Positional params + column alias
3830
- * const sum = await ctx.func<{ result: number }>('add_numbers', [1, 2], 'result');
3864
+ * // Explicit return type override
3865
+ * const result = await ctx.func<'calc_total', { total: number }>('calc_total', { order_id: 42 }, 'total');
3831
3866
  *
3832
3867
  * // No params — just column alias
3833
- * const ver = await ctx.func<{ v: string }>('get_version', 'v');
3868
+ * const ver = await ctx.func('get_version', 'v');
3834
3869
  * ```
3835
3870
  */
3836
- func<T = unknown, N extends keyof Funcs & string = keyof Funcs & string>(name: N, ...args: Funcs[N] extends void ? [
3871
+ func<N extends keyof Funcs & string = keyof Funcs & string, T = ExtractReturn<Funcs[N]>>(name: N, ...args: ExtractArgs<Funcs[N]> extends void ? [
3837
3872
  column: string
3838
3873
  ] : [
3839
- params: Funcs[N],
3874
+ params: ExtractArgs<Funcs[N]>,
3840
3875
  column: string
3841
3876
  ]): Promise<T>;
3842
3877
  /**
@@ -3848,19 +3883,19 @@ export declare class Context<DB = unknown, Procs = object, Funcs = object, Tvfs
3848
3883
  *
3849
3884
  * @example
3850
3885
  * ```typescript
3851
- * // Named params
3852
- * const sessions = await ctx.tvf<Session>('validate_session', { session_key: key });
3886
+ * // Return type inferred from tuple definition
3887
+ * const sessions = await ctx.tvf('validate_session', { session_key: key });
3853
3888
  *
3854
- * // Positional params
3855
- * const results = await ctx.tvf<Result>('search_products', ['widget', 100]);
3889
+ * // Explicit return type override
3890
+ * const sessions = await ctx.tvf<'validate_session', SpecialSession>('validate_session', { session_key: key });
3856
3891
  *
3857
3892
  * // No params
3858
- * const items = await ctx.tvf<Item>('get_active_items');
3893
+ * const items = await ctx.tvf('get_active_items');
3859
3894
  * ```
3860
3895
  */
3861
- tvf<T = unknown, N extends keyof Tvfs & string = keyof Tvfs & string>(name: N, ...args: Tvfs[N] extends void ? [
3896
+ tvf<N extends keyof Tvfs & string = keyof Tvfs & string, T = ExtractReturn<Tvfs[N]>>(name: N, ...args: ExtractArgs<Tvfs[N]> extends void ? [
3862
3897
  ] : [
3863
- params: Tvfs[N]
3898
+ params: ExtractArgs<Tvfs[N]>
3864
3899
  ]): Promise<T[]>;
3865
3900
  /**
3866
3901
  * Execute queries as a specific database principal.
package/dist/index.js CHANGED
@@ -27364,8 +27364,11 @@ var Context = class {
27364
27364
  *
27365
27365
  * @example
27366
27366
  * ```typescript
27367
- * // Named params
27368
- * const users = await ctx.proc<User>('get_users', { department_id: 1 });
27367
+ * // Return type inferred from tuple definition
27368
+ * const users = await ctx.proc('get_users', { department_id: 1 });
27369
+ *
27370
+ * // Explicit return type override
27371
+ * const users = await ctx.proc<'get_users', SpecialUser>('get_users', { department_id: 1 });
27369
27372
  *
27370
27373
  * // Positional params
27371
27374
  * await ctx.proc('simple_proc', [42, 'hello']);
@@ -27391,14 +27394,14 @@ var Context = class {
27391
27394
  *
27392
27395
  * @example
27393
27396
  * ```typescript
27394
- * // Named params + column alias
27395
- * const result = await ctx.func<{ total: number }>('calc_total', { order_id: 42 }, 'total');
27397
+ * // Return type inferred from tuple definition
27398
+ * const result = await ctx.func('calc_total', { order_id: 42 }, 'total');
27396
27399
  *
27397
- * // Positional params + column alias
27398
- * const sum = await ctx.func<{ result: number }>('add_numbers', [1, 2], 'result');
27400
+ * // Explicit return type override
27401
+ * const result = await ctx.func<'calc_total', { total: number }>('calc_total', { order_id: 42 }, 'total');
27399
27402
  *
27400
27403
  * // No params — just column alias
27401
- * const ver = await ctx.func<{ v: string }>('get_version', 'v');
27404
+ * const ver = await ctx.func('get_version', 'v');
27402
27405
  * ```
27403
27406
  */
27404
27407
  async func(name, ...args) {
@@ -27424,14 +27427,14 @@ var Context = class {
27424
27427
  *
27425
27428
  * @example
27426
27429
  * ```typescript
27427
- * // Named params
27428
- * const sessions = await ctx.tvf<Session>('validate_session', { session_key: key });
27430
+ * // Return type inferred from tuple definition
27431
+ * const sessions = await ctx.tvf('validate_session', { session_key: key });
27429
27432
  *
27430
- * // Positional params
27431
- * const results = await ctx.tvf<Result>('search_products', ['widget', 100]);
27433
+ * // Explicit return type override
27434
+ * const sessions = await ctx.tvf<'validate_session', SpecialSession>('validate_session', { session_key: key });
27432
27435
  *
27433
27436
  * // No params
27434
- * const items = await ctx.tvf<Item>('get_active_items');
27437
+ * const items = await ctx.tvf('get_active_items');
27435
27438
  * ```
27436
27439
  */
27437
27440
  async tvf(name, ...args) {