@safe-ugc-ui/schema 0.3.1 → 0.5.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.
@@ -0,0 +1,14 @@
1
+ // src/index.ts
2
+ import { ugcCardSchema } from "@safe-ugc-ui/types";
3
+ import { zodToJsonSchema } from "zod-to-json-schema";
4
+ function generateCardSchema() {
5
+ return zodToJsonSchema(ugcCardSchema, {
6
+ name: "UGCCard",
7
+ nameStrategy: "title"
8
+ });
9
+ }
10
+
11
+ export {
12
+ generateCardSchema
13
+ };
14
+ //# sourceMappingURL=chunk-R2QYKPJJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @safe-ugc-ui/schema — Public API\n *\n * Provides programmatic access to the UGC Card JSON Schema.\n *\n * For the static JSON file (editor / ajv integration), import from:\n * `@safe-ugc-ui/schema/ugc-card.schema.json`\n *\n * For runtime generation:\n * `import { generateCardSchema } from '@safe-ugc-ui/schema';`\n *\n * IMPORTANT: JSON Schema covers structural validation only.\n * Security rules, resource limits, and context-dependent checks require\n * the @safe-ugc-ui/validator package.\n */\n\nimport { ugcCardSchema } from '@safe-ugc-ui/types';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n/**\n * Generate the UGC Card JSON Schema at runtime.\n *\n * Returns a plain object conforming to JSON Schema Draft 7.\n * Equivalent to the static `ugc-card.schema.json` file produced at build time.\n */\nexport function generateCardSchema(): Record<string, unknown> {\n return zodToJsonSchema(ugcCardSchema, {\n name: 'UGCCard',\n nameStrategy: 'title',\n }) as Record<string, unknown>;\n}\n"],"mappings":";AAgBA,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAQzB,SAAS,qBAA8C;AAC5D,SAAO,gBAAgB,eAAe;AAAA,IACpC,MAAM;AAAA,IACN,cAAc;AAAA,EAChB,CAAC;AACH;","names":[]}
@@ -1,2 +1,19 @@
1
+ /**
2
+ * @safe-ugc-ui/schema — JSON Schema Generator (build-time script)
3
+ *
4
+ * Converts the Zod-based UGCCard schema from @safe-ugc-ui/types into a
5
+ * standard JSON Schema document and writes it to dist/ugc-card.schema.json.
6
+ *
7
+ * Run via: `node dist/generate.js` (called automatically by the build script).
8
+ *
9
+ * NOTE: This produces a *structural* schema only. Context-dependent rules
10
+ * (position constraints, security checks, resource limits, etc.) cannot be
11
+ * expressed in JSON Schema and require the validator package.
12
+ */
13
+ declare function generateCardSchemaJson(): string;
14
+ declare function getDefaultOutputPath(moduleUrl?: string): string;
15
+ declare function writeGeneratedSchema(outputPath: string): string;
16
+ declare function runGenerateScript(moduleUrl?: string): string;
17
+ declare function isDirectExecution(moduleUrl?: string, argv1?: string | undefined): boolean;
1
18
 
2
- export { }
19
+ export { generateCardSchemaJson, getDefaultOutputPath, isDirectExecution, runGenerateScript, writeGeneratedSchema };
package/dist/generate.js CHANGED
@@ -1,15 +1,40 @@
1
+ import {
2
+ generateCardSchema
3
+ } from "./chunk-R2QYKPJJ.js";
4
+
1
5
  // src/generate.ts
2
6
  import { writeFileSync } from "fs";
3
7
  import { dirname, resolve } from "path";
4
8
  import { fileURLToPath } from "url";
