@memberjunction/data-context-server 0.9.2

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.
@@ -0,0 +1,14 @@
1
+ import { UserInfo } from "@memberjunction/core";
2
+ import { DataContextItem } from "@memberjunction/data-context";
3
+ export declare class DataContextItemServer extends DataContextItem {
4
+ /**
5
+ * Server-Side only method to load the data context item from a SQL statement
6
+ * @param dataSource - The data source to load the data context item from (this implementation uses TypeORM's DataSource object)
7
+ * @param contextUser - The user that is requesting the data context
8
+ */
9
+ protected LoadFromSQL(dataSource: any, contextUser?: UserInfo): Promise<boolean>;
10
+ }
11
+ /**
12
+ * Call this function after you import this package to ensure that the DataContextItemServer class is not tree shaken out of the final build
13
+ */
14
+ export declare function LoadDataContextItemsServer(): void;
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.LoadDataContextItemsServer = exports.DataContextItemServer = void 0;
10
+ const global_1 = require("@memberjunction/global");
11
+ const core_1 = require("@memberjunction/core");
12
+ const data_context_1 = require("@memberjunction/data-context");
13
+ let DataContextItemServer = class DataContextItemServer extends data_context_1.DataContextItem {
14
+ /**
15
+ * Server-Side only method to load the data context item from a SQL statement
16
+ * @param dataSource - The data source to load the data context item from (this implementation uses TypeORM's DataSource object)
17
+ * @param contextUser - The user that is requesting the data context
18
+ */
19
+ async LoadFromSQL(dataSource, contextUser) {
20
+ try {
21
+ const ds = dataSource;
22
+ const result = await ds.query(this.SQL);
23
+ this.Data = result;
24
+ return true; // if we get here the above query didn't fail by throwing an exception which would get caught below
25
+ }
26
+ catch (e) {
27
+ (0, core_1.LogError)(`Error loading data context item from SQL: ${e && e.message ? e.message : e}`);
28
+ return false;
29
+ }
30
+ }
31
+ };
32
+ exports.DataContextItemServer = DataContextItemServer;
33
+ exports.DataContextItemServer = DataContextItemServer = __decorate([
34
+ (0, global_1.RegisterClass)(data_context_1.DataContextItem, undefined, 2) // higher priority for this class
35
+ ], DataContextItemServer);
36
+ /**
37
+ * Call this function after you import this package to ensure that the DataContextItemServer class is not tree shaken out of the final build
38
+ */
39
+ function LoadDataContextItemsServer() {
40
+ // nothing to do here - this is called from packages that import this package in order to prevent tree shaking from removing the DataContextItemServer class
41
+ // that can happen since there is no static code path to instantiate the class
42
+ }
43
+ exports.LoadDataContextItemsServer = LoadDataContextItemsServer;
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAAuD;AACvD,+CAA0D;AAC1D,+DAA+D;AAIxD,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,8BAAe;IACtD;;;;OAIG;IACgB,KAAK,CAAC,WAAW,CAAC,UAAe,EAAE,WAAsB;QACxE,IAAI,CAAC;YACD,MAAM,EAAE,GAAG,UAAwB,CAAC;YACpC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;YACnB,OAAO,IAAI,CAAC,CAAC,mGAAmG;QACpH,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,IAAA,eAAQ,EAAC,6CAA6C,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACxF,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;CACJ,CAAA;AAlBY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAa,EAAC,8BAAe,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,iCAAiC;GAClE,qBAAqB,CAkBjC;AAED;;GAEG;AACH,SAAgB,0BAA0B;IACtC,4JAA4J;IAC5J,8EAA8E;AAClF,CAAC;AAHD,gEAGC"}
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@memberjunction/data-context-server",
3
+ "version": "0.9.2",
4
+ "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.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "scripts": {
11
+ "start": "ts-node-dev src/index.ts",
12
+ "build": "tsc",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "author": "MemberJunction.com",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "ts-node-dev": "^2.0.0",
19
+ "typescript": "^5.3.3"
20
+ },
21
+ "dependencies": {
22
+ "@memberjunction/data-context": "^0.9.4",
23
+ "@memberjunction/global": "^0.9.132",
24
+ "typeorm": "^0.3.20"
25
+ }
26
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # @memberjunction/data-context-server
2
+
3
+ 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.