@structured-id/ids 0.0.0-stage → 0.1.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 +202 -0
- package/NOTICE +14 -0
- package/README.md +67 -2
- package/dist/index.cjs +381 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +353 -0
- package/dist/index.d.ts +353 -0
- package/dist/index.js +368 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -4
- package/schema/sid/v1/ids/ids.proto +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@structured-id/ids
|
|
2
|
+
Copyright (C) Dmitry Prudnikov
|
|
3
|
+
|
|
4
|
+
StructuredID identifiers: checked identifier types, the sid.v1.ids wire
|
|
5
|
+
messages and validated conversions between them. Carries
|
|
6
|
+
schema/sid/v1/ids/ids.proto from the StructuredID proto definitions, also
|
|
7
|
+
distributed under the Apache License, version 2.0.
|
|
8
|
+
|
|
9
|
+
LICENSE
|
|
10
|
+
-------
|
|
11
|
+
This software is distributed under the Apache License, version 2.0. See the
|
|
12
|
+
LICENSE file.
|
|
13
|
+
|
|
14
|
+
Contact: oss@structured.id
|
package/README.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @structured-id/ids
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
StructuredID identifiers for TypeScript: one class per identifier kind
|
|
4
|
+
(`BindingId`, `MachineUserId`, `PasswordOperationId`,
|
|
5
|
+
`ProvisioningConnectorId`, `ProvisioningCredentialId`, `ResourceId`), the
|
|
6
|
+
`sid.v1.ids` wire messages and checked conversions between them.
|
|
7
|
+
|
|
8
|
+
Each identifier is exactly 16 bytes of an RFC 9562 UUIDv7 in network byte
|
|
9
|
+
order. A value of one of these classes is always valid: it is built only
|
|
10
|
+
through validation, which refuses other lengths, the nil and max UUIDs, other
|
|
11
|
+
variants and other versions, naming the reason. Values of different kinds are
|
|
12
|
+
different types, even with equal bytes. A valid identifier proves only its
|
|
13
|
+
shape, not whom it belongs to or what it may do.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @structured-id/ids
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { BindingId, IdError, required, optional, wire } from "@structured-id/ids";
|
|
23
|
+
|
|
24
|
+
// Wire to domain: a decoded message is an untrusted DTO until converted.
|
|
25
|
+
const message = wire.BindingId.fromBinary(bytes);
|
|
26
|
+
const id = required(BindingId, message); // throws MissingIdError or IdError
|
|
27
|
+
|
|
28
|
+
// An optional field keeps absence apart from an invalid value.
|
|
29
|
+
const maybe = optional(BindingId, undefined); // undefined
|
|
30
|
+
|
|
31
|
+
// Domain to wire: the same 16 bytes.
|
|
32
|
+
const encoded = wire.BindingId.toBinary(id.toWire());
|
|
33
|
+
|
|
34
|
+
// Text is for display; the wire carries bytes.
|
|
35
|
+
console.log(id.toString()); // 019290a4-7b3c-7d2e-8f00-112233445566
|
|
36
|
+
BindingId.parse("019290a4-7b3c-7d2e-8f00-112233445566");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`wire` holds the generated messages with their binary and standard ProtoJSON
|
|
40
|
+
codecs (`toJson` / `fromJson`): `bytes` are base64 there, as the ProtoJSON
|
|
41
|
+
mapping defines.
|
|
42
|
+
|
|
43
|
+
Messages of your own that carry an identifier import
|
|
44
|
+
`@structured-id/ids/schema/sid/v1/ids/ids.proto` (`PROTO_PATH` under an
|
|
45
|
+
include root) and use this package's `wire` types for those fields instead of
|
|
46
|
+
generating a second copy.
|
|
47
|
+
|
|
48
|
+
## Corpus
|
|
49
|
+
|
|
50
|
+
`sid/v1/ids/ids.corpus.json` in the
|
|
51
|
+
[proto definitions](https://github.com/structured-id/proto) holds every case
|
|
52
|
+
of the identifier contract for each kind. This package's tests run that file
|
|
53
|
+
unchanged, as the Rust crates `sid-ids` and `sid-ids-proto` do.
|
|
54
|
+
|
|
55
|
+
## Verify
|
|
56
|
+
|
|
57
|
+
From the `typescript/` directory of the SDK repository, with its `proto`
|
|
58
|
+
submodule checked out:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
yarn install
|
|
62
|
+
yarn test
|
|
63
|
+
ci/check-package.sh
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
Apache License, version 2.0. See `LICENSE` and `NOTICE`.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var runtime = require('@protobuf-ts/runtime');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/errors.ts
|
|
12
|
+
function describe(reason) {
|
|
13
|
+
switch (reason.type) {
|
|
14
|
+
case "malformed":
|
|
15
|
+
return "not a UUID";
|
|
16
|
+
case "length":
|
|
17
|
+
return `${reason.length} bytes, expected 16`;
|
|
18
|
+
case "nil":
|
|
19
|
+
return "the nil UUID";
|
|
20
|
+
case "max":
|
|
21
|
+
return "the max UUID";
|
|
22
|
+
case "variant":
|
|
23
|
+
return "not an RFC 4122 UUID";
|
|
24
|
+
case "version":
|
|
25
|
+
return `UUID version ${reason.version}, expected version 7`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
var IdError = class extends Error {
|
|
29
|
+
constructor(kind, reason) {
|
|
30
|
+
super(`invalid ${kind}: ${describe(reason)}`);
|
|
31
|
+
this.kind = kind;
|
|
32
|
+
this.reason = reason;
|
|
33
|
+
}
|
|
34
|
+
kind;
|
|
35
|
+
reason;
|
|
36
|
+
name = "IdError";
|
|
37
|
+
};
|
|
38
|
+
var MissingIdError = class extends Error {
|
|
39
|
+
constructor(kind) {
|
|
40
|
+
super(`missing ${kind}`);
|
|
41
|
+
this.kind = kind;
|
|
42
|
+
}
|
|
43
|
+
kind;
|
|
44
|
+
name = "MissingIdError";
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/validate.ts
|
|
48
|
+
function validate(bytes, kind) {
|
|
49
|
+
if (bytes.length !== 16) {
|
|
50
|
+
throw new IdError(kind, { type: "length", length: bytes.length });
|
|
51
|
+
}
|
|
52
|
+
let zero = true;
|
|
53
|
+
let ones = true;
|
|
54
|
+
for (const byte of bytes) {
|
|
55
|
+
zero &&= byte === 0;
|
|
56
|
+
ones &&= byte === 255;
|
|
57
|
+
}
|
|
58
|
+
if (zero) throw new IdError(kind, { type: "nil" });
|
|
59
|
+
if (ones) throw new IdError(kind, { type: "max" });
|
|
60
|
+
if ((bytes[8] & 192) !== 128) {
|
|
61
|
+
throw new IdError(kind, { type: "variant" });
|
|
62
|
+
}
|
|
63
|
+
const version = bytes[6] >> 4;
|
|
64
|
+
if (version !== 7) throw new IdError(kind, { type: "version", version });
|
|
65
|
+
return bytes.slice();
|
|
66
|
+
}
|
|
67
|
+
var HEX = /^[0-9a-fA-F]{32}$/;
|
|
68
|
+
function parseText(text, kind) {
|
|
69
|
+
let body = text;
|
|
70
|
+
if (body.length === 45 && body.startsWith("urn:uuid:")) {
|
|
71
|
+
body = body.slice(9);
|
|
72
|
+
} else if (body.length === 38 && body.startsWith("{") && body.endsWith("}")) {
|
|
73
|
+
body = body.slice(1, 37);
|
|
74
|
+
}
|
|
75
|
+
let hex;
|
|
76
|
+
if (body.length === 36) {
|
|
77
|
+
if (body[8] !== "-" || body[13] !== "-" || body[18] !== "-" || body[23] !== "-") {
|
|
78
|
+
throw new IdError(kind, { type: "malformed" });
|
|
79
|
+
}
|
|
80
|
+
hex = body.slice(0, 8) + body.slice(9, 13) + body.slice(14, 18) + body.slice(19, 23) + body.slice(24);
|
|
81
|
+
} else if (body.length === 32 && text.length === 32) {
|
|
82
|
+
hex = body;
|
|
83
|
+
} else {
|
|
84
|
+
throw new IdError(kind, { type: "malformed" });
|
|
85
|
+
}
|
|
86
|
+
if (!HEX.test(hex)) throw new IdError(kind, { type: "malformed" });
|
|
87
|
+
const bytes = new Uint8Array(16);
|
|
88
|
+
for (let i = 0; i < 16; i++) {
|
|
89
|
+
bytes[i] = Number.parseInt(hex.slice(2 * i, 2 * i + 2), 16);
|
|
90
|
+
}
|
|
91
|
+
return bytes;
|
|
92
|
+
}
|
|
93
|
+
function formatText(bytes) {
|
|
94
|
+
let hex = "";
|
|
95
|
+
for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
|
|
96
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/ids.ts
|
|
100
|
+
var Identifier = class _Identifier {
|
|
101
|
+
#bytes;
|
|
102
|
+
constructor(bytes) {
|
|
103
|
+
this.#bytes = bytes;
|
|
104
|
+
}
|
|
105
|
+
/** A copy of the 16 bytes in network order: the wire value. */
|
|
106
|
+
toBytes() {
|
|
107
|
+
return this.#bytes.slice();
|
|
108
|
+
}
|
|
109
|
+
/** Lowercase hyphenated text, for display only; the wire carries bytes. */
|
|
110
|
+
toString() {
|
|
111
|
+
return formatText(this.#bytes);
|
|
112
|
+
}
|
|
113
|
+
/** The same text as `toString`, so JSON logs show a readable value. */
|
|
114
|
+
toJSON() {
|
|
115
|
+
return this.toString();
|
|
116
|
+
}
|
|
117
|
+
/** True for an identifier of the same kind with the same bytes. */
|
|
118
|
+
equals(other) {
|
|
119
|
+
if (!(other instanceof _Identifier) || other.kind !== this.kind) return false;
|
|
120
|
+
const theirs = other.#bytes;
|
|
121
|
+
return this.#bytes.every((byte, i) => byte === theirs[i]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var BindingId = class _BindingId extends Identifier {
|
|
125
|
+
static kind = "BindingId";
|
|
126
|
+
kind = "BindingId";
|
|
127
|
+
constructor(bytes) {
|
|
128
|
+
super(bytes);
|
|
129
|
+
}
|
|
130
|
+
/** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
|
|
131
|
+
static fromBytes(bytes) {
|
|
132
|
+
return new _BindingId(validate(bytes, _BindingId.kind));
|
|
133
|
+
}
|
|
134
|
+
/** Accept a textual UUID as this identifier, or throw `IdError`. */
|
|
135
|
+
static parse(text) {
|
|
136
|
+
return _BindingId.fromBytes(parseText(text, _BindingId.kind));
|
|
137
|
+
}
|
|
138
|
+
/** Validate a decoded wire message; throws `IdError`. */
|
|
139
|
+
static fromWire(message) {
|
|
140
|
+
return _BindingId.fromBytes(message.value);
|
|
141
|
+
}
|
|
142
|
+
/** The wire message carrying this identifier's bytes. */
|
|
143
|
+
toWire() {
|
|
144
|
+
return { value: this.toBytes() };
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var MachineUserId = class _MachineUserId extends Identifier {
|
|
148
|
+
static kind = "MachineUserId";
|
|
149
|
+
kind = "MachineUserId";
|
|
150
|
+
constructor(bytes) {
|
|
151
|
+
super(bytes);
|
|
152
|
+
}
|
|
153
|
+
/** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
|
|
154
|
+
static fromBytes(bytes) {
|
|
155
|
+
return new _MachineUserId(validate(bytes, _MachineUserId.kind));
|
|
156
|
+
}
|
|
157
|
+
/** Accept a textual UUID as this identifier, or throw `IdError`. */
|
|
158
|
+
static parse(text) {
|
|
159
|
+
return _MachineUserId.fromBytes(parseText(text, _MachineUserId.kind));
|
|
160
|
+
}
|
|
161
|
+
/** Validate a decoded wire message; throws `IdError`. */
|
|
162
|
+
static fromWire(message) {
|
|
163
|
+
return _MachineUserId.fromBytes(message.value);
|
|
164
|
+
}
|
|
165
|
+
/** The wire message carrying this identifier's bytes. */
|
|
166
|
+
toWire() {
|
|
167
|
+
return { value: this.toBytes() };
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var PasswordOperationId = class _PasswordOperationId extends Identifier {
|
|
171
|
+
static kind = "PasswordOperationId";
|
|
172
|
+
kind = "PasswordOperationId";
|
|
173
|
+
constructor(bytes) {
|
|
174
|
+
super(bytes);
|
|
175
|
+
}
|
|
176
|
+
/** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
|
|
177
|
+
static fromBytes(bytes) {
|
|
178
|
+
return new _PasswordOperationId(validate(bytes, _PasswordOperationId.kind));
|
|
179
|
+
}
|
|
180
|
+
/** Accept a textual UUID as this identifier, or throw `IdError`. */
|
|
181
|
+
static parse(text) {
|
|
182
|
+
return _PasswordOperationId.fromBytes(parseText(text, _PasswordOperationId.kind));
|
|
183
|
+
}
|
|
184
|
+
/** Validate a decoded wire message; throws `IdError`. */
|
|
185
|
+
static fromWire(message) {
|
|
186
|
+
return _PasswordOperationId.fromBytes(message.value);
|
|
187
|
+
}
|
|
188
|
+
/** The wire message carrying this identifier's bytes. */
|
|
189
|
+
toWire() {
|
|
190
|
+
return { value: this.toBytes() };
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var ProvisioningConnectorId = class _ProvisioningConnectorId extends Identifier {
|
|
194
|
+
static kind = "ProvisioningConnectorId";
|
|
195
|
+
kind = "ProvisioningConnectorId";
|
|
196
|
+
constructor(bytes) {
|
|
197
|
+
super(bytes);
|
|
198
|
+
}
|
|
199
|
+
/** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
|
|
200
|
+
static fromBytes(bytes) {
|
|
201
|
+
return new _ProvisioningConnectorId(validate(bytes, _ProvisioningConnectorId.kind));
|
|
202
|
+
}
|
|
203
|
+
/** Accept a textual UUID as this identifier, or throw `IdError`. */
|
|
204
|
+
static parse(text) {
|
|
205
|
+
return _ProvisioningConnectorId.fromBytes(parseText(text, _ProvisioningConnectorId.kind));
|
|
206
|
+
}
|
|
207
|
+
/** Validate a decoded wire message; throws `IdError`. */
|
|
208
|
+
static fromWire(message) {
|
|
209
|
+
return _ProvisioningConnectorId.fromBytes(message.value);
|
|
210
|
+
}
|
|
211
|
+
/** The wire message carrying this identifier's bytes. */
|
|
212
|
+
toWire() {
|
|
213
|
+
return { value: this.toBytes() };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var ProvisioningCredentialId = class _ProvisioningCredentialId extends Identifier {
|
|
217
|
+
static kind = "ProvisioningCredentialId";
|
|
218
|
+
kind = "ProvisioningCredentialId";
|
|
219
|
+
constructor(bytes) {
|
|
220
|
+
super(bytes);
|
|
221
|
+
}
|
|
222
|
+
/** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
|
|
223
|
+
static fromBytes(bytes) {
|
|
224
|
+
return new _ProvisioningCredentialId(validate(bytes, _ProvisioningCredentialId.kind));
|
|
225
|
+
}
|
|
226
|
+
/** Accept a textual UUID as this identifier, or throw `IdError`. */
|
|
227
|
+
static parse(text) {
|
|
228
|
+
return _ProvisioningCredentialId.fromBytes(parseText(text, _ProvisioningCredentialId.kind));
|
|
229
|
+
}
|
|
230
|
+
/** Validate a decoded wire message; throws `IdError`. */
|
|
231
|
+
static fromWire(message) {
|
|
232
|
+
return _ProvisioningCredentialId.fromBytes(message.value);
|
|
233
|
+
}
|
|
234
|
+
/** The wire message carrying this identifier's bytes. */
|
|
235
|
+
toWire() {
|
|
236
|
+
return { value: this.toBytes() };
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var ResourceId = class _ResourceId extends Identifier {
|
|
240
|
+
static kind = "ResourceId";
|
|
241
|
+
kind = "ResourceId";
|
|
242
|
+
constructor(bytes) {
|
|
243
|
+
super(bytes);
|
|
244
|
+
}
|
|
245
|
+
/** Accept 16 bytes as this identifier, or throw `IdError` saying why not. */
|
|
246
|
+
static fromBytes(bytes) {
|
|
247
|
+
return new _ResourceId(validate(bytes, _ResourceId.kind));
|
|
248
|
+
}
|
|
249
|
+
/** Accept a textual UUID as this identifier, or throw `IdError`. */
|
|
250
|
+
static parse(text) {
|
|
251
|
+
return _ResourceId.fromBytes(parseText(text, _ResourceId.kind));
|
|
252
|
+
}
|
|
253
|
+
/** Validate a decoded wire message; throws `IdError`. */
|
|
254
|
+
static fromWire(message) {
|
|
255
|
+
return _ResourceId.fromBytes(message.value);
|
|
256
|
+
}
|
|
257
|
+
/** The wire message carrying this identifier's bytes. */
|
|
258
|
+
toWire() {
|
|
259
|
+
return { value: this.toBytes() };
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
function required(type, message) {
|
|
263
|
+
if (message === void 0) throw new MissingIdError(type.kind);
|
|
264
|
+
return type.fromWire(message);
|
|
265
|
+
}
|
|
266
|
+
function optional(type, message) {
|
|
267
|
+
return message === void 0 ? void 0 : type.fromWire(message);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/generated/sid/v1/ids/ids.ts
|
|
271
|
+
var ids_exports = {};
|
|
272
|
+
__export(ids_exports, {
|
|
273
|
+
BindingId: () => BindingId2,
|
|
274
|
+
MachineUserId: () => MachineUserId2,
|
|
275
|
+
PasswordOperationId: () => PasswordOperationId2,
|
|
276
|
+
ProvisioningConnectorId: () => ProvisioningConnectorId2,
|
|
277
|
+
ProvisioningCredentialId: () => ProvisioningCredentialId2,
|
|
278
|
+
ResourceId: () => ResourceId2
|
|
279
|
+
});
|
|
280
|
+
var BindingId$Type = class extends runtime.MessageType {
|
|
281
|
+
constructor() {
|
|
282
|
+
super("sid.v1.ids.BindingId", [
|
|
283
|
+
{
|
|
284
|
+
no: 1,
|
|
285
|
+
name: "value",
|
|
286
|
+
kind: "scalar",
|
|
287
|
+
T: 12
|
|
288
|
+
/*ScalarType.BYTES*/
|
|
289
|
+
}
|
|
290
|
+
]);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
var BindingId2 = new BindingId$Type();
|
|
294
|
+
var PasswordOperationId$Type = class extends runtime.MessageType {
|
|
295
|
+
constructor() {
|
|
296
|
+
super("sid.v1.ids.PasswordOperationId", [
|
|
297
|
+
{
|
|
298
|
+
no: 1,
|
|
299
|
+
name: "value",
|
|
300
|
+
kind: "scalar",
|
|
301
|
+
T: 12
|
|
302
|
+
/*ScalarType.BYTES*/
|
|
303
|
+
}
|
|
304
|
+
]);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
var PasswordOperationId2 = new PasswordOperationId$Type();
|
|
308
|
+
var MachineUserId$Type = class extends runtime.MessageType {
|
|
309
|
+
constructor() {
|
|
310
|
+
super("sid.v1.ids.MachineUserId", [
|
|
311
|
+
{
|
|
312
|
+
no: 1,
|
|
313
|
+
name: "value",
|
|
314
|
+
kind: "scalar",
|
|
315
|
+
T: 12
|
|
316
|
+
/*ScalarType.BYTES*/
|
|
317
|
+
}
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var MachineUserId2 = new MachineUserId$Type();
|
|
322
|
+
var ProvisioningConnectorId$Type = class extends runtime.MessageType {
|
|
323
|
+
constructor() {
|
|
324
|
+
super("sid.v1.ids.ProvisioningConnectorId", [
|
|
325
|
+
{
|
|
326
|
+
no: 1,
|
|
327
|
+
name: "value",
|
|
328
|
+
kind: "scalar",
|
|
329
|
+
T: 12
|
|
330
|
+
/*ScalarType.BYTES*/
|
|
331
|
+
}
|
|
332
|
+
]);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var ProvisioningConnectorId2 = new ProvisioningConnectorId$Type();
|
|
336
|
+
var ResourceId$Type = class extends runtime.MessageType {
|
|
337
|
+
constructor() {
|
|
338
|
+
super("sid.v1.ids.ResourceId", [
|
|
339
|
+
{
|
|
340
|
+
no: 1,
|
|
341
|
+
name: "value",
|
|
342
|
+
kind: "scalar",
|
|
343
|
+
T: 12
|
|
344
|
+
/*ScalarType.BYTES*/
|
|
345
|
+
}
|
|
346
|
+
]);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
var ResourceId2 = new ResourceId$Type();
|
|
350
|
+
var ProvisioningCredentialId$Type = class extends runtime.MessageType {
|
|
351
|
+
constructor() {
|
|
352
|
+
super("sid.v1.ids.ProvisioningCredentialId", [
|
|
353
|
+
{
|
|
354
|
+
no: 1,
|
|
355
|
+
name: "value",
|
|
356
|
+
kind: "scalar",
|
|
357
|
+
T: 12
|
|
358
|
+
/*ScalarType.BYTES*/
|
|
359
|
+
}
|
|
360
|
+
]);
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
var ProvisioningCredentialId2 = new ProvisioningCredentialId$Type();
|
|
364
|
+
|
|
365
|
+
// src/index.ts
|
|
366
|
+
var PROTO_PATH = "sid/v1/ids/ids.proto";
|
|
367
|
+
|
|
368
|
+
exports.BindingId = BindingId;
|
|
369
|
+
exports.IdError = IdError;
|
|
370
|
+
exports.MachineUserId = MachineUserId;
|
|
371
|
+
exports.MissingIdError = MissingIdError;
|
|
372
|
+
exports.PROTO_PATH = PROTO_PATH;
|
|
373
|
+
exports.PasswordOperationId = PasswordOperationId;
|
|
374
|
+
exports.ProvisioningConnectorId = ProvisioningConnectorId;
|
|
375
|
+
exports.ProvisioningCredentialId = ProvisioningCredentialId;
|
|
376
|
+
exports.ResourceId = ResourceId;
|
|
377
|
+
exports.optional = optional;
|
|
378
|
+
exports.required = required;
|
|
379
|
+
exports.wire = ids_exports;
|
|
380
|
+
//# sourceMappingURL=index.cjs.map
|
|
381
|
+
//# sourceMappingURL=index.cjs.map
|