@oddington/sdk 0.1.5 → 0.1.7
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 +119 -2
- package/dist/index.js +1419 -344
- package/dist/types/packages/sdk/src/public.d.ts +66 -2
- package/dist/types/shared/data-contract.d.ts +14 -0
- package/dist/types/shared/files-contract.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -697,7 +697,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
697
697
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
698
698
|
});
|
|
699
699
|
}
|
|
700
|
-
function __generator(thisArg,
|
|
700
|
+
function __generator(thisArg, body2) {
|
|
701
701
|
var _ = { label: 0, sent: function() {
|
|
702
702
|
if (t[0] & 1)
|
|
703
703
|
throw t[1];
|
|
@@ -761,7 +761,7 @@ function __generator(thisArg, body) {
|
|
|
761
761
|
_.trys.pop();
|
|
762
762
|
continue;
|
|
763
763
|
}
|
|
764
|
-
op =
|
|
764
|
+
op = body2.call(thisArg, _);
|
|
765
765
|
} catch (e) {
|
|
766
766
|
op = [6, e];
|
|
767
767
|
y = 0;
|
|
@@ -6329,30 +6329,30 @@ var init_PDFArray = __esm(() => {
|
|
|
6329
6329
|
init_errors();
|
|
6330
6330
|
PDFArray = function(_super) {
|
|
6331
6331
|
__extends(PDFArray2, _super);
|
|
6332
|
-
function PDFArray2(
|
|
6332
|
+
function PDFArray2(context2) {
|
|
6333
6333
|
var _this = _super.call(this) || this;
|
|
6334
6334
|
_this.array = [];
|
|
6335
|
-
_this.context =
|
|
6335
|
+
_this.context = context2;
|
|
6336
6336
|
return _this;
|
|
6337
6337
|
}
|
|
6338
6338
|
PDFArray2.prototype.size = function() {
|
|
6339
6339
|
return this.array.length;
|
|
6340
6340
|
};
|
|
6341
|
-
PDFArray2.prototype.push = function(
|
|
6342
|
-
this.array.push(
|
|
6341
|
+
PDFArray2.prototype.push = function(object4) {
|
|
6342
|
+
this.array.push(object4);
|
|
6343
6343
|
};
|
|
6344
|
-
PDFArray2.prototype.insert = function(index,
|
|
6345
|
-
this.array.splice(index, 0,
|
|
6344
|
+
PDFArray2.prototype.insert = function(index, object4) {
|
|
6345
|
+
this.array.splice(index, 0, object4);
|
|
6346
6346
|
};
|
|
6347
|
-
PDFArray2.prototype.indexOf = function(
|
|
6348
|
-
var index = this.array.indexOf(
|
|
6347
|
+
PDFArray2.prototype.indexOf = function(object4) {
|
|
6348
|
+
var index = this.array.indexOf(object4);
|
|
6349
6349
|
return index === -1 ? undefined : index;
|
|
6350
6350
|
};
|
|
6351
6351
|
PDFArray2.prototype.remove = function(index) {
|
|
6352
6352
|
this.array.splice(index, 1);
|
|
6353
6353
|
};
|
|
6354
|
-
PDFArray2.prototype.set = function(idx2,
|
|
6355
|
-
this.array[idx2] =
|
|
6354
|
+
PDFArray2.prototype.set = function(idx2, object4) {
|
|
6355
|
+
this.array[idx2] = object4;
|
|
6356
6356
|
};
|
|
6357
6357
|
PDFArray2.prototype.get = function(index) {
|
|
6358
6358
|
return this.array[index];
|
|
@@ -6389,8 +6389,8 @@ var init_PDFArray = __esm(() => {
|
|
|
6389
6389
|
PDFArray2.prototype.asArray = function() {
|
|
6390
6390
|
return this.array.slice();
|
|
6391
6391
|
};
|
|
6392
|
-
PDFArray2.prototype.clone = function(
|
|
6393
|
-
var clone = PDFArray2.withContext(
|
|
6392
|
+
PDFArray2.prototype.clone = function(context2) {
|
|
6393
|
+
var clone = PDFArray2.withContext(context2 || this.context);
|
|
6394
6394
|
for (var idx2 = 0, len = this.size();idx2 < len; idx2++) {
|
|
6395
6395
|
clone.push(this.array[idx2]);
|
|
6396
6396
|
}
|
|
@@ -6432,8 +6432,8 @@ var init_PDFArray = __esm(() => {
|
|
|
6432
6432
|
}
|
|
6433
6433
|
}
|
|
6434
6434
|
};
|
|
6435
|
-
PDFArray2.withContext = function(
|
|
6436
|
-
return new PDFArray2(
|
|
6435
|
+
PDFArray2.withContext = function(context2) {
|
|
6436
|
+
return new PDFArray2(context2);
|
|
6437
6437
|
};
|
|
6438
6438
|
return PDFArray2;
|
|
6439
6439
|
}(PDFObject_default);
|
|
@@ -6708,10 +6708,10 @@ var init_PDFDict = __esm(() => {
|
|
|
6708
6708
|
init_CharCodes();
|
|
6709
6709
|
PDFDict = function(_super) {
|
|
6710
6710
|
__extends(PDFDict2, _super);
|
|
6711
|
-
function PDFDict2(map,
|
|
6711
|
+
function PDFDict2(map, context2) {
|
|
6712
6712
|
var _this = _super.call(this) || this;
|
|
6713
6713
|
_this.dict = map;
|
|
6714
|
-
_this.context =
|
|
6714
|
+
_this.context = context2;
|
|
6715
6715
|
return _this;
|
|
6716
6716
|
}
|
|
6717
6717
|
PDFDict2.prototype.keys = function() {
|
|
@@ -6780,8 +6780,8 @@ var init_PDFDict = __esm(() => {
|
|
|
6780
6780
|
}
|
|
6781
6781
|
return key;
|
|
6782
6782
|
};
|
|
6783
|
-
PDFDict2.prototype.clone = function(
|
|
6784
|
-
var clone = PDFDict2.withContext(
|
|
6783
|
+
PDFDict2.prototype.clone = function(context2) {
|
|
6784
|
+
var clone = PDFDict2.withContext(context2 || this.context);
|
|
6785
6785
|
var entries = this.entries();
|
|
6786
6786
|
for (var idx3 = 0, len2 = entries.length;idx3 < len2; idx3++) {
|
|
6787
6787
|
var _a = entries[idx3], key = _a[0], value = _a[1];
|
|
@@ -6827,11 +6827,11 @@ var init_PDFDict = __esm(() => {
|
|
|
6827
6827
|
buffer[offset++] = CharCodes_default.GreaterThan;
|
|
6828
6828
|
return offset - initialOffset;
|
|
6829
6829
|
};
|
|
6830
|
-
PDFDict2.withContext = function(
|
|
6831
|
-
return new PDFDict2(new Map,
|
|
6830
|
+
PDFDict2.withContext = function(context2) {
|
|
6831
|
+
return new PDFDict2(new Map, context2);
|
|
6832
6832
|
};
|
|
6833
|
-
PDFDict2.fromMapWithContext = function(map,
|
|
6834
|
-
return new PDFDict2(map,
|
|
6833
|
+
PDFDict2.fromMapWithContext = function(map, context2) {
|
|
6834
|
+
return new PDFDict2(map, context2);
|
|
6835
6835
|
};
|
|
6836
6836
|
return PDFDict2;
|
|
6837
6837
|
}(PDFObject_default);
|
|
@@ -6934,8 +6934,8 @@ var init_PDFRawStream = __esm(() => {
|
|
|
6934
6934
|
PDFRawStream2.prototype.asUint8Array = function() {
|
|
6935
6935
|
return this.contents.slice();
|
|
6936
6936
|
};
|
|
6937
|
-
PDFRawStream2.prototype.clone = function(
|
|
6938
|
-
return PDFRawStream2.of(this.dict.clone(
|
|
6937
|
+
PDFRawStream2.prototype.clone = function(context2) {
|
|
6938
|
+
return PDFRawStream2.of(this.dict.clone(context2), this.contents.slice());
|
|
6939
6939
|
};
|
|
6940
6940
|
PDFRawStream2.prototype.getContentsString = function() {
|
|
6941
6941
|
return arrayAsString(this.contents);
|
|
@@ -7016,11 +7016,11 @@ var init_PDFOperator = __esm(() => {
|
|
|
7016
7016
|
this.name = name;
|
|
7017
7017
|
this.args = args || [];
|
|
7018
7018
|
}
|
|
7019
|
-
PDFOperator2.prototype.clone = function(
|
|
7019
|
+
PDFOperator2.prototype.clone = function(context2) {
|
|
7020
7020
|
var args = new Array(this.args.length);
|
|
7021
7021
|
for (var idx3 = 0, len2 = args.length;idx3 < len2; idx3++) {
|
|
7022
7022
|
var arg = this.args[idx3];
|
|
7023
|
-
args[idx3] = arg instanceof PDFObject_default ? arg.clone(
|
|
7023
|
+
args[idx3] = arg instanceof PDFObject_default ? arg.clone(context2) : arg;
|
|
7024
7024
|
}
|
|
7025
7025
|
return PDFOperator2.of(this.name, args);
|
|
7026
7026
|
};
|
|
@@ -7205,13 +7205,13 @@ var init_PDFContentStream = __esm(() => {
|
|
|
7205
7205
|
}
|
|
7206
7206
|
(_a = this.operators).push.apply(_a, operators);
|
|
7207
7207
|
};
|
|
7208
|
-
PDFContentStream2.prototype.clone = function(
|
|
7208
|
+
PDFContentStream2.prototype.clone = function(context2) {
|
|
7209
7209
|
var operators = new Array(this.operators.length);
|
|
7210
7210
|
for (var idx3 = 0, len2 = this.operators.length;idx3 < len2; idx3++) {
|
|
7211
|
-
operators[idx3] = this.operators[idx3].clone(
|
|
7211
|
+
operators[idx3] = this.operators[idx3].clone(context2);
|
|
7212
7212
|
}
|
|
7213
7213
|
var _a = this, dict = _a.dict, encode = _a.encode;
|
|
7214
|
-
return PDFContentStream2.of(dict.clone(
|
|
7214
|
+
return PDFContentStream2.of(dict.clone(context2), operators, encode);
|
|
7215
7215
|
};
|
|
7216
7216
|
PDFContentStream2.prototype.getContentsString = function() {
|
|
7217
7217
|
var value = "";
|
|
@@ -7299,8 +7299,8 @@ var init_PDFContext = __esm(() => {
|
|
|
7299
7299
|
this.indirectObjects = new Map;
|
|
7300
7300
|
this.rng = SimpleRNG.withSeed(1);
|
|
7301
7301
|
}
|
|
7302
|
-
PDFContext2.prototype.assign = function(ref,
|
|
7303
|
-
this.indirectObjects.set(ref,
|
|
7302
|
+
PDFContext2.prototype.assign = function(ref, object4) {
|
|
7303
|
+
this.indirectObjects.set(ref, object4);
|
|
7304
7304
|
if (ref.objectNumber > this.largestObjectNumber) {
|
|
7305
7305
|
this.largestObjectNumber = ref.objectNumber;
|
|
7306
7306
|
}
|
|
@@ -7309,9 +7309,9 @@ var init_PDFContext = __esm(() => {
|
|
|
7309
7309
|
this.largestObjectNumber += 1;
|
|
7310
7310
|
return PDFRef_default.of(this.largestObjectNumber);
|
|
7311
7311
|
};
|
|
7312
|
-
PDFContext2.prototype.register = function(
|
|
7312
|
+
PDFContext2.prototype.register = function(object4) {
|
|
7313
7313
|
var ref = this.nextRef();
|
|
7314
|
-
this.assign(ref,
|
|
7314
|
+
this.assign(ref, object4);
|
|
7315
7315
|
return ref;
|
|
7316
7316
|
};
|
|
7317
7317
|
PDFContext2.prototype.delete = function(ref) {
|
|
@@ -7361,8 +7361,8 @@ var init_PDFContext = __esm(() => {
|
|
|
7361
7361
|
PDFContext2.prototype.getObjectRef = function(pdfObject) {
|
|
7362
7362
|
var entries = Array.from(this.indirectObjects.entries());
|
|
7363
7363
|
for (var idx3 = 0, len2 = entries.length;idx3 < len2; idx3++) {
|
|
7364
|
-
var _a = entries[idx3], ref = _a[0],
|
|
7365
|
-
if (
|
|
7364
|
+
var _a = entries[idx3], ref = _a[0], object4 = _a[1];
|
|
7365
|
+
if (object4 === pdfObject) {
|
|
7366
7366
|
return ref;
|
|
7367
7367
|
}
|
|
7368
7368
|
}
|
|
@@ -7390,9 +7390,9 @@ var init_PDFContext = __esm(() => {
|
|
|
7390
7390
|
return array2;
|
|
7391
7391
|
} else {
|
|
7392
7392
|
var dict = PDFDict_default.withContext(this);
|
|
7393
|
-
var
|
|
7394
|
-
for (var idx3 = 0, len2 =
|
|
7395
|
-
var key =
|
|
7393
|
+
var keys4 = Object.keys(literal);
|
|
7394
|
+
for (var idx3 = 0, len2 = keys4.length;idx3 < len2; idx3++) {
|
|
7395
|
+
var key = keys4[idx3];
|
|
7396
7396
|
var value = literal[key];
|
|
7397
7397
|
if (value !== undefined)
|
|
7398
7398
|
dict.set(PDFName_default.of(key), this.obj(value));
|
|
@@ -7469,17 +7469,17 @@ var init_PDFPageLeaf = __esm(() => {
|
|
|
7469
7469
|
init_PDFStream();
|
|
7470
7470
|
PDFPageLeaf = function(_super) {
|
|
7471
7471
|
__extends(PDFPageLeaf2, _super);
|
|
7472
|
-
function PDFPageLeaf2(map,
|
|
7472
|
+
function PDFPageLeaf2(map, context2, autoNormalizeCTM) {
|
|
7473
7473
|
if (autoNormalizeCTM === undefined) {
|
|
7474
7474
|
autoNormalizeCTM = true;
|
|
7475
7475
|
}
|
|
7476
|
-
var _this = _super.call(this, map,
|
|
7476
|
+
var _this = _super.call(this, map, context2) || this;
|
|
7477
7477
|
_this.normalized = false;
|
|
7478
7478
|
_this.autoNormalizeCTM = autoNormalizeCTM;
|
|
7479
7479
|
return _this;
|
|
7480
7480
|
}
|
|
7481
|
-
PDFPageLeaf2.prototype.clone = function(
|
|
7482
|
-
var clone = PDFPageLeaf2.fromMapWithContext(new Map,
|
|
7481
|
+
PDFPageLeaf2.prototype.clone = function(context2) {
|
|
7482
|
+
var clone = PDFPageLeaf2.fromMapWithContext(new Map, context2 || this.context, this.autoNormalizeCTM);
|
|
7483
7483
|
var entries = this.entries();
|
|
7484
7484
|
for (var idx3 = 0, len2 = entries.length;idx3 < len2; idx3++) {
|
|
7485
7485
|
var _a = entries[idx3], key = _a[0], value = _a[1];
|
|
@@ -7605,25 +7605,25 @@ var init_PDFPageLeaf = __esm(() => {
|
|
|
7605
7605
|
PDFPageLeaf2.prototype.normalize = function() {
|
|
7606
7606
|
if (this.normalized)
|
|
7607
7607
|
return;
|
|
7608
|
-
var
|
|
7608
|
+
var context2 = this.context;
|
|
7609
7609
|
var contentsRef = this.get(PDFName_default.Contents);
|
|
7610
7610
|
var contents = this.context.lookup(contentsRef);
|
|
7611
7611
|
if (contents instanceof PDFStream_default) {
|
|
7612
|
-
this.set(PDFName_default.Contents,
|
|
7612
|
+
this.set(PDFName_default.Contents, context2.obj([contentsRef]));
|
|
7613
7613
|
}
|
|
7614
7614
|
if (this.autoNormalizeCTM) {
|
|
7615
7615
|
this.wrapContentStreams(this.context.getPushGraphicsStateContentStream(), this.context.getPopGraphicsStateContentStream());
|
|
7616
7616
|
}
|
|
7617
7617
|
var dictOrRef = this.getInheritableAttribute(PDFName_default.Resources);
|
|
7618
|
-
var Resources =
|
|
7618
|
+
var Resources = context2.lookupMaybe(dictOrRef, PDFDict_default) || context2.obj({});
|
|
7619
7619
|
this.set(PDFName_default.Resources, Resources);
|
|
7620
|
-
var Font3 = Resources.lookupMaybe(PDFName_default.Font, PDFDict_default) ||
|
|
7620
|
+
var Font3 = Resources.lookupMaybe(PDFName_default.Font, PDFDict_default) || context2.obj({});
|
|
7621
7621
|
Resources.set(PDFName_default.Font, Font3);
|
|
7622
|
-
var XObject = Resources.lookupMaybe(PDFName_default.XObject, PDFDict_default) ||
|
|
7622
|
+
var XObject = Resources.lookupMaybe(PDFName_default.XObject, PDFDict_default) || context2.obj({});
|
|
7623
7623
|
Resources.set(PDFName_default.XObject, XObject);
|
|
7624
|
-
var ExtGState = Resources.lookupMaybe(PDFName_default.ExtGState, PDFDict_default) ||
|
|
7624
|
+
var ExtGState = Resources.lookupMaybe(PDFName_default.ExtGState, PDFDict_default) || context2.obj({});
|
|
7625
7625
|
Resources.set(PDFName_default.ExtGState, ExtGState);
|
|
7626
|
-
var Annots = this.Annots() ||
|
|
7626
|
+
var Annots = this.Annots() || context2.obj([]);
|
|
7627
7627
|
this.set(PDFName_default.Annots, Annots);
|
|
7628
7628
|
this.normalized = true;
|
|
7629
7629
|
};
|
|
@@ -7647,19 +7647,19 @@ var init_PDFPageLeaf = __esm(() => {
|
|
|
7647
7647
|
"CropBox",
|
|
7648
7648
|
"Rotate"
|
|
7649
7649
|
];
|
|
7650
|
-
PDFPageLeaf2.withContextAndParent = function(
|
|
7650
|
+
PDFPageLeaf2.withContextAndParent = function(context2, parent) {
|
|
7651
7651
|
var dict = new Map;
|
|
7652
7652
|
dict.set(PDFName_default.Type, PDFName_default.Page);
|
|
7653
7653
|
dict.set(PDFName_default.Parent, parent);
|
|
7654
|
-
dict.set(PDFName_default.Resources,
|
|
7655
|
-
dict.set(PDFName_default.MediaBox,
|
|
7656
|
-
return new PDFPageLeaf2(dict,
|
|
7654
|
+
dict.set(PDFName_default.Resources, context2.obj({}));
|
|
7655
|
+
dict.set(PDFName_default.MediaBox, context2.obj([0, 0, 612, 792]));
|
|
7656
|
+
return new PDFPageLeaf2(dict, context2, false);
|
|
7657
7657
|
};
|
|
7658
|
-
PDFPageLeaf2.fromMapWithContext = function(map,
|
|
7658
|
+
PDFPageLeaf2.fromMapWithContext = function(map, context2, autoNormalizeCTM) {
|
|
7659
7659
|
if (autoNormalizeCTM === undefined) {
|
|
7660
7660
|
autoNormalizeCTM = true;
|
|
7661
7661
|
}
|
|
7662
|
-
return new PDFPageLeaf2(map,
|
|
7662
|
+
return new PDFPageLeaf2(map, context2, autoNormalizeCTM);
|
|
7663
7663
|
};
|
|
7664
7664
|
return PDFPageLeaf2;
|
|
7665
7665
|
}(PDFDict_default);
|
|
@@ -7679,8 +7679,8 @@ var init_PDFObjectCopier = __esm(() => {
|
|
|
7679
7679
|
function PDFObjectCopier2(src, dest) {
|
|
7680
7680
|
var _this = this;
|
|
7681
7681
|
this.traversedObjects = new Map;
|
|
7682
|
-
this.copy = function(
|
|
7683
|
-
return
|
|
7682
|
+
this.copy = function(object4) {
|
|
7683
|
+
return object4 instanceof PDFPageLeaf_default ? _this.copyPDFPage(object4) : object4 instanceof PDFDict_default ? _this.copyPDFDict(object4) : object4 instanceof PDFArray_default ? _this.copyPDFArray(object4) : object4 instanceof PDFStream_default ? _this.copyPDFStream(object4) : object4 instanceof PDFRef_default ? _this.copyPDFIndirectObject(object4) : object4.clone();
|
|
7684
7684
|
};
|
|
7685
7685
|
this.copyPDFPage = function(originalPage) {
|
|
7686
7686
|
var clonedPage = originalPage.clone();
|
|
@@ -7974,11 +7974,11 @@ var init_PDFObjectStream = __esm(() => {
|
|
|
7974
7974
|
init_utils2();
|
|
7975
7975
|
PDFObjectStream = function(_super) {
|
|
7976
7976
|
__extends(PDFObjectStream2, _super);
|
|
7977
|
-
function PDFObjectStream2(
|
|
7977
|
+
function PDFObjectStream2(context2, objects2, encode) {
|
|
7978
7978
|
if (encode === undefined) {
|
|
7979
7979
|
encode = true;
|
|
7980
7980
|
}
|
|
7981
|
-
var _this = _super.call(this,
|
|
7981
|
+
var _this = _super.call(this, context2.obj({}), encode) || this;
|
|
7982
7982
|
_this.objects = objects2;
|
|
7983
7983
|
_this.offsets = _this.computeObjectOffsets();
|
|
7984
7984
|
_this.offsetsString = _this.computeOffsetsString();
|
|
@@ -7990,14 +7990,14 @@ var init_PDFObjectStream = __esm(() => {
|
|
|
7990
7990
|
PDFObjectStream2.prototype.getObjectsCount = function() {
|
|
7991
7991
|
return this.objects.length;
|
|
7992
7992
|
};
|
|
7993
|
-
PDFObjectStream2.prototype.clone = function(
|
|
7994
|
-
return PDFObjectStream2.withContextAndObjects(
|
|
7993
|
+
PDFObjectStream2.prototype.clone = function(context2) {
|
|
7994
|
+
return PDFObjectStream2.withContextAndObjects(context2 || this.dict.context, this.objects.slice(), this.encode);
|
|
7995
7995
|
};
|
|
7996
7996
|
PDFObjectStream2.prototype.getContentsString = function() {
|
|
7997
7997
|
var value = this.offsetsString;
|
|
7998
7998
|
for (var idx3 = 0, len2 = this.objects.length;idx3 < len2; idx3++) {
|
|
7999
|
-
var _a = this.objects[idx3],
|
|
8000
|
-
value +=
|
|
7999
|
+
var _a = this.objects[idx3], object4 = _a[1];
|
|
8000
|
+
value += object4 + `
|
|
8001
8001
|
`;
|
|
8002
8002
|
}
|
|
8003
8003
|
return value;
|
|
@@ -8006,8 +8006,8 @@ var init_PDFObjectStream = __esm(() => {
|
|
|
8006
8006
|
var buffer = new Uint8Array(this.getUnencodedContentsSize());
|
|
8007
8007
|
var offset = copyStringIntoBuffer(this.offsetsString, buffer, 0);
|
|
8008
8008
|
for (var idx3 = 0, len2 = this.objects.length;idx3 < len2; idx3++) {
|
|
8009
|
-
var _a = this.objects[idx3],
|
|
8010
|
-
offset +=
|
|
8009
|
+
var _a = this.objects[idx3], object4 = _a[1];
|
|
8010
|
+
offset += object4.copyBytesInto(buffer, offset);
|
|
8011
8011
|
buffer[offset++] = CharCodes_default.Newline;
|
|
8012
8012
|
}
|
|
8013
8013
|
return buffer;
|
|
@@ -8027,17 +8027,17 @@ var init_PDFObjectStream = __esm(() => {
|
|
|
8027
8027
|
var offset = 0;
|
|
8028
8028
|
var offsets = new Array(this.objects.length);
|
|
8029
8029
|
for (var idx3 = 0, len2 = this.objects.length;idx3 < len2; idx3++) {
|
|
8030
|
-
var _a = this.objects[idx3], ref = _a[0],
|
|
8030
|
+
var _a = this.objects[idx3], ref = _a[0], object4 = _a[1];
|
|
8031
8031
|
offsets[idx3] = [ref.objectNumber, offset];
|
|
8032
|
-
offset +=
|
|
8032
|
+
offset += object4.sizeInBytes() + 1;
|
|
8033
8033
|
}
|
|
8034
8034
|
return offsets;
|
|
8035
8035
|
};
|
|
8036
|
-
PDFObjectStream2.withContextAndObjects = function(
|
|
8036
|
+
PDFObjectStream2.withContextAndObjects = function(context2, objects2, encode) {
|
|
8037
8037
|
if (encode === undefined) {
|
|
8038
8038
|
encode = true;
|
|
8039
8039
|
}
|
|
8040
|
-
return new PDFObjectStream2(
|
|
8040
|
+
return new PDFObjectStream2(context2, objects2, encode);
|
|
8041
8041
|
};
|
|
8042
8042
|
return PDFObjectStream2;
|
|
8043
8043
|
}(PDFFlateStream_default);
|
|
@@ -8056,19 +8056,19 @@ var init_PDFWriter = __esm(() => {
|
|
|
8056
8056
|
init_CharCodes();
|
|
8057
8057
|
init_utils2();
|
|
8058
8058
|
PDFWriter = function() {
|
|
8059
|
-
function PDFWriter2(
|
|
8059
|
+
function PDFWriter2(context2, objectsPerTick) {
|
|
8060
8060
|
var _this = this;
|
|
8061
8061
|
this.parsedObjects = 0;
|
|
8062
8062
|
this.shouldWaitForTick = function(n) {
|
|
8063
8063
|
_this.parsedObjects += n;
|
|
8064
8064
|
return _this.parsedObjects % _this.objectsPerTick === 0;
|
|
8065
8065
|
};
|
|
8066
|
-
this.context =
|
|
8066
|
+
this.context = context2;
|
|
8067
8067
|
this.objectsPerTick = objectsPerTick;
|
|
8068
8068
|
}
|
|
8069
8069
|
PDFWriter2.prototype.serializeToBuffer = function() {
|
|
8070
8070
|
return __awaiter(this, undefined, undefined, function() {
|
|
8071
|
-
var _a, size, header, indirectObjects, xref, trailerDict, trailer, offset, buffer, idx3, len2, _b, ref,
|
|
8071
|
+
var _a, size, header, indirectObjects, xref, trailerDict, trailer, offset, buffer, idx3, len2, _b, ref, object4, objectNumber, generationNumber, n;
|
|
8072
8072
|
return __generator(this, function(_c) {
|
|
8073
8073
|
switch (_c.label) {
|
|
8074
8074
|
case 0:
|
|
@@ -8085,7 +8085,7 @@ var init_PDFWriter = __esm(() => {
|
|
|
8085
8085
|
case 2:
|
|
8086
8086
|
if (!(idx3 < len2))
|
|
8087
8087
|
return [3, 5];
|
|
8088
|
-
_b = indirectObjects[idx3], ref = _b[0],
|
|
8088
|
+
_b = indirectObjects[idx3], ref = _b[0], object4 = _b[1];
|
|
8089
8089
|
objectNumber = String(ref.objectNumber);
|
|
8090
8090
|
offset += copyStringIntoBuffer(objectNumber, buffer, offset);
|
|
8091
8091
|
buffer[offset++] = CharCodes_default.Space;
|
|
@@ -8096,7 +8096,7 @@ var init_PDFWriter = __esm(() => {
|
|
|
8096
8096
|
buffer[offset++] = CharCodes_default.b;
|
|
8097
8097
|
buffer[offset++] = CharCodes_default.j;
|
|
8098
8098
|
buffer[offset++] = CharCodes_default.Newline;
|
|
8099
|
-
offset +=
|
|
8099
|
+
offset += object4.copyBytesInto(buffer, offset);
|
|
8100
8100
|
buffer[offset++] = CharCodes_default.Newline;
|
|
8101
8101
|
buffer[offset++] = CharCodes_default.e;
|
|
8102
8102
|
buffer[offset++] = CharCodes_default.n;
|
|
@@ -8106,7 +8106,7 @@ var init_PDFWriter = __esm(() => {
|
|
|
8106
8106
|
buffer[offset++] = CharCodes_default.j;
|
|
8107
8107
|
buffer[offset++] = CharCodes_default.Newline;
|
|
8108
8108
|
buffer[offset++] = CharCodes_default.Newline;
|
|
8109
|
-
n =
|
|
8109
|
+
n = object4 instanceof PDFObjectStream_default ? object4.getObjectsCount() : 1;
|
|
8110
8110
|
if (!this.shouldWaitForTick(n))
|
|
8111
8111
|
return [3, 4];
|
|
8112
8112
|
return [4, waitForTick()];
|
|
@@ -8133,9 +8133,9 @@ var init_PDFWriter = __esm(() => {
|
|
|
8133
8133
|
});
|
|
8134
8134
|
};
|
|
8135
8135
|
PDFWriter2.prototype.computeIndirectObjectSize = function(_a) {
|
|
8136
|
-
var ref = _a[0],
|
|
8136
|
+
var ref = _a[0], object4 = _a[1];
|
|
8137
8137
|
var refSize = ref.sizeInBytes() + 3;
|
|
8138
|
-
var objectSize =
|
|
8138
|
+
var objectSize = object4.sizeInBytes() + 9;
|
|
8139
8139
|
return refSize + objectSize;
|
|
8140
8140
|
};
|
|
8141
8141
|
PDFWriter2.prototype.createTrailerDict = function() {
|
|
@@ -8187,8 +8187,8 @@ var init_PDFWriter = __esm(() => {
|
|
|
8187
8187
|
});
|
|
8188
8188
|
});
|
|
8189
8189
|
};
|
|
8190
|
-
PDFWriter2.forContext = function(
|
|
8191
|
-
return new PDFWriter2(
|
|
8190
|
+
PDFWriter2.forContext = function(context2, objectsPerTick) {
|
|
8191
|
+
return new PDFWriter2(context2, objectsPerTick);
|
|
8192
8192
|
};
|
|
8193
8193
|
return PDFWriter2;
|
|
8194
8194
|
}();
|
|
@@ -8336,9 +8336,9 @@ var init_PDFCrossRefStream = __esm(() => {
|
|
|
8336
8336
|
this.indexCache.invalidate();
|
|
8337
8337
|
this.contentsCache.invalidate();
|
|
8338
8338
|
};
|
|
8339
|
-
PDFCrossRefStream2.prototype.clone = function(
|
|
8339
|
+
PDFCrossRefStream2.prototype.clone = function(context2) {
|
|
8340
8340
|
var _a = this, dict = _a.dict, entries = _a.entries, encode = _a.encode;
|
|
8341
|
-
return PDFCrossRefStream2.of(dict.clone(
|
|
8341
|
+
return PDFCrossRefStream2.of(dict.clone(context2), entries.slice(), encode);
|
|
8342
8342
|
};
|
|
8343
8343
|
PDFCrossRefStream2.prototype.getContentsString = function() {
|
|
8344
8344
|
var entryTuples = this.entryTuplesCache.access();
|
|
@@ -8392,9 +8392,9 @@ var init_PDFCrossRefStream = __esm(() => {
|
|
|
8392
8392
|
_super.prototype.updateDict.call(this);
|
|
8393
8393
|
var byteWidths = this.maxByteWidthsCache.access();
|
|
8394
8394
|
var index = this.indexCache.access();
|
|
8395
|
-
var
|
|
8396
|
-
this.dict.set(PDFName_default.of("W"),
|
|
8397
|
-
this.dict.set(PDFName_default.of("Index"),
|
|
8395
|
+
var context2 = this.dict.context;
|
|
8396
|
+
this.dict.set(PDFName_default.of("W"), context2.obj(byteWidths));
|
|
8397
|
+
this.dict.set(PDFName_default.of("Index"), context2.obj(index));
|
|
8398
8398
|
};
|
|
8399
8399
|
PDFCrossRefStream2.create = function(dict, encode) {
|
|
8400
8400
|
if (encode === undefined) {
|
|
@@ -8432,15 +8432,15 @@ var init_PDFStreamWriter = __esm(() => {
|
|
|
8432
8432
|
init_utils2();
|
|
8433
8433
|
PDFStreamWriter = function(_super) {
|
|
8434
8434
|
__extends(PDFStreamWriter2, _super);
|
|
8435
|
-
function PDFStreamWriter2(
|
|
8436
|
-
var _this = _super.call(this,
|
|
8435
|
+
function PDFStreamWriter2(context2, objectsPerTick, encodeStreams, objectsPerStream) {
|
|
8436
|
+
var _this = _super.call(this, context2, objectsPerTick) || this;
|
|
8437
8437
|
_this.encodeStreams = encodeStreams;
|
|
8438
8438
|
_this.objectsPerStream = objectsPerStream;
|
|
8439
8439
|
return _this;
|
|
8440
8440
|
}
|
|
8441
8441
|
PDFStreamWriter2.prototype.computeBufferSize = function() {
|
|
8442
8442
|
return __awaiter(this, undefined, undefined, function() {
|
|
8443
|
-
var objectNumber, header, size, xrefStream, uncompressedObjects, compressedObjects, objectStreamRefs, indirectObjects, idx3, len2, indirectObject, ref,
|
|
8443
|
+
var objectNumber, header, size, xrefStream, uncompressedObjects, compressedObjects, objectStreamRefs, indirectObjects, idx3, len2, indirectObject, ref, object4, shouldNotCompress, chunk, objectStreamRef, idx3, len2, chunk, ref, objectStream, xrefStreamRef, xrefOffset, trailer;
|
|
8444
8444
|
return __generator(this, function(_a) {
|
|
8445
8445
|
switch (_a.label) {
|
|
8446
8446
|
case 0:
|
|
@@ -8458,8 +8458,8 @@ var init_PDFStreamWriter = __esm(() => {
|
|
|
8458
8458
|
if (!(idx3 < len2))
|
|
8459
8459
|
return [3, 6];
|
|
8460
8460
|
indirectObject = indirectObjects[idx3];
|
|
8461
|
-
ref = indirectObject[0],
|
|
8462
|
-
shouldNotCompress = ref === this.context.trailerInfo.Encrypt ||
|
|
8461
|
+
ref = indirectObject[0], object4 = indirectObject[1];
|
|
8462
|
+
shouldNotCompress = ref === this.context.trailerInfo.Encrypt || object4 instanceof PDFStream_default || object4 instanceof PDFInvalidObject_default || ref.generationNumber !== 0;
|
|
8463
8463
|
if (!shouldNotCompress)
|
|
8464
8464
|
return [3, 4];
|
|
8465
8465
|
uncompressedObjects.push(indirectObject);
|
|
@@ -8523,14 +8523,14 @@ var init_PDFStreamWriter = __esm(() => {
|
|
|
8523
8523
|
});
|
|
8524
8524
|
});
|
|
8525
8525
|
};
|
|
8526
|
-
PDFStreamWriter2.forContext = function(
|
|
8526
|
+
PDFStreamWriter2.forContext = function(context2, objectsPerTick, encodeStreams, objectsPerStream) {
|
|
8527
8527
|
if (encodeStreams === undefined) {
|
|
8528
8528
|
encodeStreams = true;
|
|
8529
8529
|
}
|
|
8530
8530
|
if (objectsPerStream === undefined) {
|
|
8531
8531
|
objectsPerStream = 50;
|
|
8532
8532
|
}
|
|
8533
|
-
return new PDFStreamWriter2(
|
|
8533
|
+
return new PDFStreamWriter2(context2, objectsPerTick, encodeStreams, objectsPerStream);
|
|
8534
8534
|
};
|
|
8535
8535
|
return PDFStreamWriter2;
|
|
8536
8536
|
}(PDFWriter_default);
|
|
@@ -8665,18 +8665,18 @@ var init_StandardFontEmbedder = __esm(() => {
|
|
|
8665
8665
|
var yBottom = Descender || FontBBox[1];
|
|
8666
8666
|
return 1000 * height / (yTop - yBottom);
|
|
8667
8667
|
};
|
|
8668
|
-
StandardFontEmbedder2.prototype.embedIntoContext = function(
|
|
8669
|
-
var fontDict =
|
|
8668
|
+
StandardFontEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
8669
|
+
var fontDict = context2.obj({
|
|
8670
8670
|
Type: "Font",
|
|
8671
8671
|
Subtype: "Type1",
|
|
8672
8672
|
BaseFont: this.customName || this.fontName,
|
|
8673
8673
|
Encoding: this.encoding === Encodings.WinAnsi ? "WinAnsiEncoding" : undefined
|
|
8674
8674
|
});
|
|
8675
8675
|
if (ref) {
|
|
8676
|
-
|
|
8676
|
+
context2.assign(ref, fontDict);
|
|
8677
8677
|
return ref;
|
|
8678
8678
|
} else {
|
|
8679
|
-
return
|
|
8679
|
+
return context2.register(fontDict);
|
|
8680
8680
|
}
|
|
8681
8681
|
};
|
|
8682
8682
|
StandardFontEmbedder2.prototype.widthOfGlyph = function(glyphName) {
|
|
@@ -8991,21 +8991,21 @@ var init_CustomFontEmbedder = __esm(() => {
|
|
|
8991
8991
|
var yBottom = (descent || bbox.minY) * this.scale;
|
|
8992
8992
|
return 1000 * height / (yTop - yBottom);
|
|
8993
8993
|
};
|
|
8994
|
-
CustomFontEmbedder2.prototype.embedIntoContext = function(
|
|
8995
|
-
this.baseFontName = this.customName ||
|
|
8996
|
-
return this.embedFontDict(
|
|
8994
|
+
CustomFontEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
8995
|
+
this.baseFontName = this.customName || context2.addRandomSuffix(this.fontName);
|
|
8996
|
+
return this.embedFontDict(context2, ref);
|
|
8997
8997
|
};
|
|
8998
|
-
CustomFontEmbedder2.prototype.embedFontDict = function(
|
|
8998
|
+
CustomFontEmbedder2.prototype.embedFontDict = function(context2, ref) {
|
|
8999
8999
|
return __awaiter(this, undefined, undefined, function() {
|
|
9000
9000
|
var cidFontDictRef, unicodeCMapRef, fontDict;
|
|
9001
9001
|
return __generator(this, function(_a) {
|
|
9002
9002
|
switch (_a.label) {
|
|
9003
9003
|
case 0:
|
|
9004
|
-
return [4, this.embedCIDFontDict(
|
|
9004
|
+
return [4, this.embedCIDFontDict(context2)];
|
|
9005
9005
|
case 1:
|
|
9006
9006
|
cidFontDictRef = _a.sent();
|
|
9007
|
-
unicodeCMapRef = this.embedUnicodeCmap(
|
|
9008
|
-
fontDict =
|
|
9007
|
+
unicodeCMapRef = this.embedUnicodeCmap(context2);
|
|
9008
|
+
fontDict = context2.obj({
|
|
9009
9009
|
Type: "Font",
|
|
9010
9010
|
Subtype: "Type0",
|
|
9011
9011
|
BaseFont: this.baseFontName,
|
|
@@ -9014,10 +9014,10 @@ var init_CustomFontEmbedder = __esm(() => {
|
|
|
9014
9014
|
ToUnicode: unicodeCMapRef
|
|
9015
9015
|
});
|
|
9016
9016
|
if (ref) {
|
|
9017
|
-
|
|
9017
|
+
context2.assign(ref, fontDict);
|
|
9018
9018
|
return [2, ref];
|
|
9019
9019
|
} else {
|
|
9020
|
-
return [2,
|
|
9020
|
+
return [2, context2.register(fontDict)];
|
|
9021
9021
|
}
|
|
9022
9022
|
return [2];
|
|
9023
9023
|
}
|
|
@@ -9027,16 +9027,16 @@ var init_CustomFontEmbedder = __esm(() => {
|
|
|
9027
9027
|
CustomFontEmbedder2.prototype.isCFF = function() {
|
|
9028
9028
|
return this.font.cff;
|
|
9029
9029
|
};
|
|
9030
|
-
CustomFontEmbedder2.prototype.embedCIDFontDict = function(
|
|
9030
|
+
CustomFontEmbedder2.prototype.embedCIDFontDict = function(context2) {
|
|
9031
9031
|
return __awaiter(this, undefined, undefined, function() {
|
|
9032
9032
|
var fontDescriptorRef, cidFontDict;
|
|
9033
9033
|
return __generator(this, function(_a) {
|
|
9034
9034
|
switch (_a.label) {
|
|
9035
9035
|
case 0:
|
|
9036
|
-
return [4, this.embedFontDescriptor(
|
|
9036
|
+
return [4, this.embedFontDescriptor(context2)];
|
|
9037
9037
|
case 1:
|
|
9038
9038
|
fontDescriptorRef = _a.sent();
|
|
9039
|
-
cidFontDict =
|
|
9039
|
+
cidFontDict = context2.obj({
|
|
9040
9040
|
Type: "Font",
|
|
9041
9041
|
Subtype: this.isCFF() ? "CIDFontType0" : "CIDFontType2",
|
|
9042
9042
|
CIDToGIDMap: "Identity",
|
|
@@ -9049,25 +9049,25 @@ var init_CustomFontEmbedder = __esm(() => {
|
|
|
9049
9049
|
FontDescriptor: fontDescriptorRef,
|
|
9050
9050
|
W: this.computeWidths()
|
|
9051
9051
|
});
|
|
9052
|
-
return [2,
|
|
9052
|
+
return [2, context2.register(cidFontDict)];
|
|
9053
9053
|
}
|
|
9054
9054
|
});
|
|
9055
9055
|
});
|
|
9056
9056
|
};
|
|
9057
|
-
CustomFontEmbedder2.prototype.embedFontDescriptor = function(
|
|
9057
|
+
CustomFontEmbedder2.prototype.embedFontDescriptor = function(context2) {
|
|
9058
9058
|
return __awaiter(this, undefined, undefined, function() {
|
|
9059
9059
|
var fontStreamRef, scale, _a, italicAngle, ascent, descent, capHeight, xHeight, _b, minX, minY, maxX, maxY, fontDescriptor;
|
|
9060
9060
|
var _c;
|
|
9061
9061
|
return __generator(this, function(_d) {
|
|
9062
9062
|
switch (_d.label) {
|
|
9063
9063
|
case 0:
|
|
9064
|
-
return [4, this.embedFontStream(
|
|
9064
|
+
return [4, this.embedFontStream(context2)];
|
|
9065
9065
|
case 1:
|
|
9066
9066
|
fontStreamRef = _d.sent();
|
|
9067
9067
|
scale = this.scale;
|
|
9068
9068
|
_a = this.font, italicAngle = _a.italicAngle, ascent = _a.ascent, descent = _a.descent, capHeight = _a.capHeight, xHeight = _a.xHeight;
|
|
9069
9069
|
_b = this.font.bbox, minX = _b.minX, minY = _b.minY, maxX = _b.maxX, maxY = _b.maxY;
|
|
9070
|
-
fontDescriptor =
|
|
9070
|
+
fontDescriptor = context2.obj((_c = {
|
|
9071
9071
|
Type: "FontDescriptor",
|
|
9072
9072
|
FontName: this.baseFontName,
|
|
9073
9073
|
Flags: deriveFontFlags(this.font),
|
|
@@ -9079,7 +9079,7 @@ var init_CustomFontEmbedder = __esm(() => {
|
|
|
9079
9079
|
XHeight: (xHeight || 0) * scale,
|
|
9080
9080
|
StemV: 0
|
|
9081
9081
|
}, _c[this.isCFF() ? "FontFile3" : "FontFile2"] = fontStreamRef, _c));
|
|
9082
|
-
return [2,
|
|
9082
|
+
return [2, context2.register(fontDescriptor)];
|
|
9083
9083
|
}
|
|
9084
9084
|
});
|
|
9085
9085
|
});
|
|
@@ -9091,27 +9091,27 @@ var init_CustomFontEmbedder = __esm(() => {
|
|
|
9091
9091
|
});
|
|
9092
9092
|
});
|
|
9093
9093
|
};
|
|
9094
|
-
CustomFontEmbedder2.prototype.embedFontStream = function(
|
|
9094
|
+
CustomFontEmbedder2.prototype.embedFontStream = function(context2) {
|
|
9095
9095
|
return __awaiter(this, undefined, undefined, function() {
|
|
9096
9096
|
var fontStream, _a, _b;
|
|
9097
9097
|
return __generator(this, function(_c) {
|
|
9098
9098
|
switch (_c.label) {
|
|
9099
9099
|
case 0:
|
|
9100
|
-
_b = (_a =
|
|
9100
|
+
_b = (_a = context2).flateStream;
|
|
9101
9101
|
return [4, this.serializeFont()];
|
|
9102
9102
|
case 1:
|
|
9103
9103
|
fontStream = _b.apply(_a, [_c.sent(), {
|
|
9104
9104
|
Subtype: this.isCFF() ? "CIDFontType0C" : undefined
|
|
9105
9105
|
}]);
|
|
9106
|
-
return [2,
|
|
9106
|
+
return [2, context2.register(fontStream)];
|
|
9107
9107
|
}
|
|
9108
9108
|
});
|
|
9109
9109
|
});
|
|
9110
9110
|
};
|
|
9111
|
-
CustomFontEmbedder2.prototype.embedUnicodeCmap = function(
|
|
9111
|
+
CustomFontEmbedder2.prototype.embedUnicodeCmap = function(context2) {
|
|
9112
9112
|
var cmap = createCmap(this.glyphCache.access(), this.glyphId.bind(this));
|
|
9113
|
-
var cmapStream =
|
|
9114
|
-
return
|
|
9113
|
+
var cmapStream = context2.flateStream(cmap);
|
|
9114
|
+
return context2.register(cmapStream);
|
|
9115
9115
|
};
|
|
9116
9116
|
CustomFontEmbedder2.prototype.glyphId = function(glyph) {
|
|
9117
9117
|
return glyph ? glyph.id : -1;
|
|
@@ -9243,12 +9243,12 @@ var init_FileEmbedder = __esm(() => {
|
|
|
9243
9243
|
}
|
|
9244
9244
|
return new FileEmbedder2(bytes, fileName, options);
|
|
9245
9245
|
};
|
|
9246
|
-
FileEmbedder2.prototype.embedIntoContext = function(
|
|
9246
|
+
FileEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
9247
9247
|
return __awaiter(this, undefined, undefined, function() {
|
|
9248
9248
|
var _a, mimeType, description, creationDate, modificationDate, afRelationship, embeddedFileStream, embeddedFileStreamRef, fileSpecDict;
|
|
9249
9249
|
return __generator(this, function(_b) {
|
|
9250
9250
|
_a = this.options, mimeType = _a.mimeType, description = _a.description, creationDate = _a.creationDate, modificationDate = _a.modificationDate, afRelationship = _a.afRelationship;
|
|
9251
|
-
embeddedFileStream =
|
|
9251
|
+
embeddedFileStream = context2.flateStream(this.fileData, {
|
|
9252
9252
|
Type: "EmbeddedFile",
|
|
9253
9253
|
Subtype: mimeType !== null && mimeType !== undefined ? mimeType : undefined,
|
|
9254
9254
|
Params: {
|
|
@@ -9257,8 +9257,8 @@ var init_FileEmbedder = __esm(() => {
|
|
|
9257
9257
|
ModDate: modificationDate ? PDFString_default.fromDate(modificationDate) : undefined
|
|
9258
9258
|
}
|
|
9259
9259
|
});
|
|
9260
|
-
embeddedFileStreamRef =
|
|
9261
|
-
fileSpecDict =
|
|
9260
|
+
embeddedFileStreamRef = context2.register(embeddedFileStream);
|
|
9261
|
+
fileSpecDict = context2.obj({
|
|
9262
9262
|
Type: "Filespec",
|
|
9263
9263
|
F: PDFString_default.of(this.fileName),
|
|
9264
9264
|
UF: PDFHexString_default.fromText(this.fileName),
|
|
@@ -9267,10 +9267,10 @@ var init_FileEmbedder = __esm(() => {
|
|
|
9267
9267
|
AFRelationship: afRelationship !== null && afRelationship !== undefined ? afRelationship : undefined
|
|
9268
9268
|
});
|
|
9269
9269
|
if (ref) {
|
|
9270
|
-
|
|
9270
|
+
context2.assign(ref, fileSpecDict);
|
|
9271
9271
|
return [2, ref];
|
|
9272
9272
|
} else {
|
|
9273
|
-
return [2,
|
|
9273
|
+
return [2, context2.register(fileSpecDict)];
|
|
9274
9274
|
}
|
|
9275
9275
|
return [2];
|
|
9276
9276
|
});
|
|
@@ -9353,11 +9353,11 @@ var init_JpegEmbedder = __esm(() => {
|
|
|
9353
9353
|
});
|
|
9354
9354
|
});
|
|
9355
9355
|
};
|
|
9356
|
-
JpegEmbedder2.prototype.embedIntoContext = function(
|
|
9356
|
+
JpegEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
9357
9357
|
return __awaiter(this, undefined, undefined, function() {
|
|
9358
9358
|
var xObject;
|
|
9359
9359
|
return __generator(this, function(_a) {
|
|
9360
|
-
xObject =
|
|
9360
|
+
xObject = context2.stream(this.imageData, {
|
|
9361
9361
|
Type: "XObject",
|
|
9362
9362
|
Subtype: "Image",
|
|
9363
9363
|
BitsPerComponent: this.bitsPerComponent,
|
|
@@ -9368,10 +9368,10 @@ var init_JpegEmbedder = __esm(() => {
|
|
|
9368
9368
|
Decode: this.colorSpace === ColorSpace.DeviceCMYK ? [1, 0, 1, 0, 1, 0, 1, 0] : undefined
|
|
9369
9369
|
});
|
|
9370
9370
|
if (ref) {
|
|
9371
|
-
|
|
9371
|
+
context2.assign(ref, xObject);
|
|
9372
9372
|
return [2, ref];
|
|
9373
9373
|
} else {
|
|
9374
|
-
return [2,
|
|
9374
|
+
return [2, context2.register(xObject)];
|
|
9375
9375
|
}
|
|
9376
9376
|
return [2];
|
|
9377
9377
|
});
|
|
@@ -10996,12 +10996,12 @@ var init_PngEmbedder = __esm(() => {
|
|
|
10996
10996
|
});
|
|
10997
10997
|
});
|
|
10998
10998
|
};
|
|
10999
|
-
PngEmbedder2.prototype.embedIntoContext = function(
|
|
10999
|
+
PngEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
11000
11000
|
return __awaiter(this, undefined, undefined, function() {
|
|
11001
11001
|
var SMask, xObject;
|
|
11002
11002
|
return __generator(this, function(_a) {
|
|
11003
|
-
SMask = this.embedAlphaChannel(
|
|
11004
|
-
xObject =
|
|
11003
|
+
SMask = this.embedAlphaChannel(context2);
|
|
11004
|
+
xObject = context2.flateStream(this.image.rgbChannel, {
|
|
11005
11005
|
Type: "XObject",
|
|
11006
11006
|
Subtype: "Image",
|
|
11007
11007
|
BitsPerComponent: this.image.bitsPerComponent,
|
|
@@ -11011,19 +11011,19 @@ var init_PngEmbedder = __esm(() => {
|
|
|
11011
11011
|
SMask
|
|
11012
11012
|
});
|
|
11013
11013
|
if (ref) {
|
|
11014
|
-
|
|
11014
|
+
context2.assign(ref, xObject);
|
|
11015
11015
|
return [2, ref];
|
|
11016
11016
|
} else {
|
|
11017
|
-
return [2,
|
|
11017
|
+
return [2, context2.register(xObject)];
|
|
11018
11018
|
}
|
|
11019
11019
|
return [2];
|
|
11020
11020
|
});
|
|
11021
11021
|
});
|
|
11022
11022
|
};
|
|
11023
|
-
PngEmbedder2.prototype.embedAlphaChannel = function(
|
|
11023
|
+
PngEmbedder2.prototype.embedAlphaChannel = function(context2) {
|
|
11024
11024
|
if (!this.image.alphaChannel)
|
|
11025
11025
|
return;
|
|
11026
|
-
var xObject =
|
|
11026
|
+
var xObject = context2.flateStream(this.image.alphaChannel, {
|
|
11027
11027
|
Type: "XObject",
|
|
11028
11028
|
Subtype: "Image",
|
|
11029
11029
|
Height: this.image.height,
|
|
@@ -11032,7 +11032,7 @@ var init_PngEmbedder = __esm(() => {
|
|
|
11032
11032
|
ColorSpace: "DeviceGray",
|
|
11033
11033
|
Decode: [0, 1]
|
|
11034
11034
|
});
|
|
11035
|
-
return
|
|
11035
|
+
return context2.register(xObject);
|
|
11036
11036
|
};
|
|
11037
11037
|
return PngEmbedder2;
|
|
11038
11038
|
}();
|
|
@@ -12550,7 +12550,7 @@ var init_PDFPageEmbedder = __esm(() => {
|
|
|
12550
12550
|
});
|
|
12551
12551
|
});
|
|
12552
12552
|
};
|
|
12553
|
-
PDFPageEmbedder2.prototype.embedIntoContext = function(
|
|
12553
|
+
PDFPageEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
12554
12554
|
return __awaiter(this, undefined, undefined, function() {
|
|
12555
12555
|
var _a, Contents, Resources, decodedContents, _b, left, bottom, right, top, xObject;
|
|
12556
12556
|
return __generator(this, function(_c) {
|
|
@@ -12559,7 +12559,7 @@ var init_PDFPageEmbedder = __esm(() => {
|
|
|
12559
12559
|
throw new MissingPageContentsEmbeddingError;
|
|
12560
12560
|
decodedContents = this.decodeContents(Contents);
|
|
12561
12561
|
_b = this.boundingBox, left = _b.left, bottom = _b.bottom, right = _b.right, top = _b.top;
|
|
12562
|
-
xObject =
|
|
12562
|
+
xObject = context2.flateStream(decodedContents, {
|
|
12563
12563
|
Type: "XObject",
|
|
12564
12564
|
Subtype: "Form",
|
|
12565
12565
|
FormType: 1,
|
|
@@ -12568,10 +12568,10 @@ var init_PDFPageEmbedder = __esm(() => {
|
|
|
12568
12568
|
Resources
|
|
12569
12569
|
});
|
|
12570
12570
|
if (ref) {
|
|
12571
|
-
|
|
12571
|
+
context2.assign(ref, xObject);
|
|
12572
12572
|
return [2, ref];
|
|
12573
12573
|
} else {
|
|
12574
|
-
return [2,
|
|
12574
|
+
return [2, context2.register(xObject)];
|
|
12575
12575
|
}
|
|
12576
12576
|
return [2];
|
|
12577
12577
|
});
|
|
@@ -12824,8 +12824,8 @@ var init_ViewerPreferences = __esm(() => {
|
|
|
12824
12824
|
ViewerPreferences2.fromDict = function(dict) {
|
|
12825
12825
|
return new ViewerPreferences2(dict);
|
|
12826
12826
|
};
|
|
12827
|
-
ViewerPreferences2.create = function(
|
|
12828
|
-
var dict =
|
|
12827
|
+
ViewerPreferences2.create = function(context2) {
|
|
12828
|
+
var dict = context2.obj({});
|
|
12829
12829
|
return new ViewerPreferences2(dict);
|
|
12830
12830
|
};
|
|
12831
12831
|
return ViewerPreferences2;
|
|
@@ -13334,9 +13334,9 @@ var init_PDFWidgetAnnotation = __esm(() => {
|
|
|
13334
13334
|
var _a;
|
|
13335
13335
|
var normal = (_a = this.getAppearances()) === null || _a === undefined ? undefined : _a.normal;
|
|
13336
13336
|
if (normal instanceof PDFDict_default) {
|
|
13337
|
-
var
|
|
13338
|
-
for (var idx3 = 0, len2 =
|
|
13339
|
-
var key =
|
|
13337
|
+
var keys4 = normal.keys();
|
|
13338
|
+
for (var idx3 = 0, len2 = keys4.length;idx3 < len2; idx3++) {
|
|
13339
|
+
var key = keys4[idx3];
|
|
13340
13340
|
if (key !== PDFName_default.of("Off"))
|
|
13341
13341
|
return key;
|
|
13342
13342
|
}
|
|
@@ -13346,8 +13346,8 @@ var init_PDFWidgetAnnotation = __esm(() => {
|
|
|
13346
13346
|
PDFWidgetAnnotation2.fromDict = function(dict) {
|
|
13347
13347
|
return new PDFWidgetAnnotation2(dict);
|
|
13348
13348
|
};
|
|
13349
|
-
PDFWidgetAnnotation2.create = function(
|
|
13350
|
-
var dict =
|
|
13349
|
+
PDFWidgetAnnotation2.create = function(context2, parent) {
|
|
13350
|
+
var dict = context2.obj({
|
|
13351
13351
|
Type: "Annot",
|
|
13352
13352
|
Subtype: "Widget",
|
|
13353
13353
|
Rect: [0, 0, 0, 0],
|
|
@@ -13553,12 +13553,12 @@ var init_PDFAcroCheckBox = __esm(() => {
|
|
|
13553
13553
|
PDFAcroCheckBox2.fromDict = function(dict, ref) {
|
|
13554
13554
|
return new PDFAcroCheckBox2(dict, ref);
|
|
13555
13555
|
};
|
|
13556
|
-
PDFAcroCheckBox2.create = function(
|
|
13557
|
-
var dict =
|
|
13556
|
+
PDFAcroCheckBox2.create = function(context2) {
|
|
13557
|
+
var dict = context2.obj({
|
|
13558
13558
|
FT: "Btn",
|
|
13559
13559
|
Kids: []
|
|
13560
13560
|
});
|
|
13561
|
-
var ref =
|
|
13561
|
+
var ref = context2.register(dict);
|
|
13562
13562
|
return new PDFAcroCheckBox2(dict, ref);
|
|
13563
13563
|
};
|
|
13564
13564
|
return PDFAcroCheckBox2;
|
|
@@ -13740,13 +13740,13 @@ var init_PDFAcroComboBox = __esm(() => {
|
|
|
13740
13740
|
PDFAcroComboBox2.fromDict = function(dict, ref) {
|
|
13741
13741
|
return new PDFAcroComboBox2(dict, ref);
|
|
13742
13742
|
};
|
|
13743
|
-
PDFAcroComboBox2.create = function(
|
|
13744
|
-
var dict =
|
|
13743
|
+
PDFAcroComboBox2.create = function(context2) {
|
|
13744
|
+
var dict = context2.obj({
|
|
13745
13745
|
FT: "Ch",
|
|
13746
13746
|
Ff: AcroChoiceFlags.Combo,
|
|
13747
13747
|
Kids: []
|
|
13748
13748
|
});
|
|
13749
|
-
var ref =
|
|
13749
|
+
var ref = context2.register(dict);
|
|
13750
13750
|
return new PDFAcroComboBox2(dict, ref);
|
|
13751
13751
|
};
|
|
13752
13752
|
return PDFAcroComboBox2;
|
|
@@ -13780,9 +13780,9 @@ var init_PDFAcroNonTerminal = __esm(() => {
|
|
|
13780
13780
|
PDFAcroNonTerminal2.fromDict = function(dict, ref) {
|
|
13781
13781
|
return new PDFAcroNonTerminal2(dict, ref);
|
|
13782
13782
|
};
|
|
13783
|
-
PDFAcroNonTerminal2.create = function(
|
|
13784
|
-
var dict =
|
|
13785
|
-
var ref =
|
|
13783
|
+
PDFAcroNonTerminal2.create = function(context2) {
|
|
13784
|
+
var dict = context2.obj({});
|
|
13785
|
+
var ref = context2.register(dict);
|
|
13786
13786
|
return new PDFAcroNonTerminal2(dict, ref);
|
|
13787
13787
|
};
|
|
13788
13788
|
return PDFAcroNonTerminal2;
|
|
@@ -13866,12 +13866,12 @@ var init_PDFAcroText = __esm(() => {
|
|
|
13866
13866
|
PDFAcroText2.fromDict = function(dict, ref) {
|
|
13867
13867
|
return new PDFAcroText2(dict, ref);
|
|
13868
13868
|
};
|
|
13869
|
-
PDFAcroText2.create = function(
|
|
13870
|
-
var dict =
|
|
13869
|
+
PDFAcroText2.create = function(context2) {
|
|
13870
|
+
var dict = context2.obj({
|
|
13871
13871
|
FT: "Tx",
|
|
13872
13872
|
Kids: []
|
|
13873
13873
|
});
|
|
13874
|
-
var ref =
|
|
13874
|
+
var ref = context2.register(dict);
|
|
13875
13875
|
return new PDFAcroText2(dict, ref);
|
|
13876
13876
|
};
|
|
13877
13877
|
return PDFAcroText2;
|
|
@@ -13893,13 +13893,13 @@ var init_PDFAcroPushButton = __esm(() => {
|
|
|
13893
13893
|
PDFAcroPushButton2.fromDict = function(dict, ref) {
|
|
13894
13894
|
return new PDFAcroPushButton2(dict, ref);
|
|
13895
13895
|
};
|
|
13896
|
-
PDFAcroPushButton2.create = function(
|
|
13897
|
-
var dict =
|
|
13896
|
+
PDFAcroPushButton2.create = function(context2) {
|
|
13897
|
+
var dict = context2.obj({
|
|
13898
13898
|
FT: "Btn",
|
|
13899
13899
|
Ff: AcroButtonFlags.PushButton,
|
|
13900
13900
|
Kids: []
|
|
13901
13901
|
});
|
|
13902
|
-
var ref =
|
|
13902
|
+
var ref = context2.register(dict);
|
|
13903
13903
|
return new PDFAcroPushButton2(dict, ref);
|
|
13904
13904
|
};
|
|
13905
13905
|
return PDFAcroPushButton2;
|
|
@@ -13952,13 +13952,13 @@ var init_PDFAcroRadioButton = __esm(() => {
|
|
|
13952
13952
|
PDFAcroRadioButton2.fromDict = function(dict, ref) {
|
|
13953
13953
|
return new PDFAcroRadioButton2(dict, ref);
|
|
13954
13954
|
};
|
|
13955
|
-
PDFAcroRadioButton2.create = function(
|
|
13956
|
-
var dict =
|
|
13955
|
+
PDFAcroRadioButton2.create = function(context2) {
|
|
13956
|
+
var dict = context2.obj({
|
|
13957
13957
|
FT: "Btn",
|
|
13958
13958
|
Ff: AcroButtonFlags.Radio,
|
|
13959
13959
|
Kids: []
|
|
13960
13960
|
});
|
|
13961
|
-
var ref =
|
|
13961
|
+
var ref = context2.register(dict);
|
|
13962
13962
|
return new PDFAcroRadioButton2(dict, ref);
|
|
13963
13963
|
};
|
|
13964
13964
|
return PDFAcroRadioButton2;
|
|
@@ -13979,12 +13979,12 @@ var init_PDFAcroListBox = __esm(() => {
|
|
|
13979
13979
|
PDFAcroListBox2.fromDict = function(dict, ref) {
|
|
13980
13980
|
return new PDFAcroListBox2(dict, ref);
|
|
13981
13981
|
};
|
|
13982
|
-
PDFAcroListBox2.create = function(
|
|
13983
|
-
var dict =
|
|
13982
|
+
PDFAcroListBox2.create = function(context2) {
|
|
13983
|
+
var dict = context2.obj({
|
|
13984
13984
|
FT: "Ch",
|
|
13985
13985
|
Kids: []
|
|
13986
13986
|
});
|
|
13987
|
-
var ref =
|
|
13987
|
+
var ref = context2.register(dict);
|
|
13988
13988
|
return new PDFAcroListBox2(dict, ref);
|
|
13989
13989
|
};
|
|
13990
13990
|
return PDFAcroListBox2;
|
|
@@ -14101,28 +14101,28 @@ var init_PDFAcroForm = __esm(() => {
|
|
|
14101
14101
|
this.dict = dict;
|
|
14102
14102
|
}
|
|
14103
14103
|
PDFAcroForm2.prototype.Fields = function() {
|
|
14104
|
-
var
|
|
14105
|
-
if (
|
|
14106
|
-
return
|
|
14104
|
+
var fields4 = this.dict.lookup(PDFName_default.of("Fields"));
|
|
14105
|
+
if (fields4 instanceof PDFArray_default)
|
|
14106
|
+
return fields4;
|
|
14107
14107
|
return;
|
|
14108
14108
|
};
|
|
14109
14109
|
PDFAcroForm2.prototype.getFields = function() {
|
|
14110
14110
|
var Fields = this.normalizedEntries().Fields;
|
|
14111
|
-
var
|
|
14111
|
+
var fields4 = new Array(Fields.size());
|
|
14112
14112
|
for (var idx3 = 0, len2 = Fields.size();idx3 < len2; idx3++) {
|
|
14113
14113
|
var ref = Fields.get(idx3);
|
|
14114
14114
|
var dict = Fields.lookup(idx3, PDFDict_default);
|
|
14115
|
-
|
|
14115
|
+
fields4[idx3] = [createPDFAcroField(dict, ref), ref];
|
|
14116
14116
|
}
|
|
14117
|
-
return
|
|
14117
|
+
return fields4;
|
|
14118
14118
|
};
|
|
14119
14119
|
PDFAcroForm2.prototype.getAllFields = function() {
|
|
14120
14120
|
var allFields = [];
|
|
14121
|
-
var pushFields = function(
|
|
14122
|
-
if (!
|
|
14121
|
+
var pushFields = function(fields4) {
|
|
14122
|
+
if (!fields4)
|
|
14123
14123
|
return;
|
|
14124
|
-
for (var idx3 = 0, len2 =
|
|
14125
|
-
var field =
|
|
14124
|
+
for (var idx3 = 0, len2 = fields4.length;idx3 < len2; idx3++) {
|
|
14125
|
+
var field = fields4[idx3];
|
|
14126
14126
|
allFields.push(field);
|
|
14127
14127
|
var fieldModel = field[0];
|
|
14128
14128
|
if (fieldModel instanceof PDFAcroNonTerminal_default) {
|
|
@@ -14139,13 +14139,13 @@ var init_PDFAcroForm = __esm(() => {
|
|
|
14139
14139
|
};
|
|
14140
14140
|
PDFAcroForm2.prototype.removeField = function(field) {
|
|
14141
14141
|
var parent = field.getParent();
|
|
14142
|
-
var
|
|
14143
|
-
var index =
|
|
14144
|
-
if (
|
|
14142
|
+
var fields4 = parent === undefined ? this.normalizedEntries().Fields : parent.Kids();
|
|
14143
|
+
var index = fields4 === null || fields4 === undefined ? undefined : fields4.indexOf(field.ref);
|
|
14144
|
+
if (fields4 === undefined || index === undefined) {
|
|
14145
14145
|
throw new Error("Tried to remove inexistent field " + field.getFullyQualifiedName());
|
|
14146
14146
|
}
|
|
14147
|
-
|
|
14148
|
-
if (parent !== undefined &&
|
|
14147
|
+
fields4.remove(index);
|
|
14148
|
+
if (parent !== undefined && fields4.size() === 0) {
|
|
14149
14149
|
this.removeField(parent);
|
|
14150
14150
|
}
|
|
14151
14151
|
};
|
|
@@ -14160,8 +14160,8 @@ var init_PDFAcroForm = __esm(() => {
|
|
|
14160
14160
|
PDFAcroForm2.fromDict = function(dict) {
|
|
14161
14161
|
return new PDFAcroForm2(dict);
|
|
14162
14162
|
};
|
|
14163
|
-
PDFAcroForm2.create = function(
|
|
14164
|
-
var dict =
|
|
14163
|
+
PDFAcroForm2.create = function(context2) {
|
|
14164
|
+
var dict = context2.obj({ Fields: [] });
|
|
14165
14165
|
return new PDFAcroForm2(dict);
|
|
14166
14166
|
};
|
|
14167
14167
|
return PDFAcroForm2;
|
|
@@ -14248,14 +14248,14 @@ var init_PDFCatalog = __esm(() => {
|
|
|
14248
14248
|
PDFCatalog2.prototype.removeLeafNode = function(index) {
|
|
14249
14249
|
this.Pages().removeLeafNode(index);
|
|
14250
14250
|
};
|
|
14251
|
-
PDFCatalog2.withContextAndPages = function(
|
|
14251
|
+
PDFCatalog2.withContextAndPages = function(context2, pages) {
|
|
14252
14252
|
var dict = new Map;
|
|
14253
14253
|
dict.set(PDFName_default.of("Type"), PDFName_default.of("Catalog"));
|
|
14254
14254
|
dict.set(PDFName_default.of("Pages"), pages);
|
|
14255
|
-
return new PDFCatalog2(dict,
|
|
14255
|
+
return new PDFCatalog2(dict, context2);
|
|
14256
14256
|
};
|
|
14257
|
-
PDFCatalog2.fromMapWithContext = function(map,
|
|
14258
|
-
return new PDFCatalog2(map,
|
|
14257
|
+
PDFCatalog2.fromMapWithContext = function(map, context2) {
|
|
14258
|
+
return new PDFCatalog2(map, context2);
|
|
14259
14259
|
};
|
|
14260
14260
|
return PDFCatalog2;
|
|
14261
14261
|
}(PDFDict_default);
|
|
@@ -14394,17 +14394,17 @@ var init_PDFPageTree = __esm(() => {
|
|
|
14394
14394
|
}
|
|
14395
14395
|
Kids.remove(kidIdx);
|
|
14396
14396
|
};
|
|
14397
|
-
PDFPageTree2.withContext = function(
|
|
14397
|
+
PDFPageTree2.withContext = function(context2, parent) {
|
|
14398
14398
|
var dict = new Map;
|
|
14399
14399
|
dict.set(PDFName_default.of("Type"), PDFName_default.of("Pages"));
|
|
14400
|
-
dict.set(PDFName_default.of("Kids"),
|
|
14401
|
-
dict.set(PDFName_default.of("Count"),
|
|
14400
|
+
dict.set(PDFName_default.of("Kids"), context2.obj([]));
|
|
14401
|
+
dict.set(PDFName_default.of("Count"), context2.obj(0));
|
|
14402
14402
|
if (parent)
|
|
14403
14403
|
dict.set(PDFName_default.of("Parent"), parent);
|
|
14404
|
-
return new PDFPageTree2(dict,
|
|
14404
|
+
return new PDFPageTree2(dict, context2);
|
|
14405
14405
|
};
|
|
14406
|
-
PDFPageTree2.fromMapWithContext = function(map,
|
|
14407
|
-
return new PDFPageTree2(map,
|
|
14406
|
+
PDFPageTree2.fromMapWithContext = function(map, context2) {
|
|
14407
|
+
return new PDFPageTree2(map, context2);
|
|
14408
14408
|
};
|
|
14409
14409
|
return PDFPageTree2;
|
|
14410
14410
|
}(PDFDict_default);
|
|
@@ -14724,12 +14724,12 @@ var init_PDFObjectParser = __esm(() => {
|
|
|
14724
14724
|
init_utils2();
|
|
14725
14725
|
PDFObjectParser = function(_super) {
|
|
14726
14726
|
__extends(PDFObjectParser2, _super);
|
|
14727
|
-
function PDFObjectParser2(byteStream,
|
|
14727
|
+
function PDFObjectParser2(byteStream, context2, capNumbers) {
|
|
14728
14728
|
if (capNumbers === undefined) {
|
|
14729
14729
|
capNumbers = false;
|
|
14730
14730
|
}
|
|
14731
14731
|
var _this = _super.call(this, byteStream, capNumbers) || this;
|
|
14732
|
-
_this.context =
|
|
14732
|
+
_this.context = context2;
|
|
14733
14733
|
return _this;
|
|
14734
14734
|
}
|
|
14735
14735
|
PDFObjectParser2.prototype.parseObject = function() {
|
|
@@ -14896,14 +14896,14 @@ var init_PDFObjectParser = __esm(() => {
|
|
|
14896
14896
|
throw new PDFStreamParsingError(startPos);
|
|
14897
14897
|
return end;
|
|
14898
14898
|
};
|
|
14899
|
-
PDFObjectParser2.forBytes = function(bytes,
|
|
14900
|
-
return new PDFObjectParser2(ByteStream_default.of(bytes),
|
|
14899
|
+
PDFObjectParser2.forBytes = function(bytes, context2, capNumbers) {
|
|
14900
|
+
return new PDFObjectParser2(ByteStream_default.of(bytes), context2, capNumbers);
|
|
14901
14901
|
};
|
|
14902
|
-
PDFObjectParser2.forByteStream = function(byteStream,
|
|
14902
|
+
PDFObjectParser2.forByteStream = function(byteStream, context2, capNumbers) {
|
|
14903
14903
|
if (capNumbers === undefined) {
|
|
14904
14904
|
capNumbers = false;
|
|
14905
14905
|
}
|
|
14906
|
-
return new PDFObjectParser2(byteStream,
|
|
14906
|
+
return new PDFObjectParser2(byteStream, context2, capNumbers);
|
|
14907
14907
|
};
|
|
14908
14908
|
return PDFObjectParser2;
|
|
14909
14909
|
}(BaseParser_default);
|
|
@@ -14936,7 +14936,7 @@ var init_PDFObjectStreamParser = __esm(() => {
|
|
|
14936
14936
|
}
|
|
14937
14937
|
PDFObjectStreamParser2.prototype.parseIntoContext = function() {
|
|
14938
14938
|
return __awaiter(this, undefined, undefined, function() {
|
|
14939
|
-
var offsetsAndObjectNumbers, idx4, len3, _a, objectNumber, offset,
|
|
14939
|
+
var offsetsAndObjectNumbers, idx4, len3, _a, objectNumber, offset, object4, ref;
|
|
14940
14940
|
return __generator(this, function(_b) {
|
|
14941
14941
|
switch (_b.label) {
|
|
14942
14942
|
case 0:
|
|
@@ -14952,9 +14952,9 @@ var init_PDFObjectStreamParser = __esm(() => {
|
|
|
14952
14952
|
return [3, 4];
|
|
14953
14953
|
_a = offsetsAndObjectNumbers[idx4], objectNumber = _a.objectNumber, offset = _a.offset;
|
|
14954
14954
|
this.bytes.moveTo(this.firstOffset + offset);
|
|
14955
|
-
|
|
14955
|
+
object4 = this.parseObject();
|
|
14956
14956
|
ref = PDFRef_default.of(objectNumber, 0);
|
|
14957
|
-
this.context.assign(ref,
|
|
14957
|
+
this.context.assign(ref, object4);
|
|
14958
14958
|
if (!this.shouldWaitForTick())
|
|
14959
14959
|
return [3, 3];
|
|
14960
14960
|
return [4, waitForTick()];
|
|
@@ -15164,8 +15164,8 @@ var init_PDFParser = __esm(() => {
|
|
|
15164
15164
|
if (!isValidCatalog(catalog)) {
|
|
15165
15165
|
var indirectObjects = this.context.enumerateIndirectObjects();
|
|
15166
15166
|
for (var idx4 = 0, len3 = indirectObjects.length;idx4 < len3; idx4++) {
|
|
15167
|
-
var _a = indirectObjects[idx4], ref = _a[0],
|
|
15168
|
-
if (isValidCatalog(
|
|
15167
|
+
var _a = indirectObjects[idx4], ref = _a[0], object4 = _a[1];
|
|
15168
|
+
if (isValidCatalog(object4)) {
|
|
15169
15169
|
this.context.trailerInfo.Root = ref;
|
|
15170
15170
|
}
|
|
15171
15171
|
}
|
|
@@ -15208,26 +15208,26 @@ var init_PDFParser = __esm(() => {
|
|
|
15208
15208
|
};
|
|
15209
15209
|
PDFParser2.prototype.parseIndirectObject = function() {
|
|
15210
15210
|
return __awaiter(this, undefined, undefined, function() {
|
|
15211
|
-
var ref,
|
|
15211
|
+
var ref, object4;
|
|
15212
15212
|
return __generator(this, function(_a) {
|
|
15213
15213
|
switch (_a.label) {
|
|
15214
15214
|
case 0:
|
|
15215
15215
|
ref = this.parseIndirectObjectHeader();
|
|
15216
15216
|
this.skipWhitespaceAndComments();
|
|
15217
|
-
|
|
15217
|
+
object4 = this.parseObject();
|
|
15218
15218
|
this.skipWhitespaceAndComments();
|
|
15219
15219
|
this.matchKeyword(Keywords.endobj);
|
|
15220
|
-
if (!(
|
|
15220
|
+
if (!(object4 instanceof PDFRawStream_default && object4.dict.lookup(PDFName_default.of("Type")) === PDFName_default.of("ObjStm")))
|
|
15221
15221
|
return [3, 2];
|
|
15222
|
-
return [4, PDFObjectStreamParser_default.forStream(
|
|
15222
|
+
return [4, PDFObjectStreamParser_default.forStream(object4, this.shouldWaitForTick).parseIntoContext()];
|
|
15223
15223
|
case 1:
|
|
15224
15224
|
_a.sent();
|
|
15225
15225
|
return [3, 3];
|
|
15226
15226
|
case 2:
|
|
15227
|
-
if (
|
|
15228
|
-
PDFXRefStreamParser_default.forStream(
|
|
15227
|
+
if (object4 instanceof PDFRawStream_default && object4.dict.lookup(PDFName_default.of("Type")) === PDFName_default.of("XRef")) {
|
|
15228
|
+
PDFXRefStreamParser_default.forStream(object4).parseIntoContext();
|
|
15229
15229
|
} else {
|
|
15230
|
-
this.context.assign(ref,
|
|
15230
|
+
this.context.assign(ref, object4);
|
|
15231
15231
|
}
|
|
15232
15232
|
_a.label = 3;
|
|
15233
15233
|
case 3:
|
|
@@ -15258,8 +15258,8 @@ var init_PDFParser = __esm(() => {
|
|
|
15258
15258
|
if (failed)
|
|
15259
15259
|
throw new PDFInvalidObjectParsingError(startPos);
|
|
15260
15260
|
var end = this.bytes.offset() - Keywords.endobj.length;
|
|
15261
|
-
var
|
|
15262
|
-
this.context.assign(ref,
|
|
15261
|
+
var object4 = PDFInvalidObject_default.of(this.bytes.slice(start, end));
|
|
15262
|
+
this.context.assign(ref, object4);
|
|
15263
15263
|
return ref;
|
|
15264
15264
|
};
|
|
15265
15265
|
PDFParser2.prototype.parseIndirectObjects = function() {
|
|
@@ -15337,12 +15337,12 @@ var init_PDFParser = __esm(() => {
|
|
|
15337
15337
|
return;
|
|
15338
15338
|
this.skipWhitespaceAndComments();
|
|
15339
15339
|
var dict = this.parseDict();
|
|
15340
|
-
var
|
|
15341
|
-
|
|
15342
|
-
Root: dict.get(PDFName_default.of("Root")) ||
|
|
15343
|
-
Encrypt: dict.get(PDFName_default.of("Encrypt")) ||
|
|
15344
|
-
Info: dict.get(PDFName_default.of("Info")) ||
|
|
15345
|
-
ID: dict.get(PDFName_default.of("ID")) ||
|
|
15340
|
+
var context2 = this.context;
|
|
15341
|
+
context2.trailerInfo = {
|
|
15342
|
+
Root: dict.get(PDFName_default.of("Root")) || context2.trailerInfo.Root,
|
|
15343
|
+
Encrypt: dict.get(PDFName_default.of("Encrypt")) || context2.trailerInfo.Encrypt,
|
|
15344
|
+
Info: dict.get(PDFName_default.of("Info")) || context2.trailerInfo.Info,
|
|
15345
|
+
ID: dict.get(PDFName_default.of("ID")) || context2.trailerInfo.ID
|
|
15346
15346
|
};
|
|
15347
15347
|
};
|
|
15348
15348
|
PDFParser2.prototype.maybeParseTrailer = function() {
|
|
@@ -17666,21 +17666,21 @@ var init_PDFField = __esm(() => {
|
|
|
17666
17666
|
};
|
|
17667
17667
|
PDFField2.prototype.createAppearanceStream = function(widget, appearance, font) {
|
|
17668
17668
|
var _a;
|
|
17669
|
-
var
|
|
17669
|
+
var context2 = this.acroField.dict.context;
|
|
17670
17670
|
var _b = widget.getRectangle(), width = _b.width, height = _b.height;
|
|
17671
17671
|
var Resources = font && { Font: (_a = {}, _a[font.name] = font.ref, _a) };
|
|
17672
|
-
var stream2 =
|
|
17672
|
+
var stream2 = context2.formXObject(appearance, {
|
|
17673
17673
|
Resources,
|
|
17674
|
-
BBox:
|
|
17675
|
-
Matrix:
|
|
17674
|
+
BBox: context2.obj([0, 0, width, height]),
|
|
17675
|
+
Matrix: context2.obj([1, 0, 0, 1, 0, 0])
|
|
17676
17676
|
});
|
|
17677
|
-
var streamRef =
|
|
17677
|
+
var streamRef = context2.register(stream2);
|
|
17678
17678
|
return streamRef;
|
|
17679
17679
|
};
|
|
17680
17680
|
PDFField2.prototype.createImageAppearanceStream = function(widget, image, alignment2) {
|
|
17681
17681
|
var _a;
|
|
17682
17682
|
var _b;
|
|
17683
|
-
var
|
|
17683
|
+
var context2 = this.acroField.dict.context;
|
|
17684
17684
|
var rectangle2 = widget.getRectangle();
|
|
17685
17685
|
var ap = widget.getAppearanceCharacteristics();
|
|
17686
17686
|
var bs = widget.getBorderStyle();
|
|
@@ -17708,18 +17708,18 @@ var init_PDFField = __esm(() => {
|
|
|
17708
17708
|
var imageName = this.doc.context.addRandomSuffix("Image", 10);
|
|
17709
17709
|
var appearance = __spreadArrays(rotate, drawImage(imageName, options));
|
|
17710
17710
|
var Resources = { XObject: (_a = {}, _a[imageName] = image.ref, _a) };
|
|
17711
|
-
var stream2 =
|
|
17711
|
+
var stream2 = context2.formXObject(appearance, {
|
|
17712
17712
|
Resources,
|
|
17713
|
-
BBox:
|
|
17714
|
-
Matrix:
|
|
17713
|
+
BBox: context2.obj([0, 0, rectangle2.width, rectangle2.height]),
|
|
17714
|
+
Matrix: context2.obj([1, 0, 0, 1, 0, 0])
|
|
17715
17715
|
});
|
|
17716
|
-
return
|
|
17716
|
+
return context2.register(stream2);
|
|
17717
17717
|
};
|
|
17718
17718
|
PDFField2.prototype.createAppearanceDict = function(widget, appearance, onValue) {
|
|
17719
|
-
var
|
|
17719
|
+
var context2 = this.acroField.dict.context;
|
|
17720
17720
|
var onStreamRef = this.createAppearanceStream(widget, appearance.on);
|
|
17721
17721
|
var offStreamRef = this.createAppearanceStream(widget, appearance.off);
|
|
17722
|
-
var appearanceDict =
|
|
17722
|
+
var appearanceDict = context2.obj({});
|
|
17723
17723
|
appearanceDict.set(onValue, onStreamRef);
|
|
17724
17724
|
appearanceDict.set(PDFName_default.of("Off"), offStreamRef);
|
|
17725
17725
|
return appearanceDict;
|
|
@@ -18725,9 +18725,9 @@ var PDFForm, PDFForm_default, convertToPDFField = function(field, ref, doc) {
|
|
|
18725
18725
|
var parent = _a[0], parentRef = _a[1];
|
|
18726
18726
|
var field = _b[0], fieldRef = _b[1];
|
|
18727
18727
|
var entries = parent.normalizedEntries();
|
|
18728
|
-
var
|
|
18729
|
-
for (var idx4 = 0, len3 =
|
|
18730
|
-
if (
|
|
18728
|
+
var fields4 = createPDFAcroFields("Kids" in entries ? entries.Kids : entries.Fields);
|
|
18729
|
+
for (var idx4 = 0, len3 = fields4.length;idx4 < len3; idx4++) {
|
|
18730
|
+
if (fields4[idx4][0].getPartialName() === partialName) {
|
|
18731
18731
|
throw new FieldAlreadyExistsError(partialName);
|
|
18732
18732
|
}
|
|
18733
18733
|
}
|
|
@@ -18772,20 +18772,20 @@ var init_PDFForm = __esm(() => {
|
|
|
18772
18772
|
};
|
|
18773
18773
|
PDFForm2.prototype.getFields = function() {
|
|
18774
18774
|
var allFields = this.acroForm.getAllFields();
|
|
18775
|
-
var
|
|
18775
|
+
var fields4 = [];
|
|
18776
18776
|
for (var idx4 = 0, len3 = allFields.length;idx4 < len3; idx4++) {
|
|
18777
18777
|
var _a = allFields[idx4], acroField = _a[0], ref = _a[1];
|
|
18778
18778
|
var field = convertToPDFField(acroField, ref, this.doc);
|
|
18779
18779
|
if (field)
|
|
18780
|
-
|
|
18780
|
+
fields4.push(field);
|
|
18781
18781
|
}
|
|
18782
|
-
return
|
|
18782
|
+
return fields4;
|
|
18783
18783
|
};
|
|
18784
18784
|
PDFForm2.prototype.getFieldMaybe = function(name) {
|
|
18785
18785
|
assertIs(name, "name", ["string"]);
|
|
18786
|
-
var
|
|
18787
|
-
for (var idx4 = 0, len3 =
|
|
18788
|
-
var field =
|
|
18786
|
+
var fields4 = this.getFields();
|
|
18787
|
+
for (var idx4 = 0, len3 = fields4.length;idx4 < len3; idx4++) {
|
|
18788
|
+
var field = fields4[idx4];
|
|
18789
18789
|
if (field.getName() === name)
|
|
18790
18790
|
return field;
|
|
18791
18791
|
}
|
|
@@ -18908,9 +18908,9 @@ var init_PDFForm = __esm(() => {
|
|
|
18908
18908
|
if (options.updateFieldAppearances) {
|
|
18909
18909
|
this.updateFieldAppearances();
|
|
18910
18910
|
}
|
|
18911
|
-
var
|
|
18912
|
-
for (var i3 = 0, lenFields =
|
|
18913
|
-
var field =
|
|
18911
|
+
var fields4 = this.getFields();
|
|
18912
|
+
for (var i3 = 0, lenFields = fields4.length;i3 < lenFields; i3++) {
|
|
18913
|
+
var field = fields4[i3];
|
|
18914
18914
|
var widgets = field.acroField.getWidgets();
|
|
18915
18915
|
for (var j = 0, lenWidgets = widgets.length;j < lenWidgets; j++) {
|
|
18916
18916
|
var widget = widgets[j];
|
|
@@ -18957,9 +18957,9 @@ var init_PDFForm = __esm(() => {
|
|
|
18957
18957
|
PDFForm2.prototype.updateFieldAppearances = function(font) {
|
|
18958
18958
|
assertOrUndefined(font, "font", [[PDFFont_default, "PDFFont"]]);
|
|
18959
18959
|
font = font !== null && font !== undefined ? font : this.getDefaultFont();
|
|
18960
|
-
var
|
|
18961
|
-
for (var idx4 = 0, len3 =
|
|
18962
|
-
var field =
|
|
18960
|
+
var fields4 = this.getFields();
|
|
18961
|
+
for (var idx4 = 0, len3 = fields4.length;idx4 < len3; idx4++) {
|
|
18962
|
+
var field = fields4[idx4];
|
|
18963
18963
|
if (field.needsAppearancesUpdate()) {
|
|
18964
18964
|
field.defaultUpdateAppearances(font);
|
|
18965
18965
|
}
|
|
@@ -19037,9 +19037,9 @@ var init_PDFForm = __esm(() => {
|
|
|
19037
19037
|
return nonTerminal;
|
|
19038
19038
|
};
|
|
19039
19039
|
PDFForm2.prototype.findNonTerminal = function(partialName, parent) {
|
|
19040
|
-
var
|
|
19041
|
-
for (var idx4 = 0, len3 =
|
|
19042
|
-
var _a =
|
|
19040
|
+
var fields4 = parent instanceof PDFAcroForm_default ? this.acroForm.getFields() : createPDFAcroFields(parent.Kids());
|
|
19041
|
+
for (var idx4 = 0, len3 = fields4.length;idx4 < len3; idx4++) {
|
|
19042
|
+
var _a = fields4[idx4], field = _a[0], ref = _a[1];
|
|
19043
19043
|
if (field.getPartialName() === partialName) {
|
|
19044
19044
|
if (field instanceof PDFAcroNonTerminal_default)
|
|
19045
19045
|
return [field, ref];
|
|
@@ -19196,26 +19196,26 @@ var init_PDFJavaScript = __esm(() => {
|
|
|
19196
19196
|
}
|
|
19197
19197
|
PDFJavaScript2.prototype.embed = function() {
|
|
19198
19198
|
return __awaiter(this, undefined, undefined, function() {
|
|
19199
|
-
var _a, catalog,
|
|
19199
|
+
var _a, catalog, context2, ref, Names, Javascript, JSNames;
|
|
19200
19200
|
return __generator(this, function(_b) {
|
|
19201
19201
|
switch (_b.label) {
|
|
19202
19202
|
case 0:
|
|
19203
19203
|
if (!!this.alreadyEmbedded)
|
|
19204
19204
|
return [3, 2];
|
|
19205
|
-
_a = this.doc, catalog = _a.catalog,
|
|
19205
|
+
_a = this.doc, catalog = _a.catalog, context2 = _a.context;
|
|
19206
19206
|
return [4, this.embedder.embedIntoContext(this.doc.context, this.ref)];
|
|
19207
19207
|
case 1:
|
|
19208
19208
|
ref = _b.sent();
|
|
19209
19209
|
if (!catalog.has(PDFName_default.of("Names"))) {
|
|
19210
|
-
catalog.set(PDFName_default.of("Names"),
|
|
19210
|
+
catalog.set(PDFName_default.of("Names"), context2.obj({}));
|
|
19211
19211
|
}
|
|
19212
19212
|
Names = catalog.lookup(PDFName_default.of("Names"), PDFDict_default);
|
|
19213
19213
|
if (!Names.has(PDFName_default.of("JavaScript"))) {
|
|
19214
|
-
Names.set(PDFName_default.of("JavaScript"),
|
|
19214
|
+
Names.set(PDFName_default.of("JavaScript"), context2.obj({}));
|
|
19215
19215
|
}
|
|
19216
19216
|
Javascript = Names.lookup(PDFName_default.of("JavaScript"), PDFDict_default);
|
|
19217
19217
|
if (!Javascript.has(PDFName_default.of("Names"))) {
|
|
19218
|
-
Javascript.set(PDFName_default.of("Names"),
|
|
19218
|
+
Javascript.set(PDFName_default.of("Names"), context2.obj([]));
|
|
19219
19219
|
}
|
|
19220
19220
|
JSNames = Javascript.lookup(PDFName_default.of("Names"), PDFArray_default);
|
|
19221
19221
|
JSNames.push(PDFHexString_default.fromText(this.embedder.scriptName));
|
|
@@ -19249,20 +19249,20 @@ var init_JavaScriptEmbedder = __esm(() => {
|
|
|
19249
19249
|
JavaScriptEmbedder2.for = function(script, scriptName) {
|
|
19250
19250
|
return new JavaScriptEmbedder2(script, scriptName);
|
|
19251
19251
|
};
|
|
19252
|
-
JavaScriptEmbedder2.prototype.embedIntoContext = function(
|
|
19252
|
+
JavaScriptEmbedder2.prototype.embedIntoContext = function(context2, ref) {
|
|
19253
19253
|
return __awaiter(this, undefined, undefined, function() {
|
|
19254
19254
|
var jsActionDict;
|
|
19255
19255
|
return __generator(this, function(_a) {
|
|
19256
|
-
jsActionDict =
|
|
19256
|
+
jsActionDict = context2.obj({
|
|
19257
19257
|
Type: "Action",
|
|
19258
19258
|
S: "JavaScript",
|
|
19259
19259
|
JS: PDFHexString_default.fromText(this.script)
|
|
19260
19260
|
});
|
|
19261
19261
|
if (ref) {
|
|
19262
|
-
|
|
19262
|
+
context2.assign(ref, jsActionDict);
|
|
19263
19263
|
return [2, ref];
|
|
19264
19264
|
} else {
|
|
19265
|
-
return [2,
|
|
19265
|
+
return [2, context2.register(jsActionDict)];
|
|
19266
19266
|
}
|
|
19267
19267
|
return [2];
|
|
19268
19268
|
});
|
|
@@ -19297,7 +19297,7 @@ var init_PDFDocument = __esm(() => {
|
|
|
19297
19297
|
init_PDFJavaScript();
|
|
19298
19298
|
init_JavaScriptEmbedder();
|
|
19299
19299
|
PDFDocument = function() {
|
|
19300
|
-
function PDFDocument2(
|
|
19300
|
+
function PDFDocument2(context2, ignoreEncryption, updateMetadata) {
|
|
19301
19301
|
var _this = this;
|
|
19302
19302
|
this.defaultWordBreaks = [" "];
|
|
19303
19303
|
this.computePages = function() {
|
|
@@ -19318,11 +19318,11 @@ var init_PDFDocument = __esm(() => {
|
|
|
19318
19318
|
var acroForm = _this.catalog.getOrCreateAcroForm();
|
|
19319
19319
|
return PDFForm_default.of(acroForm, _this);
|
|
19320
19320
|
};
|
|
19321
|
-
assertIs(
|
|
19321
|
+
assertIs(context2, "context", [[PDFContext_default, "PDFContext"]]);
|
|
19322
19322
|
assertIs(ignoreEncryption, "ignoreEncryption", ["boolean"]);
|
|
19323
|
-
this.context =
|
|
19324
|
-
this.catalog =
|
|
19325
|
-
this.isEncrypted = !!
|
|
19323
|
+
this.context = context2;
|
|
19324
|
+
this.catalog = context2.lookup(context2.trailerInfo.Root);
|
|
19325
|
+
this.isEncrypted = !!context2.lookup(context2.trailerInfo.Encrypt);
|
|
19326
19326
|
this.pageCache = Cache_default.populatedBy(this.computePages);
|
|
19327
19327
|
this.pageMap = new Map;
|
|
19328
19328
|
this.formCache = Cache_default.populatedBy(this.getOrCreateForm);
|
|
@@ -19341,7 +19341,7 @@ var init_PDFDocument = __esm(() => {
|
|
|
19341
19341
|
options = {};
|
|
19342
19342
|
}
|
|
19343
19343
|
return __awaiter(this, undefined, undefined, function() {
|
|
19344
|
-
var _a, ignoreEncryption, _b, parseSpeed, _c, throwOnInvalidObject, _d, updateMetadata, _e, capNumbers, bytes,
|
|
19344
|
+
var _a, ignoreEncryption, _b, parseSpeed, _c, throwOnInvalidObject, _d, updateMetadata, _e, capNumbers, bytes, context2;
|
|
19345
19345
|
return __generator(this, function(_f) {
|
|
19346
19346
|
switch (_f.label) {
|
|
19347
19347
|
case 0:
|
|
@@ -19353,8 +19353,8 @@ var init_PDFDocument = __esm(() => {
|
|
|
19353
19353
|
bytes = toUint8Array(pdf);
|
|
19354
19354
|
return [4, PDFParser_default.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers).parseDocument()];
|
|
19355
19355
|
case 1:
|
|
19356
|
-
|
|
19357
|
-
return [2, new PDFDocument2(
|
|
19356
|
+
context2 = _f.sent();
|
|
19357
|
+
return [2, new PDFDocument2(context2, ignoreEncryption, updateMetadata)];
|
|
19358
19358
|
}
|
|
19359
19359
|
});
|
|
19360
19360
|
});
|
|
@@ -19364,15 +19364,15 @@ var init_PDFDocument = __esm(() => {
|
|
|
19364
19364
|
options = {};
|
|
19365
19365
|
}
|
|
19366
19366
|
return __awaiter(this, undefined, undefined, function() {
|
|
19367
|
-
var _a, updateMetadata,
|
|
19367
|
+
var _a, updateMetadata, context2, pageTree, pageTreeRef, catalog;
|
|
19368
19368
|
return __generator(this, function(_b) {
|
|
19369
19369
|
_a = options.updateMetadata, updateMetadata = _a === undefined ? true : _a;
|
|
19370
|
-
|
|
19371
|
-
pageTree = PDFPageTree_default.withContext(
|
|
19372
|
-
pageTreeRef =
|
|
19373
|
-
catalog = PDFCatalog_default.withContextAndPages(
|
|
19374
|
-
|
|
19375
|
-
return [2, new PDFDocument2(
|
|
19370
|
+
context2 = PDFContext_default.create();
|
|
19371
|
+
pageTree = PDFPageTree_default.withContext(context2);
|
|
19372
|
+
pageTreeRef = context2.register(pageTree);
|
|
19373
|
+
catalog = PDFCatalog_default.withContextAndPages(context2, pageTreeRef);
|
|
19374
|
+
context2.trailerInfo.Root = context2.register(catalog);
|
|
19375
|
+
return [2, new PDFDocument2(context2, false, updateMetadata)];
|
|
19376
19376
|
});
|
|
19377
19377
|
});
|
|
19378
19378
|
};
|
|
@@ -19789,7 +19789,7 @@ var init_PDFDocument = __esm(() => {
|
|
|
19789
19789
|
transformationMatrices = [];
|
|
19790
19790
|
}
|
|
19791
19791
|
return __awaiter(this, undefined, undefined, function() {
|
|
19792
|
-
var idx4, len3, currPage, nextPage,
|
|
19792
|
+
var idx4, len3, currPage, nextPage, context2, maybeCopyPage, embeddedPages, idx4, len3, page, box, matrix, embedder, ref;
|
|
19793
19793
|
var _a;
|
|
19794
19794
|
return __generator(this, function(_b) {
|
|
19795
19795
|
switch (_b.label) {
|
|
@@ -19803,10 +19803,10 @@ var init_PDFDocument = __esm(() => {
|
|
|
19803
19803
|
throw new PageEmbeddingMismatchedContextError;
|
|
19804
19804
|
}
|
|
19805
19805
|
}
|
|
19806
|
-
|
|
19807
|
-
maybeCopyPage =
|
|
19806
|
+
context2 = pages[0].node.context;
|
|
19807
|
+
maybeCopyPage = context2 === this.context ? function(p) {
|
|
19808
19808
|
return p;
|
|
19809
|
-
} : PDFObjectCopier_default.for(
|
|
19809
|
+
} : PDFObjectCopier_default.for(context2, this.context).copy;
|
|
19810
19810
|
embeddedPages = new Array(pages.length);
|
|
19811
19811
|
idx4 = 0, len3 = pages.length;
|
|
19812
19812
|
_b.label = 1;
|
|
@@ -21709,6 +21709,49 @@ class DataOperationError extends Error {
|
|
|
21709
21709
|
}
|
|
21710
21710
|
}
|
|
21711
21711
|
|
|
21712
|
+
// ../../shared/data-search-input.ts
|
|
21713
|
+
var invalid = () => {
|
|
21714
|
+
throw new DataOperationError("invalid_query");
|
|
21715
|
+
};
|
|
21716
|
+
var scalarText = (value) => typeof value === "string" && !/[\u0000\uD800-\uDFFF]/u.test(value);
|
|
21717
|
+
function captureRecordsSearchInput(query, options) {
|
|
21718
|
+
if (!scalarText(query))
|
|
21719
|
+
return invalid();
|
|
21720
|
+
const length = [...query.trim()].length;
|
|
21721
|
+
if (length < 1 || length > 256)
|
|
21722
|
+
return invalid();
|
|
21723
|
+
if (options === undefined)
|
|
21724
|
+
return { query };
|
|
21725
|
+
if (!options || typeof options !== "object" || Array.isArray(options) || ![Object.prototype, null].includes(Object.getPrototypeOf(options)))
|
|
21726
|
+
return invalid();
|
|
21727
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
21728
|
+
if (Reflect.ownKeys(options).some((key) => typeof key !== "string" || !["collections", "limit"].includes(key) || !descriptors[key]?.enumerable || !Object.hasOwn(descriptors[key], "value")))
|
|
21729
|
+
return invalid();
|
|
21730
|
+
const captured = {};
|
|
21731
|
+
if (Object.hasOwn(descriptors, "collections")) {
|
|
21732
|
+
const supplied = descriptors.collections.value;
|
|
21733
|
+
if (!Array.isArray(supplied) || supplied.length < 1 || supplied.length > 16 || Reflect.ownKeys(supplied).length !== supplied.length + 1)
|
|
21734
|
+
return invalid();
|
|
21735
|
+
const collections = [];
|
|
21736
|
+
for (let index = 0;index < supplied.length; index++) {
|
|
21737
|
+
const descriptor = Object.getOwnPropertyDescriptor(supplied, String(index));
|
|
21738
|
+
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value") || !scalarText(descriptor.value))
|
|
21739
|
+
return invalid();
|
|
21740
|
+
collections.push(descriptor.value);
|
|
21741
|
+
}
|
|
21742
|
+
if (new Set(collections).size !== collections.length)
|
|
21743
|
+
return invalid();
|
|
21744
|
+
captured.collections = collections;
|
|
21745
|
+
}
|
|
21746
|
+
if (Object.hasOwn(descriptors, "limit")) {
|
|
21747
|
+
const supplied = descriptors.limit.value;
|
|
21748
|
+
if (!Number.isInteger(supplied) || supplied < 1 || supplied > 100)
|
|
21749
|
+
return invalid();
|
|
21750
|
+
captured.limit = supplied;
|
|
21751
|
+
}
|
|
21752
|
+
return { query, options: captured };
|
|
21753
|
+
}
|
|
21754
|
+
|
|
21712
21755
|
// ../../shared/data-envelope.ts
|
|
21713
21756
|
var DATA_REQUEST_LIMIT = 256 * 1024;
|
|
21714
21757
|
var invalidChange = () => {
|
|
@@ -21841,56 +21884,57 @@ class FileOperationError extends Error {
|
|
|
21841
21884
|
}
|
|
21842
21885
|
}
|
|
21843
21886
|
var FILE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
21887
|
+
var FILE_ORIGINAL_MAX_BYTES = 5 * 1024 ** 3;
|
|
21844
21888
|
function parseFileDescriptor(value) {
|
|
21845
|
-
const
|
|
21889
|
+
const invalid2 = () => {
|
|
21846
21890
|
throw new FileOperationError("unavailable", 503, true);
|
|
21847
21891
|
};
|
|
21848
21892
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
21849
|
-
return
|
|
21893
|
+
return invalid2();
|
|
21850
21894
|
const f = value;
|
|
21851
|
-
if (Object.keys(f).sort().join(",") !== "details,enrichments,id,mediaType,name,path,sha256,size" || typeof f.id !== "string" || !FILE_ID_PATTERN.test(f.id) || !safeFileName(f.name) || !safeFilePath(f.path) || !Number.isSafeInteger(f.size) || f.size < 0 || f.size >
|
|
21852
|
-
return
|
|
21895
|
+
if (Object.keys(f).sort().join(",") !== "details,enrichments,id,mediaType,name,path,sha256,size" || typeof f.id !== "string" || !FILE_ID_PATTERN.test(f.id) || !safeFileName(f.name) || !safeFilePath(f.path) || !Number.isSafeInteger(f.size) || f.size < 0 || f.size > FILE_ORIGINAL_MAX_BYTES || typeof f.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(f.sha256) || !f.enrichments || typeof f.enrichments !== "object" || Array.isArray(f.enrichments) || !f.details || typeof f.details !== "object" || Array.isArray(f.details))
|
|
21896
|
+
return invalid2();
|
|
21853
21897
|
const d = f.details;
|
|
21854
21898
|
if (d.kind === "other") {
|
|
21855
21899
|
if (Object.keys(d).length !== 1 || f.mediaType !== "application/octet-stream")
|
|
21856
|
-
return
|
|
21900
|
+
return invalid2();
|
|
21857
21901
|
} else if (d.kind === "csv") {
|
|
21858
21902
|
if (Object.keys(d).sort().join(",") !== "dataRows,delimiter,encoding,headerRow,kind" || f.mediaType !== "text/csv" || !["utf-8", "windows-1252"].includes(d.encoding) || ![",", ";", "\t"].includes(d.delimiter) || !Number.isSafeInteger(d.headerRow) || d.headerRow < 1 || !Number.isSafeInteger(d.dataRows) || d.dataRows < 0)
|
|
21859
|
-
return
|
|
21903
|
+
return invalid2();
|
|
21860
21904
|
} else
|
|
21861
|
-
return
|
|
21905
|
+
return invalid2();
|
|
21862
21906
|
for (const [name, descriptor] of Object.entries(f.enrichments)) {
|
|
21863
21907
|
if (!safeEnrichmentName(name))
|
|
21864
|
-
return
|
|
21908
|
+
return invalid2();
|
|
21865
21909
|
parseEnrichmentDescriptor(descriptor);
|
|
21866
21910
|
}
|
|
21867
21911
|
if (new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024)
|
|
21868
|
-
return
|
|
21912
|
+
return invalid2();
|
|
21869
21913
|
return f;
|
|
21870
21914
|
}
|
|
21871
21915
|
function parseEnrichmentDescriptor(value) {
|
|
21872
|
-
const
|
|
21916
|
+
const invalid2 = () => {
|
|
21873
21917
|
throw new FileOperationError("unavailable", 503, true);
|
|
21874
21918
|
};
|
|
21875
21919
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
21876
|
-
return
|
|
21920
|
+
return invalid2();
|
|
21877
21921
|
const d = value;
|
|
21878
21922
|
if (Object.keys(d).sort().join(",") !== "mediaType,sha256,size" || !["application/octet-stream", "text/plain", "text/markdown", "application/json"].includes(d.mediaType) || !Number.isSafeInteger(d.size) || d.size < 0 || d.size > 16 * 1024 * 1024 || typeof d.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(d.sha256))
|
|
21879
|
-
return
|
|
21923
|
+
return invalid2();
|
|
21880
21924
|
return d;
|
|
21881
21925
|
}
|
|
21882
21926
|
function safeEnrichmentName(value) {
|
|
21883
21927
|
return safeFileName(value) && !/^original(?:\.|$)/i.test(value);
|
|
21884
21928
|
}
|
|
21885
21929
|
function parseFileEnrichMetadata(value, maxBytes) {
|
|
21886
|
-
const
|
|
21930
|
+
const invalid2 = () => {
|
|
21887
21931
|
throw new FileOperationError("invalid_input", 400);
|
|
21888
21932
|
};
|
|
21889
21933
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
21890
|
-
return
|
|
21934
|
+
return invalid2();
|
|
21891
21935
|
const d = value;
|
|
21892
21936
|
if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key)) || !safeEnrichmentName(d.name) || !Number.isSafeInteger(d.size) || d.size < 0 || d.mediaType !== undefined && (typeof d.mediaType !== "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType)) || d.replace !== undefined && (typeof d.replace !== "string" || !/^[0-9a-f]{64}$/.test(d.replace)))
|
|
21893
|
-
return
|
|
21937
|
+
return invalid2();
|
|
21894
21938
|
if (d.size > maxBytes)
|
|
21895
21939
|
throw new FileOperationError("request_too_large", 413);
|
|
21896
21940
|
return d;
|
|
@@ -21902,37 +21946,37 @@ function safeFilePath(value) {
|
|
|
21902
21946
|
return typeof value === "string" && value.length <= 1024 && value.split("/").every(safeFileName);
|
|
21903
21947
|
}
|
|
21904
21948
|
function parseFileCreateMetadata(value, maxBytes) {
|
|
21905
|
-
const
|
|
21949
|
+
const invalid2 = () => {
|
|
21906
21950
|
throw new FileOperationError("invalid_input", 400);
|
|
21907
21951
|
};
|
|
21908
21952
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
21909
|
-
return
|
|
21953
|
+
return invalid2();
|
|
21910
21954
|
const input = value;
|
|
21911
21955
|
if (Object.keys(input).some((key) => !["name", "path", "storage", "csv", "size", "requestKey"].includes(key)))
|
|
21912
|
-
return
|
|
21956
|
+
return invalid2();
|
|
21913
21957
|
const path = input.path === undefined ? "Files" : input.path;
|
|
21914
21958
|
if (!safeFileName(input.name) || !safeFilePath(path))
|
|
21915
|
-
return
|
|
21959
|
+
return invalid2();
|
|
21916
21960
|
if (input.storage !== undefined && input.storage !== "remote" && input.storage !== "local")
|
|
21917
|
-
return
|
|
21961
|
+
return invalid2();
|
|
21918
21962
|
if (!Number.isSafeInteger(input.size) || input.size < 0)
|
|
21919
|
-
return
|
|
21963
|
+
return invalid2();
|
|
21920
21964
|
if (input.size > maxBytes)
|
|
21921
21965
|
throw new FileOperationError("request_too_large", 413);
|
|
21922
21966
|
if (typeof input.requestKey !== "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey))
|
|
21923
|
-
return
|
|
21967
|
+
return invalid2();
|
|
21924
21968
|
let csv;
|
|
21925
21969
|
if (input.csv !== undefined) {
|
|
21926
21970
|
if (!input.csv || typeof input.csv !== "object" || Array.isArray(input.csv))
|
|
21927
|
-
return
|
|
21971
|
+
return invalid2();
|
|
21928
21972
|
const hints = input.csv;
|
|
21929
21973
|
if (Object.keys(hints).some((key) => !["encoding", "delimiter", "headerRow"].includes(key)))
|
|
21930
|
-
return
|
|
21974
|
+
return invalid2();
|
|
21931
21975
|
const encoding = hints.encoding === undefined ? "utf-8" : hints.encoding;
|
|
21932
21976
|
const delimiter = hints.delimiter === undefined ? "," : hints.delimiter;
|
|
21933
21977
|
const headerRow = hints.headerRow === undefined ? 1 : hints.headerRow;
|
|
21934
21978
|
if (encoding !== "utf-8" && encoding !== "windows-1252" || ![",", ";", "\t"].includes(delimiter) || !Number.isSafeInteger(headerRow) || headerRow < 1 || headerRow > 1e5)
|
|
21935
|
-
return
|
|
21979
|
+
return invalid2();
|
|
21936
21980
|
csv = { encoding, delimiter, headerRow };
|
|
21937
21981
|
}
|
|
21938
21982
|
return {
|
|
@@ -22057,6 +22101,19 @@ function installMemberContext(resolve) {
|
|
|
22057
22101
|
memberContext = undefined;
|
|
22058
22102
|
};
|
|
22059
22103
|
}
|
|
22104
|
+
async function resolveAppContext() {
|
|
22105
|
+
const host = memberContext;
|
|
22106
|
+
if (!host)
|
|
22107
|
+
throw new Error("App context unavailable.");
|
|
22108
|
+
const context = await host();
|
|
22109
|
+
if (host !== memberContext || !context.isCurrent() || context.expiresAt <= Date.now()) {
|
|
22110
|
+
throw new Error("App context unavailable.");
|
|
22111
|
+
}
|
|
22112
|
+
if (context.kind !== "local" && (typeof context.accessToken !== "string" || !/^[^\s]{1,8192}$/.test(context.accessToken))) {
|
|
22113
|
+
throw new Error("App context unavailable.");
|
|
22114
|
+
}
|
|
22115
|
+
return context;
|
|
22116
|
+
}
|
|
22060
22117
|
async function resolveDataContext() {
|
|
22061
22118
|
try {
|
|
22062
22119
|
const local = localRoutineRequest();
|
|
@@ -22068,6 +22125,10 @@ async function resolveDataContext() {
|
|
|
22068
22125
|
const host = memberContext;
|
|
22069
22126
|
if (host !== undefined) {
|
|
22070
22127
|
const context = await host();
|
|
22128
|
+
if (host !== memberContext || !context.isCurrent() || context.expiresAt <= Date.now())
|
|
22129
|
+
throw new Error;
|
|
22130
|
+
if (context.kind === "local")
|
|
22131
|
+
return { local: context.requestData };
|
|
22071
22132
|
if (!context || !Number.isFinite(context.expiresAt) || context.expiresAt <= Date.now() || typeof context.accessToken !== "string" || !/^[^\s]{1,8192}$/.test(context.accessToken))
|
|
22072
22133
|
throw new Error;
|
|
22073
22134
|
return checked(context.workspace, context.endpoint, { authorization: `Bearer ${context.accessToken}` });
|
|
@@ -22094,6 +22155,8 @@ async function resolveFilesContext() {
|
|
|
22094
22155
|
const host = memberContext;
|
|
22095
22156
|
if (host) {
|
|
22096
22157
|
const context = await host();
|
|
22158
|
+
if (context.kind === "local")
|
|
22159
|
+
throw new Error;
|
|
22097
22160
|
if (!Number.isFinite(context.expiresAt) || context.expiresAt <= Date.now() || typeof context.accessToken !== "string" || !/^[^\s]{1,8192}$/.test(context.accessToken))
|
|
22098
22161
|
throw new Error;
|
|
22099
22162
|
return {
|
|
@@ -22156,7 +22219,16 @@ var data = {
|
|
|
22156
22219
|
list: () => send({ operation: "collections.list" }),
|
|
22157
22220
|
schema: (name) => send({ operation: "collections.schema", name })
|
|
22158
22221
|
},
|
|
22159
|
-
records: {
|
|
22222
|
+
records: {
|
|
22223
|
+
select: (query) => send({ operation: "records.select", query }),
|
|
22224
|
+
search: (query, options) => {
|
|
22225
|
+
try {
|
|
22226
|
+
return send({ operation: "records.search", ...captureRecordsSearchInput(query, options) });
|
|
22227
|
+
} catch (error) {
|
|
22228
|
+
return Promise.reject(error);
|
|
22229
|
+
}
|
|
22230
|
+
}
|
|
22231
|
+
},
|
|
22160
22232
|
changes() {
|
|
22161
22233
|
let updates = [], creates = [], deletes = [], publicationId;
|
|
22162
22234
|
let pending, confirmed;
|
|
@@ -22255,13 +22327,14 @@ var data = {
|
|
|
22255
22327
|
};
|
|
22256
22328
|
// src/files.ts
|
|
22257
22329
|
var MAX_BYTES = 16 * 1024 * 1024;
|
|
22330
|
+
var PART_BYTES = 8 * 1024 * 1024;
|
|
22258
22331
|
var METADATA_BYTES = 4096;
|
|
22259
22332
|
var RESULT_BYTES = 16 * 1024;
|
|
22260
22333
|
var TIMEOUT_MS = 30000;
|
|
22261
22334
|
var MAX_ACTIVE = 4;
|
|
22262
22335
|
var ATTEMPTS = 2;
|
|
22263
22336
|
var active = 0;
|
|
22264
|
-
var
|
|
22337
|
+
var invalid2 = () => new FileOperationError("invalid_input", 400);
|
|
22265
22338
|
var unavailable = () => new FileOperationError("unavailable", 503, true);
|
|
22266
22339
|
var failures = {
|
|
22267
22340
|
400: ["invalid_input", "unsupported_context"],
|
|
@@ -22285,7 +22358,7 @@ async function boundedBytes(stream, limit) {
|
|
|
22285
22358
|
if (done)
|
|
22286
22359
|
break;
|
|
22287
22360
|
if (!(value instanceof Uint8Array))
|
|
22288
|
-
throw
|
|
22361
|
+
throw invalid2();
|
|
22289
22362
|
size += value.byteLength;
|
|
22290
22363
|
if (size > limit)
|
|
22291
22364
|
throw new FileOperationError("request_too_large", 413);
|
|
@@ -22296,7 +22369,7 @@ async function boundedBytes(stream, limit) {
|
|
|
22296
22369
|
}
|
|
22297
22370
|
return bytes.slice(0, size);
|
|
22298
22371
|
}
|
|
22299
|
-
async function timed(work, parent) {
|
|
22372
|
+
async function timed(work, parent, timeout = TIMEOUT_MS) {
|
|
22300
22373
|
const controller = new AbortController;
|
|
22301
22374
|
let timer;
|
|
22302
22375
|
let abort;
|
|
@@ -22305,7 +22378,7 @@ async function timed(work, parent) {
|
|
|
22305
22378
|
controller.abort();
|
|
22306
22379
|
reject(unavailable());
|
|
22307
22380
|
};
|
|
22308
|
-
timer = setTimeout(abort,
|
|
22381
|
+
timer = setTimeout(abort, timeout);
|
|
22309
22382
|
parent?.addEventListener("abort", abort, { once: true });
|
|
22310
22383
|
if (parent?.aborted)
|
|
22311
22384
|
abort();
|
|
@@ -22325,6 +22398,74 @@ async function result(response) {
|
|
|
22325
22398
|
throw unavailable();
|
|
22326
22399
|
}
|
|
22327
22400
|
}
|
|
22401
|
+
async function hostedContent(url, init, parent) {
|
|
22402
|
+
const delivery = new AbortController;
|
|
22403
|
+
const abort = () => delivery.abort(parent.reason);
|
|
22404
|
+
parent.addEventListener("abort", abort, { once: true });
|
|
22405
|
+
if (parent.aborted)
|
|
22406
|
+
abort();
|
|
22407
|
+
const detach = () => parent.removeEventListener("abort", abort);
|
|
22408
|
+
try {
|
|
22409
|
+
const response = await fetch(url, { ...init, signal: delivery.signal });
|
|
22410
|
+
if (delivery.signal.aborted) {
|
|
22411
|
+
response.body?.cancel().catch(() => {});
|
|
22412
|
+
throw unavailable();
|
|
22413
|
+
}
|
|
22414
|
+
if (!response.body) {
|
|
22415
|
+
detach();
|
|
22416
|
+
return response;
|
|
22417
|
+
}
|
|
22418
|
+
const source = response.body;
|
|
22419
|
+
let reader;
|
|
22420
|
+
let settled = false;
|
|
22421
|
+
const cancel = async (reason) => {
|
|
22422
|
+
if (settled)
|
|
22423
|
+
return;
|
|
22424
|
+
settled = true;
|
|
22425
|
+
detach();
|
|
22426
|
+
delivery.abort(reason);
|
|
22427
|
+
try {
|
|
22428
|
+
await (reader ? reader.cancel(reason) : source.cancel(reason));
|
|
22429
|
+
} catch (error) {
|
|
22430
|
+
if (error !== delivery.signal.reason && !(error instanceof Error && error.name === "AbortError"))
|
|
22431
|
+
throw error;
|
|
22432
|
+
} finally {
|
|
22433
|
+
reader?.releaseLock();
|
|
22434
|
+
}
|
|
22435
|
+
};
|
|
22436
|
+
const body = new ReadableStream({
|
|
22437
|
+
async pull(controller) {
|
|
22438
|
+
try {
|
|
22439
|
+
reader ??= source.getReader();
|
|
22440
|
+
const { done, value } = await reader.read();
|
|
22441
|
+
if (settled)
|
|
22442
|
+
return;
|
|
22443
|
+
if (done) {
|
|
22444
|
+
settled = true;
|
|
22445
|
+
detach();
|
|
22446
|
+
reader.releaseLock();
|
|
22447
|
+
controller.close();
|
|
22448
|
+
} else
|
|
22449
|
+
controller.enqueue(value);
|
|
22450
|
+
} catch (error) {
|
|
22451
|
+
if (settled)
|
|
22452
|
+
return;
|
|
22453
|
+
controller.error(error);
|
|
22454
|
+
await cancel(error).catch(() => {});
|
|
22455
|
+
}
|
|
22456
|
+
},
|
|
22457
|
+
cancel
|
|
22458
|
+
}, { highWaterMark: 0 });
|
|
22459
|
+
const wrapped = new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
22460
|
+
for (const key of ["url", "redirected", "type"])
|
|
22461
|
+
Object.defineProperty(wrapped, key, { value: response[key] });
|
|
22462
|
+
return wrapped;
|
|
22463
|
+
} catch (error) {
|
|
22464
|
+
detach();
|
|
22465
|
+
delivery.abort(error);
|
|
22466
|
+
throw error;
|
|
22467
|
+
}
|
|
22468
|
+
}
|
|
22328
22469
|
async function send(suffix, init, descriptor, initial, parent) {
|
|
22329
22470
|
const original = initial;
|
|
22330
22471
|
const checkCurrent = () => {
|
|
@@ -22360,13 +22501,17 @@ async function send(suffix, init, descriptor, initial, parent) {
|
|
|
22360
22501
|
return new Response(Uint8Array.from(data2, (c) => c.charCodeAt(0)), { status: value2.status, headers: value2.headers });
|
|
22361
22502
|
}
|
|
22362
22503
|
return Response.json(value2.json, { status: value2.status, headers: value2.headers });
|
|
22363
|
-
})() : await
|
|
22364
|
-
|
|
22365
|
-
|
|
22366
|
-
|
|
22367
|
-
|
|
22368
|
-
|
|
22369
|
-
|
|
22504
|
+
})() : await (async () => {
|
|
22505
|
+
const url = `${context.url}${suffix}`;
|
|
22506
|
+
const request = {
|
|
22507
|
+
...init,
|
|
22508
|
+
signal: parent,
|
|
22509
|
+
headers: { ...context.headers, ...init.headers },
|
|
22510
|
+
redirect: "error",
|
|
22511
|
+
cache: "no-store"
|
|
22512
|
+
};
|
|
22513
|
+
return descriptor ? fetch(url, request) : hostedContent(url, request, parent);
|
|
22514
|
+
})();
|
|
22370
22515
|
if (!response.ok) {
|
|
22371
22516
|
const value2 = await result(response);
|
|
22372
22517
|
const error = value2 && typeof value2 === "object" && "error" in value2 ? value2.error : undefined;
|
|
@@ -22387,6 +22532,10 @@ async function send(suffix, init, descriptor, initial, parent) {
|
|
|
22387
22532
|
if (!descriptor)
|
|
22388
22533
|
return response;
|
|
22389
22534
|
const value = await result(response);
|
|
22535
|
+
if (descriptor === "control") {
|
|
22536
|
+
checkCurrent();
|
|
22537
|
+
return value;
|
|
22538
|
+
}
|
|
22390
22539
|
let parsed;
|
|
22391
22540
|
if (descriptor === "enrichment") {
|
|
22392
22541
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -22410,9 +22559,129 @@ async function send(suffix, init, descriptor, initial, parent) {
|
|
|
22410
22559
|
}
|
|
22411
22560
|
function idPath(id2) {
|
|
22412
22561
|
if (typeof id2 !== "string" || !FILE_ID_PATTERN.test(id2))
|
|
22413
|
-
throw
|
|
22562
|
+
throw invalid2();
|
|
22414
22563
|
return `/${id2}`;
|
|
22415
22564
|
}
|
|
22565
|
+
async function multipartCreate(input, metadata, context) {
|
|
22566
|
+
let ticket;
|
|
22567
|
+
let reader;
|
|
22568
|
+
let chunk, offset = 0;
|
|
22569
|
+
const receipts = [];
|
|
22570
|
+
const pending = new Set;
|
|
22571
|
+
const request = (work, timeout = TIMEOUT_MS) => timed((signal) => {
|
|
22572
|
+
const task = work(signal);
|
|
22573
|
+
pending.add(task);
|
|
22574
|
+
task.then(() => pending.delete(task), () => pending.delete(task));
|
|
22575
|
+
return task;
|
|
22576
|
+
}, undefined, timeout);
|
|
22577
|
+
const control = (body) => ({
|
|
22578
|
+
method: "POST",
|
|
22579
|
+
headers: { "content-type": "application/json", ...ticket ? { "x-oddington-transfer": ticket } : {} },
|
|
22580
|
+
body: JSON.stringify(body)
|
|
22581
|
+
});
|
|
22582
|
+
try {
|
|
22583
|
+
const start = await request((signal) => send("/multipart/start", control(metadata), "control", context, signal));
|
|
22584
|
+
if (!start || typeof start !== "object" || Array.isArray(start))
|
|
22585
|
+
throw unavailable();
|
|
22586
|
+
const session = start;
|
|
22587
|
+
if (Object.keys(session).sort().join(",") !== "partBytes,ticket" || session.partBytes !== PART_BYTES || typeof session.ticket !== "string" || !session.ticket || session.ticket.length > 8192)
|
|
22588
|
+
throw unavailable();
|
|
22589
|
+
ticket = session.ticket;
|
|
22590
|
+
if (input.file instanceof ReadableStream)
|
|
22591
|
+
reader = input.file.getReader();
|
|
22592
|
+
let lastProgress = Date.now();
|
|
22593
|
+
const next = async () => {
|
|
22594
|
+
try {
|
|
22595
|
+
if (Date.now() - lastProgress >= TIMEOUT_MS)
|
|
22596
|
+
throw unavailable();
|
|
22597
|
+
const value = await request(() => reader.read(), Math.max(1, TIMEOUT_MS - (Date.now() - lastProgress)));
|
|
22598
|
+
if (value.value?.byteLength)
|
|
22599
|
+
lastProgress = Date.now();
|
|
22600
|
+
return value;
|
|
22601
|
+
} catch (error) {
|
|
22602
|
+
await reader.cancel(error).catch(() => {});
|
|
22603
|
+
throw error;
|
|
22604
|
+
}
|
|
22605
|
+
};
|
|
22606
|
+
for (let sent = 0, partNumber = 1;sent < metadata.size; partNumber++) {
|
|
22607
|
+
const length = Math.min(PART_BYTES, metadata.size - sent);
|
|
22608
|
+
let part;
|
|
22609
|
+
if (input.file instanceof Uint8Array)
|
|
22610
|
+
part = input.file.subarray(sent, sent + length).slice();
|
|
22611
|
+
else if (input.file instanceof Blob) {
|
|
22612
|
+
const slice = input.file.slice(sent, sent + length);
|
|
22613
|
+
part = new Uint8Array(await request(() => slice.arrayBuffer()));
|
|
22614
|
+
} else {
|
|
22615
|
+
part = new Uint8Array(length);
|
|
22616
|
+
let filled = 0;
|
|
22617
|
+
while (filled < length) {
|
|
22618
|
+
if (!chunk || offset === chunk.byteLength) {
|
|
22619
|
+
chunk = undefined;
|
|
22620
|
+
offset = 0;
|
|
22621
|
+
const value2 = await next();
|
|
22622
|
+
if (value2.done)
|
|
22623
|
+
throw invalid2();
|
|
22624
|
+
if (!(value2.value instanceof Uint8Array))
|
|
22625
|
+
throw invalid2();
|
|
22626
|
+
chunk = value2.value;
|
|
22627
|
+
if (chunk.byteLength > metadata.size - sent - filled)
|
|
22628
|
+
throw invalid2();
|
|
22629
|
+
}
|
|
22630
|
+
const take = Math.min(length - filled, chunk.byteLength - offset);
|
|
22631
|
+
part.set(chunk.subarray(offset, offset + take), filled);
|
|
22632
|
+
filled += take;
|
|
22633
|
+
offset += take;
|
|
22634
|
+
if (offset === chunk.byteLength) {
|
|
22635
|
+
chunk = undefined;
|
|
22636
|
+
offset = 0;
|
|
22637
|
+
}
|
|
22638
|
+
}
|
|
22639
|
+
}
|
|
22640
|
+
if (part.byteLength !== length)
|
|
22641
|
+
throw invalid2();
|
|
22642
|
+
if (reader && sent + length === metadata.size) {
|
|
22643
|
+
lastProgress = Date.now();
|
|
22644
|
+
for (;; ) {
|
|
22645
|
+
const value2 = await next();
|
|
22646
|
+
if (value2.done)
|
|
22647
|
+
break;
|
|
22648
|
+
if (!(value2.value instanceof Uint8Array) || value2.value.byteLength)
|
|
22649
|
+
throw invalid2();
|
|
22650
|
+
}
|
|
22651
|
+
}
|
|
22652
|
+
const value = await request((signal) => send("/multipart/part", {
|
|
22653
|
+
method: "POST",
|
|
22654
|
+
headers: { "content-type": "application/octet-stream", "x-oddington-transfer": ticket, "x-oddington-part": String(partNumber) },
|
|
22655
|
+
body: part.buffer
|
|
22656
|
+
}, "control", context, signal));
|
|
22657
|
+
const receipt = value;
|
|
22658
|
+
if (!receipt || typeof receipt !== "object" || Object.keys(receipt).sort().join(",") !== "etag,partNumber" || receipt.partNumber !== partNumber || typeof receipt.etag !== "string" || !receipt.etag || receipt.etag.length > 256 || /[\u0000-\u001f\u007f]/.test(receipt.etag))
|
|
22659
|
+
throw unavailable();
|
|
22660
|
+
receipts.push({ partNumber, etag: receipt.etag });
|
|
22661
|
+
sent += length;
|
|
22662
|
+
lastProgress = Date.now();
|
|
22663
|
+
}
|
|
22664
|
+
const completion = control({ parts: receipts });
|
|
22665
|
+
if (new TextEncoder().encode(completion.body).byteLength > 128 * 1024)
|
|
22666
|
+
throw unavailable();
|
|
22667
|
+
return await request((signal) => send("/multipart/complete", completion, true, context, signal), TIMEOUT_MS + Math.ceil(metadata.size / (1024 * 1024)) * 1000);
|
|
22668
|
+
} catch (error) {
|
|
22669
|
+
if (reader)
|
|
22670
|
+
await reader.cancel(error).catch(() => {});
|
|
22671
|
+
if (ticket)
|
|
22672
|
+
await request((signal) => send("/multipart/abort", control({}), "control", context, signal)).catch(() => {});
|
|
22673
|
+
throw error instanceof FileOperationError ? error : unavailable();
|
|
22674
|
+
} finally {
|
|
22675
|
+
chunk = undefined;
|
|
22676
|
+
reader?.releaseLock();
|
|
22677
|
+
if (pending.size)
|
|
22678
|
+
Promise.allSettled([...pending]).then(() => {
|
|
22679
|
+
active--;
|
|
22680
|
+
});
|
|
22681
|
+
else
|
|
22682
|
+
active--;
|
|
22683
|
+
}
|
|
22684
|
+
}
|
|
22416
22685
|
async function operation(work, initial, parent) {
|
|
22417
22686
|
const context = initial ?? await resolveFilesContext();
|
|
22418
22687
|
if (active >= MAX_ACTIVE)
|
|
@@ -22433,7 +22702,7 @@ function contentPath(id2, name) {
|
|
|
22433
22702
|
if (name === undefined)
|
|
22434
22703
|
return `${path}/content`;
|
|
22435
22704
|
if (!safeEnrichmentName(name))
|
|
22436
|
-
throw
|
|
22705
|
+
throw invalid2();
|
|
22437
22706
|
return `${path}/enrichments/${encodeURIComponent(name)}/content`;
|
|
22438
22707
|
}
|
|
22439
22708
|
async function read(id2, names) {
|
|
@@ -22444,16 +22713,16 @@ async function read(id2, names) {
|
|
|
22444
22713
|
return operation((context2, signal) => send(path, { method: "GET" }, false, context2, signal), context);
|
|
22445
22714
|
}
|
|
22446
22715
|
if (!Array.isArray(names))
|
|
22447
|
-
throw
|
|
22716
|
+
throw invalid2();
|
|
22448
22717
|
const distinct = [];
|
|
22449
22718
|
const seen = new Set;
|
|
22450
22719
|
for (const name of names) {
|
|
22451
22720
|
if (typeof name !== "string" || !safeEnrichmentName(name))
|
|
22452
|
-
throw
|
|
22721
|
+
throw invalid2();
|
|
22453
22722
|
if (seen.has(name))
|
|
22454
22723
|
continue;
|
|
22455
22724
|
if (seen.size === 16)
|
|
22456
|
-
throw
|
|
22725
|
+
throw invalid2();
|
|
22457
22726
|
seen.add(name);
|
|
22458
22727
|
distinct.push(name);
|
|
22459
22728
|
}
|
|
@@ -22487,15 +22756,15 @@ var files = {
|
|
|
22487
22756
|
async create(input, options) {
|
|
22488
22757
|
const context = await resolveFilesContext();
|
|
22489
22758
|
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some((key) => !["file", "size", "path", "name", "storage", "csv"].includes(key)) || options !== undefined && (!options || typeof options !== "object" || Array.isArray(options) || Object.keys(options).some((key) => key !== "requestKey")))
|
|
22490
|
-
throw
|
|
22759
|
+
throw invalid2();
|
|
22491
22760
|
const blob = input.file instanceof Blob;
|
|
22492
22761
|
const array2 = input.file instanceof Uint8Array;
|
|
22493
22762
|
const stream = input.file instanceof ReadableStream;
|
|
22494
22763
|
if (!blob && !array2 && !stream)
|
|
22495
|
-
throw
|
|
22764
|
+
throw invalid2();
|
|
22496
22765
|
const intrinsic = blob ? input.file.size : array2 ? input.file.byteLength : undefined;
|
|
22497
22766
|
if (intrinsic !== undefined && input.size !== undefined && input.size !== intrinsic)
|
|
22498
|
-
throw
|
|
22767
|
+
throw invalid2();
|
|
22499
22768
|
let name = input.name;
|
|
22500
22769
|
if (name === undefined && blob && "name" in input.file && typeof input.file.name === "string") {
|
|
22501
22770
|
name = typeof globalThis.File !== "undefined" && input.file instanceof globalThis.File ? input.file.name : input.file.name.split(/[\\/]/).at(-1);
|
|
@@ -22507,20 +22776,22 @@ var files = {
|
|
|
22507
22776
|
storage: input.storage,
|
|
22508
22777
|
csv: input.csv,
|
|
22509
22778
|
requestKey: options?.requestKey === undefined ? crypto.randomUUID() : options.requestKey
|
|
22510
|
-
}, MAX_BYTES);
|
|
22779
|
+
}, context.local ? MAX_BYTES : FILE_ORIGINAL_MAX_BYTES);
|
|
22511
22780
|
if (!context.local && metadata.storage === "local")
|
|
22512
22781
|
throw new FileOperationError("unsupported_context", 400);
|
|
22513
22782
|
const header = encodeURIComponent(JSON.stringify(metadata));
|
|
22514
22783
|
if (new TextEncoder().encode(header).byteLength > METADATA_BYTES)
|
|
22515
|
-
throw
|
|
22784
|
+
throw invalid2();
|
|
22516
22785
|
if (active >= MAX_ACTIVE)
|
|
22517
22786
|
throw new FileOperationError("capacity", 429, true);
|
|
22518
22787
|
active++;
|
|
22788
|
+
if (metadata.size > MAX_BYTES)
|
|
22789
|
+
return multipartCreate(input, metadata, context);
|
|
22519
22790
|
return timed(async (signal) => {
|
|
22520
22791
|
try {
|
|
22521
22792
|
const bytes = array2 ? input.file.slice() : await boundedBytes(blob ? input.file.stream() : input.file, metadata.size);
|
|
22522
22793
|
if (bytes.byteLength !== metadata.size)
|
|
22523
|
-
throw
|
|
22794
|
+
throw invalid2();
|
|
22524
22795
|
if (signal.aborted)
|
|
22525
22796
|
throw unavailable();
|
|
22526
22797
|
return await send("", {
|
|
@@ -22538,7 +22809,7 @@ var files = {
|
|
|
22538
22809
|
async enrich(input) {
|
|
22539
22810
|
const context = await resolveFilesContext();
|
|
22540
22811
|
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some((key) => !["file", "name", "content", "mediaType", "replace"].includes(key)) || typeof input.content !== "string" && !(input.content instanceof Uint8Array))
|
|
22541
|
-
throw
|
|
22812
|
+
throw invalid2();
|
|
22542
22813
|
const path = `${idPath(input.file)}/enrichments`;
|
|
22543
22814
|
if (typeof input.content === "string" ? input.content.length > MAX_BYTES : input.content.byteLength > MAX_BYTES)
|
|
22544
22815
|
throw new FileOperationError("request_too_large", 413);
|
|
@@ -22560,7 +22831,7 @@ var files = {
|
|
|
22560
22831
|
}, MAX_BYTES);
|
|
22561
22832
|
const header = encodeURIComponent(JSON.stringify(metadata));
|
|
22562
22833
|
if (new TextEncoder().encode(header).byteLength > METADATA_BYTES)
|
|
22563
|
-
throw
|
|
22834
|
+
throw invalid2();
|
|
22564
22835
|
const result2 = await send(path, { method: "POST", headers: {
|
|
22565
22836
|
"content-type": "application/octet-stream",
|
|
22566
22837
|
"x-oddington-enrichment": header
|
|
@@ -22575,14 +22846,204 @@ var files = {
|
|
|
22575
22846
|
},
|
|
22576
22847
|
read
|
|
22577
22848
|
};
|
|
22849
|
+
// src/app-context.ts
|
|
22850
|
+
var sessionKey = "_os.app.session";
|
|
22851
|
+
|
|
22852
|
+
class AppResponseReadError extends Error {
|
|
22853
|
+
}
|
|
22854
|
+
async function appResponse(response, maximum, signal) {
|
|
22855
|
+
if (signal.aborted || !response.body || response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() !== "application/json")
|
|
22856
|
+
throw new Error;
|
|
22857
|
+
const reader = response.body.getReader();
|
|
22858
|
+
const abort = () => {
|
|
22859
|
+
reader.cancel().catch(() => {});
|
|
22860
|
+
};
|
|
22861
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
22862
|
+
let bytes = 0, text3 = "";
|
|
22863
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
22864
|
+
try {
|
|
22865
|
+
while (true) {
|
|
22866
|
+
let chunk;
|
|
22867
|
+
try {
|
|
22868
|
+
chunk = await reader.read();
|
|
22869
|
+
} catch {
|
|
22870
|
+
throw new AppResponseReadError;
|
|
22871
|
+
}
|
|
22872
|
+
if (signal.aborted)
|
|
22873
|
+
throw new Error;
|
|
22874
|
+
if (chunk.done)
|
|
22875
|
+
return JSON.parse(text3 + decoder.decode());
|
|
22876
|
+
bytes += chunk.value.byteLength;
|
|
22877
|
+
if (bytes > maximum) {
|
|
22878
|
+
abort();
|
|
22879
|
+
throw new Error;
|
|
22880
|
+
}
|
|
22881
|
+
text3 += decoder.decode(chunk.value, { stream: true });
|
|
22882
|
+
}
|
|
22883
|
+
} finally {
|
|
22884
|
+
signal.removeEventListener("abort", abort);
|
|
22885
|
+
reader.releaseLock();
|
|
22886
|
+
}
|
|
22887
|
+
}
|
|
22888
|
+
function isAppOrigin(value) {
|
|
22889
|
+
try {
|
|
22890
|
+
const url = new URL(value);
|
|
22891
|
+
return url.protocol === "http:" && url.hostname === "127.0.0.1" && Boolean(url.port) && url.port !== "0" && url.origin === value;
|
|
22892
|
+
} catch {
|
|
22893
|
+
return false;
|
|
22894
|
+
}
|
|
22895
|
+
}
|
|
22896
|
+
function appContext(origin, active2) {
|
|
22897
|
+
let binding;
|
|
22898
|
+
let credential;
|
|
22899
|
+
let denied = false;
|
|
22900
|
+
const controller = new AbortController;
|
|
22901
|
+
let expiry;
|
|
22902
|
+
const invalidate = () => {
|
|
22903
|
+
denied = true;
|
|
22904
|
+
controller.abort();
|
|
22905
|
+
clearTimeout(expiry);
|
|
22906
|
+
clearInterval(monitor);
|
|
22907
|
+
try {
|
|
22908
|
+
if (active2() && globalThis.location.origin === origin && (!credential || globalThis.localStorage.getItem(sessionKey) === credential)) {
|
|
22909
|
+
globalThis.localStorage.removeItem(sessionKey);
|
|
22910
|
+
}
|
|
22911
|
+
} catch {}
|
|
22912
|
+
};
|
|
22913
|
+
const current = () => {
|
|
22914
|
+
try {
|
|
22915
|
+
return !denied && active2() && globalThis.location.origin === origin && globalThis.localStorage.getItem(sessionKey) === credential && (!binding || binding.expiresAt > Date.now());
|
|
22916
|
+
} catch {
|
|
22917
|
+
return false;
|
|
22918
|
+
}
|
|
22919
|
+
};
|
|
22920
|
+
const monitor = setInterval(() => {
|
|
22921
|
+
if (credential && !current())
|
|
22922
|
+
invalidate();
|
|
22923
|
+
}, 100);
|
|
22924
|
+
const dispose = () => {
|
|
22925
|
+
controller.abort();
|
|
22926
|
+
clearTimeout(expiry);
|
|
22927
|
+
clearInterval(monitor);
|
|
22928
|
+
};
|
|
22929
|
+
async function requestData(operation2, input) {
|
|
22930
|
+
try {
|
|
22931
|
+
if (operation2 !== "data/query" || !current())
|
|
22932
|
+
throw new Error;
|
|
22933
|
+
const url = `${origin}/_os/app/data`;
|
|
22934
|
+
const response = await fetch(url, {
|
|
22935
|
+
method: "POST",
|
|
22936
|
+
credentials: "omit",
|
|
22937
|
+
redirect: "error",
|
|
22938
|
+
cache: "no-store",
|
|
22939
|
+
referrerPolicy: "no-referrer",
|
|
22940
|
+
signal: controller.signal,
|
|
22941
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${credential}` },
|
|
22942
|
+
body: JSON.stringify(input)
|
|
22943
|
+
});
|
|
22944
|
+
if (!current() || response.redirected || response.url && response.url !== url)
|
|
22945
|
+
throw new Error;
|
|
22946
|
+
if (response.status === 401 || response.status === 403) {
|
|
22947
|
+
invalidate();
|
|
22948
|
+
throw new DataOperationError("access_denied");
|
|
22949
|
+
}
|
|
22950
|
+
const result2 = await appResponse(response, Number.MAX_SAFE_INTEGER, controller.signal);
|
|
22951
|
+
if (!current())
|
|
22952
|
+
throw new Error;
|
|
22953
|
+
if (!response.ok)
|
|
22954
|
+
throw dataTransportError(response.status, result2);
|
|
22955
|
+
return result2;
|
|
22956
|
+
} catch (error) {
|
|
22957
|
+
if (error instanceof DataOperationError)
|
|
22958
|
+
throw error;
|
|
22959
|
+
if (!current() || controller.signal.aborted)
|
|
22960
|
+
throw new DataOperationError("context_unavailable");
|
|
22961
|
+
throw new DataOperationError("unavailable", true);
|
|
22962
|
+
}
|
|
22963
|
+
}
|
|
22964
|
+
async function requestRoutine(key, suffix, init = {}) {
|
|
22965
|
+
if (!current()) {
|
|
22966
|
+
invalidate();
|
|
22967
|
+
throw new Error("Local app context unavailable.");
|
|
22968
|
+
}
|
|
22969
|
+
const url = `${origin}/_os/app/routines/${encodeURIComponent(key)}/${suffix}`;
|
|
22970
|
+
const response = await fetch(url, {
|
|
22971
|
+
...init,
|
|
22972
|
+
credentials: "omit",
|
|
22973
|
+
redirect: "error",
|
|
22974
|
+
cache: "no-store",
|
|
22975
|
+
referrerPolicy: "no-referrer",
|
|
22976
|
+
signal: controller.signal,
|
|
22977
|
+
headers: { ...init.body === undefined ? {} : { "content-type": "application/json" }, authorization: `Bearer ${credential}` }
|
|
22978
|
+
});
|
|
22979
|
+
if (!current() || response.redirected || response.url && response.url !== url) {
|
|
22980
|
+
invalidate();
|
|
22981
|
+
throw new Error("Local app context unavailable.");
|
|
22982
|
+
}
|
|
22983
|
+
if (response.status === 401 || response.status === 403)
|
|
22984
|
+
invalidate();
|
|
22985
|
+
return response;
|
|
22986
|
+
}
|
|
22987
|
+
const resolve = async () => {
|
|
22988
|
+
try {
|
|
22989
|
+
if (denied || !active2() || globalThis.location.origin !== origin)
|
|
22990
|
+
throw new Error;
|
|
22991
|
+
const stored = globalThis.localStorage.getItem(sessionKey);
|
|
22992
|
+
if (!stored || !/^[A-Za-z0-9_-]{43}$/.test(stored) || credential && stored !== credential)
|
|
22993
|
+
throw new Error;
|
|
22994
|
+
credential = stored;
|
|
22995
|
+
if (!current())
|
|
22996
|
+
throw new Error;
|
|
22997
|
+
const response = await fetch(`${origin}/_os/app/context`, {
|
|
22998
|
+
credentials: "omit",
|
|
22999
|
+
redirect: "error",
|
|
23000
|
+
referrerPolicy: "no-referrer",
|
|
23001
|
+
headers: { authorization: `Bearer ${credential}` },
|
|
23002
|
+
signal: controller.signal
|
|
23003
|
+
});
|
|
23004
|
+
if (!response.ok || response.redirected || response.url && response.url !== `${origin}/_os/app/context` || !response.headers.get("content-type")?.startsWith("application/json"))
|
|
23005
|
+
throw new Error;
|
|
23006
|
+
const value = await appResponse(response, 4096, controller.signal);
|
|
23007
|
+
if (!validBinding(value) || !current() || value.expiresAt <= Date.now() || value.expiresAt > Date.now() + 600000 || binding && (value.appId !== binding.appId || value.memberId !== binding.memberId || value.workspace !== binding.workspace || value.expiresAt > binding.expiresAt))
|
|
23008
|
+
throw new Error;
|
|
23009
|
+
binding = { ...value };
|
|
23010
|
+
clearTimeout(expiry);
|
|
23011
|
+
expiry = setTimeout(invalidate, binding.expiresAt - Date.now());
|
|
23012
|
+
return {
|
|
23013
|
+
kind: "local",
|
|
23014
|
+
...binding,
|
|
23015
|
+
isCurrent: current,
|
|
23016
|
+
signal: controller.signal,
|
|
23017
|
+
invalidate,
|
|
23018
|
+
requestRoutine,
|
|
23019
|
+
requestData,
|
|
23020
|
+
requestAvailability: (key) => requestRoutine(key, "availability", { method: "GET" })
|
|
23021
|
+
};
|
|
23022
|
+
} catch {
|
|
23023
|
+
invalidate();
|
|
23024
|
+
throw new Error("Local app context unavailable.");
|
|
23025
|
+
}
|
|
23026
|
+
};
|
|
23027
|
+
return { resolve, invalidate, dispose };
|
|
23028
|
+
}
|
|
23029
|
+
function validBinding(value) {
|
|
23030
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).sort().join(",") !== "appId,expiresAt,memberId,workspace")
|
|
23031
|
+
return false;
|
|
23032
|
+
const binding = value;
|
|
23033
|
+
return typeof binding.appId === "string" && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(binding.appId) && typeof binding.workspace === "string" && /^[a-z0-9][a-z0-9-]{0,62}$/.test(binding.workspace) && typeof binding.memberId === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(binding.memberId) && typeof binding.expiresAt === "number" && Number.isFinite(binding.expiresAt);
|
|
23034
|
+
}
|
|
23035
|
+
|
|
22578
23036
|
// src/os.ts
|
|
22579
23037
|
var installedDispose;
|
|
22580
23038
|
function init({ auth }) {
|
|
22581
23039
|
installedDispose?.();
|
|
22582
23040
|
let endpoint;
|
|
22583
23041
|
let workspace;
|
|
23042
|
+
let localOrigin;
|
|
22584
23043
|
try {
|
|
22585
23044
|
const url = new URL(globalThis.location.origin);
|
|
23045
|
+
if (isAppOrigin(globalThis.location.origin))
|
|
23046
|
+
localOrigin = url.origin;
|
|
22586
23047
|
const slug = url.hostname.endsWith(".oddington.ai") ? url.hostname.slice(0, -".oddington.ai".length) : "";
|
|
22587
23048
|
if (url.protocol === "https:" && !url.port && !url.username && !url.password && !url.search && !url.hash && url.pathname === "/" && /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(slug) && slug !== "auth") {
|
|
22588
23049
|
endpoint = url.origin;
|
|
@@ -22592,18 +23053,23 @@ function init({ auth }) {
|
|
|
22592
23053
|
let active2 = true;
|
|
22593
23054
|
let revision = 0;
|
|
22594
23055
|
let person;
|
|
23056
|
+
const local = localOrigin ? appContext(localOrigin, () => active2) : undefined;
|
|
22595
23057
|
const { data: { subscription } } = auth.onAuthStateChange((event, session) => {
|
|
22596
23058
|
const next = session?.user.id ?? null;
|
|
22597
|
-
if (event === "SIGNED_OUT" || person !== undefined && next !== person)
|
|
23059
|
+
if (event === "SIGNED_OUT" || person !== undefined && next !== person) {
|
|
22598
23060
|
revision++;
|
|
23061
|
+
local?.invalidate();
|
|
23062
|
+
}
|
|
22599
23063
|
person = next;
|
|
22600
23064
|
});
|
|
22601
23065
|
const resolve = async () => {
|
|
22602
|
-
if (
|
|
23066
|
+
if (local)
|
|
23067
|
+
return local.resolve();
|
|
23068
|
+
if (!active2 || !endpoint || !workspace || globalThis.location.origin !== endpoint)
|
|
22603
23069
|
throw new Error("Hosted Data context unavailable.");
|
|
22604
23070
|
const started = revision;
|
|
22605
23071
|
const { data: { session }, error } = await auth.getSession();
|
|
22606
|
-
if (!active2 || started !== revision || error || !session || person !== undefined && person !== session.user.id) {
|
|
23072
|
+
if (!active2 || globalThis.location.origin !== endpoint || started !== revision || error || !session || person !== undefined && person !== session.user.id) {
|
|
22607
23073
|
throw new Error("Hosted Data context unavailable.");
|
|
22608
23074
|
}
|
|
22609
23075
|
const expiresAt = (session.expires_at ?? 0) * 1000;
|
|
@@ -22616,7 +23082,7 @@ function init({ auth }) {
|
|
|
22616
23082
|
endpoint,
|
|
22617
23083
|
accessToken: session.access_token,
|
|
22618
23084
|
expiresAt,
|
|
22619
|
-
isCurrent: () => active2 && revision === started && person === session.user.id
|
|
23085
|
+
isCurrent: () => active2 && globalThis.location.origin === endpoint && revision === started && person === session.user.id
|
|
22620
23086
|
};
|
|
22621
23087
|
};
|
|
22622
23088
|
const uninstall = installMemberContext(resolve);
|
|
@@ -22624,6 +23090,7 @@ function init({ auth }) {
|
|
|
22624
23090
|
if (!active2)
|
|
22625
23091
|
return;
|
|
22626
23092
|
active2 = false;
|
|
23093
|
+
local?.dispose();
|
|
22627
23094
|
revision++;
|
|
22628
23095
|
subscription.unsubscribe();
|
|
22629
23096
|
uninstall();
|
|
@@ -22633,6 +23100,611 @@ function init({ auth }) {
|
|
|
22633
23100
|
installedDispose = dispose;
|
|
22634
23101
|
}
|
|
22635
23102
|
var os = { init };
|
|
23103
|
+
// src/app-routine-browser.ts
|
|
23104
|
+
var identifier = /^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/;
|
|
23105
|
+
var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
23106
|
+
var isReason = (value) => value === "authority_unavailable" || value === "execution_unavailable" || value === "invalid_input";
|
|
23107
|
+
|
|
23108
|
+
class AppRoutineError extends Error {
|
|
23109
|
+
reason;
|
|
23110
|
+
constructor(reason) {
|
|
23111
|
+
super(reason);
|
|
23112
|
+
this.reason = reason;
|
|
23113
|
+
this.name = "AppRoutineError";
|
|
23114
|
+
}
|
|
23115
|
+
}
|
|
23116
|
+
function fail3(reason) {
|
|
23117
|
+
throw new AppRoutineError(reason);
|
|
23118
|
+
}
|
|
23119
|
+
function object3(value) {
|
|
23120
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
23121
|
+
}
|
|
23122
|
+
function keys3(value, expected) {
|
|
23123
|
+
return Object.keys(value).sort().join(",") === expected;
|
|
23124
|
+
}
|
|
23125
|
+
function current(context) {
|
|
23126
|
+
if (!context.isCurrent() || context.signal.aborted)
|
|
23127
|
+
fail3("authority_unavailable");
|
|
23128
|
+
}
|
|
23129
|
+
async function body(context, response, maximum) {
|
|
23130
|
+
try {
|
|
23131
|
+
const value = await appResponse(response, maximum, context.signal);
|
|
23132
|
+
current(context);
|
|
23133
|
+
if (!response.ok) {
|
|
23134
|
+
if (object3(value) && keys3(value, "error") && isReason(value.error)) {
|
|
23135
|
+
if (value.error === "authority_unavailable")
|
|
23136
|
+
context.invalidate();
|
|
23137
|
+
fail3(value.error);
|
|
23138
|
+
}
|
|
23139
|
+
fail3("authority_unavailable");
|
|
23140
|
+
}
|
|
23141
|
+
return value;
|
|
23142
|
+
} catch (error) {
|
|
23143
|
+
current(context);
|
|
23144
|
+
if (error instanceof AppResponseReadError)
|
|
23145
|
+
throw error;
|
|
23146
|
+
if (error instanceof AppRoutineError)
|
|
23147
|
+
throw error;
|
|
23148
|
+
return fail3("execution_unavailable");
|
|
23149
|
+
}
|
|
23150
|
+
}
|
|
23151
|
+
function descriptor(value, key) {
|
|
23152
|
+
if (!object3(value) || !keys3(value, "after,key,routine,runId") || value.key !== key || typeof value.runId !== "string" || !uuid.test(value.runId) || value.after !== 0 || typeof value.routine !== "string" || !identifier.test(value.routine))
|
|
23153
|
+
fail3("execution_unavailable");
|
|
23154
|
+
return value;
|
|
23155
|
+
}
|
|
23156
|
+
function safeValue(value, depth = 0) {
|
|
23157
|
+
if (depth > 32)
|
|
23158
|
+
return false;
|
|
23159
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
23160
|
+
return true;
|
|
23161
|
+
if (typeof value === "number")
|
|
23162
|
+
return Number.isFinite(value);
|
|
23163
|
+
if (Array.isArray(value))
|
|
23164
|
+
return value.every((item) => safeValue(item, depth + 1));
|
|
23165
|
+
return object3(value) && Object.entries(value).every(([key, item]) => !["__proto__", "constructor", "prototype"].includes(key) && safeValue(item, depth + 1));
|
|
23166
|
+
}
|
|
23167
|
+
function event(value, run, steps) {
|
|
23168
|
+
if (!object3(value) || value.runId !== run.runId || value.key !== run.key || value.routine !== run.routine || !Number.isSafeInteger(value.sequence) || value.sequence < 1 || new TextEncoder().encode(JSON.stringify(value)).byteLength > 16 * 1024)
|
|
23169
|
+
fail3("execution_unavailable");
|
|
23170
|
+
const common = "key,routine,runId,sequence,";
|
|
23171
|
+
if (value.type === "started" && keys3(value, common + "type") && value.sequence === 1)
|
|
23172
|
+
return { type: "started" };
|
|
23173
|
+
if (value.type === "step" && typeof value.id === "string" && identifier.test(value.id) && (!steps || steps.includes(value.id)) && keys3(value, "id," + common + (Object.hasOwn(value, "summary") ? "summary,type" : "type")) && (!Object.hasOwn(value, "summary") || safeValue(value.summary))) {
|
|
23174
|
+
return {
|
|
23175
|
+
type: "step",
|
|
23176
|
+
id: value.id,
|
|
23177
|
+
...Object.hasOwn(value, "summary") ? { summary: value.summary } : {}
|
|
23178
|
+
};
|
|
23179
|
+
}
|
|
23180
|
+
if (value.type === "finished") {
|
|
23181
|
+
if (value.state === "succeeded" && keys3(value, "key," + (Object.hasOwn(value, "result") ? "result," : "") + "routine,runId,sequence,state,type") && (!Object.hasOwn(value, "result") || safeValue(value.result))) {
|
|
23182
|
+
return {
|
|
23183
|
+
type: "finished",
|
|
23184
|
+
state: "succeeded",
|
|
23185
|
+
...Object.hasOwn(value, "result") ? { result: value.result } : {}
|
|
23186
|
+
};
|
|
23187
|
+
}
|
|
23188
|
+
if (value.state === "failed" && value.error === "execution_failed" && keys3(value, "error," + common + "state,type")) {
|
|
23189
|
+
return { type: "finished", state: "failed", error: "execution_failed" };
|
|
23190
|
+
}
|
|
23191
|
+
if (value.state === "cancelled" && keys3(value, common + "state,type"))
|
|
23192
|
+
return { type: "finished", state: "cancelled" };
|
|
23193
|
+
}
|
|
23194
|
+
return fail3("execution_unavailable");
|
|
23195
|
+
}
|
|
23196
|
+
async function pause(context, delay) {
|
|
23197
|
+
current(context);
|
|
23198
|
+
await new Promise((resolve, reject) => {
|
|
23199
|
+
const abort = () => {
|
|
23200
|
+
clearTimeout(timer);
|
|
23201
|
+
reject(new AppRoutineError("authority_unavailable"));
|
|
23202
|
+
};
|
|
23203
|
+
const timer = setTimeout(() => {
|
|
23204
|
+
context.signal.removeEventListener("abort", abort);
|
|
23205
|
+
resolve();
|
|
23206
|
+
}, delay);
|
|
23207
|
+
context.signal.addEventListener("abort", abort, { once: true });
|
|
23208
|
+
});
|
|
23209
|
+
current(context);
|
|
23210
|
+
}
|
|
23211
|
+
function handle(context, run, steps) {
|
|
23212
|
+
return Object.freeze({
|
|
23213
|
+
async* events(...args) {
|
|
23214
|
+
if (args.length)
|
|
23215
|
+
fail3("invalid_input");
|
|
23216
|
+
let cursor = 0, terminal = false, delay = 100, retainedBytes = 0;
|
|
23217
|
+
const seen = [];
|
|
23218
|
+
while (!terminal) {
|
|
23219
|
+
current(context);
|
|
23220
|
+
let response;
|
|
23221
|
+
try {
|
|
23222
|
+
response = await context.requestRoutine(run.key, `runs/${run.runId}/events?after=${cursor}`);
|
|
23223
|
+
} catch {
|
|
23224
|
+
current(context);
|
|
23225
|
+
await pause(context, delay);
|
|
23226
|
+
delay = Math.min(delay * 2, 2000);
|
|
23227
|
+
continue;
|
|
23228
|
+
}
|
|
23229
|
+
if (response.status >= 500) {
|
|
23230
|
+
await response.body?.cancel();
|
|
23231
|
+
await pause(context, delay);
|
|
23232
|
+
delay = Math.min(delay * 2, 2000);
|
|
23233
|
+
continue;
|
|
23234
|
+
}
|
|
23235
|
+
let value;
|
|
23236
|
+
try {
|
|
23237
|
+
value = await body(context, response, 80 * 1024);
|
|
23238
|
+
} catch (error) {
|
|
23239
|
+
if (!(error instanceof AppResponseReadError))
|
|
23240
|
+
throw error;
|
|
23241
|
+
await pause(context, delay);
|
|
23242
|
+
delay = Math.min(delay * 2, 2000);
|
|
23243
|
+
continue;
|
|
23244
|
+
}
|
|
23245
|
+
if (!object3(value) || !keys3(value, "after,events,terminal") || !Array.isArray(value.events) || value.events.length > 256 || typeof value.terminal !== "boolean" || !Number.isSafeInteger(value.after))
|
|
23246
|
+
fail3("execution_unavailable");
|
|
23247
|
+
const delivery = [];
|
|
23248
|
+
for (const raw of value.events) {
|
|
23249
|
+
const publicEvent = event(raw, run, steps);
|
|
23250
|
+
const encoded = JSON.stringify(raw);
|
|
23251
|
+
const sequence = raw.sequence;
|
|
23252
|
+
if (sequence <= cursor) {
|
|
23253
|
+
if (seen[sequence - 1] !== encoded)
|
|
23254
|
+
fail3("execution_unavailable");
|
|
23255
|
+
continue;
|
|
23256
|
+
}
|
|
23257
|
+
if (terminal || sequence !== cursor + 1 || sequence > 256 || (cursor === 0 ? publicEvent.type !== "started" : publicEvent.type === "started"))
|
|
23258
|
+
fail3("execution_unavailable");
|
|
23259
|
+
retainedBytes += new TextEncoder().encode(encoded).byteLength;
|
|
23260
|
+
if (retainedBytes > 1024 * 1024)
|
|
23261
|
+
fail3("execution_unavailable");
|
|
23262
|
+
seen.push(encoded);
|
|
23263
|
+
cursor = sequence;
|
|
23264
|
+
terminal = publicEvent.type === "finished";
|
|
23265
|
+
delivery.push(publicEvent);
|
|
23266
|
+
}
|
|
23267
|
+
if (value.after !== cursor || value.terminal !== terminal)
|
|
23268
|
+
fail3("execution_unavailable");
|
|
23269
|
+
for (const item of delivery) {
|
|
23270
|
+
current(context);
|
|
23271
|
+
yield item;
|
|
23272
|
+
}
|
|
23273
|
+
delay = 100;
|
|
23274
|
+
if (!terminal)
|
|
23275
|
+
await pause(context, delivery.length ? 100 : 250);
|
|
23276
|
+
}
|
|
23277
|
+
},
|
|
23278
|
+
async cancel(...args) {
|
|
23279
|
+
if (args.length)
|
|
23280
|
+
fail3("invalid_input");
|
|
23281
|
+
try {
|
|
23282
|
+
const value = await body(context, await context.requestRoutine(run.key, `runs/${run.runId}/cancel`, { method: "POST" }), 1024);
|
|
23283
|
+
if (!object3(value) || !keys3(value, "cancelled") || value.cancelled !== true)
|
|
23284
|
+
fail3("execution_unavailable");
|
|
23285
|
+
} catch (error) {
|
|
23286
|
+
current(context);
|
|
23287
|
+
if (error instanceof AppRoutineError)
|
|
23288
|
+
throw error;
|
|
23289
|
+
fail3("execution_unavailable");
|
|
23290
|
+
}
|
|
23291
|
+
}
|
|
23292
|
+
});
|
|
23293
|
+
}
|
|
23294
|
+
async function appRoutineOperation(key, input, recover) {
|
|
23295
|
+
let context;
|
|
23296
|
+
try {
|
|
23297
|
+
if (!identifier.test(key))
|
|
23298
|
+
fail3("authority_unavailable");
|
|
23299
|
+
const resolved = await resolveAppContext();
|
|
23300
|
+
if (resolved.kind !== "local")
|
|
23301
|
+
fail3("execution_unavailable");
|
|
23302
|
+
context = resolved;
|
|
23303
|
+
if (recover) {
|
|
23304
|
+
const value2 = await body(context, await context.requestRoutine(key, "runs"), 16 * 1024);
|
|
23305
|
+
if (!object3(value2) || !keys3(value2, "runs") || !Array.isArray(value2.runs) || value2.runs.length > 20)
|
|
23306
|
+
fail3("execution_unavailable");
|
|
23307
|
+
const runs = value2.runs.map((run) => descriptor(run, key));
|
|
23308
|
+
if (new Set(runs.map((run) => run.runId)).size !== runs.length || new Set(runs.map((run) => run.routine)).size > 1)
|
|
23309
|
+
fail3("execution_unavailable");
|
|
23310
|
+
return runs.map((run) => handle(resolved, run));
|
|
23311
|
+
}
|
|
23312
|
+
const available = await body(context, await context.requestAvailability(key), 16 * 1024);
|
|
23313
|
+
if (object3(available) && keys3(available, "available,reason") && available.available === false && isReason(available.reason))
|
|
23314
|
+
fail3(available.reason);
|
|
23315
|
+
if (!object3(available) || !keys3(available, "available,steps") || available.available !== true || !Array.isArray(available.steps) || available.steps.length < 1 || available.steps.length > 64 || !available.steps.every((step) => typeof step === "string" && identifier.test(step)) || new Set(available.steps).size !== available.steps.length)
|
|
23316
|
+
fail3("execution_unavailable");
|
|
23317
|
+
const steps = [...available.steps];
|
|
23318
|
+
let encoded;
|
|
23319
|
+
try {
|
|
23320
|
+
encoded = JSON.stringify(input);
|
|
23321
|
+
if (encoded === undefined || new TextEncoder().encode(encoded).byteLength > 16 * 1024)
|
|
23322
|
+
fail3("invalid_input");
|
|
23323
|
+
} catch {
|
|
23324
|
+
fail3("invalid_input");
|
|
23325
|
+
}
|
|
23326
|
+
const value = await body(context, await context.requestRoutine(key, "runs", {
|
|
23327
|
+
method: "POST",
|
|
23328
|
+
body: `{"input":${encoded}}`
|
|
23329
|
+
}), 16 * 1024);
|
|
23330
|
+
return handle(context, descriptor(value, key), steps);
|
|
23331
|
+
} catch (error) {
|
|
23332
|
+
if (context)
|
|
23333
|
+
current(context);
|
|
23334
|
+
if (error instanceof AppRoutineError)
|
|
23335
|
+
throw error;
|
|
23336
|
+
return fail3(context ? "execution_unavailable" : "authority_unavailable");
|
|
23337
|
+
}
|
|
23338
|
+
}
|
|
23339
|
+
|
|
23340
|
+
// src/app.ts
|
|
23341
|
+
var authorityUnavailable = () => ({ available: false, reason: "authority_unavailable" });
|
|
23342
|
+
var MAX_RESPONSE_BYTES = 16 * 1024;
|
|
23343
|
+
async function availability(key) {
|
|
23344
|
+
try {
|
|
23345
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/.test(key))
|
|
23346
|
+
return authorityUnavailable();
|
|
23347
|
+
const context = await resolveAppContext();
|
|
23348
|
+
if (context.kind !== "local")
|
|
23349
|
+
return { available: false, reason: "execution_unavailable" };
|
|
23350
|
+
const response = await context.requestAvailability(key);
|
|
23351
|
+
if (!response.ok || response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() !== "application/json") {
|
|
23352
|
+
return authorityUnavailable();
|
|
23353
|
+
}
|
|
23354
|
+
const value = await appResponse(response, MAX_RESPONSE_BYTES, context.signal);
|
|
23355
|
+
if (!context.isCurrent())
|
|
23356
|
+
return authorityUnavailable();
|
|
23357
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
23358
|
+
return authorityUnavailable();
|
|
23359
|
+
const result2 = value;
|
|
23360
|
+
if (result2.available === false && Object.keys(result2).sort().join(",") === "available,reason" && (result2.reason === "authority_unavailable" || result2.reason === "execution_unavailable")) {
|
|
23361
|
+
return { available: false, reason: result2.reason };
|
|
23362
|
+
}
|
|
23363
|
+
if (result2.available !== true || Object.keys(result2).sort().join(",") !== "available,steps" || !Array.isArray(result2.steps) || result2.steps.length < 1 || result2.steps.length > 64 || !result2.steps.every((step) => typeof step === "string" && /^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/.test(step)) || new Set(result2.steps).size !== result2.steps.length)
|
|
23364
|
+
return authorityUnavailable();
|
|
23365
|
+
return { available: true, steps: [...result2.steps] };
|
|
23366
|
+
} catch {
|
|
23367
|
+
return authorityUnavailable();
|
|
23368
|
+
}
|
|
23369
|
+
}
|
|
23370
|
+
var app = Object.freeze({ routines: new Proxy(Object.create(null), {
|
|
23371
|
+
get(_target, key) {
|
|
23372
|
+
if (typeof key !== "string")
|
|
23373
|
+
return;
|
|
23374
|
+
return Object.freeze({
|
|
23375
|
+
availability: (...args) => args.length ? Promise.resolve(authorityUnavailable()) : availability(key),
|
|
23376
|
+
run: (...args) => args.length === 1 ? appRoutineOperation(key, args[0], false) : Promise.reject(new AppRoutineError("invalid_input")),
|
|
23377
|
+
recover: (...args) => args.length === 0 ? appRoutineOperation(key, undefined, true) : Promise.reject(new AppRoutineError("invalid_input"))
|
|
23378
|
+
});
|
|
23379
|
+
},
|
|
23380
|
+
set: () => false,
|
|
23381
|
+
defineProperty: () => false,
|
|
23382
|
+
deleteProperty: () => false
|
|
23383
|
+
}) });
|
|
23384
|
+
// ../../shared/app-routine-contract.ts
|
|
23385
|
+
class AppRoutineContractError extends Error {
|
|
23386
|
+
code;
|
|
23387
|
+
constructor(code) {
|
|
23388
|
+
super(code);
|
|
23389
|
+
this.code = code;
|
|
23390
|
+
}
|
|
23391
|
+
}
|
|
23392
|
+
var propertyName = /^[a-z][A-Za-z0-9]*(?![\s\S])/;
|
|
23393
|
+
var stepId = /^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/;
|
|
23394
|
+
var routineName = /^[a-z0-9][a-z0-9-]{0,62}(?![\s\S])/;
|
|
23395
|
+
var owns = (value, key) => Object.hasOwn(value, key);
|
|
23396
|
+
var invalidContract = () => {
|
|
23397
|
+
throw new AppRoutineContractError("invalid_contract");
|
|
23398
|
+
};
|
|
23399
|
+
var invalidValue = () => {
|
|
23400
|
+
throw new AppRoutineContractError("invalid_value");
|
|
23401
|
+
};
|
|
23402
|
+
function record2(value) {
|
|
23403
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
23404
|
+
}
|
|
23405
|
+
function fields3(value, required, optional = []) {
|
|
23406
|
+
return required.every((key) => owns(value, key)) && Object.keys(value).every((key) => required.includes(key) || optional.includes(key));
|
|
23407
|
+
}
|
|
23408
|
+
function denseArray(value) {
|
|
23409
|
+
return Array.isArray(value) && Object.keys(value).length === value.length && Array.from({ length: value.length }, (_, index) => owns(value, String(index))).every(Boolean);
|
|
23410
|
+
}
|
|
23411
|
+
function parseAppRoutineContract(value) {
|
|
23412
|
+
let properties = 0;
|
|
23413
|
+
function schema(value2, depth = 1) {
|
|
23414
|
+
if (depth > 8 || !record2(value2))
|
|
23415
|
+
return invalidContract();
|
|
23416
|
+
switch (value2.type) {
|
|
23417
|
+
case "object": {
|
|
23418
|
+
if (!fields3(value2, ["type", "properties", "additionalProperties"], ["required"]) || value2.additionalProperties !== false || !record2(value2.properties))
|
|
23419
|
+
return invalidContract();
|
|
23420
|
+
const entries = Object.entries(value2.properties);
|
|
23421
|
+
properties += entries.length;
|
|
23422
|
+
if (properties > 64 || entries.some(([key]) => !propertyName.test(key)))
|
|
23423
|
+
return invalidContract();
|
|
23424
|
+
let required;
|
|
23425
|
+
if (owns(value2, "required")) {
|
|
23426
|
+
if (!denseArray(value2.required) || value2.required.some((key) => typeof key !== "string" || !owns(value2.properties, key)) || new Set(value2.required).size !== value2.required.length)
|
|
23427
|
+
return invalidContract();
|
|
23428
|
+
required = [...value2.required];
|
|
23429
|
+
}
|
|
23430
|
+
return {
|
|
23431
|
+
type: "object",
|
|
23432
|
+
properties: Object.fromEntries(entries.map(([key, child]) => [key, schema(child, depth + 1)])),
|
|
23433
|
+
...required === undefined ? {} : { required },
|
|
23434
|
+
additionalProperties: false
|
|
23435
|
+
};
|
|
23436
|
+
}
|
|
23437
|
+
case "array":
|
|
23438
|
+
if (!fields3(value2, ["type", "items", "maxItems"]) || !Number.isSafeInteger(value2.maxItems) || value2.maxItems < 1 || value2.maxItems > 64)
|
|
23439
|
+
return invalidContract();
|
|
23440
|
+
return { type: "array", items: schema(value2.items, depth + 1), maxItems: value2.maxItems };
|
|
23441
|
+
case "boolean":
|
|
23442
|
+
case "file":
|
|
23443
|
+
if (!fields3(value2, ["type"]))
|
|
23444
|
+
return invalidContract();
|
|
23445
|
+
return { type: value2.type };
|
|
23446
|
+
case "string":
|
|
23447
|
+
if (!fields3(value2, ["type"], ["maxLength"]) || owns(value2, "maxLength") && (!Number.isSafeInteger(value2.maxLength) || value2.maxLength < 0 || value2.maxLength > 4096))
|
|
23448
|
+
return invalidContract();
|
|
23449
|
+
return { type: "string", ...owns(value2, "maxLength") ? { maxLength: value2.maxLength } : {} };
|
|
23450
|
+
case "integer":
|
|
23451
|
+
case "number": {
|
|
23452
|
+
const validNumber = value2.type === "integer" ? Number.isSafeInteger : Number.isFinite;
|
|
23453
|
+
if (!fields3(value2, ["type"], ["minimum", "maximum"]) || owns(value2, "minimum") && !validNumber(value2.minimum) || owns(value2, "maximum") && !validNumber(value2.maximum) || owns(value2, "minimum") && owns(value2, "maximum") && value2.minimum > value2.maximum)
|
|
23454
|
+
return invalidContract();
|
|
23455
|
+
return {
|
|
23456
|
+
type: value2.type,
|
|
23457
|
+
...owns(value2, "minimum") ? { minimum: value2.minimum } : {},
|
|
23458
|
+
...owns(value2, "maximum") ? { maximum: value2.maximum } : {}
|
|
23459
|
+
};
|
|
23460
|
+
}
|
|
23461
|
+
default:
|
|
23462
|
+
return invalidContract();
|
|
23463
|
+
}
|
|
23464
|
+
}
|
|
23465
|
+
if (!record2(value) || !fields3(value, ["routine", "input", "steps"], ["result"]) || typeof value.routine !== "string" || !routineName.test(value.routine) || !denseArray(value.steps) || value.steps.length < 1 || value.steps.length > 64)
|
|
23466
|
+
return invalidContract();
|
|
23467
|
+
const input = schema(value.input);
|
|
23468
|
+
const result2 = owns(value, "result") ? schema(value.result) : undefined;
|
|
23469
|
+
const ids = new Set;
|
|
23470
|
+
const steps = value.steps.map((step) => {
|
|
23471
|
+
if (!record2(step) || !fields3(step, ["id"], ["summary"]) || typeof step.id !== "string" || !stepId.test(step.id) || ids.has(step.id))
|
|
23472
|
+
return invalidContract();
|
|
23473
|
+
ids.add(step.id);
|
|
23474
|
+
return { id: step.id, ...owns(step, "summary") ? { summary: schema(step.summary) } : {} };
|
|
23475
|
+
});
|
|
23476
|
+
return { routine: value.routine, input, steps, ...result2 === undefined ? {} : { result: result2 } };
|
|
23477
|
+
}
|
|
23478
|
+
function jsonData(value, ancestors = new Set) {
|
|
23479
|
+
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))
|
|
23480
|
+
return;
|
|
23481
|
+
if (!record2(value) && !denseArray(value))
|
|
23482
|
+
return invalidValue();
|
|
23483
|
+
if (ancestors.has(value))
|
|
23484
|
+
return invalidValue();
|
|
23485
|
+
ancestors.add(value);
|
|
23486
|
+
for (const child of Object.values(value))
|
|
23487
|
+
jsonData(child, ancestors);
|
|
23488
|
+
ancestors.delete(value);
|
|
23489
|
+
}
|
|
23490
|
+
function validate(schema, value) {
|
|
23491
|
+
switch (schema.type) {
|
|
23492
|
+
case "object":
|
|
23493
|
+
if (!record2(value) || (schema.required ?? []).some((key) => !owns(value, key)) || Object.keys(value).some((key) => !owns(schema.properties, key)))
|
|
23494
|
+
return invalidValue();
|
|
23495
|
+
for (const [key, child] of Object.entries(value))
|
|
23496
|
+
validate(schema.properties[key], child);
|
|
23497
|
+
return;
|
|
23498
|
+
case "array":
|
|
23499
|
+
if (!denseArray(value) || value.length > schema.maxItems)
|
|
23500
|
+
return invalidValue();
|
|
23501
|
+
for (const child of value)
|
|
23502
|
+
validate(schema.items, child);
|
|
23503
|
+
return;
|
|
23504
|
+
case "boolean":
|
|
23505
|
+
if (typeof value !== "boolean")
|
|
23506
|
+
return invalidValue();
|
|
23507
|
+
return;
|
|
23508
|
+
case "string":
|
|
23509
|
+
if (typeof value !== "string" || Array.from(value).length > (schema.maxLength ?? 4096))
|
|
23510
|
+
return invalidValue();
|
|
23511
|
+
return;
|
|
23512
|
+
case "integer":
|
|
23513
|
+
case "number":
|
|
23514
|
+
if (typeof value !== "number" || !(schema.type === "integer" ? Number.isSafeInteger(value) : Number.isFinite(value)) || schema.minimum !== undefined && value < schema.minimum || schema.maximum !== undefined && value > schema.maximum)
|
|
23515
|
+
return invalidValue();
|
|
23516
|
+
return;
|
|
23517
|
+
case "file":
|
|
23518
|
+
try {
|
|
23519
|
+
jsonData(value);
|
|
23520
|
+
parseFileDescriptor(value);
|
|
23521
|
+
} catch {
|
|
23522
|
+
return invalidValue();
|
|
23523
|
+
}
|
|
23524
|
+
}
|
|
23525
|
+
}
|
|
23526
|
+
function boundedValue(schema, value) {
|
|
23527
|
+
validate(schema, value);
|
|
23528
|
+
if (new TextEncoder().encode(JSON.stringify(value)).byteLength > 16 * 1024)
|
|
23529
|
+
return invalidValue();
|
|
23530
|
+
}
|
|
23531
|
+
function validateAppRoutineInput(contract, value) {
|
|
23532
|
+
boundedValue(contract.input, value);
|
|
23533
|
+
}
|
|
23534
|
+
function validateAppRoutineResult(contract, value) {
|
|
23535
|
+
if (contract.result === undefined) {
|
|
23536
|
+
if (value !== undefined)
|
|
23537
|
+
return invalidValue();
|
|
23538
|
+
} else
|
|
23539
|
+
boundedValue(contract.result, value);
|
|
23540
|
+
}
|
|
23541
|
+
function validateAppRoutineStep(contract, id2, summary) {
|
|
23542
|
+
const step = contract.steps.find((step2) => step2.id === id2);
|
|
23543
|
+
if (!step)
|
|
23544
|
+
return invalidValue();
|
|
23545
|
+
if (step.summary === undefined) {
|
|
23546
|
+
if (summary !== undefined)
|
|
23547
|
+
return invalidValue();
|
|
23548
|
+
} else
|
|
23549
|
+
validate(step.summary, summary);
|
|
23550
|
+
}
|
|
23551
|
+
|
|
23552
|
+
// src/app-run.ts
|
|
23553
|
+
var LIMIT = 16 * 1024;
|
|
23554
|
+
var context;
|
|
23555
|
+
var unavailable2 = () => new Error("App routine reporting unavailable");
|
|
23556
|
+
function freeze(value) {
|
|
23557
|
+
if (value !== null && typeof value === "object") {
|
|
23558
|
+
for (const child of Object.values(value))
|
|
23559
|
+
freeze(child);
|
|
23560
|
+
Object.freeze(value);
|
|
23561
|
+
}
|
|
23562
|
+
return value;
|
|
23563
|
+
}
|
|
23564
|
+
if (typeof process !== "undefined" && process.env.ODDINGTON_APP_RUN !== undefined) {
|
|
23565
|
+
let fail4 = function() {
|
|
23566
|
+
broken = true;
|
|
23567
|
+
pending?.reject(unavailable2());
|
|
23568
|
+
pending = undefined;
|
|
23569
|
+
channel.destroy();
|
|
23570
|
+
}, report = function(value) {
|
|
23571
|
+
let frame;
|
|
23572
|
+
try {
|
|
23573
|
+
frame = JSON.stringify({ ...value, sequence: ++sequence });
|
|
23574
|
+
if (Buffer.byteLength(frame) > LIMIT)
|
|
23575
|
+
return rejected();
|
|
23576
|
+
} catch {
|
|
23577
|
+
return rejected();
|
|
23578
|
+
}
|
|
23579
|
+
const operation2 = queue.then(async () => {
|
|
23580
|
+
if (broken)
|
|
23581
|
+
throw unavailable2();
|
|
23582
|
+
await new Promise((resolve, reject) => {
|
|
23583
|
+
const timeout = setTimeout(fail4, 30000);
|
|
23584
|
+
pending = {
|
|
23585
|
+
sequence: JSON.parse(frame).sequence,
|
|
23586
|
+
resolve() {
|
|
23587
|
+
clearTimeout(timeout);
|
|
23588
|
+
resolve();
|
|
23589
|
+
},
|
|
23590
|
+
reject(error) {
|
|
23591
|
+
clearTimeout(timeout);
|
|
23592
|
+
reject(error);
|
|
23593
|
+
}
|
|
23594
|
+
};
|
|
23595
|
+
channel.ref();
|
|
23596
|
+
channel.write(`${frame}
|
|
23597
|
+
`, (error) => {
|
|
23598
|
+
if (error)
|
|
23599
|
+
fail4();
|
|
23600
|
+
});
|
|
23601
|
+
});
|
|
23602
|
+
});
|
|
23603
|
+
queue = operation2.catch(() => {});
|
|
23604
|
+
return operation2;
|
|
23605
|
+
}, rejected = function() {
|
|
23606
|
+
if (!broken)
|
|
23607
|
+
channel.end(`{"type":"invalid"}
|
|
23608
|
+
`);
|
|
23609
|
+
broken = true;
|
|
23610
|
+
pending?.reject(unavailable2());
|
|
23611
|
+
pending = undefined;
|
|
23612
|
+
return Promise.reject(unavailable2());
|
|
23613
|
+
};
|
|
23614
|
+
if (process.env.ODDINGTON_APP_RUN !== "1")
|
|
23615
|
+
throw unavailable2();
|
|
23616
|
+
const { readSync, closeSync } = await import("node:fs");
|
|
23617
|
+
const { Socket } = await import("node:net");
|
|
23618
|
+
let bootstrap;
|
|
23619
|
+
try {
|
|
23620
|
+
const chunks = [];
|
|
23621
|
+
let size = 0;
|
|
23622
|
+
for (;; ) {
|
|
23623
|
+
const bytes2 = new Uint8Array(4096);
|
|
23624
|
+
const count = readSync(4, bytes2, 0, bytes2.length, null);
|
|
23625
|
+
if (!count)
|
|
23626
|
+
break;
|
|
23627
|
+
size += count;
|
|
23628
|
+
if (size > 131072)
|
|
23629
|
+
throw unavailable2();
|
|
23630
|
+
chunks.push(bytes2.slice(0, count));
|
|
23631
|
+
}
|
|
23632
|
+
closeSync(4);
|
|
23633
|
+
const bytes = new Uint8Array(size);
|
|
23634
|
+
let offset = 0;
|
|
23635
|
+
for (const chunk of chunks) {
|
|
23636
|
+
bytes.set(chunk, offset);
|
|
23637
|
+
offset += chunk.length;
|
|
23638
|
+
}
|
|
23639
|
+
bootstrap = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
23640
|
+
if (!bootstrap || Object.keys(bootstrap).sort().join(",") !== "contract,input")
|
|
23641
|
+
throw unavailable2();
|
|
23642
|
+
} catch {
|
|
23643
|
+
throw unavailable2();
|
|
23644
|
+
}
|
|
23645
|
+
const contract = parseAppRoutineContract(bootstrap.contract);
|
|
23646
|
+
validateAppRoutineInput(contract, bootstrap.input);
|
|
23647
|
+
const input = freeze(bootstrap.input);
|
|
23648
|
+
const channel = new Socket({ fd: 3, readable: true, writable: true });
|
|
23649
|
+
channel.unref();
|
|
23650
|
+
let broken = false, finishing = false, sequence = 0;
|
|
23651
|
+
let pending;
|
|
23652
|
+
let buffer = "";
|
|
23653
|
+
channel.on("error", fail4);
|
|
23654
|
+
channel.on("close", fail4);
|
|
23655
|
+
channel.on("end", fail4);
|
|
23656
|
+
channel.on("data", (bytes) => {
|
|
23657
|
+
buffer += bytes.toString("utf8");
|
|
23658
|
+
if (Buffer.byteLength(buffer) > 1024)
|
|
23659
|
+
return fail4();
|
|
23660
|
+
const end = buffer.indexOf(`
|
|
23661
|
+
`);
|
|
23662
|
+
if (end < 0)
|
|
23663
|
+
return;
|
|
23664
|
+
try {
|
|
23665
|
+
const ack = JSON.parse(buffer.slice(0, end));
|
|
23666
|
+
if (end !== buffer.length - 1 || !pending || !ack || Object.keys(ack).sort().join(",") !== "accepted,sequence" || ack.sequence !== pending.sequence || ack.accepted !== true)
|
|
23667
|
+
return fail4();
|
|
23668
|
+
buffer = "";
|
|
23669
|
+
pending.resolve();
|
|
23670
|
+
pending = undefined;
|
|
23671
|
+
channel.unref();
|
|
23672
|
+
} catch {
|
|
23673
|
+
fail4();
|
|
23674
|
+
}
|
|
23675
|
+
});
|
|
23676
|
+
let queue = Promise.resolve();
|
|
23677
|
+
context = {
|
|
23678
|
+
input,
|
|
23679
|
+
step(id2, ...summary) {
|
|
23680
|
+
if (finishing || broken || summary.length > 1)
|
|
23681
|
+
return rejected();
|
|
23682
|
+
try {
|
|
23683
|
+
validateAppRoutineStep(contract, id2, summary[0]);
|
|
23684
|
+
} catch {
|
|
23685
|
+
return rejected();
|
|
23686
|
+
}
|
|
23687
|
+
return report({ type: "step", id: id2, ...summary.length ? { summary: summary[0] } : {} });
|
|
23688
|
+
},
|
|
23689
|
+
finish(...result2) {
|
|
23690
|
+
if (finishing || broken || result2.length > 1)
|
|
23691
|
+
return rejected();
|
|
23692
|
+
finishing = true;
|
|
23693
|
+
try {
|
|
23694
|
+
validateAppRoutineResult(contract, result2[0]);
|
|
23695
|
+
} catch {
|
|
23696
|
+
return rejected();
|
|
23697
|
+
}
|
|
23698
|
+
return report({ type: "finish", ...result2.length ? { result: result2[0] } : {} });
|
|
23699
|
+
}
|
|
23700
|
+
};
|
|
23701
|
+
Object.freeze(context);
|
|
23702
|
+
}
|
|
23703
|
+
var appRun = {
|
|
23704
|
+
current() {
|
|
23705
|
+
return context;
|
|
23706
|
+
}
|
|
23707
|
+
};
|
|
22636
23708
|
|
|
22637
23709
|
// src/index.ts
|
|
22638
23710
|
init_inbox_contract();
|
|
@@ -22657,13 +23729,13 @@ function routinePublicationClient(options = {}) {
|
|
|
22657
23729
|
} : async () => {
|
|
22658
23730
|
throw new Error("Member publication requires a host-supplied request");
|
|
22659
23731
|
});
|
|
22660
|
-
async function send2(operation2,
|
|
23732
|
+
async function send2(operation2, body2) {
|
|
22661
23733
|
if (local)
|
|
22662
|
-
return await local(operation2,
|
|
23734
|
+
return await local(operation2, body2);
|
|
22663
23735
|
const response = await request(`/api/cli/workspaces/${workspace}/inbox/${operation2}`, {
|
|
22664
23736
|
method: "POST",
|
|
22665
23737
|
headers: { "content-type": "application/json", ...headers },
|
|
22666
|
-
body: JSON.stringify(
|
|
23738
|
+
body: JSON.stringify(body2)
|
|
22667
23739
|
});
|
|
22668
23740
|
const result2 = await response.json();
|
|
22669
23741
|
if (!response.ok && operation2 === "records/update")
|
|
@@ -22673,11 +23745,11 @@ function routinePublicationClient(options = {}) {
|
|
|
22673
23745
|
return result2;
|
|
22674
23746
|
}
|
|
22675
23747
|
const transport = {
|
|
22676
|
-
async publish(
|
|
22677
|
-
return await send2("publish",
|
|
23748
|
+
async publish(body2) {
|
|
23749
|
+
return await send2("publish", body2);
|
|
22678
23750
|
},
|
|
22679
|
-
async resolve(
|
|
22680
|
-
await send2("resolve",
|
|
23751
|
+
async resolve(body2) {
|
|
23752
|
+
await send2("resolve", body2);
|
|
22681
23753
|
}
|
|
22682
23754
|
};
|
|
22683
23755
|
async function readRecords(input) {
|
|
@@ -22729,8 +23801,8 @@ function routinePublicationClient(options = {}) {
|
|
|
22729
23801
|
return await verifyInboxFile(bytes, validateInboxFile(result2));
|
|
22730
23802
|
}
|
|
22731
23803
|
},
|
|
22732
|
-
async check(
|
|
22733
|
-
await send2("check", { requestKey:
|
|
23804
|
+
async check(body2) {
|
|
23805
|
+
await send2("check", { requestKey: body2.requestKey, item: validatePublication(body2.item) });
|
|
22734
23806
|
}
|
|
22735
23807
|
};
|
|
22736
23808
|
}
|
|
@@ -22751,9 +23823,12 @@ export {
|
|
|
22751
23823
|
continueAsk,
|
|
22752
23824
|
connections,
|
|
22753
23825
|
asksBlock,
|
|
23826
|
+
appRun,
|
|
23827
|
+
app,
|
|
22754
23828
|
RoutineRecordWriteError,
|
|
22755
23829
|
InboxContractError,
|
|
22756
23830
|
FileOperationError,
|
|
22757
23831
|
DataOperationError,
|
|
23832
|
+
AppRoutineError,
|
|
22758
23833
|
AirtableOperationError
|
|
22759
23834
|
};
|