Uses atcute to show how you can do upserts with atproto records

switching computers

+87
+2
.gitignore
···
··· 1 + node_modules 2 + .idea
+17
package.json
···
··· 1 + { 2 + "name": "upsert_example", 3 + "version": "1.0.0", 4 + "description": "", 5 + "type": "module", 6 + "main": "index.js", 7 + "scripts": { 8 + "example:tid": "node ./tid.js" 9 + }, 10 + "keywords": [], 11 + "author": "", 12 + "license": "ISC", 13 + "packageManager": "pnpm@10.16.1", 14 + "dependencies": { 15 + "@atcute/tid": "^1.1.1" 16 + } 17 + }
+50
pnpm-lock.yaml
···
··· 1 + lockfileVersion: '9.0' 2 + 3 + settings: 4 + autoInstallPeers: true 5 + excludeLinksFromLockfile: false 6 + 7 + importers: 8 + 9 + .: 10 + dependencies: 11 + '@atcute/tid': 12 + specifier: ^1.1.1 13 + version: 1.1.1 14 + 15 + packages: 16 + 17 + '@atcute/tid@1.1.1': 18 + resolution: {integrity: sha512-djJ8UGhLkTU5V51yCnBEruMg35qETjWzWy5sJG/2gEOl2Gd7rQWHSaf+yrO6vMS5EFA38U2xOWE3EDUPzvc2ZQ==} 19 + 20 + '@atcute/time-ms@1.0.0': 21 + resolution: {integrity: sha512-iWEOlMBcO3ktB+zQPC2kXka9H/798we+IWq2sjhb+hQJNNfcJrwejzvNi/68Q3jKo/hdfwZjRU9iF8U6D32/2Q==} 22 + 23 + '@types/node@22.19.7': 24 + resolution: {integrity: sha512-MciR4AKGHWl7xwxkBa6xUGxQJ4VBOmPTF7sL+iGzuahOFaO0jHCsuEfS80pan1ef4gWId1oWOweIhrDEYLuaOw==} 25 + 26 + node-gyp-build@4.8.4: 27 + resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==} 28 + hasBin: true 29 + 30 + undici-types@6.21.0: 31 + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} 32 + 33 + snapshots: 34 + 35 + '@atcute/tid@1.1.1': 36 + dependencies: 37 + '@atcute/time-ms': 1.0.0 38 + 39 + '@atcute/time-ms@1.0.0': 40 + dependencies: 41 + '@types/node': 22.19.7 42 + node-gyp-build: 4.8.4 43 + 44 + '@types/node@22.19.7': 45 + dependencies: 46 + undici-types: 6.21.0 47 + 48 + node-gyp-build@4.8.4: {} 49 + 50 + undici-types@6.21.0: {}
+18
tid.js
···
··· 1 + import * as TID from '@atcute/tid'; 2 + 3 + const rightMeow = new Date(); 4 + console.log(`It's ${rightMeow.toLocaleString()} or ${rightMeow.getTime()}`); 5 + 6 + //Tids timestamps are in microseconds. Padding it a bit since we don't need that precision. 7 + const rightNowMicroSeconds = rightMeow * 1000; 8 + //Every TID needs a clock id, can be your favorite number even. 9 + const clockId = 23; 10 + 11 + const rightMeowTid = TID.create(rightNowMicroSeconds, clockId) 12 + console.log(`TID: ${rightMeowTid}`) 13 + const { timestamp} = TID.parse(rightMeowTid) 14 + 15 + //remove the padding 16 + const backToMilliSeconds = timestamp / 1000 17 + const rightNowConvertedBack = new Date(backToMilliSeconds) 18 + console.log(`Converted back: ${rightNowConvertedBack.toLocaleString()} or ${backToMilliSeconds}`)