@memberjunction/ai-vectordb 5.38.0 → 5.39.0

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.
@@ -2,6 +2,7 @@ import { UserInfo } from '@memberjunction/core';
2
2
  import { BaseRequestParams, BaseResponse, CreateIndexParams, EditIndexParams, IndexList, ListVectorIDsParams, ListVectorIDsResult, UpdateOptions, VectorRecord } from "./record.js";
3
3
  import { HybridQueryOptions, QueryOptions } from './query.types.js';
4
4
  import { SharedIndexFilterOptions } from './MetadataFilter.js';
5
+ import { ColocatedQueryOptions, ColocatedQueryResult, IColocatedVectorHost } from './colocated.types.js';
5
6
  export declare abstract class VectorDBBase {
6
7
  private _apiKey;
7
8
  /**
@@ -9,6 +10,17 @@ export declare abstract class VectorDBBase {
9
10
  */
10
11
  protected get ApiKey(): string;
11
12
  constructor(apiKey: string);
13
+ /**
14
+ * True when this driver does not accept ingestion via `CreateRecord(s)` /
15
+ * `UpdateRecord(s)` — implies vectors are managed out-of-band (e.g.
16
+ * `SimpleVectorServiceProvider` reads embeddings directly from
17
+ * `MJ: Entity Record Documents.VectorJSON`). Pipelines that would
18
+ * otherwise call ingestion APIs should short-circuit when this is true
19
+ * to avoid spurious "unsupported" error logs.
20
+ *
21
+ * Subclasses that genuinely support ingestion leave the default `false`.
22
+ */
23
+ get IsReadOnly(): boolean;
12
24
  abstract ListIndexes(): IndexList | Promise<IndexList>;
13
25
  abstract GetIndex(params: BaseRequestParams): BaseResponse | Promise<BaseResponse>;
14
26
  abstract CreateIndex(params: CreateIndexParams): BaseResponse | Promise<BaseResponse>;
@@ -84,5 +96,55 @@ export declare abstract class VectorDBBase {
84
96
  * @returns A native filter object, or undefined if no filters
85
97
  */
86
98
  BuildMetadataFilter(options: SharedIndexFilterOptions): object | undefined;
99
+ /**
100
+ * The host relational connection a colocated provider borrows to store and query
101
+ * vectors in the same database as the application's entity data. `undefined` until
102
+ * {@link SetColocatedHost} (or {@link TryWireColocatedHost}) is called.
103
+ */
104
+ protected ColocatedHost: IColocatedVectorHost | undefined;
105
+ /**
106
+ * Whether this provider stores vectors inside the application's relational database and
107
+ * can resolve query results to entity records without an external mapping hop. Override
108
+ * and return `true` in colocated providers (e.g. `PgVectorColocated`, `SQLServerVectorDatabase`).
109
+ */
110
+ get SupportsColocatedQuery(): boolean;
111
+ /**
112
+ * Wire in the host relational connection so this provider reuses it for colocated
113
+ * storage and queries instead of opening its own pool. No-op semantics for providers
114
+ * that ignore it; colocated providers require it before any operation.
115
+ */
116
+ SetColocatedHost(host: IColocatedVectorHost): void;
117
+ /**
118
+ * Convenience used by callers that hold an opaque provider reference (the active MJ data
119
+ * provider). If `host` implements {@link IColocatedVectorHost} *and* this provider supports
120
+ * colocated queries, wire it in.
121
+ *
122
+ * @returns `true` if the host was wired in, `false` otherwise.
123
+ */
124
+ TryWireColocatedHost(host: unknown): boolean;
125
+ /**
126
+ * Run a colocated query that fuses a vector component with an optional keyword component
127
+ * in a single server-side statement, applying an optional metadata filter. Only meaningful
128
+ * when {@link SupportsColocatedQuery} is `true`; the default implementation throws to surface
129
+ * misuse on providers that don't support it.
130
+ */
131
+ ColocatedQuery(_params: ColocatedQueryOptions, _contextUser?: UserInfo): Promise<ColocatedQueryResult>;
132
+ /**
133
+ * Build a standard SUCCESS {@link BaseResponse}. Shared across all drivers so every
134
+ * provider reports results in a uniform shape.
135
+ *
136
+ * @param data - The provider-specific payload to attach to the response.
137
+ */
138
+ protected wrapSuccessResponse(data: unknown): BaseResponse;
139
+ /**
140
+ * Build a standard FAILURE {@link BaseResponse}.
141
+ *
142
+ * **Always** return this (never a success response) from a `catch` block — returning a
143
+ * success response on error silently swallows real failures and makes callers, and the
144
+ * vectorization pipeline, believe an operation worked when it did not.
145
+ *
146
+ * @param message - Optional human-readable error detail; falls back to a generic message.
147
+ */
148
+ protected wrapFailureResponse(message?: string): BaseResponse;
87
149
  }
88
150
  //# sourceMappingURL=VectorDBBase.d.ts.map
@@ -1 +1 @@
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ated.types.js';
2
3
  export class VectorDBBase {
3
4
  /**
4
5
  * Only sub-classes can access the API key
@@ -11,6 +12,19 @@ export class VectorDBBase {
11
12
  throw new Error('API key cannot be empty');
12
13
  this._apiKey = apiKey;
13
14
  }
15
+ /**
16
+ * True when this driver does not accept ingestion via `CreateRecord(s)` /
17
+ * `UpdateRecord(s)` — implies vectors are managed out-of-band (e.g.
18
+ * `SimpleVectorServiceProvider` reads embeddings directly from
19
+ * `MJ: Entity Record Documents.VectorJSON`). Pipelines that would
20
+ * otherwise call ingestion APIs should short-circuit when this is true
21
+ * to avoid spurious "unsupported" error logs.
22
+ *
23
+ * Subclasses that genuinely support ingestion leave the default `false`.
24
+ */
25
+ get IsReadOnly() {
26
+ return false;
27
+ }
14
28
  /**
15
29
  * Whether this provider supports hybrid (vector + keyword) search.
16
30
  * Override and return true in providers that implement HybridQuery().
@@ -59,5 +73,73 @@ export class VectorDBBase {
59
73
  BuildMetadataFilter(options) {
60
74
  return VectorMetadataFilter.FromOptions(options);
61
75
  }
76
+ /**
77
+ * Whether this provider stores vectors inside the application's relational database and
78
+ * can resolve query results to entity records without an external mapping hop. Override
79
+ * and return `true` in colocated providers (e.g. `PgVectorColocated`, `SQLServerVectorDatabase`).
80
+ */
81
+ get SupportsColocatedQuery() {
82
+ return false;
83
+ }
84
+ /**
85
+ * Wire in the host relational connection so this provider reuses it for colocated
86
+ * storage and queries instead of opening its own pool. No-op semantics for providers
87
+ * that ignore it; colocated providers require it before any operation.
88
+ */
89
+ SetColocatedHost(host) {
90
+ this.ColocatedHost = host;
91
+ }
92
+ /**
93
+ * Convenience used by callers that hold an opaque provider reference (the active MJ data
94
+ * provider). If `host` implements {@link IColocatedVectorHost} *and* this provider supports
95
+ * colocated queries, wire it in.
96
+ *
97
+ * @returns `true` if the host was wired in, `false` otherwise.
98
+ */
99
+ TryWireColocatedHost(host) {
100
+ if (this.SupportsColocatedQuery && IsColocatedVectorHost(host)) {
101
+ this.SetColocatedHost(host);
102
+ return true;
103
+ }
104
+ return false;
105
+ }
106
+ /**
107
+ * Run a colocated query that fuses a vector component with an optional keyword component
108
+ * in a single server-side statement, applying an optional metadata filter. Only meaningful
109
+ * when {@link SupportsColocatedQuery} is `true`; the default implementation throws to surface
110
+ * misuse on providers that don't support it.
111
+ */
112
+ ColocatedQuery(_params, _contextUser) {
113
+ return Promise.reject(new Error('ColocatedQuery is not supported by this provider (SupportsColocatedQuery is false)'));
114
+ }
115
+ /**
116
+ * Build a standard SUCCESS {@link BaseResponse}. Shared across all drivers so every
117
+ * provider reports results in a uniform shape.
118
+ *
119
+ * @param data - The provider-specific payload to attach to the response.
120
+ */
121
+ wrapSuccessResponse(data) {
122
+ return {
123
+ success: true,
124
+ message: '',
125
+ data,
126
+ };
127
+ }
128
+ /**
129
+ * Build a standard FAILURE {@link BaseResponse}.
130
+ *
131
+ * **Always** return this (never a success response) from a `catch` block — returning a
132
+ * success response on error silently swallows real failures and makes callers, and the
133
+ * vectorization pipeline, believe an operation worked when it did not.
134
+ *
135
+ * @param message - Optional human-readable error detail; falls back to a generic message.
136
+ */
137
+ wrapFailureResponse(message) {
138
+ return {
139
+ success: false,
140
+ message: message || 'An error occurred',
141
+ data: null,
142
+ };
143
+ }
62
144
  }
63
145
  //# sourceMappingURL=VectorDBBase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VectorDBBase.js","sourceRoot":"","sources":["../../src/generic/VectorDBBase.ts"],"names":[],"mappings":"AAKA,OAAO,EAA4B,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAElF,MAAM,OAAgB,YAAY;IAE9B;;OAEG;IACH,IAAc,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,YAAa,MAAc;QACvB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAE/C,IAAI,CAAC,OAAO,GAAG,MAA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ED;;;;OAIG;IACI,gBAAgB,CAAC,IAA0B;QAC9C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACI,oBAAoB,CAAC,IAAa;QACrC,IAAI,IAAI,CAAC,sBAAsB,IAAI,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7D,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,OAA8B,EAAE,YAAuB;QACzE,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC,CAAC;IAC3H,CAAC;IAED;;;;;OAKG;IACO,mBAAmB,CAAC,IAAa;QACvC,OAAO;YACH,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,EAAE;YACX,IAAI;SACP,CAAC;IACN,CAAC;IAED;;;;;;;;OAQG;IACO,mBAAmB,CAAC,OAAgB;QAC1C,OAAO;YACH,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,OAAO,IAAI,mBAAmB;YACvC,IAAI,EAAE,IAAI;SACb,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Types and contracts for **colocated** vector search — the case where the
3
+ * application's relational database is *also* the vector store (PostgreSQL + pgvector, or
4
+ * SQL Server 2025 native vectors), rather than a separate remote service (Pinecone, Qdrant).
5
+ *
6
+ * A colocated provider borrows the host data provider's connection via {@link IColocatedVectorHost}
7
+ * instead of opening its own pool. This gives three properties a foreign store cannot:
8
+ * 1. one connection / one credential, and the same transaction as the entity write;
9
+ * 2. results resolve to entity records without a second round-trip;
10
+ * 3. true hybrid search (vector + keyword + filter) fused server-side in a single query.
11
+ *
12
+ * @module @memberjunction/ai-vectordb
13
+ */
14
+ import type { DatabasePlatform } from '@memberjunction/sql-dialect';
15
+ /**
16
+ * Validate that `name` is a safe SQL identifier (schema, table, column) and return it unchanged.
17
+ * Throws otherwise. Colocated providers build raw SQL with these identifiers interpolated (they
18
+ * bypass the data providers' auto-quoting), and the values can originate from admin-supplied
19
+ * `MJVectorIndex.ProviderConfig` — so every interpolated identifier is validated against an
20
+ * allow-list rather than "cleaned", which would silently alter it and still miss escape vectors.
21
+ */
22
+ export declare function ValidateSqlIdentifier(name: string, kind?: string): string;
23
+ /**
24
+ * Contract a relational data provider implements so a colocated vector provider can borrow
25
+ * its connection — running vector DDL/DML in the SAME database (and, when a transaction is
26
+ * open, the same transaction) as the application's entity data.
27
+ *
28
+ * Implemented by `SQLServerDataProvider` / `PostgreSQLDataProvider`. When a host is wired in,
29
+ * the vector provider never opens its own pool.
30
+ */
31
+ export interface IColocatedVectorHost {
32
+ /** Which SQL platform this host speaks — selects the colocated provider's SQL/placeholder syntax.
33
+ * Reuses the canonical {@link DatabasePlatform} from `@memberjunction/sql-dialect`. */
34
+ readonly ColocatedDialect: DatabasePlatform;
35
+ /** Default schema where MJ entity tables/views live (e.g. `"__mj"`). */
36
+ readonly ColocatedSchema: string;
37
+ /**
38
+ * Execute a parameterized statement against the host connection and return result rows.
39
+ * Placeholders use the host dialect's native convention: `$1..$n` (PostgreSQL) or
40
+ * `@p0..@pN` (SQL Server). Params are positional; index `i` maps to `$${i+1}` / `@p${i}`.
41
+ */
42
+ RunColocatedSQL<T = Record<string, unknown>>(sql: string, params?: ReadonlyArray<unknown>): Promise<T[]>;
43
+ }
44
+ /**
45
+ * Runtime type guard for {@link IColocatedVectorHost}. Structural so a data provider can
46
+ * satisfy the contract without `ai-vectordb` having to import the data-provider package.
47
+ */
48
+ export declare function IsColocatedVectorHost(obj: unknown): obj is IColocatedVectorHost;
49
+ /** How a colocated provider fuses the vector and keyword result lists in a hybrid query. */
50
+ export type ColocatedFusion = 'rrf' | 'vector-only' | 'keyword-only';
51
+ /**
52
+ * Options for a colocated query — a vector component, an optional keyword component, fused
53
+ * together, with an optional metadata filter. Distinct from {@link QueryOptions} because it
54
+ * carries the keyword + fusion controls and is answered in a single server-side statement.
55
+ */
56
+ export interface ColocatedQueryOptions {
57
+ /** Index (table) name. */
58
+ indexName: string;
59
+ /** Query embedding. Optional only when {@link keyword} is supplied (keyword-only search). */
60
+ vector?: number[];
61
+ /** Keyword string for the full-text component of a hybrid query. */
62
+ keyword?: string;
63
+ /** Maximum results to return. */
64
+ topK: number;
65
+ /** Metadata filter — same shape accepted by `QueryOptions.filter`. */
66
+ filter?: object;
67
+ /**
68
+ * Fusion strategy. Defaults to `'rrf'` when both a vector and a keyword are present,
69
+ * otherwise the single available component is used.
70
+ */
71
+ fusion?: ColocatedFusion;
72
+ /** Include raw embedding values with each match (default false). */
73
+ includeValues?: boolean;
74
+ /** Include stored metadata with each match (default true). */
75
+ includeMetadata?: boolean;
76
+ }
77
+ /** A single match from a colocated query. */
78
+ export interface ColocatedMatch {
79
+ /** Vector record id, stored in `CompositeKey` URL format to mirror the external providers. */
80
+ id: string;
81
+ /** Fused relevance score; higher is more relevant regardless of the underlying metric. */
82
+ score: number;
83
+ /** Stored metadata, present when `includeMetadata` is true. */
84
+ metadata?: Record<string, string | number | boolean | string[]>;
85
+ /** Embedding values, present when `includeValues` is true. */
86
+ values?: number[];
87
+ }
88
+ /** Result of a colocated query. */
89
+ export interface ColocatedQueryResult {
90
+ matches: ColocatedMatch[];
91
+ }
92
+ //# sourceMappingURL=colocated.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colocated.types.d.ts","sourceRoot":"","sources":["../../src/generic/colocated.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAKpE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAe,GAAG,MAAM,CAK/E;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;I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AE,MAAM,EAAE,CAAC;CACrB;AAED,mCAAmC;AACnC,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,cAAc,EAAE,CAAC;CAC7B"}
@@ -0,0 +1,31 @@
1
+ /** Matches a safe, unquoted SQL identifier: a letter/underscore followed by word characters. */
2
+ const SQL_IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
3
+ /**
4
+ * Validate that `name` is a safe SQL identifier (schema, table, column) and return it unchanged.
5
+ * Throws otherwise. Colocated providers build raw SQL with these identifiers interpolated (they
6
+ * bypass the data providers' auto-quoting), and the values can originate from admin-supplied
7
+ * `MJVectorIndex.ProviderConfig` — so every interpolated identifier is validated against an
8
+ * allow-list rather than "cleaned", which would silently alter it and still miss escape vectors.
9
+ */
10
+ export function ValidateSqlIdentifier(name, kind = 'identifier') {
11
+ if (typeof name !== 'string' || !SQL_IDENTIFIER_PATTERN.test(name)) {
12
+ throw new Error(`Invalid SQL ${kind}: ${JSON.stringify(name)} (must match ${SQL_IDENTIFIER_PATTERN}).`);
13
+ }
14
+ return name;
15
+ }
16
+ /**
17
+ * Runtime type guard for {@link IColocatedVectorHost}. Structural so a data provider can
18
+ * satisfy the contract without `ai-vectordb` having to import the data-provider package.
19
+ */
20
+ export function IsColocatedVectorHost(obj) {
21
+ if (!obj || typeof obj !== 'object') {
22
+ return false;
23
+ }
24
+ const o = obj;
25
+ // Structural check only — don't enumerate specific platforms, so this stays correct as
26
+ // DatabasePlatform grows. The compile-time type enforces the valid platform set.
27
+ return typeof o['ColocatedDialect'] === 'string'
28
+ && typeof o['ColocatedSchema'] === 'string'
29
+ && typeof o['RunColocatedSQL'] === 'function';
30
+ }
31
+ //# sourceMappingURL=colocated.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colocated.types.js","sourceRoot":"","sources":["../../src/generic/colocated.types.ts"],"names":[],"mappings":"AAeA,gGAAgG;AAChG,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,IAAI,GAAG,YAAY;IACnE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,sBAAsB,IAAI,CAAC,CAAC;IAC5G,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAwBD;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY;IAC9C,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,uFAAuF;IACvF,iFAAiF;IACjF,OAAO,OAAO,CAAC,CAAC,kBAAkB,CAAC,KAAK,QAAQ;WACzC,OAAO,CAAC,CAAC,iBAAiB,CAAC,KAAK,QAAQ;WACxC,OAAO,CAAC,CAAC,iBAAiB,CAAC,KAAK,UAAU,CAAC;AACtD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './generic/record.js';
2
2
  export * from './generic/VectorDBBase.js';
3
3
  export * from './generic/query.types.js';
4
+ export * from './generic/colocated.types.js';
4
5
  export * from './generic/MetadataFilter.js';
5
6
  export * from './generic/configuration.types.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './generic/record.js';
2
2
  export * from './generic/VectorDBBase.js';
3
3
  export * from './generic/query.types.js';
4
+ export * from './generic/colocated.types.js';
4
5
  export * from './generic/MetadataFilter.js';
5
6
  export * from './generic/configuration.types.js';
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-vectordb",
3
3
  "type": "module",
4
- "version": "5.38.0",
4
+ "version": "5.39.0",
5
5
  "description": "MemberJunction: AI Vector Database Module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -17,8 +17,9 @@
17
17
  "author": "MemberJunction.com",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@memberjunction/core": "5.38.0",
21
- "@memberjunction/global": "5.38.0",
20
+ "@memberjunction/core": "5.39.0",
21
+ "@memberjunction/global": "5.39.0",
22
+ "@memberjunction/sql-dialect": "5.39.0",
22
23
  "dotenv": "^17.2.4"
23
24
  },
24
25
  "devDependencies": {