5
- import { ugcCardSchema } from "@safe-ugc-ui/types";
6
- import { zodToJsonSchema } from "zod-to-json-schema";
7
- var jsonSchema = zodToJsonSchema(ugcCardSchema, {
8
- name: "UGCCard",
9
- nameStrategy: "title"
10
- });
11
- var __dirname = dirname(fileURLToPath(import.meta.url));
12
- var outputPath = resolve(__dirname, "ugc-card.schema.json");
13
- writeFileSync(outputPath, JSON.stringify(jsonSchema, null, 2), "utf-8");
14
- console.log(`Generated ${outputPath}`);
9
+ function generateCardSchemaJson() {
10
+ return JSON.stringify(generateCardSchema(), null, 2);
11
+ }
12
+ function getDefaultOutputPath(moduleUrl = import.meta.url) {
13
+ const moduleDir = dirname(fileURLToPath(moduleUrl));
14
+ return resolve(moduleDir, "ugc-card.schema.json");
15
+ }
16
+ function writeGeneratedSchema(outputPath) {
17
+ writeFileSync(outputPath, generateCardSchemaJson(), "utf-8");
18
+ return outputPath;
19
+ }
20
+ function runGenerateScript(moduleUrl = import.meta.url) {
21
+ return writeGeneratedSchema(getDefaultOutputPath(moduleUrl));
22
+ }
23
+ function isDirectExecution(moduleUrl = import.meta.url, argv1 = process.argv[1]) {
24
+ if (!argv1) {
25
+ return false;
26
+ }
27
+ return fileURLToPath(moduleUrl) === resolve(argv1);
28
+ }
29
+ if (isDirectExecution()) {
30
+ const outputPath = runGenerateScript();
31
+ console.log(`Generated ${outputPath}`);
32
+ }
33
+ export {
34
+ generateCardSchemaJson,
35
+ getDefaultOutputPath,
36
+ isDirectExecution,
37
+ runGenerateScript,
38
+ writeGeneratedSchema
39
+ };
15
40
  //# sourceMappingURL=generate.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/generate.ts"],"sourcesContent":["/**\n * @safe-ugc-ui/schema — JSON Schema Generator (build-time script)\n *\n * Converts the Zod-based UGCCard schema from @safe-ugc-ui/types into a\n * standard JSON Schema document and writes it to dist/ugc-card.schema.json.\n *\n * Run via: `node dist/generate.js` (called automatically by the build script).\n *\n * NOTE: This produces a *structural* schema only. Context-dependent rules\n * (position constraints, security checks, resource limits, etc.) cannot be\n * expressed in JSON Schema and require the validator package.\n */\n\nimport { writeFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { ugcCardSchema } from '@safe-ugc-ui/types';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\nconst jsonSchema = zodToJsonSchema(ugcCardSchema, {\n name: 'UGCCard',\n nameStrategy: 'title',\n});\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst outputPath = resolve(__dirname, 'ugc-card.schema.json');\n\nwriteFileSync(outputPath, JSON.stringify(jsonSchema, null, 2), 'utf-8');\n\nconsole.log(`Generated ${outputPath}`);\n"],"mappings":";AAaA,SAAS,qBAAqB;AAC9B,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAE9B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAEhC,IAAM,aAAa,gBAAgB,eAAe;AAAA,EAChD,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAED,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AACxD,IAAM,aAAa,QAAQ,WAAW,sBAAsB;AAE5D,cAAc,YAAY,KAAK,UAAU,YAAY,MAAM,CAAC,GAAG,OAAO;AAEtE,QAAQ,IAAI,aAAa,UAAU,EAAE;","names":[]}
