@arisutalk/character-spec 0.0.6 → 0.0.7

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/v0/utils.js CHANGED
@@ -1,26 +1,30 @@
1
- import { z as e } from "zod";
2
- const i = e.url().meta({
1
+ import { z as t } from "zod";
2
+ const a = t.url().meta({
3
3
  description: "URL of an image. `local:` for browser storage (OpFS), otherwise a fetchable URL. While it can be `data:` URL for base64 encoded images, it's not recommended."
4
- }), r = e.instanceof(Uint8Array).meta({
4
+ }), i = t.instanceof(Uint8Array).meta({
5
5
  description: "The binary data of the file. Used for local assets.",
6
6
  tsType: "Uint8Array"
7
- }), s = e.union([
7
+ }), s = t.union([
8
8
  // URL Asset
9
- i,
10
- r
9
+ a,
10
+ i
11
11
  ]).meta({
12
12
  description: `Represents a file, either as a URL or as binary data (Uint8Array).
13
13
  @type {string | Uint8Array}
14
14
  `
15
15
  });
16
16
  function c(n) {
17
- return (t) => new Set(t.map((a) => a[n])).size === t.length;
17
+ return (e) => new Set(e.map((r) => r[n])).size === e.length;
18
+ }
19
+ const m = t.int().min(1).meta({ description: "Positive integer (>= 1)" });
20
+ function p(n, e) {
21
+ return n.parse(e);
18
22
  }
19
- const m = e.int().min(1).meta({ description: "Positive integer (>= 1)" });
20
23
  export {
21
24
  s as FileSchema,
22
- i as ImageURLSchema,
23
- r as Uint8ArraySchema,
25
+ a as ImageURLSchema,
26
+ i as Uint8ArraySchema,
27
+ p as apply,
24
28
  m as positiveInteger,
25
29
  c as unique
26
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/types/v0/utils.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * This type is used to represent the URL of an image.\n * It is used to validate the URL of an image.\n * This should only be used in exported character. When importing the character, it should be converted to `local:`.\n * If its protocol is `local:`, it means the image is stored in the browser, usually OpFS.\n * Otherwise, it should be a valid URL which can be fetched in browser.\n * Don't use `data:` URL for large images, as it can bloat the character spec size.\n *\n */\nexport const ImageURLSchema = z.url().meta({\n description:\n \"URL of an image. `local:` for browser storage (OpFS), otherwise a fetchable URL. While it can be `data:` URL for base64 encoded images, it's not recommended.\",\n});\n\n/**\n * Binary data represented as Uint8Array.\n * Useful for local file assets.\n */\nexport const Uint8ArraySchema = z.instanceof(Uint8Array).meta({\n description: \"The binary data of the file. Used for local assets.\",\n tsType: \"Uint8Array\",\n});\n\n/**\n * Represents a file, either as a URL or as binary data (Uint8Array).\n * Used for file assets.\n */\nexport const FileSchema = z\n .union([\n // URL Asset\n ImageURLSchema,\n Uint8ArraySchema,\n ])\n .meta({\n description:\n \"Represents a file, either as a URL or as binary data (Uint8Array).\\n\" +\n \"@type {string | Uint8Array}\\n\",\n });\n/**\n * Custom validator to ensure all objects in the array have unique values for a specific key.\n * @param key The key to check for uniqueness. It should be a string key of the object.\n * @returns A predicate function for `z.refine`.\n * @example\n * ```ts\n * const schema = z.array(z.object({ name: z.string() })).refine(unique(\"name\"), { message: \"Not unique\" });\n * ```\n */\nexport function unique<\n const ARR extends {\n [key: string]: unknown;\n },\n>(key: keyof ARR) {\n return (i: ARR[]) => {\n return new Set(i.map((j) => j[key])).size === i.length;\n };\n}\n\n/**\n * Zod custom schema to ensure the value is a positive integer.\n */\nexport const positiveInteger = z\n .int()\n .min(1)\n .meta({ description: \"Positive integer (>= 1)\" });\n"],"names":["ImageURLSchema","z","Uint8ArraySchema","FileSchema","unique","key","i","j","positiveInteger"],"mappings":";AAWO,MAAMA,IAAiBC,EAAE,IAAA,EAAM,KAAK;AAAA,EACvC,aACI;AACR,CAAC,GAMYC,IAAmBD,EAAE,WAAW,UAAU,EAAE,KAAK;AAAA,EAC1D,aAAa;AAAA,EACb,QAAQ;AACZ,CAAC,GAMYE,IAAaF,EACrB,MAAM;AAAA;AAAA,EAEHD;AAAA,EACAE;AACJ,CAAC,EACA,KAAK;AAAA,EACF,aACI;AAAA;AAAA;AAER,CAAC;AAUE,SAASE,EAIdC,GAAgB;AACd,SAAO,CAACC,MACG,IAAI,IAAIA,EAAE,IAAI,CAACC,MAAMA,EAAEF,CAAG,CAAC,CAAC,EAAE,SAASC,EAAE;AAExD;AAKO,MAAME,IAAkBP,EAC1B,IAAA,EACA,IAAI,CAAC,EACL,KAAK,EAAE,aAAa,0BAAA,CAA2B;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/types/v0/utils.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * This type is used to represent the URL of an image.\n * It is used to validate the URL of an image.\n * This should only be used in exported character. When importing the character, it should be converted to `local:`.\n * If its protocol is `local:`, it means the image is stored in the browser, usually OpFS.\n * Otherwise, it should be a valid URL which can be fetched in browser.\n * Don't use `data:` URL for large images, as it can bloat the character spec size.\n *\n */\nexport const ImageURLSchema = z.url().meta({\n description:\n \"URL of an image. `local:` for browser storage (OpFS), otherwise a fetchable URL. While it can be `data:` URL for base64 encoded images, it's not recommended.\",\n});\n\n/**\n * Binary data represented as Uint8Array.\n * Useful for local file assets.\n */\nexport const Uint8ArraySchema = z.instanceof(Uint8Array).meta({\n description: \"The binary data of the file. Used for local assets.\",\n tsType: \"Uint8Array\",\n});\n\n/**\n * Represents a file, either as a URL or as binary data (Uint8Array).\n * Used for file assets.\n */\nexport const FileSchema = z\n .union([\n // URL Asset\n ImageURLSchema,\n Uint8ArraySchema,\n ])\n .meta({\n description:\n \"Represents a file, either as a URL or as binary data (Uint8Array).\\n\" +\n \"@type {string | Uint8Array}\\n\",\n });\n/**\n * Custom validator to ensure all objects in the array have unique values for a specific key.\n * @param key The key to check for uniqueness. It should be a string key of the object.\n * @returns A predicate function for `z.refine`.\n * @example\n * ```ts\n * const schema = z.array(z.object({ name: z.string() })).refine(unique(\"name\"), { message: \"Not unique\" });\n * ```\n */\nexport function unique<\n const ARR extends {\n [key: string]: unknown;\n },\n>(key: keyof ARR) {\n return (i: ARR[]) => {\n return new Set(i.map((j) => j[key])).size === i.length;\n };\n}\n\n/**\n * Zod custom schema to ensure the value is a positive integer.\n */\nexport const positiveInteger = z\n .int()\n .min(1)\n .meta({ description: \"Positive integer (>= 1)\" });\n\n/**\n * Applies the given Zod schema to the provided data and returns the parsed output.\n * @param schema The Zod schema to apply.\n * @param data The data to be validated and parsed. Don't need to pass optional fields.\n * @returns The parsed output of the schema.\n */\nexport function apply<T extends z.ZodType>(\n schema: T,\n data: z.input<T>,\n): z.output<T> {\n return schema.parse(data);\n}\n"],"names":["ImageURLSchema","z","Uint8ArraySchema","FileSchema","unique","key","i","j","positiveInteger","apply","schema","data"],"mappings":";AAWO,MAAMA,IAAiBC,EAAE,IAAA,EAAM,KAAK;AAAA,EACvC,aACI;AACR,CAAC,GAMYC,IAAmBD,EAAE,WAAW,UAAU,EAAE,KAAK;AAAA,EAC1D,aAAa;AAAA,EACb,QAAQ;AACZ,CAAC,GAMYE,IAAaF,EACrB,MAAM;AAAA;AAAA,EAEHD;AAAA,EACAE;AACJ,CAAC,EACA,KAAK;AAAA,EACF,aACI;AAAA;AAAA;AAER,CAAC;AAUE,SAASE,EAIdC,GAAgB;AACd,SAAO,CAACC,MACG,IAAI,IAAIA,EAAE,IAAI,CAACC,MAAMA,EAAEF,CAAG,CAAC,CAAC,EAAE,SAASC,EAAE;AAExD;AAKO,MAAME,IAAkBP,EAC1B,IAAA,EACA,IAAI,CAAC,EACL,KAAK,EAAE,aAAa,0BAAA,CAA2B;AAQ7C,SAASQ,EACZC,GACAC,GACW;AACX,SAAOD,EAAO,MAAMC,CAAI;AAC5B;"}
package/dist/v0.js CHANGED
@@ -1,8 +1,9 @@
1
- import { FileSchema as i, ImageURLSchema as m, Uint8ArraySchema as r, positiveInteger as t, unique as c } from "./v0/utils.js";
1
+ import { FileSchema as i, ImageURLSchema as m, Uint8ArraySchema as r, apply as p, positiveInteger as t, unique as c } from "./v0/utils.js";
2
2
  export {
3
3
  i as FileSchema,
4
4
  m as ImageURLSchema,
5
5
  r as Uint8ArraySchema,
6
+ p as apply,
6
7
  t as positiveInteger,
7
8
  c as unique
8
9
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arisutalk/character-spec",
3
3
  "description": "Character specification, schema & migration for ArisuTalk",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "concertypin",
@@ -58,4 +58,4 @@
58
58
  }
59
59
  },
60
60
  "packageManager": "pnpm@10.16.1+sha512.0e155aa2629db8672b49e8475da6226aa4bdea85fdcdfdc15350874946d4f3c91faaf64cbdc4a5d1ab8002f473d5c3fcedcd197989cf0390f9badd3c04678706"
61
- }
61
+ }