@noormdev/sdk 1.0.0-alpha.22 → 1.0.0-alpha.24
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 +32 -5
- package/dist/index.js +69 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3696,7 +3696,7 @@ export declare class NoormOps {
|
|
|
3696
3696
|
* the impersonated principal. Mirrors Context's query surface without
|
|
3697
3697
|
* lifecycle or noorm ops.
|
|
3698
3698
|
*/
|
|
3699
|
-
export interface ImpersonatedScope<DB = unknown, Procs = object, Funcs = object> {
|
|
3699
|
+
export interface ImpersonatedScope<DB = unknown, Procs = object, Funcs = object, Tvfs = object> {
|
|
3700
3700
|
kysely: Kysely<DB>;
|
|
3701
3701
|
proc: <T = unknown, N extends keyof Procs & string = keyof Procs & string>(name: N, ...args: Procs[N] extends void ? [
|
|
3702
3702
|
] : [
|
|
@@ -3708,6 +3708,10 @@ export interface ImpersonatedScope<DB = unknown, Procs = object, Funcs = object>
|
|
|
3708
3708
|
params: Funcs[N],
|
|
3709
3709
|
column: string
|
|
3710
3710
|
]) => Promise<T>;
|
|
3711
|
+
tvf: <T = unknown, N extends keyof Tvfs & string = keyof Tvfs & string>(name: N, ...args: Tvfs[N] extends void ? [
|
|
3712
|
+
] : [
|
|
3713
|
+
params: Tvfs[N]
|
|
3714
|
+
]) => Promise<T[]>;
|
|
3711
3715
|
transaction: <T>(fn: (trx: Transaction<DB>) => Promise<T>) => Promise<T>;
|
|
3712
3716
|
revert: () => Promise<void>;
|
|
3713
3717
|
}
|
|
@@ -3743,7 +3747,7 @@ export declare class ImpersonationError extends Error {
|
|
|
3743
3747
|
* await ctx.disconnect()
|
|
3744
3748
|
* ```
|
|
3745
3749
|
*/
|
|
3746
|
-
export declare class Context<DB = unknown, Procs = object, Funcs = object> {
|
|
3750
|
+
export declare class Context<DB = unknown, Procs = object, Funcs = object, Tvfs = object> {
|
|
3747
3751
|
#private;
|
|
3748
3752
|
constructor(config: Config, settings: Settings, identity: Identity, options: CreateContextOptions, projectRoot: string);
|
|
3749
3753
|
get dialect(): Dialect;
|
|
@@ -3835,6 +3839,29 @@ export declare class Context<DB = unknown, Procs = object, Funcs = object> {
|
|
|
3835
3839
|
params: Funcs[N],
|
|
3836
3840
|
column: string
|
|
3837
3841
|
]): Promise<T>;
|
|
3842
|
+
/**
|
|
3843
|
+
* Call a table-valued function and return the result set.
|
|
3844
|
+
*
|
|
3845
|
+
* Generates SELECT * FROM name(...) with dialect-specific parameter
|
|
3846
|
+
* syntax. Returns multiple rows, unlike func() which returns a scalar.
|
|
3847
|
+
* Only supported on MSSQL and PostgreSQL — MySQL and SQLite throw.
|
|
3848
|
+
*
|
|
3849
|
+
* @example
|
|
3850
|
+
* ```typescript
|
|
3851
|
+
* // Named params
|
|
3852
|
+
* const sessions = await ctx.tvf<Session>('validate_session', { session_key: key });
|
|
3853
|
+
*
|
|
3854
|
+
* // Positional params
|
|
3855
|
+
* const results = await ctx.tvf<Result>('search_products', ['widget', 100]);
|
|
3856
|
+
*
|
|
3857
|
+
* // No params
|
|
3858
|
+
* const items = await ctx.tvf<Item>('get_active_items');
|
|
3859
|
+
* ```
|
|
3860
|
+
*/
|
|
3861
|
+
tvf<T = unknown, N extends keyof Tvfs & string = keyof Tvfs & string>(name: N, ...args: Tvfs[N] extends void ? [
|
|
3862
|
+
] : [
|
|
3863
|
+
params: Tvfs[N]
|
|
3864
|
+
]): Promise<T[]>;
|
|
3838
3865
|
/**
|
|
3839
3866
|
* Execute queries as a specific database principal.
|
|
3840
3867
|
*
|
|
@@ -3855,8 +3882,8 @@ export declare class Context<DB = unknown, Procs = object, Funcs = object> {
|
|
|
3855
3882
|
* await scope.revert();
|
|
3856
3883
|
* ```
|
|
3857
3884
|
*/
|
|
3858
|
-
impersonate<T>(username: string, fn: (scope: ImpersonatedScope<DB, Procs, Funcs>) => Promise<T>): Promise<T>;
|
|
3859
|
-
impersonate(username: string): Promise<ImpersonatedScope<DB, Procs, Funcs>>;
|
|
3885
|
+
impersonate<T>(username: string, fn: (scope: ImpersonatedScope<DB, Procs, Funcs, Tvfs>) => Promise<T>): Promise<T>;
|
|
3886
|
+
impersonate(username: string): Promise<ImpersonatedScope<DB, Procs, Funcs, Tvfs>>;
|
|
3860
3887
|
}
|
|
3861
3888
|
/**
|
|
3862
3889
|
* Error thrown when requireTest is enabled but config.isTest is false.
|
|
@@ -3925,7 +3952,7 @@ export declare class ProtectedConfigError extends Error {
|
|
|
3925
3952
|
* const ctx = await createContext()
|
|
3926
3953
|
* ```
|
|
3927
3954
|
*/
|
|
3928
|
-
export declare function createContext<DB = unknown, Procs = object, Funcs = object>(options?: CreateContextOptions): Promise<Context<DB, Procs, Funcs>>;
|
|
3955
|
+
export declare function createContext<DB = unknown, Procs = object, Funcs = object, Tvfs = object>(options?: CreateContextOptions): Promise<Context<DB, Procs, Funcs, Tvfs>>;
|
|
3929
3956
|
|
|
3930
3957
|
export {
|
|
3931
3958
|
Lock$1 as Lock,
|
package/dist/index.js
CHANGED
|
@@ -14712,6 +14712,10 @@ var LoggingConfigSchema = external_exports.object({
|
|
|
14712
14712
|
maxSize: FileSizeSchema.default("10mb"),
|
|
14713
14713
|
maxFiles: external_exports.number().int().min(1).default(5)
|
|
14714
14714
|
});
|
|
14715
|
+
var TeardownConfigSchema = external_exports.object({
|
|
14716
|
+
preserveTables: external_exports.array(external_exports.string()).optional(),
|
|
14717
|
+
postScript: external_exports.string().optional()
|
|
14718
|
+
});
|
|
14715
14719
|
var SettingsSchema = external_exports.object({
|
|
14716
14720
|
build: BuildConfigSchema.optional(),
|
|
14717
14721
|
paths: PathConfigSchema.optional(),
|
|
@@ -14719,7 +14723,8 @@ var SettingsSchema = external_exports.object({
|
|
|
14719
14723
|
stages: external_exports.record(external_exports.string(), StageSchema).optional(),
|
|
14720
14724
|
strict: StrictConfigSchema.optional(),
|
|
14721
14725
|
logging: LoggingConfigSchema.optional(),
|
|
14722
|
-
secrets: external_exports.array(StageSecretSchema).optional()
|
|
14726
|
+
secrets: external_exports.array(StageSecretSchema).optional(),
|
|
14727
|
+
teardown: TeardownConfigSchema.optional()
|
|
14723
14728
|
});
|
|
14724
14729
|
var SettingsValidationError = class extends Error {
|
|
14725
14730
|
constructor(message, field, issues) {
|
|
@@ -16823,6 +16828,27 @@ function buildFuncCall(dialect, name, column, params) {
|
|
|
16823
16828
|
const joined = sql.join(values.map((v) => sql`${v}`));
|
|
16824
16829
|
return sql`SELECT ${rawName}(${joined}) AS ${rawCol}`;
|
|
16825
16830
|
}
|
|
16831
|
+
function buildTvfCall(dialect, name, params) {
|
|
16832
|
+
if (dialect === "sqlite") {
|
|
16833
|
+
throw new Error("SQLite does not support table-valued functions.");
|
|
16834
|
+
}
|
|
16835
|
+
if (dialect === "mysql") {
|
|
16836
|
+
throw new Error("MySQL does not support table-valued functions.");
|
|
16837
|
+
}
|
|
16838
|
+
const rawName = sql.raw(name);
|
|
16839
|
+
if (!params || Array.isArray(params) && params.length === 0 || !Array.isArray(params) && Object.keys(params).length === 0) {
|
|
16840
|
+
return sql`SELECT * FROM ${rawName}()`;
|
|
16841
|
+
}
|
|
16842
|
+
if (dialect === "postgres" && !Array.isArray(params)) {
|
|
16843
|
+
const parts = Object.entries(params).map(
|
|
16844
|
+
([key, val]) => sql`${sql.raw(key)} => ${val}`
|
|
16845
|
+
);
|
|
16846
|
+
return sql`SELECT * FROM ${rawName}(${sql.join(parts)})`;
|
|
16847
|
+
}
|
|
16848
|
+
const values = Array.isArray(params) ? params : Object.values(params);
|
|
16849
|
+
const joined = sql.join(values.map((v) => sql`${v}`));
|
|
16850
|
+
return sql`SELECT * FROM ${rawName}(${joined})`;
|
|
16851
|
+
}
|
|
16826
16852
|
function buildMssqlProc(rawName, params) {
|
|
16827
16853
|
if (Array.isArray(params)) {
|
|
16828
16854
|
const joined = sql.join(params.map((v) => sql`${v}`));
|
|
@@ -23017,8 +23043,7 @@ async function fetchDetail(db, dialect, category, name, schema) {
|
|
|
23017
23043
|
var { quote, qualifiedName } = createDialectQuoting({
|
|
23018
23044
|
open: '"',
|
|
23019
23045
|
close: '"',
|
|
23020
|
-
escape: '""'
|
|
23021
|
-
defaultSchema: "public"
|
|
23046
|
+
escape: '""'
|
|
23022
23047
|
});
|
|
23023
23048
|
var postgresTeardownOperations = {
|
|
23024
23049
|
disableForeignKeyChecks() {
|
|
@@ -23092,8 +23117,7 @@ var mysqlTeardownOperations = {
|
|
|
23092
23117
|
var { quote: quote3, qualifiedName: qualifiedName3 } = createDialectQuoting({
|
|
23093
23118
|
open: "[",
|
|
23094
23119
|
close: "]",
|
|
23095
|
-
escape: "]]"
|
|
23096
|
-
defaultSchema: "dbo"
|
|
23120
|
+
escape: "]]"
|
|
23097
23121
|
});
|
|
23098
23122
|
var mssqlTeardownOperations = {
|
|
23099
23123
|
disableForeignKeyChecks() {
|
|
@@ -27215,6 +27239,12 @@ function buildScope(db, revertFn, dialect) {
|
|
|
27215
27239
|
const result = await query.execute(db);
|
|
27216
27240
|
return result.rows?.[0] ?? null;
|
|
27217
27241
|
},
|
|
27242
|
+
async tvf(name, ...args) {
|
|
27243
|
+
const params = args[0];
|
|
27244
|
+
const query = buildTvfCall(dialect, name, params);
|
|
27245
|
+
const result = await query.execute(db);
|
|
27246
|
+
return result.rows ?? [];
|
|
27247
|
+
},
|
|
27218
27248
|
async transaction(fn) {
|
|
27219
27249
|
return db.transaction().execute(fn);
|
|
27220
27250
|
},
|
|
@@ -27382,6 +27412,40 @@ var Context = class {
|
|
|
27382
27412
|
const result = await query.execute(this.kysely);
|
|
27383
27413
|
return result.rows?.[0] ?? null;
|
|
27384
27414
|
}
|
|
27415
|
+
// ─────────────────────────────────────────────────────────
|
|
27416
|
+
// Table-Valued Functions
|
|
27417
|
+
// ─────────────────────────────────────────────────────────
|
|
27418
|
+
/**
|
|
27419
|
+
* Call a table-valued function and return the result set.
|
|
27420
|
+
*
|
|
27421
|
+
* Generates SELECT * FROM name(...) with dialect-specific parameter
|
|
27422
|
+
* syntax. Returns multiple rows, unlike func() which returns a scalar.
|
|
27423
|
+
* Only supported on MSSQL and PostgreSQL — MySQL and SQLite throw.
|
|
27424
|
+
*
|
|
27425
|
+
* @example
|
|
27426
|
+
* ```typescript
|
|
27427
|
+
* // Named params
|
|
27428
|
+
* const sessions = await ctx.tvf<Session>('validate_session', { session_key: key });
|
|
27429
|
+
*
|
|
27430
|
+
* // Positional params
|
|
27431
|
+
* const results = await ctx.tvf<Result>('search_products', ['widget', 100]);
|
|
27432
|
+
*
|
|
27433
|
+
* // No params
|
|
27434
|
+
* const items = await ctx.tvf<Item>('get_active_items');
|
|
27435
|
+
* ```
|
|
27436
|
+
*/
|
|
27437
|
+
async tvf(name, ...args) {
|
|
27438
|
+
if (this.dialect === "sqlite") {
|
|
27439
|
+
throw new Error("SQLite does not support table-valued functions.");
|
|
27440
|
+
}
|
|
27441
|
+
if (this.dialect === "mysql") {
|
|
27442
|
+
throw new Error("MySQL does not support table-valued functions.");
|
|
27443
|
+
}
|
|
27444
|
+
const params = args[0];
|
|
27445
|
+
const query = buildTvfCall(this.dialect, name, params);
|
|
27446
|
+
const result = await query.execute(this.kysely);
|
|
27447
|
+
return result.rows ?? [];
|
|
27448
|
+
}
|
|
27385
27449
|
async impersonate(username, fn) {
|
|
27386
27450
|
const strategy = dialectStrategy[this.dialect];
|
|
27387
27451
|
if (!strategy) {
|