Something went wrong. Try again.
Highly ambitious ATProtocol AppView service and sdks
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596#!/bin/bash
# Script to generate network_slices_lexicons.txt from lexicon files# This script finds all network.slices.* lexicon JSON files (record types only) and converts them# to the format used in network_slices_lexicons.txt## Purpose: In case the system lexicons are deleted, copy and paste these one by one into https://pdsls.dev/# This allows restoring the lexicon definitions to the PDS.# Note: This is not a common thing and only slices.network needs to worry about this right now.
set -e
LEXICONS_DIR="./lexicons"OUTPUT_FILE="./network_slices_lexicons.txt"SLICES_CONFIG="./slices.json"
# Check if required files/directories existif [ ! -d "$LEXICONS_DIR" ]; then echo "Error: lexicons directory not found at $LEXICONS_DIR" exit 1fi
if [ ! -f "$SLICES_CONFIG" ]; then echo "Error: slices.json not found at $SLICES_CONFIG" exit 1fi
# Extract slice URI from slices.jsonSLICE_URI=$(jq -r '.slice' "$SLICES_CONFIG")if [ "$SLICE_URI" = "null" ] || [ -z "$SLICE_URI" ]; then echo "Error: Could not extract slice URI from $SLICES_CONFIG" exit 1fi
# Get current timestampCREATED_AT=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")
# Clear output file> "$OUTPUT_FILE"
# Counter for generated lexiconsCOUNT=0
echo "Generating network.slices lexicons..."
# Find all network.slices lexicon files and process themfind "$LEXICONS_DIR" -path "*/network/slices/*" -name "*.json" -type f | sort | while read -r file; do # Extract the lexicon ID from the file content LEXICON_ID=$(jq -r '.id // empty' "$file" 2>/dev/null)
# Skip if not a network.slices lexicon or if ID extraction failed if [ -z "$LEXICON_ID" ] || [[ ! "$LEXICON_ID" =~ ^network\.slices\. ]]; then continue fi
# Extract definitions DEFINITIONS=$(jq -c '.defs' "$file" 2>/dev/null)
if [ "$DEFINITIONS" = "null" ] || [ -z "$DEFINITIONS" ]; then echo "Warning: Could not extract definitions from $file" continue fi
# Check if this is a record type (skip procedures and queries) MAIN_TYPE=$(jq -r '.defs.main.type // empty' "$file" 2>/dev/null) if [ "$MAIN_TYPE" != "record" ]; then continue fi
# Create the output JSON object OUTPUT_JSON=$(jq -n \ --arg nsid "$LEXICON_ID" \ --arg type "network.slices.lexicon" \ --arg slice "$SLICE_URI" \ --arg createdAt "$CREATED_AT" \ --argjson definitions "$DEFINITIONS" \ '{ "nsid": $nsid, "$type": $type, "slice": $slice, "createdAt": $createdAt, "definitions": ($definitions | tostring) }')
# Append to output file with double newline separator if [ $COUNT -gt 0 ]; then echo "" >> "$OUTPUT_FILE" fi echo "$OUTPUT_JSON" >> "$OUTPUT_FILE"
echo " - $LEXICON_ID" COUNT=$((COUNT + 1))done
echo ""echo "Generated $COUNT lexicon entries in $OUTPUT_FILE"