@onlineapps/content-resolver 1.1.1 → 1.1.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/README.md +7 -0
- package/package.json +2 -1
- package/src/index.js +11 -2
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ const content = await resolver.resolve('minio://workflow/path/to/file.txt');
|
|
|
41
41
|
// Store large content - returns Content Descriptor
|
|
42
42
|
const descriptor = await resolver.store(largeText, { workflow_id: 'wf-123' }, 'document.html');
|
|
43
43
|
// → {
|
|
44
|
+
// _descriptor: true,
|
|
44
45
|
// type: 'file',
|
|
45
46
|
// storage_ref: 'minio://workflow/...',
|
|
46
47
|
// filename: 'document.html',
|
|
@@ -122,6 +123,7 @@ Stores large content fields as Descriptors (returns Descriptors, not plain strin
|
|
|
122
123
|
```javascript
|
|
123
124
|
// Inline content (small)
|
|
124
125
|
{
|
|
126
|
+
_descriptor: true,
|
|
125
127
|
type: 'inline',
|
|
126
128
|
content: 'actual text content',
|
|
127
129
|
encoding: 'utf-8',
|
|
@@ -133,6 +135,7 @@ Stores large content fields as Descriptors (returns Descriptors, not plain strin
|
|
|
133
135
|
|
|
134
136
|
// File content (large or binary)
|
|
135
137
|
{
|
|
138
|
+
_descriptor: true,
|
|
136
139
|
type: 'file',
|
|
137
140
|
storage_ref: 'minio://workflow/path/to/file',
|
|
138
141
|
filename: 'invoice.pdf',
|
|
@@ -142,6 +145,10 @@ Stores large content fields as Descriptors (returns Descriptors, not plain strin
|
|
|
142
145
|
}
|
|
143
146
|
```
|
|
144
147
|
|
|
148
|
+
**Descriptor Identification:**
|
|
149
|
+
- `_descriptor: true` - Explicit identifier that value is a Content Descriptor
|
|
150
|
+
- `type: "inline"|"file"` - Distinguishes inline text from file reference
|
|
151
|
+
|
|
145
152
|
### Usage Example
|
|
146
153
|
|
|
147
154
|
```javascript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/content-resolver",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Automatic conversion between text content and storage references with Content Descriptor pattern",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,3 +22,4 @@
|
|
|
22
22
|
"@onlineapps/conn-base-storage": "^1.0.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
|
package/src/index.js
CHANGED
|
@@ -28,7 +28,8 @@ function isDescriptor(value) {
|
|
|
28
28
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
// Check explicit identifier first, then fallback to type check for backward compatibility
|
|
32
|
+
return value._descriptor === true || (value.type === 'inline' || value.type === 'file');
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -196,6 +197,7 @@ class ContentResolver {
|
|
|
196
197
|
async store(content, context = {}, filename = null, content_type = null) {
|
|
197
198
|
if (!content) {
|
|
198
199
|
return {
|
|
200
|
+
_descriptor: true,
|
|
199
201
|
type: 'inline',
|
|
200
202
|
content: '',
|
|
201
203
|
encoding: 'utf-8',
|
|
@@ -417,6 +419,7 @@ class ContentResolver {
|
|
|
417
419
|
const finalContentType = content_type || getContentType(finalFilename, buffer);
|
|
418
420
|
|
|
419
421
|
return {
|
|
422
|
+
_descriptor: true,
|
|
420
423
|
type: 'file',
|
|
421
424
|
storage_ref: `minio://workflow/${result.path}`,
|
|
422
425
|
filename: finalFilename,
|
|
@@ -450,6 +453,7 @@ class ContentResolver {
|
|
|
450
453
|
const finalFilename = filename || `${result.fingerprint.slice(0, 8)}.${ext}`;
|
|
451
454
|
|
|
452
455
|
return {
|
|
456
|
+
_descriptor: true,
|
|
453
457
|
type: 'file',
|
|
454
458
|
storage_ref: `minio://workflow/${result.path}`,
|
|
455
459
|
filename: finalFilename,
|
|
@@ -464,6 +468,7 @@ class ContentResolver {
|
|
|
464
468
|
const fingerprint = crypto.createHash('sha256').update(contentString).digest('hex');
|
|
465
469
|
|
|
466
470
|
return {
|
|
471
|
+
_descriptor: true,
|
|
467
472
|
type: 'inline',
|
|
468
473
|
content: contentString,
|
|
469
474
|
encoding: 'utf-8',
|
|
@@ -481,8 +486,12 @@ class ContentResolver {
|
|
|
481
486
|
* @returns {Promise<Object>} Content Descriptor
|
|
482
487
|
*/
|
|
483
488
|
async normalizeToDescriptor(value, options = {}) {
|
|
484
|
-
// Already a Descriptor
|
|
489
|
+
// Already a Descriptor - ensure it has _descriptor flag
|
|
485
490
|
if (isDescriptor(value)) {
|
|
491
|
+
// Ensure _descriptor flag is present
|
|
492
|
+
if (value._descriptor !== true) {
|
|
493
|
+
return { ...value, _descriptor: true };
|
|
494
|
+
}
|
|
486
495
|
return value;
|
|
487
496
|
}
|
|
488
497
|
|