@azure-net/node-kit 0.1.0 → 0.1.2

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/VALIDATION.md CHANGED
@@ -726,6 +726,7 @@ existence, ownership, authenticity, allocation, or reachability checks.
726
726
  | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
727
727
  | `email(o?)` | ASCII dot-atom local part up to 64 characters, dotted DNS domain, total up to 254; not all RFC 5322 mailboxes, no quoted local parts or deliverability check |
728
728
  | `uuid(o?)` | RFC 9562 versions 1-8; `UuidOptions.version` restricts version; unrestricted also accepts Nil/Max UUIDs; case-insensitive |
729
+ | `nonEmptyUuid(o?)` | Like `uuid`, but rejects `00000000-0000-0000-0000-000000000000`; accepts `UuidOptions`, including version and custom message. |
729
730
  | `guid(o?)` | Hyphenated `8-4-4-4-12` hex shape without UUID version/variant constraints |
730
731
  | `url(o?)` | Absolute WHATWG URL, including non-HTTP schemes; `UrlOptions.protocol`/`hostname` RegExp filters |
731
732
  | `httpUrl(o?)` | HTTP/HTTPS with explicit `://` and hostname; same URL filters; localhost/IPs can pass |
@@ -11,9 +11,9 @@ export interface EnvParseOptions<T> extends EnvGetOptions {
11
11
  parse: (context: EnvParseContext) => T;
12
12
  }
13
13
  /** Reads the supplied object on each get; never reads process.env implicitly. */
