@memberjunction/data-context-server 6.2.0-edge.3 → 6.2.0-edge.5
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/README.md +13 -12
- package/dist/index.d.ts +13 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -12
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/readme.md +13 -12
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# @memberjunction/data-context-server
|
|
2
2
|
|
|
3
|
-
Server-side implementation of the MemberJunction Data Context system.
|
|
3
|
+
Server-side implementation of the MemberJunction Data Context system. Loads the data of `sql`-type `DataContextItem` objects by running their SQL through a query provider's screened ad-hoc path.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The `@memberjunction/data-context-server` package extends the base `DataContextItem` class from `@memberjunction/data-context` with a server-side implementation
|
|
7
|
+
The `@memberjunction/data-context-server` package extends the base `DataContextItem` class from `@memberjunction/data-context` with a server-side implementation of `LoadFromSQL`. It runs the item's SQL through `RunQuery({ SQL })` on a query provider, the same ad-hoc path `ExecuteAdhocQuery` uses, so the SQL must be a single read statement. On PostgreSQL that path also runs it in a read-only transaction that is rolled back. It never sends SQL to a raw connection pool. This is the server counterpart to the client-side GraphQL-based data context loading.
|
|
8
8
|
|
|
9
9
|
```mermaid
|
|
10
10
|
graph TD
|
|
11
11
|
A["DataContextItemServer"] -->|extends| B["DataContextItem<br/>(data-context package)"]
|
|
12
|
-
A -->|
|
|
13
|
-
C --> D["
|
|
12
|
+
A -->|"RunQuery({ SQL })"| C["Read-only query provider"]
|
|
13
|
+
C --> D["Database"]
|
|
14
14
|
|
|
15
15
|
E["Server-Side Code<br/>(MJAPI, Actions, etc.)"] --> A
|
|
16
16
|
F["Client-Side Code<br/>(Angular, React)"] --> G["DataContextItemClient<br/>(GraphQL-based)"]
|
|
@@ -31,28 +31,29 @@ npm install @memberjunction/data-context-server
|
|
|
31
31
|
|
|
32
32
|
## How It Works
|
|
33
33
|
|
|
34
|
-
The package registers `DataContextItemServer` as a subclass of `DataContextItem` using MemberJunction's `@RegisterClass` decorator. When server-side code creates a `DataContextItem`, the class factory automatically returns the server implementation
|
|
34
|
+
The package registers `DataContextItemServer` as a subclass of `DataContextItem` using MemberJunction's `@RegisterClass` decorator. When server-side code creates a `DataContextItem`, the class factory automatically returns the server implementation.
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import '@memberjunction/data-context-server';
|
|
38
|
-
// DataContextItem instances now
|
|
38
|
+
// DataContextItem instances can now load `sql` items on the server
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
The `LoadFromSQL` method:
|
|
42
|
-
1. Receives a
|
|
43
|
-
2.
|
|
44
|
-
3.
|
|
45
|
-
4. Stores the
|
|
42
|
+
1. Receives a query provider (`IRunQueryProvider`) as the data source. MJServer passes its read-only provider.
|
|
43
|
+
2. Refuses when there is no context user, or when the data source is not a query provider (for example a raw connection pool)
|
|
44
|
+
3. Runs `DataContextItem.SQL` through `RunQuery({ SQL })` for the context user. The provider accepts only a single read statement.
|
|
45
|
+
4. Stores the result rows in `DataContextItem.Data`
|
|
46
46
|
5. Returns success/failure with error details on `DataLoadingError`
|
|
47
47
|
|
|
48
|
+
Callers decide who may run an item's SQL. MJServer's `GetDataContextData` and `GetDataContextItemData` queries allow it only for the data context's owner or an administrator, never for a scope-limited session, and only on the read-only provider.
|
|
49
|
+
|
|
48
50
|
## Dependencies
|
|
49
51
|
|
|
50
52
|
| Package | Purpose |
|
|
51
53
|
|---------|---------|
|
|
52
|
-
| `@memberjunction/core` | UserInfo
|
|
54
|
+
| `@memberjunction/core` | `IRunQueryProvider`, `UserInfo`, `LogError` |
|
|
53
55
|
| `@memberjunction/global` | RegisterClass decorator |
|
|
54
56
|
| `@memberjunction/data-context` | Base DataContextItem class |
|
|
55
|
-
| `mssql` | SQL Server connectivity |
|
|
56
57
|
|
|
57
58
|
## License
|
|
58
59
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { UserInfo } from "@memberjunction/core";
|
|
1
|
+
import type { IRunQueryProvider, UserInfo } from "@memberjunction/core";
|
|
2
2
|
import { DataContextItem } from "@memberjunction/data-context";
|
|
3
|
+
/**
|
|
4
|
+
* Server-side DataContextItem. Runs the SQL of a `sql` item through a query provider's ad-hoc path,
|
|
5
|
+
* which accepts only a single read statement.
|
|
6
|
+
*/
|
|
3
7
|
export declare class DataContextItemServer extends DataContextItem {
|
|
4
8
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
9
|
+
* Loads the item's data by running its SQL through `dataSource.RunQuery` for `contextUser`.
|
|
10
|
+
* Refuses when there is no context user or when `dataSource` is not a query provider, such as a
|
|
11
|
+
* raw connection pool handed in through `LoadData`'s untyped data source.
|
|
12
|
+
* @param dataSource - the query provider to run the SQL on; MJServer passes its read-only provider
|
|
13
|
+
* @param contextUser - the user the SQL runs for
|
|
8
14
|
*/
|
|
9
|
-
protected LoadFromSQL(dataSource:
|
|
15
|
+
protected LoadFromSQL(dataSource: IRunQueryProvider | null | undefined, contextUser?: UserInfo): Promise<boolean>;
|
|
16
|
+
/** Records why the item's SQL was not loaded and returns false. */
|
|
17
|
+
private failSQLLoad;
|
|
10
18
|
}
|
|
11
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;GAGG;AACH,qBACa,qBAAsB,SAAQ,eAAe;IACtD;;;;;;OAMG;cACsB,WAAW,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBhI,mEAAmE;IACnE,OAAO,CAAC,WAAW;CAKtB"}
|
package/dist/index.js
CHANGED
|
@@ -7,27 +7,46 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { RegisterClass } from "@memberjunction/global";
|
|
8
8
|
import { LogError } from "@memberjunction/core";
|
|
9
9
|
import { DataContextItem } from "@memberjunction/data-context";
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Server-side DataContextItem. Runs the SQL of a `sql` item through a query provider's ad-hoc path,
|
|
12
|
+
* which accepts only a single read statement.
|
|
13
|
+
*/
|
|
11
14
|
let DataContextItemServer = class DataContextItemServer extends DataContextItem {
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
+
* Loads the item's data by running its SQL through `dataSource.RunQuery` for `contextUser`.
|
|
17
|
+
* Refuses when there is no context user or when `dataSource` is not a query provider, such as a
|
|
18
|
+
* raw connection pool handed in through `LoadData`'s untyped data source.
|
|
19
|
+
* @param dataSource - the query provider to run the SQL on; MJServer passes its read-only provider
|
|
20
|
+
* @param contextUser - the user the SQL runs for
|
|
16
21
|
*/
|
|
17
22
|
async LoadFromSQL(dataSource, contextUser) {
|
|
23
|
+
if (!contextUser) {
|
|
24
|
+
return this.failSQLLoad('a context user is required');
|
|
25
|
+
}
|
|
26
|
+
if (!dataSource || typeof dataSource.RunQuery !== 'function') {
|
|
27
|
+
return this.failSQLLoad('SQL items run only through a query provider, never on a raw connection');
|
|
28
|
+
}
|
|
29
|
+
if (!this.SQL?.trim()) {
|
|
30
|
+
return this.failSQLLoad('the item has no SQL');
|
|
31
|
+
}
|
|
18
32
|
try {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
const result = await dataSource.RunQuery({ SQL: this.SQL }, contextUser);
|
|
34
|
+
if (!result.Success) {
|
|
35
|
+
return this.failSQLLoad(result.ErrorMessage);
|
|
36
|
+
}
|
|
37
|
+
this.Data = result.Results;
|
|
38
|
+
return true;
|
|
24
39
|
}
|
|
25
40
|
catch (e) {
|
|
26
|
-
this.
|
|
27
|
-
LogError(this.DataLoadingError);
|
|
28
|
-
return false;
|
|
41
|
+
return this.failSQLLoad(e instanceof Error ? e.message : String(e));
|
|
29
42
|
}
|
|
30
43
|
}
|
|
44
|
+
/** Records why the item's SQL was not loaded and returns false. */
|
|
45
|
+
failSQLLoad(reason) {
|
|
46
|
+
this.DataLoadingError = `Error loading data context item from SQL: ${reason}`;
|
|
47
|
+
LogError(this.DataLoadingError);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
31
50
|
};
|
|
32
51
|
DataContextItemServer = __decorate([
|
|
33
52
|
RegisterClass(DataContextItem, undefined, undefined, true)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;;GAGG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,eAAe;IACtD;;;;;;OAMG;IACgB,KAAK,CAAC,WAAW,CAAC,UAAgD,EAAE,WAAsB;QACzG,IAAI,CAAC,WAAW,EAAE,CAAC;Y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7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/data-context-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.0-edge.
|
|
4
|
+
"version": "6.2.0-edge.5",
|
|
5
5
|
"description": "This library provides a server-side implementation of the DataContextItem class from @memberjunction/data-context that can handle the server-side only use case of loading data into a context using raw SQL statements.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"typescript": "^5.9.3"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@memberjunction/core": "6.2.0-edge.
|
|
19
|
-
"@memberjunction/data-context": "6.2.0-edge.
|
|
20
|
-
"@memberjunction/global": "6.2.0-edge.
|
|
18
|
+
"@memberjunction/core": "6.2.0-edge.5",
|
|
19
|
+
"@memberjunction/data-context": "6.2.0-edge.5",
|
|
20
|
+
"@memberjunction/global": "6.2.0-edge.5",
|
|
21
21
|
"mssql": "^12.2.0"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
package/readme.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# @memberjunction/data-context-server
|
|
2
2
|
|
|
3
|
-
Server-side implementation of the MemberJunction Data Context system.
|
|
3
|
+
Server-side implementation of the MemberJunction Data Context system. Loads the data of `sql`-type `DataContextItem` objects by running their SQL through a query provider's screened ad-hoc path.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The `@memberjunction/data-context-server` package extends the base `DataContextItem` class from `@memberjunction/data-context` with a server-side implementation
|
|
7
|
+
The `@memberjunction/data-context-server` package extends the base `DataContextItem` class from `@memberjunction/data-context` with a server-side implementation of `LoadFromSQL`. It runs the item's SQL through `RunQuery({ SQL })` on a query provider, the same ad-hoc path `ExecuteAdhocQuery` uses, so the SQL must be a single read statement. On PostgreSQL that path also runs it in a read-only transaction that is rolled back. It never sends SQL to a raw connection pool. This is the server counterpart to the client-side GraphQL-based data context loading.
|
|
8
8
|
|
|
9
9
|
```mermaid
|
|
10
10
|
graph TD
|
|
11
11
|
A["DataContextItemServer"] -->|extends| B["DataContextItem<br/>(data-context package)"]
|
|
12
|
-
A -->|
|
|
13
|
-
C --> D["
|
|
12
|
+
A -->|"RunQuery({ SQL })"| C["Read-only query provider"]
|
|
13
|
+
C --> D["Database"]
|
|
14
14
|
|
|
15
15
|
E["Server-Side Code<br/>(MJAPI, Actions, etc.)"] --> A
|
|
16
16
|
F["Client-Side Code<br/>(Angular, React)"] --> G["DataContextItemClient<br/>(GraphQL-based)"]
|
|
@@ -31,28 +31,29 @@ npm install @memberjunction/data-context-server
|
|
|
31
31
|
|
|
32
32
|
## How It Works
|
|
33
33
|
|
|
34
|
-
The package registers `DataContextItemServer` as a subclass of `DataContextItem` using MemberJunction's `@RegisterClass` decorator. When server-side code creates a `DataContextItem`, the class factory automatically returns the server implementation
|
|
34
|
+
The package registers `DataContextItemServer` as a subclass of `DataContextItem` using MemberJunction's `@RegisterClass` decorator. When server-side code creates a `DataContextItem`, the class factory automatically returns the server implementation.
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import '@memberjunction/data-context-server';
|
|
38
|
-
// DataContextItem instances now
|
|
38
|
+
// DataContextItem instances can now load `sql` items on the server
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
The `LoadFromSQL` method:
|
|
42
|
-
1. Receives a
|
|
43
|
-
2.
|
|
44
|
-
3.
|
|
45
|
-
4. Stores the
|
|
42
|
+
1. Receives a query provider (`IRunQueryProvider`) as the data source. MJServer passes its read-only provider.
|
|
43
|
+
2. Refuses when there is no context user, or when the data source is not a query provider (for example a raw connection pool)
|
|
44
|
+
3. Runs `DataContextItem.SQL` through `RunQuery({ SQL })` for the context user. The provider accepts only a single read statement.
|
|
45
|
+
4. Stores the result rows in `DataContextItem.Data`
|
|
46
46
|
5. Returns success/failure with error details on `DataLoadingError`
|
|
47
47
|
|
|
48
|
+
Callers decide who may run an item's SQL. MJServer's `GetDataContextData` and `GetDataContextItemData` queries allow it only for the data context's owner or an administrator, never for a scope-limited session, and only on the read-only provider.
|
|
49
|
+
|
|
48
50
|
## Dependencies
|
|
49
51
|
|
|
50
52
|
| Package | Purpose |
|
|
51
53
|
|---------|---------|
|
|
52
|
-
| `@memberjunction/core` | UserInfo
|
|
54
|
+
| `@memberjunction/core` | `IRunQueryProvider`, `UserInfo`, `LogError` |
|
|
53
55
|
| `@memberjunction/global` | RegisterClass decorator |
|
|
54
56
|
| `@memberjunction/data-context` | Base DataContextItem class |
|
|
55
|
-
| `mssql` | SQL Server connectivity |
|
|
56
57
|
|
|
57
58
|
## License
|
|
58
59
|
|