Skip to content

Commit

Permalink
add missing schema
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Sep 5, 2024
1 parent b4a778c commit 226aace
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libraries/schemata/nip66/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
46 changes: 46 additions & 0 deletions libraries/schemata/nip66/scripts/convert.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
4 changes: 4 additions & 0 deletions libraries/schemata/nip66/scripts/deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const fs = require("fs")
const nip01 = require( "@nostrwatch/nip01-schema")

fs.writeFileSync( "./src/nip01.json", JSON.stringify(nip01) )
39 changes: 39 additions & 0 deletions libraries/schemata/nip66/scripts/deref.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
2 changes: 2 additions & 0 deletions libraries/schemata/nip66/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const schema = require('../dist/schema.json')
module.exports = schema
1 change: 1 addition & 0 deletions libraries/schemata/nip66/src/nip01.json
Original file line number Diff line number Diff line change
@@ -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}$"}}}
5 changes: 5 additions & 0 deletions libraries/schemata/nip66/src/schema.10166.yaml
Original file line number Diff line number Diff line change
@@ -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"
188 changes: 188 additions & 0 deletions libraries/schemata/nip66/src/schema.30166.yaml
Original file line number Diff line number Diff line change
@@ -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}):(.*)$"
7 changes: 7 additions & 0 deletions libraries/schemata/nip66/src/schema.yaml
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 12 additions & 0 deletions libraries/schemata/nip66/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"]
}
25 changes: 25 additions & 0 deletions libraries/schemata/nip66/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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']
}
};

0 comments on commit 226aace

Please sign in to comment.