14
- export declare class Env {
14
+ export declare class Env<TKey extends string = string> {
15
15
  private readonly values;
16
16
  constructor(values: EnvValues);
17
- get<T>(name: string, options: EnvParseOptions<T>): T;
18
- get(name: string, options?: EnvGetOptions): string;
17
+ get<T>(name: TKey, options: EnvParseOptions<T>): T;
18
+ get(name: TKey, options?: EnvGetOptions): string;
19
19
  }
@@ -84,6 +84,7 @@ export const validationMessagesEn = Object.freeze({
84
84
  uppercase: "Must be uppercase.",
85
85
  email: "Must be a valid email address.",
86
86
  uuid: "Must be a valid UUID.",
87
+ nonEmptyUuid: "Must be a valid non-empty UUID.",
87
88
  guid: "Must be a valid GUID.",
88
89
  url: "Must be a valid absolute URL.",
89
90
  httpUrl: "Must be a valid HTTP or HTTPS URL.",
@@ -84,6 +84,7 @@ export const validationMessagesRu = Object.freeze({
84
84
  uppercase: "Строка должна быть в верхнем регистре.",
85
85
  email: "Некорректный адрес электронной почты.",
86
86
  uuid: "Некорректный UUID.",
87
+ nonEmptyUuid: "Требуется корректный ненулевой UUID.",
87
88
  guid: "Некорректный GUID.",
88
89
  url: "Некорректный абсолютный URL.",
89
90
  httpUrl: "Некорректный HTTP или HTTPS URL.",
@@ -30,11 +30,6 @@ export interface IsoDateTimeOptions extends IsoTimeOptions {
30
30
  readonly local?: boolean;
31
31
  }
32
32
  export type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha384" | "sha512";
33
- /**
34
- * Noncoercive format checks. Format scope was reviewed against Zod 4.6.7's
35
- * src/v4/core/{regexes,schemas}.ts (MIT, Colin McDonnell and contributors).
36
- * Implementations below are independent; no Zod runtime dependency is required.
37
- */
38
33
  export declare const stringRules: {
39
34
  string(options?: RuleOptions): BuiltinRule<string>;
40
35
  /** Strings count Unicode code points by default, arrays count elements, maps/sets count entries. */
@@ -52,6 +47,8 @@ export declare const stringRules: {
52
47
  email(options?: RuleOptions): BuiltinRule<string>;
53
48
  /** RFC 9562 versions 1-8 and, without a version filter, Nil/Max UUIDs. */
54
49
  uuid(options?: UuidOptions): BuiltinRule<string>;
50
+ /** A valid UUID excluding the all-zero Nil UUID. */
51
+ nonEmptyUuid(options?: UuidOptions): BuiltinRule<string>;
55
52
  guid(options?: RuleOptions): BuiltinRule<string>;
56
53
  /** Absolute WHATWG URLs, including non-HTTP schemes; not a safe-URL/security policy. */
57
54
  url(options?: UrlOptions): BuiltinRule<string>;
@@ -174,6 +174,18 @@ let currencies;
174
174
  * src/v4/core/{regexes,schemas}.ts (MIT, Colin McDonnell and contributors).
175
175
  * Implementations below are independent; no Zod runtime dependency is required.
176
176
  */
177
+ function uuidRule(options, nonNil) {
178
+ checkOptions(options);
179
+ const version = options.version;
180
+ if (version !== undefined &&
181
+ (!Number.isInteger(version) || version < 1 || version > 8))
182
+ throw new RangeError("UUID version must be 1 through 8.");
183
+ const normal = full(`[0-9a-f]{8}-[0-9a-f]{4}-${version ?? "[1-8]"}[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`, "i");
184
+ return format(nonNil ? "nonEmptyUuid" : "uuid", (value) => normal.test(value) ||
185
+ (version === undefined &&
186
+ ((!nonNil && value === "00000000-0000-0000-0000-000000000000") ||
187
+ value.toLowerCase() === "ffffffff-ffff-ffff-ffff-ffffffffffff")), options, { version: version ?? "any" });
188
+ }
177
189
  export const stringRules = {
178
190
  string(options = {}) {
179
191
  checkOptions(options);
@@ -241,16 +253,11 @@ export const stringRules = {
241
253
  },
242
254
  /** RFC 9562 versions 1-8 and, without a version filter, Nil/Max UUIDs. */
243
255
  uuid(options = {}) {
244
- checkOptions(options);
245
- const version = options.version;
246
- if (version !== undefined &&
247
- (!Number.isInteger(version) || version < 1 || version > 8))
248
- throw new RangeError("UUID version must be 1 through 8.");
249
- const normal = full(`[0-9a-f]{8}-[0-9a-f]{4}-${version ?? "[1-8]"}[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`, "i");
250
- return format("uuid", (value) => normal.test(value) ||
251
- (version === undefined &&
252
- (value === "00000000-0000-0000-0000-000000000000" ||
253
- value.toLowerCase() === "ffffffff-ffff-ffff-ffff-ffffffffffff")), options, { version: version ?? "any" });
256
+ return uuidRule(options, false);
257
+ },
258
+ /** A valid UUID excluding the all-zero Nil UUID. */
259
+ nonEmptyUuid(options = {}) {
260
+ return uuidRule(options, true);
254
261
  },
255
262
  guid(options = {}) {
256
263
  return pattern("guid", "[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}", options, "i");
@@ -44,6 +44,7 @@ export declare const rules: Readonly<{
44
44
  uppercase(options?: RuleOptions): BuiltinRule<string>;
45
45
  email(options?: RuleOptions): BuiltinRule<string>;
46
46
  uuid(options?: import("./StringRules.js").UuidOptions): BuiltinRule<string>;
47
+ nonEmptyUuid(options?: import("./StringRules.js").UuidOptions): BuiltinRule<string>;
47
48
  guid(options?: RuleOptions): BuiltinRule<string>;
48
49
  url(options?: import("./StringRules.js").UrlOptions): BuiltinRule<string>;
49
50
  httpUrl(options?: import("./StringRules.js").UrlOptions): BuiltinRule<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/node-kit",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Framework-independent Node.js toolkit for the Azure-net ecosystem",
5
5
  "type": "module",
6
6
  "license": "MIT",