Skip to content

Commit

Permalink
Removed global params for now
Browse files Browse the repository at this point in the history
  • Loading branch information
NuroDev committed Apr 28, 2024
1 parent 29cf72f commit 654a973
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 48 deletions.
21 changes: 2 additions & 19 deletions packages/uuid.rocks/src/_shared/_shared.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,5 @@ export const UUIDSchema = z.union([
NanoIDSchema,
]);

export const GlobalParamsSchema = z
.object({
/** Uses the [nanoid](https://www.npmjs.com/package/nanoid) package to generate ID’s. Supports &len= param to adjust ID length. If this is not a number it will be silently ignored. If used in combonation with bulk api, may fail if len is too long. */
nanoid: z.boolean(),

/** Switches from standard uuidv4 format to [Readable UUIDs](https://github.com/Debdut/uuid-readable), that are Shakespearean grammatically correct sentences. */
readable: z.boolean(),

/** Switches from standard UUIDv4 to a [Short ID](https://www.npmjs.com/package/short-uuid). These ID’s are converted from UUIDv4 ID’s so they are just as unique & colission free. */
short: z.boolean(),

/**
* Uses the [ulidx](https://www.npmjs.com/package/ulidx) package to generate ULID’s.
*
* Eg. 01FB0CCPD8R0H9KAJBFQJDFYJB
*/
ulid: z.boolean(),
})
.partial();
// TODO(@nurodev): Implement global search params once I have time to narrow down each endpoints support for each param.
export const GlobalParamsSchema = z.object({});
6 changes: 2 additions & 4 deletions packages/uuid.rocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
JsonBulkParams,
JsonMap,
JsonMapParams,
JsonParams,
} from "./json/json.types";
import type { NanoID, NanoIDParams } from "./nanoid/nanoid.types";
import type {
Expand All @@ -18,15 +17,14 @@ import type {
PlainMapParams,
PlainNamespaceMap,
PlainNamespaceMapParams,
PlainParams,
} from "./plain/plain.types";
import type { Stats } from "./stats/stats.types";

const u = initUntypeable();

const router = u.router({
/** Gets single uuid with JSON output */
"/json": u.input<JsonParams>().output<Json>(),
"/json": u.input<GlobalParams>().output<Json>(),

/** Gets uuids in bulk (up to 20k) with JSON output */
"/json/bulk": u.input<JsonBulkParams>().output<JsonBulk>(),
Expand All @@ -38,7 +36,7 @@ const router = u.router({
"/nanoid": u.input<NanoIDParams>().output<NanoID>(),

/** Gets single UUID in plaintext */
"/plain": u.input<PlainParams>().output<Plain>(),
"/plain": u.input<GlobalParams>().output<Plain>(),

/** Gets uuids in bulk (up to 20k) in plaintext */
"/plain/bulk": u.input<PlainBulkParams>().output<PlainBulk>(),
Expand Down
2 changes: 0 additions & 2 deletions packages/uuid.rocks/src/json/json.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import type {
JsonBulkSchema,
JsonMapParamsSchema,
JsonMapSchema,
JsonParamsSchema,
JsonSchema,
} from "./json.validators";

export type JsonParams = z.infer<typeof JsonParamsSchema>;
export type Json = z.infer<typeof JsonSchema>;

export type JsonBulkParams = z.infer<typeof JsonBulkParamsSchema>;
Expand Down
15 changes: 3 additions & 12 deletions packages/uuid.rocks/src/json/json.validators.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { z } from "zod";

import { GlobalParamsSchema, UUIDSchema } from "../_shared/_shared.validators";

export const JsonParamsSchema = GlobalParamsSchema.pick({
nanoid: true,
readable: true,
short: true,
ulid: true,
});
import { UUIDSchema } from "../_shared/_shared.validators";

export const JsonSchema = z.object({
apiVersion: z.string(),
Expand All @@ -18,9 +11,7 @@ export const JsonSchema = z.object({
uuid: UUIDSchema,
});

export const JsonBulkParamsSchema = GlobalParamsSchema.pick({
readable: true,
}).extend({
export const JsonBulkParamsSchema = z.object({
count: z.number().int().positive().max(20000),
});

Expand All @@ -31,7 +22,7 @@ export const JsonBulkSchema = z.object({
timestamp: z.coerce.date(),
});

export const JsonMapParamsSchema = GlobalParamsSchema.extend({
export const JsonMapParamsSchema = z.object({
key: z.string().min(1),
});

Expand Down
2 changes: 0 additions & 2 deletions packages/uuid.rocks/src/plain/plain.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import type {
PlainMapSchema,
PlainNamespaceMapParamsSchema,
PlainNamespaceMapSchema,
PlainParamsSchema,
PlainSchema,
} from "./plain.validators";

export type PlainParams = z.infer<typeof PlainParamsSchema>;
export type Plain = z.infer<typeof PlainSchema>;

export type PlainBulkParams = z.infer<typeof PlainBulkParamsSchema>;
Expand Down
9 changes: 4 additions & 5 deletions packages/uuid.rocks/src/plain/plain.validators.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { z } from "zod";

import { GlobalParamsSchema, UUIDSchema } from "../_shared/_shared.validators";
import { UUIDSchema } from "../_shared/_shared.validators";

export const PlainParamsSchema = GlobalParamsSchema;
export const PlainSchema = UUIDSchema;

export const PlainBulkParamsSchema = GlobalParamsSchema.extend({
export const PlainBulkParamsSchema = z.object({
count: z.number().int().positive().max(20000),
});
export const PlainBulkSchema = z.string(); // TODO: Improve this schema to check for UUID's broken up with a new line.

export const PlainMapParamsSchema = GlobalParamsSchema.extend({
export const PlainMapParamsSchema = z.object({
key: z.string().min(1),
});
export const PlainMapSchema = UUIDSchema;

export const PlainNamespaceMapParamsSchema = GlobalParamsSchema.extend({
export const PlainNamespaceMapParamsSchema = z.object({
namespace: z.string().min(1),
key: z.string().min(1),
});
Expand Down
6 changes: 2 additions & 4 deletions packages/uuid.rocks/src/runtimeSafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
JsonBulkSchema,
JsonMapParamsSchema,
JsonMapSchema,
JsonParamsSchema,
JsonSchema,
} from "./json/json.validators";
import { NanoIDSchema, NanoIdParamsSchema } from "./nanoid/nanoid.validators";
Expand All @@ -18,15 +17,14 @@ import {
PlainNamespaceMapSchema,
PlainMapParamsSchema,
PlainMapSchema,
PlainParamsSchema,
} from "./plain/plain.validators";
import { StatsSchema } from "./stats/stats.validators";

const u = initUntypeable();

export const uuidRocksSafeRouter = u.router({
/** Gets single uuid with JSON output */
"/json": u.input(JsonParamsSchema).output(JsonSchema),
"/json": u.input(GlobalParamsSchema).output(JsonSchema),

/** Gets uuids in bulk (up to 20k) with JSON output */
"/json/bulk": u.input(JsonBulkParamsSchema).output(JsonBulkSchema),
Expand All @@ -38,7 +36,7 @@ export const uuidRocksSafeRouter = u.router({
"/nanoid": u.input(NanoIdParamsSchema).output(NanoIDSchema),

/** Gets single UUID in plaintext */
"/plain": u.input(PlainParamsSchema).output(PlainSchema),
"/plain": u.input(GlobalParamsSchema).output(PlainSchema),

/** Gets uuids in bulk (up to 20k) in plaintext */
"/plain/bulk": u.input(PlainBulkParamsSchema).output(PlainBulkSchema),
Expand Down

0 comments on commit 654a973

Please sign in to comment.