@korajs/core 1.0.0-beta.0 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bindings/index.d.cts +2 -2
- package/dist/bindings/index.d.ts +2 -2
- package/dist/{build-scope-map-DOf4JLTh.d.ts → build-scope-map-BvdTzmm4.d.ts} +1 -1
- package/dist/{build-scope-map-BIeawJzC.d.cts → build-scope-map-K25AyQXb.d.cts} +1 -1
- package/dist/{events-BynBOsO3.d.cts → events-DhblJN4r.d.cts} +144 -2
- package/dist/{events-BynBOsO3.d.ts → events-DhblJN4r.d.ts} +144 -2
- package/dist/index.cjs +566 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +174 -7
- package/dist/index.d.ts +174 -7
- package/dist/index.js +553 -22
- package/dist/index.js.map +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/{operation-D5WOZYvy.d.ts → operation-CC7O3-wf.d.ts} +1 -1
- package/dist/{operation-BpZlYSpe.d.cts → operation-D-pemjcf.d.cts} +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as RandomSource, A as AtomicOpType, a as AtomicOp, F as FieldBuilder,
|
|
2
|
-
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder,
|
|
3
|
-
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-
|
|
4
|
-
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-
|
|
1
|
+
import { R as RandomSource, B as BlobRef, C as CollectionDefinition, A as AtomicOpType, a as AtomicOp, F as FieldBuilder, b as CustomResolver, M as MigrationDefinition, S as SchemaDefinition, c as RelationDefinition, O as OperationType, E as EnumFieldBuilder, J as JsonFieldBuilder, d as ArrayFieldBuilder, e as FieldKind, f as Operation, V as VersionVector, g as MigrationStep, h as StateMachineConstraint, T as TransitionMap, i as TransitionValidationResult } from './events-DhblJN4r.cjs';
|
|
2
|
+
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder, D as SecretMode, G as SequenceConfig, I as StateMachineDefinition, L as SyncDiagnosticsSnapshot, N as SyncRuleDefinition, P as TimeSource, Q as migrate, U as t } from './events-DhblJN4r.cjs';
|
|
3
|
+
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-D-pemjcf.cjs';
|
|
4
|
+
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-K25AyQXb.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Base error class for all Kora errors.
|
|
@@ -161,6 +161,137 @@ declare function extractTimestamp(uuid: string): number;
|
|
|
161
161
|
*/
|
|
162
162
|
declare function isValidUUIDv7(uuid: string): boolean;
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Compute the hex-encoded SHA-256 content hash of a byte buffer.
|
|
166
|
+
*
|
|
167
|
+
* This is the content address of a blob: identical bytes always hash to the same
|
|
168
|
+
* value, which is what lets the blob store deduplicate content and lets a peer
|
|
169
|
+
* skip transferring bytes it already holds.
|
|
170
|
+
*
|
|
171
|
+
* @param bytes - The binary content to hash
|
|
172
|
+
* @returns The hex-encoded SHA-256 hash
|
|
173
|
+
*/
|
|
174
|
+
declare function hashBlob(bytes: Uint8Array): Promise<string>;
|
|
175
|
+
/** Optional metadata carried alongside a blob reference. */
|
|
176
|
+
interface BlobRefMetadata {
|
|
177
|
+
mimeType?: string;
|
|
178
|
+
filename?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a content-addressed {@link BlobRef} for a byte buffer.
|
|
182
|
+
*
|
|
183
|
+
* @param bytes - The binary content
|
|
184
|
+
* @param metadata - Optional MIME type and filename
|
|
185
|
+
* @returns A reference carrying the content hash, size, and metadata
|
|
186
|
+
*/
|
|
187
|
+
declare function createBlobRef(bytes: Uint8Array, metadata?: BlobRefMetadata): Promise<BlobRef>;
|
|
188
|
+
/**
|
|
189
|
+
* Type guard: whether a value is a structurally valid {@link BlobRef}.
|
|
190
|
+
*
|
|
191
|
+
* Validates the shape only (a non-empty hex hash and a non-negative size); it
|
|
192
|
+
* does not verify that the bytes behind the hash exist or match. Integrity
|
|
193
|
+
* verification against the actual bytes happens in the blob store on read.
|
|
194
|
+
*/
|
|
195
|
+
declare function isBlobRef(value: unknown): value is BlobRef;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Field-level cryptography for `secret` fields.
|
|
199
|
+
*
|
|
200
|
+
* Two protection modes, matching the two ways secrets are used:
|
|
201
|
+
* - `encrypted`: reversible AES-256-GCM (tokens, API keys — decrypt to use).
|
|
202
|
+
* - `hashed`: one-way PBKDF2-SHA-256 with a random salt (passwords — verify only).
|
|
203
|
+
*
|
|
204
|
+
* These primitives use only the standard WebCrypto API so they live in
|
|
205
|
+
* `@korajs/core` with no dependency on `@korajs/auth`; a `secret` field is
|
|
206
|
+
* therefore self-contained. Higher-level key management composes on top.
|
|
207
|
+
*/
|
|
208
|
+
/**
|
|
209
|
+
* Encrypt a secret's plaintext with AES-256-GCM under a key derived from
|
|
210
|
+
* `secretKey`. The returned string bundles the salt, IV, and ciphertext (all hex,
|
|
211
|
+
* dot-separated) so it is self-describing and safe to store and sync.
|
|
212
|
+
*
|
|
213
|
+
* @param plaintext - The secret value to protect
|
|
214
|
+
* @param secretKey - The key material (from a key provider), never stored
|
|
215
|
+
* @returns An opaque `v1.salt.iv.ciphertext` string
|
|
216
|
+
*/
|
|
217
|
+
declare function encryptSecret(plaintext: string, secretKey: string): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Decrypt a value produced by {@link encryptSecret} with the same key.
|
|
220
|
+
*
|
|
221
|
+
* @param encrypted - The `v1.salt.iv.ciphertext` string
|
|
222
|
+
* @param secretKey - The key material used to encrypt
|
|
223
|
+
* @returns The original plaintext
|
|
224
|
+
* @throws If the format is invalid or the key is wrong (GCM auth failure)
|
|
225
|
+
*/
|
|
226
|
+
declare function decryptSecret(encrypted: string, secretKey: string): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* One-way hash a secret (a password) with PBKDF2-SHA-256 and a random salt.
|
|
229
|
+
* The result bundles the salt and hash so {@link verifySecret} needs nothing
|
|
230
|
+
* else. There is no way to recover the plaintext from the result.
|
|
231
|
+
*
|
|
232
|
+
* @param plaintext - The secret value to hash
|
|
233
|
+
* @returns An opaque `v1.salt.hash` string
|
|
234
|
+
*/
|
|
235
|
+
declare function hashSecret(plaintext: string): Promise<string>;
|
|
236
|
+
/**
|
|
237
|
+
* Verify a plaintext against a value produced by {@link hashSecret}, in constant
|
|
238
|
+
* time with respect to the stored hash.
|
|
239
|
+
*
|
|
240
|
+
* @param plaintext - The candidate secret
|
|
241
|
+
* @param stored - The `v1.salt.hash` string
|
|
242
|
+
* @returns Whether the plaintext matches
|
|
243
|
+
*/
|
|
244
|
+
declare function verifySecret(plaintext: string, stored: string): Promise<boolean>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Provider of the key material used to encrypt reversible (`encrypted`) secret
|
|
248
|
+
* fields. Called at write and reveal time so the key can be loaded lazily (for
|
|
249
|
+
* example derived from a user passphrase after unlock). Returns undefined when
|
|
250
|
+
* no key is available.
|
|
251
|
+
*/
|
|
252
|
+
type SecretKeyProvider = () => string | undefined | Promise<string | undefined>;
|
|
253
|
+
/** Thrown when an `encrypted` secret field is written or read without a key. */
|
|
254
|
+
declare class MissingSecretKeyError extends Error {
|
|
255
|
+
readonly field: string;
|
|
256
|
+
constructor(field: string);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Transform the secret fields of a record's write payload into their at-rest
|
|
260
|
+
* form BEFORE the operation is created, so plaintext never enters the operation
|
|
261
|
+
* log, the store, or the sync stream.
|
|
262
|
+
*
|
|
263
|
+
* - `hashed` fields become a one-way salted hash.
|
|
264
|
+
* - `encrypted` fields become ciphertext (requires a key).
|
|
265
|
+
*
|
|
266
|
+
* Non-secret fields, and secret fields not present in `data`, are passed through
|
|
267
|
+
* untouched. Null/undefined secret values are left as-is (nothing to protect).
|
|
268
|
+
*
|
|
269
|
+
* @param data - The validated write payload (plaintext secret values)
|
|
270
|
+
* @param collectionDef - The collection definition (for field kinds/modes)
|
|
271
|
+
* @param keyProvider - Supplies the encryption key for `encrypted` fields
|
|
272
|
+
* @returns A new payload with secret fields replaced by their at-rest form
|
|
273
|
+
*/
|
|
274
|
+
declare function transformSecretFieldsForWrite(data: Record<string, unknown>, collectionDef: CollectionDefinition, keyProvider?: SecretKeyProvider): Promise<Record<string, unknown>>;
|
|
275
|
+
/**
|
|
276
|
+
* Reveal the plaintext of an `encrypted` secret field's stored value. Throws for
|
|
277
|
+
* `hashed` fields, which are one-way and cannot be revealed.
|
|
278
|
+
*
|
|
279
|
+
* @param storedValue - The at-rest value (ciphertext)
|
|
280
|
+
* @param mode - The field's secret mode
|
|
281
|
+
* @param keyProvider - Supplies the decryption key
|
|
282
|
+
* @param field - Field name (for error messages)
|
|
283
|
+
* @returns The decrypted plaintext
|
|
284
|
+
*/
|
|
285
|
+
declare function revealSecret(storedValue: string, mode: 'hashed' | 'encrypted', keyProvider: SecretKeyProvider | undefined, field?: string): Promise<string>;
|
|
286
|
+
/**
|
|
287
|
+
* Verify a plaintext candidate against a `hashed` secret field's stored value.
|
|
288
|
+
*
|
|
289
|
+
* @param candidate - The plaintext to check (for example a login password)
|
|
290
|
+
* @param storedValue - The stored one-way hash
|
|
291
|
+
* @returns Whether the candidate matches
|
|
292
|
+
*/
|
|
293
|
+
declare function verifySecretValue(candidate: string, storedValue: string): Promise<boolean>;
|
|
294
|
+
|
|
164
295
|
/**
|
|
165
296
|
* Outcome of applying a single operation to materialized storage (local or remote).
|
|
166
297
|
*/
|
|
@@ -474,6 +605,38 @@ declare function generateSQL(collectionName: string, collection: CollectionDefin
|
|
|
474
605
|
*/
|
|
475
606
|
declare function generateFullDDL(schema: SchemaDefinition): string[];
|
|
476
607
|
|
|
608
|
+
/**
|
|
609
|
+
* Quote a SQL identifier (table or column name) for safe interpolation into
|
|
610
|
+
* generated SQL.
|
|
611
|
+
*
|
|
612
|
+
* Uses standard double-quote quoting, which both SQLite and PostgreSQL honor,
|
|
613
|
+
* and doubles any embedded double-quote per the SQL standard. Quoting is what
|
|
614
|
+
* lets a valid JavaScript identifier — camelCase (`formResponses`), PascalCase
|
|
615
|
+
* (`UserProfiles`), or a word that happens to be a SQL keyword (`order`,
|
|
616
|
+
* `select`) — round-trip through generated DDL and queries without ever
|
|
617
|
+
* producing invalid or ambiguous SQL.
|
|
618
|
+
*
|
|
619
|
+
* Schema validation (see `validateCollectionName` / `validateFieldName`)
|
|
620
|
+
* already restricts identifiers to `[A-Za-z][A-Za-z0-9_]*`, so the escape here
|
|
621
|
+
* never actually fires in practice; it is defense in depth so this helper is
|
|
622
|
+
* correct for any input rather than only for pre-validated names.
|
|
623
|
+
*
|
|
624
|
+
* Consistency is the contract: every path that emits an identifier for a
|
|
625
|
+
* user-defined collection or field MUST go through this helper, because a
|
|
626
|
+
* quoted `CREATE TABLE "order"` paired with an unquoted `SELECT ... FROM order`
|
|
627
|
+
* would reintroduce the exact keyword-collision bug this guards against.
|
|
628
|
+
*
|
|
629
|
+
* @param name - The raw identifier (collection name, field/column name).
|
|
630
|
+
* @returns The identifier wrapped in double quotes, ready to splice into SQL.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```typescript
|
|
634
|
+
* quoteIdent('formResponses') // => '"formResponses"'
|
|
635
|
+
* quoteIdent('order') // => '"order"'
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
declare function quoteIdent(name: string): string;
|
|
639
|
+
|
|
477
640
|
/**
|
|
478
641
|
* Validates a record's data against a collection's field definitions.
|
|
479
642
|
* Applies defaults, rejects auto fields, and type-checks each value.
|
|
@@ -508,12 +671,16 @@ interface FieldKindToType {
|
|
|
508
671
|
richtext: string;
|
|
509
672
|
enum: string;
|
|
510
673
|
array: unknown[];
|
|
674
|
+
object: Record<string, unknown>;
|
|
675
|
+
json: unknown;
|
|
676
|
+
blob: BlobRef;
|
|
677
|
+
secret: string;
|
|
511
678
|
}
|
|
512
679
|
/**
|
|
513
680
|
* Infers the TypeScript type for a single field descriptor or builder.
|
|
514
681
|
* Supports both FieldBuilder (class instances) and FieldDescriptor (compiled objects).
|
|
515
682
|
*/
|
|
516
|
-
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
683
|
+
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends JsonFieldBuilder<infer T, any, any> ? T : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
517
684
|
kind: 'enum';
|
|
518
685
|
enumValues: infer V;
|
|
519
686
|
} ? V extends readonly (infer S)[] ? S : string : F extends {
|
|
@@ -719,7 +886,7 @@ declare function migrationStepsToSQL(steps: readonly MigrationStep[]): string[];
|
|
|
719
886
|
*
|
|
720
887
|
* const rollbackSQL = rollbackStepsToSQL(migration)
|
|
721
888
|
* // ['DROP INDEX IF EXISTS idx_todos_priority',
|
|
722
|
-
* // 'ALTER TABLE todos DROP COLUMN priority']
|
|
889
|
+
* // 'ALTER TABLE "todos" DROP COLUMN "priority"']
|
|
723
890
|
* ```
|
|
724
891
|
*/
|
|
725
892
|
declare function rollbackStepsToSQL(migration: MigrationDefinition): string[];
|
|
@@ -910,4 +1077,4 @@ interface ProtoOutput {
|
|
|
910
1077
|
*/
|
|
911
1078
|
declare function generateProtoDefinitions(schema: SchemaDefinition): ProtoOutput;
|
|
912
1079
|
|
|
913
|
-
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createReversibleMigration, createVersionVector, decodeBytesFromOpData, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, isApplyFailure, isAtomicOp, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, resolveAtomicOp, rollbackStepsToSQL, serializeVector, toAtomicOp, validateRecord, validateTransition, vectorsEqual };
|
|
1080
|
+
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, BlobRef, type BlobRefMetadata, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, MissingSecretKeyError, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, type SecretKeyProvider, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createBlobRef, createReversibleMigration, createVersionVector, decodeBytesFromOpData, decryptSecret, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, encryptSecret, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, hashBlob, hashSecret, isApplyFailure, isAtomicOp, isBlobRef, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, quoteIdent, resolveAtomicOp, revealSecret, rollbackStepsToSQL, serializeVector, toAtomicOp, transformSecretFieldsForWrite, validateRecord, validateTransition, vectorsEqual, verifySecret, verifySecretValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as RandomSource, A as AtomicOpType, a as AtomicOp, F as FieldBuilder,
|
|
2
|
-
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder,
|
|
3
|
-
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-
|
|
4
|
-
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-
|
|
1
|
+
import { R as RandomSource, B as BlobRef, C as CollectionDefinition, A as AtomicOpType, a as AtomicOp, F as FieldBuilder, b as CustomResolver, M as MigrationDefinition, S as SchemaDefinition, c as RelationDefinition, O as OperationType, E as EnumFieldBuilder, J as JsonFieldBuilder, d as ArrayFieldBuilder, e as FieldKind, f as Operation, V as VersionVector, g as MigrationStep, h as StateMachineConstraint, T as TransitionMap, i as TransitionValidationResult } from './events-DhblJN4r.js';
|
|
2
|
+
export { j as CONNECTION_QUALITIES, k as ConnectionQuality, l as Constraint, m as FieldDescriptor, n as FieldMergeStrategy, H as HLCTimestamp, K as KoraEvent, o as KoraEventByType, p as KoraEventEmitter, q as KoraEventListener, r as KoraEventType, s as MERGE_STRATEGIES, t as MergeStrategy, u as MergeTrace, v as MigrationBuilder, w as OnDeleteAction, x as OperationInput, y as RelationType, z as RollbackBuilder, D as SecretMode, G as SequenceConfig, I as StateMachineDefinition, L as SyncDiagnosticsSnapshot, N as SyncRuleDefinition, P as TimeSource, Q as migrate, U as t } from './events-DhblJN4r.js';
|
|
3
|
+
export { H as HybridLogicalClock, M as MAX_LOGICAL, c as createOperation, i as isValidOperation, v as verifyOperationIntegrity } from './operation-CC7O3-wf.js';
|
|
4
|
+
export { S as ScopeMap, b as buildScopeMap } from './build-scope-map-BvdTzmm4.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Base error class for all Kora errors.
|
|
@@ -161,6 +161,137 @@ declare function extractTimestamp(uuid: string): number;
|
|
|
161
161
|
*/
|
|
162
162
|
declare function isValidUUIDv7(uuid: string): boolean;
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Compute the hex-encoded SHA-256 content hash of a byte buffer.
|
|
166
|
+
*
|
|
167
|
+
* This is the content address of a blob: identical bytes always hash to the same
|
|
168
|
+
* value, which is what lets the blob store deduplicate content and lets a peer
|
|
169
|
+
* skip transferring bytes it already holds.
|
|
170
|
+
*
|
|
171
|
+
* @param bytes - The binary content to hash
|
|
172
|
+
* @returns The hex-encoded SHA-256 hash
|
|
173
|
+
*/
|
|
174
|
+
declare function hashBlob(bytes: Uint8Array): Promise<string>;
|
|
175
|
+
/** Optional metadata carried alongside a blob reference. */
|
|
176
|
+
interface BlobRefMetadata {
|
|
177
|
+
mimeType?: string;
|
|
178
|
+
filename?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a content-addressed {@link BlobRef} for a byte buffer.
|
|
182
|
+
*
|
|
183
|
+
* @param bytes - The binary content
|
|
184
|
+
* @param metadata - Optional MIME type and filename
|
|
185
|
+
* @returns A reference carrying the content hash, size, and metadata
|
|
186
|
+
*/
|
|
187
|
+
declare function createBlobRef(bytes: Uint8Array, metadata?: BlobRefMetadata): Promise<BlobRef>;
|
|
188
|
+
/**
|
|
189
|
+
* Type guard: whether a value is a structurally valid {@link BlobRef}.
|
|
190
|
+
*
|
|
191
|
+
* Validates the shape only (a non-empty hex hash and a non-negative size); it
|
|
192
|
+
* does not verify that the bytes behind the hash exist or match. Integrity
|
|
193
|
+
* verification against the actual bytes happens in the blob store on read.
|
|
194
|
+
*/
|
|
195
|
+
declare function isBlobRef(value: unknown): value is BlobRef;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Field-level cryptography for `secret` fields.
|
|
199
|
+
*
|
|
200
|
+
* Two protection modes, matching the two ways secrets are used:
|
|
201
|
+
* - `encrypted`: reversible AES-256-GCM (tokens, API keys — decrypt to use).
|
|
202
|
+
* - `hashed`: one-way PBKDF2-SHA-256 with a random salt (passwords — verify only).
|
|
203
|
+
*
|
|
204
|
+
* These primitives use only the standard WebCrypto API so they live in
|
|
205
|
+
* `@korajs/core` with no dependency on `@korajs/auth`; a `secret` field is
|
|
206
|
+
* therefore self-contained. Higher-level key management composes on top.
|
|
207
|
+
*/
|
|
208
|
+
/**
|
|
209
|
+
* Encrypt a secret's plaintext with AES-256-GCM under a key derived from
|
|
210
|
+
* `secretKey`. The returned string bundles the salt, IV, and ciphertext (all hex,
|
|
211
|
+
* dot-separated) so it is self-describing and safe to store and sync.
|
|
212
|
+
*
|
|
213
|
+
* @param plaintext - The secret value to protect
|
|
214
|
+
* @param secretKey - The key material (from a key provider), never stored
|
|
215
|
+
* @returns An opaque `v1.salt.iv.ciphertext` string
|
|
216
|
+
*/
|
|
217
|
+
declare function encryptSecret(plaintext: string, secretKey: string): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Decrypt a value produced by {@link encryptSecret} with the same key.
|
|
220
|
+
*
|
|
221
|
+
* @param encrypted - The `v1.salt.iv.ciphertext` string
|
|
222
|
+
* @param secretKey - The key material used to encrypt
|
|
223
|
+
* @returns The original plaintext
|
|
224
|
+
* @throws If the format is invalid or the key is wrong (GCM auth failure)
|
|
225
|
+
*/
|
|
226
|
+
declare function decryptSecret(encrypted: string, secretKey: string): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* One-way hash a secret (a password) with PBKDF2-SHA-256 and a random salt.
|
|
229
|
+
* The result bundles the salt and hash so {@link verifySecret} needs nothing
|
|
230
|
+
* else. There is no way to recover the plaintext from the result.
|
|
231
|
+
*
|
|
232
|
+
* @param plaintext - The secret value to hash
|
|
233
|
+
* @returns An opaque `v1.salt.hash` string
|
|
234
|
+
*/
|
|
235
|
+
declare function hashSecret(plaintext: string): Promise<string>;
|
|
236
|
+
/**
|
|
237
|
+
* Verify a plaintext against a value produced by {@link hashSecret}, in constant
|
|
238
|
+
* time with respect to the stored hash.
|
|
239
|
+
*
|
|
240
|
+
* @param plaintext - The candidate secret
|
|
241
|
+
* @param stored - The `v1.salt.hash` string
|
|
242
|
+
* @returns Whether the plaintext matches
|
|
243
|
+
*/
|
|
244
|
+
declare function verifySecret(plaintext: string, stored: string): Promise<boolean>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Provider of the key material used to encrypt reversible (`encrypted`) secret
|
|
248
|
+
* fields. Called at write and reveal time so the key can be loaded lazily (for
|
|
249
|
+
* example derived from a user passphrase after unlock). Returns undefined when
|
|
250
|
+
* no key is available.
|
|
251
|
+
*/
|
|
252
|
+
type SecretKeyProvider = () => string | undefined | Promise<string | undefined>;
|
|
253
|
+
/** Thrown when an `encrypted` secret field is written or read without a key. */
|
|
254
|
+
declare class MissingSecretKeyError extends Error {
|
|
255
|
+
readonly field: string;
|
|
256
|
+
constructor(field: string);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Transform the secret fields of a record's write payload into their at-rest
|
|
260
|
+
* form BEFORE the operation is created, so plaintext never enters the operation
|
|
261
|
+
* log, the store, or the sync stream.
|
|
262
|
+
*
|
|
263
|
+
* - `hashed` fields become a one-way salted hash.
|
|
264
|
+
* - `encrypted` fields become ciphertext (requires a key).
|
|
265
|
+
*
|
|
266
|
+
* Non-secret fields, and secret fields not present in `data`, are passed through
|
|
267
|
+
* untouched. Null/undefined secret values are left as-is (nothing to protect).
|
|
268
|
+
*
|
|
269
|
+
* @param data - The validated write payload (plaintext secret values)
|
|
270
|
+
* @param collectionDef - The collection definition (for field kinds/modes)
|
|
271
|
+
* @param keyProvider - Supplies the encryption key for `encrypted` fields
|
|
272
|
+
* @returns A new payload with secret fields replaced by their at-rest form
|
|
273
|
+
*/
|
|
274
|
+
declare function transformSecretFieldsForWrite(data: Record<string, unknown>, collectionDef: CollectionDefinition, keyProvider?: SecretKeyProvider): Promise<Record<string, unknown>>;
|
|
275
|
+
/**
|
|
276
|
+
* Reveal the plaintext of an `encrypted` secret field's stored value. Throws for
|
|
277
|
+
* `hashed` fields, which are one-way and cannot be revealed.
|
|
278
|
+
*
|
|
279
|
+
* @param storedValue - The at-rest value (ciphertext)
|
|
280
|
+
* @param mode - The field's secret mode
|
|
281
|
+
* @param keyProvider - Supplies the decryption key
|
|
282
|
+
* @param field - Field name (for error messages)
|
|
283
|
+
* @returns The decrypted plaintext
|
|
284
|
+
*/
|
|
285
|
+
declare function revealSecret(storedValue: string, mode: 'hashed' | 'encrypted', keyProvider: SecretKeyProvider | undefined, field?: string): Promise<string>;
|
|
286
|
+
/**
|
|
287
|
+
* Verify a plaintext candidate against a `hashed` secret field's stored value.
|
|
288
|
+
*
|
|
289
|
+
* @param candidate - The plaintext to check (for example a login password)
|
|
290
|
+
* @param storedValue - The stored one-way hash
|
|
291
|
+
* @returns Whether the candidate matches
|
|
292
|
+
*/
|
|
293
|
+
declare function verifySecretValue(candidate: string, storedValue: string): Promise<boolean>;
|
|
294
|
+
|
|
164
295
|
/**
|
|
165
296
|
* Outcome of applying a single operation to materialized storage (local or remote).
|
|
166
297
|
*/
|
|
@@ -474,6 +605,38 @@ declare function generateSQL(collectionName: string, collection: CollectionDefin
|
|
|
474
605
|
*/
|
|
475
606
|
declare function generateFullDDL(schema: SchemaDefinition): string[];
|
|
476
607
|
|
|
608
|
+
/**
|
|
609
|
+
* Quote a SQL identifier (table or column name) for safe interpolation into
|
|
610
|
+
* generated SQL.
|
|
611
|
+
*
|
|
612
|
+
* Uses standard double-quote quoting, which both SQLite and PostgreSQL honor,
|
|
613
|
+
* and doubles any embedded double-quote per the SQL standard. Quoting is what
|
|
614
|
+
* lets a valid JavaScript identifier — camelCase (`formResponses`), PascalCase
|
|
615
|
+
* (`UserProfiles`), or a word that happens to be a SQL keyword (`order`,
|
|
616
|
+
* `select`) — round-trip through generated DDL and queries without ever
|
|
617
|
+
* producing invalid or ambiguous SQL.
|
|
618
|
+
*
|
|
619
|
+
* Schema validation (see `validateCollectionName` / `validateFieldName`)
|
|
620
|
+
* already restricts identifiers to `[A-Za-z][A-Za-z0-9_]*`, so the escape here
|
|
621
|
+
* never actually fires in practice; it is defense in depth so this helper is
|
|
622
|
+
* correct for any input rather than only for pre-validated names.
|
|
623
|
+
*
|
|
624
|
+
* Consistency is the contract: every path that emits an identifier for a
|
|
625
|
+
* user-defined collection or field MUST go through this helper, because a
|
|
626
|
+
* quoted `CREATE TABLE "order"` paired with an unquoted `SELECT ... FROM order`
|
|
627
|
+
* would reintroduce the exact keyword-collision bug this guards against.
|
|
628
|
+
*
|
|
629
|
+
* @param name - The raw identifier (collection name, field/column name).
|
|
630
|
+
* @returns The identifier wrapped in double quotes, ready to splice into SQL.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```typescript
|
|
634
|
+
* quoteIdent('formResponses') // => '"formResponses"'
|
|
635
|
+
* quoteIdent('order') // => '"order"'
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
declare function quoteIdent(name: string): string;
|
|
639
|
+
|
|
477
640
|
/**
|
|
478
641
|
* Validates a record's data against a collection's field definitions.
|
|
479
642
|
* Applies defaults, rejects auto fields, and type-checks each value.
|
|
@@ -508,12 +671,16 @@ interface FieldKindToType {
|
|
|
508
671
|
richtext: string;
|
|
509
672
|
enum: string;
|
|
510
673
|
array: unknown[];
|
|
674
|
+
object: Record<string, unknown>;
|
|
675
|
+
json: unknown;
|
|
676
|
+
blob: BlobRef;
|
|
677
|
+
secret: string;
|
|
511
678
|
}
|
|
512
679
|
/**
|
|
513
680
|
* Infers the TypeScript type for a single field descriptor or builder.
|
|
514
681
|
* Supports both FieldBuilder (class instances) and FieldDescriptor (compiled objects).
|
|
515
682
|
*/
|
|
516
|
-
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
683
|
+
type InferFieldType<F> = F extends EnumFieldBuilder<infer V, any, any> ? V[number] : F extends JsonFieldBuilder<infer T, any, any> ? T : F extends ArrayFieldBuilder<infer K, any, any> ? FieldKindToType[K][] : F extends FieldBuilder<infer K, any, any> ? K extends keyof FieldKindToType ? FieldKindToType[K] : unknown : F extends {
|
|
517
684
|
kind: 'enum';
|
|
518
685
|
enumValues: infer V;
|
|
519
686
|
} ? V extends readonly (infer S)[] ? S : string : F extends {
|
|
@@ -719,7 +886,7 @@ declare function migrationStepsToSQL(steps: readonly MigrationStep[]): string[];
|
|
|
719
886
|
*
|
|
720
887
|
* const rollbackSQL = rollbackStepsToSQL(migration)
|
|
721
888
|
* // ['DROP INDEX IF EXISTS idx_todos_priority',
|
|
722
|
-
* // 'ALTER TABLE todos DROP COLUMN priority']
|
|
889
|
+
* // 'ALTER TABLE "todos" DROP COLUMN "priority"']
|
|
723
890
|
* ```
|
|
724
891
|
*/
|
|
725
892
|
declare function rollbackStepsToSQL(migration: MigrationDefinition): string[];
|
|
@@ -910,4 +1077,4 @@ interface ProtoOutput {
|
|
|
910
1077
|
*/
|
|
911
1078
|
declare function generateProtoDefinitions(schema: SchemaDefinition): ProtoOutput;
|
|
912
1079
|
|
|
913
|
-
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createReversibleMigration, createVersionVector, decodeBytesFromOpData, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, isApplyFailure, isAtomicOp, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, resolveAtomicOp, rollbackStepsToSQL, serializeVector, toAtomicOp, validateRecord, validateTransition, vectorsEqual };
|
|
1080
|
+
export { APPLY_FAILURE_CODES, APPLY_RESULTS, AppNotReadyError, type ApplyFailureReason, type ApplyResult, ArrayFieldBuilder, AtomicOp, type AtomicOpSentinel, AtomicOpType, BlobRef, type BlobRefMetadata, CausalTracker, ClockDriftError, CollectionDefinition, type CollectionInput, type ConstraintInput, CustomResolver, EnumFieldBuilder, FieldBuilder, FieldKind, type FieldKindToType, type InferFieldType, type InferInsertInput, type InferRecord, type InferUpdateInput, InvalidTimestampError, KORA_ERROR_FIX_SUGGESTIONS, type KoraBytesValue, KoraError, MergeConflictError, MigrationDefinition, MigrationRollbackError, MigrationStep, MissingSecretKeyError, Operation, OperationError, type OperationLog, type OperationTransform, OperationType, type ProtoOutput, RandomSource, RelationDefinition, type RelationInput, RemoteClockDriftError, type ReversibleMigration, SchemaDefinition, type SchemaInput, SchemaValidationError, type SecretKeyProvider, StateMachineConstraint, type StateMachineInput, StorageError, SyncError, TransitionMap, TransitionValidationResult, type TypedSchemaDefinition, VersionVector, advanceVector, applyOperationTransforms, base64ToBytes, buildStateMachineConstraints, bytesToBase64, canAutoRollback, collectSchemaScopeFields, collectSchemaScopeValueKeys, computeDelta, createBlobRef, createReversibleMigration, createVersionVector, decodeBytesFromOpData, decryptSecret, defaultApplyFailureReason, defaultSequenceFormat, defineSchema, deserializeVector, dominates, encodeBytesForOpData, encryptSecret, extractScopeValuesFromClaims, extractTimestamp, formatSequenceValue, generateFullDDL, generateProtoDefinitions, generateRollbackSteps, generateSQL, generateUUIDv7, getCollectionScopeBindings, getKoraErrorFix, getTransitionMap, hasSchemaSyncRules, hashBlob, hashSecret, isApplyFailure, isAtomicOp, isBlobRef, isCollectionSyncScoped, isKoraBytesValue, isLegacyNumericByteObject, isValidUUIDv7, mergeVectors, migrationStepsToSQL, op, quoteIdent, resolveAtomicOp, revealSecret, rollbackStepsToSQL, serializeVector, toAtomicOp, transformSecretFieldsForWrite, validateRecord, validateTransition, vectorsEqual, verifySecret, verifySecretValue };
|