@anizoptera/uuid-slug 0.2.0
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/LICENSE +181 -0
- package/README.md +65 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +649 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.js +647 -0
- package/dist/web/index.js +648 -0
- package/package.json +68 -0
- package/src/base64url.ts +76 -0
- package/src/codec.ts +218 -0
- package/src/errors.ts +26 -0
- package/src/index.ts +74 -0
- package/src/mask.ts +95 -0
- package/src/runtime/bun.ts +33 -0
- package/src/runtime/node.ts +23 -0
- package/src/runtime/types.ts +12 -0
- package/src/runtime/web.ts +20 -0
- package/src/schema.ts +123 -0
- package/src/types.ts +89 -0
- package/src/uuid.ts +158 -0
- package/src/v7.ts +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Copyright 2026 Anizoptera
|
|
2
|
+
Copyright 2026 Art Shendrik
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or
|
|
44
|
+
Object form, that is based on (or derived from) the Work and for
|
|
45
|
+
which the editorial revisions, annotations, elaborations, or other
|
|
46
|
+
modifications represent, as a whole, an original work of authorship.
|
|
47
|
+
For the purposes of this License, Derivative Works shall not include
|
|
48
|
+
works that remain separable from, or merely link (or bind by name)
|
|
49
|
+
to the interfaces of, the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses granted
|
|
88
|
+
to You under this License for that Work shall terminate as of the date
|
|
89
|
+
such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License.
|
|
120
|
+
|
|
121
|
+
You may add Your own copyright statement to Your modifications and
|
|
122
|
+
may provide additional or different license terms and conditions for
|
|
123
|
+
use, reproduction, or distribution of Your modifications, or for any
|
|
124
|
+
such Derivative Works as a whole, provided Your use, reproduction,
|
|
125
|
+
and distribution of the Work otherwise complies with the conditions
|
|
126
|
+
stated in this License.
|
|
127
|
+
|
|
128
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
129
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
130
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
131
|
+
this License, without any additional terms or conditions.
|
|
132
|
+
|
|
133
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
134
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
135
|
+
except as required for reasonable and customary use in describing the
|
|
136
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
137
|
+
|
|
138
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
139
|
+
to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
140
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
141
|
+
implied, including, without limitation, any warranties or conditions
|
|
142
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
143
|
+
PARTICULAR PURPOSE.
|
|
144
|
+
|
|
145
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
146
|
+
whether in tort, contract, or otherwise, unless required by
|
|
147
|
+
applicable law or agreed to in writing, shall any Contributor be
|
|
148
|
+
liable to You for damages, including any direct, indirect, special,
|
|
149
|
+
incidental, or consequential damages of any character arising as a
|
|
150
|
+
result of this License or out of the use or inability to use the Work.
|
|
151
|
+
|
|
152
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
153
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
154
|
+
charge a fee for, acceptance of support, warranty, indemnity, or
|
|
155
|
+
other liability obligations and/or rights consistent with this
|
|
156
|
+
License. However, in accepting such obligations, You may act only on
|
|
157
|
+
Your own behalf and on Your sole responsibility, not on behalf of any
|
|
158
|
+
other Contributor.
|
|
159
|
+
|
|
160
|
+
END OF TERMS AND CONDITIONS
|
|
161
|
+
|
|
162
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
163
|
+
|
|
164
|
+
To apply the Apache License to your work, attach the following
|
|
165
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
166
|
+
replaced with your own identifying information. The text should be
|
|
167
|
+
enclosed in the appropriate comment syntax for the file format.
|
|
168
|
+
|
|
169
|
+
Copyright [yyyy] [name of copyright owner]
|
|
170
|
+
|
|
171
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
172
|
+
you may not use this file except in compliance with the License.
|
|
173
|
+
You may obtain a copy of the License at
|
|
174
|
+
|
|
175
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
176
|
+
|
|
177
|
+
Unless required by applicable law or agreed to in writing, software
|
|
178
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
179
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
180
|
+
See the License for the specific language governing permissions and
|
|
181
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @anizoptera/uuid-slug
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@anizoptera/uuid-slug)
|
|
4
|
+
[](https://github.com/Anizoptera/uuid-slug/actions/workflows/check.yml)
|
|
5
|
+
[](package.json)
|
|
6
|
+
[](https://bun.sh/docs/cli/test)
|
|
7
|
+
[](package.json)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
|
|
10
|
+
Zero-dependency UUID v4/v7 generation, canonical parsing, 22-character base64url direct slugs, and configurable masked UUIDv7 slugs.
|
|
11
|
+
|
|
12
|
+
This package does not define a new identifier scheme. Direct slugs are the same 16 UUID bytes encoded as unpadded base64url. Masked slugs are reversible obfuscation for textual transmission; they are not encryption, authentication, bearer tokens, or secret material.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @anizoptera/uuid-slug
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createUuidSlugCodec } from "@anizoptera/uuid-slug";
|
|
24
|
+
|
|
25
|
+
export const ids = createUuidSlugCodec({
|
|
26
|
+
mask: { seed: "project-stable-obfuscation-seed" },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const publicId = ids.uuidV7MaskedSlug();
|
|
30
|
+
const uuid = ids.maskedSlugToUuidV7(publicId);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Create one codec per project policy and reuse it. Schema derivation and sentinel maps are precomputed at construction.
|
|
34
|
+
|
|
35
|
+
## Sentinels
|
|
36
|
+
|
|
37
|
+
Sentinels are precomputed per codec and always use direct raw UUID slugs so they stay recognizable in logs and textual transmission.
|
|
38
|
+
|
|
39
|
+
Default sentinels:
|
|
40
|
+
|
|
41
|
+
- `00000000-0000-7000-8000-000000000000` -> `AAAAAAAAcACAAAAAAAAAAA`
|
|
42
|
+
- `00000000-0001-7000-8000-000000000000` -> `AAAAAAABcACAAAAAAAAAAA`
|
|
43
|
+
- `00000000-0002-7000-8000-000000000000` -> `AAAAAAACcACAAAAAAAAAAA`
|
|
44
|
+
|
|
45
|
+
## Runtime
|
|
46
|
+
|
|
47
|
+
- Bun uses `Bun.randomUUIDv7` for v7 string, bytes, and direct slug paths.
|
|
48
|
+
- Node uses native `crypto.randomUUID` for v4 and native `crypto.randomUUIDv7` when present; otherwise it uses the package fallback v7 generator.
|
|
49
|
+
- Browser and Deno use Web Crypto for v4/random bytes and the fallback v7 generator.
|
|
50
|
+
|
|
51
|
+
Runtime dependencies are forbidden. Benchmark candidates are dev-only and excluded from the packed artifact.
|
|
52
|
+
|
|
53
|
+
## Publishing
|
|
54
|
+
|
|
55
|
+
Release checks publish from a cleaned package artifact, not the source tree. The artifact check runs `publish-clean`, blocks private project files and benchmark dependencies, then runs package validators against the final cleaned npm tarball.
|
|
56
|
+
|
|
57
|
+
Use an explicit npm dist-tag:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm run publish:clean
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The project script publishes with `--access public --tag latest --provenance`.
|
|
64
|
+
`@anizoptera/publish-clean` is consumed from npm; regenerate `bun.lock` after
|
|
65
|
+
the first publish-clean release exists on the registry.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
declare const brand: unique symbol;
|
|
3
|
+
type Brand<T, Name extends string> = T & {
|
|
4
|
+
readonly [brand]?: Name;
|
|
5
|
+
};
|
|
6
|
+
type Base64UrlString = Brand<string, "Base64UrlString">;
|
|
7
|
+
type UuidString = Brand<string, "UuidString">;
|
|
8
|
+
type UuidV4String = Brand<UuidString, "UuidV4String">;
|
|
9
|
+
type UuidV7String = Brand<UuidString, "UuidV7String">;
|
|
10
|
+
type UuidSlug = Brand<Base64UrlString, "UuidSlug">;
|
|
11
|
+
type UuidV4Slug = Brand<UuidSlug, "UuidV4Slug">;
|
|
12
|
+
type UuidV7Slug = Brand<UuidSlug, "UuidV7Slug">;
|
|
13
|
+
type MaskedUuidSlug = Brand<UuidSlug, "MaskedUuidSlug">;
|
|
14
|
+
type MaskedUuidV7Slug = Brand<MaskedUuidSlug, "MaskedUuidV7Slug">;
|
|
15
|
+
type SentinelUuidV7Slug = Brand<UuidV7Slug, "SentinelUuidV7Slug">;
|
|
16
|
+
type PublicUuidV7Slug = MaskedUuidV7Slug | SentinelUuidV7Slug;
|
|
17
|
+
type UuidBytes = Brand<Uint8Array, "UuidBytes">;
|
|
18
|
+
interface FreshValidationOptions {
|
|
19
|
+
now?: () => number;
|
|
20
|
+
windowMs?: number;
|
|
21
|
+
}
|
|
22
|
+
interface UuidV7Generator {
|
|
23
|
+
uuidV7(): UuidV7String;
|
|
24
|
+
uuidV7Bytes(out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
interface MaskSchema {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly inverse: Uint8Array;
|
|
29
|
+
readonly permute: Uint8Array;
|
|
30
|
+
readonly tagBits: 4 | 6;
|
|
31
|
+
readonly xor: Uint8Array;
|
|
32
|
+
}
|
|
33
|
+
interface MaskSchemaOptions {
|
|
34
|
+
readonly id?: string;
|
|
35
|
+
readonly seed: string | Uint8Array;
|
|
36
|
+
readonly tagBits?: 4 | 6;
|
|
37
|
+
}
|
|
38
|
+
interface ExplicitMaskSchema {
|
|
39
|
+
readonly id?: string;
|
|
40
|
+
readonly permute: Uint8Array;
|
|
41
|
+
readonly tagBits: 4 | 6;
|
|
42
|
+
readonly xor: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
interface UuidV7SentinelDefinition {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly uuid: UuidV7String;
|
|
47
|
+
}
|
|
48
|
+
interface UuidV7Sentinel {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly slug: SentinelUuidV7Slug;
|
|
51
|
+
readonly uuid: UuidV7String;
|
|
52
|
+
}
|
|
53
|
+
interface UuidSlugCodecOptions {
|
|
54
|
+
readonly generator?: UuidV7Generator;
|
|
55
|
+
readonly legacy?: {
|
|
56
|
+
readonly directDecode?: boolean;
|
|
57
|
+
readonly masks?: readonly MaskSchema[];
|
|
58
|
+
};
|
|
59
|
+
readonly mask?: MaskSchema | MaskSchemaOptions;
|
|
60
|
+
readonly sentinels?: readonly UuidV7SentinelDefinition[];
|
|
61
|
+
}
|
|
62
|
+
interface UuidSlugCodec {
|
|
63
|
+
readonly sentinels: readonly UuidV7Sentinel[];
|
|
64
|
+
uuidV4(): UuidV4String;
|
|
65
|
+
uuidV7(): UuidV7String;
|
|
66
|
+
uuidV4Bytes(out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
67
|
+
uuidV7Bytes(out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
68
|
+
uuidV4Slug(): UuidV4Slug;
|
|
69
|
+
uuidV7Slug(): UuidV7Slug;
|
|
70
|
+
uuidV7MaskedSlug(): MaskedUuidV7Slug;
|
|
71
|
+
uuidToSlug(uuid: string): Error | UuidSlug;
|
|
72
|
+
slugToUuid(slug: string): Error | UuidString;
|
|
73
|
+
uuidToMaskedSlug(uuid: string): Error | MaskedUuidSlug;
|
|
74
|
+
maskedSlugToUuid(slug: string): Error | UuidString;
|
|
75
|
+
uuidV7ToMaskedSlug(uuid: string): Error | PublicUuidV7Slug;
|
|
76
|
+
maskedSlugToUuidV7(slug: string): Error | UuidV7String;
|
|
77
|
+
parseUuid(uuid: string, out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
78
|
+
formatUuid(bytes: Uint8Array, offset?: number): Error | UuidString;
|
|
79
|
+
parseUuidSlug(slug: string, out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
80
|
+
formatUuidSlug(bytes: Uint8Array, offset?: number): Error | UuidSlug;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/base64url.d.ts
|
|
84
|
+
declare function encodeBase64Url(bytes: Uint8Array): Base64UrlString;
|
|
85
|
+
declare function decodeBase64Url(value: string, out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
86
|
+
declare function isBase64Url(value: null | string | undefined): value is Base64UrlString;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/uuid.d.ts
|
|
89
|
+
declare function parseUuid(uuid: string, out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
90
|
+
declare function formatUuid(bytes: Uint8Array, offset?: number): Error | UuidString;
|
|
91
|
+
declare function isUuidString(uuid: null | string | undefined): uuid is UuidString;
|
|
92
|
+
declare function isUuidV4String(uuid: null | string | undefined): uuid is UuidV4String;
|
|
93
|
+
declare function isUuidV7String(uuid: null | string | undefined): uuid is UuidV7String;
|
|
94
|
+
declare function isUuidV7Bytes(bytes: Uint8Array): boolean;
|
|
95
|
+
declare function uuidBytesToSlug(bytes: Uint8Array, offset?: number): Error | UuidSlug;
|
|
96
|
+
declare function slugToUuidBytes(slug: string, out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
97
|
+
declare function uuidToSlug(uuid: string): Error | UuidSlug;
|
|
98
|
+
declare function slugToUuid(slug: string): Error | UuidString;
|
|
99
|
+
declare function formatUuidSlug(bytes: Uint8Array, offset?: number): Error | UuidSlug;
|
|
100
|
+
declare function parseUuidSlug(slug: string, out?: Uint8Array, offset?: number): Error | Uint8Array;
|
|
101
|
+
declare function isUuidSlug(slug: null | string | undefined): slug is UuidSlug;
|
|
102
|
+
declare function isUuidV4Slug(slug: null | string | undefined): slug is UuidV4Slug;
|
|
103
|
+
declare function isUuidV7Slug(slug: null | string | undefined): slug is UuidV7Slug;
|
|
104
|
+
declare function extractUuidV7Timestamp(bytes: Uint8Array, offset?: number): number;
|
|
105
|
+
declare function hasUuidV7Entropy(bytes: Uint8Array, offset?: number): boolean;
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/codec.d.ts
|
|
108
|
+
declare const UUID_V7_SENTINEL_DEFINITIONS: readonly UuidV7SentinelDefinition[];
|
|
109
|
+
declare function createUuidSlugCodec(options?: UuidSlugCodecOptions): UuidSlugCodec;
|
|
110
|
+
declare const defaultCodec: UuidSlugCodec;
|
|
111
|
+
declare function validateUuidV7Fresh(uuid: string, options?: FreshValidationOptions): Error | UuidV7String;
|
|
112
|
+
declare function validateUuidV7SlugFresh(slug: string, options?: FreshValidationOptions): Error | UuidV7Slug;
|
|
113
|
+
declare function validateMaskedUuidV7SlugFresh(slug: string, options?: FreshValidationOptions): Error | MaskedUuidV7Slug;
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/errors.d.ts
|
|
116
|
+
type UuidSlugErrorCode = "invalid_base64url" | "invalid_buffer" | "invalid_mask_schema" | "invalid_uuid" | "invalid_uuid_slug" | "invalid_uuid_version" | "rng_unavailable" | "stale_uuid";
|
|
117
|
+
declare class UuidSlugError extends Error {
|
|
118
|
+
readonly code: UuidSlugErrorCode;
|
|
119
|
+
constructor(code: UuidSlugErrorCode, message: string, options?: ErrorOptions);
|
|
120
|
+
}
|
|
121
|
+
declare class UuidRuntimeError extends UuidSlugError {
|
|
122
|
+
constructor(message: string, options?: ErrorOptions);
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/schema.d.ts
|
|
126
|
+
declare const LEGACY_MASK_SCHEMA_V1: MaskSchema;
|
|
127
|
+
declare function defineMaskSchema(schema: ExplicitMaskSchema): Error | MaskSchema;
|
|
128
|
+
declare function createMaskSchema(options: MaskSchemaOptions): Error | MaskSchema;
|
|
129
|
+
declare const DEFAULT_MASK_SCHEMA: MaskSchema;
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/runtime/types.d.ts
|
|
132
|
+
interface Runtime {
|
|
133
|
+
/**
|
|
134
|
+
* The buffer is pinned to a plain `ArrayBuffer` because Web Crypto's `getRandomValues`
|
|
135
|
+
* rejects a `SharedArrayBuffer` view at runtime, and the unparameterised `Uint8Array`
|
|
136
|
+
* admits one. Narrowing here makes that refusal unrepresentable instead of a throw.
|
|
137
|
+
*/
|
|
138
|
+
fillRandom(bytes: Uint8Array<ArrayBuffer>): void;
|
|
139
|
+
uuidV4?(): string;
|
|
140
|
+
uuidV7?(): string;
|
|
141
|
+
uuidV7Bytes?(out?: Uint8Array, offset?: number): Uint8Array;
|
|
142
|
+
uuidV7Slug?(): string;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/v7.d.ts
|
|
146
|
+
interface UuidV7GeneratorOptions {
|
|
147
|
+
readonly clock?: () => number;
|
|
148
|
+
readonly fillRandom: (bytes: Uint8Array<ArrayBuffer>) => void;
|
|
149
|
+
}
|
|
150
|
+
declare function createUuidV7Generator(options: UuidV7GeneratorOptions): UuidV7Generator;
|
|
151
|
+
declare function createRuntimeGenerator(runtime: Runtime): UuidV7Generator;
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/index.d.ts
|
|
154
|
+
declare const uuidV4: () => UuidV4String;
|
|
155
|
+
declare const uuidV7: () => UuidV7String;
|
|
156
|
+
declare const uuidV4Bytes: (out?: Uint8Array, offset?: number) => Error | Uint8Array;
|
|
157
|
+
declare const uuidV7Bytes: (out?: Uint8Array, offset?: number) => Error | Uint8Array;
|
|
158
|
+
declare const uuidV4Slug: () => UuidV4Slug;
|
|
159
|
+
declare const uuidV7Slug: () => UuidV7Slug;
|
|
160
|
+
declare const uuidV7MaskedSlug: () => MaskedUuidV7Slug;
|
|
161
|
+
declare const uuidToMaskedSlug: (uuid: string) => Error | MaskedUuidSlug;
|
|
162
|
+
declare const maskedSlugToUuid: (slug: string) => Error | UuidString;
|
|
163
|
+
declare const uuidV7ToMaskedSlug: (uuid: string) => Error | PublicUuidV7Slug;
|
|
164
|
+
declare const maskedSlugToUuidV7: (slug: string) => Error | UuidV7String;
|
|
165
|
+
declare const UUID_V7_SENTINELS: readonly UuidV7Sentinel[];
|
|
166
|
+
//#endregion
|
|
167
|
+
export { type Base64UrlString, DEFAULT_MASK_SCHEMA, type ExplicitMaskSchema, type FreshValidationOptions, LEGACY_MASK_SCHEMA_V1, type MaskSchema, type MaskSchemaOptions, type MaskedUuidSlug, type MaskedUuidV7Slug, type PublicUuidV7Slug, type SentinelUuidV7Slug, UUID_V7_SENTINELS, UUID_V7_SENTINEL_DEFINITIONS, type UuidBytes, UuidRuntimeError, type UuidSlug, type UuidSlugCodec, type UuidSlugCodecOptions, UuidSlugError, type UuidString, type UuidV4Slug, type UuidV4String, type UuidV7Generator, type UuidV7Sentinel, type UuidV7SentinelDefinition, type UuidV7Slug, type UuidV7String, createMaskSchema, createRuntimeGenerator, createUuidSlugCodec, createUuidV7Generator, decodeBase64Url, defaultCodec, defineMaskSchema, encodeBase64Url, extractUuidV7Timestamp, formatUuid, formatUuidSlug, hasUuidV7Entropy, isBase64Url, isUuidSlug, isUuidString, isUuidV4Slug, isUuidV4String, isUuidV7Bytes, isUuidV7Slug, isUuidV7String, maskedSlugToUuid, maskedSlugToUuidV7, parseUuid, parseUuidSlug, slugToUuid, slugToUuidBytes, uuidBytesToSlug, uuidToMaskedSlug, uuidToSlug, uuidV4, uuidV4Bytes, uuidV4Slug, uuidV7, uuidV7Bytes, uuidV7MaskedSlug, uuidV7Slug, uuidV7ToMaskedSlug, validateMaskedUuidV7SlugFresh, validateUuidV7Fresh, validateUuidV7SlugFresh };
|
|
168
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/base64url.ts","../src/uuid.ts","../src/codec.ts","../src/errors.ts","../src/schema.ts","../src/runtime/types.ts","../src/v7.ts","../src/index.ts"],"mappings":";cAAc;KAEF,MAAM,GAAG,uBAAuB;YAAgB,SAAS;;KAE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