@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,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Table shape, and the payload-as-truth rule.
|
|
5
|
+
*
|
|
6
|
+
* Every read reconstructs the record from `payload` alone. The projected
|
|
7
|
+
* `f_*` columns are written on every write and consulted only by `WHERE` and
|
|
8
|
+
* `ORDER BY` — never by a read path (research.md R6).
|
|
9
|
+
*
|
|
10
|
+
* That single rule is what makes two requirements structural rather than
|
|
11
|
+
* carefully maintained. FR-018's byte fidelity holds because nothing else is
|
|
12
|
+
* consulted to rebuild a record, and FR-019's explicit-null versus
|
|
13
|
+
* absent-field distinction holds because a NULL projected column cannot be
|
|
14
|
+
* ambiguous if no read ever looks at it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { collectionTable, hasSoftDelete, hasTimestamps, projectedColumn } from "../schema/declare.js";
|
|
18
|
+
import { num, text } from "./values.js";
|
|
19
|
+
export const RESERVED_COLUMNS = ['id', 'payload', 'created_at', 'updated_at', 'deleted_at'];
|
|
20
|
+
|
|
21
|
+
/** SQLite affinity for a declared field type. */
|
|
22
|
+
function affinityOf(field) {
|
|
23
|
+
switch (field.type) {
|
|
24
|
+
case 'number':
|
|
25
|
+
case 'timestamp':
|
|
26
|
+
return 'REAL';
|
|
27
|
+
case 'boolean':
|
|
28
|
+
return 'INTEGER';
|
|
29
|
+
case 'string':
|
|
30
|
+
default:
|
|
31
|
+
return 'TEXT';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function createTableSql(schema) {
|
|
35
|
+
const columns = ['id TEXT PRIMARY KEY', 'payload TEXT NOT NULL', 'created_at INTEGER', 'updated_at INTEGER', 'deleted_at INTEGER', ...(schema.fields ?? []).map(field => `"${projectedColumn(field.name)}" ${affinityOf(field)}`)];
|
|
36
|
+
return `CREATE TABLE IF NOT EXISTS "${collectionTable(schema.name)}" (${columns.join(', ')})`;
|
|
37
|
+
}
|
|
38
|
+
export function addColumnSql(schema, field) {
|
|
39
|
+
return `ALTER TABLE "${collectionTable(schema.name)}" ADD COLUMN "${projectedColumn(field.name)}" ${affinityOf(field)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The name an index has in the database file.
|
|
44
|
+
*
|
|
45
|
+
* Index names are database-wide in SQLite, but declared per collection. Until
|
|
46
|
+
* 0.2.0 the declared name was used as is, so a second collection declaring an
|
|
47
|
+
* index of the same name hit `IF NOT EXISTS` and silently got no index — a
|
|
48
|
+
* UNIQUE constraint included. The double underscore keeps a declared name from
|
|
49
|
+
* colliding with the package's own `<table>_live` index.
|
|
50
|
+
*/
|
|
51
|
+
export function physicalIndexName(schema, declaredName) {
|
|
52
|
+
return `${collectionTable(schema.name)}__${declaredName}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The declared name back from a physical one, for reporting to the app. */
|
|
56
|
+
export function declaredIndexName(schema, physicalName) {
|
|
57
|
+
const prefix = `${collectionTable(schema.name)}__`;
|
|
58
|
+
return physicalName.startsWith(prefix) ? physicalName.slice(prefix.length) : physicalName;
|
|
59
|
+
}
|
|
60
|
+
export function createIndexSql(schema) {
|
|
61
|
+
const table = collectionTable(schema.name);
|
|
62
|
+
const statements = (schema.indexes ?? []).map(index => {
|
|
63
|
+
const columns = index.fields.map(field => `"${projectedColumn(field)}"`).join(', ');
|
|
64
|
+
return `CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX IF NOT EXISTS "${physicalIndexName(schema, index.name)}" ON "${table}" (${columns})`;
|
|
65
|
+
});
|
|
66
|
+
if (hasSoftDelete(schema)) {
|
|
67
|
+
// Every default query carries `deleted_at IS NULL`, so without this the
|
|
68
|
+
// exclusion turns the cheapest possible filter into a full scan.
|
|
69
|
+
statements.push(`CREATE INDEX IF NOT EXISTS "${table}_live" ON "${table}" (deleted_at)`);
|
|
70
|
+
}
|
|
71
|
+
return statements;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Project a declared field for the WHERE and ORDER BY columns.
|
|
76
|
+
*
|
|
77
|
+
* Anything that is not a comparable primitive projects to NULL. A nested
|
|
78
|
+
* object has no defensible ordering, and inventing one would make a filter
|
|
79
|
+
* silently match records a consumer never meant to select.
|
|
80
|
+
*/
|
|
81
|
+
export function projectValue(data, field) {
|
|
82
|
+
if (!Object.prototype.hasOwnProperty.call(data, field.name)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const value = data[field.name];
|
|
86
|
+
if (value === null) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
switch (typeof value) {
|
|
90
|
+
case 'boolean':
|
|
91
|
+
return value ? 1 : 0;
|
|
92
|
+
case 'number':
|
|
93
|
+
return Number.isFinite(value) ? value : null;
|
|
94
|
+
case 'string':
|
|
95
|
+
return value;
|
|
96
|
+
default:
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function projectedValues(schema, data) {
|
|
101
|
+
return (schema.fields ?? []).map(field => projectValue(data, field));
|
|
102
|
+
}
|
|
103
|
+
export function projectedColumnNames(schema) {
|
|
104
|
+
return (schema.fields ?? []).map(field => projectedColumn(field.name));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Serialize on the way in, so a caller mutating its object cannot change
|
|
108
|
+
* what is stored (FR-022). */
|
|
109
|
+
export function encodePayload(data) {
|
|
110
|
+
return JSON.stringify(data ?? {});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Rebuild a record from the payload column and nothing else.
|
|
114
|
+
*
|
|
115
|
+
* The timestamp and soft-delete fields are surfaced only when the collection
|
|
116
|
+
* declared them, so a consumer cannot come to depend on a field the schema
|
|
117
|
+
* never promised.
|
|
118
|
+
*/
|
|
119
|
+
export function decodeRow(schema, row) {
|
|
120
|
+
const record = {
|
|
121
|
+
id: text(row.id),
|
|
122
|
+
data: JSON.parse(text(row.payload))
|
|
123
|
+
};
|
|
124
|
+
if (hasTimestamps(schema)) {
|
|
125
|
+
if (row.created_at != null) {
|
|
126
|
+
record.createdAt = num(row.created_at);
|
|
127
|
+
}
|
|
128
|
+
if (row.updated_at != null) {
|
|
129
|
+
record.updatedAt = num(row.updated_at);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (hasSoftDelete(schema)) {
|
|
133
|
+
record.deletedAt = row.deleted_at == null ? null : num(row.deleted_at);
|
|
134
|
+
}
|
|
135
|
+
return record;
|
|
136
|
+
}
|
|
137
|
+
export function insertColumns(schema, id, data, now, /** The payload already serialized by the budget check, to avoid a second pass. */
|
|
138
|
+
payload = encodePayload(data)) {
|
|
139
|
+
const columns = ['id', 'payload'];
|
|
140
|
+
const values = [id, payload];
|
|
141
|
+
if (hasTimestamps(schema)) {
|
|
142
|
+
columns.push('created_at', 'updated_at');
|
|
143
|
+
values.push(now, now);
|
|
144
|
+
}
|
|
145
|
+
if (hasSoftDelete(schema)) {
|
|
146
|
+
columns.push('deleted_at');
|
|
147
|
+
values.push(null);
|
|
148
|
+
}
|
|
149
|
+
const projected = projectedValues(schema, data);
|
|
150
|
+
for (const [index, name] of projectedColumnNames(schema).entries()) {
|
|
151
|
+
columns.push(name);
|
|
152
|
+
values.push(projected[index]);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
columns,
|
|
156
|
+
values
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function updateAssignments(schema, data, now, payload = encodePayload(data)) {
|
|
160
|
+
const columns = ['payload'];
|
|
161
|
+
const values = [payload];
|
|
162
|
+
if (hasTimestamps(schema)) {
|
|
163
|
+
columns.push('updated_at');
|
|
164
|
+
values.push(now);
|
|
165
|
+
}
|
|
166
|
+
const projected = projectedValues(schema, data);
|
|
167
|
+
for (const [index, name] of projectedColumnNames(schema).entries()) {
|
|
168
|
+
columns.push(name);
|
|
169
|
+
values.push(projected[index]);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
columns,
|
|
173
|
+
values
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=row-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["collectionTable","hasSoftDelete","hasTimestamps","projectedColumn","num","text","RESERVED_COLUMNS","affinityOf","field","type","createTableSql","schema","columns","fields","map","name","join","addColumnSql","physicalIndexName","declaredName","declaredIndexName","physicalName","prefix","startsWith","slice","length","createIndexSql","table","statements","indexes","index","unique","push","projectValue","data","Object","prototype","hasOwnProperty","call","value","Number","isFinite","projectedValues","projectedColumnNames","encodePayload","JSON","stringify","decodeRow","row","record","id","parse","payload","created_at","createdAt","updated_at","updatedAt","deletedAt","deleted_at","insertColumns","now","values","projected","entries","updateAssignments"],"sourceRoot":"../../../src","sources":["sqlite/row-codec.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,eAAe,EAAEC,aAAa,EAAEC,aAAa,EAAEC,eAAe,QAAQ,sBAAmB;AAElG,SAASC,GAAG,EAAEC,IAAI,QAAQ,aAAU;AAEpC,OAAO,MAAMC,gBAAgB,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;;AAE3F;AACA,SAASC,UAAUA,CAACC,KAAuB,EAAU;EACpD,QAAQA,KAAK,CAACC,IAAI;IACjB,KAAK,QAAQ;IACb,KAAK,WAAW;MACf,OAAO,MAAM;IACd,KAAK,SAAS;MACb,OAAO,SAAS;IACjB,KAAK,QAAQ;IACb;MACC,OAAO,MAAM;EACf;AACD;AAEA,OAAO,SAASC,cAAcA,CAACC,MAAwB,EAAU;EAChE,MAAMC,OAAO,GAAG,CACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,GAAG,CAACD,MAAM,CAACE,MAAM,IAAI,EAAE,EAAEC,GAAG,CAACN,KAAK,IAAI,IAAIL,eAAe,CAACK,KAAK,CAACO,IAAI,CAAC,KAAKR,UAAU,CAACC,KAAK,CAAC,EAAE,CAAC,CAC9F;EACD,OAAO,+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SAAS,CAAChC,KAAK,CAAE,CAAC;EAC/B;EACA,OAAO;IAAElB,OAAO;IAAEiD;EAAO,CAAC;AAC3B","ignoreList":[]}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filter tree to parameterized SQL.
|
|
5
|
+
*
|
|
6
|
+
* Nothing a consumer supplies is ever concatenated into a statement. Field
|
|
7
|
+
* names are resolved through the schema first — validation has already run
|
|
8
|
+
* and rejected anything undeclared (FR-034) — so the only identifiers that
|
|
9
|
+
* reach SQL are ones this package generated from a declaration it checked.
|
|
10
|
+
* Values bind as parameters, without exception. Injection stops being a thing
|
|
11
|
+
* to remember and becomes a thing the shape of the code prevents.
|
|
12
|
+
*
|
|
13
|
+
* The other half of this file is keyset pagination. `OFFSET` was rejected for
|
|
14
|
+
* two measured reasons (research.md R6): it degrades linearly at the 100,000
|
|
15
|
+
* record budget because the engine still walks the skipped rows, and it
|
|
16
|
+
* shifts pages under concurrent writes so a record can be skipped or returned
|
|
17
|
+
* twice — the exact failure SC-007 forbids.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { projectedColumn } from "../schema/declare.js";
|
|
21
|
+
const TRUE = {
|
|
22
|
+
sql: '1',
|
|
23
|
+
params: []
|
|
24
|
+
};
|
|
25
|
+
const FALSE = {
|
|
26
|
+
sql: '0',
|
|
27
|
+
params: []
|
|
28
|
+
};
|
|
29
|
+
function columnFor(field) {
|
|
30
|
+
return field === 'id' ? 'id' : `"${projectedColumn(field)}"`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The JSON path for a declared field.
|
|
35
|
+
*
|
|
36
|
+
* Safe to interpolate: the field name came from a schema declaration that
|
|
37
|
+
* validation already matched against `^[A-Za-z][A-Za-z0-9_]{0,62}$`, so it
|
|
38
|
+
* cannot carry a quote, a dollar sign, or a path separator.
|
|
39
|
+
*/
|
|
40
|
+
function jsonType(field) {
|
|
41
|
+
return `json_type(payload, '$.${field}')`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Present, and holding something a comparison can be defined over. */
|
|
45
|
+
function presentPrimitive(field) {
|
|
46
|
+
return `(${jsonType(field)} IS NOT NULL AND ${jsonType(field)} NOT IN ('object', 'array'))`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Present and explicitly null — the condition `isNull` actually means. */
|
|
50
|
+
function isExplicitNull(field) {
|
|
51
|
+
return `${jsonType(field)} = 'null'`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Booleans project to 0/1, so a bound parameter has to match. */
|
|
55
|
+
function bind(value) {
|
|
56
|
+
return typeof value === 'boolean' ? value ? 1 : 0 : value;
|
|
57
|
+
}
|
|
58
|
+
function comparison(node) {
|
|
59
|
+
const field = node.field;
|
|
60
|
+
const column = columnFor(field);
|
|
61
|
+
switch (node.op) {
|
|
62
|
+
case 'exists':
|
|
63
|
+
return {
|
|
64
|
+
sql: node.value ? `${jsonType(field)} IS NOT NULL` : `${jsonType(field)} IS NULL`,
|
|
65
|
+
params: []
|
|
66
|
+
};
|
|
67
|
+
case 'isNull':
|
|
68
|
+
return {
|
|
69
|
+
sql: isExplicitNull(field),
|
|
70
|
+
params: []
|
|
71
|
+
};
|
|
72
|
+
case 'isNotNull':
|
|
73
|
+
return {
|
|
74
|
+
sql: `(${jsonType(field)} IS NOT NULL AND ${jsonType(field)} != 'null')`,
|
|
75
|
+
params: []
|
|
76
|
+
};
|
|
77
|
+
case 'eq':
|
|
78
|
+
// Matching an explicit null needs the JSON type: `col = NULL` is
|
|
79
|
+
// NULL in SQL, which is not true, and a projected NULL cannot tell
|
|
80
|
+
// "absent" from "null" on its own.
|
|
81
|
+
return node.value === null ? {
|
|
82
|
+
sql: isExplicitNull(field),
|
|
83
|
+
params: []
|
|
84
|
+
} : {
|
|
85
|
+
sql: `${column} = ?`,
|
|
86
|
+
params: [bind(node.value)]
|
|
87
|
+
};
|
|
88
|
+
case 'ne':
|
|
89
|
+
return node.value === null ? {
|
|
90
|
+
sql: `(${presentPrimitive(field)} AND ${jsonType(field)} != 'null')`,
|
|
91
|
+
params: []
|
|
92
|
+
} : {
|
|
93
|
+
sql: `(${presentPrimitive(field)} AND ${column} IS NOT ?)`,
|
|
94
|
+
params: [bind(node.value)]
|
|
95
|
+
};
|
|
96
|
+
case 'lt':
|
|
97
|
+
case 'lte':
|
|
98
|
+
case 'gt':
|
|
99
|
+
case 'gte':
|
|
100
|
+
{
|
|
101
|
+
if (node.value === null) {
|
|
102
|
+
// An ordered comparison against null has no answer; SQL would
|
|
103
|
+
// return NULL and the in-memory adapter returns false. Being
|
|
104
|
+
// explicit keeps the two identical.
|
|
105
|
+
return FALSE;
|
|
106
|
+
}
|
|
107
|
+
const operator = {
|
|
108
|
+
lt: '<',
|
|
109
|
+
lte: '<=',
|
|
110
|
+
gt: '>',
|
|
111
|
+
gte: '>='
|
|
112
|
+
}[node.op];
|
|
113
|
+
return {
|
|
114
|
+
sql: `(${column} IS NOT NULL AND ${column} ${operator} ?)`,
|
|
115
|
+
params: [bind(node.value)]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
case 'between':
|
|
119
|
+
{
|
|
120
|
+
const [low, high] = node.value;
|
|
121
|
+
if (low === null || high === null) {
|
|
122
|
+
return FALSE;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
sql: `(${column} IS NOT NULL AND ${column} BETWEEN ? AND ?)`,
|
|
126
|
+
params: [bind(low), bind(high)]
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
case 'in':
|
|
130
|
+
case 'nin':
|
|
131
|
+
{
|
|
132
|
+
const values = node.value;
|
|
133
|
+
const nonNull = values.filter(value => value !== null);
|
|
134
|
+
const acceptsNull = values.length !== nonNull.length;
|
|
135
|
+
const clauses = [];
|
|
136
|
+
const params = [];
|
|
137
|
+
if (nonNull.length > 0) {
|
|
138
|
+
clauses.push(`${column} IN (${nonNull.map(() => '?').join(', ')})`);
|
|
139
|
+
params.push(...nonNull.map(value => bind(value)));
|
|
140
|
+
}
|
|
141
|
+
if (acceptsNull) {
|
|
142
|
+
clauses.push(isExplicitNull(field));
|
|
143
|
+
}
|
|
144
|
+
const membership = clauses.length > 0 ? `(${clauses.join(' OR ')})` : '0';
|
|
145
|
+
if (node.op === 'in') {
|
|
146
|
+
return {
|
|
147
|
+
sql: membership,
|
|
148
|
+
params
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// `nin` excludes, but only among records that have the field at
|
|
152
|
+
// all: an absent field satisfies no comparison, negated or not.
|
|
153
|
+
return {
|
|
154
|
+
sql: `(${presentPrimitive(field)} AND NOT IFNULL(${membership}, 0))`,
|
|
155
|
+
params
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
default:
|
|
159
|
+
return FALSE;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export function buildFilter(node) {
|
|
163
|
+
if (!node) {
|
|
164
|
+
return TRUE;
|
|
165
|
+
}
|
|
166
|
+
switch (node.op) {
|
|
167
|
+
case 'and':
|
|
168
|
+
case 'or':
|
|
169
|
+
{
|
|
170
|
+
const parts = node.nodes.map(child => buildFilter(child));
|
|
171
|
+
return {
|
|
172
|
+
sql: `(${parts.map(part => part.sql).join(node.op === 'and' ? ' AND ' : ' OR ')})`,
|
|
173
|
+
params: parts.flatMap(part => part.params)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
case 'not':
|
|
177
|
+
{
|
|
178
|
+
const inner = buildFilter(node.node);
|
|
179
|
+
// IFNULL, because NOT NULL is NULL in SQL and would quietly drop
|
|
180
|
+
// rows the in-memory adapter keeps.
|
|
181
|
+
return {
|
|
182
|
+
sql: `(NOT IFNULL(${inner.sql}, 0))`,
|
|
183
|
+
params: inner.params
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
default:
|
|
187
|
+
return comparison(node);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
export function buildOrderBy(sort) {
|
|
191
|
+
return sort.map(key => `${columnFor(key.field)} ${key.direction === 'desc' ? 'DESC' : 'ASC'}`).join(', ');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The keyset predicate: everything strictly after the cursor position.
|
|
196
|
+
*
|
|
197
|
+
* Lexicographic across the sort keys — equal on the first means the second
|
|
198
|
+
* decides, down to the `id` tiebreaker that guarantees a total order. NULL is
|
|
199
|
+
* treated as smaller than every value, matching both SQLite's default
|
|
200
|
+
* ordering and `compareValues`, so the two adapters page identically.
|
|
201
|
+
*/
|
|
202
|
+
export function buildKeysetPredicate(sort, anchor) {
|
|
203
|
+
const params = [];
|
|
204
|
+
const build = index => {
|
|
205
|
+
if (index >= sort.length) {
|
|
206
|
+
return '0';
|
|
207
|
+
}
|
|
208
|
+
const key = sort[index];
|
|
209
|
+
const column = columnFor(key.field);
|
|
210
|
+
const value = anchor[index] ?? null;
|
|
211
|
+
const descending = key.direction === 'desc';
|
|
212
|
+
let strictly;
|
|
213
|
+
if (descending) {
|
|
214
|
+
if (value === null) {
|
|
215
|
+
// Nothing sorts before null, so a descending walk anchored on
|
|
216
|
+
// null has nothing left ahead of it on this key.
|
|
217
|
+
strictly = '0';
|
|
218
|
+
} else {
|
|
219
|
+
strictly = `(${column} IS NULL OR ${column} < ?)`;
|
|
220
|
+
params.push(bind(value));
|
|
221
|
+
}
|
|
222
|
+
} else if (value === null) {
|
|
223
|
+
strictly = `${column} IS NOT NULL`;
|
|
224
|
+
} else {
|
|
225
|
+
strictly = `${column} > ?`;
|
|
226
|
+
params.push(bind(value));
|
|
227
|
+
}
|
|
228
|
+
const equal = `${column} IS ?`;
|
|
229
|
+
const equalParam = bind(value);
|
|
230
|
+
if (index === sort.length - 1) {
|
|
231
|
+
return strictly;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Params are pushed in the order the fragments are concatenated, so the
|
|
235
|
+
// equality parameter has to land between this key's comparison and the
|
|
236
|
+
// next key's fragment.
|
|
237
|
+
const head = `(${strictly} OR (${equal} AND `;
|
|
238
|
+
params.push(equalParam);
|
|
239
|
+
const tail = build(index + 1);
|
|
240
|
+
return `${head}${tail}))`;
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
sql: build(0),
|
|
244
|
+
params
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=sql-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["projectedColumn","TRUE","sql","params","FALSE","columnFor","field","jsonType","presentPrimitive","isExplicitNull","bind","value","comparison","node","column","op","operator","lt","lte","gt","gte","low","high","values","nonNull","filter","acceptsNull","length","clauses","push","map","join","membership","buildFilter","parts","nodes","child","part","flatMap","inner","buildOrderBy","sort","key","direction","buildKeysetPredicate","anchor","build","index","descending","strictly","equal","equalParam","head","tail"],"sourceRoot":"../../../src","sources":["sqlite/sql-builder.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,eAAe,QAAQ,sBAAmB;AAQnD,MAAMC,IAAiB,GAAG;EAAEC,GAAG,EAAE,GAAG;EAAEC,MAAM,EAAE;AAAG,CAAC;AAClD,MAAMC,KAAkB,GAAG;EAAEF,GAAG,EAAE,GAAG;EAAEC,MAAM,EAAE;AAAG,CAAC;AAEnD,SAASE,SAASA,CAACC,KAAa,EAAU;EACzC,OAAOA,KAAK,KAAK,IAAI,GAAG,IAAI,GAAG,IAAIN,eAAe,CAACM,KAAK,CAAC,GAAG;AAC7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAACD,KAAa,EAAU;EACxC,OAAO,yBAAyBA,KAAK,IAAI;AAC1C;;AAEA;AACA,SAASE,gBAAgBA,CAACF,KAAa,EAAU;EAChD,OAAO,IAAIC,QAAQ,CAACD,KAAK,CAAC,oBAAoBC,QAA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|
6
|
+
* The collection API and the batch each used to assemble their own INSERT and
|
|
7
|
+
* UPDATE text. Two copies of the same rule is how a batch upsert came to treat
|
|
8
|
+
* a soft-deleted row differently from a collection upsert.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { collectionTable, hasSoftDelete } from "../schema/declare.js";
|
|
12
|
+
import { insertColumns, updateAssignments } from "./row-codec.js";
|
|
13
|
+
// Built once per table and column list rather than on every write (PERF-10).
|
|
14
|
+
const insertTexts = new Map();
|
|
15
|
+
function insertText(table, columns) {
|
|
16
|
+
const key = `${table}|${columns.join(',')}`;
|
|
17
|
+
let sql = insertTexts.get(key);
|
|
18
|
+
if (sql === undefined) {
|
|
19
|
+
sql = `INSERT INTO "${table}" (${columns.map(name => `"${name}"`).join(', ')}) VALUES (${columns.map(() => '?').join(', ')})`;
|
|
20
|
+
insertTexts.set(key, sql);
|
|
21
|
+
}
|
|
22
|
+
return sql;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `ignore` leaves a row that already holds the id untouched and reports zero
|
|
27
|
+
* rows affected, so a conflict is detected without a SELECT beforehand.
|
|
28
|
+
*/
|
|
29
|
+
export function insertStatement(schema, id, data, now, payload, onConflict = 'fail') {
|
|
30
|
+
const {
|
|
31
|
+
columns,
|
|
32
|
+
values
|
|
33
|
+
} = insertColumns(schema, id, data, now, payload);
|
|
34
|
+
const sql = insertText(collectionTable(schema.name), columns);
|
|
35
|
+
return [onConflict === 'ignore' ? `${sql} ON CONFLICT(id) DO NOTHING` : sql, values];
|
|
36
|
+
}
|
|
37
|
+
export function updateStatement(schema, id, data, now, payload, options = {}) {
|
|
38
|
+
const {
|
|
39
|
+
columns,
|
|
40
|
+
values
|
|
41
|
+
} = updateAssignments(schema, data, now, payload);
|
|
42
|
+
const assignments = columns.map(name => `"${name}" = ?`);
|
|
43
|
+
if (options.restore === true && hasSoftDelete(schema)) {
|
|
44
|
+
assignments.push('deleted_at = NULL');
|
|
45
|
+
}
|
|
46
|
+
const live = options.liveOnly === true ? ' AND deleted_at IS NULL' : '';
|
|
47
|
+
return [`UPDATE "${collectionTable(schema.name)}" SET ${assignments.join(', ')} WHERE id = ?${live}`, [...values, id]];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=statements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["collectionTable","hasSoftDelete","insertColumns","updateAssignments","insertTexts","Map","insertText","table","columns","key","join","sql","get","undefined","map","name","set","insertStatement","schema","id","data","now","payload","onConflict","values","updateStatement","options","assignments","restore","push","live","liveOnly"],"sourceRoot":"../../../src","sources":["sqlite/statements.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,EAAEC,aAAa,QAAQ,sBAAmB;AAElE,SAASC,aAAa,EAAEC,iBAAiB,QAAQ,gBAAa;AAM9D;AACA,MAAMC,WAAW,GAAG,IAAIC,GAAG,CAAiB,CAAC;AAE7C,SAASC,UAAUA,CAACC,KAAa,EAAEC,OAA0B,EAAU;EACtE,MAAMC,GAAG,GAAG,GAAGF,KAAK,IAAIC,OAAO,CAACE,IAAI,CAAC,GAAG,CAAC,EAAE;EAC3C,IAAIC,GAAG,GAAGP,WAAW,CAACQ,GAAG,CAACH,GAAG,CAAC;EAC9B,IAAIE,GAAG,KAAKE,SAAS,EAAE;IACtBF,GAAG,GAAG,gBAAgBJ,KAAK,MAAMC,OAAO,CAACM,GAAG,CAACC,IAAI,IAAI,IAAIA,IAAI,GAAG,CAAC,CAACL,IAAI,CAAC,IAAI,CAAC,aAAaF,OAAO,CAC9FM,GAAG,CAAC,MAAM,GAAG,CAAC,CACdJ,IAAI,CAAC,IAAI,CAAC,GAAG;IACfN,WAAW,CAACY,GAAG,CAACP,GAAG,EAAEE,GAAG,CAAC;EAC1B;EACA,OAAOA,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASM,eAAeA,CAC9BC,MAAwB,EACxBC,EAAU,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|
4
|
+
* The per-handle queue that keeps a transaction to itself.
|
|
5
|
+
*
|
|
6
|
+
* A transaction holds the queue until it settles; work arriving meanwhile
|
|
7
|
+
* through the handle waits its turn and then runs on its own, instead of
|
|
8
|
+
* joining the transaction and vanishing with its rollback (LDB-01). Shared by
|
|
9
|
+
* the SQLite connection and the memory adapter so both isolate the same way.
|
|
10
|
+
*
|
|
11
|
+
* Pure: no engine, no React, so the memory adapter can use it without loading
|
|
12
|
+
* native code.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { DiagnosticCodes } from "../contract/errors.js";
|
|
16
|
+
import { raise } from "../diagnostics/errors.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How long work through the handle waits behind a transaction before it is
|
|
20
|
+
* refused.
|
|
21
|
+
*
|
|
22
|
+
* Not a performance budget: it exists for the one wait that never ends. A
|
|
23
|
+
* transaction body that awaits the handle's own `collection()` or
|
|
24
|
+
* `attachments()` is waiting on work queued behind itself. Until 0.2.0 that
|
|
25
|
+
* work ran inside the transaction; now it is refused after this long with a
|
|
26
|
+
* message naming `tx.collection()` / `tx.attachments()`, and the transaction
|
|
27
|
+
* rolls back, rather than both waiting forever.
|
|
28
|
+
*/
|
|
29
|
+
export const TRANSACTION_WAIT_LIMIT_MS = 10_000;
|
|
30
|
+
export function createTransactionQueue(waitLimitMs = TRANSACTION_WAIT_LIMIT_MS) {
|
|
31
|
+
/** Tail of the queue. Never rejects, so one failure cannot stall the rest. */
|
|
32
|
+
let tail = Promise.resolve();
|
|
33
|
+
/** Transactions queued or running. Only work behind one of them can deadlock. */
|
|
34
|
+
let transactions = 0;
|
|
35
|
+
const enqueue = work => {
|
|
36
|
+
const run = tail.then(work, work);
|
|
37
|
+
tail = run.catch(() => undefined);
|
|
38
|
+
return run;
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
run(work) {
|
|
42
|
+
if (transactions === 0) {
|
|
43
|
+
return enqueue(work);
|
|
44
|
+
}
|
|
45
|
+
let abandoned = false;
|
|
46
|
+
let timer;
|
|
47
|
+
const started = enqueue(() => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
// Refused while waiting: it must not run late, after its caller was
|
|
50
|
+
// already told it failed.
|
|
51
|
+
return abandoned ? Promise.resolve(undefined) : work();
|
|
52
|
+
});
|
|
53
|
+
const refused = new Promise((_, reject) => {
|
|
54
|
+
timer = setTimeout(() => {
|
|
55
|
+
abandoned = true;
|
|
56
|
+
try {
|
|
57
|
+
raise(DiagnosticCodes.TRANSACTION_STATE, {
|
|
58
|
+
message: 'waited too long behind an in-flight transaction; inside a transaction body use tx.collection() and tx.attachments(), not the handle'
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
reject(error);
|
|
62
|
+
}
|
|
63
|
+
}, waitLimitMs);
|
|
64
|
+
});
|
|
65
|
+
return Promise.race([started, refused]);
|
|
66
|
+
},
|
|
67
|
+
runTransaction(work) {
|
|
68
|
+
transactions += 1;
|
|
69
|
+
return enqueue(work).finally(() => {
|
|
70
|
+
transactions -= 1;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=transaction-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DiagnosticCodes","raise","TRANSACTION_WAIT_LIMIT_MS","createTransactionQueue","waitLimitMs","tail","Promise","resolve","transactions","enqueue","work","run","then","catch","undefined","abandoned","timer","started","clearTimeout","refused","_","reject","setTimeout","TRANSACTION_STATE","message","error","race","runTransaction","finally"],"sourceRoot":"../../../src","sources":["sqlite/transaction-queue.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,uBAAoB;AACpD,SAASC,KAAK,QAAQ,0BAAuB;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB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B,EAAc;MACrDF,YAAY,IAAI,CAAC;MACjB,OAAOC,OAAO,CAACC,IAAI,CAAC,CAACkB,OAAO,CAAC,MAAM;QAClCpB,YAAY,IAAI,CAAC;MAClB,CAAC,CAAC;IACH;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The transaction primitive.
|
|
5
|
+
*
|
|
6
|
+
* A transaction never spans two scopes, and not because a check forbids it:
|
|
7
|
+
* a transaction runs on one connection, a connection is opened against one
|
|
8
|
+
* scope's file, and the public surface offers no way to reach a second one
|
|
9
|
+
* from inside. FR-038 is a type error rather than a runtime one (research.md
|
|
10
|
+
* R2).
|
|
11
|
+
*
|
|
12
|
+
* Rollback fidelity is SQLite's, not this package's. A failure at any step
|
|
13
|
+
* unwinds through the engine's own `ROLLBACK`, which is the only way SC-006's
|
|
14
|
+
* "identical to its pre-transaction state, every time" survives a process
|
|
15
|
+
* kill halfway through.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Run `body` inside one transaction on one scope.
|
|
20
|
+
*
|
|
21
|
+
* Deliberately thin. The interesting behavior — read-your-own-writes,
|
|
22
|
+
* terminal-state rejection, what a settled transaction does when used again —
|
|
23
|
+
* belongs to `adapter/transaction.ts`, where both adapters can be held to the
|
|
24
|
+
* same rules.
|
|
25
|
+
*/
|
|
26
|
+
export function runInTransaction(connection, body) {
|
|
27
|
+
return connection.transaction(body);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=transactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["runInTransaction","connection","body","transaction"],"sourceRoot":"../../../src","sources":["sqlite/transactions.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,gBAAgBA,CAC/BC,UAAsB,EACtBC,IAA6C,EAChC;EACb,OAAOD,UAAU,CAACE,WAAW,CAACD,IAAI,CAAC;AACpC","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reading values back out of a result row.
|
|
5
|
+
*
|
|
6
|
+
* The engine hands back `unknown` per column, and every read site would
|
|
7
|
+
* otherwise repeat the same `String(...)` / `Number(...)` coercion with a
|
|
8
|
+
* slightly different null check. One place to do it means one place where the
|
|
9
|
+
* "NULL means absent, not empty string" rule is decided.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export function text(value) {
|
|
13
|
+
return typeof value === 'string' ? value : String(value);
|
|
14
|
+
}
|
|
15
|
+
export function num(value) {
|
|
16
|
+
return typeof value === 'number' ? value : Number(value);
|
|
17
|
+
}
|
|
18
|
+
export function maybeText(value) {
|
|
19
|
+
return value == null ? null : text(value);
|
|
20
|
+
}
|
|
21
|
+
export function maybeNum(value) {
|
|
22
|
+
return value == null ? null : num(value);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["text","value","String","num","Number","maybeText","maybeNum"],"sourceRoot":"../../../src","sources":["sqlite/values.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASA,IAAIA,CAACC,KAAc,EAAU;EAC5C,OAAO,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGC,MAAM,CAACD,KAAkC,CAAC;AACtF;AAEA,OAAO,SAASE,GAAGA,CAACF,KAAc,EAAU;EAC3C,OAAO,OAAOA,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGG,MAAM,CAACH,KAAwB,CAAC;AAC5E;AAEA,OAAO,SAASI,SAASA,CAACJ,KAAc,EAAiB;EACxD,OAAOA,KAAK,IAAI,IAAI,GAAG,IAAI,GAAGD,IAAI,CAACC,KAAK,CAAC;AAC1C;AAEA,OAAO,SAASK,QAAQA,CAACL,KAAc,EAAiB;EACvD,OAAOA,KAAK,IAAI,IAAI,GAAG,IAAI,GAAGE,GAAG,CAACF,KAAK,CAAC;AACzC","ignoreList":[]}
|