@wildo-ai/platform-config-lib 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/_unimplemented/soft-warn.d.ts +24 -49
- package/dist/esm/_unimplemented/soft-warn.d.ts.map +1 -1
- package/dist/esm/_unimplemented/soft-warn.js +24 -49
- package/dist/esm/_unimplemented/soft-warn.js.map +1 -1
- package/dist/esm/blueprint/anchored-region.d.ts.map +1 -1
- package/dist/esm/blueprint/anchored-region.js.map +1 -1
- package/dist/esm/blueprint/blueprint.schemas.d.ts +0 -89
- package/dist/esm/blueprint/blueprint.schemas.d.ts.map +1 -1
- package/dist/esm/blueprint/blueprint.schemas.js.map +1 -1
- package/dist/esm/bootstrap/application-backend-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/application-backend-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/application-creation-verification-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/application-creation-verification-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts +8 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js +15 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +10 -2
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +10 -2
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts +21 -0
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.js +25 -0
- package/dist/esm/bootstrap/platform-store-preconnect.js.map +1 -1
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.d.ts +80 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.d.ts.map +1 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.js +81 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.js.map +1 -0
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts +41 -9
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.js +77 -28
- package/dist/esm/bootstrap/runtime-backing-service-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.d.ts +117 -12
- package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.js +222 -23
- package/dist/esm/bootstrap/runtime-network-policy.js.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.d.ts +31 -4
- package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.js +43 -2
- package/dist/esm/bootstrap/runtime-network-topology.js.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts +40 -2
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.js +66 -3
- package/dist/esm/bootstrap/runtime-principal.contracts.js.map +1 -1
- package/dist/esm/bootstrap/runtime-response-integrity.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-response-integrity.js +3 -3
- package/dist/esm/bootstrap/runtime-response-integrity.js.map +1 -1
- package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-secret-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.js.map +1 -1
- package/dist/esm/bootstrap/wildo-owner-organization.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/wildo-owner-organization.contracts.js.map +1 -1
- package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts.map +1 -1
- package/dist/esm/canonical-json/rfc8785-canonical-json.js.map +1 -1
- package/dist/esm/config-authoring.entry.d.ts.map +1 -1
- package/dist/esm/config-authoring.entry.js.map +1 -1
- package/dist/esm/credentials/credential-generator.service.d.ts.map +1 -1
- package/dist/esm/credentials/credential-generator.service.js.map +1 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.d.ts +119 -0
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.js +109 -0
- package/dist/esm/key-management/application-legacy-envelope-key.contracts.js.map +1 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.d.ts +182 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.js +145 -0
- package/dist/esm/key-management/application-signing-key-rotation.contracts.js.map +1 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.d.ts +156 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.d.ts.map +1 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.js +617 -0
- package/dist/esm/key-management/approval-seal-manifested-copy.js.map +1 -0
- package/dist/esm/key-management/approval-seal-verifier.d.ts +114 -40
- package/dist/esm/key-management/approval-seal-verifier.d.ts.map +1 -1
- package/dist/esm/key-management/approval-seal-verifier.js +143 -12
- package/dist/esm/key-management/approval-seal-verifier.js.map +1 -1
- package/dist/esm/key-management/approval-seal.contracts.d.ts +12 -15
- package/dist/esm/key-management/approval-seal.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/approval-seal.contracts.js +20 -0
- package/dist/esm/key-management/approval-seal.contracts.js.map +1 -1
- package/dist/esm/key-management/data-key.contracts.d.ts +0 -2
- package/dist/esm/key-management/data-key.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/data-key.contracts.js.map +1 -1
- package/dist/esm/key-management/es256-jws.d.ts.map +1 -1
- package/dist/esm/key-management/es256-jws.js.map +1 -1
- package/dist/esm/key-management/key-provider.spi.d.ts +8 -1
- package/dist/esm/key-management/key-provider.spi.d.ts.map +1 -1
- package/dist/esm/key-management/key-provider.spi.js.map +1 -1
- package/dist/esm/key-management/keyring-rotation.contracts.d.ts +2 -12
- package/dist/esm/key-management/keyring-rotation.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/keyring-rotation.contracts.js +3 -3
- package/dist/esm/key-management/keyring-rotation.contracts.js.map +1 -1
- package/dist/esm/key-management/keyring-status.contracts.d.ts +0 -7
- package/dist/esm/key-management/keyring-status.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/keyring-status.contracts.js.map +1 -1
- package/dist/esm/key-management/pdf-incremental-update.d.ts +158 -0
- package/dist/esm/key-management/pdf-incremental-update.d.ts.map +1 -0
- package/dist/esm/key-management/pdf-incremental-update.js +730 -0
- package/dist/esm/key-management/pdf-incremental-update.js.map +1 -0
- package/dist/esm/key-management/pdf-truetype-font.d.ts +35 -0
- package/dist/esm/key-management/pdf-truetype-font.d.ts.map +1 -0
- package/dist/esm/key-management/pdf-truetype-font.js +152 -0
- package/dist/esm/key-management/pdf-truetype-font.js.map +1 -0
- package/dist/esm/key-management/qr-code.d.ts +38 -0
- package/dist/esm/key-management/qr-code.d.ts.map +1 -0
- package/dist/esm/key-management/qr-code.js +325 -0
- package/dist/esm/key-management/qr-code.js.map +1 -0
- package/dist/esm/key-management/signature-request.contracts.d.ts +0 -4
- package/dist/esm/key-management/signature-request.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/signature-request.contracts.js.map +1 -1
- package/dist/esm/key-management/signing-log-export.contracts.d.ts +0 -1
- package/dist/esm/key-management/signing-log-export.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/signing-log-export.contracts.js.map +1 -1
- package/dist/esm/key-management/vault-custody.contracts.d.ts +43 -0
- package/dist/esm/key-management/vault-custody.contracts.d.ts.map +1 -1
- package/dist/esm/key-management/vault-custody.contracts.js +66 -0
- package/dist/esm/key-management/vault-custody.contracts.js.map +1 -1
- package/dist/esm/lockfile/build-parallelism.d.ts.map +1 -1
- package/dist/esm/lockfile/build-parallelism.js.map +1 -1
- package/dist/esm/lockfile/canonical-json.d.ts +1 -1
- package/dist/esm/lockfile/canonical-json.d.ts.map +1 -1
- package/dist/esm/lockfile/canonical-json.js +1 -1
- package/dist/esm/lockfile/canonical-json.js.map +1 -1
- package/dist/esm/lockfile/file-lock-hold.d.ts.map +1 -1
- package/dist/esm/lockfile/file-lock-hold.js +2 -1
- package/dist/esm/lockfile/file-lock-hold.js.map +1 -1
- package/dist/esm/lockfile/lockfile-io.d.ts +6 -8
- package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.js +6 -8
- package/dist/esm/lockfile/lockfile-io.js.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.d.ts +5 -6
- package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.js +4 -5
- package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +1 -247
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
- package/dist/esm/pnpm-settings/application-pnpm-settings.d.ts +146 -0
- package/dist/esm/pnpm-settings/application-pnpm-settings.d.ts.map +1 -0
- package/dist/esm/pnpm-settings/application-pnpm-settings.js +573 -0
- package/dist/esm/pnpm-settings/application-pnpm-settings.js.map +1 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -1
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js +15 -3
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -1
- package/dist/esm/project-config/application-served-public-documents.loader.d.ts.map +1 -1
- package/dist/esm/project-config/application-served-public-documents.loader.js +16 -8
- package/dist/esm/project-config/application-served-public-documents.loader.js.map +1 -1
- package/dist/esm/project-config/backend-compliance-section.reader.d.ts +35 -0
- package/dist/esm/project-config/backend-compliance-section.reader.d.ts.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.reader.js +123 -0
- package/dist/esm/project-config/backend-compliance-section.reader.js.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.worker.d.ts +20 -0
- package/dist/esm/project-config/backend-compliance-section.worker.d.ts.map +1 -0
- package/dist/esm/project-config/backend-compliance-section.worker.js +78 -0
- package/dist/esm/project-config/backend-compliance-section.worker.js.map +1 -0
- package/dist/esm/project-config/config-module-resolution.d.ts +32 -0
- package/dist/esm/project-config/config-module-resolution.d.ts.map +1 -0
- package/dist/esm/project-config/config-module-resolution.js +33 -0
- package/dist/esm/project-config/config-module-resolution.js.map +1 -0
- package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-framework-config.js.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.d.ts +146 -55
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +124 -71
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/define-minion-config.d.ts +26 -36
- package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-minion-config.js +64 -25
- package/dist/esm/project-config/define-minion-config.js.map +1 -1
- package/dist/esm/project-config/define-saas-config.d.ts +41 -437
- package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.js +102 -94
- package/dist/esm/project-config/define-saas-config.js.map +1 -1
- package/dist/esm/project-config/define-worker-config.d.ts +10 -20
- package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-worker-config.js +10 -12
- package/dist/esm/project-config/define-worker-config.js.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.js +2 -1
- package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/index.d.ts +2 -0
- package/dist/esm/project-config/index.d.ts.map +1 -1
- package/dist/esm/project-config/index.js +2 -0
- package/dist/esm/project-config/index.js.map +1 -1
- package/dist/esm/project-config/loader-instances-zod.d.ts +19 -0
- package/dist/esm/project-config/loader-instances-zod.d.ts.map +1 -0
- package/dist/esm/project-config/loader-instances-zod.js +40 -0
- package/dist/esm/project-config/loader-instances-zod.js.map +1 -0
- package/dist/esm/project-config/loader.d.ts +131 -14
- package/dist/esm/project-config/loader.d.ts.map +1 -1
- package/dist/esm/project-config/loader.js +226 -12
- package/dist/esm/project-config/loader.js.map +1 -1
- package/dist/esm/project-config/minion-liveness.contracts.d.ts +131 -0
- package/dist/esm/project-config/minion-liveness.contracts.d.ts.map +1 -0
- package/dist/esm/project-config/minion-liveness.contracts.js +167 -0
- package/dist/esm/project-config/minion-liveness.contracts.js.map +1 -0
- package/dist/esm/project-config/minion-local-provider-registration.d.ts.map +1 -1
- package/dist/esm/project-config/minion-local-provider-registration.js.map +1 -1
- package/dist/esm/project-config/npm-version-range.d.ts.map +1 -1
- package/dist/esm/project-config/npm-version-range.js.map +1 -1
- package/dist/esm/project-config/owning-package-tsconfig.d.ts +7 -7
- package/dist/esm/project-config/owning-package-tsconfig.d.ts.map +1 -1
- package/dist/esm/project-config/owning-package-tsconfig.js +7 -7
- package/dist/esm/project-config/owning-package-tsconfig.js.map +1 -1
- package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
- package/dist/esm/project-config/provider-catalog-types.js.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +3 -1
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +71 -46
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +150 -4
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts +0 -2
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.js.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.d.ts +0 -17
- package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/backing-service-servability.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-service-servability.js.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts +9 -10
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.js +13 -15
- package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.d.ts +0 -51
- package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.d.ts +34 -6
- package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.js +52 -8
- package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.d.ts +60 -13
- package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.js +77 -24
- package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.d.ts +72 -84
- package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.js +40 -12
- package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.d.ts +0 -8
- package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/env-example-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.d.ts +95 -8
- package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.js +122 -10
- package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +10 -4
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/k8s-utils.js.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-platform-access.vocabulary.js.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +20 -0
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.js +21 -2
- package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
- package/dist/esm/project-config/shared/object-storage-session-policy.d.ts.map +1 -1
- package/dist/esm/project-config/shared/object-storage-session-policy.js.map +1 -1
- package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts +67 -38
- package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-key-management.schemas.js +113 -5
- package/dist/esm/project-config/shared/platform-key-management.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.d.ts +2 -2
- package/dist/esm/project-config/shared/platform-storage.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.js +16 -2
- package/dist/esm/project-config/shared/platform-storage.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts +21 -23
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.js +4 -5
- package/dist/esm/project-config/shared/service-definitions.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts +0 -18
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.js.map +1 -1
- package/dist/esm/project-config/static-asset-import-noop.d.ts +20 -3
- package/dist/esm/project-config/static-asset-import-noop.d.ts.map +1 -1
- package/dist/esm/project-config/static-asset-import-noop.js +36 -20
- package/dist/esm/project-config/static-asset-import-noop.js.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.d.ts +0 -5
- package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.js.map +1 -1
- package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/digest.schemas.js.map +1 -1
- package/dist/esm/registry/index.d.ts +2 -3
- package/dist/esm/registry/index.d.ts.map +1 -1
- package/dist/esm/registry/index.js +2 -3
- package/dist/esm/registry/index.js.map +1 -1
- package/dist/esm/registry/local-checkout-source.d.ts.map +1 -1
- package/dist/esm/registry/local-checkout-source.js.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +1 -98
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.js +1 -2
- package/dist/esm/registry/lockfile-modules-section.schemas.js.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.d.ts +17 -17
- package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.js.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.d.ts +151 -219
- package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.js +145 -13
- package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
- package/dist/esm/registry/module-search.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-search.schemas.js.map +1 -1
- package/dist/esm/registry/registry-config.schemas.d.ts +0 -18
- package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-config.schemas.js.map +1 -1
- package/dist/esm/registry/registry-defaults.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-defaults.constants.js.map +1 -1
- package/dist/esm/registry/registry-errors.d.ts +81 -3
- package/dist/esm/registry/registry-errors.d.ts.map +1 -1
- package/dist/esm/registry/registry-errors.js +185 -4
- package/dist/esm/registry/registry-errors.js.map +1 -1
- package/dist/esm/registry/registry-keys.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-keys.schemas.js.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.js.map +1 -1
- package/dist/esm/registry/registry-url-resolution.d.ts.map +1 -1
- package/dist/esm/registry/registry-url-resolution.js.map +1 -1
- package/dist/esm/release/framework-release.constants.d.ts.map +1 -1
- package/dist/esm/release/framework-release.constants.js.map +1 -1
- package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-info.schemas.js.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.d.ts +0 -7
- package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.d.ts +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.d.ts +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.d.ts +2 -2
- package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.js.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.js.map +1 -1
- package/dist/esm/workspace-scope/index.d.ts.map +1 -1
- package/dist/esm/workspace-scope/index.js.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.d.ts.map +1 -1
- package/dist/esm/workspace-scope/resolve-homes.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope-detector.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope-detector.js.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-scope.schemas.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/dist/esm/_unimplemented/index.d.ts +0 -3
- package/dist/esm/_unimplemented/index.d.ts.map +0 -1
- package/dist/esm/_unimplemented/index.js +0 -3
- package/dist/esm/_unimplemented/index.js.map +0 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts +0 -137
- package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts.map +0 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.js +0 -153
- package/dist/esm/_unimplemented/unimplemented-field-warning.js.map +0 -1
- package/dist/esm/project-config/shared/cdn.example.d.ts +0 -14
- package/dist/esm/project-config/shared/cdn.example.d.ts.map +0 -1
- package/dist/esm/project-config/shared/cdn.example.js +0 -38
- package/dist/esm/project-config/shared/cdn.example.js.map +0 -1
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts +0 -15
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +0 -1
- package/dist/esm/project-config/shared/schema-version.schemas.js +0 -40
- package/dist/esm/project-config/shared/schema-version.schemas.js.map +0 -1
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
import { inflateSync } from 'node:zlib';
|
|
2
|
+
/**
|
|
3
|
+
* # Appending to a PDF without touching its bytes (#2907)
|
|
4
|
+
*
|
|
5
|
+
* The smallest PDF capability the manifested copy of an approved deliverable needs, written here because the PDF stack
|
|
6
|
+
* the engine has (`@react-pdf/renderer`) renders whole documents and cannot open an existing one. It does exactly two
|
|
7
|
+
* things: READ enough of a PDF to locate its page tree (the cross-reference chain, the trailer, a handful of objects), and
|
|
8
|
+
* APPEND an incremental-update section that adds objects and redefines one existing object. The original bytes are never
|
|
9
|
+
* rewritten: the result is the original, byte for byte, followed by the new section, which every conforming reader
|
|
10
|
+
* applies on top. That property is the point: a verifier holding the copy holds the original as its prefix.
|
|
11
|
+
*
|
|
12
|
+
* Supported: classic cross-reference tables, cross-reference streams (FlateDecode, with or without a PNG predictor), hybrid
|
|
13
|
+
* files (`/XRefStm`), objects held in object streams, a `/Prev` chain of earlier updates. Refused with a typed reason:
|
|
14
|
+
* an encrypted file (`/Encrypt`: the appended objects would have to be encrypted too), a file that does not begin with
|
|
15
|
+
* `%PDF-`, and any structure this reader cannot follow (a filter other than FlateDecode on a stream it must decode, a
|
|
16
|
+
* page-tree root whose `/Kids` is not a direct array). A refusal is a statement that no copy can be made, never a guess.
|
|
17
|
+
*
|
|
18
|
+
* Deliberately NOT a general PDF library: it parses objects only to re-serialize the one it redefines, and serializes
|
|
19
|
+
* every string as hexadecimal and every number by its original token, so a value it did not change is written with the
|
|
20
|
+
* same meaning. Everything it writes is a pure function of its inputs, so the same inputs give the same bytes, which is
|
|
21
|
+
* what lets the verifier rebuild a copy and compare.
|
|
22
|
+
*
|
|
23
|
+
* Rejected: adopting pdf-lib (#2907 named it as the candidate). It saves by rewriting the whole file (no incremental
|
|
24
|
+
* save), so the copy would no longer carry the original as its prefix, and the verifier would need the original from
|
|
25
|
+
* elsewhere to tie the two; adding it also meant a dependency and lockfile change in every application.
|
|
26
|
+
*
|
|
27
|
+
* spec-cite: ISO 32000-1:2008 §7.3 (objects), §7.5.4 (cross-reference table), §7.5.5 (file trailer), §7.5.6 (incremental
|
|
28
|
+
* updates), §7.5.7 (object streams), §7.5.8 (cross-reference streams, hybrid files), §7.4.4.4 (PNG predictors, by reference
|
|
29
|
+
* to the FlateDecode parameters). Cited by section; the subset implemented is this file's decision.
|
|
30
|
+
*/
|
|
31
|
+
/** Why a PDF cannot be appended to. */
|
|
32
|
+
export var PdfIncrementalUpdateRefusal;
|
|
33
|
+
(function (PdfIncrementalUpdateRefusal) {
|
|
34
|
+
/** The bytes do not begin with a PDF header. */
|
|
35
|
+
PdfIncrementalUpdateRefusal["NOT_A_PDF"] = "not_a_pdf";
|
|
36
|
+
/** The file is encrypted: appended objects would have to be encrypted with a key nobody here holds. */
|
|
37
|
+
PdfIncrementalUpdateRefusal["ENCRYPTED"] = "encrypted";
|
|
38
|
+
/** A structure this reader does not follow (named in the message). */
|
|
39
|
+
PdfIncrementalUpdateRefusal["UNSUPPORTED_STRUCTURE"] = "unsupported_structure";
|
|
40
|
+
})(PdfIncrementalUpdateRefusal || (PdfIncrementalUpdateRefusal = {}));
|
|
41
|
+
/** A PDF that cannot be appended to, and why. */
|
|
42
|
+
export class PdfIncrementalUpdateRefusedError extends Error {
|
|
43
|
+
refusal;
|
|
44
|
+
constructor(refusal, message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.refusal = refusal;
|
|
47
|
+
this.name = 'PdfIncrementalUpdateRefusedError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Constructors, for the objects a caller appends. */
|
|
51
|
+
export const pdf = {
|
|
52
|
+
null: () => ({ kind: 'null' }),
|
|
53
|
+
bool: (value) => ({ kind: 'bool', value }),
|
|
54
|
+
int: (value) => {
|
|
55
|
+
if (!Number.isSafeInteger(value))
|
|
56
|
+
throw new Error(`Not an integer: ${value}`);
|
|
57
|
+
return { kind: 'number', text: String(value) };
|
|
58
|
+
},
|
|
59
|
+
/** A real written with at most 2 decimals, without exponent: deterministic. */
|
|
60
|
+
real: (value) => ({ kind: 'number', text: formatPdfReal(value) }),
|
|
61
|
+
name: (value) => ({ kind: 'name', value }),
|
|
62
|
+
string: (value) => ({ kind: 'string', bytes: typeof value === 'string' ? Buffer.from(value, 'latin1') : value }),
|
|
63
|
+
array: (items) => ({ kind: 'array', items }),
|
|
64
|
+
dict: (entries) => ({
|
|
65
|
+
kind: 'dict',
|
|
66
|
+
entries: new Map(Object.entries(entries).filter((entry) => entry[1] !== undefined)),
|
|
67
|
+
}),
|
|
68
|
+
ref: (num, gen = 0) => ({ kind: 'ref', num, gen }),
|
|
69
|
+
};
|
|
70
|
+
/** A real number as a PDF token: no exponent, at most two decimals, trailing zeros dropped. */
|
|
71
|
+
export function formatPdfReal(value) {
|
|
72
|
+
if (!Number.isFinite(value))
|
|
73
|
+
throw new Error(`Not a finite number: ${value}`);
|
|
74
|
+
const fixed = (Math.round(value * 100) / 100).toFixed(2);
|
|
75
|
+
const trimmed = fixed.replace(/\.?0+$/, '');
|
|
76
|
+
return trimmed === '-0' || trimmed === '' ? '0' : trimmed;
|
|
77
|
+
}
|
|
78
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
79
|
+
// Lexing and parsing
|
|
80
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
81
|
+
const WHITESPACE = new Set([0x00, 0x09, 0x0a, 0x0c, 0x0d, 0x20]);
|
|
82
|
+
const DELIMITERS = new Set([0x28, 0x29, 0x3c, 0x3e, 0x5b, 0x5d, 0x7b, 0x7d, 0x2f, 0x25]);
|
|
83
|
+
const unsupported = (message) => new PdfIncrementalUpdateRefusedError(PdfIncrementalUpdateRefusal.UNSUPPORTED_STRUCTURE, message);
|
|
84
|
+
function isRegular(byte) {
|
|
85
|
+
return byte !== undefined && !WHITESPACE.has(byte) && !DELIMITERS.has(byte);
|
|
86
|
+
}
|
|
87
|
+
/** A cursor over a byte range. */
|
|
88
|
+
class PdfLexer {
|
|
89
|
+
bytes;
|
|
90
|
+
pos;
|
|
91
|
+
end;
|
|
92
|
+
constructor(bytes, pos, end = bytes.length) {
|
|
93
|
+
this.bytes = bytes;
|
|
94
|
+
this.pos = pos;
|
|
95
|
+
this.end = end;
|
|
96
|
+
}
|
|
97
|
+
peek(offset = 0) {
|
|
98
|
+
const at = this.pos + offset;
|
|
99
|
+
return at < this.end ? this.bytes[at] : undefined;
|
|
100
|
+
}
|
|
101
|
+
/** Skip whitespace and comments. */
|
|
102
|
+
skip() {
|
|
103
|
+
while (this.pos < this.end) {
|
|
104
|
+
const byte = this.bytes[this.pos];
|
|
105
|
+
if (WHITESPACE.has(byte)) {
|
|
106
|
+
this.pos += 1;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (byte === 0x25) {
|
|
110
|
+
while (this.pos < this.end && this.bytes[this.pos] !== 0x0a && this.bytes[this.pos] !== 0x0d)
|
|
111
|
+
this.pos += 1;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** The next run of regular characters, without consuming it. */
|
|
118
|
+
peekToken() {
|
|
119
|
+
this.skip();
|
|
120
|
+
let at = this.pos;
|
|
121
|
+
while (at < this.end && isRegular(this.bytes[at]))
|
|
122
|
+
at += 1;
|
|
123
|
+
return this.bytes.toString('latin1', this.pos, at);
|
|
124
|
+
}
|
|
125
|
+
readToken() {
|
|
126
|
+
const token = this.peekToken();
|
|
127
|
+
this.pos += token.length;
|
|
128
|
+
return token;
|
|
129
|
+
}
|
|
130
|
+
expectKeyword(keyword) {
|
|
131
|
+
const token = this.readToken();
|
|
132
|
+
if (token !== keyword)
|
|
133
|
+
throw unsupported(`expected "${keyword}" at offset ${this.pos - token.length}, found "${token.slice(0, 20)}"`);
|
|
134
|
+
}
|
|
135
|
+
readValue(depth = 0) {
|
|
136
|
+
if (depth > 64)
|
|
137
|
+
throw unsupported('objects nested deeper than 64 levels');
|
|
138
|
+
this.skip();
|
|
139
|
+
const byte = this.peek();
|
|
140
|
+
if (byte === undefined)
|
|
141
|
+
throw unsupported('unexpected end of data');
|
|
142
|
+
if (byte === 0x3c && this.peek(1) === 0x3c)
|
|
143
|
+
return this.readDict(depth);
|
|
144
|
+
if (byte === 0x3c)
|
|
145
|
+
return this.readHexString();
|
|
146
|
+
if (byte === 0x28)
|
|
147
|
+
return this.readLiteralString();
|
|
148
|
+
if (byte === 0x5b)
|
|
149
|
+
return this.readArray(depth);
|
|
150
|
+
if (byte === 0x2f)
|
|
151
|
+
return this.readName();
|
|
152
|
+
const token = this.readToken();
|
|
153
|
+
if (token === 'true' || token === 'false')
|
|
154
|
+
return { kind: 'bool', value: token === 'true' };
|
|
155
|
+
if (token === 'null')
|
|
156
|
+
return { kind: 'null' };
|
|
157
|
+
if (/^[+-]?(\d+\.?\d*|\.\d+)$/.test(token)) {
|
|
158
|
+
// An integer may be the first of `num gen R`.
|
|
159
|
+
if (/^\d+$/.test(token)) {
|
|
160
|
+
const save = this.pos;
|
|
161
|
+
const gen = this.readToken();
|
|
162
|
+
if (/^\d+$/.test(gen) && this.readToken() === 'R')
|
|
163
|
+
return { kind: 'ref', num: Number(token), gen: Number(gen) };
|
|
164
|
+
this.pos = save;
|
|
165
|
+
}
|
|
166
|
+
return { kind: 'number', text: token };
|
|
167
|
+
}
|
|
168
|
+
throw unsupported(`unexpected token "${token.slice(0, 20)}" at offset ${this.pos - token.length}`);
|
|
169
|
+
}
|
|
170
|
+
readDict(depth) {
|
|
171
|
+
this.pos += 2;
|
|
172
|
+
const entries = new Map();
|
|
173
|
+
for (;;) {
|
|
174
|
+
this.skip();
|
|
175
|
+
if (this.peek() === 0x3e && this.peek(1) === 0x3e) {
|
|
176
|
+
this.pos += 2;
|
|
177
|
+
return { kind: 'dict', entries };
|
|
178
|
+
}
|
|
179
|
+
const key = this.readValue(depth + 1);
|
|
180
|
+
if (key.kind !== 'name')
|
|
181
|
+
throw unsupported(`a dictionary key that is not a name at offset ${this.pos}`);
|
|
182
|
+
entries.set(key.value, this.readValue(depth + 1));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
readArray(depth) {
|
|
186
|
+
this.pos += 1;
|
|
187
|
+
const items = [];
|
|
188
|
+
for (;;) {
|
|
189
|
+
this.skip();
|
|
190
|
+
if (this.peek() === 0x5d) {
|
|
191
|
+
this.pos += 1;
|
|
192
|
+
return { kind: 'array', items };
|
|
193
|
+
}
|
|
194
|
+
items.push(this.readValue(depth + 1));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
readName() {
|
|
198
|
+
this.pos += 1;
|
|
199
|
+
const start = this.pos;
|
|
200
|
+
while (this.pos < this.end && isRegular(this.bytes[this.pos]))
|
|
201
|
+
this.pos += 1;
|
|
202
|
+
const raw = this.bytes.toString('latin1', start, this.pos);
|
|
203
|
+
return { kind: 'name', value: raw.replace(/#([0-9A-Fa-f]{2})/g, (_match, hex) => String.fromCharCode(parseInt(hex, 16))) };
|
|
204
|
+
}
|
|
205
|
+
readHexString() {
|
|
206
|
+
this.pos += 1;
|
|
207
|
+
let hex = '';
|
|
208
|
+
while (this.pos < this.end && this.bytes[this.pos] !== 0x3e) {
|
|
209
|
+
const char = String.fromCharCode(this.bytes[this.pos]);
|
|
210
|
+
if (/[0-9A-Fa-f]/.test(char))
|
|
211
|
+
hex += char;
|
|
212
|
+
this.pos += 1;
|
|
213
|
+
}
|
|
214
|
+
this.pos += 1;
|
|
215
|
+
if (hex.length % 2 === 1)
|
|
216
|
+
hex += '0';
|
|
217
|
+
return { kind: 'string', bytes: Buffer.from(hex, 'hex') };
|
|
218
|
+
}
|
|
219
|
+
readLiteralString() {
|
|
220
|
+
this.pos += 1;
|
|
221
|
+
const out = [];
|
|
222
|
+
let nesting = 1;
|
|
223
|
+
while (this.pos < this.end) {
|
|
224
|
+
const byte = this.bytes[this.pos++];
|
|
225
|
+
if (byte === 0x5c) {
|
|
226
|
+
const next = this.bytes[this.pos++];
|
|
227
|
+
if (next === undefined)
|
|
228
|
+
break;
|
|
229
|
+
const simple = { 0x6e: 0x0a, 0x72: 0x0d, 0x74: 0x09, 0x62: 0x08, 0x66: 0x0c, 0x28: 0x28, 0x29: 0x29, 0x5c: 0x5c };
|
|
230
|
+
if (simple[next] !== undefined) {
|
|
231
|
+
out.push(simple[next]);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (next >= 0x30 && next <= 0x37) {
|
|
235
|
+
let octal = next - 0x30;
|
|
236
|
+
for (let digit = 0; digit < 2 && this.bytes[this.pos] >= 0x30 && this.bytes[this.pos] <= 0x37; digit += 1)
|
|
237
|
+
octal = octal * 8 + (this.bytes[this.pos++] - 0x30);
|
|
238
|
+
out.push(octal & 0xff);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (next === 0x0d) {
|
|
242
|
+
if (this.bytes[this.pos] === 0x0a)
|
|
243
|
+
this.pos += 1;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (next === 0x0a)
|
|
247
|
+
continue;
|
|
248
|
+
out.push(next);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (byte === 0x28)
|
|
252
|
+
nesting += 1;
|
|
253
|
+
if (byte === 0x29) {
|
|
254
|
+
nesting -= 1;
|
|
255
|
+
if (nesting === 0)
|
|
256
|
+
return { kind: 'string', bytes: Buffer.from(out) };
|
|
257
|
+
}
|
|
258
|
+
out.push(byte);
|
|
259
|
+
}
|
|
260
|
+
throw unsupported('an unterminated string');
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
264
|
+
// Serialization
|
|
265
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
266
|
+
/** A name's bytes written with `#xx` for every byte that is not a regular printable character (§7.3.5). */
|
|
267
|
+
function serializeName(value) {
|
|
268
|
+
let out = '/';
|
|
269
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
270
|
+
const code = value.charCodeAt(index) & 0xff;
|
|
271
|
+
out += code > 0x20 && code < 0x7f && code !== 0x23 && !DELIMITERS.has(code)
|
|
272
|
+
? String.fromCharCode(code)
|
|
273
|
+
: `#${code.toString(16).padStart(2, '0').toUpperCase()}`;
|
|
274
|
+
}
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
/** One object as PDF syntax, latin1. Strings are hexadecimal; numbers keep their token. */
|
|
278
|
+
export function serializePdfObject(object) {
|
|
279
|
+
switch (object.kind) {
|
|
280
|
+
case 'null': return 'null';
|
|
281
|
+
case 'bool': return object.value ? 'true' : 'false';
|
|
282
|
+
case 'number': return object.text;
|
|
283
|
+
case 'name': return serializeName(object.value);
|
|
284
|
+
case 'string': return `<${object.bytes.toString('hex').toUpperCase()}>`;
|
|
285
|
+
case 'array': return `[${object.items.map(serializePdfObject).join(' ')}]`;
|
|
286
|
+
case 'ref': return `${object.num} ${object.gen} R`;
|
|
287
|
+
case 'dict': return `<<${[...object.entries].map(([key, value]) => ` ${serializeName(key)} ${serializePdfObject(value)}`).join('')} >>`;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/** A literal string's syntax (§7.3.4.2) for latin1 text: `(`, `)` and `\` escaped. For content streams. */
|
|
291
|
+
export function pdfLiteralString(latin1) {
|
|
292
|
+
return `(${latin1.replace(/[\\()]/g, (char) => `\\${char}`)})`;
|
|
293
|
+
}
|
|
294
|
+
/** The layout of the most recent cross-reference section, which an update continues. */
|
|
295
|
+
export var PdfCrossReferenceForm;
|
|
296
|
+
(function (PdfCrossReferenceForm) {
|
|
297
|
+
PdfCrossReferenceForm["TABLE"] = "table";
|
|
298
|
+
PdfCrossReferenceForm["STREAM"] = "stream";
|
|
299
|
+
})(PdfCrossReferenceForm || (PdfCrossReferenceForm = {}));
|
|
300
|
+
const MAX_XREF_SECTIONS = 1024;
|
|
301
|
+
function numberOf(object) {
|
|
302
|
+
return object?.kind === 'number' && /^[+-]?\d+$/.test(object.text) ? Number(object.text) : undefined;
|
|
303
|
+
}
|
|
304
|
+
function realOf(object) {
|
|
305
|
+
return object?.kind === 'number' ? Number(object.text) : undefined;
|
|
306
|
+
}
|
|
307
|
+
/** A PDF read for appending: its cross-reference chain, its latest trailer, and an object resolver. */
|
|
308
|
+
export class PdfDocumentReader {
|
|
309
|
+
bytes;
|
|
310
|
+
entries = new Map();
|
|
311
|
+
/** The latest trailer (the xref stream's dictionary when the latest section is a stream). */
|
|
312
|
+
trailer;
|
|
313
|
+
/** The offset of the latest cross-reference section: what an update's `/Prev` names. */
|
|
314
|
+
lastXrefOffset;
|
|
315
|
+
lastXrefForm;
|
|
316
|
+
objectStreams = new Map();
|
|
317
|
+
constructor(bytes) {
|
|
318
|
+
this.bytes = bytes;
|
|
319
|
+
if (bytes.subarray(0, 5).toString('latin1') !== '%PDF-') {
|
|
320
|
+
throw new PdfIncrementalUpdateRefusedError(PdfIncrementalUpdateRefusal.NOT_A_PDF, 'the bytes do not begin with %PDF-');
|
|
321
|
+
}
|
|
322
|
+
const tail = bytes.subarray(Math.max(0, bytes.length - 2048)).toString('latin1');
|
|
323
|
+
const at = tail.lastIndexOf('startxref');
|
|
324
|
+
if (at < 0)
|
|
325
|
+
throw unsupported('no startxref near the end of the file');
|
|
326
|
+
const lexer = new PdfLexer(bytes, bytes.length - tail.length + at + 'startxref'.length);
|
|
327
|
+
const offset = Number(lexer.readToken());
|
|
328
|
+
if (!Number.isSafeInteger(offset) || offset <= 0 || offset >= bytes.length)
|
|
329
|
+
throw unsupported('startxref names no offset inside the file');
|
|
330
|
+
this.lastXrefOffset = offset;
|
|
331
|
+
let trailer;
|
|
332
|
+
let form;
|
|
333
|
+
const visited = new Set();
|
|
334
|
+
let next = offset;
|
|
335
|
+
while (next !== undefined) {
|
|
336
|
+
if (visited.has(next) || visited.size >= MAX_XREF_SECTIONS)
|
|
337
|
+
throw unsupported('a cross-reference chain that loops or never ends');
|
|
338
|
+
visited.add(next);
|
|
339
|
+
const section = this.readSection(next);
|
|
340
|
+
trailer ??= section.trailer;
|
|
341
|
+
form ??= section.form;
|
|
342
|
+
next = numberOf(section.trailer.entries.get('Prev'));
|
|
343
|
+
}
|
|
344
|
+
this.trailer = trailer;
|
|
345
|
+
this.lastXrefForm = form;
|
|
346
|
+
if (this.trailer.entries.has('Encrypt')) {
|
|
347
|
+
throw new PdfIncrementalUpdateRefusedError(PdfIncrementalUpdateRefusal.ENCRYPTED, 'the file is encrypted');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/** The number one past the highest object number in use: where appended objects start. */
|
|
351
|
+
get size() {
|
|
352
|
+
const declared = numberOf(this.trailer.entries.get('Size'));
|
|
353
|
+
if (declared === undefined || declared < 1)
|
|
354
|
+
throw unsupported('the trailer states no /Size');
|
|
355
|
+
let size = declared;
|
|
356
|
+
for (const num of this.entries.keys())
|
|
357
|
+
size = Math.max(size, num + 1);
|
|
358
|
+
return size;
|
|
359
|
+
}
|
|
360
|
+
/** Record an entry unless a later section already defined that object. */
|
|
361
|
+
setEntry(num, entry) {
|
|
362
|
+
if (!this.entries.has(num))
|
|
363
|
+
this.entries.set(num, entry);
|
|
364
|
+
}
|
|
365
|
+
readSection(offset) {
|
|
366
|
+
const lexer = new PdfLexer(this.bytes, offset);
|
|
367
|
+
if (lexer.peekToken() === 'xref') {
|
|
368
|
+
lexer.readToken();
|
|
369
|
+
for (;;) {
|
|
370
|
+
const token = lexer.peekToken();
|
|
371
|
+
if (token === 'trailer')
|
|
372
|
+
break;
|
|
373
|
+
const start = Number(lexer.readToken());
|
|
374
|
+
const count = Number(lexer.readToken());
|
|
375
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(count) || count < 0)
|
|
376
|
+
throw unsupported(`a malformed cross-reference subsection at offset ${lexer.pos}`);
|
|
377
|
+
for (let index = 0; index < count; index += 1) {
|
|
378
|
+
const entryOffset = Number(lexer.readToken());
|
|
379
|
+
const gen = Number(lexer.readToken());
|
|
380
|
+
const type = lexer.readToken();
|
|
381
|
+
if (type === 'n')
|
|
382
|
+
this.setEntry(start + index, { type: 'offset', offset: entryOffset, gen });
|
|
383
|
+
else if (type === 'f')
|
|
384
|
+
this.setEntry(start + index, { type: 'free' });
|
|
385
|
+
else
|
|
386
|
+
throw unsupported(`a cross-reference entry of type "${type}"`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
lexer.readToken();
|
|
390
|
+
const trailer = lexer.readValue();
|
|
391
|
+
if (trailer.kind !== 'dict')
|
|
392
|
+
throw unsupported('a trailer that is not a dictionary');
|
|
393
|
+
// A hybrid file: the table's objects first, then those only its cross-reference stream lists (§7.5.8.4).
|
|
394
|
+
const xrefStm = numberOf(trailer.entries.get('XRefStm'));
|
|
395
|
+
if (xrefStm !== undefined)
|
|
396
|
+
this.readXrefStream(xrefStm);
|
|
397
|
+
return { trailer, form: PdfCrossReferenceForm.TABLE };
|
|
398
|
+
}
|
|
399
|
+
return { trailer: this.readXrefStream(offset), form: PdfCrossReferenceForm.STREAM };
|
|
400
|
+
}
|
|
401
|
+
/** A cross-reference stream at `offset`: its entries recorded, its dictionary returned (§7.5.8). */
|
|
402
|
+
readXrefStream(offset) {
|
|
403
|
+
const { dict, data } = this.readStreamAt(offset);
|
|
404
|
+
if (dict.entries.get('Type')?.kind !== 'name' || dict.entries.get('Type').value !== 'XRef') {
|
|
405
|
+
throw unsupported(`the cross-reference at offset ${offset} is neither a table nor an XRef stream`);
|
|
406
|
+
}
|
|
407
|
+
const widths = dict.entries.get('W');
|
|
408
|
+
if (widths?.kind !== 'array' || widths.items.length !== 3)
|
|
409
|
+
throw unsupported('an XRef stream without a three-member /W');
|
|
410
|
+
const [w0, w1, w2] = widths.items.map((item) => numberOf(item) ?? -1);
|
|
411
|
+
if ([w0, w1, w2].some((width) => width < 0 || width > 8))
|
|
412
|
+
throw unsupported('an XRef stream /W outside 0..8');
|
|
413
|
+
const size = numberOf(dict.entries.get('Size')) ?? 0;
|
|
414
|
+
const index = dict.entries.get('Index');
|
|
415
|
+
const ranges = index?.kind === 'array' ? index.items.map((item) => numberOf(item) ?? -1) : [0, size];
|
|
416
|
+
const decoded = decodeStream(dict, data);
|
|
417
|
+
const rowWidth = w0 + w1 + w2;
|
|
418
|
+
const field = (row, start, width) => {
|
|
419
|
+
let value = 0;
|
|
420
|
+
for (let byte = 0; byte < width; byte += 1)
|
|
421
|
+
value = value * 256 + decoded[row * rowWidth + start + byte];
|
|
422
|
+
return value;
|
|
423
|
+
};
|
|
424
|
+
let row = 0;
|
|
425
|
+
for (let range = 0; range + 1 < ranges.length; range += 2) {
|
|
426
|
+
const first = ranges[range];
|
|
427
|
+
const count = ranges[range + 1];
|
|
428
|
+
if (first < 0 || count < 0)
|
|
429
|
+
throw unsupported('a malformed XRef /Index');
|
|
430
|
+
for (let entry = 0; entry < count; entry += 1, row += 1) {
|
|
431
|
+
if ((row + 1) * rowWidth > decoded.length)
|
|
432
|
+
throw unsupported('an XRef stream shorter than its /Index');
|
|
433
|
+
const type = w0 === 0 ? 1 : field(row, 0, w0);
|
|
434
|
+
const second = field(row, w0, w1);
|
|
435
|
+
const third = field(row, w0 + w1, w2);
|
|
436
|
+
if (type === 0)
|
|
437
|
+
this.setEntry(first + entry, { type: 'free' });
|
|
438
|
+
else if (type === 1)
|
|
439
|
+
this.setEntry(first + entry, { type: 'offset', offset: second, gen: third });
|
|
440
|
+
else if (type === 2)
|
|
441
|
+
this.setEntry(first + entry, { type: 'compressed', streamNum: second, index: third });
|
|
442
|
+
// Other types are reserved and read as null objects (§7.5.8.3): left undefined here.
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return dict;
|
|
446
|
+
}
|
|
447
|
+
/** The `num gen obj` at `offset`: its header checked, its value read, its stream data when it has one. */
|
|
448
|
+
readIndirectAt(offset, expected) {
|
|
449
|
+
const lexer = new PdfLexer(this.bytes, offset);
|
|
450
|
+
const num = Number(lexer.readToken());
|
|
451
|
+
const gen = Number(lexer.readToken());
|
|
452
|
+
lexer.expectKeyword('obj');
|
|
453
|
+
if (!Number.isSafeInteger(num) || !Number.isSafeInteger(gen))
|
|
454
|
+
throw unsupported(`no object header at offset ${offset}`);
|
|
455
|
+
if (expected && (expected.num !== num || expected.gen !== gen))
|
|
456
|
+
throw unsupported(`the cross-reference names object ${expected.num} at offset ${offset}, where ${num} ${gen} is`);
|
|
457
|
+
const value = lexer.readValue();
|
|
458
|
+
if (value.kind === 'dict' && lexer.peekToken() === 'stream') {
|
|
459
|
+
lexer.readToken();
|
|
460
|
+
// `stream` is followed by CRLF or LF (§7.3.8.1).
|
|
461
|
+
if (lexer.peek() === 0x0d)
|
|
462
|
+
lexer.pos += 1;
|
|
463
|
+
if (lexer.peek() === 0x0a)
|
|
464
|
+
lexer.pos += 1;
|
|
465
|
+
const start = lexer.pos;
|
|
466
|
+
const lengthObject = value.entries.get('Length');
|
|
467
|
+
let length = lengthObject?.kind === 'ref' ? numberOf(this.resolve(lengthObject)) : numberOf(lengthObject);
|
|
468
|
+
if (length === undefined || length < 0 || start + length > this.bytes.length || !this.bytes.toString('latin1', start + length, start + length + 12).includes('endstream')) {
|
|
469
|
+
const end = this.bytes.indexOf('endstream', start, 'latin1');
|
|
470
|
+
if (end < 0)
|
|
471
|
+
throw unsupported(`an unterminated stream at offset ${offset}`);
|
|
472
|
+
length = end;
|
|
473
|
+
while (length > start && (this.bytes[length - 1] === 0x0a || this.bytes[length - 1] === 0x0d))
|
|
474
|
+
length -= 1;
|
|
475
|
+
length -= start;
|
|
476
|
+
}
|
|
477
|
+
return { value, data: this.bytes.subarray(start, start + length), num, gen };
|
|
478
|
+
}
|
|
479
|
+
return { value, num, gen };
|
|
480
|
+
}
|
|
481
|
+
readStreamAt(offset) {
|
|
482
|
+
const read = this.readIndirectAt(offset);
|
|
483
|
+
if (read.value.kind !== 'dict' || !read.data)
|
|
484
|
+
throw unsupported(`no stream at offset ${offset}`);
|
|
485
|
+
return { dict: read.value, data: read.data };
|
|
486
|
+
}
|
|
487
|
+
/** The value of an object, a reference followed (a chain of at most 16), a missing or free object as `null`. */
|
|
488
|
+
resolve(object, hops = 0) {
|
|
489
|
+
if (!object)
|
|
490
|
+
return { kind: 'null' };
|
|
491
|
+
if (object.kind !== 'ref')
|
|
492
|
+
return object;
|
|
493
|
+
if (hops > 16)
|
|
494
|
+
throw unsupported('a chain of references longer than 16');
|
|
495
|
+
return this.resolve(this.readObject(object.num, object.gen), hops + 1);
|
|
496
|
+
}
|
|
497
|
+
/** Object `num`'s current definition. */
|
|
498
|
+
readObject(num, gen) {
|
|
499
|
+
const entry = this.entries.get(num);
|
|
500
|
+
if (!entry || entry.type === 'free')
|
|
501
|
+
return { kind: 'null' };
|
|
502
|
+
if (entry.type === 'offset') {
|
|
503
|
+
if (gen !== undefined && gen !== entry.gen)
|
|
504
|
+
return { kind: 'null' };
|
|
505
|
+
return this.readIndirectAt(entry.offset, { num, gen: entry.gen }).value;
|
|
506
|
+
}
|
|
507
|
+
const stream = this.objectStream(entry.streamNum);
|
|
508
|
+
const at = stream.offsets.get(entry.index);
|
|
509
|
+
if (at === undefined)
|
|
510
|
+
throw unsupported(`object stream ${entry.streamNum} has no object at index ${entry.index}`);
|
|
511
|
+
return new PdfLexer(stream.data, stream.first + at).readValue();
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* The raw (still encoded) data of stream object `num`, when it is stored at an offset; undefined otherwise. What a
|
|
515
|
+
* reader of an update uses to take back the streams it wrote, which are written unencoded.
|
|
516
|
+
*/
|
|
517
|
+
streamDataOf(num) {
|
|
518
|
+
const entry = this.entries.get(num);
|
|
519
|
+
if (entry?.type !== 'offset')
|
|
520
|
+
return undefined;
|
|
521
|
+
try {
|
|
522
|
+
return this.readIndirectAt(entry.offset, { num, gen: entry.gen }).data;
|
|
523
|
+
}
|
|
524
|
+
catch {
|
|
525
|
+
return undefined;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/** The generation an object is currently defined with: what a redefinition of it must reuse. */
|
|
529
|
+
generationOf(num) {
|
|
530
|
+
const entry = this.entries.get(num);
|
|
531
|
+
return entry?.type === 'offset' ? entry.gen : 0;
|
|
532
|
+
}
|
|
533
|
+
objectStream(num) {
|
|
534
|
+
const cached = this.objectStreams.get(num);
|
|
535
|
+
if (cached)
|
|
536
|
+
return cached;
|
|
537
|
+
const entry = this.entries.get(num);
|
|
538
|
+
if (entry?.type !== 'offset')
|
|
539
|
+
throw unsupported(`object stream ${num} is not stored at an offset`);
|
|
540
|
+
const { dict, data } = this.readStreamAt(entry.offset);
|
|
541
|
+
const decoded = decodeStream(dict, data);
|
|
542
|
+
const count = numberOf(dict.entries.get('N')) ?? 0;
|
|
543
|
+
const first = numberOf(dict.entries.get('First')) ?? 0;
|
|
544
|
+
const header = new PdfLexer(decoded, 0, first);
|
|
545
|
+
const offsets = new Map();
|
|
546
|
+
for (let index = 0; index < count; index += 1) {
|
|
547
|
+
header.readToken();
|
|
548
|
+
offsets.set(index, Number(header.readToken()));
|
|
549
|
+
}
|
|
550
|
+
const loaded = { data: decoded, offsets, first };
|
|
551
|
+
this.objectStreams.set(num, loaded);
|
|
552
|
+
return loaded;
|
|
553
|
+
}
|
|
554
|
+
/** A dictionary, a reference followed; refused when the value is not one. */
|
|
555
|
+
dictOf(object, what) {
|
|
556
|
+
const resolved = this.resolve(object);
|
|
557
|
+
if (resolved.kind !== 'dict')
|
|
558
|
+
throw unsupported(`${what} is not a dictionary`);
|
|
559
|
+
return resolved;
|
|
560
|
+
}
|
|
561
|
+
/** A box (`/MediaBox`) as four numbers, a reference followed; undefined when it is not one. */
|
|
562
|
+
boxOf(object) {
|
|
563
|
+
const resolved = this.resolve(object);
|
|
564
|
+
if (resolved.kind !== 'array' || resolved.items.length !== 4)
|
|
565
|
+
return undefined;
|
|
566
|
+
const numbers = resolved.items.map((item) => realOf(this.resolve(item)));
|
|
567
|
+
return numbers.every((value) => value !== undefined && Number.isFinite(value)) ? numbers : undefined;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
/** Decode a stream's data: FlateDecode, with an optional PNG predictor (§7.4.4). Any other filter is refused. */
|
|
571
|
+
function decodeStream(dict, data) {
|
|
572
|
+
const filter = dict.entries.get('Filter');
|
|
573
|
+
const filters = filter === undefined ? [] : filter.kind === 'array' ? filter.items : [filter];
|
|
574
|
+
if (filters.length === 0)
|
|
575
|
+
return data;
|
|
576
|
+
if (filters.length !== 1 || filters[0].kind !== 'name' || filters[0].value !== 'FlateDecode') {
|
|
577
|
+
throw unsupported('a stream this reader must decode uses a filter other than FlateDecode');
|
|
578
|
+
}
|
|
579
|
+
let inflated;
|
|
580
|
+
try {
|
|
581
|
+
inflated = inflateSync(data);
|
|
582
|
+
}
|
|
583
|
+
catch {
|
|
584
|
+
throw unsupported('a FlateDecode stream that does not inflate');
|
|
585
|
+
}
|
|
586
|
+
const parmsObject = dict.entries.get('DecodeParms');
|
|
587
|
+
const parms = parmsObject?.kind === 'array' ? parmsObject.items[0] : parmsObject;
|
|
588
|
+
const predictor = parms?.kind === 'dict' ? numberOf(parms.entries.get('Predictor')) ?? 1 : 1;
|
|
589
|
+
if (predictor === 1)
|
|
590
|
+
return inflated;
|
|
591
|
+
if (predictor < 10)
|
|
592
|
+
throw unsupported(`a stream with predictor ${predictor}`);
|
|
593
|
+
const params = parms;
|
|
594
|
+
const columns = numberOf(params.entries.get('Columns')) ?? 1;
|
|
595
|
+
const colors = numberOf(params.entries.get('Colors')) ?? 1;
|
|
596
|
+
const bits = numberOf(params.entries.get('BitsPerComponent')) ?? 8;
|
|
597
|
+
const bytesPerPixel = Math.max(1, Math.ceil((colors * bits) / 8));
|
|
598
|
+
const rowLength = Math.ceil((columns * colors * bits) / 8);
|
|
599
|
+
const rows = Math.floor(inflated.length / (rowLength + 1));
|
|
600
|
+
const out = Buffer.alloc(rows * rowLength);
|
|
601
|
+
for (let row = 0; row < rows; row += 1) {
|
|
602
|
+
const type = inflated[row * (rowLength + 1)];
|
|
603
|
+
const source = row * (rowLength + 1) + 1;
|
|
604
|
+
for (let column = 0; column < rowLength; column += 1) {
|
|
605
|
+
const raw = inflated[source + column];
|
|
606
|
+
const left = column >= bytesPerPixel ? out[row * rowLength + column - bytesPerPixel] : 0;
|
|
607
|
+
const up = row > 0 ? out[(row - 1) * rowLength + column] : 0;
|
|
608
|
+
const upLeft = row > 0 && column >= bytesPerPixel ? out[(row - 1) * rowLength + column - bytesPerPixel] : 0;
|
|
609
|
+
let value;
|
|
610
|
+
switch (type) {
|
|
611
|
+
case 0:
|
|
612
|
+
value = raw;
|
|
613
|
+
break;
|
|
614
|
+
case 1:
|
|
615
|
+
value = raw + left;
|
|
616
|
+
break;
|
|
617
|
+
case 2:
|
|
618
|
+
value = raw + up;
|
|
619
|
+
break;
|
|
620
|
+
case 3:
|
|
621
|
+
value = raw + Math.floor((left + up) / 2);
|
|
622
|
+
break;
|
|
623
|
+
case 4: {
|
|
624
|
+
const estimate = left + up - upLeft;
|
|
625
|
+
const toLeft = Math.abs(estimate - left);
|
|
626
|
+
const toUp = Math.abs(estimate - up);
|
|
627
|
+
const toUpLeft = Math.abs(estimate - upLeft);
|
|
628
|
+
value = raw + (toLeft <= toUp && toLeft <= toUpLeft ? left : toUp <= toUpLeft ? up : upLeft);
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
default: throw unsupported(`a PNG predictor row of type ${type}`);
|
|
632
|
+
}
|
|
633
|
+
out[row * rowLength + column] = value & 0xff;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return out;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* The update section, appended after `prelude` (bytes the caller places first, a comment line). The trailer carries the
|
|
640
|
+
* previous one's `/Root`, `/Info` and `/ID` unchanged, a `/Size` past the highest object written, and `/Prev`; it is
|
|
641
|
+
* written in the form the latest section used, so a file read through cross-reference streams stays that way.
|
|
642
|
+
*/
|
|
643
|
+
export function appendPdfIncrementalUpdate(reader, prelude, objects) {
|
|
644
|
+
const base = reader.bytes.length;
|
|
645
|
+
const chunks = [Buffer.from(prelude, 'latin1')];
|
|
646
|
+
let position = base + chunks[0].length;
|
|
647
|
+
const offsets = new Map();
|
|
648
|
+
const write = (chunk) => { chunks.push(chunk); position += chunk.length; };
|
|
649
|
+
for (const object of [...objects].sort((first, second) => first.num - second.num)) {
|
|
650
|
+
offsets.set(object.num, { offset: position, gen: object.gen });
|
|
651
|
+
let value = object.value;
|
|
652
|
+
if (object.stream) {
|
|
653
|
+
if (value.kind !== 'dict')
|
|
654
|
+
throw new Error('A stream object needs a dictionary');
|
|
655
|
+
value = { kind: 'dict', entries: new Map([...value.entries, ['Length', pdf.int(object.stream.length)]]) };
|
|
656
|
+
}
|
|
657
|
+
write(Buffer.from(`${object.num} ${object.gen} obj\n${serializePdfObject(value)}\n`, 'latin1'));
|
|
658
|
+
if (object.stream) {
|
|
659
|
+
write(Buffer.from('stream\n', 'latin1'));
|
|
660
|
+
write(object.stream);
|
|
661
|
+
write(Buffer.from('\nendstream\n', 'latin1'));
|
|
662
|
+
}
|
|
663
|
+
write(Buffer.from('endobj\n', 'latin1'));
|
|
664
|
+
}
|
|
665
|
+
if (offsets.size === 0)
|
|
666
|
+
throw new Error('An update writes at least one object');
|
|
667
|
+
const highest = [...offsets.keys()].reduce((max, num) => Math.max(max, num), 0);
|
|
668
|
+
const kept = (name) => reader.trailer.entries.get(name);
|
|
669
|
+
const trailerEntries = (size) => ({
|
|
670
|
+
Size: pdf.int(size),
|
|
671
|
+
Root: kept('Root'),
|
|
672
|
+
Info: kept('Info'),
|
|
673
|
+
ID: kept('ID'),
|
|
674
|
+
Prev: pdf.int(reader.lastXrefOffset),
|
|
675
|
+
});
|
|
676
|
+
if (reader.lastXrefForm === PdfCrossReferenceForm.TABLE) {
|
|
677
|
+
const xrefOffset = position;
|
|
678
|
+
let table = 'xref\n';
|
|
679
|
+
for (const [first, nums] of contiguousRuns([...offsets.keys()])) {
|
|
680
|
+
table += `${first} ${nums.length}\n`;
|
|
681
|
+
for (const num of nums) {
|
|
682
|
+
const { offset, gen } = offsets.get(num);
|
|
683
|
+
table += `${String(offset).padStart(10, '0')} ${String(gen).padStart(5, '0')} n\r\n`;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
table += `trailer\n${serializePdfObject(pdf.dict(trailerEntries(Math.max(reader.size, highest + 1))))}\nstartxref\n${xrefOffset}\n%%EOF\n`;
|
|
687
|
+
write(Buffer.from(table, 'latin1'));
|
|
688
|
+
return Buffer.concat([reader.bytes, ...chunks]);
|
|
689
|
+
}
|
|
690
|
+
// A cross-reference stream: its own object comes last, and lists itself (§7.5.8.2).
|
|
691
|
+
const streamNum = Math.max(reader.size, highest + 1);
|
|
692
|
+
const xrefOffset = position;
|
|
693
|
+
offsets.set(streamNum, { offset: xrefOffset, gen: 0 });
|
|
694
|
+
if (xrefOffset > 0xffffffff)
|
|
695
|
+
throw unsupported('a file larger than 4 GiB');
|
|
696
|
+
const nums = [...offsets.keys()].sort((first, second) => first - second);
|
|
697
|
+
const index = [];
|
|
698
|
+
const rows = [];
|
|
699
|
+
for (const [first, run] of contiguousRuns(nums)) {
|
|
700
|
+
index.push(pdf.int(first), pdf.int(run.length));
|
|
701
|
+
for (const num of run) {
|
|
702
|
+
const { offset, gen } = offsets.get(num);
|
|
703
|
+
const row = Buffer.alloc(7);
|
|
704
|
+
row[0] = 1;
|
|
705
|
+
row.writeUInt32BE(offset, 1);
|
|
706
|
+
row.writeUInt16BE(gen, 5);
|
|
707
|
+
rows.push(row);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const data = Buffer.concat(rows);
|
|
711
|
+
const dict = pdf.dict({ Type: pdf.name('XRef'), ...trailerEntries(streamNum + 1), W: pdf.array([pdf.int(1), pdf.int(4), pdf.int(2)]), Index: pdf.array(index), Length: pdf.int(data.length) });
|
|
712
|
+
write(Buffer.from(`${streamNum} 0 obj\n${serializePdfObject(dict)}\nstream\n`, 'latin1'));
|
|
713
|
+
write(data);
|
|
714
|
+
write(Buffer.from(`\nendstream\nendobj\nstartxref\n${xrefOffset}\n%%EOF\n`, 'latin1'));
|
|
715
|
+
return Buffer.concat([reader.bytes, ...chunks]);
|
|
716
|
+
}
|
|
717
|
+
/** Sorted numbers grouped into runs of consecutive values: each run is one cross-reference subsection. */
|
|
718
|
+
function contiguousRuns(nums) {
|
|
719
|
+
const sorted = [...nums].sort((first, second) => first - second);
|
|
720
|
+
const runs = [];
|
|
721
|
+
for (const num of sorted) {
|
|
722
|
+
const last = runs[runs.length - 1];
|
|
723
|
+
if (last && last[1][last[1].length - 1] === num - 1)
|
|
724
|
+
last[1].push(num);
|
|
725
|
+
else
|
|
726
|
+
runs.push([num, [num]]);
|
|
727
|
+
}
|
|
728
|
+
return runs;
|
|
729
|
+
}
|
|
730
|
+
//# sourceMappingURL=pdf-incremental-update.js.map
|