@liquidmetal-ai/drizzle 0.4.1 → 0.4.3

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/dist/mrn.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { MRNObject } from '@liquidmetal-ai/raindrop-framework';
2
+ /**
3
+ * Parses a Metal Resource Name (MRN) string into its exploded object form.
4
+ *
5
+ * @param mrn - The MRN string to parse
6
+ * @returns An object representing the parsed MRN components
7
+ * @throws {Error} If the MRN format is invalid
8
+ */
9
+ export declare function parseMRN(mrn: string): MRNObject;
10
+ export declare function parsePartialMRN(mrn: string): Partial<MRNObject>;
11
+ /**
12
+ * Serializes an MRN object back into its string representation.
13
+ *
14
+ * @param mrnObject - The MRN object to serialize
15
+ * @returns The MRN string representation
16
+ */
17
+ export declare function serializeMRN(mrnObject: MRNObject): string;
18
+ /**
19
+ * Serializes a partial MRN object into its string representation.
20
+ * Only includes the parts that are defined, building incrementally.
21
+ *
22
+ * @param mrnObject - The partial MRN object to serialize
23
+ * @returns The partial MRN string representation
24
+ */
25
+ export declare function serializePartialMRN(mrnObject: Partial<MRNObject>): string;
26
+ //# sourceMappingURL=mrn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mrn.d.ts","sourceRoot":"","sources":["../src/mrn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAqC/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CA8B/D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAkBzD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,MAAM,CAkCzE"}
package/dist/mrn.js ADDED
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Parses a Metal Resource Name (MRN) string into its exploded object form.
3
+ *
4
+ * @param mrn - The MRN string to parse
5
+ * @returns An object representing the parsed MRN components
6
+ * @throws {Error} If the MRN format is invalid
7
+ */
8
+ export function parseMRN(mrn) {
9
+ const parts = mrn.split(':');
10
+ if (parts.length !== 6) {
11
+ throw new Error(`Invalid MRN format: ${mrn}`);
12
+ }
13
+ const [type, applicationName, versionId, module, itemOrKey, revision] = parts;
14
+ if (!type || !applicationName || !versionId) {
15
+ throw new Error(`MRN must contain type, applicationName, and versionId: ${mrn}`);
16
+ }
17
+ if (!['annotation', 'label'].includes(type)) {
18
+ throw new Error(`Invalid MRN type: ${type}`);
19
+ }
20
+ const mrnObject = {
21
+ type: type,
22
+ applicationName,
23
+ versionId,
24
+ };
25
+ if (module) {
26
+ mrnObject.module = module;
27
+ }
28
+ if (itemOrKey) {
29
+ if (itemOrKey.includes('^')) {
30
+ const [item, keyValue] = itemOrKey.split('^');
31
+ mrnObject.item = item;
32
+ mrnObject.key = keyValue || '';
33
+ }
34
+ else {
35
+ mrnObject.key = itemOrKey;
36
+ }
37
+ }
38
+ if (revision) {
39
+ mrnObject.revision = revision;
40
+ }
41
+ return mrnObject;
42
+ }
43
+ /* parse partial mrn, useful for partial lists or queries */
44
+ export function parsePartialMRN(mrn) {
45
+ const parts = mrn.split(':');
46
+ const partialMRN = {};
47
+ const [type, applicationName, versionId, module, itemOrKey, revision] = parts;
48
+ if (type) {
49
+ partialMRN.type = type;
50
+ }
51
+ if (applicationName) {
52
+ partialMRN.applicationName = applicationName;
53
+ }
54
+ if (versionId) {
55
+ partialMRN.versionId = versionId;
56
+ }
57
+ if (module) {
58
+ partialMRN.module = module;
59
+ }
60
+ if (itemOrKey) {
61
+ if (itemOrKey.includes('^')) {
62
+ const [item, keyValue] = itemOrKey.split('^');
63
+ partialMRN.item = item;
64
+ partialMRN.key = keyValue || '';
65
+ }
66
+ else {
67
+ partialMRN.key = itemOrKey;
68
+ partialMRN.item = undefined; // Ensure item is not set if only key is present
69
+ }
70
+ }
71
+ if (revision) {
72
+ partialMRN.revision = revision;
73
+ }
74
+ return partialMRN;
75
+ }
76
+ /**
77
+ * Serializes an MRN object back into its string representation.
78
+ *
79
+ * @param mrnObject - The MRN object to serialize
80
+ * @returns The MRN string representation
81
+ */
82
+ export function serializeMRN(mrnObject) {
83
+ let keyPart = '';
84
+ if (mrnObject.item !== undefined) {
85
+ keyPart = `${mrnObject.item}^${mrnObject.key || ''}`;
86
+ }
87
+ else if (mrnObject.key) {
88
+ keyPart = mrnObject.key;
89
+ }
90
+ const parts = [
91
+ mrnObject.type,
92
+ mrnObject.applicationName,
93
+ mrnObject.versionId,
94
+ mrnObject.module || '',
95
+ keyPart,
96
+ mrnObject.revision || '',
97
+ ];
98
+ return parts.join(':');
99
+ }
100
+ /**
101
+ * Serializes a partial MRN object into its string representation.
102
+ * Only includes the parts that are defined, building incrementally.
103
+ *
104
+ * @param mrnObject - The partial MRN object to serialize
105
+ * @returns The partial MRN string representation
106
+ */
107
+ export function serializePartialMRN(mrnObject) {
108
+ const parts = [];
109
+ if (mrnObject.type) {
110
+ parts.push(mrnObject.type);
111
+ }
112
+ if (mrnObject.applicationName) {
113
+ parts.push(mrnObject.applicationName);
114
+ }
115
+ if (mrnObject.versionId) {
116
+ parts.push(mrnObject.versionId);
117
+ }
118
+ if (mrnObject.module) {
119
+ parts.push(mrnObject.module);
120
+ }
121
+ if (mrnObject.item !== undefined || mrnObject.key) {
122
+ let keyPart = '';
123
+ if (mrnObject.item !== undefined) {
124
+ keyPart = `${mrnObject.item}^${mrnObject.key || ''}`;
125
+ }
126
+ else if (mrnObject.key) {
127
+ keyPart = mrnObject.key;
128
+ }
129
+ parts.push(keyPart);
130
+ }
131
+ if (mrnObject.revision) {
132
+ parts.push(mrnObject.revision);
133
+ }
134
+ return parts.join(':');
135
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mrn.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mrn.test.d.ts","sourceRoot":"","sources":["../src/mrn.test.ts"],"names":[],"mappings":""}