From 226aaceb9c52df58d971c260b83d7c247e44ef04 Mon Sep 17 00:00:00 2001 From: dskvr Date: Thu, 5 Sep 2024 16:36:19 +0200 Subject: [PATCH] add missing schema --- libraries/schemata/nip66/package.json | 28 +++ libraries/schemata/nip66/scripts/convert.js | 46 +++++ libraries/schemata/nip66/scripts/deps.js | 4 + libraries/schemata/nip66/scripts/deref.mjs | 39 ++++ libraries/schemata/nip66/src/index.ts | 2 + libraries/schemata/nip66/src/nip01.json | 1 + .../schemata/nip66/src/schema.10166.yaml | 5 + .../schemata/nip66/src/schema.30166.yaml | 188 ++++++++++++++++++ libraries/schemata/nip66/src/schema.yaml | 7 + libraries/schemata/nip66/tsconfig.json | 12 ++ libraries/schemata/nip66/webpack.config.js | 25 +++ 11 files changed, 357 insertions(+) create mode 100644 libraries/schemata/nip66/package.json create mode 100644 libraries/schemata/nip66/scripts/convert.js create mode 100755 libraries/schemata/nip66/scripts/deps.js create mode 100755 libraries/schemata/nip66/scripts/deref.mjs create mode 100644 libraries/schemata/nip66/src/index.ts create mode 100644 libraries/schemata/nip66/src/nip01.json create mode 100644 libraries/schemata/nip66/src/schema.10166.yaml create mode 100644 libraries/schemata/nip66/src/schema.30166.yaml create mode 100644 libraries/schemata/nip66/src/schema.yaml create mode 100644 libraries/schemata/nip66/tsconfig.json create mode 100644 libraries/schemata/nip66/webpack.config.js diff --git a/libraries/schemata/nip66/package.json b/libraries/schemata/nip66/package.json new file mode 100644 index 00000000..6309925b --- /dev/null +++ b/libraries/schemata/nip66/package.json @@ -0,0 +1,28 @@ +{ + "name": "@nostrwatch/nip66-schema", + "version": "0.0.1", + "main": "index.js", + "license": "MIT", + "dependencies": { + "json-loader": "0.5.7", + "ts-loader": "9.5.1", + "typescript": "5.5.4", + "webpack": "5.93.0", + "webpack-cli": "5.1.4", + "webpack-merge": "6.0.1", + "webpack-node-externals": "3.0.0", + "yaml-convert": "1.0.1" + }, + "devDependencies": { + "@apidevtools/json-schema-ref-parser": "11.7.0", + "@nostrwatch/nip01-schema": "0.0.1" + }, + "scripts": { + "clean": "rimraf dist/*", + "deps": "node scripts/deps.js", + "deref": "./scripts/deref.mjs ./dist/schema.json", + "convert": "node ./scripts/convert.js", + "prebuild": "mkdir -p dist && yarn clean && yarn deps && yarn deref", + "build": "yarn prebuild && tsc && webpack --mode development --stats verbose" + } +} diff --git a/libraries/schemata/nip66/scripts/convert.js b/libraries/schemata/nip66/scripts/convert.js new file mode 100644 index 00000000..6cef879f --- /dev/null +++ b/libraries/schemata/nip66/scripts/convert.js @@ -0,0 +1,46 @@ +const fs = require('fs'); +const path = require('path'); +const { exec } = require('child_process'); + +// Directories +const INPUT_DIR = './dist'; +const OUTPUT_DIR = './dist'; + +// Ensure output directory exists +if (!fs.existsSync(OUTPUT_DIR)) { + fs.mkdirSync(OUTPUT_DIR, { recursive: true }); +} + +// Function to convert YAML to JSON +function convertYAMLtoJSON(filename) { + const inputPath = path.join(INPUT_DIR, filename); + const outputPath = path.join(OUTPUT_DIR, `${path.basename(filename, '.yaml')}.json`); + + const command = `yaml-convert --pretty true --input "${inputPath}" --output "${outputPath}"`; + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Error: ${error.message}`); + return; + } + if (stderr) { + console.error(`Stderr: ${stderr}`); + return; + } + console.log(`Converted '${inputPath}' to '${outputPath}'`); + console.log(stdout); + }); +} + +// Read the input directory and process each YAML file +fs.readdir(INPUT_DIR, (err, files) => { + if (err) { + console.error(`Error reading directory ${INPUT_DIR}: ${err}`); + return; + } + + files.forEach(file => { + if (path.extname(file) === '.yaml') { + convertYAMLtoJSON(file); + } + }); +}); diff --git a/libraries/schemata/nip66/scripts/deps.js b/libraries/schemata/nip66/scripts/deps.js new file mode 100755 index 00000000..97004993 --- /dev/null +++ b/libraries/schemata/nip66/scripts/deps.js @@ -0,0 +1,4 @@ +const fs = require("fs") +const nip01 = require( "@nostrwatch/nip01-schema") + +fs.writeFileSync( "./src/nip01.json", JSON.stringify(nip01) ) \ No newline at end of file diff --git a/libraries/schemata/nip66/scripts/deref.mjs b/libraries/schemata/nip66/scripts/deref.mjs new file mode 100755 index 00000000..d212607e --- /dev/null +++ b/libraries/schemata/nip66/scripts/deref.mjs @@ -0,0 +1,39 @@ +#!/usr/bin/env node +import $RefParser from "@apidevtools/json-schema-ref-parser"; +import fs from "fs"; +import path from "path"; + +const inputDir = './src'; // Directory containing JSON files +const outputDir = './dist'; // Output directory for dereferenced files + +// Ensure output directory exists +if (!fs.existsSync(outputDir)){ + fs.mkdirSync(outputDir, { recursive: true }); +} + +// Function to dereference a JSON file +async function dereferenceJson(filePath) { + try { + const dereferenced = await $RefParser.dereference(filePath); + const outputFilePath = path.join(outputDir, `${path.basename(filePath, '.yaml')}.json`); + fs.writeFileSync(outputFilePath, JSON.stringify(dereferenced, null, 2)); + console.log(`File successfully written: ${outputFilePath}`); + } catch (error) { + console.error(`Error processing ${filePath}:`, error); + } +} + +// Read all files in the input directory and process each JSON file +fs.readdir(inputDir, (err, files) => { + if (err) { + console.error(`Error reading directory ${inputDir}:`, err); + return; + } + + files.forEach(file => { + if (path.extname(file) === '.yaml') { + const fullPath = path.join(inputDir, file); + dereferenceJson(fullPath); + } + }); +}); \ No newline at end of file diff --git a/libraries/schemata/nip66/src/index.ts b/libraries/schemata/nip66/src/index.ts new file mode 100644 index 00000000..dcad6104 --- /dev/null +++ b/libraries/schemata/nip66/src/index.ts @@ -0,0 +1,2 @@ +const schema = require('../dist/schema.json') +module.exports = schema \ No newline at end of file diff --git a/libraries/schemata/nip66/src/nip01.json b/libraries/schemata/nip66/src/nip01.json new file mode 100644 index 00000000..b30eb1d1 --- /dev/null +++ b/libraries/schemata/nip66/src/nip01.json @@ -0,0 +1 @@ +{"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"content":{"type":"string"},"created_at":{"type":"integer"},"id":{"$ref":"#/$defs/secp256k1"},"kind":{"type":"integer"},"pubkey":{"$ref":"#/$defs/secp256k1"},"sig":{"type":"string"},"tags":{"type":"array","items":[{"type":"array","items":[{"type":"string"}]}]}},"required":["content","created_at","id","kind","pubkey","sig","tags"],"$defs":{"secp256k1":{"type":"string","pattern":"^[a-f0-9]{64}$"}}} \ No newline at end of file diff --git a/libraries/schemata/nip66/src/schema.10166.yaml b/libraries/schemata/nip66/src/schema.10166.yaml new file mode 100644 index 00000000..471fb31e --- /dev/null +++ b/libraries/schemata/nip66/src/schema.10166.yaml @@ -0,0 +1,5 @@ +$id: "https://kind10166.nip66.schemata.nostr.watch" +$schema: "http://json-schema.org/draft-07/schema#" +title: "k10166" +type: "object" +$ref: "nip01.json" \ No newline at end of file diff --git a/libraries/schemata/nip66/src/schema.30166.yaml b/libraries/schemata/nip66/src/schema.30166.yaml new file mode 100644 index 00000000..9efe0d00 --- /dev/null +++ b/libraries/schemata/nip66/src/schema.30166.yaml @@ -0,0 +1,188 @@ +$id: "https://kind30166.nip66.schemata.nostr.watch" +$schema: "http://json-schema.org/draft-07/schema#" +title: "k30166" +allOf: + - $ref: "nip01.json" + - type: "object" + properties: + kind: + type: integer + const: 30166 + tags: + type: array + items: + anyOf: + - $ref: "#/$defs/d" + - $ref: "#/$defs/rtt" + - $ref: "#/$defs/s" + - $ref: "#/$defs/n" + - $ref: "#/$defs/R" + - $ref: "#/$defs/N" + - $ref: "#/$defs/k" + - $ref: "#/$defs/T" + - $ref: "#/$defs/t" + - $ref: "#/$defs/p" + - $ref: "#/$defs/l" + - $ref: "#/$defs/L" + - $ref: "#/$defs/e" + - $ref: "#/$defs/g" + +$defs: + url: + type: string + pattern: "^(wss://|ws://).*$" + d: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: "d" + - $ref: "#/$defs/url" + rtt: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + pattern: "^(rtt-)([a-zA-Z]+)$" + - type: string + pattern: "^([0-9]+)$" + l: + type: array + minItems: 3 + maxItems: 3 + additionalItems: false + items: + - type: string + const: 'l' + - type: string + - type: string + + L: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'L' + - type: string + + k: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'k' + - type: string + pattern: "^([0-9]+)$" + + + p: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'p' + - type: string + + e: + type: array + minItems: 2 + maxItems: 3 + additionalItems: false + items: + - type: string + const: 'e' + - type: string + - $ref: "#/$defs/url" + + t: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 't' + - type: string + + T: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'T' + - type: string + + n: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'n' + - type: string + + N: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'N' + - type: string + pattern: "^([0-9]+)$" + + R: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'R' + - type: string + + s: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 's' + - type: string + + g: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'g' + - type: string + pattern: "^[0-9bcdefghjkmnpqrstuvwxyz]{1,12}$" + + a: + type: array + minItems: 2 + maxItems: 2 + additionalItems: false + items: + - type: string + const: 'a' + - type: string + pattern: "^([0-9]+):([a-f0-9]{64}):(.*)$" \ No newline at end of file diff --git a/libraries/schemata/nip66/src/schema.yaml b/libraries/schemata/nip66/src/schema.yaml new file mode 100644 index 00000000..54570845 --- /dev/null +++ b/libraries/schemata/nip66/src/schema.yaml @@ -0,0 +1,7 @@ +$id: "https://nip66.schemata.nostr.watch" +$schema: "http://json-schema.org/draft-07/schema#" +title: "nip66" +type: "object" +oneOf: + - $ref: "schema.30166.yaml" + - $ref: "schema.10166.yaml" \ No newline at end of file diff --git a/libraries/schemata/nip66/tsconfig.json b/libraries/schemata/nip66/tsconfig.json new file mode 100644 index 00000000..67a3f050 --- /dev/null +++ b/libraries/schemata/nip66/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "esnext", + "target": "esnext", + "moduleResolution": "node", + "esModuleInterop": true, + "resolveJsonModule": true, + "outDir": "./dist", + "rootDir": "./src" + }, + "include": ["src/**/*"] +} \ No newline at end of file diff --git a/libraries/schemata/nip66/webpack.config.js b/libraries/schemata/nip66/webpack.config.js new file mode 100644 index 00000000..ac51e6c9 --- /dev/null +++ b/libraries/schemata/nip66/webpack.config.js @@ -0,0 +1,25 @@ +const path = require('path'); + +module.exports = { + entry: path.resolve(__dirname, 'src', 'index.ts'), // Ensures absolute path resolution + output: { + path: path.resolve(__dirname, 'dist'), // Explicitly resolves to your project's dist directory + filename: 'bundle.js' + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/, + }, + { + test: /\.json$/, + type: 'json' // Handles JSON files correctly + } + ] + }, + resolve: { + extensions: ['.tsx', '.ts', '.js', '.json'] + } +};