@chipmobilesdk/rn-local-db 0.3.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 +160 -1
- package/README.md +99 -19
- 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/skills/sdk-rn-local-db/SKILL.md +1 -1
- package/src/adapter/budgets.ts +1 -10
- package/src/adapter/collection.ts +38 -66
- package/src/adapter/deletion.ts +48 -0
- package/src/adapter/handle.ts +311 -0
- package/src/adapter/lifecycle.ts +10 -338
- package/src/adapter/schema-sync.ts +155 -0
- package/src/artifacts/cascade.ts +0 -14
- package/src/artifacts/store.ts +60 -10
- package/src/contract/attachment.ts +24 -3
- package/src/contract/migration.ts +4 -1
- package/src/crypto/provider.ts +7 -3
- package/src/diagnostics/dev-log.ts +5 -1
- package/src/migration/executor.ts +27 -6
- package/src/migration/ledger.ts +18 -27
- package/src/platform/fs.ts +2 -8
- package/src/platform/location.ts +0 -3
- package/src/query/budgets.ts +32 -5
- package/src/schema/validate-config.ts +3 -53
- package/src/sqlite/batch.ts +40 -51
- package/src/sqlite/connection.ts +0 -9
- package/src/sqlite/row-codec.ts +5 -2
- package/src/sqlite/statements.ts +74 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/memory-adapter/attachments.ts +146 -0
- package/src/testing/memory-adapter/index.ts +13 -111
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Batch writes: many operations, one atomic unit, one outcome (FR-028).
|
|
5
|
+
*
|
|
6
|
+
* Every statement is resolved before any of them runs. That ordering is the
|
|
7
|
+
* point: a conflict or a missing record is reported with the database still
|
|
8
|
+
* untouched, so "the batch failed" and "the batch was partly applied" are
|
|
9
|
+
* never the same event. The statements then go to the engine's own
|
|
10
|
+
* `executeBatch`, which wraps them in a single transaction — the batch is
|
|
11
|
+
* atomic because SQLite makes it atomic, not because this file is careful.
|
|
12
|
+
*
|
|
13
|
+
* Resolution keeps an overlay of what earlier operations in the same batch
|
|
14
|
+
* did, so `insert` followed by `update` on the same id resolves against the
|
|
15
|
+
* batch's own effect rather than against the database as it was before it.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { DiagnosticCodes } from "../contract/errors.js";
|
|
19
|
+
import { raise } from "../diagnostics/errors.js";
|
|
20
|
+
import { assertBatchWithinBudget, assertRecordWithinBudget } from "../query/budgets.js";
|
|
21
|
+
import { collectionTable, hasSoftDelete } from "../schema/declare.js";
|
|
22
|
+
import { insertStatement, updateStatement } from "./statements.js";
|
|
23
|
+
function quoted(schema) {
|
|
24
|
+
return `"${collectionTable(schema.name)}"`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Where a record stands, as this batch has left it so far. Three states, not
|
|
29
|
+
* two: a soft-deleted row is invisible to reads but still holds its primary
|
|
30
|
+
* key, so an insert over it conflicts and an upsert over it restores it — the
|
|
31
|
+
* same rules the collection API applies. Treating it as absent made a batch
|
|
32
|
+
* upsert issue an INSERT and fail the whole batch on the primary key.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function conflict(schema, id) {
|
|
36
|
+
raise(DiagnosticCodes.RECORD_CONFLICT, {
|
|
37
|
+
message: 'record already exists',
|
|
38
|
+
detail: {
|
|
39
|
+
collection: schema.name,
|
|
40
|
+
recordId: id
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function missing(schema, id) {
|
|
45
|
+
raise(DiagnosticCodes.RECORD_NOT_FOUND, {
|
|
46
|
+
message: 'record not found',
|
|
47
|
+
detail: {
|
|
48
|
+
collection: schema.name,
|
|
49
|
+
recordId: id
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function resolveInsert(resolver, operation) {
|
|
54
|
+
const {
|
|
55
|
+
schema,
|
|
56
|
+
now
|
|
57
|
+
} = resolver;
|
|
58
|
+
const payload = assertRecordWithinBudget(schema.name, operation.record.data);
|
|
59
|
+
if ((await resolver.state(operation.record.id)) !== 'absent') {
|
|
60
|
+
conflict(schema, operation.record.id);
|
|
61
|
+
}
|
|
62
|
+
resolver.stage(operation.record.id, 'live');
|
|
63
|
+
return {
|
|
64
|
+
command: insertStatement(schema, operation.record.id, operation.record.data, now, payload),
|
|
65
|
+
outcome: {
|
|
66
|
+
operation: 'created',
|
|
67
|
+
id: operation.record.id
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function resolveUpdate(resolver, operation) {
|
|
72
|
+
const {
|
|
73
|
+
schema,
|
|
74
|
+
now
|
|
75
|
+
} = resolver;
|
|
76
|
+
const payload = assertRecordWithinBudget(schema.name, operation.data);
|
|
77
|
+
if ((await resolver.state(operation.id)) !== 'live') {
|
|
78
|
+
missing(schema, operation.id);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
command: updateStatement(schema, operation.id, operation.data, now, payload, {
|
|
82
|
+
restore: false
|
|
83
|
+
}),
|
|
84
|
+
outcome: {
|
|
85
|
+
operation: 'updated',
|
|
86
|
+
id: operation.id
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function resolveUpsert(resolver, operation) {
|
|
91
|
+
const {
|
|
92
|
+
schema,
|
|
93
|
+
now
|
|
94
|
+
} = resolver;
|
|
95
|
+
const payload = assertRecordWithinBudget(schema.name, operation.record.data);
|
|
96
|
+
const present = (await resolver.state(operation.record.id)) !== 'absent';
|
|
97
|
+
resolver.stage(operation.record.id, 'live');
|
|
98
|
+
return {
|
|
99
|
+
command: present ? updateStatement(schema, operation.record.id, operation.record.data, now, payload, {
|
|
100
|
+
restore: true
|
|
101
|
+
}) : insertStatement(schema, operation.record.id, operation.record.data, now, payload),
|
|
102
|
+
outcome: {
|
|
103
|
+
operation: present ? 'updated' : 'created',
|
|
104
|
+
id: operation.record.id
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function resolveDelete(resolver, operation) {
|
|
109
|
+
const {
|
|
110
|
+
schema
|
|
111
|
+
} = resolver;
|
|
112
|
+
if ((await resolver.state(operation.id)) !== 'live') {
|
|
113
|
+
missing(schema, operation.id);
|
|
114
|
+
}
|
|
115
|
+
resolver.stage(operation.id, 'absent');
|
|
116
|
+
return {
|
|
117
|
+
command: [`DELETE FROM ${quoted(schema)} WHERE id = ?`, [operation.id]],
|
|
118
|
+
outcome: {
|
|
119
|
+
operation: 'deleted',
|
|
120
|
+
id: operation.id
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function resolveSoftDelete(resolver, operation) {
|
|
125
|
+
const {
|
|
126
|
+
schema,
|
|
127
|
+
now
|
|
128
|
+
} = resolver;
|
|
129
|
+
if (!hasSoftDelete(schema)) {
|
|
130
|
+
raise(DiagnosticCodes.CONFIG_INVALID, {
|
|
131
|
+
message: 'collection does not declare soft delete',
|
|
132
|
+
detail: {
|
|
133
|
+
collection: schema.name
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if ((await resolver.state(operation.id)) !== 'live') {
|
|
138
|
+
missing(schema, operation.id);
|
|
139
|
+
}
|
|
140
|
+
resolver.stage(operation.id, 'softDeleted');
|
|
141
|
+
return {
|
|
142
|
+
command: [`UPDATE ${quoted(schema)} SET deleted_at = ? WHERE id = ?`, [now, operation.id]],
|
|
143
|
+
outcome: {
|
|
144
|
+
operation: 'deleted',
|
|
145
|
+
id: operation.id
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function resolveOperation(resolver, operation) {
|
|
150
|
+
switch (operation.type) {
|
|
151
|
+
case 'insert':
|
|
152
|
+
return resolveInsert(resolver, operation);
|
|
153
|
+
case 'update':
|
|
154
|
+
return resolveUpdate(resolver, operation);
|
|
155
|
+
case 'upsert':
|
|
156
|
+
return resolveUpsert(resolver, operation);
|
|
157
|
+
case 'delete':
|
|
158
|
+
return resolveDelete(resolver, operation);
|
|
159
|
+
case 'softDelete':
|
|
160
|
+
return resolveSoftDelete(resolver, operation);
|
|
161
|
+
default:
|
|
162
|
+
raise(DiagnosticCodes.CONFIG_INVALID, {
|
|
163
|
+
message: 'unsupported batch operation'
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export async function runBatch(context, operations) {
|
|
168
|
+
assertBatchWithinBudget(operations.length);
|
|
169
|
+
const commands = [];
|
|
170
|
+
const outcomes = [];
|
|
171
|
+
const overlay = new Map();
|
|
172
|
+
|
|
173
|
+
// What the batch will touch, read once per collection (LDB-08). A batch of a
|
|
174
|
+
// thousand operations used to make a thousand SELECTs before its one write.
|
|
175
|
+
// The ids travel as one JSON parameter, so no variable limit applies.
|
|
176
|
+
const known = new Map();
|
|
177
|
+
const idsByCollection = new Map();
|
|
178
|
+
for (const operation of operations) {
|
|
179
|
+
const id = 'record' in operation ? operation.record.id : operation.id;
|
|
180
|
+
const ids = idsByCollection.get(operation.collection) ?? new Set();
|
|
181
|
+
ids.add(id);
|
|
182
|
+
idsByCollection.set(operation.collection, ids);
|
|
183
|
+
}
|
|
184
|
+
for (const [collection, ids] of idsByCollection) {
|
|
185
|
+
const schema = context.schemaFor(collection);
|
|
186
|
+
const result = await context.connection.execute(`SELECT id, deleted_at FROM ${quoted(schema)} WHERE id IN (SELECT value FROM json_each(?))`, [JSON.stringify([...ids])]);
|
|
187
|
+
for (const row of result.rows) {
|
|
188
|
+
known.set(`${schema.name}:${String(row.id)}`, row.deleted_at === null || row.deleted_at === undefined ? 'live' : 'softDeleted');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const operation of operations) {
|
|
192
|
+
const schema = context.schemaFor(operation.collection);
|
|
193
|
+
const resolver = {
|
|
194
|
+
schema,
|
|
195
|
+
now: context.now(),
|
|
196
|
+
async state(id) {
|
|
197
|
+
const key = `${schema.name}:${id}`;
|
|
198
|
+
return overlay.get(key) ?? known.get(key) ?? 'absent';
|
|
199
|
+
},
|
|
200
|
+
stage(id, state) {
|
|
201
|
+
overlay.set(`${schema.name}:${id}`, state);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const resolved = await resolveOperation(resolver, operation);
|
|
205
|
+
commands.push(resolved.command);
|
|
206
|
+
outcomes.push(resolved.outcome);
|
|
207
|
+
}
|
|
208
|
+
await context.connection.executeBatch(commands);
|
|
209
|
+
return {
|
|
210
|
+
applied: outcomes.length,
|
|
211
|
+
outcomes
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DiagnosticCodes","raise","assertBatchWithinBudget","assertRecordWithinBudget","collectionTable","hasSoftDelete","insertStatement","updateStatement","quoted","schema","name","conflict","id","RECORD_CONFLICT","message","detail","collection","recordId","missing","RECORD_NOT_FOUND","resolveInsert","resolver","operation","now","payload","record","data","state","stage","command","outcome","resolveUpdate","restore","resolveUpsert","present","resolveDelete","resolveSoftDelete","CONFIG_INVALID","resolveOperation","type","runBatch","context","operations","length","commands","outcomes","overlay","Map","known","idsByCollection","ids","get","Set","add","set","schemaFor","result","connection","execute","JSON","stringify","row","rows","String","deleted_at","undefined","key","resolved","push","executeBatch","applied"],"sourceRoot":"../../../src","sources":["sqlite/batch.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,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
|
4
|
+
* The catalog: one registry per logical database, listing the scopes that
|
|
5
|
+
* exist.
|
|
6
|
+
*
|
|
7
|
+
* This is the only structure that spans scopes, so it is deliberately the
|
|
8
|
+
* smallest thing that answers the questions the package must answer without
|
|
9
|
+
* opening every scope file. It holds a digest, timestamps, and two posture
|
|
10
|
+
* flags — **no raw scope components** (FR-014), so a device with full disk
|
|
11
|
+
* access cannot mine it for identities or tenant names even though the
|
|
12
|
+
* catalog itself is never encrypted.
|
|
13
|
+
*
|
|
14
|
+
* The `deleting` flag is the load-bearing part. It is written before a scope
|
|
15
|
+
* deletion begins and cleared last, so a crash at any point leaves the
|
|
16
|
+
* interruption visible on the next open. Clearing it first would make an
|
|
17
|
+
* interrupted deletion look complete — the exact failure FR-063 exists to
|
|
18
|
+
* prevent.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { num, text } from "./values.js";
|
|
22
|
+
const CREATE_SCOPES = `CREATE TABLE IF NOT EXISTS scopes (
|
|
23
|
+
scope_key TEXT PRIMARY KEY,
|
|
24
|
+
created_at INTEGER NOT NULL,
|
|
25
|
+
deletion_state TEXT NOT NULL,
|
|
26
|
+
backup_posture TEXT NOT NULL,
|
|
27
|
+
encrypted INTEGER NOT NULL
|
|
28
|
+
)`;
|
|
29
|
+
export async function ensureCatalog(connection) {
|
|
30
|
+
await connection.execute(CREATE_SCOPES);
|
|
31
|
+
}
|
|
32
|
+
export async function readEntry(connection, scopeKey) {
|
|
33
|
+
const result = await connection.execute('SELECT scope_key, created_at, deletion_state, backup_posture, encrypted FROM scopes WHERE scope_key = ?', [scopeKey]);
|
|
34
|
+
const row = result.rows[0];
|
|
35
|
+
if (!row) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
scopeKey: text(row.scope_key),
|
|
40
|
+
createdAt: num(row.created_at),
|
|
41
|
+
deletionState: text(row.deletion_state),
|
|
42
|
+
backupPosture: text(row.backup_posture),
|
|
43
|
+
encrypted: num(row.encrypted) === 1
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export async function listEntries(connection) {
|
|
47
|
+
const result = await connection.execute('SELECT scope_key, created_at, deletion_state, backup_posture, encrypted FROM scopes');
|
|
48
|
+
return result.rows.map(row => ({
|
|
49
|
+
scopeKey: text(row.scope_key),
|
|
50
|
+
createdAt: num(row.created_at),
|
|
51
|
+
deletionState: text(row.deletion_state),
|
|
52
|
+
backupPosture: text(row.backup_posture),
|
|
53
|
+
encrypted: num(row.encrypted) === 1
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
export async function registerScope(connection, entry) {
|
|
57
|
+
await connection.execute(`INSERT INTO scopes (scope_key, created_at, deletion_state, backup_posture, encrypted)
|
|
58
|
+
VALUES (?, ?, ?, ?, ?)
|
|
59
|
+
ON CONFLICT(scope_key) DO UPDATE SET
|
|
60
|
+
deletion_state = excluded.deletion_state,
|
|
61
|
+
backup_posture = excluded.backup_posture,
|
|
62
|
+
encrypted = excluded.encrypted`, [entry.scopeKey, entry.createdAt, entry.deletionState, entry.backupPosture, entry.encrypted ? 1 : 0]);
|
|
63
|
+
}
|
|
64
|
+
export async function markDeleting(connection, scopeKey) {
|
|
65
|
+
await connection.execute('UPDATE scopes SET deletion_state = ? WHERE scope_key = ?', ['deleting', scopeKey]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Cleared last, on purpose. See the note at the top of this file. */
|
|
69
|
+
export async function clearScope(connection, scopeKey) {
|
|
70
|
+
await connection.execute('DELETE FROM scopes WHERE scope_key = ?', [scopeKey]);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["num","text","CREATE_SCOPES","ensureCatalog","connection","execute","readEntry","scopeKey","result","row","rows","scope_key","createdAt","created_at","deletionState","deletion_state","backupPosture","backup_posture","encrypted","listEntries","map","registerScope","entry","markDeleting","clearScope"],"sourceRoot":"../../../src","sources":["sql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,IAAI,CAACQ,GAAG,CAACM,cAAc,CAAuB;IAC7DC,aAAa,EAAEf,IAAI,CAACQ,GAAG,CAACQ,cAAc,CAA4B;IAClEC,SAAS,EAAElB,GAAG,CAACS,GAAG,CAACS,SAAS,CAAC,KAAK;EACnC,CAAC,CAAC,CAAC;AACJ;AAEA,OAAO,eAAeG,aAAaA,CAACjB,UAAsB,EAAEkB,KAAmB,EAAiB;EAC/F,MAAMlB,UAAU,CAACC,OAAO,CACvB;AACF;AACA;AACA;AACA;AACA,oCAAoC,EAClC,CACCiB,KAAK,CAACf,QAAQ,EACde,KAAK,CAACV,SAAS,EACfU,KAAK,CAACR,aAAa,EACnBQ,KAAK,CAACN,aAAa,EACnBM,KAAK,CAACJ,SAAS,GAAG,CAAC,GAAG,CAAC,CAEzB,CAAC;AACF;AAEA,OAAO,eAAeK,YAAYA,CAACnB,UAAsB,EAAEG,QAAgB,EAAiB;EAC3F,MAAMH,UAAU,CAACC,OAAO,CAAC,0DAA0D,EAAE,CACpF,UAAU,EACVE,QAAQ,CACR,CAAC;AACH;;AAEA;AACA,OAAO,eAAeiB,UAAUA,CAACpB,UAAsB,EAAEG,QAAgB,EAAiB;EACzF,MAAMH,UAAU,CAACC,OAAO,CAAC,wCAAwC,EAAE,CAACE,QAAQ,CAAC,CAAC;AAC/E","ignoreList":[]}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One connection per database file.
|
|
5
|
+
*
|
|
6
|
+
* Two things about this file carry design weight:
|
|
7
|
+
*
|
|
8
|
+
* **Scope isolation is the file boundary.** A connection is opened against
|
|
9
|
+
* one scope's `data.db`, whose directory is named by the scope digest and
|
|
10
|
+
* never by the components (FR-014). No SQL this package could generate — and
|
|
11
|
+
* none a future bug could generate — reaches another scope's rows, because
|
|
12
|
+
* they are in a file this connection never opened (research.md R2).
|
|
13
|
+
*
|
|
14
|
+
* **A transaction owns the connection while it runs, and only its own
|
|
15
|
+
* executor reaches it.** Every operation queues on the connection, and a
|
|
16
|
+
* transaction holds the queue until it settles. Work issued through the
|
|
17
|
+
* connection meanwhile — a background sync, a second screen — waits and then
|
|
18
|
+
* runs on its own, rather than joining the transaction and vanishing with its
|
|
19
|
+
* rollback. Until 0.2.0 `execute` routed into whatever transaction was in
|
|
20
|
+
* flight, which is how an unrelated write was lost. Work meant to be part of
|
|
21
|
+
* the transaction goes through the executor the transaction hands out
|
|
22
|
+
* (`tx.collection`, `tx.attachments`).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { DiagnosticCodes } from "../contract/errors.js";
|
|
26
|
+
import { raise } from "../diagnostics/errors.js";
|
|
27
|
+
import { raiseNative } from "../diagnostics/map-native.js";
|
|
28
|
+
import { fileSystem } from "../platform/fs.js";
|
|
29
|
+
import { createTransactionQueue } from "./transaction-queue.js";
|
|
30
|
+
import { engine } from "./native.js";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The executor a transaction body runs against, plus the one control it
|
|
34
|
+
* needs. `rollback` is handed to the body rather than returned from
|
|
35
|
+
* `transaction`, so an explicit abort cannot outlive the transaction it
|
|
36
|
+
* belongs to.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
function splitPath(path) {
|
|
40
|
+
const index = path.lastIndexOf('/');
|
|
41
|
+
return index === -1 ? {
|
|
42
|
+
location: '',
|
|
43
|
+
name: path
|
|
44
|
+
} : {
|
|
45
|
+
location: path.slice(0, index),
|
|
46
|
+
name: path.slice(index + 1)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export async function openConnection(options) {
|
|
50
|
+
const {
|
|
51
|
+
location,
|
|
52
|
+
name
|
|
53
|
+
} = splitPath(options.path);
|
|
54
|
+
const encrypted = options.encryptionKey !== undefined;
|
|
55
|
+
try {
|
|
56
|
+
await fileSystem().mkdir(location);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
raiseNative(error, {
|
|
59
|
+
operation: 'open'
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
let database;
|
|
63
|
+
try {
|
|
64
|
+
database = engine().open({
|
|
65
|
+
name,
|
|
66
|
+
location,
|
|
67
|
+
// Passing the key only when encryption is on keeps an unencrypted
|
|
68
|
+
// database from being opened as an encrypted one with an empty key,
|
|
69
|
+
// which SQLCipher accepts and which would produce a file neither
|
|
70
|
+
// posture can reopen.
|
|
71
|
+
...(encrypted ? {
|
|
72
|
+
encryptionKey: options.encryptionKey
|
|
73
|
+
} : {})
|
|
74
|
+
});
|
|
75
|
+
} catch (error) {
|
|
76
|
+
raiseNative(error, {
|
|
77
|
+
operation: 'open',
|
|
78
|
+
encrypted
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
let closed = false;
|
|
82
|
+
let active = null;
|
|
83
|
+
const queue = createTransactionQueue();
|
|
84
|
+
const assertOpen = () => {
|
|
85
|
+
if (closed) {
|
|
86
|
+
raise(DiagnosticCodes.CLOSED_HANDLE, {
|
|
87
|
+
message: 'connection is closed'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const classify = sql => /^\s*select|^\s*pragma|^\s*explain/i.test(sql) ? 'read' : 'write';
|
|
92
|
+
const connection = {
|
|
93
|
+
path: options.path,
|
|
94
|
+
encrypted,
|
|
95
|
+
execute(sql, params = []) {
|
|
96
|
+
assertOpen();
|
|
97
|
+
// Never into an in-flight transaction: queued behind it instead. See
|
|
98
|
+
// the note at the top of this file.
|
|
99
|
+
return queue.run(async () => {
|
|
100
|
+
try {
|
|
101
|
+
return await database.execute(sql, params);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
raiseNative(error, {
|
|
104
|
+
operation: classify(sql),
|
|
105
|
+
encrypted
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
async transaction(fn) {
|
|
111
|
+
assertOpen();
|
|
112
|
+
if (active) {
|
|
113
|
+
// Nested transactions would need savepoints and would let a
|
|
114
|
+
// partial rollback look like a full one. Refused rather than
|
|
115
|
+
// queued: a body that opened a second transaction would otherwise
|
|
116
|
+
// wait on itself forever.
|
|
117
|
+
raise(DiagnosticCodes.TRANSACTION_STATE, {
|
|
118
|
+
message: 'a transaction is already in flight on this connection'
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return queue.runTransaction(async () => {
|
|
122
|
+
try {
|
|
123
|
+
return await database.transaction(async tx => {
|
|
124
|
+
active = tx;
|
|
125
|
+
let settled = false;
|
|
126
|
+
try {
|
|
127
|
+
return await fn({
|
|
128
|
+
execute: (sql, params = []) => {
|
|
129
|
+
if (settled) {
|
|
130
|
+
// After an explicit rollback the body is still running
|
|
131
|
+
// inside the engine's callback. Its remaining statements
|
|
132
|
+
// are refused, not run in autocommit (LDB-V1).
|
|
133
|
+
raise(DiagnosticCodes.TRANSACTION_STATE, {
|
|
134
|
+
message: 'transaction already rolled back'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return tx.execute(sql, params);
|
|
138
|
+
},
|
|
139
|
+
rollback: async () => {
|
|
140
|
+
await tx.rollback();
|
|
141
|
+
settled = true;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} finally {
|
|
145
|
+
active = null;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
raiseNative(error, {
|
|
150
|
+
operation: 'transaction',
|
|
151
|
+
encrypted
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
executeBatch(commands) {
|
|
157
|
+
assertOpen();
|
|
158
|
+
return queue.run(async () => {
|
|
159
|
+
try {
|
|
160
|
+
await database.executeBatch(commands);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
raiseNative(error, {
|
|
163
|
+
operation: 'write',
|
|
164
|
+
encrypted
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
async close() {
|
|
170
|
+
if (closed) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
closed = true;
|
|
174
|
+
try {
|
|
175
|
+
await database.close();
|
|
176
|
+
} catch {
|
|
177
|
+
// A close that fails leaves nothing for a caller to do, and
|
|
178
|
+
// reporting it would turn an orderly sign-out into an error.
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// Write-ahead logging so a reader is not blocked by the writer — FR-045's
|
|
184
|
+
// "reads proceed while a write is in flight" is this pragma plus op-sqlite's
|
|
185
|
+
// single-writer serialization, not a lock this package maintains.
|
|
186
|
+
await connection.execute('PRAGMA journal_mode = WAL');
|
|
187
|
+
await connection.execute('PRAGMA foreign_keys = ON');
|
|
188
|
+
// Durability over speed: a half-written record after a crash is exactly
|
|
189
|
+
// what FR-039 promises never happens.
|
|
190
|
+
await connection.execute('PRAGMA synchronous = FULL');
|
|
191
|
+
return connection;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Confirm a freshly opened database is readable.
|
|
196
|
+
*
|
|
197
|
+
* Deliberately not `PRAGMA integrity_check`: that walks the whole file and
|
|
198
|
+
* would put open time far past the 150-millisecond budget on a large scope.
|
|
199
|
+
* One trivial read is enough to surface the failures that matter at open —
|
|
200
|
+
* a wrong key, a truncated file, a malformed header — because all three fail
|
|
201
|
+
* it, and the error mapping keeps them distinguishable (FR-076, FR-078).
|
|
202
|
+
*/
|
|
203
|
+
export async function assertReadable(connection) {
|
|
204
|
+
await connection.execute('SELECT count(*) AS n FROM sqlite_master');
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DiagnosticCodes","raise","raiseNative","fileSystem","createTransactionQueue","engine","splitPath","path","index","lastIndexOf","location","name","slice","openConnection","options","encrypted","encryptionKey","undefined","mkdir","error","operation","database","open","closed","active","queue","assertOpen","CLOSED_HANDLE","message","classify","sql","test","connection","execute","params","run","transaction","fn","TRANSACTION_STATE","runTransaction","tx","settled","rollback","executeBatch","commands","close","assertReadable"],"sourceRoot":"../../../src","sources":["sqlite/connection.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,uBAAoB;AACpD,SAASC,KAAK,QAAQ,0BAAuB;AAC7C,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SAASC,UAAU,QAAQ,mBAAgB;AAC3C,SAASC,sBAAsB,QAAQ,wBAAqB;AAC5D,SACCC,MAAM,QAKA,aAAU;;AAMjB;AACA;AACA;AACA;AACA;AACA;;AAmBA,SAASC,SAASA,CAACC,IAAY,EAAsC;EACpE,MAAMC,KAAK,GAAGD,IAAI,CAACE,WAAW,CAAC,GAAG,CAAC;EACnC,OAAOD,KAAK,KAAK,CAAC,CAAC,GAChB;IAAEE,QAAQ,EAAE,EAAE;IAAEC,IAAI,EAAEJ;EAAK,CAAC,GAC5B;IAAEG,QAAQ,EAAEH,IAAI,CAACK,KAAK,CAAC,CAAC,EAAEJ,KAAK,CAAC;IAAEG,IAAI,EAAEJ,IAAI,CAACK,KAAK,CAACJ,KAAK,GAAG,CAAC;EAAE,CAAC;AACnE;AAEA,OAAO,eAAeK,cAAcA,CAACC,OAA8B,EAAuB;EACzF,MAAM;IAAEJ,QAAQ;IAAEC;EAAK,CAAC,GAAGL,SAAS,CAACQ,OAAO,CAACP,IAAI,CAAC;EAClD,MAAMQ,SAAS,GAAGD,OAAO,CAACE,aAAa,KAAKC,SAAS;EAErD,IAAI;IACH,MAAMd,UAAU,CAAC,CAAC,CAACe,KAAK,CAACR,QAAQ,CAAC;EACnC,CAAC,CAAC,OAAOS,KAAK,EAAE;IACfjB,WAAW,CAACiB,KAAK,EAAE;MAAEC,SAAS,EAAE;IAAO,CAAC,CAAC;EAC1C;EAEA,IAAIC,Q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AAK,EAAE;UACfjB,WAAW,CAACiB,KAAK,EAAE;YAAEC,SAAS,EAAE,OAAO;YAAEL;UAAU,CAAC,CAAC;QACtD;MACD,CAAC,CAAC;IACH,CAAC;IAED,MAAM8B,KAAKA,CAAA,EAAG;MACb,IAAItB,MAAM,EAAE;QACX;MACD;MACAA,MAAM,GAAG,IAAI;MACb,IAAI;QACH,MAAMF,QAAQ,CAACwB,KAAK,CAAC,CAAC;MACvB,CAAC,CAAC,MAAM;QACP;QACA;MAAA;IAEF;EACD,CAAC;;EAED;EACA;EACA;EACA,MAAMb,UAAU,CAACC,OAAO,CAAC,2BAA2B,CAAC;EACrD,MAAMD,UAAU,CAACC,OAAO,CAAC,0BAA0B,CAAC;EACpD;EACA;EACA,MAAMD,UAAU,CAACC,OAAO,CAAC,2BAA2B,CAAC;EAErD,OAAOD,UAAU;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAec,cAAcA,CAACd,UAAsB,EAAiB;EAC3E,MAAMA,UAAU,CAACC,OAAO,CAAC,yCAAyC,CAAC;AACpE","ignoreList":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* "Is this query covered by an index?", answered by the engine rather than by
|
|
5
|
+
* inspection of the declarations (FR-037).
|
|
6
|
+
*
|
|
7
|
+
* Reading the schema would answer what the developer intended; `EXPLAIN QUERY
|
|
8
|
+
* PLAN` answers what SQLite will actually do, and the two diverge exactly
|
|
9
|
+
* where it matters — a filter on an indexed field that the planner declines
|
|
10
|
+
* because of a type mismatch or a leading wildcard still reports as "indexed"
|
|
11
|
+
* if you only read declarations.
|
|
12
|
+
*
|
|
13
|
+
* Exposed as a development-mode diagnostic. It runs an extra statement, so an
|
|
14
|
+
* app calling it on every list would pay for it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { collectionTable } from "../schema/declare.js";
|
|
18
|
+
import { buildFilter, buildOrderBy } from "./sql-builder.js";
|
|
19
|
+
import { declaredIndexName } from "./row-codec.js";
|
|
20
|
+
const SCAN = /\bSCAN\b/i;
|
|
21
|
+
const USING_INDEX = /USING\s+(COVERING\s+)?INDEX\s+"?([A-Za-z0-9_]+)"?/i;
|
|
22
|
+
export async function explainQuery(executor, schema, query, sort) {
|
|
23
|
+
const filter = buildFilter(query?.filter);
|
|
24
|
+
const table = collectionTable(schema.name);
|
|
25
|
+
const sql = `EXPLAIN QUERY PLAN SELECT id FROM "${table}" WHERE ${filter.sql} ORDER BY ${buildOrderBy(sort)}`;
|
|
26
|
+
const result = await executor.execute(sql, filter.params);
|
|
27
|
+
const detail = result.rows.map(row => String(row.detail ?? row.DETAIL ?? '')).filter(Boolean).join('; ');
|
|
28
|
+
const match = USING_INDEX.exec(detail);
|
|
29
|
+
return {
|
|
30
|
+
collection: schema.name,
|
|
31
|
+
usesIndex: match !== null,
|
|
32
|
+
// Reported under the name the app declared, not the collection-scoped
|
|
33
|
+
// name it has in the file.
|
|
34
|
+
indexName: match?.[2] === undefined ? undefined : declaredIndexName(schema, match[2]),
|
|
35
|
+
detail: detail || (SCAN.test(detail) ? 'full table scan' : 'the engine returned no plan for this query')
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index-coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["collectionTable","buildFilter","buildOrderBy","declaredIndexName","SCAN","USING_INDEX","explainQuery","executor","schema","query","sort","filter","table","name","sql","result","execute","params","detail","rows","map","row","String","DETAIL","Boolean","join","match","exec","collection","usesIndex","indexName","undefined","test"],"sourceRoot":"../../../src","sources":["sqlite/index-coverage.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,eAAe,QAAQ,sBAAmB;AAEnD,SAASC,WAAW,EAAEC,YAAY,QAAQ,kBAAe;AACzD,SAASC,iBAAiB,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
4
|
+
* The storage engine peer, behind one lazy accessor.
|
|
5
|
+
*
|
|
6
|
+
* Every native call the package makes to SQLite passes through this type.
|
|
7
|
+
* Note what is missing: `executeSync`. op-sqlite ships it, and using it would
|
|
8
|
+
* put a database read on the interface thread — the one thing PERF-001's
|
|
9
|
+
* 16-millisecond rule cannot survive (research.md R9). A surface that cannot
|
|
10
|
+
* express the synchronous call is a stronger guarantee than a review comment.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { lazyPeer } from '@chipmobilesdk/rn-core';
|
|
14
|
+
import { DiagnosticCodes } from "../contract/errors.js";
|
|
15
|
+
import { StorageError } from "../diagnostics/errors.js";
|
|
16
|
+
/** Loaded on first use (rn-core's lazy peer); a missing peer is `OPEN_FAILED`. */
|
|
17
|
+
const sqlite = lazyPeer('@op-engineering/op-sqlite', () => {
|
|
18
|
+
// Inside `try`, so Metro bundles an app that leaves this optional peer out.
|
|
19
|
+
try {
|
|
20
|
+
return require('@op-engineering/op-sqlite');
|
|
21
|
+
} catch (cause) {
|
|
22
|
+
throw cause;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** Swap the engine. Tests only; `null` goes back to the real one. */
|
|
27
|
+
export function setEngine(next) {
|
|
28
|
+
sqlite.override(next ?? undefined);
|
|
29
|
+
}
|
|
30
|
+
export function engine() {
|
|
31
|
+
return sqlite.require((_peer, cause) => new StorageError(DiagnosticCodes.OPEN_FAILED, {
|
|
32
|
+
message: 'storage engine peer is not installed',
|
|
33
|
+
cause
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether SQLCipher is compiled into this build.
|
|
39
|
+
*
|
|
40
|
+
* A build flag in the consuming app, not a separate peer (research.md R1a).
|
|
41
|
+
* An app that enables encryption without it must fail loudly rather than
|
|
42
|
+
* write plaintext to a file it believes is encrypted.
|
|
43
|
+
*/
|
|
44
|
+
export function isEncryptionAvailable() {
|
|
45
|
+
const current = engine();
|
|
46
|
+
return typeof current.isSQLCipher === 'function' ? current.isSQLCipher() === true : false;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["lazyPeer","DiagnosticCodes","StorageError","sqlite","require","cause","setEngine","next","override","undefined","engine","_peer","OPEN_FAILED","message","isEncryptionAvailable","current","isSQLCipher"],"sourceRoot":"../../../src","sources":["sqlite/native.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,wBAAwB;AAEjD,SAASC,eAAe,QAAQ,uBAAoB;AACpD,SAASC,YAAY,QAAQ,0BAAuB;AAmCpD;AACA,MAAMC,MAAM,GAAGH,QAAQ,CAAC,2BAA2B,EAAE,MAAM;EAC1D;EACA,IAAI;IACH,OAAOI,OAAO,CAAC,2BAA2B,CAAC;EAC5C,CAAC,CAAC,OAAOC,KAAK,EAAE;IACf,MAAMA,KAAK;EACZ;AACD,CAAC,CAAC;;AAEF;AACA,OAAO,SAASC,SAASA,CAACC,IAAmB,EAAQ;EACpDJ,MAAM,CAACK,QAAQ,CAACD,IAAI,IAAIE,SAAS,CAAC;AACnC;AAEA,OAAO,SAASC,MAAMA,CAAA,EAAW;EAChC,OAAOP,MAAM,CAACC,OAAO,CACpB,CAACO,KAAK,EAAEN,KAAK,KACZ,IAAIH,YAAY,CAACD,eAAe,CAACW,WAAW,EAAE;IAC7CC,OAAO,EAAE,sCAAsC;IAC/CR;EACD,CAAC,CACH,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,qBAAqBA,CAAA,EAAY;EAChD,MAAMC,OAAO,GAAGL,MAAM,CAAC,CAAC;EACxB,OAAO,OAAOK,OAAO,CAACC,WAAW,KAAK,UAAU,GAAGD,OAAO,CAACC,WAAW,CAAC,CAAC,KAAK,IAAI,GAAG,KAAK;AAC1F","ignoreList":[]}
|