Update AtUri import to use official package with fix for usernames that start with numbers (close #414) (#418)

zio/stable
Paul Frazee 2023-04-07 10:30:58 -05:00 committed by GitHub
parent b84533090d
commit 4b98992257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 17 additions and 181 deletions

View File

@ -21,7 +21,7 @@
"e2e:run": "detox test --configuration ios.sim.debug --take-screenshots all" "e2e:run": "detox test --configuration ios.sim.debug --take-screenshots all"
}, },
"dependencies": { "dependencies": {
"@atproto/api": "0.2.4", "@atproto/api": "0.2.5",
"@bam.tech/react-native-image-resizer": "^3.0.4", "@bam.tech/react-native-image-resizer": "^3.0.4",
"@expo/webpack-config": "^18.0.1", "@expo/webpack-config": "^18.0.1",
"@fortawesome/fontawesome-svg-core": "^6.1.1", "@fortawesome/fontawesome-svg-core": "^6.1.1",

View File

@ -6,7 +6,7 @@ import {
ComAtprotoRepoUploadBlob, ComAtprotoRepoUploadBlob,
RichText, RichText,
} from '@atproto/api' } from '@atproto/api'
import {AtUri} from '../../third-party/uri' import {AtUri} from '@atproto/api'
import {RootStoreModel} from 'state/models/root-store' import {RootStoreModel} from 'state/models/root-store'
import {isNetworkError} from 'lib/strings/errors' import {isNetworkError} from 'lib/strings/errors'
import {LinkMeta} from '../link-meta/link-meta' import {LinkMeta} from '../link-meta/link-meta'

View File

@ -1,4 +1,4 @@
import {AtUri} from '../../third-party/uri' import {AtUri} from '@atproto/api'
import {PROD_SERVICE} from 'state/index' import {PROD_SERVICE} from 'state/index'
import TLDs from 'tlds' import TLDs from 'tlds'

View File

@ -5,7 +5,7 @@ import {
AppBskyFeedDefs, AppBskyFeedDefs,
RichText, RichText,
} from '@atproto/api' } from '@atproto/api'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import {RootStoreModel} from '../root-store' import {RootStoreModel} from '../root-store'
import * as apilib from 'lib/api/index' import * as apilib from 'lib/api/index'
import {cleanError} from 'lib/strings/errors' import {cleanError} from 'lib/strings/errors'

View File

@ -1,6 +1,6 @@
import {makeAutoObservable} from 'mobx' import {makeAutoObservable} from 'mobx'
import {AppBskyFeedPost as Post} from '@atproto/api' import {AppBskyFeedPost as Post} from '@atproto/api'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import {RootStoreModel} from '../root-store' import {RootStoreModel} from '../root-store'
import {cleanError} from 'lib/strings/errors' import {cleanError} from 'lib/strings/errors'

View File

@ -1,5 +1,5 @@
import {makeAutoObservable, runInAction} from 'mobx' import {makeAutoObservable, runInAction} from 'mobx'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import {AppBskyFeedGetLikes as GetLikes} from '@atproto/api' import {AppBskyFeedGetLikes as GetLikes} from '@atproto/api'
import {RootStoreModel} from '../root-store' import {RootStoreModel} from '../root-store'
import {cleanError} from 'lib/strings/errors' import {cleanError} from 'lib/strings/errors'

View File