1
+ {"version":3,"sources":["../src/generate.ts"],"sourcesContent":["/**\n * @safe-ugc-ui/schema — JSON Schema Generator (build-time script)\n *\n * Converts the Zod-based UGCCard schema from @safe-ugc-ui/types into a\n * standard JSON Schema document and writes it to dist/ugc-card.schema.json.\n *\n * Run via: `node dist/generate.js` (called automatically by the build script).\n *\n * NOTE: This produces a *structural* schema only. Context-dependent rules\n * (position constraints, security checks, resource limits, etc.) cannot be\n * expressed in JSON Schema and require the validator package.\n */\n\nimport { writeFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { generateCardSchema } from './index.js';\n\nexport function generateCardSchemaJson(): string {\n return JSON.stringify(generateCardSchema(), null, 2);\n}\n\nexport function getDefaultOutputPath(moduleUrl: string = import.meta.url): string {\n const moduleDir = dirname(fileURLToPath(moduleUrl));\n return resolve(moduleDir, 'ugc-card.schema.json');\n}\n\nexport function writeGeneratedSchema(outputPath: string): string {\n writeFileSync(outputPath, generateCardSchemaJson(), 'utf-8');\n return outputPath;\n}\n\nexport function runGenerateScript(moduleUrl: string = import.meta.url): string {\n return writeGeneratedSchema(getDefaultOutputPath(moduleUrl));\n}\n\nexport function isDirectExecution(\n moduleUrl: string = import.meta.url,\n argv1: string | undefined = process.argv[1],\n): boolean {\n if (!argv1) {\n return false;\n }\n\n return fileURLToPath(moduleUrl) === resolve(argv1);\n}\n\nif (isDirectExecution()) {\n const outputPath = runGenerateScript();\n console.log(`Generated ${outputPath}`);\n}\n"],"mappings":";;;;;AAaA,SAAS,qBAAqB;AAC9B,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAIvB,SAAS,yBAAiC;AAC/C,SAAO,KAAK,UAAU,mBAAmB,GAAG,MAAM,CAAC;AACrD;AAEO,SAAS,qBAAqB,YAAoB,YAAY,KAAa;AAChF,QAAM,YAAY,QAAQ,cAAc,SAAS,CAAC;AAClD,SAAO,QAAQ,WAAW,sBAAsB;AAClD;AAEO,SAAS,qBAAqB,YAA4B;AAC/D,gBAAc,YAAY,uBAAuB,GAAG,OAAO;AAC3D,SAAO;AACT;AAEO,SAAS,kBAAkB,YAAoB,YAAY,KAAa;AAC7E,SAAO,qBAAqB,qBAAqB,SAAS,CAAC;AAC7D;AAEO,SAAS,kBACd,YAAoB,YAAY,KAChC,QAA4B,QAAQ,KAAK,CAAC,GACjC;AACT,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,SAAO,cAAc,SAAS,MAAM,QAAQ,KAAK;AACnD;AAEA,IAAI,kBAAkB,GAAG;AACvB,QAAM,aAAa,kBAAkB;AACrC,UAAQ,IAAI,aAAa,UAAU,EAAE;AACvC;","names":[]}
package/dist/index.js CHANGED
@@ -1,12 +1,6 @@
1
- // src/index.ts
2
- import { ugcCardSchema } from "@safe-ugc-ui/types";
3
- import { zodToJsonSchema } from "zod-to-json-schema";
4
- function generateCardSchema() {
5
- return zodToJsonSchema(ugcCardSchema, {
6
- name: "UGCCard",
7
- nameStrategy: "title"
8
- });
9
- }
1
+ import {
2
+ generateCardSchema
3
+ } from "./chunk-R2QYKPJJ.js";
10
4
  export {
11
5
  generateCardSchema
12
6
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @safe-ugc-ui/schema — Public API\n *\n * Provides programmatic access to the UGC Card JSON Schema.\n *\n * For the static JSON file (editor / ajv integration), import from:\n * `@safe-ugc-ui/schema/ugc-card.schema.json`\n *\n * For runtime generation:\n * `import { generateCardSchema } from '@safe-ugc-ui/schema';`\n *\n * IMPORTANT: JSON Schema covers structural validation only.\n * Security rules, resource limits, and context-dependent checks require\n * the @safe-ugc-ui/validator package.\n */\n\nimport { ugcCardSchema } from '@safe-ugc-ui/types';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n/**\n * Generate the UGC Card JSON Schema at runtime.\n *\n * Returns a plain object conforming to JSON Schema Draft 7.\n * Equivalent to the static `ugc-card.schema.json` file produced at build time.\n */\nexport function generateCardSchema(): Record<string, unknown> {\n return zodToJsonSchema(ugcCardSchema, {\n name: 'UGCCard',\n nameStrategy: 'title',\n }) as Record<string, unknown>;\n}\n"],"mappings":";AAgBA,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAQzB,SAAS,qBAA8C;AAC5D,SAAO,gBAAgB,eAAe;AAAA,IACpC,MAAM;AAAA,IACN,cAAc;AAAA,EAChB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}