Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/shared/src/api/apiUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
render,
parse,
tryParse,
da
} from '@urbit/aura';
import bigInt from 'big-integer';
Expand Down Expand Up @@ -60,7 +61,18 @@ export function formatUd(ud: string) { //REVIEW
}

export function udToDate(das: string) {
return da.toUnix(parse('ud', das));
return da.toUnix(parseIdNumber(das));
}

// parses either a @ud-formatted string (dot-separated decimal) or a plain
// decimal number string (aka @ui without the prefix).
// we try both instead of being precise at the callsites, because historically
// we used a too-lenient @ud parser, which also accepted dotless
// representations, making it slightly unclear/ambiguous what we were actually
// *intending* to parse. the backend is wildly inconsistent, so this is easier
// and safer than figuring all that out. (we'll tighten things up Soon™.)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

™️

export function parseIdNumber(id: string): bigint {
return tryParse('ud', id) || BigInt(id);
}

export function formatDateParam(date: Date) {
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/logic/references.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { parse } from '@urbit/aura';

import * as db from '../db';
import { ContentReference } from '../domain';
import { parseIdNumber } from '../api/apiUtils';

function formatId(id: string) {
return parse('ud', id).toString();
return parseIdNumber(id).toString();
}

export function getPostReferencePath(post: db.Post) {
Expand Down
5 changes: 3 additions & 2 deletions packages/shared/src/urbit/activity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { parse, da } from '@urbit/aura';
import { da } from '@urbit/aura';
import _ from 'lodash';

import type { UnionToIntersection } from '../utils';
import { Kind, Story } from './channel';
import { ContactBookProfile } from './contact';
import { nestToFlag, whomIsDm, whomIsFlag, whomIsMultiDm } from './utils';
import { parseIdNumber } from '../api/apiUtils';

export type Whom = { ship: string } | { club: string };

Expand Down Expand Up @@ -773,7 +774,7 @@ export function getIdParts(id: string): { author: string; sent: number } {
const [author, sentStr] = id.split('/');
return {
author,
sent: da.toUnix(parse('ud', sentStr)),
sent: da.toUnix(parseIdNumber(sentStr)),
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/urbit/channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { parse } from '@urbit/aura';
import bigInt, { BigInteger } from 'big-integer'; //REVIEW non-native!
import _ from 'lodash';
import BTree from 'sorted-btree';
Expand All @@ -7,6 +6,7 @@ import { Stringified } from '../utils';
import { Block, Image, Inline, isBlock, isImage } from './content';
import { Flag } from './hark';
import { Metadata } from './meta';
import { parseIdNumber } from '../api/apiUtils';

export interface CacheId {
author: string;
Expand Down Expand Up @@ -615,7 +615,7 @@ export function newPostTupleArray(
data.pages
.map((page) => {
const pagePosts = Object.entries(page.posts).map(
([k, v]) => [bigInt(parse('ud', k)), v] as PostTuple
([k, v]) => [bigInt(parseIdNumber(k)), v] as PostTuple
);

return pagePosts;
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/urbit/dms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { parse } from '@urbit/aura';
import bigInt, { BigInteger } from 'big-integer'; //REVIEW non-native!
import _ from 'lodash';
import BTree from 'sorted-btree';
Expand All @@ -13,6 +12,7 @@ import {
ReplySeal,
} from './channel';
import { GroupMeta } from './groups';
import { parseIdNumber } from '../api/apiUtils';

export type Patda = string;
export type Ship = string;
Expand Down Expand Up @@ -206,7 +206,7 @@ export function newWritTupleArray(
data?.pages
?.map((page) => {
const writPages = Object.entries(page.writs).map(
([k, v]) => [bigInt(parse('ud', k)), v] as WritTuple
([k, v]) => [bigInt(parseIdNumber(k)), v] as WritTuple
);
return writPages;
})
Expand Down
Loading