@chipmobilesdk/rn-local-db 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/README.md +69 -8
- package/lib/commonjs/adapter/budgets.js +79 -0
- package/lib/commonjs/adapter/budgets.js.map +1 -0
- package/lib/commonjs/adapter/collection.js +236 -0
- package/lib/commonjs/adapter/collection.js.map +1 -0
- package/lib/commonjs/adapter/deletion.js +291 -0
- package/lib/commonjs/adapter/deletion.js.map +1 -0
- package/lib/commonjs/adapter/handle.js +259 -0
- package/lib/commonjs/adapter/handle.js.map +1 -0
- package/lib/commonjs/adapter/index.js +67 -0
- package/lib/commonjs/adapter/index.js.map +1 -0
- package/lib/commonjs/adapter/lifecycle.js +176 -0
- package/lib/commonjs/adapter/lifecycle.js.map +1 -0
- package/lib/commonjs/adapter/schema-sync.js +124 -0
- package/lib/commonjs/adapter/schema-sync.js.map +1 -0
- package/lib/commonjs/adapter/transaction.js +58 -0
- package/lib/commonjs/adapter/transaction.js.map +1 -0
- package/lib/commonjs/artifacts/availability.js +90 -0
- package/lib/commonjs/artifacts/availability.js.map +1 -0
- package/lib/commonjs/artifacts/cascade.js +80 -0
- package/lib/commonjs/artifacts/cascade.js.map +1 -0
- package/lib/commonjs/artifacts/paths.js +31 -0
- package/lib/commonjs/artifacts/paths.js.map +1 -0
- package/lib/commonjs/artifacts/reconcile.js +55 -0
- package/lib/commonjs/artifacts/reconcile.js.map +1 -0
- package/lib/commonjs/artifacts/store.js +300 -0
- package/lib/commonjs/artifacts/store.js.map +1 -0
- package/lib/commonjs/contract/adapter.js +6 -0
- package/lib/commonjs/contract/adapter.js.map +1 -0
- package/lib/commonjs/contract/attachment.js +2 -0
- package/lib/commonjs/contract/attachment.js.map +1 -0
- package/lib/commonjs/contract/backup.js +2 -0
- package/lib/commonjs/contract/backup.js.map +1 -0
- package/lib/commonjs/contract/config.js +31 -0
- package/lib/commonjs/contract/config.js.map +1 -0
- package/lib/commonjs/contract/encryption.js +6 -0
- package/lib/commonjs/contract/encryption.js.map +1 -0
- package/lib/commonjs/contract/errors.js +64 -0
- package/lib/commonjs/contract/errors.js.map +1 -0
- package/lib/commonjs/contract/migration.js +6 -0
- package/lib/commonjs/contract/migration.js.map +1 -0
- package/lib/commonjs/contract/query.js +6 -0
- package/lib/commonjs/contract/query.js.map +1 -0
- package/lib/commonjs/contract/record.js +6 -0
- package/lib/commonjs/contract/record.js.map +1 -0
- package/lib/commonjs/contract/schema.js +2 -0
- package/lib/commonjs/contract/schema.js.map +1 -0
- package/lib/commonjs/contract/scope.js +2 -0
- package/lib/commonjs/contract/scope.js.map +1 -0
- package/lib/commonjs/contract/transaction.js +6 -0
- package/lib/commonjs/contract/transaction.js.map +1 -0
- package/lib/commonjs/crypto/chunked-cipher.js +147 -0
- package/lib/commonjs/crypto/chunked-cipher.js.map +1 -0
- package/lib/commonjs/crypto/derive.js +61 -0
- package/lib/commonjs/crypto/derive.js.map +1 -0
- package/lib/commonjs/crypto/key-provider.js +70 -0
- package/lib/commonjs/crypto/key-provider.js.map +1 -0
- package/lib/commonjs/crypto/provider.js +54 -0
- package/lib/commonjs/crypto/provider.js.map +1 -0
- package/lib/commonjs/diagnostics/dev-log.js +127 -0
- package/lib/commonjs/diagnostics/dev-log.js.map +1 -0
- package/lib/commonjs/diagnostics/errors.js +57 -0
- package/lib/commonjs/diagnostics/errors.js.map +1 -0
- package/lib/commonjs/diagnostics/faults.js +54 -0
- package/lib/commonjs/diagnostics/faults.js.map +1 -0
- package/lib/commonjs/diagnostics/map-native.js +98 -0
- package/lib/commonjs/diagnostics/map-native.js.map +1 -0
- package/lib/commonjs/diagnostics/redact.js +110 -0
- package/lib/commonjs/diagnostics/redact.js.map +1 -0
- package/lib/commonjs/index.js +70 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/migration/executor.js +136 -0
- package/lib/commonjs/migration/executor.js.map +1 -0
- package/lib/commonjs/migration/ledger.js +64 -0
- package/lib/commonjs/migration/ledger.js.map +1 -0
- package/lib/commonjs/migration/validate-chain.js +76 -0
- package/lib/commonjs/migration/validate-chain.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/platform/backup-android-verify.js +76 -0
- package/lib/commonjs/platform/backup-android-verify.js.map +1 -0
- package/lib/commonjs/platform/backup-ios.js +50 -0
- package/lib/commonjs/platform/backup-ios.js.map +1 -0
- package/lib/commonjs/platform/bytes.js +158 -0
- package/lib/commonjs/platform/bytes.js.map +1 -0
- package/lib/commonjs/platform/fs.js +59 -0
- package/lib/commonjs/platform/fs.js.map +1 -0
- package/lib/commonjs/platform/location.js +129 -0
- package/lib/commonjs/platform/location.js.map +1 -0
- package/lib/commonjs/query/budgets.js +95 -0
- package/lib/commonjs/query/budgets.js.map +1 -0
- package/lib/commonjs/query/compare.js +97 -0
- package/lib/commonjs/query/compare.js.map +1 -0
- package/lib/commonjs/query/cursor.js +97 -0
- package/lib/commonjs/query/cursor.js.map +1 -0
- package/lib/commonjs/query/filter.js +82 -0
- package/lib/commonjs/query/filter.js.map +1 -0
- package/lib/commonjs/query/paginate.js +48 -0
- package/lib/commonjs/query/paginate.js.map +1 -0
- package/lib/commonjs/query/sort.js +61 -0
- package/lib/commonjs/query/sort.js.map +1 -0
- package/lib/commonjs/query/validate.js +180 -0
- package/lib/commonjs/query/validate.js.map +1 -0
- package/lib/commonjs/schema/declare.js +47 -0
- package/lib/commonjs/schema/declare.js.map +1 -0
- package/lib/commonjs/schema/validate-config.js +115 -0
- package/lib/commonjs/schema/validate-config.js.map +1 -0
- package/lib/commonjs/scope/hash.js +107 -0
- package/lib/commonjs/scope/hash.js.map +1 -0
- package/lib/commonjs/scope/normalize.js +73 -0
- package/lib/commonjs/scope/normalize.js.map +1 -0
- package/lib/commonjs/scope/validate.js +81 -0
- package/lib/commonjs/scope/validate.js.map +1 -0
- package/lib/commonjs/sqlite/adapter.js +31 -0
- package/lib/commonjs/sqlite/adapter.js.map +1 -0
- package/lib/commonjs/sqlite/batch.js +218 -0
- package/lib/commonjs/sqlite/batch.js.map +1 -0
- package/lib/commonjs/sqlite/catalog.js +81 -0
- package/lib/commonjs/sqlite/catalog.js.map +1 -0
- package/lib/commonjs/sqlite/connection.js +210 -0
- package/lib/commonjs/sqlite/connection.js.map +1 -0
- package/lib/commonjs/sqlite/index-coverage.js +42 -0
- package/lib/commonjs/sqlite/index-coverage.js.map +1 -0
- package/lib/commonjs/sqlite/native.js +54 -0
- package/lib/commonjs/sqlite/native.js.map +1 -0
- package/lib/commonjs/sqlite/row-codec.js +192 -0
- package/lib/commonjs/sqlite/row-codec.js.map +1 -0
- package/lib/commonjs/sqlite/sql-builder.js +253 -0
- package/lib/commonjs/sqlite/sql-builder.js.map +1 -0
- package/lib/commonjs/sqlite/statements.js +54 -0
- package/lib/commonjs/sqlite/statements.js.map +1 -0
- package/lib/commonjs/sqlite/transaction-queue.js +79 -0
- package/lib/commonjs/sqlite/transaction-queue.js.map +1 -0
- package/lib/commonjs/sqlite/transactions.js +33 -0
- package/lib/commonjs/sqlite/transactions.js.map +1 -0
- package/lib/commonjs/sqlite/values.js +31 -0
- package/lib/commonjs/sqlite/values.js.map +1 -0
- package/lib/commonjs/testing/conformance/attachments.js +180 -0
- package/lib/commonjs/testing/conformance/attachments.js.map +1 -0
- package/lib/commonjs/testing/conformance/encryption.js +187 -0
- package/lib/commonjs/testing/conformance/encryption.js.map +1 -0
- package/lib/commonjs/testing/conformance/index.js +103 -0
- package/lib/commonjs/testing/conformance/index.js.map +1 -0
- package/lib/commonjs/testing/conformance/lifecycle.js +134 -0
- package/lib/commonjs/testing/conformance/lifecycle.js.map +1 -0
- package/lib/commonjs/testing/conformance/migrations.js +167 -0
- package/lib/commonjs/testing/conformance/migrations.js.map +1 -0
- package/lib/commonjs/testing/conformance/queries.js +278 -0
- package/lib/commonjs/testing/conformance/queries.js.map +1 -0
- package/lib/commonjs/testing/conformance/records.js +224 -0
- package/lib/commonjs/testing/conformance/records.js.map +1 -0
- package/lib/commonjs/testing/conformance/scopes.js +107 -0
- package/lib/commonjs/testing/conformance/scopes.js.map +1 -0
- package/lib/commonjs/testing/conformance/transactions.js +228 -0
- package/lib/commonjs/testing/conformance/transactions.js.map +1 -0
- package/lib/commonjs/testing/faults.js +38 -0
- package/lib/commonjs/testing/faults.js.map +1 -0
- package/lib/commonjs/testing/index.js +59 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/testing/memory-adapter/attachments.js +145 -0
- package/lib/commonjs/testing/memory-adapter/attachments.js.map +1 -0
- package/lib/commonjs/testing/memory-adapter/collection.js +224 -0
- package/lib/commonjs/testing/memory-adapter/collection.js.map +1 -0
- package/lib/commonjs/testing/memory-adapter/index.js +366 -0
- package/lib/commonjs/testing/memory-adapter/index.js.map +1 -0
- package/lib/commonjs/testing/memory-adapter/migrations.js +126 -0
- package/lib/commonjs/testing/memory-adapter/migrations.js.map +1 -0
- package/lib/commonjs/testing/memory-adapter/reset.js +49 -0
- package/lib/commonjs/testing/memory-adapter/reset.js.map +1 -0
- package/lib/commonjs/testing/memory-adapter/store.js +107 -0
- package/lib/commonjs/testing/memory-adapter/store.js.map +1 -0
- package/lib/module/adapter/budgets.js +51 -0
- package/lib/module/adapter/budgets.js.map +1 -0
- package/lib/module/adapter/collection.js +232 -0
- package/lib/module/adapter/collection.js.map +1 -0
- package/lib/module/adapter/deletion.js +280 -0
- package/lib/module/adapter/deletion.js.map +1 -0
- package/lib/module/adapter/handle.js +254 -0
- package/lib/module/adapter/handle.js.map +1 -0
- package/lib/module/adapter/index.js +59 -0
- package/lib/module/adapter/index.js.map +1 -0
- package/lib/module/adapter/lifecycle.js +172 -0
- package/lib/module/adapter/lifecycle.js.map +1 -0
- package/lib/module/adapter/schema-sync.js +121 -0
- package/lib/module/adapter/schema-sync.js.map +1 -0
- package/lib/module/adapter/transaction.js +54 -0
- package/lib/module/adapter/transaction.js.map +1 -0
- package/lib/module/artifacts/availability.js +86 -0
- package/lib/module/artifacts/availability.js.map +1 -0
- package/lib/module/artifacts/cascade.js +75 -0
- package/lib/module/artifacts/cascade.js.map +1 -0
- package/lib/module/artifacts/paths.js +26 -0
- package/lib/module/artifacts/paths.js.map +1 -0
- package/lib/module/artifacts/reconcile.js +51 -0
- package/lib/module/artifacts/reconcile.js.map +1 -0
- package/lib/module/artifacts/store.js +289 -0
- package/lib/module/artifacts/store.js.map +1 -0
- package/lib/module/contract/adapter.js +4 -0
- package/lib/module/contract/adapter.js.map +1 -0
- package/lib/module/contract/attachment.js +2 -0
- package/lib/module/contract/attachment.js.map +1 -0
- package/lib/module/contract/backup.js +2 -0
- package/lib/module/contract/backup.js.map +1 -0
- package/lib/module/contract/config.js +27 -0
- package/lib/module/contract/config.js.map +1 -0
- package/lib/module/contract/encryption.js +4 -0
- package/lib/module/contract/encryption.js.map +1 -0
- package/lib/module/contract/errors.js +60 -0
- package/lib/module/contract/errors.js.map +1 -0
- package/lib/module/contract/migration.js +4 -0
- package/lib/module/contract/migration.js.map +1 -0
- package/lib/module/contract/query.js +4 -0
- package/lib/module/contract/query.js.map +1 -0
- package/lib/module/contract/record.js +4 -0
- package/lib/module/contract/record.js.map +1 -0
- package/lib/module/contract/schema.js +2 -0
- package/lib/module/contract/schema.js.map +1 -0
- package/lib/module/contract/scope.js +2 -0
- package/lib/module/contract/scope.js.map +1 -0
- package/lib/module/contract/transaction.js +4 -0
- package/lib/module/contract/transaction.js.map +1 -0
- package/lib/module/crypto/chunked-cipher.js +134 -0
- package/lib/module/crypto/chunked-cipher.js.map +1 -0
- package/lib/module/crypto/derive.js +56 -0
- package/lib/module/crypto/derive.js.map +1 -0
- package/lib/module/crypto/key-provider.js +67 -0
- package/lib/module/crypto/key-provider.js.map +1 -0
- package/lib/module/crypto/provider.js +49 -0
- package/lib/module/crypto/provider.js.map +1 -0
- package/lib/module/diagnostics/dev-log.js +120 -0
- package/lib/module/diagnostics/dev-log.js.map +1 -0
- package/lib/module/diagnostics/errors.js +44 -0
- package/lib/module/diagnostics/errors.js.map +1 -0
- package/lib/module/diagnostics/faults.js +47 -0
- package/lib/module/diagnostics/faults.js.map +1 -0
- package/lib/module/diagnostics/map-native.js +93 -0
- package/lib/module/diagnostics/map-native.js.map +1 -0
- package/lib/module/diagnostics/redact.js +102 -0
- package/lib/module/diagnostics/redact.js.map +1 -0
- package/lib/module/index.js +28 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/migration/executor.js +132 -0
- package/lib/module/migration/executor.js.map +1 -0
- package/lib/module/migration/ledger.js +57 -0
- package/lib/module/migration/ledger.js.map +1 -0
- package/lib/module/migration/validate-chain.js +70 -0
- package/lib/module/migration/validate-chain.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/platform/backup-android-verify.js +69 -0
- package/lib/module/platform/backup-android-verify.js.map +1 -0
- package/lib/module/platform/backup-ios.js +44 -0
- package/lib/module/platform/backup-ios.js.map +1 -0
- package/lib/module/platform/bytes.js +148 -0
- package/lib/module/platform/bytes.js.map +1 -0
- package/lib/module/platform/fs.js +54 -0
- package/lib/module/platform/fs.js.map +1 -0
- package/lib/module/platform/location.js +120 -0
- package/lib/module/platform/location.js.map +1 -0
- package/lib/module/query/budgets.js +88 -0
- package/lib/module/query/budgets.js.map +1 -0
- package/lib/module/query/compare.js +90 -0
- package/lib/module/query/compare.js.map +1 -0
- package/lib/module/query/cursor.js +91 -0
- package/lib/module/query/cursor.js.map +1 -0
- package/lib/module/query/filter.js +78 -0
- package/lib/module/query/filter.js.map +1 -0
- package/lib/module/query/paginate.js +40 -0
- package/lib/module/query/paginate.js.map +1 -0
- package/lib/module/query/sort.js +53 -0
- package/lib/module/query/sort.js.map +1 -0
- package/lib/module/query/validate.js +173 -0
- package/lib/module/query/validate.js.map +1 -0
- package/lib/module/schema/declare.js +37 -0
- package/lib/module/schema/declare.js.map +1 -0
- package/lib/module/schema/validate-config.js +111 -0
- package/lib/module/schema/validate-config.js.map +1 -0
- package/lib/module/scope/hash.js +102 -0
- package/lib/module/scope/hash.js.map +1 -0
- package/lib/module/scope/normalize.js +67 -0
- package/lib/module/scope/normalize.js.map +1 -0
- package/lib/module/scope/validate.js +76 -0
- package/lib/module/scope/validate.js.map +1 -0
- package/lib/module/sqlite/adapter.js +27 -0
- package/lib/module/sqlite/adapter.js.map +1 -0
- package/lib/module/sqlite/batch.js +214 -0
- package/lib/module/sqlite/batch.js.map +1 -0
- package/lib/module/sqlite/catalog.js +72 -0
- package/lib/module/sqlite/catalog.js.map +1 -0
- package/lib/module/sqlite/connection.js +206 -0
- package/lib/module/sqlite/connection.js.map +1 -0
- package/lib/module/sqlite/index-coverage.js +38 -0
- package/lib/module/sqlite/index-coverage.js.map +1 -0
- package/lib/module/sqlite/native.js +48 -0
- package/lib/module/sqlite/native.js.map +1 -0
- package/lib/module/sqlite/row-codec.js +176 -0
- package/lib/module/sqlite/row-codec.js.map +1 -0
- package/lib/module/sqlite/sql-builder.js +247 -0
- package/lib/module/sqlite/sql-builder.js.map +1 -0
- package/lib/module/sqlite/statements.js +49 -0
- package/lib/module/sqlite/statements.js.map +1 -0
- package/lib/module/sqlite/transaction-queue.js +75 -0
- package/lib/module/sqlite/transaction-queue.js.map +1 -0
- package/lib/module/sqlite/transactions.js +29 -0
- package/lib/module/sqlite/transactions.js.map +1 -0
- package/lib/module/sqlite/values.js +24 -0
- package/lib/module/sqlite/values.js.map +1 -0
- package/lib/module/testing/conformance/attachments.js +176 -0
- package/lib/module/testing/conformance/attachments.js.map +1 -0
- package/lib/module/testing/conformance/encryption.js +183 -0
- package/lib/module/testing/conformance/encryption.js.map +1 -0
- package/lib/module/testing/conformance/index.js +97 -0
- package/lib/module/testing/conformance/index.js.map +1 -0
- package/lib/module/testing/conformance/lifecycle.js +130 -0
- package/lib/module/testing/conformance/lifecycle.js.map +1 -0
- package/lib/module/testing/conformance/migrations.js +163 -0
- package/lib/module/testing/conformance/migrations.js.map +1 -0
- package/lib/module/testing/conformance/queries.js +274 -0
- package/lib/module/testing/conformance/queries.js.map +1 -0
- package/lib/module/testing/conformance/records.js +220 -0
- package/lib/module/testing/conformance/records.js.map +1 -0
- package/lib/module/testing/conformance/scopes.js +103 -0
- package/lib/module/testing/conformance/scopes.js.map +1 -0
- package/lib/module/testing/conformance/transactions.js +224 -0
- package/lib/module/testing/conformance/transactions.js.map +1 -0
- package/lib/module/testing/faults.js +16 -0
- package/lib/module/testing/faults.js.map +1 -0
- package/lib/module/testing/index.js +16 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/module/testing/memory-adapter/attachments.js +142 -0
- package/lib/module/testing/memory-adapter/attachments.js.map +1 -0
- package/lib/module/testing/memory-adapter/collection.js +220 -0
- package/lib/module/testing/memory-adapter/collection.js.map +1 -0
- package/lib/module/testing/memory-adapter/index.js +351 -0
- package/lib/module/testing/memory-adapter/index.js.map +1 -0
- package/lib/module/testing/memory-adapter/migrations.js +122 -0
- package/lib/module/testing/memory-adapter/migrations.js.map +1 -0
- package/lib/module/testing/memory-adapter/reset.js +44 -0
- package/lib/module/testing/memory-adapter/reset.js.map +1 -0
- package/lib/module/testing/memory-adapter/store.js +94 -0
- package/lib/module/testing/memory-adapter/store.js.map +1 -0
- package/lib/typescript/commonjs/adapter/budgets.d.ts +19 -0
- package/lib/typescript/commonjs/adapter/budgets.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/collection.d.ts +25 -0
- package/lib/typescript/commonjs/adapter/collection.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/deletion.d.ts +48 -0
- package/lib/typescript/commonjs/adapter/deletion.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/handle.d.ts +30 -0
- package/lib/typescript/commonjs/adapter/handle.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/index.d.ts +30 -0
- package/lib/typescript/commonjs/adapter/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/lifecycle.d.ts +25 -0
- package/lib/typescript/commonjs/adapter/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/schema-sync.d.ts +19 -0
- package/lib/typescript/commonjs/adapter/schema-sync.d.ts.map +1 -0
- package/lib/typescript/commonjs/adapter/transaction.d.ts +32 -0
- package/lib/typescript/commonjs/adapter/transaction.d.ts.map +1 -0
- package/lib/typescript/commonjs/artifacts/availability.d.ts +19 -0
- package/lib/typescript/commonjs/artifacts/availability.d.ts.map +1 -0
- package/lib/typescript/commonjs/artifacts/cascade.d.ts +26 -0
- package/lib/typescript/commonjs/artifacts/cascade.d.ts.map +1 -0
- package/lib/typescript/commonjs/artifacts/paths.d.ts +16 -0
- package/lib/typescript/commonjs/artifacts/paths.d.ts.map +1 -0
- package/lib/typescript/commonjs/artifacts/reconcile.d.ts +23 -0
- package/lib/typescript/commonjs/artifacts/reconcile.d.ts.map +1 -0
- package/lib/typescript/commonjs/artifacts/store.d.ts +45 -0
- package/lib/typescript/commonjs/artifacts/store.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/adapter.d.ts +55 -0
- package/lib/typescript/commonjs/contract/adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/attachment.d.ts +84 -0
- package/lib/typescript/commonjs/contract/attachment.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/backup.d.ts +26 -0
- package/lib/typescript/commonjs/contract/backup.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/config.d.ts +50 -0
- package/lib/typescript/commonjs/contract/config.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/encryption.d.ts +31 -0
- package/lib/typescript/commonjs/contract/encryption.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/errors.d.ts +50 -0
- package/lib/typescript/commonjs/contract/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/migration.d.ts +37 -0
- package/lib/typescript/commonjs/contract/migration.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/query.d.ts +79 -0
- package/lib/typescript/commonjs/contract/query.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/record.d.ts +43 -0
- package/lib/typescript/commonjs/contract/record.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/schema.d.ts +33 -0
- package/lib/typescript/commonjs/contract/schema.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/scope.d.ts +33 -0
- package/lib/typescript/commonjs/contract/scope.d.ts.map +1 -0
- package/lib/typescript/commonjs/contract/transaction.d.ts +66 -0
- package/lib/typescript/commonjs/contract/transaction.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/chunked-cipher.d.ts +57 -0
- package/lib/typescript/commonjs/crypto/chunked-cipher.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/derive.d.ts +28 -0
- package/lib/typescript/commonjs/crypto/derive.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/key-provider.d.ts +30 -0
- package/lib/typescript/commonjs/crypto/key-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/crypto/provider.d.ts +35 -0
- package/lib/typescript/commonjs/crypto/provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/dev-log.d.ts +35 -0
- package/lib/typescript/commonjs/diagnostics/dev-log.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts +34 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/faults.d.ts +26 -0
- package/lib/typescript/commonjs/diagnostics/faults.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/map-native.d.ts +31 -0
- package/lib/typescript/commonjs/diagnostics/map-native.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/redact.d.ts +70 -0
- package/lib/typescript/commonjs/diagnostics/redact.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +30 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/migration/executor.d.ts +40 -0
- package/lib/typescript/commonjs/migration/executor.d.ts.map +1 -0
- package/lib/typescript/commonjs/migration/ledger.d.ts +34 -0
- package/lib/typescript/commonjs/migration/ledger.d.ts.map +1 -0
- package/lib/typescript/commonjs/migration/validate-chain.d.ts +20 -0
- package/lib/typescript/commonjs/migration/validate-chain.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/platform/backup-android-verify.d.ts +30 -0
- package/lib/typescript/commonjs/platform/backup-android-verify.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/backup-ios.d.ts +26 -0
- package/lib/typescript/commonjs/platform/backup-ios.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/bytes.d.ts +36 -0
- package/lib/typescript/commonjs/platform/bytes.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/fs.d.ts +47 -0
- package/lib/typescript/commonjs/platform/fs.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/location.d.ts +53 -0
- package/lib/typescript/commonjs/platform/location.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/budgets.d.ts +23 -0
- package/lib/typescript/commonjs/query/budgets.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/compare.d.ts +42 -0
- package/lib/typescript/commonjs/query/compare.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/cursor.d.ts +27 -0
- package/lib/typescript/commonjs/query/cursor.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/filter.d.ts +11 -0
- package/lib/typescript/commonjs/query/filter.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/paginate.d.ts +15 -0
- package/lib/typescript/commonjs/query/paginate.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/sort.d.ts +19 -0
- package/lib/typescript/commonjs/query/sort.d.ts.map +1 -0
- package/lib/typescript/commonjs/query/validate.d.ts +15 -0
- package/lib/typescript/commonjs/query/validate.d.ts.map +1 -0
- package/lib/typescript/commonjs/schema/declare.d.ts +20 -0
- package/lib/typescript/commonjs/schema/declare.d.ts.map +1 -0
- package/lib/typescript/commonjs/schema/validate-config.d.ts +11 -0
- package/lib/typescript/commonjs/schema/validate-config.d.ts.map +1 -0
- package/lib/typescript/commonjs/scope/hash.d.ts +24 -0
- package/lib/typescript/commonjs/scope/hash.d.ts.map +1 -0
- package/lib/typescript/commonjs/scope/normalize.d.ts +46 -0
- package/lib/typescript/commonjs/scope/normalize.d.ts.map +1 -0
- package/lib/typescript/commonjs/scope/validate.d.ts +15 -0
- package/lib/typescript/commonjs/scope/validate.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/adapter.d.ts +16 -0
- package/lib/typescript/commonjs/sqlite/adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/batch.d.ts +25 -0
- package/lib/typescript/commonjs/sqlite/batch.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/catalog.d.ts +34 -0
- package/lib/typescript/commonjs/sqlite/catalog.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/connection.d.ts +58 -0
- package/lib/typescript/commonjs/sqlite/connection.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/index-coverage.d.ts +18 -0
- package/lib/typescript/commonjs/sqlite/index-coverage.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/native.d.ts +48 -0
- package/lib/typescript/commonjs/sqlite/native.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/row-codec.d.ts +69 -0
- package/lib/typescript/commonjs/sqlite/row-codec.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/sql-builder.d.ts +34 -0
- package/lib/typescript/commonjs/sqlite/sql-builder.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/statements.d.ts +26 -0
- package/lib/typescript/commonjs/sqlite/statements.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/transaction-queue.d.ts +31 -0
- package/lib/typescript/commonjs/sqlite/transaction-queue.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/transactions.d.ts +26 -0
- package/lib/typescript/commonjs/sqlite/transactions.d.ts.map +1 -0
- package/lib/typescript/commonjs/sqlite/values.d.ts +13 -0
- package/lib/typescript/commonjs/sqlite/values.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/attachments.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/attachments.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/encryption.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/encryption.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/index.d.ts +58 -0
- package/lib/typescript/commonjs/testing/conformance/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/lifecycle.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/lifecycle.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/migrations.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/migrations.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/queries.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/queries.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/records.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/records.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/scopes.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/scopes.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance/transactions.d.ts +4 -0
- package/lib/typescript/commonjs/testing/conformance/transactions.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/faults.d.ts +13 -0
- package/lib/typescript/commonjs/testing/faults.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +13 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/memory-adapter/attachments.d.ts +23 -0
- package/lib/typescript/commonjs/testing/memory-adapter/attachments.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/memory-adapter/collection.d.ts +19 -0
- package/lib/typescript/commonjs/testing/memory-adapter/collection.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/memory-adapter/index.d.ts +22 -0
- package/lib/typescript/commonjs/testing/memory-adapter/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/memory-adapter/migrations.d.ts +11 -0
- package/lib/typescript/commonjs/testing/memory-adapter/migrations.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/memory-adapter/reset.d.ts +23 -0
- package/lib/typescript/commonjs/testing/memory-adapter/reset.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/memory-adapter/store.d.ts +54 -0
- package/lib/typescript/commonjs/testing/memory-adapter/store.d.ts.map +1 -0
- package/lib/typescript/module/adapter/budgets.d.ts +19 -0
- package/lib/typescript/module/adapter/budgets.d.ts.map +1 -0
- package/lib/typescript/module/adapter/collection.d.ts +25 -0
- package/lib/typescript/module/adapter/collection.d.ts.map +1 -0
- package/lib/typescript/module/adapter/deletion.d.ts +48 -0
- package/lib/typescript/module/adapter/deletion.d.ts.map +1 -0
- package/lib/typescript/module/adapter/handle.d.ts +30 -0
- package/lib/typescript/module/adapter/handle.d.ts.map +1 -0
- package/lib/typescript/module/adapter/index.d.ts +30 -0
- package/lib/typescript/module/adapter/index.d.ts.map +1 -0
- package/lib/typescript/module/adapter/lifecycle.d.ts +25 -0
- package/lib/typescript/module/adapter/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/adapter/schema-sync.d.ts +19 -0
- package/lib/typescript/module/adapter/schema-sync.d.ts.map +1 -0
- package/lib/typescript/module/adapter/transaction.d.ts +32 -0
- package/lib/typescript/module/adapter/transaction.d.ts.map +1 -0
- package/lib/typescript/module/artifacts/availability.d.ts +19 -0
- package/lib/typescript/module/artifacts/availability.d.ts.map +1 -0
- package/lib/typescript/module/artifacts/cascade.d.ts +26 -0
- package/lib/typescript/module/artifacts/cascade.d.ts.map +1 -0
- package/lib/typescript/module/artifacts/paths.d.ts +16 -0
- package/lib/typescript/module/artifacts/paths.d.ts.map +1 -0
- package/lib/typescript/module/artifacts/reconcile.d.ts +23 -0
- package/lib/typescript/module/artifacts/reconcile.d.ts.map +1 -0
- package/lib/typescript/module/artifacts/store.d.ts +45 -0
- package/lib/typescript/module/artifacts/store.d.ts.map +1 -0
- package/lib/typescript/module/contract/adapter.d.ts +55 -0
- package/lib/typescript/module/contract/adapter.d.ts.map +1 -0
- package/lib/typescript/module/contract/attachment.d.ts +84 -0
- package/lib/typescript/module/contract/attachment.d.ts.map +1 -0
- package/lib/typescript/module/contract/backup.d.ts +26 -0
- package/lib/typescript/module/contract/backup.d.ts.map +1 -0
- package/lib/typescript/module/contract/config.d.ts +50 -0
- package/lib/typescript/module/contract/config.d.ts.map +1 -0
- package/lib/typescript/module/contract/encryption.d.ts +31 -0
- package/lib/typescript/module/contract/encryption.d.ts.map +1 -0
- package/lib/typescript/module/contract/errors.d.ts +50 -0
- package/lib/typescript/module/contract/errors.d.ts.map +1 -0
- package/lib/typescript/module/contract/migration.d.ts +37 -0
- package/lib/typescript/module/contract/migration.d.ts.map +1 -0
- package/lib/typescript/module/contract/query.d.ts +79 -0
- package/lib/typescript/module/contract/query.d.ts.map +1 -0
- package/lib/typescript/module/contract/record.d.ts +43 -0
- package/lib/typescript/module/contract/record.d.ts.map +1 -0
- package/lib/typescript/module/contract/schema.d.ts +33 -0
- package/lib/typescript/module/contract/schema.d.ts.map +1 -0
- package/lib/typescript/module/contract/scope.d.ts +33 -0
- package/lib/typescript/module/contract/scope.d.ts.map +1 -0
- package/lib/typescript/module/contract/transaction.d.ts +66 -0
- package/lib/typescript/module/contract/transaction.d.ts.map +1 -0
- package/lib/typescript/module/crypto/chunked-cipher.d.ts +57 -0
- package/lib/typescript/module/crypto/chunked-cipher.d.ts.map +1 -0
- package/lib/typescript/module/crypto/derive.d.ts +28 -0
- package/lib/typescript/module/crypto/derive.d.ts.map +1 -0
- package/lib/typescript/module/crypto/key-provider.d.ts +30 -0
- package/lib/typescript/module/crypto/key-provider.d.ts.map +1 -0
- package/lib/typescript/module/crypto/provider.d.ts +35 -0
- package/lib/typescript/module/crypto/provider.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/dev-log.d.ts +35 -0
- package/lib/typescript/module/diagnostics/dev-log.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/errors.d.ts +34 -0
- package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/faults.d.ts +26 -0
- package/lib/typescript/module/diagnostics/faults.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/map-native.d.ts +31 -0
- package/lib/typescript/module/diagnostics/map-native.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/redact.d.ts +70 -0
- package/lib/typescript/module/diagnostics/redact.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +30 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/migration/executor.d.ts +40 -0
- package/lib/typescript/module/migration/executor.d.ts.map +1 -0
- package/lib/typescript/module/migration/ledger.d.ts +34 -0
- package/lib/typescript/module/migration/ledger.d.ts.map +1 -0
- package/lib/typescript/module/migration/validate-chain.d.ts +20 -0
- package/lib/typescript/module/migration/validate-chain.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/platform/backup-android-verify.d.ts +30 -0
- package/lib/typescript/module/platform/backup-android-verify.d.ts.map +1 -0
- package/lib/typescript/module/platform/backup-ios.d.ts +26 -0
- package/lib/typescript/module/platform/backup-ios.d.ts.map +1 -0
- package/lib/typescript/module/platform/bytes.d.ts +36 -0
- package/lib/typescript/module/platform/bytes.d.ts.map +1 -0
- package/lib/typescript/module/platform/fs.d.ts +47 -0
- package/lib/typescript/module/platform/fs.d.ts.map +1 -0
- package/lib/typescript/module/platform/location.d.ts +53 -0
- package/lib/typescript/module/platform/location.d.ts.map +1 -0
- package/lib/typescript/module/query/budgets.d.ts +23 -0
- package/lib/typescript/module/query/budgets.d.ts.map +1 -0
- package/lib/typescript/module/query/compare.d.ts +42 -0
- package/lib/typescript/module/query/compare.d.ts.map +1 -0
- package/lib/typescript/module/query/cursor.d.ts +27 -0
- package/lib/typescript/module/query/cursor.d.ts.map +1 -0
- package/lib/typescript/module/query/filter.d.ts +11 -0
- package/lib/typescript/module/query/filter.d.ts.map +1 -0
- package/lib/typescript/module/query/paginate.d.ts +15 -0
- package/lib/typescript/module/query/paginate.d.ts.map +1 -0
- package/lib/typescript/module/query/sort.d.ts +19 -0
- package/lib/typescript/module/query/sort.d.ts.map +1 -0
- package/lib/typescript/module/query/validate.d.ts +15 -0
- package/lib/typescript/module/query/validate.d.ts.map +1 -0
- package/lib/typescript/module/schema/declare.d.ts +20 -0
- package/lib/typescript/module/schema/declare.d.ts.map +1 -0
- package/lib/typescript/module/schema/validate-config.d.ts +11 -0
- package/lib/typescript/module/schema/validate-config.d.ts.map +1 -0
- package/lib/typescript/module/scope/hash.d.ts +24 -0
- package/lib/typescript/module/scope/hash.d.ts.map +1 -0
- package/lib/typescript/module/scope/normalize.d.ts +46 -0
- package/lib/typescript/module/scope/normalize.d.ts.map +1 -0
- package/lib/typescript/module/scope/validate.d.ts +15 -0
- package/lib/typescript/module/scope/validate.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/adapter.d.ts +16 -0
- package/lib/typescript/module/sqlite/adapter.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/batch.d.ts +25 -0
- package/lib/typescript/module/sqlite/batch.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/catalog.d.ts +34 -0
- package/lib/typescript/module/sqlite/catalog.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/connection.d.ts +58 -0
- package/lib/typescript/module/sqlite/connection.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/index-coverage.d.ts +18 -0
- package/lib/typescript/module/sqlite/index-coverage.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/native.d.ts +48 -0
- package/lib/typescript/module/sqlite/native.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/row-codec.d.ts +69 -0
- package/lib/typescript/module/sqlite/row-codec.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/sql-builder.d.ts +34 -0
- package/lib/typescript/module/sqlite/sql-builder.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/statements.d.ts +26 -0
- package/lib/typescript/module/sqlite/statements.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/transaction-queue.d.ts +31 -0
- package/lib/typescript/module/sqlite/transaction-queue.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/transactions.d.ts +26 -0
- package/lib/typescript/module/sqlite/transactions.d.ts.map +1 -0
- package/lib/typescript/module/sqlite/values.d.ts +13 -0
- package/lib/typescript/module/sqlite/values.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/attachments.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/attachments.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/encryption.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/encryption.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/index.d.ts +58 -0
- package/lib/typescript/module/testing/conformance/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/lifecycle.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/lifecycle.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/migrations.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/migrations.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/queries.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/queries.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/records.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/records.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/scopes.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/scopes.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance/transactions.d.ts +4 -0
- package/lib/typescript/module/testing/conformance/transactions.d.ts.map +1 -0
- package/lib/typescript/module/testing/faults.d.ts +13 -0
- package/lib/typescript/module/testing/faults.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +13 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/memory-adapter/attachments.d.ts +23 -0
- package/lib/typescript/module/testing/memory-adapter/attachments.d.ts.map +1 -0
- package/lib/typescript/module/testing/memory-adapter/collection.d.ts +19 -0
- package/lib/typescript/module/testing/memory-adapter/collection.d.ts.map +1 -0
- package/lib/typescript/module/testing/memory-adapter/index.d.ts +22 -0
- package/lib/typescript/module/testing/memory-adapter/index.d.ts.map +1 -0
- package/lib/typescript/module/testing/memory-adapter/migrations.d.ts +11 -0
- package/lib/typescript/module/testing/memory-adapter/migrations.d.ts.map +1 -0
- package/lib/typescript/module/testing/memory-adapter/reset.d.ts +23 -0
- package/lib/typescript/module/testing/memory-adapter/reset.d.ts.map +1 -0
- package/lib/typescript/module/testing/memory-adapter/store.d.ts +54 -0
- package/lib/typescript/module/testing/memory-adapter/store.d.ts.map +1 -0
- package/package.json +51 -16
- package/src/crypto/provider.ts +7 -3
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Opening and closing a database.
|
|
5
|
+
*
|
|
6
|
+
* The order of operations here is the design, not an implementation detail:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Validate everything first.** Configuration, scope, and the migration
|
|
9
|
+
* chain are checked before a file is touched, so a developer error is
|
|
10
|
+
* reported against an untouched database (FR-006, FR-053).
|
|
11
|
+
* 2. **Consult the catalog before opening the scope file.** A posture
|
|
12
|
+
* mismatch is detectable there; discovering it from SQLCipher's "file is
|
|
13
|
+
* not a database" would report corruption for what is actually an app
|
|
14
|
+
* configuration change (FR-101).
|
|
15
|
+
* 3. **Migrate before returning.** Nothing observes a half-migrated schema,
|
|
16
|
+
* because there is no handle to observe it with until the chain completes
|
|
17
|
+
* (FR-055). A failure returns no handle at all (FR-050).
|
|
18
|
+
*
|
|
19
|
+
* The handle itself is built in `handle.ts`.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { DiagnosticCodes } from "../contract/errors.js";
|
|
23
|
+
import { acquireKey } from "../crypto/key-provider.js";
|
|
24
|
+
import { isCipherAvailable } from "../crypto/provider.js";
|
|
25
|
+
import { raise } from "../diagnostics/errors.js";
|
|
26
|
+
import { throwIfFaulted } from "../diagnostics/faults.js";
|
|
27
|
+
import { runMigrations } from "../migration/executor.js";
|
|
28
|
+
import { effectivePostureFor } from "../platform/backup-android-verify.js";
|
|
29
|
+
import { ensureManagedRoot, iosPosture } from "../platform/backup-ios.js";
|
|
30
|
+
import { layoutFor } from "../platform/location.js";
|
|
31
|
+
import { indexSchemas } from "../schema/declare.js";
|
|
32
|
+
import { validateConfig } from "../schema/validate-config.js";
|
|
33
|
+
import { resolveScope } from "../scope/validate.js";
|
|
34
|
+
import { ensureCatalog, readEntry, registerScope } from "../sqlite/catalog.js";
|
|
35
|
+
import { assertReadable, openConnection } from "../sqlite/connection.js";
|
|
36
|
+
import { isEncryptionAvailable } from "../sqlite/native.js";
|
|
37
|
+
import { acquireHandleSlot, releaseHandleSlot } from "./budgets.js";
|
|
38
|
+
import { clearScopeInvalidation } from "./deletion.js";
|
|
39
|
+
import { buildHandle, schemaFor } from "./handle.js";
|
|
40
|
+
import { syncSchema } from "./schema-sync.js";
|
|
41
|
+
function resolveEncryption(config) {
|
|
42
|
+
if (config.encryption?.enabled !== true) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
// Writing plaintext to a file the app believes is encrypted is the one
|
|
46
|
+
// outcome worse than refusing to open (research.md R1a).
|
|
47
|
+
if (!isEncryptionAvailable()) {
|
|
48
|
+
raise(DiagnosticCodes.ENCRYPTION_UNAVAILABLE, {
|
|
49
|
+
message: 'encryption was requested but SQLCipher is not compiled into this build'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!isCipherAvailable()) {
|
|
53
|
+
raise(DiagnosticCodes.ENCRYPTION_UNAVAILABLE, {
|
|
54
|
+
message: 'encryption was requested but the cipher peer is not installed'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
async function assertPostureMatches(catalog, scope, encrypted) {
|
|
60
|
+
const entry = await readEntry(catalog, scope.key);
|
|
61
|
+
if (!entry) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (entry.deletionState === 'deleting') {
|
|
65
|
+
// An interrupted deletion is reported rather than opened over: the
|
|
66
|
+
// scope is neither present nor gone, and presenting it as healthy is
|
|
67
|
+
// the one answer FR-063 forbids. `deleteScopeData` finishes the job.
|
|
68
|
+
raise(DiagnosticCodes.SCOPE_DELETED, {
|
|
69
|
+
message: 'a previous deletion of this scope was interrupted',
|
|
70
|
+
detail: {
|
|
71
|
+
scopeKey: scope.key
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (entry.encrypted !== encrypted) {
|
|
76
|
+
// In-place conversion is not supported this phase (FR-103). Reporting
|
|
77
|
+
// the mismatch lets an app migrate deliberately; opening would either
|
|
78
|
+
// fail obscurely or write the wrong posture.
|
|
79
|
+
raise(DiagnosticCodes.ENCRYPTION_MISMATCH, {
|
|
80
|
+
message: 'encryption posture does not match the stored database',
|
|
81
|
+
detail: {
|
|
82
|
+
scopeKey: scope.key
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export async function openSqliteDatabase(config, options = {}) {
|
|
88
|
+
const now = options.now ?? (() => Date.now());
|
|
89
|
+
validateConfig(config);
|
|
90
|
+
throwIfFaulted('open');
|
|
91
|
+
const scope = resolveScope(config.scope);
|
|
92
|
+
const encrypted = resolveEncryption(config);
|
|
93
|
+
const includeInBackup = config.backup?.includeInPlatformBackup === true;
|
|
94
|
+
const layout = layoutFor(config.name);
|
|
95
|
+
await ensureManagedRoot(layout, includeInBackup);
|
|
96
|
+
const catalog = await openConnection({
|
|
97
|
+
path: layout.catalogPath
|
|
98
|
+
});
|
|
99
|
+
let key = null;
|
|
100
|
+
let connection = null;
|
|
101
|
+
let released = false;
|
|
102
|
+
const releaseConnection = async () => {
|
|
103
|
+
if (released || !connection) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
released = true;
|
|
107
|
+
await connection.close();
|
|
108
|
+
releaseHandleSlot();
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
await ensureCatalog(catalog);
|
|
112
|
+
await assertPostureMatches(catalog, scope, encrypted);
|
|
113
|
+
if (encrypted) {
|
|
114
|
+
key = await acquireKey(config.encryption, scope);
|
|
115
|
+
}
|
|
116
|
+
acquireHandleSlot();
|
|
117
|
+
try {
|
|
118
|
+
connection = await openConnection({
|
|
119
|
+
path: layout.scopeDataPath(scope.key),
|
|
120
|
+
...(key ? {
|
|
121
|
+
encryptionKey: key.value()
|
|
122
|
+
} : {})
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
releaseHandleSlot();
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
await assertReadable(connection);
|
|
129
|
+
const schemas = indexSchemas(config.collections);
|
|
130
|
+
// No DDL at all when the declaration is the one already applied (LDB-07).
|
|
131
|
+
const schema = await syncSchema(connection, config);
|
|
132
|
+
const scopeConnection = connection;
|
|
133
|
+
const schemaVersion = await runMigrations({
|
|
134
|
+
connection: scopeConnection,
|
|
135
|
+
config,
|
|
136
|
+
schemaFor: name => schemaFor(schemas, name),
|
|
137
|
+
now,
|
|
138
|
+
closeOnFailure: releaseConnection,
|
|
139
|
+
ledgerReady: schema.unchanged
|
|
140
|
+
});
|
|
141
|
+
await schema.record();
|
|
142
|
+
await registerScope(catalog, {
|
|
143
|
+
scopeKey: scope.key,
|
|
144
|
+
createdAt: now(),
|
|
145
|
+
deletionState: 'active',
|
|
146
|
+
backupPosture: includeInBackup ? 'included' : 'excluded',
|
|
147
|
+
encrypted
|
|
148
|
+
});
|
|
149
|
+
await catalog.close();
|
|
150
|
+
clearScopeInvalidation(config.name, scope.key);
|
|
151
|
+
return buildHandle({
|
|
152
|
+
config,
|
|
153
|
+
connection: scopeConnection,
|
|
154
|
+
key,
|
|
155
|
+
layout,
|
|
156
|
+
now,
|
|
157
|
+
schemaVersion,
|
|
158
|
+
schemas,
|
|
159
|
+
scope,
|
|
160
|
+
posture: effectivePostureFor(layout, includeInBackup, iosPosture)
|
|
161
|
+
});
|
|
162
|
+
} catch (error) {
|
|
163
|
+
// No usable handle after a failed open (FR-002). Anything already
|
|
164
|
+
// acquired is released here rather than left for a caller who is about
|
|
165
|
+
// to be handed an exception instead of a handle.
|
|
166
|
+
key?.release();
|
|
167
|
+
await releaseConnection();
|
|
168
|
+
await catalog.close();
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DiagnosticCodes","acquireKey","isCipherAvailable","raise","throwIfFaulted","runMigrations","effectivePostureFor","ensureManagedRoot","iosPosture","layoutFor","indexSchemas","validateConfig","resolveScope","ensureCatalog","readEntry","registerScope","assertReadable","openConnection","isEncryptionAvailable","acquireHandleSlot","releaseHandleSlot","clearScopeInvalidation","buildHandle","schemaFor","syncSchema","resolveEncryption","config","encryption","enabled","ENCRYPTION_UNAVAILABLE","message","assertPostureMatches","catalog","scope","encrypted","entry","key","deletionState","SCOPE_DELETED","detail","scopeKey","ENCRYPTION_MISMATCH","openSqliteDatabase","options","now","Date","includeInBackup","backup","includeInPlatformBackup","layout","name","path","catalogPath","connection","released","releaseConnection","close","scopeDataPath","encryptionKey","value","error","schemas","collections","schema","scopeConnection","schemaVersion","closeOnFailure","ledgerReady","unchanged","record","createdAt","backupPosture","posture","release"],"sourceRoot":"../../../src","sources":["adapter/lifecycle.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,eAAe,QAAQ,uBAAoB;AAEpD,SAASC,UAAU,QAAwB,2BAAwB;AACnE,SAASC,iBAAiB,QAAQ,uBAAoB;AACtD,SAASC,KAAK,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AAM,CAACK;IACrB,CAAC,CAAC;IACF,MAAML,MAAM,CAACM,MAAM,CAAC,CAAC;IAErB,MAAMtD,aAAa,CAACiB,OAAO,EAAE;MAC5BQ,QAAQ,EAAEP,KAAK,CAACG,GAAG;MACnBkC,SAAS,EAAE1B,GAAG,CAAC,CAAC;MAChBP,aAAa,EAAE,QAAQ;MACvBkC,aAAa,EAAEzB,eAAe,GAAG,UAAU,GAAG,UAAU;MACxDZ;IACD,CAAC,CAAC;IACF,MAAMF,OAAO,CAACwB,KAAK,CAAC,CAAC;IACrBnC,sBAAsB,CAACK,MAAM,CAACwB,IAAI,EAAEjB,KAAK,CAACG,GAAG,CAAC;IAE9C,OAAOd,WAAW,CAAC;MAClBI,MAAM;MACN2B,UAAU,EAAEW,eAAe;MAC3B5B,GAAG;MACHa,MAAM;MACNL,GAAG;MACHqB,aAAa;MACbJ,OAAO;MACP5B,KAAK;MACLuC,OAAO,EAAElE,mBAAmB,CAAC2C,MAAM,EAAEH,eAAe,EAAEtC,UAAU;IACjE,CAAC,CAAC;EACH,CAAC,CAAC,OAAOoD,KAAK,EAAE;IACf;IACA;IACA;IACAxB,GAAG,EAAEqC,OAAO,CAAC,CAAC;IACd,MAAMlB,iBAAiB,CAAC,CAAC;IACzB,MAAMvB,OAAO,CAACwB,KAAK,CAAC,CAAC;IACrB,MAAMI,KAAK;EACZ;AACD","ignoreList":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bringing the physical tables in line with the declared schema, and skipping
|
|
5
|
+
* that work when nothing changed (LDB-07, LDB-11).
|
|
6
|
+
*
|
|
7
|
+
* Until 0.4.0 every open ran the whole set — CREATE TABLE, PRAGMA table_info,
|
|
8
|
+
* CREATE INDEX per index, for every collection — some sixty native round-trips
|
|
9
|
+
* for ten collections, on the startup path. The applied schema is now recorded
|
|
10
|
+
* in `_meta`; an open whose declaration matches it runs no DDL at all.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { ensureAttachmentTable } from "../artifacts/store.js";
|
|
14
|
+
import { addColumnSql, createIndexSql, createTableSql, physicalIndexName } from "../sqlite/row-codec.js";
|
|
15
|
+
import { text } from "../sqlite/values.js";
|
|
16
|
+
|
|
17
|
+
/** Bumped whenever the DDL this package generates changes, so it is re-applied once. */
|
|
18
|
+
const DDL_VERSION = 1;
|
|
19
|
+
const FINGERPRINT_KEY = 'schema_fingerprint';
|
|
20
|
+
|
|
21
|
+
/** What was declared, and by which generation of this package's DDL. */
|
|
22
|
+
function fingerprintOf(config) {
|
|
23
|
+
return JSON.stringify([DDL_VERSION, config.collections]);
|
|
24
|
+
}
|
|
25
|
+
async function appliedFingerprint(connection) {
|
|
26
|
+
try {
|
|
27
|
+
const result = await connection.execute('SELECT value FROM _meta WHERE key = ?', [FINGERPRINT_KEY]);
|
|
28
|
+
const row = result.rows[0];
|
|
29
|
+
return row ? text(row.value) : null;
|
|
30
|
+
} catch {
|
|
31
|
+
// A database that has never been opened has no `_meta` yet.
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `unique` and the column list of an index, read back from the statement SQLite stored. */
|
|
37
|
+
function definitionOf(sql) {
|
|
38
|
+
const unique = /^\s*CREATE\s+UNIQUE\s/i.test(sql);
|
|
39
|
+
const columns = sql.slice(sql.lastIndexOf('(') + 1, sql.lastIndexOf(')')).replace(/["\s]/g, '');
|
|
40
|
+
return `${unique ? 'unique' : 'plain'}:${columns}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Indexes follow their declaration (LDB-11). `CREATE INDEX IF NOT EXISTS` keyed
|
|
45
|
+
* on the name alone meant that adding `unique: true` to an existing index, or
|
|
46
|
+
* changing its fields, did nothing, and an index no longer declared stayed
|
|
47
|
+
* forever. An index whose definition changed is dropped and recreated, and one
|
|
48
|
+
* of this package's that is no longer declared is dropped. Only indexes carrying
|
|
49
|
+
* the collection's own prefix are touched.
|
|
50
|
+
*/
|
|
51
|
+
async function syncIndexes(connection, schema) {
|
|
52
|
+
const table = `c_${schema.name}`;
|
|
53
|
+
const existing = await connection.execute("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ? AND sql IS NOT NULL", [table]);
|
|
54
|
+
const current = new Map(existing.rows.map(row => [text(row.name), text(row.sql)]));
|
|
55
|
+
const wanted = new Map(createIndexSql(schema).map(statement => {
|
|
56
|
+
const name = /INDEX IF NOT EXISTS "([^"]+)"/.exec(statement)?.[1] ?? '';
|
|
57
|
+
return [name, statement];
|
|
58
|
+
}));
|
|
59
|
+
for (const index of schema.indexes ?? []) {
|
|
60
|
+
// Indexes created before 0.2.0 carry the bare declared name; they are
|
|
61
|
+
// recreated under the collection-scoped one. No row data moves.
|
|
62
|
+
if (current.has(index.name) && index.name !== physicalIndexName(schema, index.name)) {
|
|
63
|
+
await connection.execute(`DROP INDEX IF EXISTS "${index.name}"`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const [name, sql] of current) {
|
|
67
|
+
const statement = wanted.get(name);
|
|
68
|
+
const ours = name.startsWith(`${table}__`);
|
|
69
|
+
if (statement === undefined && ours || statement && definitionOf(statement) !== definitionOf(sql)) {
|
|
70
|
+
await connection.execute(`DROP INDEX IF EXISTS "${name}"`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const statement of wanted.values()) {
|
|
74
|
+
await connection.execute(statement);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Adding a column rather than recreating the table is what makes declaring a
|
|
80
|
+
* new queryable field non-destructive: the payload already holds the value, so
|
|
81
|
+
* the new column is backfilled from it and no record is rewritten by hand
|
|
82
|
+
* (research.md R6).
|
|
83
|
+
*/
|
|
84
|
+
async function ensureCollection(connection, schema) {
|
|
85
|
+
await connection.execute(createTableSql(schema));
|
|
86
|
+
const info = await connection.execute(`PRAGMA table_info("c_${schema.name}")`);
|
|
87
|
+
const present = new Set(info.rows.map(row => text(row.name)));
|
|
88
|
+
for (const field of schema.fields ?? []) {
|
|
89
|
+
const column = `f_${field.name}`;
|
|
90
|
+
if (present.has(column)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
await connection.execute(addColumnSql(schema, field));
|
|
94
|
+
// The same projection a write applies (`projectValue`): an object or an
|
|
95
|
+
// array projects to NULL. A bare json_extract backfilled those as JSON
|
|
96
|
+
// text, so a filter matched old records and new ones differently (LDB-11).
|
|
97
|
+
const path = `'$."${field.name}"'`;
|
|
98
|
+
await connection.execute(`UPDATE "c_${schema.name}" SET "${column}" = CASE WHEN json_type(payload, ${path}) IN ('object', 'array') THEN NULL ELSE json_extract(payload, ${path}) END`);
|
|
99
|
+
}
|
|
100
|
+
await syncIndexes(connection, schema);
|
|
101
|
+
}
|
|
102
|
+
export async function syncSchema(connection, config) {
|
|
103
|
+
const fingerprint = fingerprintOf(config);
|
|
104
|
+
if ((await appliedFingerprint(connection)) === fingerprint) {
|
|
105
|
+
return {
|
|
106
|
+
unchanged: true,
|
|
107
|
+
record: async () => undefined
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
for (const schema of config.collections) {
|
|
111
|
+
await ensureCollection(connection, schema);
|
|
112
|
+
}
|
|
113
|
+
await ensureAttachmentTable(connection);
|
|
114
|
+
return {
|
|
115
|
+
unchanged: false,
|
|
116
|
+
async record() {
|
|
117
|
+
await connection.execute('INSERT INTO _meta (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value', [FINGERPRINT_KEY, fingerprint]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=schema-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ensureAttachmentTable","addColumnSql","createIndexSql","createTableSql","physicalIndexName","text","DDL_VERSION","FINGERPRINT_KEY","fingerprintOf","config","JSON","stringify","collections","appliedFingerprint","connection","result","execute","row","rows","value","definitionOf","sql","unique","test","columns","slice","lastIndexOf","replace","syncIndexes","schema","table","name","existing","current","Map","map","wanted","statement","exec","index","indexes","has","get","ours","startsWith","undefined","values","ensureCollection","info","present","Set","field","fields","column","path","syncSchema","fingerprint","unchanged","record"],"sourceRoot":"../../../src","sources":["adapter/schema-sync.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,qBAAqB,QAAQ,uBAAoB;AAE1D,SACCC,YAAY,EACZC,cAAc,EACdC,cAAc,EACdC,iBAAiB,QACX,wBAAqB;AAC5B,SAASC,IAAI,QAAQ,qBAAkB;;AAEvC;AACA,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,eAAe,GAAG,oBAAoB;;AAE5C;AACA,SAASC,aAAaA,CAACC,MAAsB,EAAU;EACtD,OAAOC,IAAI,CAACC,SAAS,CAAC,CAACL,WAAW,EAAEG,MAAM,CAACG,WAAW,CAAC,CAAC;AACzD;AAEA,eAAeC,kBAAkBA,CAACC,UAAsB,EAA0B;EACjF,IAAI;IACH,MAAMC,MAAM,GAAG,MAAMD,UAAU,CAACE,OAAO,CAAC,uCAAuC,EAAE,CAChFT,eAAe,CACf,CAAC;IACF,MAAMU,GAAG,GAAGF,MAAM,CAACG,IAAI,CAAC,CAAC,CAAC;IAC1B,OAAOD,GAAG,GAAGZ,IAAI,CAACY,GAAG,CAACE,KAAK,CAAC,GAAG,IAAI;EACpC,CAAC,CAAC,MAAM;IACP;IACA,OAAO,IAAI;EACZ;AACD;;AAEA;AACA,SAASC,YAAYA,CAACC,GAAW,EAAU;EAC1C,MAAMC,MAAM,GAAG,wBAAwB,CAACC,IAAI,CAACF,GAAG,CAAC;EACjD,MAAMG,OAAO,GAAGH,GAAG,CAACI,KAAK,CAACJ,GAAG,CAACK,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAEL,GAAG,CAACK,WAAW,CAAC,GA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AACpB,IAAI,IAAI;IAClC,MAAMjB,UAAU,CAACE,OAAO,CACvB,aAAaa,MAAM,CAACE,IAAI,UAAUsB,MAAM,oCAAoCC,IAAI,iEAAiEA,IAAI,OACtJ,CAAC;EACF;EAEA,MAAM1B,WAAW,CAACd,UAAU,EAAEe,MAAM,CAAC;AACtC;AASA,OAAO,eAAe0B,UAAUA,CAC/BzC,UAAsB,EACtBL,MAAsB,EACA;EACtB,MAAM+C,WAAW,GAAGhD,aAAa,CAACC,MAAM,CAAC;EACzC,IAAI,CAAC,MAAMI,kBAAkB,CAACC,UAAU,CAAC,MAAM0C,WAAW,EAAE;IAC3D,OAAO;MAAEC,SAAS,EAAE,IAAI;MAAEC,MAAM,EAAE,MAAAA,CAAA,KAAYb;IAAU,CAAC;EAC1D;EAEA,KAAK,MAAMhB,MAAM,IAAIpB,MAAM,CAACG,WAAW,EAAE;IACxC,MAAMmC,gBAAgB,CAACjC,UAAU,EAAEe,MAAM,CAAC;EAC3C;EACA,MAAM7B,qBAAqB,CAACc,UAAU,CAAC;EAEvC,OAAO;IACN2C,SAAS,EAAE,KAAK;IAChB,MAAMC,MAAMA,CAAA,EAAG;MACd,MAAM5C,UAAU,CAACE,OAAO,CACvB,oGAAoG,EACpG,CAACT,eAAe,EAAEiD,WAAW,CAC9B,CAAC;IACF;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `Transaction` a consumer actually holds.
|
|
5
|
+
*
|
|
6
|
+
* Two rules live here rather than in either adapter, so both are held to the
|
|
7
|
+
* same standard:
|
|
8
|
+
*
|
|
9
|
+
* **Read-your-own-writes** (FR-043). Every collection reached through `tx`
|
|
10
|
+
* runs against the transaction's executor, so a read inside sees the writes
|
|
11
|
+
* made inside. A collection reached through the handle during a transaction
|
|
12
|
+
* would not, and handing one out would be a quiet correctness trap.
|
|
13
|
+
*
|
|
14
|
+
* **Terminal state is terminal** (FR-044). After a commit or an abort, using
|
|
15
|
+
* the transaction raises rather than silently writing outside it — the
|
|
16
|
+
* failure mode where a caller's cleanup code lands in the database after the
|
|
17
|
+
* rollback it was supposed to be part of.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { DiagnosticCodes } from "../contract/errors.js";
|
|
21
|
+
import { raise } from "../diagnostics/errors.js";
|
|
22
|
+
export function createTransaction(host) {
|
|
23
|
+
let settled = false;
|
|
24
|
+
const assertLive = () => {
|
|
25
|
+
if (settled) {
|
|
26
|
+
raise(DiagnosticCodes.TRANSACTION_STATE, {
|
|
27
|
+
message: 'transaction already settled'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const transaction = {
|
|
32
|
+
collection(name) {
|
|
33
|
+
assertLive();
|
|
34
|
+
return host.collection(name);
|
|
35
|
+
},
|
|
36
|
+
attachments() {
|
|
37
|
+
assertLive();
|
|
38
|
+
return host.attachments();
|
|
39
|
+
},
|
|
40
|
+
async abort() {
|
|
41
|
+
assertLive();
|
|
42
|
+
settled = true;
|
|
43
|
+
await host.rollback();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
transaction,
|
|
48
|
+
isSettled: () => settled,
|
|
49
|
+
settle: () => {
|
|
50
|
+
settled = true;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DiagnosticCodes","raise","createTransaction","host","settled","assertLive","TRANSACTION_STATE","message","transaction","collection","name","attachments","abort","rollback","isSettled","settle"],"sourceRoot":"../../../src","sources":["adapter/transaction.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,uBAAoB;AAIpD,SAASC,KAAK,QAAQ,0BAAuB;AAe7C,OAAO,SAASC,iBAAiBA,CAACC,IAAqB,EAAsB;EAC5E,IAAIC,OAAO,GAAG,KAAK;EAEnB,MAAMC,UAAU,GAAGA,CAAA,KAAY;IAC9B,IAAID,OAAO,EAAE;MACZH,KAAK,CAACD,eAAe,CAACM,iBAAiB,EAAE;QACxCC,OAAO,EAAE;MACV,CAAC,CAAC;IACH;EACD,CAAC;EAED,MAAMC,WAAwB,GAAG;IAChCC,UAAUA,CAA+BC,IAAY,EAAoB;MACxEL,UAAU,CAAC,CAAC;MACZ,OAAOF,IAAI,CAACM,UAAU,CAAIC,IAAI,CAAC;IAChC,CAAC;IACDC,WAAWA,CAAA,EAAgB;MAC1BN,UAAU,CAAC,CAAC;MACZ,OAAOF,IAAI,CAACQ,WAAW,CAAC,CAAC;IAC1B,CAAC;IACD,MAAMC,KAAKA,CAAA,EAAkB;MAC5BP,UAAU,CAAC,CAAC;MACZD,OAAO,GAAG,IAAI;MACd,MAAMD,IAAI,CAACU,QAAQ,CAAC,CAAC;IACtB;EACD,CAAC;EAED,OAAO;IACNL,WAAW;IACXM,SAAS,EAAEA,CAAA,KAAMV,OAAO;IACxBW,MAAM,EAAEA,CAAA,KAAM;MACbX,OAAO,GAAG,IAAI;IACf;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* "Is this artifact still there?", answered without opening it.
|
|
5
|
+
*
|
|
6
|
+
* `stat()` and, for an encrypted artifact, the 22-byte header. Never a
|
|
7
|
+
* content byte and never a decryption (FR-073e, FR-107b). An availability
|
|
8
|
+
* check that decrypted would make a gallery screen showing fifty thumbnails
|
|
9
|
+
* decrypt fifty artifacts to answer a question none of them asked, and would
|
|
10
|
+
* put key material in play for an operation that does not need it.
|
|
11
|
+
*
|
|
12
|
+
* The four states are deliberately four rather than two. `missing` is data
|
|
13
|
+
* that is gone; `undecryptable` is data that exists under a key that does not
|
|
14
|
+
* open it, which is often recoverable and always a different conversation to
|
|
15
|
+
* have with the user (FR-107c).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { fileSystem } from "../platform/fs.js";
|
|
19
|
+
import { asciiAt, base64ToBytes } from "../platform/bytes.js";
|
|
20
|
+
import { HEADER_BYTES, MAGIC } from "../crypto/chunked-cipher.js";
|
|
21
|
+
import { artifactPath } from "./paths.js";
|
|
22
|
+
import { readReference } from "./store.js";
|
|
23
|
+
export async function artifactAvailability(context, executor, id) {
|
|
24
|
+
const reference = await readReference(executor, id);
|
|
25
|
+
if (!reference) {
|
|
26
|
+
// No reference is "missing" rather than an error: the caller asked
|
|
27
|
+
// about an artifact this scope does not claim to have.
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
state: 'missing'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const path = artifactPath(context.layout, context.scopeKey, id);
|
|
34
|
+
let size;
|
|
35
|
+
try {
|
|
36
|
+
const stat = await fileSystem().stat(path);
|
|
37
|
+
if (!stat.isFile()) {
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
state: 'inaccessible'
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
size = stat.size;
|
|
44
|
+
} catch {
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
state: 'missing'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (context.artifactKey(id) === null) {
|
|
51
|
+
return {
|
|
52
|
+
id,
|
|
53
|
+
state: 'available',
|
|
54
|
+
size: reference.size
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (size < HEADER_BYTES) {
|
|
58
|
+
return {
|
|
59
|
+
id,
|
|
60
|
+
state: 'undecryptable',
|
|
61
|
+
size: reference.size
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const header = base64ToBytes(await fileSystem().read(path, HEADER_BYTES, 0, 'base64'));
|
|
66
|
+
if (asciiAt(header, 0, 4) !== MAGIC) {
|
|
67
|
+
return {
|
|
68
|
+
id,
|
|
69
|
+
state: 'undecryptable',
|
|
70
|
+
size: reference.size
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
return {
|
|
75
|
+
id,
|
|
76
|
+
state: 'inaccessible',
|
|
77
|
+
size: reference.size
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
id,
|
|
82
|
+
state: 'available',
|
|
83
|
+
size: reference.size
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=availability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fileSystem","asciiAt","base64ToBytes","HEADER_BYTES","MAGIC","artifactPath","readReference","artifactAvailability","context","executor","id","reference","state","path","layout","scopeKey","size","stat","isFile","artifactKey","header","read"],"sourceRoot":"../../../src","sources":["artifacts/availability.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,QAAQ,mBAAgB;AAC3C,SAASC,OAAO,EAAEC,aAAa,QAAQ,sBAAmB;AAC1D,SAASC,YAAY,EAAEC,KAAK,QAAQ,6BAA0B;AAE9D,SAASC,YAAY,QAAQ,YAAS;AACtC,SAASC,aAAa,QAA8B,YAAS;AAE7D,OAAO,eAAeC,oBAAoBA,CACzCC,OAAwB,EACxBC,QAAkB,EAClBC,EAAU,EACwB;EAClC,MAAMC,SAAS,GAAG,MAAML,aAAa,CAACG,QAAQ,EAAEC,EAAE,CAAC;EACnD,IAAI,CAACC,SAAS,EAAE;IACf;IACA;IACA,OAAO;MAAED,EAAE;MAAEE,KAAK,EAAE;IAAU,CAAC;EAChC;EAEA,MAAMC,IAAI,GAAGR,YAAY,CAACG,OAAO,CAACM,MAAM,EAAEN,OAAO,CAACO,QAAQ,EAAEL,EAAE,CAAC;EAE/D,IAAIM,IA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0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cascading artifact removal.
|
|
5
|
+
*
|
|
6
|
+
* The package deletes the files, because the Q2 clarification made it the
|
|
7
|
+
* owner of them (FR-073c). That is the single riskiest thing this package
|
|
8
|
+
* does — POL-011(b)'s media-and-files row exists for it — so two rules hold
|
|
9
|
+
* without exception: every path goes through the boundary guard in
|
|
10
|
+
* `paths.ts`, and the outcome reports what was removed **and what could not
|
|
11
|
+
* be**, never a bare success (FR-071).
|
|
12
|
+
*
|
|
13
|
+
* A failed removal is reported rather than retried or swallowed. A file the
|
|
14
|
+
* package could not delete is still on disk holding the user's data, and an
|
|
15
|
+
* app that told them "deleted" would have said something untrue.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { fileSystem, removeIfPresent } from "../platform/fs.js";
|
|
19
|
+
import { artifactPath } from "./paths.js";
|
|
20
|
+
import { deleteReference, listReferencesFor } from "./store.js";
|
|
21
|
+
/** Unlinks one artifact file. True when the file is gone afterwards, whoever removed it. */
|
|
22
|
+
export async function unlinkArtifact(path) {
|
|
23
|
+
if (await removeIfPresent(path)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// `removeIfPresent` cannot tell "already gone" from "could not remove". A
|
|
27
|
+
// file that was already gone counts as removed: the end state the caller
|
|
28
|
+
// asked for is the end state they got.
|
|
29
|
+
try {
|
|
30
|
+
return !(await fileSystem().exists(path));
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function removeAll(context, executor, ids, deferred) {
|
|
36
|
+
const removedArtifacts = [];
|
|
37
|
+
const failedRemovals = [];
|
|
38
|
+
for (const id of ids) {
|
|
39
|
+
// The reference first. A reference left pointing at a deleted file is
|
|
40
|
+
// the unrecoverable state; a file left without its reference is an
|
|
41
|
+
// orphan reconciliation finds.
|
|
42
|
+
if (!(await deleteReference(executor, id))) {
|
|
43
|
+
failedRemovals.push(id);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const path = artifactPath(context.layout, context.scopeKey, id);
|
|
47
|
+
if (deferred) {
|
|
48
|
+
deferred.add(path);
|
|
49
|
+
removedArtifacts.push(id);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (await unlinkArtifact(path)) {
|
|
53
|
+
removedArtifacts.push(id);
|
|
54
|
+
} else {
|
|
55
|
+
// Still on disk holding the user's data: reported, never claimed removed.
|
|
56
|
+
failedRemovals.push(id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
removedRecords: 0,
|
|
61
|
+
removedArtifacts,
|
|
62
|
+
orphanedReferences: [],
|
|
63
|
+
failedRemovals
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Everything belonging to one record, for the FR-070 cascade. Inside a
|
|
69
|
+
* transaction pass `deferred`: the files are removed only once it commits.
|
|
70
|
+
*/
|
|
71
|
+
export async function cascadeForOwner(context, executor, owner, deferred) {
|
|
72
|
+
const references = await listReferencesFor(executor, owner);
|
|
73
|
+
return removeAll(context, executor, references.map(reference => reference.id), deferred);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=cascade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fileSystem","removeIfPresent","artifactPath","deleteReference","listReferencesFor","unlinkArtifact","path","exists","removeAll","context","executor","ids","deferred","removedArtifacts","failedRemovals","id","push","layout","scopeKey","add","removedRecords","orphanedReferences","cascadeForOwner","owner","references","map","reference"],"sourceRoot":"../../../src","sources":["artifacts/cascade.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,EAAEC,eAAe,QAAQ,mBAAgB;AAE5D,SAASC,YAAY,QAAQ,YAAS;AACtC,SACCC,eAAe,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a,KAAsB,EACtBX,QAA0B,EACC;EAC3B,MAAMY,UAAU,GAAG,MAAMpB,iBAAiB,CAACM,QAAQ,EAAEa,KAAK,CAAC;EAC3D,OAAOf,SAAS,CACfC,OAAO,EACPC,QAAQ,EACRc,UAAU,CAACC,GAAG,CAACC,SAAS,IAAIA,SAAS,CAACX,EAAE,CAAC,EACzCH,QACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every artifact path, resolved through one guard.
|
|
5
|
+
*
|
|
6
|
+
* POL-011(b) flags media-and-files as a risk precisely because this package
|
|
7
|
+
* deletes files from disk on cascade. The mitigation is structural rather
|
|
8
|
+
* than procedural: no code in `artifacts/` builds a path by string
|
|
9
|
+
* concatenation, and the one function that turns an attachment id into a path
|
|
10
|
+
* refuses anything escaping the managed root (FR-073, FR-073f).
|
|
11
|
+
*
|
|
12
|
+
* That is what makes SC-013a's filesystem tracing pass reliably rather than
|
|
13
|
+
* usually — there is no second path to audit.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { assertWithinManagedArea } from "../platform/location.js";
|
|
17
|
+
export function artifactsDirectory(layout, scopeKey) {
|
|
18
|
+
return assertWithinManagedArea(layout, layout.scopeArtifactsPath(scopeKey));
|
|
19
|
+
}
|
|
20
|
+
export function artifactPath(layout, scopeKey, attachmentId) {
|
|
21
|
+
// `layout.artifactPath` already rejects an id that is not a safe single
|
|
22
|
+
// path segment; the guard then re-checks the assembled result, so a change
|
|
23
|
+
// to either one alone cannot open a hole.
|
|
24
|
+
return assertWithinManagedArea(layout, layout.artifactPath(scopeKey, attachmentId));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["assertWithinManagedArea","artifactsDirectory","layout","scopeKey","scopeArtifactsPath","artifactPath","attachmentId"],"sourceRoot":"../../../src","sources":["artifacts/paths.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,QAA4B,yBAAsB;AAElF,OAAO,SAASC,kBAAkBA,CAACC,MAAqB,EAAEC,QAAgB,EAAU;EACnF,OAAOH,uBAAuB,CAACE,MAAM,EAAEA,MAAM,CAACE,kBAAkB,CAACD,QAAQ,CAAC,CAAC;AAC5E;AAEA,OAAO,SAASE,YAAYA,CAC3BH,MAAqB,EACrBC,QAAgB,EAChBG,YAAoB,EACX;EACT;EACA;EACA;EACA,OAAON,uBAAuB,CAACE,MAAM,EAAEA,MAAM,CAACG,YAAY,CAACF,QAAQ,EAAEG,YAAY,CAAC,CAAC;AACpF","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reconciliation: the two ways the database and the disk can disagree.
|
|
5
|
+
*
|
|
6
|
+
* An **orphaned artifact** is a file with no reference — left by a rolled-back
|
|
7
|
+
* transaction, or by a crash between the write and the insert. A **dangling
|
|
8
|
+
* reference** is the reverse: a row pointing at a file the operating system
|
|
9
|
+
* reclaimed, or the user deleted through a file manager.
|
|
10
|
+
*
|
|
11
|
+
* App-triggered only (FR-073d). A background sweep would run during a user's
|
|
12
|
+
* session without their knowledge, delete files it believes are orphans, and
|
|
13
|
+
* have no way to distinguish "orphan" from "written by a transaction that has
|
|
14
|
+
* not committed yet". Handing the trigger to the app makes that an explicit
|
|
15
|
+
* decision at a moment the app knows is quiet.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { fileSystem, removeIfPresent } from "../platform/fs.js";
|
|
19
|
+
import { byteOrder } from "../query/compare.js";
|
|
20
|
+
import { artifactPath, artifactsDirectory } from "./paths.js";
|
|
21
|
+
import { listReferences } from "./store.js";
|
|
22
|
+
async function filesOnDisk(context) {
|
|
23
|
+
try {
|
|
24
|
+
return await fileSystem().readdir(artifactsDirectory(context.layout, context.scopeKey));
|
|
25
|
+
} catch {
|
|
26
|
+
// No directory means no artifacts, which is a valid answer rather than
|
|
27
|
+
// a failure — a scope that never wrote one never created it.
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function reconcileArtifacts(context, executor, options = {}) {
|
|
32
|
+
const references = await listReferences(executor);
|
|
33
|
+
const referenced = new Set(references.map(reference => reference.id));
|
|
34
|
+
const present = new Set(await filesOnDisk(context));
|
|
35
|
+
const orphanedArtifacts = [...present].filter(id => !referenced.has(id)).sort(byteOrder);
|
|
36
|
+
const danglingReferences = references.filter(reference => !present.has(reference.id)).map(reference => reference.id).sort(byteOrder);
|
|
37
|
+
const removedArtifacts = [];
|
|
38
|
+
if (options.removeOrphans) {
|
|
39
|
+
for (const id of orphanedArtifacts) {
|
|
40
|
+
if (await removeIfPresent(artifactPath(context.layout, context.scopeKey, id))) {
|
|
41
|
+
removedArtifacts.push(id);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
orphanedArtifacts,
|
|
47
|
+
danglingReferences,
|
|
48
|
+
removedArtifacts
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=reconcile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fileSystem","removeIfPresent","byteOrder","artifactPath","artifactsDirectory","listReferences","filesOnDisk","context","readdir","layout","scopeKey","reconcileArtifacts","executor","options","references","referenced","Set","map","reference","id","present","orphanedArtifacts","filter","has","sort","danglingReferences","removedArtifacts","removeOrphans","push"],"sourceRoot":"../../../src","sources":["artifacts/reconcile.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,UAAU,EAAEC,eAAe,QAAQ,mBAAgB;AAC5D,SAASC,SAAS,QAAQ,qBAAkB;AAE5C,SAASC,Y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