From 6b14ff17a2141558a1cfddd0616864b0aa47794d Mon Sep 17 00:00:00 2001 From: ijungleboy Date: Fri, 3 Dec 2021 17:46:05 +0100 Subject: [PATCH] remove obsolete .data feature --- .../$2sxc/src/sxc-instance/data/sxc-data.ts | 23 ++++++++++ projects/$2sxc/src/sxc-instance/index.ts | 2 - .../sxc-instance-with-internals.ts | 43 +++++++++++-------- .../$2sxc/src/sxc-instance/sxc-instance.ts | 5 +++ .../src/sxc-instance/web-api/sxc-web-api.ts | 7 +-- 5 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 projects/$2sxc/src/sxc-instance/data/sxc-data.ts diff --git a/projects/$2sxc/src/sxc-instance/data/sxc-data.ts b/projects/$2sxc/src/sxc-instance/data/sxc-data.ts new file mode 100644 index 000000000..0c3fe5296 --- /dev/null +++ b/projects/$2sxc/src/sxc-instance/data/sxc-data.ts @@ -0,0 +1,23 @@ +import { SxcInstance } from ".."; +import { SxcWebApi } from "../web-api/sxc-web-api"; + +export class SxcData { + private readonly webApi: SxcWebApi; + + constructor( + private readonly sxc: SxcInstance, + readonly contentType: string + ) { + this.webApi = sxc.webApi; + + if (contentType == null) throw "contentType is empty"; + if (contentType.indexOf("/") != -1 || contentType.indexOf("\\") != -1) + throw "contentType has slashes - not allowed"; + } + + get(ids?: string | number, params?: string | Record): Promise { + let path = "app/auto/content/" + this.contentType; + if (ids && (typeof ids === 'string' || typeof ids === 'number')) path += "/" + ids; + return this.webApi.fetchJson(this.webApi.url(path, params)); + } +} diff --git a/projects/$2sxc/src/sxc-instance/index.ts b/projects/$2sxc/src/sxc-instance/index.ts index 9a964c7e0..e7ff6e4b4 100644 --- a/projects/$2sxc/src/sxc-instance/index.ts +++ b/projects/$2sxc/src/sxc-instance/index.ts @@ -5,5 +5,3 @@ export * from './sxc-instance-with-internals'; export * from './web-api/sxc-web-api'; export * from './web-api/ajax-promise'; export * from './web-api/ajax-settings'; - -export * from './deprecated/sxc-instance-data'; \ No newline at end of file diff --git a/projects/$2sxc/src/sxc-instance/sxc-instance-with-internals.ts b/projects/$2sxc/src/sxc-instance/sxc-instance-with-internals.ts index f4b234290..c50c58647 100644 --- a/projects/$2sxc/src/sxc-instance/sxc-instance-with-internals.ts +++ b/projects/$2sxc/src/sxc-instance/sxc-instance-with-internals.ts @@ -1,27 +1,32 @@ import { SxcRootInternals } from '../sxc-root/sxc-root-internals'; import { SxcRoot } from '../sxc-root/sxc-root'; -import { SxcInstance, SxcInstanceDataDeprecated } from '.'; +import { SxcInstance } from '.'; import { ContextIdentifier } from '../sxc-root/context-identifier'; export class SxcInstanceWithInternals extends SxcInstance { - data: SxcInstanceDataDeprecated; - source: any = null; - isLoaded = false; - lastRefresh: Date = null; - - constructor( - public id: number, - public cbid: number, - public cacheKey: string, - protected $2sxc: SxcRoot & SxcRootInternals, - ctx?: ContextIdentifier + source: any = null; + isLoaded = false; + lastRefresh: Date = null; + + constructor( + public id: number, + public cbid: number, + public cacheKey: string, + protected $2sxc: SxcRoot & SxcRootInternals, + ctx?: ContextIdentifier ) { - super(id, cbid, $2sxc, ctx); - this.data = new SxcInstanceDataDeprecated(this); - } + super(id, cbid, $2sxc, ctx); + + // Help cach error on call of old code + (this.data as any).on = () => { + throw 'Warning Obsolete Feature on 2sxc JS: the .data has been obsolete for a long time and is repurposed. \n' + + 'If you are calling .data.on(...) you are running very old code. \n' + + 'Guidance to fix this: https://r.2sxc.org/brc-13-id.' + }; + } - recreate(resetCache: boolean): SxcInstanceWithInternals { - if (resetCache) delete this.$2sxc._controllers[this.cacheKey]; // clear cache - return this.$2sxc(this.id, this.cbid) as any as SxcInstanceWithInternals; // generate new - } + recreate(resetCache: boolean): SxcInstanceWithInternals { + if (resetCache) delete this.$2sxc._controllers[this.cacheKey]; // clear cache + return this.$2sxc(this.id, this.cbid) as any as SxcInstanceWithInternals; // generate new + } } diff --git a/projects/$2sxc/src/sxc-instance/sxc-instance.ts b/projects/$2sxc/src/sxc-instance/sxc-instance.ts index eca568fc2..c4c16f533 100644 --- a/projects/$2sxc/src/sxc-instance/sxc-instance.ts +++ b/projects/$2sxc/src/sxc-instance/sxc-instance.ts @@ -6,6 +6,7 @@ import { SxcRoot } from '../sxc-root/sxc-root'; import { HasLog } from '..'; import { SxcRootInternals } from '../sxc-root/sxc-root-internals'; import { SxcInstanceManage } from './sxc-instance-manage'; +import { SxcData } from './data/sxc-data'; // const serviceScopes = ['app', 'app-sys', 'app-api', 'app-query', 'app-content', 'eav', 'view', 'dnn']; @@ -59,6 +60,10 @@ export class SxcInstance extends HasLog implements Public.SxcInstance { } + data(contentType: string) { + return new SxcData(this, contentType); + } + /** * converts a short api-call path like "/app/Blog/query/xyz" to the DNN full path * which varies from installation to installation like "/desktopmodules/api/2sxc/app/..." diff --git a/projects/$2sxc/src/sxc-instance/web-api/sxc-web-api.ts b/projects/$2sxc/src/sxc-instance/web-api/sxc-web-api.ts index 1805f9b37..da419012d 100644 --- a/projects/$2sxc/src/sxc-instance/web-api/sxc-web-api.ts +++ b/projects/$2sxc/src/sxc-instance/web-api/sxc-web-api.ts @@ -12,12 +12,7 @@ import { NoJQ } from '../..'; */ export class SxcWebApi implements Public.SxcWebApi { public readonly env: Environment; - constructor( - private readonly sxc: SxcInstance, - // private readonly id: number, - // private readonly cbid: number, - // public readonly env: Environment - ) { + constructor(private readonly sxc: SxcInstance) { this.env = sxc.root.env; } /**