@platecms/delta-plate-resource-notation 0.1.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.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # plate-resource-notation
2
+
3
+ This package defines a PRN object, which allows for creation from strings conform PRN formatting or separate
4
+ components.
5
+
6
+ * [Definition](#definition)
7
+ * [Requests and responses](#requests-and-responses)
8
+ * [Features](#features)
9
+
10
+ # Definition
11
+
12
+ We define the Plate Resource Name (PRN, derived from URN) format as follows:
13
+ `prn:<partition>:<organization-id>:<service>:<resource-type>:<resource-id>`
14
+
15
+ - Partition: The instance of Plate Delta in which the resource resides. E.g. `plate`, `plate-dev`, `<client-name>`
16
+ - Organization ID: The ID of the organization that owns the resource.
17
+ - Service: The abbreviation of the name of the service that owns resource. E.g. `am` (Asset Manager), `cxc` (Content
18
+ Experience Center), etc.
19
+ - Resource type: The type of the resource. E.g. asset, directory, content-type
20
+ - Resource id: Id of the resource. E.g. 1234, abcd. This can be any string.
21
+
22
+ Each name is formatted as slug: `asset-library`
23
+
24
+ Some examples are:
25
+
26
+ - `prn:plate:am:1234:asset:124124`
27
+ - `prn:jumbo:cxc:abc:content-value:xyz`
28
+
29
+ # Requests and responses
30
+
31
+ A PRN should be formatted as a string in requests and responses. It will be parsed to a PRN object inside the
32
+ microservice.
33
+ Inside of services we use PRN objects. In the database we use the id part of the PRN.
34
+
35
+ # Features
36
+
37
+ - `PRN` class to represent a PRN object. The constructor takes in the components of a PRN object.
38
+ - Static method `fromString` to convert a string into a `PRN` instance.
39
+ - `toString` on the PRN class to convert a PRN object into a string.
40
+ - `InvalidPrnError` class to represent an error while parsing PRNs.
41
+ - `TransformPrn` decorator to transform a PRN object into a string using `class-transformer`
42
+ - `ServiceAbbreviation` enum to represent the service abbreviations.
43
+ - `PRN_REGEX` constant to represent the regex used to validate PRN strings.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@platecms/delta-plate-resource-notation",
3
+ "version": "0.1.0",
4
+ "description": "PRNs are Plate's replacement for IDs. They contain context about the resource the PRN describes.",
5
+ "license": "UNLICENSED",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://bitbucket.org/startmetplate/delta.git"
12
+ },
13
+ "homepage": "https://bitbucket.org/startmetplate/delta/src/dev/packages/plate-resource-notation",
14
+ "main": "./src/index.js",
15
+ "types": "./src/index.d.ts",
16
+ "files": [
17
+ "src/**/*"
18
+ ],
19
+ "dependencies": {
20
+ "class-transformer": "0.5.1",
21
+ "reflect-metadata": "0.2.2",
22
+ "tslib": "2.8.1"
23
+ },
24
+ "type": "commonjs"
25
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./lib/invalid-prn.error";
2
+ export * from "./lib/prn-regex.constant";
3
+ export * from "./lib/transform-prn.decorator";
4
+ export * from "./lib/services-abbreviation.enum";
5
+ export * from "./lib/plate-resource-notation.model";
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/invalid-prn.error"), exports);
5
+ tslib_1.__exportStar(require("./lib/prn-regex.constant"), exports);
6
+ tslib_1.__exportStar(require("./lib/transform-prn.decorator"), exports);
7
+ tslib_1.__exportStar(require("./lib/services-abbreviation.enum"), exports);
8
+ tslib_1.__exportStar(require("./lib/plate-resource-notation.model"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/plate-resource-notation/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,mEAAyC;AACzC,wEAA8C;AAC9C,2EAAiD;AACjD,8EAAoD"}
@@ -0,0 +1,3 @@
1
+ export declare class InvalidPrnError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidPrnError = void 0;
4
+ class InvalidPrnError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = this.constructor.name;
8
+ }
9
+ }
10
+ exports.InvalidPrnError = InvalidPrnError;
11
+ //# sourceMappingURL=invalid-prn.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-prn.error.js","sourceRoot":"","sources":["../../../../../../packages/plate-resource-notation/src/lib/invalid-prn.error.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AALD,0CAKC"}
@@ -0,0 +1,13 @@
1
+ import { ServiceAbbreviation } from "./services-abbreviation.enum";
2
+ export type PrnString = `prn:${string}:${string}:${ServiceAbbreviation}:${string}:${string}`;
3
+ export declare class PRN {
4
+ readonly partition: string;
5
+ readonly organizationId: string;
6
+ readonly service: ServiceAbbreviation;
7
+ readonly resourceType: string;
8
+ readonly resourceId: string;
9
+ constructor(partition: string, organizationId: string, service: ServiceAbbreviation, resourceType: string, resourceId: string);
10
+ static fromString(prnString: string): PRN;
11
+ toString(): string;
12
+ equals(other: unknown): boolean;
13
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRN = void 0;
4
+ const services_abbreviation_enum_1 = require("./services-abbreviation.enum");
5
+ const invalid_prn_error_1 = require("./invalid-prn.error");
6
+ const prn_regex_constant_1 = require("./prn-regex.constant");
7
+ class PRN {
8
+ constructor(partition, organizationId, service, resourceType, resourceId) {
9
+ const componentArray = [partition, service, organizationId, resourceType, resourceId];
10
+ if (!componentArray.every((comp) => typeof comp === "string" && comp.length > 0)) {
11
+ throw new invalid_prn_error_1.InvalidPrnError("Invalid PRN component(s)! All components must be a non-empty string.");
12
+ }
13
+ if (componentArray.some((comp) => comp.includes(":"))) {
14
+ throw new invalid_prn_error_1.InvalidPrnError("Invalid PRN string specification! Components cannot contain ':'.");
15
+ }
16
+ this.partition = partition;
17
+ this.organizationId = organizationId;
18
+ this.service = service;
19
+ this.resourceType = resourceType;
20
+ this.resourceId = resourceId;
21
+ }
22
+ static fromString(prnString) {
23
+ if (!prn_regex_constant_1.PRN_REGEX.test(prnString)) {
24
+ throw new invalid_prn_error_1.InvalidPrnError(`Invalid PRN string '${prnString}'! Should match the pattern '${prn_regex_constant_1.PRN_REGEX.source}'`);
25
+ }
26
+ const [_, partition, organizationId, service, resourceType, resourceId] = prnString.split(":");
27
+ if (!Object.values(services_abbreviation_enum_1.ServiceAbbreviation).map(String).includes(service)) {
28
+ throw new invalid_prn_error_1.InvalidPrnError(`Invalid ServiceAbbreviation '${service}'! Use the ServiceAbbreviation enum.`);
29
+ }
30
+ return new PRN(partition, organizationId, service, resourceType, resourceId);
31
+ }
32
+ toString() {
33
+ return `prn:${this.partition}:${this.organizationId}:${this.service}:${this.resourceType}:${this.resourceId}`;
34
+ }
35
+ equals(other) {
36
+ if (!(other instanceof PRN)) {
37
+ return false;
38
+ }
39
+ for (const key of Object.keys(this)) {
40
+ if (this[key] !== other[key]) {
41
+ return false;
42
+ }
43
+ }
44
+ return true;
45
+ }
46
+ }
47
+ exports.PRN = PRN;
48
+ //# sourceMappingURL=plate-resource-notation.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plate-resource-notation.model.js","sourceRoot":"","sources":["../../../../../../packages/plate-resource-notation/src/lib/plate-resource-notation.model.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;AACnE,2DAAsD;AACtD,6DAAiD;AAIjD,MAAa,GAAG;IA8Bd,YACE,SAAiB,EACjB,cAAsB,EACtB,OAA4B,EAC5B,YAAoB,EACpB,UAAkB;QAElB,MAAM,cAAc,GAAa,CAAC,SA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C;QAC3G,CAAC;QAED,OAAO,IAAI,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,OAA8B,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IACtG,CAAC;IAKM,QAAQ;QACb,OAAO,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;IAChH,CAAC;IAKM,MAAM,CAAC,KAAc;QAC1B,IAAI,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,IAAI,IAAI,CAAC,GAAgB,CAAC,KAAK,KAAK,CAAC,GAAgB,CAAC,EAAE,CAAC;gBACvD,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAhGD,kBAgGC"}
@@ -0,0 +1 @@
1
+ export declare const PRN_REGEX: RegExp;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRN_REGEX = void 0;
4
+ exports.PRN_REGEX = /^prn(:[A-Za-z0-9-_]+){5}$/u;
5
+ //# sourceMappingURL=prn-regex.constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prn-regex.constant.js","sourceRoot":"","sources":["../../../../../../packages/plate-resource-notation/src/lib/prn-regex.constant.ts"],"names":[],"mappings":";;;AAIa,QAAA,SAAS,GAAG,4BAA4B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare enum ServiceAbbreviation {
2
+ ASSET_MANAGER = "am",
3
+ CONTENT_EXPERIENCE_CENTER = "cxc",
4
+ ACCESS_CONTROL = "ac",
5
+ EMAILS_SERVICE = "es",
6
+ ORGANIZATIONS_CENTER = "oc"
7
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServiceAbbreviation = void 0;
4
+ var ServiceAbbreviation;
5
+ (function (ServiceAbbreviation) {
6
+ ServiceAbbreviation["ASSET_MANAGER"] = "am";
7
+ ServiceAbbreviation["CONTENT_EXPERIENCE_CENTER"] = "cxc";
8
+ ServiceAbbreviation["ACCESS_CONTROL"] = "ac";
9
+ ServiceAbbreviation["EMAILS_SERVICE"] = "es";
10
+ ServiceAbbreviation["ORGANIZATIONS_CENTER"] = "oc";
11
+ })(ServiceAbbreviation || (exports.ServiceAbbreviation = ServiceAbbreviation = {}));
12
+ //# sourceMappingURL=services-abbreviation.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services-abbreviation.enum.js","sourceRoot":"","sources":["../../../../../../packages/plate-resource-notation/src/lib/services-abbreviation.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC7B,2CAAoB,CAAA;IACpB,wDAAiC,CAAA;IACjC,4CAAqB,CAAA;IACrB,4CAAqB,CAAA;IACrB,kDAA2B,CAAA;AAC7B,CAAC,EANW,mBAAmB,mCAAnB,mBAAmB,QAM9B"}
@@ -0,0 +1,6 @@
1
+ import "reflect-metadata";
2
+ export interface TransformPrnOptions {
3
+ array?: boolean;
4
+ nullable?: boolean;
5
+ }
6
+ export declare function TransformPrn(transformPrnOptions?: TransformPrnOptions): PropertyDecorator;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformPrn = TransformPrn;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const plate_resource_notation_model_1 = require("./plate-resource-notation.model");
6
+ require("reflect-metadata");
7
+ function TransformPrn(transformPrnOptions = { array: false, nullable: false }) {
8
+ return function (target, propertyKey) {
9
+ const reflectedType = Reflect.getMetadata("design:type", target, propertyKey);
10
+ if (reflectedType !== plate_resource_notation_model_1.PRN &&
11
+ !(reflectedType === Array && transformPrnOptions.array === true) &&
12
+ !(transformPrnOptions.nullable === true)) {
13
+ throw new TypeError("Only PRN types are valid for this decorator. If the field is nullable, you must specify it explicitly. " +
14
+ "If the field is an array of PRNs, you must specify the array option to be true (and be sure that the property is an array of PRNs).");
15
+ }
16
+ (0, class_transformer_1.Transform)(({ value }) => {
17
+ if (value === null || value === undefined) {
18
+ return value;
19
+ }
20
+ if (Array.isArray(value)) {
21
+ return value.map((prn) => plate_resource_notation_model_1.PRN.fromString(prn));
22
+ }
23
+ return plate_resource_notation_model_1.PRN.fromString(value);
24
+ }, {
25
+ toClassOnly: true,
26
+ })(target, propertyKey);
27
+ (0, class_transformer_1.Transform)(({ value }) => {
28
+ if (value === null || value === undefined) {
29
+ return value;
30
+ }
31
+ if (Array.isArray(value)) {
32
+ return value.map((prn) => prn.toString());
33
+ }
34
+ return value.toString();
35
+ }, {
36
+ toPlainOnly: true,
37
+ })(target, propertyKey);
38
+ };
39
+ }
40
+ //# sourceMappingURL=transform-prn.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-prn.decorator.js","sourceRoot":"","sources":["../../../../../../packages/plate-resource-notation/src/lib/transform-prn.decorator.ts"],"names":[],"mappings":";;AAcA,oCAmDC;AAjED,yDAA8C;AAC9C,mFAAsD;AACtD,4BAA0B;AAY1B,SAAgB,YAAY,CAC1B,sBAA2C,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE;IAE5E,OAAO,UAAU,MAAc,EAAE,WAA4B;QAE3D,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC9E,IACE,aAAa,KAAK,mCAAG;YACrB,CAAC,CAAC,aAAa,KAAK,KAAK,IAAI,mBAAmB,CAAC,KAAK,KAAK,IAAI,CAAC;YAChE,CAAC,CAAC,mBAAmB,CAAC,QAAQ,KAAK,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