@ -1,5 +1,5 @@
import {makeAutoObservable, runInAction} from 'mobx' import {makeAutoObservable, runInAction} from 'mobx'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import { import {
AppBskyFeedGetRepostedBy as GetRepostedBy, AppBskyFeedGetRepostedBy as GetRepostedBy,
AppBskyActorDefs, AppBskyActorDefs,

View File

@ -1,136 +0,0 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
ATP_URI_REGEX: () => ATP_URI_REGEX,
AtUri: () => AtUri
});
module.exports = __toCommonJS(src_exports);
var ATP_URI_REGEX = /^(at:\/\/)?((?:did:[a-z0-9:%-]+)|(?:[a-z][a-z0-9.:-]*))(\/[^?#\s]*)?(\?[^#\s]+)?(#[^\s]+)?$/i;
var RELATIVE_REGEX = /^(\/[^?#\s]*)?(\?[^#\s]+)?(#[^\s]+)?$/i;
var AtUri = class {
constructor(uri, base) {
let parsed;
if (base) {
parsed = parse(base);
if (!parsed) {
throw new Error(`Invalid at uri: ${base}`);
}
const relativep = parseRelative(uri);
if (!relativep) {
throw new Error(`Invalid path: ${uri}`);
}
Object.assign(parsed, relativep);
} else {
parsed = parse(uri);
if (!parsed) {
throw new Error(`Invalid at uri: ${uri}`);
}
}
this.hash = parsed.hash;
this.host = parsed.host;
this.pathname = parsed.pathname;
this.searchParams = parsed.searchParams;
}
get protocol() {
return "at:";
}
get origin() {
return `at://${this.host}`;
}
get hostname() {
return this.host;
}
set hostname(v) {
this.host = v;
}
get search() {
return this.searchParams.toString();
}
set search(v) {
this.searchParams = new URLSearchParams(v);
}
get collection() {
return this.pathname.split("/").filter(Boolean)[0] || "";
}
set collection(v) {
const parts = this.pathname.split("/").filter(Boolean);
parts[0] = v;
this.pathname = parts.join("/");
}
get rkey() {
return this.pathname.split("/").filter(Boolean)[1] || "";
}
set rkey(v) {
const parts = this.pathname.split("/").filter(Boolean);
if (!parts[0])
parts[0] = "undefined";
parts[1] = v;
this.pathname = parts.join("/");
}
get href() {
return this.toString();
}
toString() {
let path = this.pathname || "/";
if (!path.startsWith("/")) {
path = `/${path}`;
}
let qs = this.searchParams.toString();
if (qs && !qs.startsWith("?")) {
qs = `?${qs}`;
}
let hash = this.hash;
if (hash && !hash.startsWith("#")) {
hash = `#${hash}`;
}
return `at://${this.host}${path}${qs}${hash}`;
}
};
function parse(str) {
const match = ATP_URI_REGEX.exec(str);
if (match) {
return {
hash: match[5] || "",
host: match[2] || "",
pathname: match[3] || "",
searchParams: new URLSearchParams(match[4] || "")
};
}
return void 0;
}
function parseRelative(str) {
const match = RELATIVE_REGEX.exec(str);
if (match) {
return {
hash: match[3] || "",
pathname: match[1] || "",
searchParams: new URLSearchParams(match[2] || "")
};
}
return void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ATP_URI_REGEX,
AtUri
});
//# sourceMappingURL=index.js.map

View File

@ -1,7 +0,0 @@
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["export const ATP_URI_REGEX =\n // proto- --did-------------- --name------------- --path---- --query-- --hash--\n /^(at:\\/\\/)?((?:did:[a-z0-9:%-]+)|(?:[a-z][a-z0-9.:-]*))(\\/[^?#\\s]*)?(\\?[^#\\s]+)?(#[^\\s]+)?$/i\n// --path----- --query-- --hash--\nconst RELATIVE_REGEX = /^(\\/[^?#\\s]*)?(\\?[^#\\s]+)?(#[^\\s]+)?$/i\n\nexport class AtUri {\n hash: string\n host: string\n pathname: string\n searchParams: URLSearchParams\n\n constructor(uri: string, base?: string) {\n let parsed\n if (base) {\n parsed = parse(base)\n if (!parsed) {\n throw new Error(`Invalid at uri: ${base}`)\n }\n const relativep = parseRelative(uri)\n if (!relativep) {\n throw new Error(`Invalid path: ${uri}`)\n }\n Object.assign(parsed, relativep)\n } else {\n parsed = parse(uri)\n if (!parsed) {\n throw new Error(`Invalid at uri: ${uri}`)\n }\n }\n\n this.hash = parsed.hash\n this.host = parsed.host\n this.pathname = parsed.pathname\n this.searchParams = parsed.searchParams\n }\n\n get protocol() {\n return 'at:'\n }\n\n get origin() {\n return `at://${this.host}`\n }\n\n get hostname() {\n return this.host\n }\n\n set hostname(v: string) {\n this.host = v\n }\n\n get search() {\n return this.searchParams.toString()\n }\n\n set search(v: string) {\n this.searchParams = new URLSearchParams(v)\n }\n\n get collection() {\n return this.pathname.split('/').filter(Boolean)[0] || ''\n }\n\n set collection(v: string) {\n const parts = this.pathname.split('/').filter(Boolean)\n parts[0] = v\n this.pathname = parts.join('/')\n }\n\n get rkey() {\n return this.pathname.split('/').filter(Boolean)[1] || ''\n }\n\n set rkey(v: string) {\n const parts = this.pathname.split('/').filter(Boolean)\n if (!parts[0]) parts[0] = 'undefined'\n parts[1] = v\n this.pathname = parts.join('/')\n }\n\n get href() {\n return this.toString()\n }\n\n toString() {\n let path = this.pathname || '/'\n if (!path.startsWith('/')) {\n path = `/${path}`\n }\n let qs = this.searchParams.toString()\n if (qs && !qs.startsWith('?')) {\n qs = `?${qs}`\n }\n let hash = this.hash\n if (hash && !hash.startsWith('#')) {\n hash = `#${hash}`\n }\n return `at://${this.host}${path}${qs}${hash}`\n }\n}\n\nfunction parse(str: string) {\n const match = ATP_URI_REGEX.exec(str)\n if (match) {\n return {\n hash: match[5] || '',\n host: match[2] || '',\n pathname: match[3] || '',\n searchParams: new URLSearchParams(match[4] || ''),\n }\n }\n return undefined\n}\n\nfunction parseRelative(str: string) {\n const match = RELATIVE_REGEX.exec(str)\n if (match) {\n return {\n hash: match[3] || '',\n pathname: match[1] || '',\n searchParams: new URLSearchParams(match[2] || ''),\n }\n }\n return undefined\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,gBAEX;AAEF,IAAM,iBAAiB;AAEhB,IAAM,QAAN,MAAY;AAAA,EAMjB,YAAY,KAAa,MAAe;AACtC,QAAI;AACJ,QAAI,MAAM;AACR,eAAS,MAAM,IAAI;AACnB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,mBAAmB,MAAM;AAAA,MAC3C;AACA,YAAM,YAAY,cAAc,GAAG;AACnC,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,iBAAiB,KAAK;AAAA,MACxC;AACA,aAAO,OAAO,QAAQ,SAAS;AAAA,IACjC,OAAO;AACL,eAAS,MAAM,GAAG;AAClB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,mBAAmB,KAAK;AAAA,MAC1C;AAAA,IACF;A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AAa,SAAS;AACpC,QAAI,MAAM,CAAC,GAAG,WAAW,GAAG,GAAG;AAC7B,WAAK,IAAI;AAAA,IACX;AACA,QAAI,OAAO,KAAK;AAChB,QAAI,QAAQ,CAAC,KAAK,WAAW,GAAG,GAAG;AACjC,aAAO,IAAI;AAAA,IACb;AACA,WAAO,QAAQ,KAAK,OAAO,OAAO,KAAK;AAAA,EACzC;AACF;AAEA,SAAS,MAAM,KAAa;AAC1B,QAAM,QAAQ,cAAc,KAAK,GAAG;AACpC,MAAI,OAAO;AACT,WAAO;AAAA,MACL,MAAM,MAAM,MAAM;AAAA,MAClB,MAAM,MAAM,MAAM;AAAA,MAClB,UAAU,MAAM,MAAM;AAAA,MACtB,cAAc,IAAI,gBAAgB,MAAM,MAAM,EAAE;AAAA,IAClD;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,cAAc,KAAa;AAClC,QAAM,QAAQ,eAAe,KAAK,GAAG;AACrC,MAAI,OAAO;AACT,WAAO;AAAA,MACL,MAAM,MAAM,MAAM;AAAA,MAClB,UAAU,MAAM,MAAM;AAAA,MACtB,cAAc,IAAI,gBAAgB,MAAM,MAAM,EAAE;AAAA,IAClD;AAAA,EACF;AACA,SAAO;AACT;",
"names": []
}

View File

@ -1,20 +0,0 @@
export declare const ATP_URI_REGEX: RegExp;
export declare class AtUri {
hash: string;
host: string;
pathname: string;
searchParams: URLSearchParams;
constructor(uri: string, base?: string);
get protocol(): string;
get origin(): string;
get hostname(): string;
set hostname(v: string);
get search(): string;
set search(v: string);
get collection(): string;
set collection(v: string);
get rkey(): string;
set rkey(v: string);
get href(): string;
toString(): string;
}

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@ import {
View, View,
} from 'react-native' } from 'react-native'
import {AppBskyEmbedImages} from '@atproto/api' import {AppBskyEmbedImages} from '@atproto/api'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import { import {
FontAwesomeIcon, FontAwesomeIcon,
FontAwesomeIconStyle, FontAwesomeIconStyle,

View File

@ -2,7 +2,7 @@ import React from 'react'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import {Linking, StyleSheet, View} from 'react-native' import {Linking, StyleSheet, View} from 'react-native'
import Clipboard from '@react-native-clipboard/clipboard' import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import { import {
FontAwesomeIcon, FontAwesomeIcon,
FontAwesomeIconStyle, FontAwesomeIconStyle,

View File

@ -9,7 +9,7 @@ import {
} from 'react-native' } from 'react-native'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import Clipboard from '@react-native-clipboard/clipboard' import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {PostThreadModel} from 'state/models/content/post-thread' import {PostThreadModel} from 'state/models/content/post-thread'
import {Link} from '../util/Link' import {Link} from '../util/Link'

View File

@ -2,7 +2,7 @@ import React, {useMemo, useState} from 'react'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import {Linking, StyleSheet, View} from 'react-native' import {Linking, StyleSheet, View} from 'react-native'
import Clipboard from '@react-native-clipboard/clipboard' import Clipboard from '@react-native-clipboard/clipboard'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import { import {
FontAwesomeIcon, FontAwesomeIcon,
FontAwesomeIconStyle, FontAwesomeIconStyle,

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import {StyleSheet, View} from 'react-native' import {StyleSheet, View} from 'react-native'
import {PostsFeedSliceModel} from 'state/models/feeds/posts' import {PostsFeedSliceModel} from 'state/models/feeds/posts'
import {AtUri} from '../../../third-party/uri' import {AtUri} from '@atproto/api'
import {Link} from '../util/Link' import {Link} from '../util/Link'
import {Text} from '../util/text/Text' import {Text} from '../util/text/Text'
import Svg, {Circle, Line} from 'react-native-svg' import Svg, {Circle, Line} from 'react-native-svg'

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import {StyleProp, StyleSheet, ViewStyle} from 'react-native' import {StyleProp, StyleSheet, ViewStyle} from 'react-native'
import {AppBskyEmbedImages, AppBskyEmbedRecordWithMedia} from '@atproto/api' import {AppBskyEmbedImages, AppBskyEmbedRecordWithMedia} from '@atproto/api'
import {AtUri} from '../../../../third-party/uri' import {AtUri} from '@atproto/api'
import {PostMeta} from '../PostMeta' import {PostMeta} from '../PostMeta'
import {Link} from '../Link' import {Link} from '../Link'
import {Text} from '../text/Text' import {Text} from '../text/Text'

View File

@ -30,10 +30,10 @@
tlds "^1.234.0" tlds "^1.234.0"
typed-emitter "^2.1.0" typed-emitter "^2.1.0"
"@atproto/api@0.2.4": "@atproto/api@0.2.5":
version "0.2.4" version "0.2.5"
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.2.4.tgz#0a14af4f37aa665bd70a1b5f9f5d31db02313ad9" resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.2.5.tgz#24375497351469a522497c7f92016d0b4233a172"
integrity sha512-EOegRw4/TaN8Px9M/rPiWQlqIkN+QXeU3Y8NUFofqgApPiatmayiYpQiR0iBhZmFnlYFuRt6tLQBjPypI/dvfA== integrity sha512-RJGhiwj6kOjrlVy7ES/SfJt3JyFwXdFZeBP4iw2ne/Ie0ZlanKhY0y9QHx5tI4rvEUP/wf0iKtaq2neczHi3bg==
dependencies: dependencies:
"@atproto/common-web" "*" "@atproto/common-web" "*"
"@atproto/uri" "*" "@atproto/uri" "*"