@seedprotocol/eas 0.7.4-next.784.g879c6a3 → 0.7.4
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/dist/easNames.d.ts +89 -0
- package/dist/easNames.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +179 -131
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names on EAS (ADR 0008).
|
|
3
|
+
*
|
|
4
|
+
* Writing: {@link easName} is the only function that turns a local model or property name into an
|
|
5
|
+
* EAS name (`HTMLPage` → `html_page`). Everything that registers, attests or looks up a schema by
|
|
6
|
+
* name uses it.
|
|
7
|
+
*
|
|
8
|
+
* Reading: an EAS name is never turned back into a local name. It is matched against the local
|
|
9
|
+
* candidates by key, at a {@link NameMatchLevel}:
|
|
10
|
+
*
|
|
11
|
+
* - `exact`: `easName(local) === easName(eas)`.
|
|
12
|
+
* - `normalized`: lowercase alphanumerics only. `html_page`, `htmlpage`, `HTMLPage` and
|
|
13
|
+
* `html-page` are the same; this finds seeds published under older SDKs' names.
|
|
14
|
+
* - `fuzzy`: the normalized key without a trailing plural `s`, and for relations without a
|
|
15
|
+
* trailing `id`/`ids`. `posts` matches `post`, `author_id` matches the relation `author`.
|
|
16
|
+
* No edit distance: `title` never matches `tile`.
|
|
17
|
+
*
|
|
18
|
+
* The tightest tier wins; a tie in the best tier matches nothing.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The EAS name of a local model or property name: words split at lowercase-or-digit to uppercase
|
|
22
|
+
* boundaries and before the last capital of an acronym, every other run of non-alphanumerics
|
|
23
|
+
* turned into `_`, trimmed, lowercased.
|
|
24
|
+
* `HTMLPage → html_page`, `ID3Tag → id3_tag`, `imageV2 → image_v2`, `New model → new_model`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const easName: (name: string) => string;
|
|
27
|
+
export type NameMatchLevel = 'exact' | 'normalized' | 'fuzzy';
|
|
28
|
+
/** How closely two names matched: the tightest level that accepts them. */
|
|
29
|
+
export type NameMatchTier = NameMatchLevel;
|
|
30
|
+
/** The default level (ADR 0008 and the nameMatch design): fuzzy. */
|
|
31
|
+
export declare const DEFAULT_NAME_MATCH_LEVEL: NameMatchLevel;
|
|
32
|
+
/** Lowercase alphanumerics only. */
|
|
33
|
+
export declare const normalizedNameKey: (name: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* The normalized key without a relation's trailing `ids`/`id` (when `relation`), then without a
|
|
36
|
+
* trailing plural `s`. Short keys are left alone, so `ids` and `bus` stay themselves.
|
|
37
|
+
*/
|
|
38
|
+
export declare const fuzzyNameKey: (name: string, options?: {
|
|
39
|
+
relation?: boolean;
|
|
40
|
+
}) => string;
|
|
41
|
+
/**
|
|
42
|
+
* The tightest tier at which a local name and a name from EAS match, or undefined. `relation`
|
|
43
|
+
* says whether the local name is a relation (Relation, Image, File, Html, or a List of them).
|
|
44
|
+
*/
|
|
45
|
+
export declare function nameMatchTier(localName: string, name: string, options?: {
|
|
46
|
+
relation?: boolean;
|
|
47
|
+
}): NameMatchTier | undefined;
|
|
48
|
+
export declare const isNameMatchAllowed: (tier: NameMatchTier, level: NameMatchLevel) => boolean;
|
|
49
|
+
export declare const compareNameMatchTiers: (a: NameMatchTier, b: NameMatchTier) => number;
|
|
50
|
+
export type NameMatchCandidate<T> = {
|
|
51
|
+
value: T;
|
|
52
|
+
/** The local name as it is written to EAS (a list relation's storage name, for instance). */
|
|
53
|
+
name: string;
|
|
54
|
+
relation?: boolean;
|
|
55
|
+
/** This candidate's level. Default {@link DEFAULT_NAME_MATCH_LEVEL}. */
|
|
56
|
+
level?: NameMatchLevel;
|
|
57
|
+
};
|
|
58
|
+
export type NameMatchResult<T> = {
|
|
59
|
+
kind: 'match';
|
|
60
|
+
value: T;
|
|
61
|
+
tier: NameMatchTier;
|
|
62
|
+
} | {
|
|
63
|
+
kind: 'ambiguous';
|
|
64
|
+
values: T[];
|
|
65
|
+
tier: NameMatchTier;
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'none';
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The candidate an EAS name matches: the one in the tightest tier its own level allows. Several
|
|
71
|
+
* candidates in that tier are ambiguous, and match nothing.
|
|
72
|
+
*/
|
|
73
|
+
export declare function matchEasName<T>(name: string, candidates: readonly NameMatchCandidate<T>[]): NameMatchResult<T>;
|
|
74
|
+
/**
|
|
75
|
+
* The local names an EAS name matches in the tightest tier that has any (each name at `level`).
|
|
76
|
+
* Several names can share a tier, e.g. `New model` and `NewModel` for `new_model`: the caller
|
|
77
|
+
* decides whether that's ambiguous (models in different schemas) or the same thing.
|
|
78
|
+
*/
|
|
79
|
+
export declare function localNamesInBestMatchTier(name: string, localNames: Iterable<string>, options?: {
|
|
80
|
+
relation?: boolean;
|
|
81
|
+
level?: NameMatchLevel;
|
|
82
|
+
}): Set<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Names that can match `name` at the normalized level and that an SDK may have written: its EAS
|
|
85
|
+
* name, and what older SDKs published (the simple snake_case: `HTMLPage` → `htmlpage`). For
|
|
86
|
+
* fetching schemas by name; the results are then filtered with {@link matchEasName}.
|
|
87
|
+
*/
|
|
88
|
+
export declare function easNameVariants(name: string): string[];
|
|
89
|
+
//# sourceMappingURL=easNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easNames.d.ts","sourceRoot":"","sources":["../src/easNames.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,MAMrB,CAAA;AAElB,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,YAAY,GAAG,OAAO,CAAA;AAE7D,2EAA2E;AAC3E,MAAM,MAAM,aAAa,GAAG,cAAc,CAAA;AAI1C,oE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AC,EAAE,GAC3C,eAAe,CAAC,CAAC,CAAC,CAgBpB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC5B,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,cAAc,CAAA;CAAO,GAC3D,GAAG,CAAC,MAAM,CAAC,CAeb;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAGtD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from './domainOwnership.js';
|
|
|
6
6
|
export * from './publishAuthorization.js';
|
|
7
7
|
export * from './easPropertyCanonical.js';
|
|
8
8
|
export * from './easRefAttester.js';
|
|
9
|
+
export * from './easNames.js';
|
|
9
10
|
export * from './easRevokedFilter.js';
|
|
10
11
|
export * from './easUid.js';
|
|
11
12
|
export * from './publishedBy.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,8BAA8B,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,YAAY,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,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