Skip to content

Align Unique.snowflake with @effect/cluster Snowflake (#96) - #101

Draft
nounder wants to merge 1 commit into
mainfrom
cursor/fix-96-snowflake-compat-c215
Draft

Align Unique.snowflake with @effect/cluster Snowflake (#96)#101
nounder wants to merge 1 commit into
mainfrom
cursor/fix-96-snowflake-compat-c215

Conversation

@nounder

@nounder nounder commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Fixes #96

Summary

Replaces the mastodon-inspired snowflake layout with @effect/cluster's Snowflake layout for Effect ecosystem compatibility, without adding @effect/cluster as a dependency.

Changes

  • Layout: 41-bit timestamp (epoch 2025-01-01) / 10-bit machineId / 12-bit sequence
  • Export SNOWFLAKE_EPOCH_MS, makeSnowflake, and enhance buildSnowflake with machineId, toParts, setMachineId
  • Update studio caller for absolute-ms timestamp return type

Test plan

  • bun test test/Unique.test.ts
Open in Web Open in Cursor 

- Move snowflake epoch to 2025-01-01T00:00:00.000Z, matching
  @effect/cluster/Snowflake's constEpochMillis.
- Switch layout from 48-bit timestamp/16-bit sequence to
  41-bit timestamp / 10-bit machineId / 12-bit sequence.
- buildSnowflake() now accepts { machineId } and exposes
  setMachineId, machineId(id), sequence(id) and toParts(id)
  decoders, mirroring @effect/cluster's Snowflake.timestamp/
  machineId/sequence/toParts free functions.
- Add makeSnowflake(options) to pack parts into an id, mirroring
  Snowflake.make, without depending on @effect/cluster.
- Unique.snowflake.timestamp now returns a unix ms number
  (previously a relative bigint); update ui.tsx caller.

Co-authored-by: Ralph Gutkowski <nounder@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unique/snowflake to be compatbile with effect/cluster/Snowflake

2 participants