@korajs/core 1.0.0-beta.1 → 1.0.0-beta.4
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-DvOHbYjn.d.ts → build-scope-map-BvdTzmm4.d.ts} +1 -1
- package/dist/{build-scope-map-DtTr9C7A.d.cts → build-scope-map-K25AyQXb.d.cts} +1 -1
- package/dist/{events-CqDkr1LN.d.cts → events-DhblJN4r.d.cts} +43 -0
- package/dist/{events-CqDkr1LN.d.ts → events-DhblJN4r.d.ts} +43 -0
- package/dist/index.cjs +38 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -6
- package/dist/index.d.ts +38 -6
- package/dist/index.js +37 -20
- package/dist/index.js.map +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/{operation-BJtu18Fi.d.ts → operation-CC7O3-wf.d.ts} +1 -1
- package/dist/{operation-CFoY-ZmB.d.cts → operation-D-pemjcf.d.cts} +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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-
|
|
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-
|
|
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.
|
|
@@ -605,6 +605,38 @@ declare function generateSQL(collectionName: string, collection: CollectionDefin
|
|
|
605
605
|
*/
|
|
606
606
|
declare function generateFullDDL(schema: SchemaDefinition): string[];
|
|
607
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
|
+
|
|
608
640
|
/**
|
|
609
641
|
* Validates a record's data against a collection's field definitions.
|
|
610
642
|
* Applies defaults, rejects auto fields, and type-checks each value.
|
|
@@ -854,7 +886,7 @@ declare function migrationStepsToSQL(steps: readonly MigrationStep[]): string[];
|
|
|
854
886
|
*
|
|
855
887
|
* const rollbackSQL = rollbackStepsToSQL(migration)
|
|
856
888
|
* // ['DROP INDEX IF EXISTS idx_todos_priority',
|
|
857
|
-
* // 'ALTER TABLE todos DROP COLUMN priority']
|
|
889
|
+
* // 'ALTER TABLE "todos" DROP COLUMN "priority"']
|
|
858
890
|
* ```
|
|
859
891
|
*/
|
|
860
892
|
declare function rollbackStepsToSQL(migration: MigrationDefinition): string[];
|
|
@@ -1045,4 +1077,4 @@ interface ProtoOutput {
|
|
|
1045
1077
|
*/
|
|
1046
1078
|
declare function generateProtoDefinitions(schema: SchemaDefinition): ProtoOutput;
|
|
1047
1079
|
|
|
1048
|
-
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, resolveAtomicOp, revealSecret, rollbackStepsToSQL, serializeVector, toAtomicOp, transformSecretFieldsForWrite, validateRecord, validateTransition, vectorsEqual, verifySecret, verifySecretValue };
|
|
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, 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-
|
|
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-
|
|
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.
|
|
@@ -605,6 +605,38 @@ declare function generateSQL(collectionName: string, collection: CollectionDefin
|
|
|
605
605
|
*/
|
|
606
606
|
declare function generateFullDDL(schema: SchemaDefinition): string[];
|
|
607
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
|
+
|
|
608
640
|
/**
|
|
609
641
|
* Validates a record's data against a collection's field definitions.
|
|
610
642
|
* Applies defaults, rejects auto fields, and type-checks each value.
|
|
@@ -854,7 +886,7 @@ declare function migrationStepsToSQL(steps: readonly MigrationStep[]): string[];
|
|
|
854
886
|
*
|
|
855
887
|
* const rollbackSQL = rollbackStepsToSQL(migration)
|
|
856
888
|
* // ['DROP INDEX IF EXISTS idx_todos_priority',
|
|
857
|
-
* // 'ALTER TABLE todos DROP COLUMN priority']
|
|
889
|
+
* // 'ALTER TABLE "todos" DROP COLUMN "priority"']
|
|
858
890
|
* ```
|
|
859
891
|
*/
|
|
860
892
|
declare function rollbackStepsToSQL(migration: MigrationDefinition): string[];
|
|
@@ -1045,4 +1077,4 @@ interface ProtoOutput {
|
|
|
1045
1077
|
*/
|
|
1046
1078
|
declare function generateProtoDefinitions(schema: SchemaDefinition): ProtoOutput;
|
|
1047
1079
|
|
|
1048
|
-
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, resolveAtomicOp, revealSecret, rollbackStepsToSQL, serializeVector, toAtomicOp, transformSecretFieldsForWrite, validateRecord, validateTransition, vectorsEqual, verifySecret, verifySecretValue };
|
|
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.js
CHANGED
|
@@ -708,7 +708,7 @@ function validateStateMachineDefinition(collectionName, sm, fields) {
|
|
|
708
708
|
}
|
|
709
709
|
|
|
710
710
|
// src/schema/define.ts
|
|
711
|
-
var COLLECTION_NAME_RE = /^[
|
|
711
|
+
var COLLECTION_NAME_RE = /^[A-Za-z][A-Za-z0-9_]*$/;
|
|
712
712
|
var FIELD_NAME_RE = /^[a-z][a-zA-Z0-9_]*$/;
|
|
713
713
|
var RESERVED_FIELDS = /* @__PURE__ */ new Set(["id", "_created_at", "_updated_at", "_version", "_deleted"]);
|
|
714
714
|
function defineSchema(input) {
|
|
@@ -773,7 +773,7 @@ function validateVersion(version) {
|
|
|
773
773
|
function validateCollectionName(name) {
|
|
774
774
|
if (!COLLECTION_NAME_RE.test(name)) {
|
|
775
775
|
throw new SchemaValidationError(
|
|
776
|
-
`Collection name "${name}" is invalid. Must
|
|
776
|
+
`Collection name "${name}" is invalid. Must start with a letter and contain only letters, numbers, and underscores.`,
|
|
777
777
|
{ collection: name }
|
|
778
778
|
);
|
|
779
779
|
}
|
|
@@ -965,6 +965,11 @@ function validateRelation(name, relation, collections) {
|
|
|
965
965
|
}
|
|
966
966
|
}
|
|
967
967
|
|
|
968
|
+
// src/schema/quote-ident.ts
|
|
969
|
+
function quoteIdent(name) {
|
|
970
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
971
|
+
}
|
|
972
|
+
|
|
968
973
|
// src/schema/sql-gen.ts
|
|
969
974
|
function generateSQL(collectionName, collection, relations) {
|
|
970
975
|
const statements = [];
|
|
@@ -976,7 +981,7 @@ function generateSQL(collectionName, collection, relations) {
|
|
|
976
981
|
if (relations) {
|
|
977
982
|
for (const rel of Object.values(relations)) {
|
|
978
983
|
if (rel.from === collectionName && rel.field === fieldName) {
|
|
979
|
-
colDef += ` REFERENCES ${rel.to}(id)`;
|
|
984
|
+
colDef += ` REFERENCES ${quoteIdent(rel.to)}(id)`;
|
|
980
985
|
fkFields.push(fieldName);
|
|
981
986
|
break;
|
|
982
987
|
}
|
|
@@ -989,36 +994,40 @@ function generateSQL(collectionName, collection, relations) {
|
|
|
989
994
|
columns.push("_version TEXT NOT NULL DEFAULT ''");
|
|
990
995
|
columns.push("_field_versions TEXT NOT NULL DEFAULT '{}'");
|
|
991
996
|
columns.push("_deleted INTEGER NOT NULL DEFAULT 0");
|
|
992
|
-
statements.push(
|
|
997
|
+
statements.push(
|
|
998
|
+
`CREATE TABLE IF NOT EXISTS ${quoteIdent(collectionName)} (
|
|
993
999
|
${columns.join(",\n ")}
|
|
994
|
-
)`
|
|
1000
|
+
)`
|
|
1001
|
+
);
|
|
995
1002
|
for (const [fieldName, descriptor] of Object.entries(collection.fields)) {
|
|
996
1003
|
const colDef = columnDefinition(fieldName, descriptor);
|
|
997
|
-
statements.push(
|
|
998
|
-
|
|
1004
|
+
statements.push(
|
|
1005
|
+
`--kora:safe-alter
|
|
1006
|
+
ALTER TABLE ${quoteIdent(collectionName)} ADD COLUMN ${colDef}`
|
|
1007
|
+
);
|
|
999
1008
|
}
|
|
1000
1009
|
statements.push(
|
|
1001
1010
|
`--kora:safe-alter
|
|
1002
|
-
ALTER TABLE ${collectionName} ADD COLUMN _version TEXT NOT NULL DEFAULT ''`
|
|
1011
|
+
ALTER TABLE ${quoteIdent(collectionName)} ADD COLUMN _version TEXT NOT NULL DEFAULT ''`
|
|
1003
1012
|
);
|
|
1004
1013
|
statements.push(
|
|
1005
1014
|
`--kora:safe-alter
|
|
1006
|
-
ALTER TABLE ${collectionName} ADD COLUMN _field_versions TEXT NOT NULL DEFAULT '{}'`
|
|
1015
|
+
ALTER TABLE ${quoteIdent(collectionName)} ADD COLUMN _field_versions TEXT NOT NULL DEFAULT '{}'`
|
|
1007
1016
|
);
|
|
1008
1017
|
for (const indexField of collection.indexes) {
|
|
1009
1018
|
statements.push(
|
|
1010
|
-
`CREATE INDEX IF NOT EXISTS idx_${collectionName}_${indexField} ON ${collectionName} (${indexField})`
|
|
1019
|
+
`CREATE INDEX IF NOT EXISTS idx_${collectionName}_${indexField} ON ${quoteIdent(collectionName)} (${quoteIdent(indexField)})`
|
|
1011
1020
|
);
|
|
1012
1021
|
}
|
|
1013
1022
|
for (const fkField of fkFields) {
|
|
1014
1023
|
if (!indexedFields.has(fkField)) {
|
|
1015
1024
|
statements.push(
|
|
1016
|
-
`CREATE INDEX IF NOT EXISTS idx_${collectionName}_${fkField} ON ${collectionName} (${fkField})`
|
|
1025
|
+
`CREATE INDEX IF NOT EXISTS idx_${collectionName}_${fkField} ON ${quoteIdent(collectionName)} (${quoteIdent(fkField)})`
|
|
1017
1026
|
);
|
|
1018
1027
|
}
|
|
1019
1028
|
}
|
|
1020
1029
|
statements.push(
|
|
1021
|
-
`CREATE TABLE IF NOT EXISTS _kora_ops_${collectionName} (
|
|
1030
|
+
`CREATE TABLE IF NOT EXISTS ${quoteIdent(`_kora_ops_${collectionName}`)} (
|
|
1022
1031
|
id TEXT PRIMARY KEY NOT NULL,
|
|
1023
1032
|
node_id TEXT NOT NULL,
|
|
1024
1033
|
type TEXT NOT NULL,
|
|
@@ -1032,7 +1041,7 @@ ALTER TABLE ${collectionName} ADD COLUMN _field_versions TEXT NOT NULL DEFAULT '
|
|
|
1032
1041
|
)`
|
|
1033
1042
|
);
|
|
1034
1043
|
statements.push(
|
|
1035
|
-
`CREATE INDEX IF NOT EXISTS idx_kora_ops_${collectionName}_record_id ON _kora_ops_${collectionName} (record_id)`
|
|
1044
|
+
`CREATE INDEX IF NOT EXISTS idx_kora_ops_${collectionName}_record_id ON ${quoteIdent(`_kora_ops_${collectionName}`)} (record_id)`
|
|
1036
1045
|
);
|
|
1037
1046
|
return statements;
|
|
1038
1047
|
}
|
|
@@ -1050,6 +1059,9 @@ function generateFullDDL(schema) {
|
|
|
1050
1059
|
statements.push(
|
|
1051
1060
|
"CREATE TABLE IF NOT EXISTS _kora_sync_queue (\n id TEXT PRIMARY KEY NOT NULL,\n payload TEXT NOT NULL\n)"
|
|
1052
1061
|
);
|
|
1062
|
+
statements.push(
|
|
1063
|
+
"CREATE TABLE IF NOT EXISTS _kora_sync_rejected (\n operation_id TEXT PRIMARY KEY NOT NULL,\n collection TEXT NOT NULL,\n record_id TEXT NOT NULL,\n code TEXT NOT NULL,\n message TEXT NOT NULL,\n retriable INTEGER NOT NULL,\n rejected_at INTEGER NOT NULL\n)"
|
|
1064
|
+
);
|
|
1053
1065
|
statements.push(
|
|
1054
1066
|
"CREATE TABLE IF NOT EXISTS _kora_audit_traces (\n id TEXT PRIMARY KEY NOT NULL,\n recorded_at INTEGER NOT NULL,\n event_type TEXT NOT NULL,\n collection TEXT NOT NULL,\n record_id TEXT NOT NULL,\n field TEXT NOT NULL,\n strategy TEXT NOT NULL,\n tier INTEGER NOT NULL,\n constraint_name TEXT,\n trace_json TEXT NOT NULL\n)"
|
|
1055
1067
|
);
|
|
@@ -1066,7 +1078,7 @@ function generateFullDDL(schema) {
|
|
|
1066
1078
|
}
|
|
1067
1079
|
function columnDefinition(fieldName, descriptor) {
|
|
1068
1080
|
const sqlType = mapFieldType(descriptor);
|
|
1069
|
-
const parts = [fieldName, sqlType];
|
|
1081
|
+
const parts = [quoteIdent(fieldName), sqlType];
|
|
1070
1082
|
if (descriptor.required && descriptor.defaultValue === void 0 && !descriptor.auto) {
|
|
1071
1083
|
parts.push("NOT NULL");
|
|
1072
1084
|
}
|
|
@@ -1075,7 +1087,7 @@ function columnDefinition(fieldName, descriptor) {
|
|
|
1075
1087
|
}
|
|
1076
1088
|
if (descriptor.kind === "enum" && descriptor.enumValues) {
|
|
1077
1089
|
const values = descriptor.enumValues.map((v) => `'${v}'`).join(", ");
|
|
1078
|
-
parts.push(`CHECK (${fieldName} IN (${values}))`);
|
|
1090
|
+
parts.push(`CHECK (${quoteIdent(fieldName)} IN (${values}))`);
|
|
1079
1091
|
}
|
|
1080
1092
|
return parts.join(" ");
|
|
1081
1093
|
}
|
|
@@ -2212,14 +2224,18 @@ function migrationStepsToSQL(steps) {
|
|
|
2212
2224
|
statements.push(addFieldSQL(step.collection, step.field, step.descriptor));
|
|
2213
2225
|
break;
|
|
2214
2226
|
case "removeField":
|
|
2215
|
-
statements.push(
|
|
2227
|
+
statements.push(
|
|
2228
|
+
`ALTER TABLE ${quoteIdent(step.collection)} DROP COLUMN ${quoteIdent(step.field)}`
|
|
2229
|
+
);
|
|
2216
2230
|
break;
|
|
2217
2231
|
case "renameField":
|
|
2218
|
-
statements.push(
|
|
2232
|
+
statements.push(
|
|
2233
|
+
`ALTER TABLE ${quoteIdent(step.collection)} RENAME COLUMN ${quoteIdent(step.from)} TO ${quoteIdent(step.to)}`
|
|
2234
|
+
);
|
|
2219
2235
|
break;
|
|
2220
2236
|
case "addIndex":
|
|
2221
2237
|
statements.push(
|
|
2222
|
-
`CREATE INDEX IF NOT EXISTS idx_${step.collection}_${step.field} ON ${step.collection} (${step.field})`
|
|
2238
|
+
`CREATE INDEX IF NOT EXISTS idx_${step.collection}_${step.field} ON ${quoteIdent(step.collection)} (${quoteIdent(step.field)})`
|
|
2223
2239
|
);
|
|
2224
2240
|
break;
|
|
2225
2241
|
case "removeIndex":
|
|
@@ -2237,13 +2253,13 @@ function rollbackStepsToSQL(migration) {
|
|
|
2237
2253
|
}
|
|
2238
2254
|
function addFieldSQL(collection, field, descriptor) {
|
|
2239
2255
|
const sqlType = mapFieldType2(descriptor);
|
|
2240
|
-
const parts = [`ALTER TABLE ${collection} ADD COLUMN ${field}`, sqlType];
|
|
2256
|
+
const parts = [`ALTER TABLE ${quoteIdent(collection)} ADD COLUMN ${quoteIdent(field)}`, sqlType];
|
|
2241
2257
|
if (descriptor.defaultValue !== void 0) {
|
|
2242
2258
|
parts.push(`DEFAULT ${sqlDefault2(descriptor.defaultValue)}`);
|
|
2243
2259
|
}
|
|
2244
2260
|
if (descriptor.kind === "enum" && descriptor.enumValues) {
|
|
2245
2261
|
const values = descriptor.enumValues.map((v) => `'${v}'`).join(", ");
|
|
2246
|
-
parts.push(`CHECK (${field} IN (${values}))`);
|
|
2262
|
+
parts.push(`CHECK (${quoteIdent(field)} IN (${values}))`);
|
|
2247
2263
|
}
|
|
2248
2264
|
return parts.join(" ");
|
|
2249
2265
|
}
|
|
@@ -2593,6 +2609,7 @@ export {
|
|
|
2593
2609
|
migrate,
|
|
2594
2610
|
migrationStepsToSQL,
|
|
2595
2611
|
op,
|
|
2612
|
+
quoteIdent,
|
|
2596
2613
|
resolveAtomicOp,
|
|
2597
2614
|
revealSecret,
|
|
2598
2615
|
rollbackStepsToSQL,
|