hikoutei 0.3.1 → 0.3.3
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/README.md +12 -2
- package/apps-script/gateway/Code.gs +41 -6
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmMappedObservation.d.ts +2 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmMappedObservation.d.ts.map +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmMappedObservation.js +5 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmMappedObservation.js.map +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPolling.d.ts +52 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPolling.d.ts.map +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPolling.js +195 -13
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPolling.js.map +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingFastPath.d.ts +24 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingFastPath.d.ts.map +1 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingFastPath.js +124 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingFastPath.js.map +1 -0
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingInspection.js +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingInspection.js.map +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingPersistence.d.ts +15 -2
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingPersistence.d.ts.map +1 -1
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingPersistence.js +27 -3
- package/dist/adapter/persistence/providers/mikro-orm/observation/MikroOrmUserInputPollingPersistence.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/errors.d.ts +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/errors.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/errors.js +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/errors.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/index.d.ts +2 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/index.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/index.js +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/index.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperation.d.ts +3 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperation.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperation.js +9 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperation.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperationScript.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperationScript.js +139 -43
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/effect/effectOperationScript.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/observation/observationOperation.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/observation/observationOperation.js +86 -57
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/observation/observationOperation.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/shared/appsScriptStableCodecSource.d.ts +8 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/shared/appsScriptStableCodecSource.d.ts.map +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/shared/appsScriptStableCodecSource.js +122 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/shared/appsScriptStableCodecSource.js.map +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/batchAppendOperation.d.ts +31 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/batchAppendOperation.d.ts.map +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/batchAppendOperation.js +567 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/batchAppendOperation.js.map +1 -0
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/fastAppendOperation.d.ts +12 -17
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/fastAppendOperation.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/fastAppendOperation.js +27 -213
- package/dist/adapter/sheets/providers/apps-script-gateway/operations/write/fastAppendOperation.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/protocol/syncProtocol.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/protocol/syncProtocol.js +15 -36
- package/dist/adapter/sheets/providers/apps-script-gateway/protocol/syncProtocol.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/protocol/types.d.ts +2 -3
- package/dist/adapter/sheets/providers/apps-script-gateway/protocol/types.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationClient.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationClient.js +81 -8
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationClient.js.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationSyncGateway.d.ts +1 -6
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationSyncGateway.d.ts.map +1 -1
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationSyncGateway.js +15 -9
- package/dist/adapter/sheets/providers/apps-script-gateway/transport/operationSyncGateway.js.map +1 -1
- package/dist/application/orm/mapping/projection.js +1 -1
- package/dist/application/orm/mapping/projection.js.map +1 -1
- package/dist/application/orm/persistence/flush/flushCoordinator.d.ts.map +1 -1
- package/dist/application/orm/persistence/flush/flushCoordinator.js +1 -0
- package/dist/application/orm/persistence/flush/flushCoordinator.js.map +1 -1
- package/dist/application/orm/persistence/lifecycle/entityLifecycle.js +1 -1
- package/dist/application/orm/persistence/lifecycle/entityLifecycle.js.map +1 -1
- package/dist/application/sync/gateway/SyncGatewayBootstrap.d.ts +3 -1
- package/dist/application/sync/gateway/SyncGatewayBootstrap.d.ts.map +1 -1
- package/dist/application/sync/gateway/SyncGatewayBootstrap.js +3 -1
- package/dist/application/sync/gateway/SyncGatewayBootstrap.js.map +1 -1
- package/dist/application/sync/gateway/conflictProjection.d.ts +13 -0
- package/dist/application/sync/gateway/conflictProjection.d.ts.map +1 -0
- package/dist/application/sync/gateway/conflictProjection.js +58 -0
- package/dist/application/sync/gateway/conflictProjection.js.map +1 -0
- package/dist/application/sync/gateway/conflictProjectionRegistration.d.ts +11 -0
- package/dist/application/sync/gateway/conflictProjectionRegistration.d.ts.map +1 -0
- package/dist/application/sync/gateway/conflictProjectionRegistration.js +70 -0
- package/dist/application/sync/gateway/conflictProjectionRegistration.js.map +1 -0
- package/dist/application/sync/gateway/coordinator/CoordinatedSyncGateway.d.ts +102 -0
- package/dist/application/sync/gateway/coordinator/CoordinatedSyncGateway.d.ts.map +1 -0
- package/dist/application/sync/gateway/coordinator/CoordinatedSyncGateway.js +221 -0
- package/dist/application/sync/gateway/coordinator/CoordinatedSyncGateway.js.map +1 -0
- package/dist/application/sync/gateway/coordinator/asyncMutex.d.ts +51 -0
- package/dist/application/sync/gateway/coordinator/asyncMutex.d.ts.map +1 -0
- package/dist/application/sync/gateway/coordinator/asyncMutex.js +65 -0
- package/dist/application/sync/gateway/coordinator/asyncMutex.js.map +1 -0
- package/dist/application/sync/gateway/coordinator/coordinatorTelemetry.d.ts +31 -0
- package/dist/application/sync/gateway/coordinator/coordinatorTelemetry.d.ts.map +1 -0
- package/dist/application/sync/gateway/coordinator/coordinatorTelemetry.js +13 -0
- package/dist/application/sync/gateway/coordinator/coordinatorTelemetry.js.map +1 -0
- package/dist/application/sync/gateway/syncGateway.d.ts +26 -6
- package/dist/application/sync/gateway/syncGateway.d.ts.map +1 -1
- package/dist/application/sync/gateway/syncGateway.js +10 -2
- package/dist/application/sync/gateway/syncGateway.js.map +1 -1
- package/dist/application/sync/gateway/transportClassification.d.ts +62 -0
- package/dist/application/sync/gateway/transportClassification.d.ts.map +1 -0
- package/dist/application/sync/gateway/transportClassification.js +133 -0
- package/dist/application/sync/gateway/transportClassification.js.map +1 -0
- package/dist/application/sync/inbound/autoSystemConflictResolution.d.ts +26 -0
- package/dist/application/sync/inbound/autoSystemConflictResolution.d.ts.map +1 -0
- package/dist/application/sync/inbound/autoSystemConflictResolution.js +335 -0
- package/dist/application/sync/inbound/autoSystemConflictResolution.js.map +1 -0
- package/dist/application/sync/outbound/effects/AdaptiveEffectBatchController.d.ts +50 -0
- package/dist/application/sync/outbound/effects/AdaptiveEffectBatchController.d.ts.map +1 -0
- package/dist/application/sync/outbound/effects/AdaptiveEffectBatchController.js +97 -0
- package/dist/application/sync/outbound/effects/AdaptiveEffectBatchController.js.map +1 -0
- package/dist/application/sync/outbound/effects/SyncEffectSupervisor.d.ts +4 -1
- package/dist/application/sync/outbound/effects/SyncEffectSupervisor.d.ts.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectSupervisor.js +35 -1
- package/dist/application/sync/outbound/effects/SyncEffectSupervisor.js.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorker.d.ts +14 -2
- package/dist/application/sync/outbound/effects/SyncEffectWorker.d.ts.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorker.js +190 -31
- package/dist/application/sync/outbound/effects/SyncEffectWorker.js.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerConstants.d.ts +25 -2
- package/dist/application/sync/outbound/effects/SyncEffectWorkerConstants.d.ts.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerConstants.js +25 -2
- package/dist/application/sync/outbound/effects/SyncEffectWorkerConstants.js.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerDispatch.d.ts +14 -7
- package/dist/application/sync/outbound/effects/SyncEffectWorkerDispatch.d.ts.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerDispatch.js +118 -14
- package/dist/application/sync/outbound/effects/SyncEffectWorkerDispatch.js.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerRouting.d.ts +30 -9
- package/dist/application/sync/outbound/effects/SyncEffectWorkerRouting.d.ts.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerRouting.js +102 -18
- package/dist/application/sync/outbound/effects/SyncEffectWorkerRouting.js.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerTransitions.d.ts.map +1 -1
- package/dist/application/sync/outbound/effects/SyncEffectWorkerTransitions.js +49 -14
- package/dist/application/sync/outbound/effects/SyncEffectWorkerTransitions.js.map +1 -1
- package/dist/application/sync/outbound/reconciliation/ReconciliationScanner.d.ts.map +1 -1
- package/dist/application/sync/outbound/reconciliation/ReconciliationScanner.js +97 -17
- package/dist/application/sync/outbound/reconciliation/ReconciliationScanner.js.map +1 -1
- package/dist/application/sync/service/SyncServiceBootstrap.d.ts +17 -0
- package/dist/application/sync/service/SyncServiceBootstrap.d.ts.map +1 -1
- package/dist/application/sync/service/SyncServiceBootstrap.js +125 -10
- package/dist/application/sync/service/SyncServiceBootstrap.js.map +1 -1
- package/dist/application/sync/service/contracts.d.ts +2 -0
- package/dist/application/sync/service/contracts.d.ts.map +1 -1
- package/dist/application/sync/telemetry/syncTiming.d.ts +6 -0
- package/dist/application/sync/telemetry/syncTiming.d.ts.map +1 -1
- package/dist/application/sync/telemetry/syncTiming.js +2 -0
- package/dist/application/sync/telemetry/syncTiming.js.map +1 -1
- package/dist/domain/conflict/index.d.ts +1 -1
- package/dist/domain/conflict/index.d.ts.map +1 -1
- package/dist/domain/conflict/index.js +1 -1
- package/dist/domain/conflict/index.js.map +1 -1
- package/dist/domain/conflict/transitions.d.ts +3 -0
- package/dist/domain/conflict/transitions.d.ts.map +1 -1
- package/dist/domain/conflict/transitions.js +3 -2
- package/dist/domain/conflict/transitions.js.map +1 -1
- package/dist/domain/model/constants.d.ts +1 -0
- package/dist/domain/model/constants.d.ts.map +1 -1
- package/dist/domain/model/constants.js +1 -0
- package/dist/domain/model/constants.js.map +1 -1
- package/dist/infrastructure/storage/index.d.ts +4 -2
- package/dist/infrastructure/storage/index.d.ts.map +1 -1
- package/dist/infrastructure/storage/index.js +2 -1
- package/dist/infrastructure/storage/index.js.map +1 -1
- package/dist/infrastructure/storage/sqlite/migrateSchema.d.ts.map +1 -1
- package/dist/infrastructure/storage/sqlite/migrateSchema.js +59 -1
- package/dist/infrastructure/storage/sqlite/migrateSchema.js.map +1 -1
- package/dist/infrastructure/storage/sqlite/schema.d.ts +12 -1
- package/dist/infrastructure/storage/sqlite/schema.d.ts.map +1 -1
- package/dist/infrastructure/storage/sqlite/schema.js +47 -3
- package/dist/infrastructure/storage/sqlite/schema.js.map +1 -1
- package/dist/infrastructure/storage/sqlite/schemaTypes.d.ts +2 -2
- package/dist/infrastructure/storage/sqlite/schemaTypes.d.ts.map +1 -1
- package/dist/infrastructure/storage/state/canonical/canonicalCommit.js +1 -1
- package/dist/infrastructure/storage/state/canonical/canonicalCommit.js.map +1 -1
- package/dist/infrastructure/storage/state/mapped/mappedPersistenceSql.d.ts +1 -0
- package/dist/infrastructure/storage/state/mapped/mappedPersistenceSql.d.ts.map +1 -1
- package/dist/infrastructure/storage/state/mapped/mappedPersistenceSql.js +1 -1
- package/dist/infrastructure/storage/state/mapped/mappedPersistenceSql.js.map +1 -1
- package/dist/infrastructure/storage/state/observation/observationAudit.js +5 -1
- package/dist/infrastructure/storage/state/observation/observationAudit.js.map +1 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriter.d.ts +10 -0
- package/dist/infrastructure/storage/state/resolution/resolutionWriter.d.ts.map +1 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriter.js +106 -20
- package/dist/infrastructure/storage/state/resolution/resolutionWriter.js.map +1 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriterContracts.d.ts +9 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriterContracts.d.ts.map +1 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriterContracts.js +3 -0
- package/dist/infrastructure/storage/state/resolution/resolutionWriterContracts.js.map +1 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriterSql.d.ts +11 -0
- package/dist/infrastructure/storage/state/resolution/resolutionWriterSql.d.ts.map +1 -1
- package/dist/infrastructure/storage/state/resolution/resolutionWriterSql.js +35 -0
- package/dist/infrastructure/storage/state/resolution/resolutionWriterSql.js.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutbox.d.ts +12 -4
- package/dist/infrastructure/storage/sync/outbound/effectOutbox.d.ts.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutbox.js +46 -15
- package/dist/infrastructure/storage/sync/outbound/effectOutbox.js.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxContracts.d.ts +24 -0
- package/dist/infrastructure/storage/sync/outbound/effectOutboxContracts.d.ts.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxContracts.js +1 -0
- package/dist/infrastructure/storage/sync/outbound/effectOutboxContracts.js.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSql.d.ts +9 -7
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSql.d.ts.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSql.js +44 -8
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSql.js.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSupport.d.ts +3 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSupport.d.ts.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSupport.js +35 -2
- package/dist/infrastructure/storage/sync/outbound/effectOutboxSupport.js.map +1 -1
- package/dist/infrastructure/storage/sync/outbound/reconciliationSql.js +1 -0
- package/dist/infrastructure/storage/sync/outbound/reconciliationSql.js.map +1 -1
- package/dist/infrastructure/storage/sync/shared/spreadsheetAuthority.d.ts +31 -0
- package/dist/infrastructure/storage/sync/shared/spreadsheetAuthority.d.ts.map +1 -0
- package/dist/infrastructure/storage/sync/shared/spreadsheetAuthority.js +92 -0
- package/dist/infrastructure/storage/sync/shared/spreadsheetAuthority.js.map +1 -0
- package/dist/infrastructure/storage/sync/shared/writerLease.js +3 -1
- package/dist/infrastructure/storage/sync/shared/writerLease.js.map +1 -1
- package/dist/shared/encoding/constants.d.ts +1 -12
- package/dist/shared/encoding/constants.d.ts.map +1 -1
- package/dist/shared/encoding/constants.js +1 -10
- package/dist/shared/encoding/constants.js.map +1 -1
- package/dist/shared/encoding/stableEncode.d.ts +3 -30
- package/dist/shared/encoding/stableEncode.d.ts.map +1 -1
- package/dist/shared/encoding/stableEncode.js +12 -195
- package/dist/shared/encoding/stableEncode.js.map +1 -1
- package/dist/shared/encoding/types.d.ts +4 -9
- package/dist/shared/encoding/types.d.ts.map +1 -1
- package/docs/advanced-sheets-gateway-concurrency-problem.md +434 -0
- package/docs/architecture.md +53 -11
- package/docs/ci.md +27 -0
- package/docs/google-sheets-sync-scaling-strategy.md +459 -0
- package/docs/quick-start.md +15 -1
- package/docs/sync-bulk-write-benchmark.md +520 -0
- package/docs/sync-observability.md +39 -3
- package/docs/write-and-synchronization-flow.md +76 -17
- package/package.json +4 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Durable per-spreadsheet authority records used to fence remote mutations. */
|
|
2
|
+
import { STORAGE_ERROR_CODES, StorageError } from "../../errors.js";
|
|
3
|
+
import { isFencingValidWithSql } from "./writerLease.js";
|
|
4
|
+
const READ_PHYSICAL_AUTHORITY_SQL = `
|
|
5
|
+
SELECT physical.spreadsheet_id, authority.owner_id, authority.authority_epoch,
|
|
6
|
+
authority.authority_token, authority.updated_at
|
|
7
|
+
FROM physical_sheet_registry AS physical
|
|
8
|
+
LEFT JOIN spreadsheet_authority AS authority
|
|
9
|
+
ON authority.spreadsheet_id = physical.spreadsheet_id
|
|
10
|
+
WHERE physical.physical_sheet_id = ?
|
|
11
|
+
`;
|
|
12
|
+
const INSERT_AUTHORITY_SQL = `
|
|
13
|
+
INSERT INTO spreadsheet_authority (
|
|
14
|
+
spreadsheet_id, owner_id, authority_epoch, authority_token, updated_at
|
|
15
|
+
) VALUES (?, ?, ?, ?, ?)
|
|
16
|
+
`;
|
|
17
|
+
const UPDATE_AUTHORITY_SQL = `
|
|
18
|
+
UPDATE spreadsheet_authority
|
|
19
|
+
SET owner_id = ?, authority_epoch = ?, authority_token = ?, updated_at = ?
|
|
20
|
+
WHERE spreadsheet_id = ?
|
|
21
|
+
AND authority_epoch <= ?
|
|
22
|
+
`;
|
|
23
|
+
/** Ensures the current writer fence owns one registered spreadsheet authority. */
|
|
24
|
+
export async function ensureSpreadsheetAuthorityWithSql(sql, options) {
|
|
25
|
+
if (options.ownerId.length === 0 || options.physicalSheetId.length === 0) {
|
|
26
|
+
throw new StorageError(STORAGE_ERROR_CODES.INVALID_WRITER_LEASE_OPTIONS, "spreadsheet authority owner and physical sheet ID are required");
|
|
27
|
+
}
|
|
28
|
+
if (!(await isFencingValidWithSql(sql, options)))
|
|
29
|
+
return { kind: "fenced_out" };
|
|
30
|
+
const row = await sql.get(READ_PHYSICAL_AUTHORITY_SQL, [options.physicalSheetId]);
|
|
31
|
+
if (row === undefined || row.spreadsheet_id.length === 0) {
|
|
32
|
+
throw new StorageError(STORAGE_ERROR_CODES.SYNC_REGISTRY_TARGET_UNAVAILABLE, "physical sheet is not registered for spreadsheet authority");
|
|
33
|
+
}
|
|
34
|
+
if (row.authority_epoch !== undefined && row.authority_epoch !== null && (row.authority_epoch > options.writerEpoch ||
|
|
35
|
+
row.authority_epoch === options.writerEpoch && (row.authority_token !== options.fencingToken || row.owner_id !== options.ownerId))) {
|
|
36
|
+
return { kind: "fenced_out" };
|
|
37
|
+
}
|
|
38
|
+
const authority = {
|
|
39
|
+
spreadsheetId: row.spreadsheet_id,
|
|
40
|
+
ownerId: options.ownerId,
|
|
41
|
+
authorityEpoch: options.writerEpoch,
|
|
42
|
+
authorityToken: options.fencingToken,
|
|
43
|
+
updatedAt: options.now,
|
|
44
|
+
};
|
|
45
|
+
if (row.authority_epoch === undefined || row.authority_epoch === null) {
|
|
46
|
+
const inserted = await sql.run(INSERT_AUTHORITY_SQL, [
|
|
47
|
+
authority.spreadsheetId,
|
|
48
|
+
authority.ownerId,
|
|
49
|
+
authority.authorityEpoch,
|
|
50
|
+
authority.authorityToken,
|
|
51
|
+
authority.updatedAt,
|
|
52
|
+
]);
|
|
53
|
+
if (inserted.changes !== 1)
|
|
54
|
+
return { kind: "fenced_out" };
|
|
55
|
+
return { kind: "claimed", authority };
|
|
56
|
+
}
|
|
57
|
+
const updated = await sql.run(UPDATE_AUTHORITY_SQL, [
|
|
58
|
+
authority.ownerId,
|
|
59
|
+
authority.authorityEpoch,
|
|
60
|
+
authority.authorityToken,
|
|
61
|
+
authority.updatedAt,
|
|
62
|
+
authority.spreadsheetId,
|
|
63
|
+
authority.authorityEpoch,
|
|
64
|
+
]);
|
|
65
|
+
return updated.changes === 1
|
|
66
|
+
? { kind: "claimed", authority }
|
|
67
|
+
: { kind: "fenced_out" };
|
|
68
|
+
}
|
|
69
|
+
/** Ensures a spreadsheet authority through an adapter-owned transaction. */
|
|
70
|
+
export async function ensureSpreadsheetAuthorityWithAdapter(storage, options) {
|
|
71
|
+
return storage.transaction(({ sql }) => ensureSpreadsheetAuthorityWithSql(sql, options));
|
|
72
|
+
}
|
|
73
|
+
/** Reads the durable authority attached to one registered physical sheet. */
|
|
74
|
+
export async function readSpreadsheetAuthorityWithSql(sql, physicalSheetId) {
|
|
75
|
+
const row = await sql.get(READ_PHYSICAL_AUTHORITY_SQL, [physicalSheetId]);
|
|
76
|
+
if (row === undefined || row.authority_epoch === undefined || row.authority_epoch === null ||
|
|
77
|
+
row.authority_token === undefined || row.authority_token === null) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
spreadsheetId: row.spreadsheet_id,
|
|
82
|
+
ownerId: row.owner_id ?? "",
|
|
83
|
+
authorityEpoch: row.authority_epoch,
|
|
84
|
+
authorityToken: row.authority_token,
|
|
85
|
+
updatedAt: row.updated_at ?? 0,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Reads one durable spreadsheet authority through a fresh adapter context. */
|
|
89
|
+
export async function readSpreadsheetAuthorityWithAdapter(storage, physicalSheetId) {
|
|
90
|
+
return storage.read(({ sql }) => readSpreadsheetAuthorityWithSql(sql, physicalSheetId));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=spreadsheetAuthority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spreadsheetAuthority.js","sourceRoot":"","sources":["../../../../../src/infrastructure/storage/sync/shared/spreadsheetAuthority.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,MAAM,2BAA2B,GAAG;;;;;;;CAOnC,CAAC;AAEF,MAAM,oBAAoB,GAAG;;;;CAI5B,CAAC;AAEF,MAAM,oBAAoB,GAAG;;;;;CAK5B,CAAC;AAcF,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,GAAgB,EAChB,OAAwF;IAExF,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,YAAY,CACpB,mBAAmB,CAAC,4BAA4B,EAChD,gEAAgE,CACj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C;QACtE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO;QACL,aAAa,EAAE,GAAG,CAAC,cAAc;QACjC,OAAO,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE;QAC3B,cAAc,EAAE,GAAG,CAAC,eAAe;QACnC,cAAc,EAAE,GAAG,CAAC,eAAe;QACnC,SAAS,EAAE,GAAG,CAAC,UAAU,IAAI,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,mCAAmC,CACvD,OAA0B,EAC1B,eAAuB;IAEvB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,+BAA+B,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -169,7 +169,9 @@ function makeLease(role, writerId, writerEpoch, leaseUntil) {
|
|
|
169
169
|
role,
|
|
170
170
|
writerId,
|
|
171
171
|
writerEpoch,
|
|
172
|
-
|
|
172
|
+
// Include the owner identity as well as the monotonically increasing epoch;
|
|
173
|
+
// equal epochs from different roles must never share a remote authority token.
|
|
174
|
+
fencingToken: `fence-${writerEpoch}:${writerId}`,
|
|
173
175
|
leaseUntil,
|
|
174
176
|
};
|
|
175
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writerLease.js","sourceRoot":"","sources":["../../../../../src/infrastructure/storage/sync/shared/writerLease.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,qBAAqB,GACzB,mGAAmG,CAAC;AAEtG,MAAM,uBAAuB,GAAG;;;CAG/B,CAAC;AAEF,MAAM,sBAAsB,GAAG;;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AmB,CAAC,GAAgB,EAAE,IAAY;IACzD,OAAO,GAAG,CAAC,GAAG,CAAW,qBAAqB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS,CAChB,IAAY,EACZ,QAAgB,EAChB,WAAmB,EACnB,UAAkB;IAElB,OAAO;QACL,IAAI;QACJ,QAAQ;QACR,WAAW;QACX,YAAY,EAAE,SAAS,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"writerLease.js","sourceRoot":"","sources":["../../../../../src/infrastructure/storage/sync/shared/writerLease.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,qBAAqB,GACzB,mGAAmG,CAAC;AAEtG,MAAM,uBAAuB,GAAG;;;CAG/B,CAAC;AAEF,MAAM,sBAAsB,GAAG;;;;;CAK9B,CAAC;AAEF,MAAM,yBAAyB,GAAG;;;;CAIjC,CAAC;AAUF,yEAAyE;AACzE,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;CAClB,CAAC;AAMX,0EAA0E;AAC1E,MAAM,CAAC,MAAM,kCAAkC,GAAG;IAChD,aAAa,EAAE,eAAe;IAC9B,yBAAyB,EAAE,2BAA2B;IACtD,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;CAChC,CAAC;AA+BX,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG;;;CAG/B,CAAC;AAEF,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAC7B,KAAqB;IAErB,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC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,EAChD,sDAAsD,CACvD,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,OAAO,CAAC,eAAe,IAAI,CAAC,EAAE,CAAC;QACnF,MAAM,IAAI,YAAY,CACpB,mBAAmB,CAAC,4BAA4B,EAChD,uDAAuD,CACxD,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,YAAY,CACpB,mBAAmB,CAAC,4BAA4B,EAChD,8CAA8C,CAC/C,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -11,18 +11,7 @@ export declare const JAVASCRIPT_TYPE_NAMES: {
|
|
|
11
11
|
};
|
|
12
12
|
/** Closed set of JavaScript typeof result names. */
|
|
13
13
|
export type JavaScriptTypeName = (typeof JAVASCRIPT_TYPE_NAMES)[keyof typeof JAVASCRIPT_TYPE_NAMES];
|
|
14
|
-
|
|
15
|
-
export declare const STABLE_ENCODING_ERROR_CODES: {
|
|
16
|
-
readonly UNSUPPORTED_VALUE_TYPE: "unsupported_value_type";
|
|
17
|
-
readonly NON_FINITE_NUMBER: "non_finite_number";
|
|
18
|
-
readonly INVALID_DATE_FORMAT: "invalid_date_format";
|
|
19
|
-
readonly INVALID_DATE_BYTE_LENGTH: "invalid_date_byte_length";
|
|
20
|
-
readonly DUPLICATE_OBJECT_KEY: "duplicate_object_key";
|
|
21
|
-
readonly UNPAIRED_HIGH_SURROGATE: "unpaired_high_surrogate";
|
|
22
|
-
readonly UNPAIRED_LOW_SURROGATE: "unpaired_low_surrogate";
|
|
23
|
-
};
|
|
24
|
-
/** Closed set of stable encoder error codes. */
|
|
25
|
-
export type StableEncodingErrorCode = (typeof STABLE_ENCODING_ERROR_CODES)[keyof typeof STABLE_ENCODING_ERROR_CODES];
|
|
14
|
+
export { STABLE_ENCODING_ERROR_CODES, type StableEncodingErrorCode, } from "@hikoutei/kohkai";
|
|
26
15
|
/** Runtime values for normalized cell value kinds. */
|
|
27
16
|
export declare const NORMALIZED_CELL_KINDS: {
|
|
28
17
|
readonly STRING: "string";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/shared/encoding/constants.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB;;;;;;;;;CASxB,CAAC;AAEX,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/shared/encoding/constants.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB;;;;;;;;;CASxB,CAAC;AAEX,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE,OAAO,EACL,2BAA2B,EAC3B,KAAK,uBAAuB,GAC7B,MAAM,kBAAkB,CAAC;AAE1B,sDAAsD;AACtD,eAAO,MAAM,qBAAqB;;;;;CAKxB,CAAC;AAEX,iDAAiD;AACjD,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE,gEAAgE;AAChE,eAAO,MAAM,sBAAsB;;;;;;CAMzB,CAAC;AAEX,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAC7B,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -9,16 +9,7 @@ export const JAVASCRIPT_TYPE_NAMES = {
|
|
|
9
9
|
SYMBOL: "symbol",
|
|
10
10
|
FUNCTION: "function",
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
export const STABLE_ENCODING_ERROR_CODES = {
|
|
14
|
-
UNSUPPORTED_VALUE_TYPE: "unsupported_value_type",
|
|
15
|
-
NON_FINITE_NUMBER: "non_finite_number",
|
|
16
|
-
INVALID_DATE_FORMAT: "invalid_date_format",
|
|
17
|
-
INVALID_DATE_BYTE_LENGTH: "invalid_date_byte_length",
|
|
18
|
-
DUPLICATE_OBJECT_KEY: "duplicate_object_key",
|
|
19
|
-
UNPAIRED_HIGH_SURROGATE: "unpaired_high_surrogate",
|
|
20
|
-
UNPAIRED_LOW_SURROGATE: "unpaired_low_surrogate",
|
|
21
|
-
};
|
|
12
|
+
export { STABLE_ENCODING_ERROR_CODES, } from "@hikoutei/kohkai";
|
|
22
13
|
/** Runtime values for normalized cell value kinds. */
|
|
23
14
|
export const NORMALIZED_CELL_KINDS = {
|
|
24
15
|
STRING: "string",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/shared/encoding/constants.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAMX,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/shared/encoding/constants.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAMX,OAAO,EACL,2BAA2B,GAE5B,MAAM,kBAAkB,CAAC;AAE1B,sDAAsD;AACtD,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;CACJ,CAAC;AAMX,gEAAgE;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;CACN,CAAC"}
|
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `stable_encode_v1` — deterministic cross-runtime byte encoding.
|
|
3
|
-
*
|
|
4
|
-
* Grammar (no whitespace between tokens):
|
|
5
|
-
*
|
|
6
|
-
* ```
|
|
7
|
-
* null := "n"
|
|
8
|
-
* boolean := "b0" | "b1"
|
|
9
|
-
* string := "s" <utf8ByteLength> ":" <NFC UTF-8 bytes>
|
|
10
|
-
* number := "f" <asciiByteLength> ":" <canonical finite decimal>
|
|
11
|
-
* date := "d" "24" ":" <UTC YYYY-MM-DDTHH:mm:ss.SSSZ>
|
|
12
|
-
* array := "a" <count> "[" <value>* "]"
|
|
13
|
-
* object := "o" <count> "{" (<encoded string key> <value>)* "}"
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Rules:
|
|
17
|
-
* - string and object key bytes are NFC-normalized then UTF-8 byte-length prefixed
|
|
18
|
-
* - object keys are sorted by UTF-8 byte lexicographic order
|
|
19
|
-
* - array order is preserved
|
|
20
|
-
* - number is the shortest round-trip decimal of its IEEE-754 binary64 value
|
|
21
|
-
* - -0 is unified to 0; NaN/Infinity are rejected
|
|
22
|
-
* - date payload is always 24 bytes: YYYY-MM-DDTHH:mm:ss.SSSZ
|
|
23
|
-
*
|
|
24
|
-
* The SHA-256 hex of the encoded bytes is the canonical fingerprint.
|
|
25
|
-
*/
|
|
1
|
+
/** Hikoutei compatibility facade for the generic stable_encode_v1 core. */
|
|
26
2
|
import type { HikouteiStableHash } from "../identity/types.js";
|
|
27
3
|
import type { StableValue } from "./types.js";
|
|
28
|
-
/**
|
|
29
|
-
* Encodes a stable value to its canonical byte sequence.
|
|
30
|
-
* Throws on unsupported values (NaN, Infinity, non-finite numbers).
|
|
31
|
-
*/
|
|
4
|
+
/** Encodes a stable value while preserving Hikoutei's existing error contract. */
|
|
32
5
|
export declare function stableEncode(value: StableValue): Uint8Array;
|
|
33
|
-
/** SHA-256
|
|
6
|
+
/** Computes the SHA-256 fingerprint of Hikoutei's stable encoding. */
|
|
34
7
|
export declare function stableHash(value: StableValue): HikouteiStableHash;
|
|
35
8
|
//# sourceMappingURL=stableEncode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stableEncode.d.ts","sourceRoot":"","sources":["../../../src/shared/encoding/stableEncode.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stableEncode.d.ts","sourceRoot":"","sources":["../../../src/shared/encoding/stableEncode.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAG3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAS3D;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,kBAAkB,CAEjE"}
|
|
@@ -1,204 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `stable_encode_v1` — deterministic cross-runtime byte encoding.
|
|
3
|
-
*
|
|
4
|
-
* Grammar (no whitespace between tokens):
|
|
5
|
-
*
|
|
6
|
-
* ```
|
|
7
|
-
* null := "n"
|
|
8
|
-
* boolean := "b0" | "b1"
|
|
9
|
-
* string := "s" <utf8ByteLength> ":" <NFC UTF-8 bytes>
|
|
10
|
-
* number := "f" <asciiByteLength> ":" <canonical finite decimal>
|
|
11
|
-
* date := "d" "24" ":" <UTC YYYY-MM-DDTHH:mm:ss.SSSZ>
|
|
12
|
-
* array := "a" <count> "[" <value>* "]"
|
|
13
|
-
* object := "o" <count> "{" (<encoded string key> <value>)* "}"
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Rules:
|
|
17
|
-
* - string and object key bytes are NFC-normalized then UTF-8 byte-length prefixed
|
|
18
|
-
* - object keys are sorted by UTF-8 byte lexicographic order
|
|
19
|
-
* - array order is preserved
|
|
20
|
-
* - number is the shortest round-trip decimal of its IEEE-754 binary64 value
|
|
21
|
-
* - -0 is unified to 0; NaN/Infinity are rejected
|
|
22
|
-
* - date payload is always 24 bytes: YYYY-MM-DDTHH:mm:ss.SSSZ
|
|
23
|
-
*
|
|
24
|
-
* The SHA-256 hex of the encoded bytes is the canonical fingerprint.
|
|
25
|
-
*/
|
|
1
|
+
/** Hikoutei compatibility facade for the generic stable_encode_v1 core. */
|
|
26
2
|
import { createHash } from "node:crypto";
|
|
27
|
-
import { JAVASCRIPT_TYPE_NAMES, NORMALIZED_CELL_KINDS, STABLE_ENCODING_ERROR_CODES, } from "./constants.js";
|
|
28
|
-
import { isJavaScriptType, isRecord } from "./typeGuards.js";
|
|
29
|
-
import { isCanonicalUtcIsoDate } from "../validation.js";
|
|
30
3
|
import { StableEncodingError } from "../../domain/errors/stableEncoding.js";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* Throws on unsupported values (NaN, Infinity, non-finite numbers).
|
|
34
|
-
*/
|
|
4
|
+
import { StableCodecError, stableEncode as encodeStableValue, } from "@hikoutei/kohkai";
|
|
5
|
+
/** Encodes a stable value while preserving Hikoutei's existing error contract. */
|
|
35
6
|
export function stableEncode(value) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return concat(chunks);
|
|
39
|
-
}
|
|
40
|
-
/** SHA-256 hex of the stable encoding. This is the canonical fingerprint. */
|
|
41
|
-
export function stableHash(value) {
|
|
42
|
-
return createHash("sha256").update(stableEncode(value)).digest("hex");
|
|
43
|
-
}
|
|
44
|
-
function encodeValue(value, chunks) {
|
|
45
|
-
if (value === null) {
|
|
46
|
-
chunks.push(ascii("n"));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (value === true) {
|
|
50
|
-
chunks.push(ascii("b1"));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (value === false) {
|
|
54
|
-
chunks.push(ascii("b0"));
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (isJavaScriptType(value, JAVASCRIPT_TYPE_NAMES.NUMBER)) {
|
|
58
|
-
encodeNumber(value, chunks);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (isJavaScriptType(value, JAVASCRIPT_TYPE_NAMES.STRING)) {
|
|
62
|
-
encodeString(value, chunks);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (isDateValue(value)) {
|
|
66
|
-
encodeDate(value.value, chunks);
|
|
67
|
-
return;
|
|
7
|
+
try {
|
|
8
|
+
return encodeStableValue(value);
|
|
68
9
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
if (isRecord(value)) {
|
|
74
|
-
encodeObject(value, chunks);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.UNSUPPORTED_VALUE_TYPE, `stable_encode: unsupported value type: ${typeof value}`);
|
|
78
|
-
}
|
|
79
|
-
function encodeNumber(value, chunks) {
|
|
80
|
-
if (!Number.isFinite(value)) {
|
|
81
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.NON_FINITE_NUMBER, `stable_encode: non-finite number: ${value}`);
|
|
82
|
-
}
|
|
83
|
-
const unified = value === 0 ? 0 : value; // unify -0 to 0
|
|
84
|
-
const decimal = shortestRoundTripDecimal(unified);
|
|
85
|
-
const encoded = ascii(decimal);
|
|
86
|
-
const lengthPrefix = ascii(`f${encoded.length}:`);
|
|
87
|
-
chunks.push(lengthPrefix, encoded);
|
|
88
|
-
}
|
|
89
|
-
function encodeString(value, chunks) {
|
|
90
|
-
const nfc = normalizeScalarString(value);
|
|
91
|
-
const bytes = textEncode(nfc);
|
|
92
|
-
const lengthPrefix = ascii(`s${bytes.length}:`);
|
|
93
|
-
chunks.push(lengthPrefix, bytes);
|
|
94
|
-
}
|
|
95
|
-
function encodeDate(iso, chunks) {
|
|
96
|
-
if (!isCanonicalUtcIsoDate(iso)) {
|
|
97
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.INVALID_DATE_FORMAT, `stable_encode: invalid date format: ${iso}`);
|
|
98
|
-
}
|
|
99
|
-
const bytes = textEncode(iso);
|
|
100
|
-
if (bytes.length !== 24) {
|
|
101
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.INVALID_DATE_BYTE_LENGTH, `stable_encode: date must be exactly 24 bytes, got ${bytes.length}`);
|
|
102
|
-
}
|
|
103
|
-
chunks.push(ascii("d24:"), bytes);
|
|
104
|
-
}
|
|
105
|
-
function encodeArray(values, chunks) {
|
|
106
|
-
chunks.push(ascii(`a${values.length}[`));
|
|
107
|
-
for (const v of values) {
|
|
108
|
-
encodeValue(v, chunks);
|
|
109
|
-
}
|
|
110
|
-
chunks.push(ascii("]"));
|
|
111
|
-
}
|
|
112
|
-
function encodeObject(obj, chunks) {
|
|
113
|
-
const keys = Object.keys(obj);
|
|
114
|
-
const entries = [];
|
|
115
|
-
const normalizedKeys = new Set();
|
|
116
|
-
for (const key of keys) {
|
|
117
|
-
const nfcKey = normalizeScalarString(key);
|
|
118
|
-
if (normalizedKeys.has(nfcKey)) {
|
|
119
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.DUPLICATE_OBJECT_KEY, `stable_encode: duplicate object key after NFC normalization: ${nfcKey}`);
|
|
120
|
-
}
|
|
121
|
-
normalizedKeys.add(nfcKey);
|
|
122
|
-
const encodedKey = textEncode(nfcKey);
|
|
123
|
-
entries.push([encodedKey, nfcKey, obj[key]]);
|
|
124
|
-
}
|
|
125
|
-
entries.sort((a, b) => compareBytes(a[0], b[0]));
|
|
126
|
-
chunks.push(ascii(`o${entries.length}{`));
|
|
127
|
-
for (const [encodedKey, , val] of entries) {
|
|
128
|
-
const lengthPrefix = ascii(`s${encodedKey.length}:`);
|
|
129
|
-
chunks.push(lengthPrefix, encodedKey);
|
|
130
|
-
encodeValue(val, chunks);
|
|
131
|
-
}
|
|
132
|
-
chunks.push(ascii("}"));
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Produces the shortest decimal representation that round-trips to the same
|
|
136
|
-
* IEEE-754 binary64 value.
|
|
137
|
-
*
|
|
138
|
-
* - Uses the V8 `toString` which already gives shortest round-trip for most
|
|
139
|
-
* numbers. We normalize exponent format to use lowercase `e` with no leading
|
|
140
|
-
* zero in the exponent.
|
|
141
|
-
* - Integers are emitted without a decimal point.
|
|
142
|
-
*/
|
|
143
|
-
function shortestRoundTripDecimal(value) {
|
|
144
|
-
const str = value.toString();
|
|
145
|
-
// Normalize exponent: V8 uses "e+21" or "e-7", we want "e21" and "e-7"
|
|
146
|
-
return str.replace(/e([+-])0*(\d)/, (_, sign, digit) => {
|
|
147
|
-
const expSign = sign === "-" ? "-" : "";
|
|
148
|
-
return `e${expSign}${digit}`;
|
|
149
|
-
}).replace(/e\+/, "e");
|
|
150
|
-
}
|
|
151
|
-
function isDateValue(value) {
|
|
152
|
-
return (isRecord(value) &&
|
|
153
|
-
Object.keys(value).length === 2 &&
|
|
154
|
-
value.kind === NORMALIZED_CELL_KINDS.DATE &&
|
|
155
|
-
typeof value.value === "string");
|
|
156
|
-
}
|
|
157
|
-
/** Rejects unpaired UTF-16 surrogates instead of letting TextEncoder replace them. */
|
|
158
|
-
function normalizeScalarString(value) {
|
|
159
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
160
|
-
const codeUnit = value.charCodeAt(index);
|
|
161
|
-
if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
|
|
162
|
-
const next = value.charCodeAt(index + 1);
|
|
163
|
-
if (!Number.isInteger(next) || next < 0xdc00 || next > 0xdfff) {
|
|
164
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.UNPAIRED_HIGH_SURROGATE, "stable_encode: string contains an unpaired high surrogate");
|
|
165
|
-
}
|
|
166
|
-
index += 1;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
|
|
170
|
-
throw new StableEncodingError(STABLE_ENCODING_ERROR_CODES.UNPAIRED_LOW_SURROGATE, "stable_encode: string contains an unpaired low surrogate");
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error instanceof StableCodecError) {
|
|
12
|
+
throw new StableEncodingError(error.code, error.message);
|
|
171
13
|
}
|
|
14
|
+
throw error;
|
|
172
15
|
}
|
|
173
|
-
return value.normalize("NFC");
|
|
174
16
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
function textEncode(s) {
|
|
179
|
-
return new TextEncoder().encode(s);
|
|
180
|
-
}
|
|
181
|
-
function concat(chunks) {
|
|
182
|
-
let total = 0;
|
|
183
|
-
for (const c of chunks) {
|
|
184
|
-
total += c.length;
|
|
185
|
-
}
|
|
186
|
-
const result = new Uint8Array(total);
|
|
187
|
-
let offset = 0;
|
|
188
|
-
for (const c of chunks) {
|
|
189
|
-
result.set(c, offset);
|
|
190
|
-
offset += c.length;
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
function compareBytes(a, b) {
|
|
195
|
-
const min = Math.min(a.length, b.length);
|
|
196
|
-
for (let i = 0; i < min; i++) {
|
|
197
|
-
if (a[i] < b[i])
|
|
198
|
-
return -1;
|
|
199
|
-
if (a[i] > b[i])
|
|
200
|
-
return 1;
|
|
201
|
-
}
|
|
202
|
-
return a.length - b.length;
|
|
17
|
+
/** Computes the SHA-256 fingerprint of Hikoutei's stable encoding. */
|
|
18
|
+
export function stableHash(value) {
|
|
19
|
+
return createHash("sha256").update(stableEncode(value)).digest("hex");
|
|
203
20
|
}
|
|
204
21
|
//# sourceMappingURL=stableEncode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stableEncode.js","sourceRoot":"","sources":["../../../src/shared/encoding/stableEncode.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stableEncode.js","sourceRoot":"","sources":["../../../src/shared/encoding/stableEncode.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAE3E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EACL,gBAAgB,EAChB,YAAY,IAAI,iBAAiB,GAClC,MAAM,kBAAkB,CAAC;AAG1B,kFAAkF;AAClF,MAAM,UAAU,YAAY,CAAC,KAAkB;IAC7C,IAAI,CAAC;QACH,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;YACtC,MAAM,IAAI,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3D,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,UAAU,CAAC,KAAkB;IAC3C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAuB,CAAC;AAC9F,CAAC"}
|
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
* These types are the foundation for cross-runtime fingerprinting and event
|
|
5
5
|
* identity. They contain no Google SDK, SQLite, or platform-specific types.
|
|
6
6
|
*/
|
|
7
|
-
import { NORMALIZED_CELL_KINDS } from "./constants.js";
|
|
8
|
-
import type {
|
|
7
|
+
import { NORMALIZED_CELL_KINDS, type CellObservationKind } from "./constants.js";
|
|
8
|
+
import type { StableCodecDateValue, StableCodecValue } from "@hikoutei/kohkai";
|
|
9
9
|
import type { Presence } from "../state/types.js";
|
|
10
10
|
export type { CellObservationKind, NormalizedCellKind } from "./constants.js";
|
|
11
11
|
/** A date encoded as a fixed-width UTC ISO-8601 string. */
|
|
12
|
-
export
|
|
13
|
-
readonly kind: typeof NORMALIZED_CELL_KINDS.DATE;
|
|
14
|
-
readonly value: string;
|
|
15
|
-
}
|
|
12
|
+
export type DateValue = StableCodecDateValue;
|
|
16
13
|
/**
|
|
17
14
|
* A normalized scalar value that can be deterministically encoded.
|
|
18
15
|
*
|
|
@@ -45,7 +42,5 @@ export interface CellObservation {
|
|
|
45
42
|
* objects with string keys. Objects with `kind: "date"` are encoded as dates,
|
|
46
43
|
* not as plain objects.
|
|
47
44
|
*/
|
|
48
|
-
export type StableValue =
|
|
49
|
-
readonly [key: string]: StableValue;
|
|
50
|
-
};
|
|
45
|
+
export type StableValue = StableCodecValue;
|
|
51
46
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/shared/encoding/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/shared/encoding/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,EACrB,KAAK,mBAAmB,EACzB,MAA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