@platecms/delta-plate-resource-notation 0.4.1 → 0.7.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/package.json +2 -3
- package/src/lib/invalid-prn.error.ts +5 -0
- package/src/lib/plate-resource-notation.model.spec.ts +102 -0
- package/src/lib/plate-resource-notation.model.ts +103 -0
- package/src/lib/prn-regex.constant.spec.ts +41 -0
- package/src/lib/prn-regex.constant.ts +5 -0
- package/src/lib/services-abbreviation.enum.ts +7 -0
- package/src/lib/transform-prn.decorator.spec.ts +131 -0
- package/src/lib/transform-prn.decorator.ts +66 -0
- package/src/index.js +0 -9
- package/src/index.js.map +0 -1
- package/src/lib/invalid-prn.error.d.ts +0 -3
- package/src/lib/invalid-prn.error.js +0 -10
- package/src/lib/invalid-prn.error.js.map +0 -1
- package/src/lib/plate-resource-notation.model.d.ts +0 -13
- package/src/lib/plate-resource-notation.model.js +0 -48
- package/src/lib/plate-resource-notation.model.js.map +0 -1
- package/src/lib/prn-regex.constant.d.ts +0 -1
- package/src/lib/prn-regex.constant.js +0 -5
- package/src/lib/prn-regex.constant.js.map +0 -1
- package/src/lib/services-abbreviation.enum.d.ts +0 -7
- package/src/lib/services-abbreviation.enum.js +0 -12
- package/src/lib/services-abbreviation.enum.js.map +0 -1
- package/src/lib/transform-prn.decorator.d.ts +0 -6
- package/src/lib/transform-prn.decorator.js +0 -40
- package/src/lib/transform-prn.decorator.js.map +0 -1
- /package/src/{index.d.ts → index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-plate-resource-notation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "PRNs are Plate's replacement for IDs. They contain context about the resource the PRN describes.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,6 +20,5 @@
|
|
|
20
20
|
"class-transformer": "0.5.1",
|
|
21
21
|
"reflect-metadata": "0.2.2",
|
|
22
22
|
"tslib": "2.8.1"
|
|
23
|
-
}
|
|
24
|
-
"type": "commonjs"
|
|
23
|
+
}
|
|
25
24
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { InvalidPrnError } from "./invalid-prn.error";
|
|
2
|
+
import { PRN } from "./plate-resource-notation.model";
|
|
3
|
+
import { ServiceAbbreviation } from "./services-abbreviation.enum";
|
|
4
|
+
|
|
5
|
+
describe("PRN", () => {
|
|
6
|
+
describe("constructor", () => {
|
|
7
|
+
it("creates a PRN object successfully", async () => {
|
|
8
|
+
// Arrange
|
|
9
|
+
const partition = "aa";
|
|
10
|
+
const organizationId = "bb";
|
|
11
|
+
const service = ServiceAbbreviation.ASSET_MANAGER;
|
|
12
|
+
const resourceType = "dd";
|
|
13
|
+
const resourceId = "ee";
|
|
14
|
+
|
|
15
|
+
// Act
|
|
16
|
+
const result: PRN = new PRN(partition, organizationId, service, resourceType, resourceId);
|
|
17
|
+
|
|
18
|
+
// Assert
|
|
19
|
+
expect(result).toBeDefined();
|
|
20
|
+
expect(result.partition).toStrictEqual(partition);
|
|
21
|
+
expect(result.organizationId).toStrictEqual(organizationId);
|
|
22
|
+
expect(result.service).toStrictEqual(service);
|
|
23
|
+
expect(result.resourceType).toStrictEqual(resourceType);
|
|
24
|
+
expect(result.resourceId).toStrictEqual(resourceId);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each([
|
|
28
|
+
{
|
|
29
|
+
partition: "aa",
|
|
30
|
+
organizationId: "bb",
|
|
31
|
+
service: ServiceAbbreviation.ASSET_MANAGER,
|
|
32
|
+
resourceName: "cc",
|
|
33
|
+
resourceId: "", // Empty part
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
partition: "aa",
|
|
37
|
+
organizationId: "b:b", // Part has a colon in it
|
|
38
|
+
service: ServiceAbbreviation.ASSET_MANAGER,
|
|
39
|
+
resourceName: "cc",
|
|
40
|
+
resourceId: "dd",
|
|
41
|
+
},
|
|
42
|
+
])("throws an InvalidPrnError when invalid input parameters %s are used", async (input) => {
|
|
43
|
+
expect(() => {
|
|
44
|
+
new PRN(input.partition, input.organizationId, input.service, input.resourceName, input.resourceId);
|
|
45
|
+
}).toThrowError(InvalidPrnError);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("toString", () => {
|
|
50
|
+
it.each([
|
|
51
|
+
{
|
|
52
|
+
partition: "ab",
|
|
53
|
+
organizationId: "cd",
|
|
54
|
+
service: ServiceAbbreviation.CONTENT_EXPERIENCE_CENTER,
|
|
55
|
+
resourceType: "ef",
|
|
56
|
+
resourceId: "gh",
|
|
57
|
+
},
|
|
58
|
+
])(`returns the correct string for "%s"`, async (input) => {
|
|
59
|
+
expect(
|
|
60
|
+
new PRN(input.partition, input.organizationId, input.service, input.resourceType, input.resourceId).toString(),
|
|
61
|
+
).toStrictEqual(
|
|
62
|
+
`prn:${input.partition}:${input.organizationId}:${input.service}:${input.resourceType}:${input.resourceId}`,
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("fromString", () => {
|
|
68
|
+
it("creates a PRN for a given PRN string successfully", async () => {
|
|
69
|
+
const result: PRN = PRN.fromString(`prn:aa:bb:${ServiceAbbreviation.ACCESS_CONTROL}:cc:dd`);
|
|
70
|
+
expect(result).toStrictEqual(new PRN("aa", "bb", ServiceAbbreviation.ACCESS_CONTROL, "cc", "dd"));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it.each([
|
|
74
|
+
`does-not-pass-regex`,
|
|
75
|
+
`prn:aa:bb:${"invalid-service" as ServiceAbbreviation}:cc:dd`, // Invalid ServiceAbbreviation
|
|
76
|
+
])('throws an InvalidPrnError when invalid PRN string "%s" is used', async (str: string) => {
|
|
77
|
+
expect(() => PRN.fromString(str)).toThrowError(InvalidPrnError);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("equals", () => {
|
|
82
|
+
it("Successfully checks equivalence of two equivalent PRN objects", async () => {
|
|
83
|
+
expect(
|
|
84
|
+
new PRN("ab", "cd", ServiceAbbreviation.ORGANIZATIONS_CENTER, "ef", "gh").equals(
|
|
85
|
+
new PRN("ab", "cd", ServiceAbbreviation.ORGANIZATIONS_CENTER, "ef", "gh"),
|
|
86
|
+
),
|
|
87
|
+
).toStrictEqual(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("Successfully checks equivalence of two distinct PRN objects", async () => {
|
|
91
|
+
expect(
|
|
92
|
+
new PRN("aa", "bb", ServiceAbbreviation.EMAILS_SERVICE, "cc", "dd").equals(
|
|
93
|
+
new PRN("zz", "cd", ServiceAbbreviation.EMAILS_SERVICE, "ef", "gh"),
|
|
94
|
+
),
|
|
95
|
+
).toStrictEqual(false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("Successfully checks equivalence of one PRN object and a different object", async () => {
|
|
99
|
+
expect(new PRN("aa", "bb", ServiceAbbreviation.EMAILS_SERVICE, "cc", "dd").equals(1234)).toStrictEqual(false);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ServiceAbbreviation } from "./services-abbreviation.enum";
|
|
2
|
+
import { InvalidPrnError } from "./invalid-prn.error";
|
|
3
|
+
import { PRN_REGEX } from "./prn-regex.constant";
|
|
4
|
+
|
|
5
|
+
export type PrnString = `prn:${string}:${string}:${ServiceAbbreviation}:${string}:${string}`;
|
|
6
|
+
|
|
7
|
+
export class PRN {
|
|
8
|
+
/**
|
|
9
|
+
* The instance of Plate Delta in which the resource resides. E.g. 'plate', 'plate-dev', '[client-name]'
|
|
10
|
+
*/
|
|
11
|
+
public readonly partition: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The id of the organization that owns the resource.
|
|
15
|
+
*/
|
|
16
|
+
public readonly organizationId: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Name of service that owns resource. E.g. 'cxc', 'oc'.
|
|
20
|
+
*/
|
|
21
|
+
public readonly service: ServiceAbbreviation;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The type of the resource. E.g. 'asset', 'directory', 'content-type'.
|
|
25
|
+
*/
|
|
26
|
+
public readonly resourceType: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Id of the resource. E.g. '1234', 'abcd'.
|
|
30
|
+
*/
|
|
31
|
+
public readonly resourceId: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new PRN.
|
|
35
|
+
* @throws InvalidPrnError when any of the given parameters are invalid.
|
|
36
|
+
*/
|
|
37
|
+
public constructor(
|
|
38
|
+
partition: string,
|
|
39
|
+
organizationId: string,
|
|
40
|
+
service: ServiceAbbreviation,
|
|
41
|
+
resourceType: string,
|
|
42
|
+
resourceId: string,
|
|
43
|
+
) {
|
|
44
|
+
const componentArray: string[] = [partition, service, organizationId, resourceType, resourceId];
|
|
45
|
+
|
|
46
|
+
if (!componentArray.every((comp: unknown) => typeof comp === "string" && comp.length > 0)) {
|
|
47
|
+
throw new InvalidPrnError("Invalid PRN component(s). All components must be a non-empty string.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (componentArray.some((comp: string) => comp.includes(":"))) {
|
|
51
|
+
throw new InvalidPrnError("Invalid PRN string specification. Components cannot contain ':'.");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.partition = partition;
|
|
55
|
+
this.organizationId = organizationId;
|
|
56
|
+
this.service = service;
|
|
57
|
+
this.resourceType = resourceType;
|
|
58
|
+
this.resourceId = resourceId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Static method to construct a PRN object from a string in PRN formatting.
|
|
63
|
+
* @throws InvalidPrnError An InvalidPrnError is thrown if no valid PRN could be constructed from the given string.
|
|
64
|
+
*/
|
|
65
|
+
public static fromString(prnString: string): PRN {
|
|
66
|
+
if (!PRN_REGEX.test(prnString)) {
|
|
67
|
+
throw new InvalidPrnError(`Invalid PRN string '${prnString}'. Should match the pattern '${PRN_REGEX.source}'`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const [_, partition, organizationId, service, resourceType, resourceId] = prnString.split(":");
|
|
71
|
+
|
|
72
|
+
// Ensure that the service abbreviation from the string is valid
|
|
73
|
+
if (!Object.values(ServiceAbbreviation).map(String).includes(service)) {
|
|
74
|
+
throw new InvalidPrnError(`Invalid ServiceAbbreviation '${service}'. Use the ServiceAbbreviation enum.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return new PRN(partition, organizationId, service as ServiceAbbreviation, resourceType, resourceId);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Return a stringified PRN.
|
|
82
|
+
*/
|
|
83
|
+
public toString(): string {
|
|
84
|
+
return `prn:${this.partition}:${this.organizationId}:${this.service}:${this.resourceType}:${this.resourceId}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Checks whether the given object has equal fields to this.
|
|
89
|
+
*/
|
|
90
|
+
public equals(other: unknown): boolean {
|
|
91
|
+
if (!(other instanceof PRN)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const key of Object.keys(this)) {
|
|
96
|
+
if (this[key as keyof PRN] !== other[key as keyof PRN]) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { PRN_REGEX } from "./prn-regex.constant";
|
|
2
|
+
import { ServiceAbbreviation } from "./services-abbreviation.enum";
|
|
3
|
+
|
|
4
|
+
describe("PRN_REGEX", () => {
|
|
5
|
+
let prnRegex: RegExp;
|
|
6
|
+
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
prnRegex = new RegExp(PRN_REGEX.source, "u");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it.each([
|
|
12
|
+
`prn:plate:1:${ServiceAbbreviation.EMAILS_SERVICE}:-any:1234`,
|
|
13
|
+
`prn:plate:12:${ServiceAbbreviation.ACCESS_CONTROL}:anything:a9ff417a-d8f7-1125-9ad7-7941d6222227`,
|
|
14
|
+
`prn:plate:1:${ServiceAbbreviation.ORGANIZATIONS_CENTER}:-something_else:1234`,
|
|
15
|
+
`prn:plate:1:${ServiceAbbreviation.CONTENT_EXPERIENCE_CENTER}:-any:8aaf417a-d8f7-4a6a-9ad7-7941d6222227`,
|
|
16
|
+
`prn:plate:1:${ServiceAbbreviation.ASSET_MANAGER}:-any:some_id`,
|
|
17
|
+
`prn:plate:1:${ServiceAbbreviation.CONTENT_EXPERIENCE_CENTER}:-any:someId`,
|
|
18
|
+
])("accepts correct PRN string '%s'", async (prnString: string) => {
|
|
19
|
+
// Act
|
|
20
|
+
const result: boolean = prnRegex.test(prnString);
|
|
21
|
+
|
|
22
|
+
// Assert
|
|
23
|
+
expect(result).toBeDefined();
|
|
24
|
+
expect(result).toStrictEqual<boolean>(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it.each([
|
|
28
|
+
`not-prn:plate:-1:${ServiceAbbreviation.EMAILS_SERVICE}:any:1234`,
|
|
29
|
+
`prn:plate:-1${ServiceAbbreviation.ACCESS_CONTROL}:too_little_components`,
|
|
30
|
+
`prn:plate:-1:${ServiceAbbreviation.ORGANIZATIONS_CENTER}:any:1234:too_many_components`,
|
|
31
|
+
`prn:plate:-1:${ServiceAbbreviation.CONTENT_EXPERIENCE_CENTER}:-any:`, // Empty component
|
|
32
|
+
`prn:plate:-1:${ServiceAbbreviation.CONTENT_EXPERIENCE_CENTER}:has white space:1234`,
|
|
33
|
+
])("denies incorrect PRN string '%s'", async (prnString: string) => {
|
|
34
|
+
// Act
|
|
35
|
+
const result: boolean = prnRegex.test(prnString);
|
|
36
|
+
|
|
37
|
+
// Assert
|
|
38
|
+
expect(result).toBeDefined();
|
|
39
|
+
expect(result).toStrictEqual<boolean>(false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { instanceToPlain, plainToInstance } from "class-transformer";
|
|
2
|
+
import { PRN } from "./plate-resource-notation.model";
|
|
3
|
+
import { TransformPrn } from "./transform-prn.decorator";
|
|
4
|
+
|
|
5
|
+
describe("TransformPrn", () => {
|
|
6
|
+
it("throws a TypeError when the property is not a PRN", () => {
|
|
7
|
+
expect(() => {
|
|
8
|
+
class TestClass {
|
|
9
|
+
@TransformPrn()
|
|
10
|
+
public testProperty!: string;
|
|
11
|
+
}
|
|
12
|
+
}).toThrow(TypeError);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("throws a TypeError when the property is an array of non-PRNs and the array option is not set", () => {
|
|
16
|
+
expect(() => {
|
|
17
|
+
class TestClass {
|
|
18
|
+
@TransformPrn()
|
|
19
|
+
public testProperty!: string[];
|
|
20
|
+
}
|
|
21
|
+
}).toThrow(TypeError);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("does not throw a TypeError when the property is a PRN", () => {
|
|
25
|
+
expect(() => {
|
|
26
|
+
class TestClass {
|
|
27
|
+
@TransformPrn()
|
|
28
|
+
public testProperty!: PRN;
|
|
29
|
+
}
|
|
30
|
+
}).not.toThrow(TypeError);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("does not throw a TypeError when the property is an array of PRNs", () => {
|
|
34
|
+
expect(() => {
|
|
35
|
+
class TestClass {
|
|
36
|
+
@TransformPrn({ array: true })
|
|
37
|
+
public testProperty!: PRN[];
|
|
38
|
+
}
|
|
39
|
+
}).not.toThrow(TypeError);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("properly transforms a string to a PRN", () => {
|
|
43
|
+
class TestClass {
|
|
44
|
+
@TransformPrn()
|
|
45
|
+
public testProperty!: PRN;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const testInstance = plainToInstance(TestClass, {
|
|
49
|
+
testProperty: "prn:plate:-1:cxc:content-field:id",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(testInstance.testProperty).toBeInstanceOf(PRN);
|
|
53
|
+
expect(testInstance.testProperty.toString()).toStrictEqual("prn:plate:-1:cxc:content-field:id");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("properly transforms an array of strings to an array of PRNs", () => {
|
|
57
|
+
class TestClass {
|
|
58
|
+
@TransformPrn({ array: true })
|
|
59
|
+
public testProperty!: PRN[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const testInstance = plainToInstance(TestClass, {
|
|
63
|
+
testProperty: ["prn:plate:-1:cxc:content-field:id", "prn:plate:-1:cxc:content-field:title"],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(testInstance.testProperty).toBeInstanceOf(Array);
|
|
67
|
+
expect(testInstance.testProperty[0]).toBeInstanceOf(PRN);
|
|
68
|
+
expect(testInstance.testProperty[1]).toBeInstanceOf(PRN);
|
|
69
|
+
expect(testInstance.testProperty[0].toString()).toBe("prn:plate:-1:cxc:content-field:id");
|
|
70
|
+
expect(testInstance.testProperty[1].toString()).toBe("prn:plate:-1:cxc:content-field:title");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("properly transforms a PRN to a string", () => {
|
|
74
|
+
class TestClass {
|
|
75
|
+
@TransformPrn()
|
|
76
|
+
public testProperty!: PRN;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const testInstance = new TestClass();
|
|
80
|
+
testInstance.testProperty = PRN.fromString("prn:plate:-1:cxc:content-field:id");
|
|
81
|
+
|
|
82
|
+
const plainObject = instanceToPlain(testInstance);
|
|
83
|
+
expect(plainObject.testProperty).toBe("prn:plate:-1:cxc:content-field:id");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("properly transforms an array of PRNs to an array of strings", () => {
|
|
87
|
+
class TestClass {
|
|
88
|
+
@TransformPrn({ array: true })
|
|
89
|
+
public testProperty!: PRN[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const testInstance = new TestClass();
|
|
93
|
+
testInstance.testProperty = [
|
|
94
|
+
PRN.fromString("prn:plate:-1:cxc:content-field:id"),
|
|
95
|
+
PRN.fromString("prn:plate:-1:cxc:content-field:title"),
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const plainObject = instanceToPlain(testInstance) as {
|
|
99
|
+
testProperty: unknown[];
|
|
100
|
+
};
|
|
101
|
+
expect(plainObject.testProperty).toBeInstanceOf(Array);
|
|
102
|
+
expect(plainObject.testProperty[0]).toBe("prn:plate:-1:cxc:content-field:id");
|
|
103
|
+
expect(plainObject.testProperty[1]).toBe("prn:plate:-1:cxc:content-field:title");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it.each([{ prnValue: null }, { prnValue: undefined }])(
|
|
107
|
+
"returns $prnValue when the given value is $prnValue",
|
|
108
|
+
async ({ prnValue }) => {
|
|
109
|
+
// Arrange
|
|
110
|
+
class TestClass {
|
|
111
|
+
@TransformPrn({
|
|
112
|
+
nullable: true,
|
|
113
|
+
})
|
|
114
|
+
public testProperty: PRN | null | undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const testInstance = new TestClass();
|
|
118
|
+
testInstance.testProperty = prnValue;
|
|
119
|
+
|
|
120
|
+
// Act
|
|
121
|
+
const plainObject = instanceToPlain(testInstance);
|
|
122
|
+
const instanceObject = plainToInstance(TestClass, plainObject);
|
|
123
|
+
|
|
124
|
+
// Assert
|
|
125
|
+
expect(plainObject).toBeDefined();
|
|
126
|
+
expect(plainObject.testProperty).toStrictEqual(prnValue);
|
|
127
|
+
expect(instanceObject).toBeDefined();
|
|
128
|
+
expect(instanceObject.testProperty).toStrictEqual(prnValue);
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Transform } from "class-transformer";
|
|
2
|
+
import { PRN } from "./plate-resource-notation.model";
|
|
3
|
+
import "reflect-metadata";
|
|
4
|
+
|
|
5
|
+
export interface TransformPrnOptions {
|
|
6
|
+
array?: boolean;
|
|
7
|
+
|
|
8
|
+
nullable?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transform a string to a PRN and vice versa.
|
|
13
|
+
* @param transformPrnOptions Specify whether the property is an array of PRNs
|
|
14
|
+
*/
|
|
15
|
+
export function TransformPrn(
|
|
16
|
+
transformPrnOptions: TransformPrnOptions = { array: false, nullable: false },
|
|
17
|
+
): PropertyDecorator {
|
|
18
|
+
return function (target: object, propertyKey: string | symbol) {
|
|
19
|
+
// Validate whether the property is a PRN.
|
|
20
|
+
const reflectedType = Reflect.getMetadata("design:type", target, propertyKey);
|
|
21
|
+
if (
|
|
22
|
+
reflectedType !== PRN &&
|
|
23
|
+
!(reflectedType === Array && transformPrnOptions.array === true) &&
|
|
24
|
+
!(transformPrnOptions.nullable === true)
|
|
25
|
+
) {
|
|
26
|
+
throw new TypeError(
|
|
27
|
+
"Only PRN types are valid for this decorator. If the field is nullable, you must specify it explicitly. " +
|
|
28
|
+
"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).",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Transform(
|
|
33
|
+
({ value }: { value: string[] | string | null | undefined }): PRN | PRN[] | null | undefined => {
|
|
34
|
+
if (value === null || value === undefined) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
return value.map((prn) => PRN.fromString(prn));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return PRN.fromString(value);
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
toClassOnly: true,
|
|
46
|
+
},
|
|
47
|
+
)(target, propertyKey);
|
|
48
|
+
|
|
49
|
+
Transform(
|
|
50
|
+
({ value }: { value: PRN | PRN[] | null | undefined }): string[] | string | null | undefined => {
|
|
51
|
+
if (value === null || value === undefined) {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return value.map((prn) => prn.toString());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return value.toString();
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
toPlainOnly: true,
|
|
63
|
+
},
|
|
64
|
+
)(target, propertyKey);
|
|
65
|
+
};
|
|
66
|
+
}
|
package/src/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidPrnError = void 0;
|
|
4
|
-
class InvalidPrnError extends Error {
|
|
5
|
-
constructor(prn) {
|
|
6
|
-
super(`The PRN '${prn}' is invalid or malformed.`);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.InvalidPrnError = InvalidPrnError;
|
|
10
|
-
//# sourceMappingURL=invalid-prn.error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAW;QAC5B,KAAK,CAAC,YAAY,GAAG,4BAA4B,CAAC,CAAC;IACrD,CAAC;CACF;AAJD,0CAIC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QAEhG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;YAC1F,MAAM,IAAI,mCAAe,CAAC,sEAAsE,CAAC,CAAC;QACpG,CAAC;QAED,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,mCAAe,CAAC,kEAAkE,CAAC,CAAC;QAChG,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAMM,MAAM,CAAC,UAAU,CAAC,SAAiB;QACxC,IAAI,CAAC,8BAAS,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,mCAAe,CAAC,uBAAuB,SAAS,gCAAgC,8BAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QACjH,CAAC;QAED,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAG/F,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,gDAAmB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,mCAAe,CAAC,gCAAgC,OAAO,sCAAsC,CAAC,CAAC;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const PRN_REGEX: RegExp;
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,IAAI,CAAC,EACxC,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,yGAAyG;gBACvG,qIAAqI,CACxI,CAAC;QACJ,CAAC;QAED,IAAA,6BAAS,EACP,CAAC,EAAE,KAAK,EAAmD,EAAkC,EAAE;YAC7F,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC1C,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,mCAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,CAAC;YAED,OAAO,mCAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,EACD;YACE,WAAW,EAAE,IAAI;SAClB,CACF,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAEvB,IAAA,6BAAS,EACP,CAAC,EAAE,KAAK,EAA6C,EAAwC,EAAE;YAC7F,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC1C,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC5C,CAAC;YAED,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC1B,CAAC,EACD;YACE,WAAW,EAAE,IAAI;SAClB,CACF,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC"}
|
|
File without changes
|