all the project copy
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.git
|
||||||
|
.idea
|
||||||
|
.venv
|
||||||
|
**/__pycache__
|
||||||
|
**/*.pyc
|
||||||
|
node_sid/node_modules
|
||||||
|
web/frontend/node_modules
|
||||||
|
web/frontend/dist
|
||||||
20
.env.example
Normal file
20
.env.example
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Copy to .env and fill production values before running docker compose.
|
||||||
|
|
||||||
|
POSTGRES_PASSWORD=localpassword
|
||||||
|
TICKET_PG_PASSWORD=localpassword
|
||||||
|
|
||||||
|
TICKET_MYSQL_HOST=127.0.0.1
|
||||||
|
TICKET_MYSQL_PORT=3307
|
||||||
|
TICKET_MYSQL_DATABASE=smits
|
||||||
|
TICKET_MYSQL_USER=reader
|
||||||
|
TICKET_MYSQL_PASSWORD=change-me
|
||||||
|
TICKET_MYSQL_CHARSET=utf8
|
||||||
|
|
||||||
|
TICKET_TELEGRAM_TOKEN=change-me
|
||||||
|
TICKET_ADMIN_ID=145645559
|
||||||
|
TICKET_ENABLE_NOTIFICATIONS=true
|
||||||
|
|
||||||
|
TICKET_WEB_ADMIN_USERNAME=admin
|
||||||
|
TICKET_WEB_ADMIN_PASSWORD=change-me-now
|
||||||
|
TICKET_WEB_COOKIE_SECURE=false
|
||||||
|
TICKET_WEB_SESSION_DAYS=7
|
||||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
**/__pycache__/
|
||||||
|
**/*.pyc
|
||||||
|
.venv/
|
||||||
|
web/frontend/node_modules/
|
||||||
|
web/frontend/dist/
|
||||||
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
8
.idea/Ticket.iml
generated
Normal file
8
.idea/Ticket.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Ticket.iml" filepath="$PROJECT_DIR$/.idea/Ticket.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
221
COMMANDS.md
Normal file
221
COMMANDS.md
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
# Ticket Telegram Bot Commands
|
||||||
|
|
||||||
|
## Main commands
|
||||||
|
|
||||||
|
`/start`
|
||||||
|
|
||||||
|
Register the Telegram user. New users stay pending until an administrator approves them.
|
||||||
|
|
||||||
|
`/help`
|
||||||
|
|
||||||
|
Show a short command summary in Telegram.
|
||||||
|
|
||||||
|
`/tic <ticket>`
|
||||||
|
|
||||||
|
Search similar solved tickets for an existing ticket. If the user has saved filters and the command does not specify an Area/Product/Competence/Client filter, saved filters are applied automatically.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/tic 658726
|
||||||
|
/tic 658726 area
|
||||||
|
/tic 658726 sottoarea
|
||||||
|
/tic 658726 prodotto
|
||||||
|
/tic 658726 competenza
|
||||||
|
/tic 658726 cliente
|
||||||
|
/tic 658726 no_cliente
|
||||||
|
/tic 658726 filtri
|
||||||
|
/tic 658726 recenti 24
|
||||||
|
/tic 658726 codice
|
||||||
|
/tic 658726 media
|
||||||
|
/tic 658726 alta
|
||||||
|
```
|
||||||
|
|
||||||
|
Filter meanings:
|
||||||
|
|
||||||
|
- `area`: only suggestions in the same Area as the query ticket.
|
||||||
|
- `sottoarea`: only suggestions in the same Sottoarea as the query ticket.
|
||||||
|
- `prodotto`: only suggestions with the same Product.
|
||||||
|
- `competenza`: only suggestions with the same Competence.
|
||||||
|
- `cliente`: only suggestions from the same Client.
|
||||||
|
- `no_cliente`: exclude suggestions from the same Client.
|
||||||
|
- `filtri`: apply or reapply the user's saved Product/Competence/Area/Subarea filters.
|
||||||
|
- `recenti <mesi>`: only suggestions opened in the last N months.
|
||||||
|
- `codice`: require the same detected error/code token.
|
||||||
|
- `media`: require at least medium confidence.
|
||||||
|
- `alta`: require high confidence.
|
||||||
|
|
||||||
|
Explicit IDs are also supported:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/tic 658726 area 12
|
||||||
|
/tic 658726 sottoarea 44
|
||||||
|
/tic 658726 prodotto 24
|
||||||
|
/tic 658726 competenza 8
|
||||||
|
/tic 658726 cliente 1234
|
||||||
|
```
|
||||||
|
|
||||||
|
`/cerca <testo>`
|
||||||
|
|
||||||
|
Search similar solved tickets from free text, without needing a source ticket. Saved filters are applied automatically unless the command specifies an Area/Product/Competence/Client filter.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/cerca errore fiscality password non valida
|
||||||
|
/cerca --area 12 errore fiscality password non valida
|
||||||
|
/cerca --prodotto 24 --ultimi-mesi 18 errore importazione
|
||||||
|
/cerca --filtri --media errore stampa fattura
|
||||||
|
```
|
||||||
|
|
||||||
|
Supported `/cerca` flags:
|
||||||
|
|
||||||
|
- `--area <id>`
|
||||||
|
- `--sottoarea <id>`
|
||||||
|
- `--prodotto <id>`
|
||||||
|
- `--competenza <id>`
|
||||||
|
- `--cliente <id>`
|
||||||
|
- `--filtri`
|
||||||
|
- `--codice`
|
||||||
|
- `--ultimi-mesi <mesi>`
|
||||||
|
- `--media`
|
||||||
|
- `--alta`
|
||||||
|
|
||||||
|
## Inline result buttons
|
||||||
|
|
||||||
|
Every AI result includes inline buttons:
|
||||||
|
|
||||||
|
- `Dettaglio`: open the suggested ticket detail. For `/tic` searches, this also records weak positive feedback as `opened`.
|
||||||
|
- `Utile`: record useful feedback.
|
||||||
|
- `Non utile`: record negative feedback.
|
||||||
|
- `Preferito`: save the suggested ticket in your favorites and record positive feedback.
|
||||||
|
- `Altri risultati`: fetch the next page of results.
|
||||||
|
- `Solo area`, `Solo sottoarea`, `Solo prodotto`, `Solo competenza`, `Stesso cliente`, `Escludi cliente`: rerun the search with a stricter filter.
|
||||||
|
- `Recenti 24m`, `Stesso codice`, `Min media`, `Miei filtri`, `Reset`: rerun the search with the selected control.
|
||||||
|
|
||||||
|
Text feedback commands still work:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/utile_<query_ticket>_<suggested_ticket>
|
||||||
|
/non_utile_<query_ticket>_<suggested_ticket>
|
||||||
|
```
|
||||||
|
|
||||||
|
Feedback is used during future AI ranking. `utile`, `preferito`, and opened details count as positive feedback; `non_utile` counts as negative feedback.
|
||||||
|
|
||||||
|
## Ticket detail and favorites
|
||||||
|
|
||||||
|
`/Ticket_dettaglio_<ticket>`
|
||||||
|
|
||||||
|
Download and send the HTML detail for a ticket.
|
||||||
|
|
||||||
|
`/preferito_<ticket>`
|
||||||
|
|
||||||
|
Save a ticket in your favorites and notify the administrator.
|
||||||
|
|
||||||
|
`/preferiti`
|
||||||
|
|
||||||
|
Show your saved favorite tickets. The same list is available from the `💜 Preferiti` keyboard button.
|
||||||
|
|
||||||
|
## Saved filters
|
||||||
|
|
||||||
|
The main keyboard exposes:
|
||||||
|
|
||||||
|
- `🖍 Crea filtro x Competenze`
|
||||||
|
- `📦 Crea filtro x Prodotto`
|
||||||
|
- `👥 Crea filtro x Area`
|
||||||
|
- `👥 Crea filtro x Sott.Area`
|
||||||
|
- `📌 I mie filtri`
|
||||||
|
- `✖ Cancella filtro`
|
||||||
|
- `💜 Preferiti`
|
||||||
|
|
||||||
|
Automatic new-ticket notifications use saved filters with AND between different types and OR inside the same type. For example: one Area + one Competence + two Products means Area AND Competence AND (Product 1 OR Product 2).
|
||||||
|
|
||||||
|
Generated filter commands:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/_id_c_<competence_id>
|
||||||
|
/_id_p_<product_id>
|
||||||
|
/_id_area_<area_id>
|
||||||
|
/_id_suba_<subarea_id>
|
||||||
|
```
|
||||||
|
|
||||||
|
Generated delete commands:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/Competen_id_cf_<filter_id>
|
||||||
|
/Prodotto_id_cf_<filter_id>
|
||||||
|
/Area_id_cf_<filter_id>
|
||||||
|
/Sottoarea_id_cf_<filter_id>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notification controls
|
||||||
|
|
||||||
|
`/notifiche_status`
|
||||||
|
|
||||||
|
Show personal notification settings.
|
||||||
|
|
||||||
|
`/notifiche_on`
|
||||||
|
|
||||||
|
Resume personal notifications.
|
||||||
|
|
||||||
|
`/notifiche_off`
|
||||||
|
|
||||||
|
Pause personal notifications.
|
||||||
|
|
||||||
|
`/silenzio <ora_inizio> <ora_fine>`
|
||||||
|
|
||||||
|
Set quiet hours. Hours are 0-23.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/silenzio 22 7
|
||||||
|
```
|
||||||
|
|
||||||
|
`/silenzio_off`
|
||||||
|
|
||||||
|
Disable quiet hours.
|
||||||
|
|
||||||
|
`/digest <minuti>`
|
||||||
|
|
||||||
|
Send notifications at most once every N minutes.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/digest 30
|
||||||
|
```
|
||||||
|
|
||||||
|
`/digest_off`
|
||||||
|
|
||||||
|
Disable digest throttling.
|
||||||
|
|
||||||
|
`/gravita_alta_on`
|
||||||
|
|
||||||
|
Only notify tickets whose gravity text looks high/urgent/critical/blocking.
|
||||||
|
|
||||||
|
`/gravita_alta_off`
|
||||||
|
|
||||||
|
Notify all gravity levels again.
|
||||||
|
|
||||||
|
## Admin commands
|
||||||
|
|
||||||
|
`/Approval_<telegram_user_id>`
|
||||||
|
|
||||||
|
Approve a pending user. This command is restricted to administrators.
|
||||||
|
|
||||||
|
`/ai_stats`
|
||||||
|
|
||||||
|
Show indexed ticket count, search count, no-result count, average retrieval time, and feedback totals.
|
||||||
|
|
||||||
|
`/ai_no_result`
|
||||||
|
|
||||||
|
Show recent AI searches with zero results.
|
||||||
|
|
||||||
|
`/ai_negative`
|
||||||
|
|
||||||
|
Show recent negative feedback.
|
||||||
|
|
||||||
|
`/ai_top_useful`
|
||||||
|
|
||||||
|
Show tickets with the most positive feedback.
|
||||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM python:3.11.3-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY dependencies.txt .
|
||||||
|
RUN pip install --no-cache-dir -r dependencies.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["sh", "-c", "python ./api/bootstrap_db.py && python ./telepot/tele.py"]
|
||||||
414
api/ai_index.py
Normal file
414
api/ai_index.py
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from html import unescape
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import psycopg2
|
||||||
|
from psycopg2.extras import execute_values
|
||||||
|
|
||||||
|
|
||||||
|
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||||
|
CONN_DIR = ROOT_DIR / "conn"
|
||||||
|
if str(CONN_DIR) not in sys.path:
|
||||||
|
sys.path.insert(0, str(CONN_DIR))
|
||||||
|
|
||||||
|
import config
|
||||||
|
import mysql5
|
||||||
|
|
||||||
|
|
||||||
|
TAG_RE = re.compile(r"<[^>]+>")
|
||||||
|
SPACE_RE = re.compile(r"\s+")
|
||||||
|
CODE_RE = re.compile(r"\b[A-Z]{1,8}[-_/]?\d{2,}[A-Z0-9._/-]*\b|\b[A-Z0-9_]{3,}\.[A-Z0-9_.$-]+\b", re.IGNORECASE)
|
||||||
|
|
||||||
|
|
||||||
|
def get_pg_connection():
|
||||||
|
return psycopg2.connect(**config.POSTGRES_CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
def clean_text(value):
|
||||||
|
if value is None:
|
||||||
|
return ""
|
||||||
|
text = unescape(str(value))
|
||||||
|
text = TAG_RE.sub(" ", text)
|
||||||
|
text = text.replace("\x00", " ")
|
||||||
|
return SPACE_RE.sub(" ", text).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def short_text(value, max_len=420):
|
||||||
|
text = clean_text(value)
|
||||||
|
if len(text) <= max_len:
|
||||||
|
return text
|
||||||
|
return text[:max_len].rsplit(" ", 1)[0] + "..."
|
||||||
|
|
||||||
|
|
||||||
|
def extract_codes(*values):
|
||||||
|
codes = set()
|
||||||
|
for value in values:
|
||||||
|
for match in CODE_RE.findall(clean_text(value).upper()):
|
||||||
|
codes.add(match.strip(".,;:()[]{}"))
|
||||||
|
return sorted(code for code in codes if code)
|
||||||
|
|
||||||
|
|
||||||
|
def build_index_document(row):
|
||||||
|
subject = clean_text(row.get("subject"))
|
||||||
|
problem = clean_text(row.get("problem"))
|
||||||
|
solution = clean_text(row.get("solution"))
|
||||||
|
metadata = " ".join(
|
||||||
|
clean_text(row.get(name))
|
||||||
|
for name in ("competence", "product", "area", "subarea", "client", "gravity", "status", "program", "program_type")
|
||||||
|
if row.get(name) is not None
|
||||||
|
)
|
||||||
|
codes = extract_codes(subject, problem, solution, metadata)
|
||||||
|
search_text = " ".join(part for part in (subject, problem, solution, metadata, " ".join(codes)) if part)
|
||||||
|
return {
|
||||||
|
"ticket_id": int(row["ticket_id"]),
|
||||||
|
"subject_text": subject,
|
||||||
|
"problem_text": problem,
|
||||||
|
"solution_text": solution,
|
||||||
|
"solution_preview": short_text(solution),
|
||||||
|
"metadata_text": metadata,
|
||||||
|
"search_text": search_text,
|
||||||
|
"codes": codes,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_ai_schema():
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
cursor.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm")
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS ticket_ai_index (
|
||||||
|
ticket_id BIGINT PRIMARY KEY,
|
||||||
|
subject_text TEXT NOT NULL DEFAULT '',
|
||||||
|
problem_text TEXT NOT NULL DEFAULT '',
|
||||||
|
solution_text TEXT NOT NULL DEFAULT '',
|
||||||
|
solution_preview TEXT NOT NULL DEFAULT '',
|
||||||
|
metadata_text TEXT NOT NULL DEFAULT '',
|
||||||
|
search_text TEXT NOT NULL DEFAULT '',
|
||||||
|
codes TEXT[] NOT NULL DEFAULT '{}',
|
||||||
|
competence_id INTEGER,
|
||||||
|
competence TEXT,
|
||||||
|
product_id INTEGER,
|
||||||
|
product TEXT,
|
||||||
|
area_id INTEGER,
|
||||||
|
area TEXT,
|
||||||
|
subarea_id INTEGER,
|
||||||
|
subarea TEXT,
|
||||||
|
client_id INTEGER,
|
||||||
|
client TEXT,
|
||||||
|
gravity_id INTEGER,
|
||||||
|
gravity TEXT,
|
||||||
|
status_id INTEGER,
|
||||||
|
status TEXT,
|
||||||
|
opened_at TIMESTAMP,
|
||||||
|
closed_at TIMESTAMP,
|
||||||
|
program TEXT,
|
||||||
|
program_type TEXT,
|
||||||
|
version_id INTEGER,
|
||||||
|
patch_id INTEGER,
|
||||||
|
classification_id INTEGER,
|
||||||
|
os_id INTEGER,
|
||||||
|
search_vector TSVECTOR,
|
||||||
|
source_updated_at TIMESTAMP,
|
||||||
|
indexed_at TIMESTAMP NOT NULL DEFAULT now()
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE OR REPLACE FUNCTION ticket_ai_index_search_vector_update()
|
||||||
|
RETURNS trigger AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW.search_vector :=
|
||||||
|
setweight(to_tsvector('simple', COALESCE(NEW.subject_text, '')), 'A') ||
|
||||||
|
setweight(to_tsvector('simple', COALESCE(NEW.problem_text, '')), 'A') ||
|
||||||
|
setweight(to_tsvector('simple', COALESCE(NEW.solution_text, '')), 'B') ||
|
||||||
|
setweight(to_tsvector('simple', COALESCE(NEW.metadata_text, '')), 'C') ||
|
||||||
|
setweight(to_tsvector('simple', array_to_string(COALESCE(NEW.codes, '{}'), ' ')), 'A');
|
||||||
|
RETURN NEW;
|
||||||
|
END
|
||||||
|
$$ LANGUAGE plpgsql
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
DROP TRIGGER IF EXISTS ticket_ai_index_search_vector_trigger ON ticket_ai_index
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TRIGGER ticket_ai_index_search_vector_trigger
|
||||||
|
BEFORE INSERT OR UPDATE ON ticket_ai_index
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION ticket_ai_index_search_vector_update()
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_search_vector_idx ON ticket_ai_index USING GIN (search_vector)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_problem_trgm_idx ON ticket_ai_index USING GIN (problem_text gin_trgm_ops)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_subject_trgm_idx ON ticket_ai_index USING GIN (subject_text gin_trgm_ops)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_codes_idx ON ticket_ai_index USING GIN (codes)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_product_idx ON ticket_ai_index (product_id)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_area_idx ON ticket_ai_index (area_id)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_subarea_idx ON ticket_ai_index (subarea_id)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_competence_idx ON ticket_ai_index (competence_id)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_index_opened_idx ON ticket_ai_index (opened_at)")
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS ticket_ai_query_log (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
user_id BIGINT,
|
||||||
|
query_ticket_id BIGINT NOT NULL,
|
||||||
|
suggested_ticket_id BIGINT NOT NULL,
|
||||||
|
rank INTEGER NOT NULL,
|
||||||
|
total_score DOUBLE PRECISION NOT NULL,
|
||||||
|
lexical_score DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
|
trigram_score DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
|
code_score DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
|
metadata_score DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
|
feedback_score DOUBLE PRECISION NOT NULL DEFAULT 0,
|
||||||
|
confidence TEXT NOT NULL,
|
||||||
|
query_text TEXT NOT NULL,
|
||||||
|
reasons TEXT[] NOT NULL DEFAULT '{}'
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_query_log_query_idx ON ticket_ai_query_log (query_ticket_id)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_query_log_suggestion_idx ON ticket_ai_query_log (suggested_ticket_id)")
|
||||||
|
cursor.execute("ALTER TABLE ticket_ai_query_log ADD COLUMN IF NOT EXISTS code_score DOUBLE PRECISION NOT NULL DEFAULT 0")
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS ticket_ai_search_log (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
user_id BIGINT,
|
||||||
|
query_kind TEXT NOT NULL DEFAULT 'ticket',
|
||||||
|
query_ticket_id BIGINT,
|
||||||
|
query_text TEXT NOT NULL DEFAULT '',
|
||||||
|
filters JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||||
|
result_count INTEGER NOT NULL DEFAULT 0,
|
||||||
|
elapsed_ms INTEGER NOT NULL DEFAULT 0
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_search_log_created_idx ON ticket_ai_search_log (created_at)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_search_log_result_idx ON ticket_ai_search_log (result_count)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_search_log_ticket_idx ON ticket_ai_search_log (query_ticket_id)")
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS ticket_ai_feedback (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
user_id BIGINT,
|
||||||
|
query_ticket_id BIGINT NOT NULL,
|
||||||
|
suggested_ticket_id BIGINT NOT NULL,
|
||||||
|
feedback TEXT NOT NULL CHECK (feedback IN ('useful', 'not_useful', 'favorite', 'opened')),
|
||||||
|
note TEXT
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_feedback_pair_idx ON ticket_ai_feedback (query_ticket_id, suggested_ticket_id)")
|
||||||
|
cursor.execute("CREATE INDEX IF NOT EXISTS ticket_ai_feedback_suggestion_idx ON ticket_ai_feedback (suggested_ticket_id)")
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE MATERIALIZED VIEW IF NOT EXISTS ticket_ai_feedback_summary AS
|
||||||
|
SELECT
|
||||||
|
suggested_ticket_id AS ticket_id,
|
||||||
|
SUM(CASE WHEN feedback IN ('useful', 'favorite', 'opened') THEN 1 ELSE 0 END) AS positive_count,
|
||||||
|
SUM(CASE WHEN feedback = 'not_useful' THEN 1 ELSE 0 END) AS negative_count
|
||||||
|
FROM ticket_ai_feedback
|
||||||
|
GROUP BY suggested_ticket_id
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
cursor.execute("CREATE UNIQUE INDEX IF NOT EXISTS ticket_ai_feedback_summary_ticket_idx ON ticket_ai_feedback_summary (ticket_id)")
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE IF NOT EXISTS ticket_bot_user_settings (
|
||||||
|
user_id BIGINT PRIMARY KEY,
|
||||||
|
notifications_enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
quiet_start_hour INTEGER,
|
||||||
|
quiet_end_hour INTEGER,
|
||||||
|
digest_minutes INTEGER NOT NULL DEFAULT 0,
|
||||||
|
high_gravity_only BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
last_notification_at TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
CHECK (quiet_start_hour IS NULL OR (quiet_start_hour >= 0 AND quiet_start_hour <= 23)),
|
||||||
|
CHECK (quiet_end_hour IS NULL OR (quiet_end_hour >= 0 AND quiet_end_hour <= 23)),
|
||||||
|
CHECK (digest_minutes >= 0)
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
def _row_values(row):
|
||||||
|
doc = build_index_document(row)
|
||||||
|
return (
|
||||||
|
doc["ticket_id"],
|
||||||
|
doc["subject_text"],
|
||||||
|
doc["problem_text"],
|
||||||
|
doc["solution_text"],
|
||||||
|
doc["solution_preview"],
|
||||||
|
doc["metadata_text"],
|
||||||
|
doc["search_text"],
|
||||||
|
doc["codes"],
|
||||||
|
row.get("competence_id"),
|
||||||
|
row.get("competence"),
|
||||||
|
row.get("product_id"),
|
||||||
|
row.get("product"),
|
||||||
|
row.get("area_id"),
|
||||||
|
row.get("area"),
|
||||||
|
row.get("subarea_id"),
|
||||||
|
row.get("subarea"),
|
||||||
|
row.get("client_id"),
|
||||||
|
row.get("client"),
|
||||||
|
row.get("gravity_id"),
|
||||||
|
row.get("gravity"),
|
||||||
|
row.get("status_id"),
|
||||||
|
row.get("status"),
|
||||||
|
row.get("opened_at"),
|
||||||
|
row.get("closed_at"),
|
||||||
|
row.get("program"),
|
||||||
|
row.get("program_type"),
|
||||||
|
row.get("version_id"),
|
||||||
|
row.get("patch_id"),
|
||||||
|
row.get("classification_id"),
|
||||||
|
row.get("os_id"),
|
||||||
|
datetime.utcnow(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def upsert_ticket_batch(rows):
|
||||||
|
if not rows:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
values = [_row_values(row) for row in rows]
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
execute_values(
|
||||||
|
cursor,
|
||||||
|
"""
|
||||||
|
INSERT INTO ticket_ai_index (
|
||||||
|
ticket_id,
|
||||||
|
subject_text,
|
||||||
|
problem_text,
|
||||||
|
solution_text,
|
||||||
|
solution_preview,
|
||||||
|
metadata_text,
|
||||||
|
search_text,
|
||||||
|
codes,
|
||||||
|
competence_id,
|
||||||
|
competence,
|
||||||
|
product_id,
|
||||||
|
product,
|
||||||
|
area_id,
|
||||||
|
area,
|
||||||
|
subarea_id,
|
||||||
|
subarea,
|
||||||
|
client_id,
|
||||||
|
client,
|
||||||
|
gravity_id,
|
||||||
|
gravity,
|
||||||
|
status_id,
|
||||||
|
status,
|
||||||
|
opened_at,
|
||||||
|
closed_at,
|
||||||
|
program,
|
||||||
|
program_type,
|
||||||
|
version_id,
|
||||||
|
patch_id,
|
||||||
|
classification_id,
|
||||||
|
os_id,
|
||||||
|
source_updated_at
|
||||||
|
) VALUES %s
|
||||||
|
ON CONFLICT (ticket_id) DO UPDATE SET
|
||||||
|
subject_text = EXCLUDED.subject_text,
|
||||||
|
problem_text = EXCLUDED.problem_text,
|
||||||
|
solution_text = EXCLUDED.solution_text,
|
||||||
|
solution_preview = EXCLUDED.solution_preview,
|
||||||
|
metadata_text = EXCLUDED.metadata_text,
|
||||||
|
search_text = EXCLUDED.search_text,
|
||||||
|
codes = EXCLUDED.codes,
|
||||||
|
competence_id = EXCLUDED.competence_id,
|
||||||
|
competence = EXCLUDED.competence,
|
||||||
|
product_id = EXCLUDED.product_id,
|
||||||
|
product = EXCLUDED.product,
|
||||||
|
area_id = EXCLUDED.area_id,
|
||||||
|
area = EXCLUDED.area,
|
||||||
|
subarea_id = EXCLUDED.subarea_id,
|
||||||
|
subarea = EXCLUDED.subarea,
|
||||||
|
client_id = EXCLUDED.client_id,
|
||||||
|
client = EXCLUDED.client,
|
||||||
|
gravity_id = EXCLUDED.gravity_id,
|
||||||
|
gravity = EXCLUDED.gravity,
|
||||||
|
status_id = EXCLUDED.status_id,
|
||||||
|
status = EXCLUDED.status,
|
||||||
|
opened_at = EXCLUDED.opened_at,
|
||||||
|
closed_at = EXCLUDED.closed_at,
|
||||||
|
program = EXCLUDED.program,
|
||||||
|
program_type = EXCLUDED.program_type,
|
||||||
|
version_id = EXCLUDED.version_id,
|
||||||
|
patch_id = EXCLUDED.patch_id,
|
||||||
|
classification_id = EXCLUDED.classification_id,
|
||||||
|
os_id = EXCLUDED.os_id,
|
||||||
|
source_updated_at = EXCLUDED.source_updated_at,
|
||||||
|
indexed_at = now()
|
||||||
|
""",
|
||||||
|
values,
|
||||||
|
page_size=500,
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return len(rows)
|
||||||
|
|
||||||
|
|
||||||
|
def rebuild_index(batch_size=1000, max_rows=None):
|
||||||
|
ensure_ai_schema()
|
||||||
|
last_ticket = 0
|
||||||
|
indexed = 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
rows = mysql5.fetch_solved_ticket_batch(last_ticket=last_ticket, limit=batch_size)
|
||||||
|
if not rows:
|
||||||
|
break
|
||||||
|
upsert_ticket_batch(rows)
|
||||||
|
indexed += len(rows)
|
||||||
|
last_ticket = int(rows[-1]["ticket_id"])
|
||||||
|
print(f"Indexed {indexed} tickets, last ticket {last_ticket}")
|
||||||
|
if max_rows is not None and indexed >= max_rows:
|
||||||
|
break
|
||||||
|
|
||||||
|
refresh_feedback_summary()
|
||||||
|
return indexed
|
||||||
|
|
||||||
|
|
||||||
|
def refresh_feedback_summary():
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("REFRESH MATERIALIZED VIEW ticket_ai_feedback_summary")
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
batch_size = int(sys.argv[1]) if len(sys.argv) > 1 else 1000
|
||||||
|
max_rows = int(sys.argv[2]) if len(sys.argv) > 2 else None
|
||||||
|
print(f"Starting AI index rebuild with batch_size={batch_size}, max_rows={max_rows}")
|
||||||
|
total = rebuild_index(batch_size=batch_size, max_rows=max_rows)
|
||||||
|
print(f"Finished indexing {total} solved tickets")
|
||||||
926
api/ai_retriever.py
Normal file
926
api/ai_retriever.py
Normal file
@@ -0,0 +1,926 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from difflib import SequenceMatcher
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
|
import psycopg2
|
||||||
|
from psycopg2.extras import DictCursor, Json
|
||||||
|
|
||||||
|
|
||||||
|
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||||
|
CONN_DIR = ROOT_DIR / "conn"
|
||||||
|
if str(CONN_DIR) not in sys.path:
|
||||||
|
sys.path.insert(0, str(CONN_DIR))
|
||||||
|
|
||||||
|
import config
|
||||||
|
import mysql5
|
||||||
|
from ai_index import clean_text, ensure_ai_schema, extract_codes, refresh_feedback_summary
|
||||||
|
|
||||||
|
|
||||||
|
MIN_SCORE = 0.07
|
||||||
|
CONFIDENCE_MIN_SCORE = {
|
||||||
|
"bassa": MIN_SCORE,
|
||||||
|
"media": 0.18,
|
||||||
|
"alta": 0.35,
|
||||||
|
}
|
||||||
|
DEFAULT_LIMIT = 5
|
||||||
|
DIVERSITY_POOL_MULTIPLIER = 8
|
||||||
|
MAX_SOLUTION_TOKEN_SIMILARITY = 0.62
|
||||||
|
MAX_SOLUTION_TOKEN_OVERLAP = 0.65
|
||||||
|
MAX_SOLUTION_TEXT_SIMILARITY = 0.70
|
||||||
|
_SCHEMA_READY = False
|
||||||
|
TOKEN_RE = re.compile(r"\b\w{3,}\b", re.IGNORECASE)
|
||||||
|
SIGNATURE_SPACE_RE = re.compile(r"\s+")
|
||||||
|
|
||||||
|
|
||||||
|
def get_pg_connection():
|
||||||
|
return psycopg2.connect(**config.POSTGRES_CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_runtime_schema():
|
||||||
|
global _SCHEMA_READY
|
||||||
|
if not _SCHEMA_READY:
|
||||||
|
ensure_ai_schema()
|
||||||
|
_SCHEMA_READY = True
|
||||||
|
|
||||||
|
|
||||||
|
def _id_value(value):
|
||||||
|
if value is None or value == "":
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return int(value)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_int_list(value):
|
||||||
|
if value is None:
|
||||||
|
return []
|
||||||
|
if not isinstance(value, (list, tuple, set)):
|
||||||
|
value = [value]
|
||||||
|
|
||||||
|
values = []
|
||||||
|
for item in value:
|
||||||
|
parsed = _id_value(item)
|
||||||
|
if parsed is not None and parsed not in values:
|
||||||
|
values.append(parsed)
|
||||||
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
def _query_text(ticket):
|
||||||
|
parts = [
|
||||||
|
ticket.get("subject"),
|
||||||
|
ticket.get("problem"),
|
||||||
|
ticket.get("product"),
|
||||||
|
ticket.get("area"),
|
||||||
|
ticket.get("subarea"),
|
||||||
|
ticket.get("competence"),
|
||||||
|
ticket.get("program"),
|
||||||
|
ticket.get("program_type"),
|
||||||
|
]
|
||||||
|
codes = extract_codes(*parts)
|
||||||
|
cleaned = clean_text(" ".join(str(p) for p in parts if p))
|
||||||
|
return " ".join(part for part in (cleaned, " ".join(codes)) if part)
|
||||||
|
|
||||||
|
|
||||||
|
def _confidence(score):
|
||||||
|
if score >= CONFIDENCE_MIN_SCORE["alta"]:
|
||||||
|
return "Alta"
|
||||||
|
if score >= CONFIDENCE_MIN_SCORE["media"]:
|
||||||
|
return "Media"
|
||||||
|
return "Bassa"
|
||||||
|
|
||||||
|
|
||||||
|
def _min_score_from_filters(filters):
|
||||||
|
filters = filters or {}
|
||||||
|
if filters.get("min_score") is not None:
|
||||||
|
try:
|
||||||
|
return float(filters["min_score"])
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return MIN_SCORE
|
||||||
|
|
||||||
|
confidence = str(filters.get("min_confidence") or "").lower()
|
||||||
|
return CONFIDENCE_MIN_SCORE.get(confidence, MIN_SCORE)
|
||||||
|
|
||||||
|
|
||||||
|
def _solution_tokens(solution):
|
||||||
|
text = clean_text(solution).lower()
|
||||||
|
return set(TOKEN_RE.findall(text))
|
||||||
|
|
||||||
|
|
||||||
|
def _solution_signature(solution):
|
||||||
|
text = clean_text(solution).lower()
|
||||||
|
text = "".join(
|
||||||
|
char for char in unicodedata.normalize("NFKD", text)
|
||||||
|
if not unicodedata.combining(char)
|
||||||
|
)
|
||||||
|
text = re.sub(r"\b(gentile|buongiorno|ciao|salve)\b", " ", text)
|
||||||
|
text = re.sub(r"\b(cliente|mauro|martina|lisa|cinzia|nadia)\b", " ", text)
|
||||||
|
return SIGNATURE_SPACE_RE.sub(" ", text).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def _jaccard_similarity(left, right):
|
||||||
|
if not left or not right:
|
||||||
|
return 0
|
||||||
|
return len(left & right) / len(left | right)
|
||||||
|
|
||||||
|
|
||||||
|
def _overlap_similarity(left, right):
|
||||||
|
if not left or not right:
|
||||||
|
return 0
|
||||||
|
return len(left & right) / min(len(left), len(right))
|
||||||
|
|
||||||
|
|
||||||
|
def _matches_filter(row, filters, key, row_key):
|
||||||
|
values = _normalize_int_list((filters or {}).get(key))
|
||||||
|
return values and row.get(row_key) in values
|
||||||
|
|
||||||
|
|
||||||
|
def _passes_strict_metadata_filters(row, filters):
|
||||||
|
filters = filters or {}
|
||||||
|
filter_columns = (
|
||||||
|
("product_ids", "product_id"),
|
||||||
|
("area_ids", "area_id"),
|
||||||
|
("subarea_ids", "subarea_id"),
|
||||||
|
("competence_ids", "competence_id"),
|
||||||
|
("client_ids", "client_id"),
|
||||||
|
)
|
||||||
|
for key, column in filter_columns:
|
||||||
|
values = _normalize_int_list(filters.get(key))
|
||||||
|
if not values:
|
||||||
|
values = _normalize_int_list(filters.get(column))
|
||||||
|
if values and row.get(column) not in values:
|
||||||
|
return False
|
||||||
|
|
||||||
|
excluded_clients = _normalize_int_list(filters.get("exclude_client_ids"))
|
||||||
|
if not excluded_clients:
|
||||||
|
excluded_clients = _normalize_int_list(filters.get("exclude_client_id"))
|
||||||
|
if excluded_clients and row.get("client_id") in excluded_clients:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _diverse_suggestions(rows, query_ticket, limit, filters=None):
|
||||||
|
selected = []
|
||||||
|
selected_solution_tokens = []
|
||||||
|
selected_solution_signatures = []
|
||||||
|
duplicates_skipped = 0
|
||||||
|
min_score = _min_score_from_filters(filters)
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
row_dict = dict(row)
|
||||||
|
if not _passes_strict_metadata_filters(row_dict, filters):
|
||||||
|
continue
|
||||||
|
if row_dict["total_score"] < min_score:
|
||||||
|
continue
|
||||||
|
|
||||||
|
solution_tokens = _solution_tokens(row_dict.get("solution_preview"))
|
||||||
|
solution_signature = _solution_signature(row_dict.get("solution_preview"))
|
||||||
|
is_duplicate = any(
|
||||||
|
_jaccard_similarity(solution_tokens, existing_tokens) >= MAX_SOLUTION_TOKEN_SIMILARITY
|
||||||
|
or _overlap_similarity(solution_tokens, existing_tokens) >= MAX_SOLUTION_TOKEN_OVERLAP
|
||||||
|
or SequenceMatcher(None, solution_signature, existing_signature).ratio() >= MAX_SOLUTION_TEXT_SIMILARITY
|
||||||
|
for existing_tokens, existing_signature in zip(selected_solution_tokens, selected_solution_signatures)
|
||||||
|
)
|
||||||
|
if is_duplicate:
|
||||||
|
duplicates_skipped += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
row_dict["confidence"] = _confidence(row_dict["total_score"])
|
||||||
|
row_dict["reasons"] = _reasons(row_dict, query_ticket, filters)
|
||||||
|
row_dict["duplicates_skipped_before"] = duplicates_skipped
|
||||||
|
selected.append(row_dict)
|
||||||
|
selected_solution_tokens.append(solution_tokens)
|
||||||
|
selected_solution_signatures.append(solution_signature)
|
||||||
|
|
||||||
|
if len(selected) >= limit:
|
||||||
|
break
|
||||||
|
|
||||||
|
return selected
|
||||||
|
|
||||||
|
|
||||||
|
def _reasons(row, query_ticket=None, filters=None):
|
||||||
|
query_ticket = query_ticket or {}
|
||||||
|
filters = filters or {}
|
||||||
|
reasons = []
|
||||||
|
|
||||||
|
if row["lexical_score"] >= 0.08:
|
||||||
|
reasons.append("termini esatti")
|
||||||
|
if row["trigram_score"] >= 0.12:
|
||||||
|
reasons.append("testo simile")
|
||||||
|
if row["code_score"] > 0:
|
||||||
|
reasons.append("stesso codice")
|
||||||
|
|
||||||
|
if _matches_filter(row, filters, "product_ids", "product_id"):
|
||||||
|
reasons.append("filtro prodotto")
|
||||||
|
elif row["product_id"] is not None and row["product_id"] == _id_value(query_ticket.get("product_id")):
|
||||||
|
reasons.append("stesso prodotto")
|
||||||
|
|
||||||
|
if _matches_filter(row, filters, "subarea_ids", "subarea_id"):
|
||||||
|
reasons.append("filtro sottoarea")
|
||||||
|
elif row["subarea_id"] is not None and row["subarea_id"] == _id_value(query_ticket.get("subarea_id")):
|
||||||
|
reasons.append("stessa sottoarea")
|
||||||
|
elif _matches_filter(row, filters, "area_ids", "area_id"):
|
||||||
|
reasons.append("filtro area")
|
||||||
|
elif row["area_id"] is not None and row["area_id"] == _id_value(query_ticket.get("area_id")):
|
||||||
|
reasons.append("stessa area")
|
||||||
|
|
||||||
|
if _matches_filter(row, filters, "competence_ids", "competence_id"):
|
||||||
|
reasons.append("filtro competenza")
|
||||||
|
elif row["competence_id"] is not None and row["competence_id"] == _id_value(query_ticket.get("competence_id")):
|
||||||
|
reasons.append("stessa competenza")
|
||||||
|
|
||||||
|
if _matches_filter(row, filters, "client_ids", "client_id"):
|
||||||
|
reasons.append("stesso cliente")
|
||||||
|
if row["feedback_score"] > 0:
|
||||||
|
reasons.append("feedback positivo")
|
||||||
|
if filters.get("recent_months"):
|
||||||
|
reasons.append("periodo recente")
|
||||||
|
if not reasons:
|
||||||
|
reasons.append("somiglianza generale")
|
||||||
|
return reasons[:5]
|
||||||
|
|
||||||
|
|
||||||
|
def _format_date(value):
|
||||||
|
if not value:
|
||||||
|
return "-"
|
||||||
|
if hasattr(value, "strftime"):
|
||||||
|
return value.strftime("%Y-%m-%d")
|
||||||
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
def _format_suggestion(query_ticket_id, suggestion, rank):
|
||||||
|
ticket_id = suggestion["ticket_id"]
|
||||||
|
link = f"https://tsnew.sanmarcoweb.com/it/ticket/index/index/operation/view/id/{ticket_id}"
|
||||||
|
product = suggestion.get("product") or "-"
|
||||||
|
area = suggestion.get("area") or "-"
|
||||||
|
subarea = suggestion.get("subarea") or "-"
|
||||||
|
competence = suggestion.get("competence") or "-"
|
||||||
|
client = suggestion.get("client") or "-"
|
||||||
|
confidence = suggestion["confidence"]
|
||||||
|
reasons = ", ".join(suggestion["reasons"])
|
||||||
|
solution = suggestion.get("solution_preview") or "Soluzione non disponibile"
|
||||||
|
diversity_note = ""
|
||||||
|
if suggestion.get("duplicates_skipped_before"):
|
||||||
|
diversity_note = f"Alternative simili saltate: {suggestion['duplicates_skipped_before']}\n"
|
||||||
|
|
||||||
|
feedback_line = ""
|
||||||
|
if query_ticket_id:
|
||||||
|
feedback_line = f"Feedback: /utile_{query_ticket_id}_{ticket_id} /non_utile_{query_ticket_id}_{ticket_id}\n"
|
||||||
|
|
||||||
|
return (
|
||||||
|
f"\n\n----- {rank}. Confidenza {confidence} -----\n"
|
||||||
|
f"[ /Ticket_dettaglio_{ticket_id} ]\n"
|
||||||
|
f"{link}\n"
|
||||||
|
f"Cliente: {client}\n"
|
||||||
|
f"Prodotto: {product} | Competenza: {competence}\n"
|
||||||
|
f"Area: {area} | Sottoarea: {subarea}\n"
|
||||||
|
f"Apertura: {_format_date(suggestion.get('opened_at'))}\n"
|
||||||
|
f"Perche: {reasons}\n"
|
||||||
|
f"{diversity_note}"
|
||||||
|
f"Score: {suggestion['total_score']:.3f}\n"
|
||||||
|
f"SOLUZIONE: {solution}\n"
|
||||||
|
f"{feedback_line}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _has_metadata_filters(filters):
|
||||||
|
filters = filters or {}
|
||||||
|
return any(
|
||||||
|
_normalize_int_list(filters.get(key))
|
||||||
|
for key in ("product_ids", "area_ids", "subarea_ids", "competence_ids", "client_ids")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _metadata_candidate_clause(ticket, filters=None):
|
||||||
|
clauses = []
|
||||||
|
params = {}
|
||||||
|
for field in ("product_id", "area_id", "subarea_id", "competence_id"):
|
||||||
|
value = _id_value((ticket or {}).get(field))
|
||||||
|
params[field] = value
|
||||||
|
if value is not None:
|
||||||
|
clauses.append(f"i.{field} = %({field})s")
|
||||||
|
if _has_metadata_filters(filters):
|
||||||
|
clauses.append("TRUE")
|
||||||
|
if not clauses:
|
||||||
|
clauses.append("FALSE")
|
||||||
|
return " OR ".join(clauses), params
|
||||||
|
|
||||||
|
|
||||||
|
def _strict_filter_clause(filters):
|
||||||
|
filters = filters or {}
|
||||||
|
clauses = []
|
||||||
|
params = {}
|
||||||
|
|
||||||
|
filter_columns = (
|
||||||
|
("product_ids", "product_id"),
|
||||||
|
("area_ids", "area_id"),
|
||||||
|
("subarea_ids", "subarea_id"),
|
||||||
|
("competence_ids", "competence_id"),
|
||||||
|
("client_ids", "client_id"),
|
||||||
|
)
|
||||||
|
for key, column in filter_columns:
|
||||||
|
values = _normalize_int_list(filters.get(key))
|
||||||
|
if not values:
|
||||||
|
values = _normalize_int_list(filters.get(column))
|
||||||
|
if values:
|
||||||
|
clauses.append(f"i.{column} = ANY(%({key})s::int[])")
|
||||||
|
params[key] = values
|
||||||
|
|
||||||
|
excluded_clients = _normalize_int_list(filters.get("exclude_client_ids"))
|
||||||
|
if not excluded_clients:
|
||||||
|
excluded_clients = _normalize_int_list(filters.get("exclude_client_id"))
|
||||||
|
if excluded_clients:
|
||||||
|
clauses.append("NOT (i.client_id = ANY(%(exclude_client_ids)s::int[]))")
|
||||||
|
params["exclude_client_ids"] = excluded_clients
|
||||||
|
|
||||||
|
if filters.get("require_code_match"):
|
||||||
|
clauses.append("i.codes && %(query_codes)s::text[]")
|
||||||
|
|
||||||
|
recent_months = _id_value(filters.get("recent_months"))
|
||||||
|
if recent_months is not None and recent_months > 0:
|
||||||
|
clauses.append("i.opened_at >= now() - (%(recent_days)s::int * interval '1 day')")
|
||||||
|
params["recent_days"] = recent_months * 31
|
||||||
|
|
||||||
|
return " AND ".join(clauses) if clauses else "TRUE", params
|
||||||
|
|
||||||
|
|
||||||
|
def _safe_filters(filters):
|
||||||
|
safe = {}
|
||||||
|
for key, value in (filters or {}).items():
|
||||||
|
if value is None or value is False or value == []:
|
||||||
|
continue
|
||||||
|
if isinstance(value, (list, tuple, set)):
|
||||||
|
safe[key] = list(value)
|
||||||
|
else:
|
||||||
|
safe[key] = value
|
||||||
|
return safe
|
||||||
|
|
||||||
|
|
||||||
|
def _search(query_kind, query_text, query_ticket_id=None, query_ticket=None, user_id=None, limit=DEFAULT_LIMIT, offset=0, filters=None, log_results=True):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
query_text = clean_text(query_text)
|
||||||
|
if not query_text:
|
||||||
|
return []
|
||||||
|
|
||||||
|
query_ticket = query_ticket or {}
|
||||||
|
filters = filters or {}
|
||||||
|
limit = max(int(limit or DEFAULT_LIMIT), 1)
|
||||||
|
offset = max(int(offset or 0), 0)
|
||||||
|
pool_target = offset + limit
|
||||||
|
query_codes = extract_codes(query_text)
|
||||||
|
metadata_clause, metadata_params = _metadata_candidate_clause(query_ticket, filters)
|
||||||
|
strict_clause, strict_params = _strict_filter_clause(filters)
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"query_ticket_id": int(query_ticket_id) if query_ticket_id is not None else None,
|
||||||
|
"query_text": query_text,
|
||||||
|
"problem_text": clean_text(query_ticket.get("problem") or query_text),
|
||||||
|
"subject_text": clean_text(query_ticket.get("subject") or query_text),
|
||||||
|
"candidate_limit": max(pool_target * 50, 250),
|
||||||
|
"final_limit": max(pool_target * DIVERSITY_POOL_MULTIPLIER * 2, 40),
|
||||||
|
"query_product_id": _id_value(query_ticket.get("product_id")),
|
||||||
|
"query_area_id": _id_value(query_ticket.get("area_id")),
|
||||||
|
"query_subarea_id": _id_value(query_ticket.get("subarea_id")),
|
||||||
|
"query_competence_id": _id_value(query_ticket.get("competence_id")),
|
||||||
|
"query_codes": query_codes,
|
||||||
|
}
|
||||||
|
params.update(metadata_params)
|
||||||
|
params.update(strict_params)
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
WITH q AS (
|
||||||
|
SELECT websearch_to_tsquery('simple', %(query_text)s) AS tsq
|
||||||
|
),
|
||||||
|
lexical_candidates AS (
|
||||||
|
SELECT i.ticket_id
|
||||||
|
FROM ticket_ai_index i, q
|
||||||
|
WHERE (%(query_ticket_id)s IS NULL OR i.ticket_id <> %(query_ticket_id)s)
|
||||||
|
AND ({strict_clause})
|
||||||
|
AND i.search_vector @@ q.tsq
|
||||||
|
ORDER BY ts_rank_cd(i.search_vector, q.tsq) DESC
|
||||||
|
LIMIT %(candidate_limit)s
|
||||||
|
),
|
||||||
|
metadata_candidates AS (
|
||||||
|
SELECT i.ticket_id
|
||||||
|
FROM ticket_ai_index i
|
||||||
|
WHERE (%(query_ticket_id)s IS NULL OR i.ticket_id <> %(query_ticket_id)s)
|
||||||
|
AND ({strict_clause})
|
||||||
|
AND ({metadata_clause})
|
||||||
|
ORDER BY i.opened_at DESC NULLS LAST
|
||||||
|
LIMIT %(candidate_limit)s
|
||||||
|
),
|
||||||
|
code_candidates AS (
|
||||||
|
SELECT i.ticket_id
|
||||||
|
FROM ticket_ai_index i
|
||||||
|
WHERE (%(query_ticket_id)s IS NULL OR i.ticket_id <> %(query_ticket_id)s)
|
||||||
|
AND ({strict_clause})
|
||||||
|
AND i.codes && %(query_codes)s::text[]
|
||||||
|
ORDER BY i.opened_at DESC NULLS LAST
|
||||||
|
LIMIT %(candidate_limit)s
|
||||||
|
),
|
||||||
|
candidate_ids AS (
|
||||||
|
SELECT ticket_id FROM lexical_candidates
|
||||||
|
UNION
|
||||||
|
SELECT ticket_id FROM code_candidates
|
||||||
|
UNION
|
||||||
|
SELECT ticket_id FROM metadata_candidates
|
||||||
|
),
|
||||||
|
scored AS (
|
||||||
|
SELECT
|
||||||
|
i.ticket_id,
|
||||||
|
i.subject_text,
|
||||||
|
i.problem_text,
|
||||||
|
i.solution_preview,
|
||||||
|
i.competence_id,
|
||||||
|
i.competence,
|
||||||
|
i.product_id,
|
||||||
|
i.product,
|
||||||
|
i.area_id,
|
||||||
|
i.area,
|
||||||
|
i.subarea_id,
|
||||||
|
i.subarea,
|
||||||
|
i.client_id,
|
||||||
|
i.client,
|
||||||
|
i.opened_at,
|
||||||
|
ts_rank_cd(i.search_vector, q.tsq) AS lexical_score,
|
||||||
|
GREATEST(
|
||||||
|
similarity(i.problem_text, %(problem_text)s),
|
||||||
|
similarity(i.subject_text, %(subject_text)s)
|
||||||
|
) AS trigram_score,
|
||||||
|
CASE WHEN i.codes && %(query_codes)s::text[] THEN 0.18 ELSE 0 END AS code_score,
|
||||||
|
(
|
||||||
|
CASE WHEN i.product_id IS NOT DISTINCT FROM %(query_product_id)s THEN 0.045 ELSE 0 END +
|
||||||
|
CASE WHEN i.subarea_id IS NOT DISTINCT FROM %(query_subarea_id)s THEN 0.035 ELSE 0 END +
|
||||||
|
CASE WHEN i.area_id IS NOT DISTINCT FROM %(query_area_id)s THEN 0.020 ELSE 0 END +
|
||||||
|
CASE WHEN i.competence_id IS NOT DISTINCT FROM %(query_competence_id)s THEN 0.015 ELSE 0 END
|
||||||
|
) AS metadata_score,
|
||||||
|
LEAST(
|
||||||
|
GREATEST(COALESCE(fs.positive_count, 0) - COALESCE(fs.negative_count, 0), 0) * 0.015,
|
||||||
|
0.12
|
||||||
|
) AS feedback_score
|
||||||
|
FROM candidate_ids c
|
||||||
|
JOIN ticket_ai_index i ON i.ticket_id = c.ticket_id
|
||||||
|
CROSS JOIN q
|
||||||
|
LEFT JOIN ticket_ai_feedback_summary fs ON fs.ticket_id = i.ticket_id
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
*,
|
||||||
|
(
|
||||||
|
lexical_score * 0.62 +
|
||||||
|
trigram_score * 0.28 +
|
||||||
|
code_score +
|
||||||
|
metadata_score +
|
||||||
|
feedback_score
|
||||||
|
) AS total_score
|
||||||
|
FROM scored
|
||||||
|
ORDER BY total_score DESC, lexical_score DESC, opened_at DESC NULLS LAST
|
||||||
|
LIMIT %(final_limit)s
|
||||||
|
"""
|
||||||
|
|
||||||
|
started_at = time.perf_counter()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute(sql, params)
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
all_suggestions = _diverse_suggestions(rows, query_ticket, pool_target, filters)
|
||||||
|
suggestions = all_suggestions[offset:offset + limit]
|
||||||
|
elapsed_ms = int((time.perf_counter() - started_at) * 1000)
|
||||||
|
|
||||||
|
if log_results:
|
||||||
|
_log_search(cursor, user_id, query_kind, query_ticket_id, query_text, filters, len(all_suggestions), elapsed_ms)
|
||||||
|
if query_kind == "ticket" and query_ticket_id is not None and suggestions:
|
||||||
|
_log_suggestions(cursor, user_id, int(query_ticket_id), query_text, suggestions, rank_offset=offset)
|
||||||
|
connection.commit()
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return suggestions
|
||||||
|
|
||||||
|
|
||||||
|
def search_similar_tickets(query_ticket_id, user_id=None, limit=DEFAULT_LIMIT, offset=0, filters=None, log_results=True):
|
||||||
|
query_ticket = mysql5.get_ticket_context(query_ticket_id)
|
||||||
|
if not query_ticket:
|
||||||
|
return []
|
||||||
|
|
||||||
|
query_text = _query_text(query_ticket)
|
||||||
|
return _search(
|
||||||
|
"ticket",
|
||||||
|
query_text,
|
||||||
|
query_ticket_id=int(query_ticket_id),
|
||||||
|
query_ticket=query_ticket,
|
||||||
|
user_id=user_id,
|
||||||
|
limit=limit,
|
||||||
|
offset=offset,
|
||||||
|
filters=filters,
|
||||||
|
log_results=log_results,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def search_similar_text(query_text, user_id=None, limit=DEFAULT_LIMIT, offset=0, filters=None, log_results=True):
|
||||||
|
query_text = clean_text(query_text)
|
||||||
|
if not query_text:
|
||||||
|
return []
|
||||||
|
return _search(
|
||||||
|
"text",
|
||||||
|
query_text,
|
||||||
|
query_ticket_id=None,
|
||||||
|
query_ticket={},
|
||||||
|
user_id=user_id,
|
||||||
|
limit=limit,
|
||||||
|
offset=offset,
|
||||||
|
filters=filters,
|
||||||
|
log_results=log_results,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _log_search(cursor, user_id, query_kind, query_ticket_id, query_text, filters, result_count, elapsed_ms):
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO ticket_ai_search_log (
|
||||||
|
user_id,
|
||||||
|
query_kind,
|
||||||
|
query_ticket_id,
|
||||||
|
query_text,
|
||||||
|
filters,
|
||||||
|
result_count,
|
||||||
|
elapsed_ms
|
||||||
|
) VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
user_id,
|
||||||
|
query_kind,
|
||||||
|
int(query_ticket_id) if query_ticket_id is not None else None,
|
||||||
|
query_text,
|
||||||
|
Json(_safe_filters(filters)),
|
||||||
|
int(result_count),
|
||||||
|
int(elapsed_ms),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _log_suggestions(cursor, user_id, query_ticket_id, query_text, suggestions, rank_offset=0):
|
||||||
|
for rank, suggestion in enumerate(suggestions, start=1 + rank_offset):
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO ticket_ai_query_log (
|
||||||
|
user_id,
|
||||||
|
query_ticket_id,
|
||||||
|
suggested_ticket_id,
|
||||||
|
rank,
|
||||||
|
total_score,
|
||||||
|
lexical_score,
|
||||||
|
trigram_score,
|
||||||
|
code_score,
|
||||||
|
metadata_score,
|
||||||
|
feedback_score,
|
||||||
|
confidence,
|
||||||
|
query_text,
|
||||||
|
reasons
|
||||||
|
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
user_id,
|
||||||
|
query_ticket_id,
|
||||||
|
suggestion["ticket_id"],
|
||||||
|
rank,
|
||||||
|
float(suggestion["total_score"]),
|
||||||
|
float(suggestion["lexical_score"]),
|
||||||
|
float(suggestion["trigram_score"]),
|
||||||
|
float(suggestion["code_score"]),
|
||||||
|
float(suggestion["metadata_score"]),
|
||||||
|
float(suggestion["feedback_score"]),
|
||||||
|
suggestion["confidence"],
|
||||||
|
query_text,
|
||||||
|
suggestion["reasons"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def record_feedback(user_id, query_ticket_id, suggested_ticket_id, feedback, note=None):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
if feedback not in ("useful", "not_useful", "favorite", "opened"):
|
||||||
|
raise ValueError("feedback must be useful, not_useful, favorite, or opened")
|
||||||
|
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO ticket_ai_feedback (
|
||||||
|
user_id,
|
||||||
|
query_ticket_id,
|
||||||
|
suggested_ticket_id,
|
||||||
|
feedback,
|
||||||
|
note
|
||||||
|
) VALUES (%s, %s, %s, %s, %s)
|
||||||
|
""",
|
||||||
|
(user_id, int(query_ticket_id), int(suggested_ticket_id), feedback, note),
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
refresh_feedback_summary()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def record_favorite(user_id, ticket_id, query_ticket_id=None, note=None):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
ticket_id = int(ticket_id)
|
||||||
|
query_ticket_id = int(query_ticket_id) if query_ticket_id is not None else ticket_id
|
||||||
|
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT 1
|
||||||
|
FROM ticket_ai_feedback
|
||||||
|
WHERE user_id = %s
|
||||||
|
AND suggested_ticket_id = %s
|
||||||
|
AND feedback = 'favorite'
|
||||||
|
LIMIT 1
|
||||||
|
""",
|
||||||
|
(user_id, ticket_id),
|
||||||
|
)
|
||||||
|
if cursor.fetchone():
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return False
|
||||||
|
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO ticket_ai_feedback (
|
||||||
|
user_id,
|
||||||
|
query_ticket_id,
|
||||||
|
suggested_ticket_id,
|
||||||
|
feedback,
|
||||||
|
note
|
||||||
|
) VALUES (%s, %s, %s, 'favorite', %s)
|
||||||
|
""",
|
||||||
|
(user_id, query_ticket_id, ticket_id, note),
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
refresh_feedback_summary()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_favorites(user_id, limit=20):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT ON (f.suggested_ticket_id)
|
||||||
|
f.suggested_ticket_id AS ticket_id,
|
||||||
|
f.query_ticket_id,
|
||||||
|
f.created_at,
|
||||||
|
i.product,
|
||||||
|
i.area,
|
||||||
|
i.subject_text
|
||||||
|
FROM ticket_ai_feedback f
|
||||||
|
LEFT JOIN ticket_ai_index i ON i.ticket_id = f.suggested_ticket_id
|
||||||
|
WHERE f.user_id = %s
|
||||||
|
AND f.feedback = 'favorite'
|
||||||
|
ORDER BY f.suggested_ticket_id, f.created_at DESC
|
||||||
|
) favorites
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT %s
|
||||||
|
""",
|
||||||
|
(user_id, int(limit)),
|
||||||
|
)
|
||||||
|
rows = [dict(row) for row in cursor.fetchall()]
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_bot_settings(user_id):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO ticket_bot_user_settings (user_id)
|
||||||
|
VALUES (%s)
|
||||||
|
ON CONFLICT (user_id) DO NOTHING
|
||||||
|
""",
|
||||||
|
(int(user_id),),
|
||||||
|
)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT *
|
||||||
|
FROM ticket_bot_user_settings
|
||||||
|
WHERE user_id = %s
|
||||||
|
""",
|
||||||
|
(int(user_id),),
|
||||||
|
)
|
||||||
|
settings = dict(cursor.fetchone())
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
def update_user_bot_settings(user_id, **updates):
|
||||||
|
allowed = {
|
||||||
|
"notifications_enabled",
|
||||||
|
"quiet_start_hour",
|
||||||
|
"quiet_end_hour",
|
||||||
|
"digest_minutes",
|
||||||
|
"high_gravity_only",
|
||||||
|
"last_notification_at",
|
||||||
|
}
|
||||||
|
clean_updates = {key: value for key, value in updates.items() if key in allowed}
|
||||||
|
if not clean_updates:
|
||||||
|
return get_user_bot_settings(user_id)
|
||||||
|
|
||||||
|
get_user_bot_settings(user_id)
|
||||||
|
assignments = [f"{key} = %s" for key in clean_updates]
|
||||||
|
values = list(clean_updates.values())
|
||||||
|
values.append(int(user_id))
|
||||||
|
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(
|
||||||
|
f"""
|
||||||
|
UPDATE ticket_bot_user_settings
|
||||||
|
SET {", ".join(assignments)},
|
||||||
|
updated_at = now()
|
||||||
|
WHERE user_id = %s
|
||||||
|
""",
|
||||||
|
values,
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return get_user_bot_settings(user_id)
|
||||||
|
|
||||||
|
|
||||||
|
def set_notifications_enabled(user_id, enabled):
|
||||||
|
return update_user_bot_settings(user_id, notifications_enabled=bool(enabled))
|
||||||
|
|
||||||
|
|
||||||
|
def set_quiet_hours(user_id, start_hour, end_hour):
|
||||||
|
return update_user_bot_settings(
|
||||||
|
user_id,
|
||||||
|
quiet_start_hour=max(0, min(23, int(start_hour))),
|
||||||
|
quiet_end_hour=max(0, min(23, int(end_hour))),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_quiet_hours(user_id):
|
||||||
|
return update_user_bot_settings(user_id, quiet_start_hour=None, quiet_end_hour=None)
|
||||||
|
|
||||||
|
|
||||||
|
def set_digest_minutes(user_id, minutes):
|
||||||
|
return update_user_bot_settings(user_id, digest_minutes=max(0, int(minutes)))
|
||||||
|
|
||||||
|
|
||||||
|
def set_high_gravity_only(user_id, enabled):
|
||||||
|
return update_user_bot_settings(user_id, high_gravity_only=bool(enabled))
|
||||||
|
|
||||||
|
|
||||||
|
def _is_quiet_now(settings, now=None):
|
||||||
|
start = settings.get("quiet_start_hour")
|
||||||
|
end = settings.get("quiet_end_hour")
|
||||||
|
if start is None or end is None or start == end:
|
||||||
|
return False
|
||||||
|
|
||||||
|
hour = (now or datetime.now()).hour
|
||||||
|
if start < end:
|
||||||
|
return start <= hour < end
|
||||||
|
return hour >= start or hour < end
|
||||||
|
|
||||||
|
|
||||||
|
def should_send_notifications(user_id, now=None):
|
||||||
|
settings = get_user_bot_settings(user_id)
|
||||||
|
now = now or datetime.now()
|
||||||
|
if not settings.get("notifications_enabled", True):
|
||||||
|
return False
|
||||||
|
if _is_quiet_now(settings, now=now):
|
||||||
|
return False
|
||||||
|
|
||||||
|
digest_minutes = int(settings.get("digest_minutes") or 0)
|
||||||
|
last_notification_at = settings.get("last_notification_at")
|
||||||
|
if digest_minutes > 0 and last_notification_at:
|
||||||
|
elapsed_seconds = (now - last_notification_at).total_seconds()
|
||||||
|
if elapsed_seconds < digest_minutes * 60:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def mark_notification_sent(user_id):
|
||||||
|
return update_user_bot_settings(user_id, last_notification_at=datetime.now())
|
||||||
|
|
||||||
|
|
||||||
|
def get_ai_stats():
|
||||||
|
ensure_runtime_schema()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute("SELECT COUNT(*) AS indexed_count, MAX(indexed_at) AS last_indexed_at FROM ticket_ai_index")
|
||||||
|
index_stats = dict(cursor.fetchone())
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
COUNT(*) AS search_count,
|
||||||
|
COALESCE(AVG(elapsed_ms), 0)::integer AS avg_elapsed_ms,
|
||||||
|
COALESCE(SUM(CASE WHEN result_count = 0 THEN 1 ELSE 0 END), 0) AS no_result_count
|
||||||
|
FROM ticket_ai_search_log
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
search_stats = dict(cursor.fetchone())
|
||||||
|
cursor.execute("SELECT feedback, COUNT(*) AS count FROM ticket_ai_feedback GROUP BY feedback")
|
||||||
|
feedback_counts = {row["feedback"]: row["count"] for row in cursor.fetchall()}
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return {
|
||||||
|
**index_stats,
|
||||||
|
**search_stats,
|
||||||
|
"feedback_counts": feedback_counts,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_no_result_searches(limit=10):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT created_at, user_id, query_kind, query_ticket_id, query_text, filters, elapsed_ms
|
||||||
|
FROM ticket_ai_search_log
|
||||||
|
WHERE result_count = 0
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT %s
|
||||||
|
""",
|
||||||
|
(int(limit),),
|
||||||
|
)
|
||||||
|
rows = [dict(row) for row in cursor.fetchall()]
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def get_negative_feedback(limit=10):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
f.created_at,
|
||||||
|
f.user_id,
|
||||||
|
f.query_ticket_id,
|
||||||
|
f.suggested_ticket_id,
|
||||||
|
i.product,
|
||||||
|
i.area,
|
||||||
|
i.subject_text
|
||||||
|
FROM ticket_ai_feedback f
|
||||||
|
LEFT JOIN ticket_ai_index i ON i.ticket_id = f.suggested_ticket_id
|
||||||
|
WHERE f.feedback = 'not_useful'
|
||||||
|
ORDER BY f.created_at DESC
|
||||||
|
LIMIT %s
|
||||||
|
""",
|
||||||
|
(int(limit),),
|
||||||
|
)
|
||||||
|
rows = [dict(row) for row in cursor.fetchall()]
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def get_top_useful(limit=10):
|
||||||
|
ensure_runtime_schema()
|
||||||
|
connection = get_pg_connection()
|
||||||
|
cursor = connection.cursor(cursor_factory=DictCursor)
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
fs.ticket_id,
|
||||||
|
fs.positive_count,
|
||||||
|
fs.negative_count,
|
||||||
|
i.product,
|
||||||
|
i.area,
|
||||||
|
i.subject_text
|
||||||
|
FROM ticket_ai_feedback_summary fs
|
||||||
|
LEFT JOIN ticket_ai_index i ON i.ticket_id = fs.ticket_id
|
||||||
|
ORDER BY fs.positive_count DESC, fs.negative_count ASC
|
||||||
|
LIMIT %s
|
||||||
|
""",
|
||||||
|
(int(limit),),
|
||||||
|
)
|
||||||
|
rows = [dict(row) for row in cursor.fetchall()]
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def start_guessing_manual(ticket, user_id=None, filters=None, limit=DEFAULT_LIMIT, offset=0):
|
||||||
|
suggestions = search_similar_tickets(ticket, user_id=user_id, limit=limit, offset=offset, filters=filters)
|
||||||
|
return [_format_suggestion(int(ticket), suggestion, rank + offset) for rank, suggestion in enumerate(suggestions, start=1)]
|
||||||
66
api/bootstrap_db.py
Normal file
66
api/bootstrap_db.py
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
|
|
||||||
|
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||||
|
CONN_DIR = ROOT_DIR / "conn"
|
||||||
|
API_DIR = ROOT_DIR / "api"
|
||||||
|
for path in (CONN_DIR, API_DIR):
|
||||||
|
if str(path) not in sys.path:
|
||||||
|
sys.path.insert(0, str(path))
|
||||||
|
|
||||||
|
import config
|
||||||
|
from ai_index import ensure_ai_schema
|
||||||
|
|
||||||
|
|
||||||
|
BOT_SCHEMA_SQL = """
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
tid BIGINT PRIMARY KEY,
|
||||||
|
username TEXT,
|
||||||
|
surname TEXT,
|
||||||
|
status CHAR(1) NOT NULL DEFAULT 'P',
|
||||||
|
user_admin BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
CHECK (status IN ('P', 'A'))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS filters (
|
||||||
|
fid BIGSERIAL PRIMARY KEY,
|
||||||
|
tid BIGINT NOT NULL REFERENCES users(tid) ON DELETE CASCADE,
|
||||||
|
sort CHAR(1) NOT NULL,
|
||||||
|
sort_value TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
CHECK (sort IN ('A', 'S', 'C', 'P')),
|
||||||
|
UNIQUE (tid, sort, sort_value)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS filters_tid_idx ON filters (tid);
|
||||||
|
CREATE INDEX IF NOT EXISTS filters_sort_idx ON filters (sort);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS tickets (
|
||||||
|
fid BIGINT NOT NULL REFERENCES filters(fid) ON DELETE CASCADE,
|
||||||
|
ticket BIGINT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
||||||
|
PRIMARY KEY (fid, ticket)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS tickets_ticket_idx ON tickets (ticket);
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_bot_schema():
|
||||||
|
connection = psycopg2.connect(**config.POSTGRES_CONFIG)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(BOT_SCHEMA_SQL)
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ensure_bot_schema()
|
||||||
|
ensure_ai_schema()
|
||||||
|
print("PostgreSQL schema is ready")
|
||||||
2
api/cockie.py
Normal file
2
api/cockie.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
id = "r0gmffchr3kpq77ls6nish7o92"
|
||||||
42
api/connection.py
Normal file
42
api/connection.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
|
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||||
|
CONN_DIR = ROOT_DIR / "conn"
|
||||||
|
if str(CONN_DIR) not in sys.path:
|
||||||
|
sys.path.insert(0, str(CONN_DIR))
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def conn():
|
||||||
|
try:
|
||||||
|
connection = psycopg2.connect(**config.POSTGRES_CONFIG)
|
||||||
|
|
||||||
|
return connection
|
||||||
|
# cursor = connection.cursor()
|
||||||
|
|
||||||
|
# postgres_insert_query = """ INSERT INTO mobile (ID, MODEL, PRICE) VALUES (%s,%s,%s)"""
|
||||||
|
# record_to_insert = (5, 'One Plus 6', 950)
|
||||||
|
# cursor.execute(postgres_insert_query, record_to_insert)
|
||||||
|
|
||||||
|
# connection.commit()
|
||||||
|
# count = cursor.rowcount
|
||||||
|
# print(count, "Record inserted successfully into mobile table")
|
||||||
|
|
||||||
|
except (Exception, psycopg2.Error) as error:
|
||||||
|
print("Failed to insert record into mobile table", error)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# finally:
|
||||||
|
# # closing database connection.
|
||||||
|
# if connection:
|
||||||
|
# connection.cursor().close()
|
||||||
|
# connection.close()
|
||||||
|
# print("PostgreSQL connection is closed")
|
||||||
|
|
||||||
105
api/detailTicket.py
Normal file
105
api/detailTicket.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
import logging
|
||||||
|
import cockie
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def deleteDocs(ticketId):
|
||||||
|
time.sleep(2)
|
||||||
|
if os.path.exists("json/detailTicket.html"):
|
||||||
|
os.remove("json/detailTicket.html")
|
||||||
|
# os.remove('json/' + str(ticketId)+'_details.pdf')
|
||||||
|
|
||||||
|
|
||||||
|
def getDetail(ticketId):
|
||||||
|
print("arrivato con : " + str(ticketId))
|
||||||
|
|
||||||
|
pdf_file = "json/" + str(ticketId) + "_details.pdf"
|
||||||
|
html_file = "json/" + str(ticketId) + "_details.html"
|
||||||
|
try:
|
||||||
|
|
||||||
|
cookies = {
|
||||||
|
'language': 'it',
|
||||||
|
'sid': cockie.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Accept': '*/*',
|
||||||
|
'Accept-Language': 'it-IT,it;q=0.9,la;q=0.8',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
# Requests sorts cookies= alphabetically
|
||||||
|
# 'Cookie': 'language=it; sid=89q0fl4j3r54600e2fdbf952t1',
|
||||||
|
'Referer': 'https://tsnew.sanmarcoweb.com/it/ticket',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'sec-ch-ua-platform': '"Linux"',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.get('https://tsnew.sanmarcoweb.com/it/ticket/details/index/id/'+ str(ticketId), cookies=cookies, headers=headers)
|
||||||
|
|
||||||
|
content = response.text
|
||||||
|
print(html_file)
|
||||||
|
with open(html_file, 'w') as f:
|
||||||
|
f.write(str(content.replace('rows="7"', ' rows="10" cols="100" ')).encode('latin1').decode('utf8'))
|
||||||
|
|
||||||
|
# json/" + str(ticketId) + "_details.pdf"
|
||||||
|
|
||||||
|
|
||||||
|
# Write the messages
|
||||||
|
response2 = requests.get('https://tsnew.sanmarcoweb.com/it/ticket/messages/index/id/' + str(ticketId), cookies=cookies, headers=headers)
|
||||||
|
|
||||||
|
content2 = response2.text
|
||||||
|
|
||||||
|
with open(html_file, 'a', encoding='utf-8') as b:
|
||||||
|
b.write(content2.replace('rows="7"', ' rows="10" cols="100" ').encode('latin1').decode('utf8'))
|
||||||
|
|
||||||
|
# Append notes
|
||||||
|
response3 = requests.get('https://tsnew.sanmarcoweb.com/it/ticket/notes/index/id/' + str(ticketId), cookies=cookies, headers=headers)
|
||||||
|
|
||||||
|
content3 = response3.text
|
||||||
|
|
||||||
|
with open(html_file, 'a', encoding='utf-8') as c:
|
||||||
|
c.write(content3.replace('rows="7"', ' rows="10" cols="100" ').encode('latin1').decode('utf8'))
|
||||||
|
|
||||||
|
# Append the attachments
|
||||||
|
|
||||||
|
response4 = requests.get('https://tsnew.sanmarcoweb.com/it/ticket/attachments/index/id/' + str(ticketId), cookies=cookies, headers=headers)
|
||||||
|
|
||||||
|
content4 = response4.text
|
||||||
|
with open(html_file, 'a', encoding='utf-8') as d:
|
||||||
|
d.write(content4.replace('rows="7"', ' rows="10" cols="100" ').encode('latin1').decode('utf8'))
|
||||||
|
|
||||||
|
# Convert into pdf
|
||||||
|
# path_wkhtmltopdf = '/usr/bin/wkhtmltopdf'
|
||||||
|
# config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
|
||||||
|
# pdfkit.from_file(html_file, pdf_file, configuration=config)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(traceback.format_exc())
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# getDetail(456427)
|
||||||
|
|
||||||
|
# deleteDocs(456292)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
205
api/limbo/compareText.py
Normal file
205
api/limbo/compareText.py
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
import requests
|
||||||
|
import re
|
||||||
|
import json
|
||||||
|
|
||||||
|
import traceback
|
||||||
|
import logging
|
||||||
|
import cockie
|
||||||
|
import connection
|
||||||
|
import spacy_match
|
||||||
|
|
||||||
|
import spacy
|
||||||
|
|
||||||
|
nlp = spacy.load('it_core_news_lg')
|
||||||
|
|
||||||
|
def getConn():
|
||||||
|
c = connection.conn()
|
||||||
|
return c
|
||||||
|
|
||||||
|
def closeConnection(connection,cursor):
|
||||||
|
if connection:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
file_path = "output.json"
|
||||||
|
|
||||||
|
def extract_text_between_markers(text, start_marker, end_marker):
|
||||||
|
pattern = re.compile(f'{re.escape(start_marker)}(.*?){re.escape(end_marker)}', re.DOTALL)
|
||||||
|
match = pattern.search(text)
|
||||||
|
if match:
|
||||||
|
return match.group(1).strip()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Returns all the filters inserted by a user
|
||||||
|
def getObjectAndDescription(area,prodotto):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select descrizione AS result from ticket_big where competenze ='" + str(area) + "' AND prodotto = '" + prodotto + "' " #+ " OR prodotto ='' "
|
||||||
|
print(postgreSQL_select_Query)
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
# print(publisher_records)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
def getDetail(ticketId):
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
cookies = {
|
||||||
|
'language': 'it',
|
||||||
|
'sid': cockie.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Accept': '*/*',
|
||||||
|
'Accept-Language': 'it-IT,it;q=0.9,la;q=0.8',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
# Requests sorts cookies= alphabetically
|
||||||
|
# 'Cookie': 'language=it; sid=89q0fl4j3r54600e2fdbf952t1',
|
||||||
|
'Referer': 'https://tsnew.sanmarcoweb.com/it/ticket',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'sec-ch-ua-platform': '"Linux"',
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.get('https://tsnew.sanmarcoweb.com/it/ticket/details/index/id/'+ str(ticketId), cookies=cookies, headers=headers)
|
||||||
|
|
||||||
|
oggetto_start = 'name="oggetto" value="'
|
||||||
|
oggetto_end = '"'
|
||||||
|
start_marker = 'true,required: false">'
|
||||||
|
end_marker = '</textarea>'
|
||||||
|
competenza_start = '<img class="rightIcon" width="16" height="16" src="/img/_core/ticket/competence.png" />'
|
||||||
|
competenza_end = '/option>'
|
||||||
|
competenze_final_start = '" selected="selected">'
|
||||||
|
competenze_final_end = '<'
|
||||||
|
soluzione_start = '[]);}">'
|
||||||
|
soluzione_end = '</textarea>'
|
||||||
|
prodotto_start = 'id="prodotto_'+ str(ticketId)
|
||||||
|
prodotto_end = '/option>'
|
||||||
|
prodotto_final_start = 'selected="selected">'
|
||||||
|
prodotto_final_end = '<'
|
||||||
|
|
||||||
|
content = response.text
|
||||||
|
# print(content)
|
||||||
|
|
||||||
|
oggetto = extract_text_between_markers(content, oggetto_start, oggetto_end)
|
||||||
|
description = extract_text_between_markers(content, start_marker, end_marker)
|
||||||
|
competenze = extract_text_between_markers(content, competenza_start, competenza_end)
|
||||||
|
competenze = extract_text_between_markers(competenze, competenze_final_start, competenze_final_end)
|
||||||
|
soluzione = extract_text_between_markers(content, soluzione_start, soluzione_end)
|
||||||
|
prodotto = extract_text_between_markers(content, prodotto_start, prodotto_end)
|
||||||
|
prodotto = extract_text_between_markers(prodotto, prodotto_final_start, prodotto_final_end)
|
||||||
|
|
||||||
|
print(ticketId+ " --> Cercando --> ", description)
|
||||||
|
# print("Descrizione: ", description)
|
||||||
|
# print("Competenze: ", competenze)
|
||||||
|
# print("Soluzione: ", soluzione)
|
||||||
|
# print("Prodotto: ", prodotto)
|
||||||
|
|
||||||
|
|
||||||
|
# getObjectAndDescription('Assistenza Vinicoli','JExp')
|
||||||
|
# s_match(description)
|
||||||
|
|
||||||
|
|
||||||
|
if not soluzione.replace("\n", ""):
|
||||||
|
return False
|
||||||
|
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgres_insert_query = """ INSERT INTO ticket_big (id, oggetto,descrizione, competenze, soluzione,prodotto) VALUES (%s,%s,%s,%s,%s,%s)"""
|
||||||
|
record_to_insert = (str(ticketId), oggetto.replace("\n", ""),description.replace("\n", ""), competenze.replace("\n", ""),soluzione.replace("\n", ""),prodotto.replace("\n", ""))
|
||||||
|
cursor.execute(postgres_insert_query, record_to_insert)
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
count = cursor.rowcount
|
||||||
|
if count <1:
|
||||||
|
return False
|
||||||
|
print(count, "Record inserted successfully into sort table")
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(traceback.format_exc())
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# for ticket in range(456424,456429):
|
||||||
|
# getDetail(ticket)
|
||||||
|
|
||||||
|
def get_ids_from_json_file(file_path):
|
||||||
|
with open(file_path, 'r') as json_file:
|
||||||
|
data = json.load(json_file)
|
||||||
|
|
||||||
|
ids = [item['id'] for item in data['data']]
|
||||||
|
return ids
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
file_path = 'data.json'
|
||||||
|
ids_list = get_ids_from_json_file("/Users/tommal/Desktop/tickets.json")
|
||||||
|
# print(ids_list)
|
||||||
|
|
||||||
|
|
||||||
|
for ticket in ids_list:
|
||||||
|
getDetail(ticket)
|
||||||
|
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
|
||||||
|
def s_match(w_target):
|
||||||
|
# w_target = "JExp non funziona per un problema delle dogane:Esiste una procedura di emergenza per inviare i DAA?"
|
||||||
|
|
||||||
|
# List of w1 to w500
|
||||||
|
# w_list = [
|
||||||
|
# ("VIOLAZIONE REGOLA C070 non riusciamo a fare l'EAD"),
|
||||||
|
# ("L'invio dell'E-ad si blocca per la presenza dell'errore violazione regola C070")
|
||||||
|
# ]
|
||||||
|
|
||||||
|
w_list = getObjectAndDescription('Assistenza Vinicoli','JExp')
|
||||||
|
# print("\n\n")
|
||||||
|
# print(w_list)
|
||||||
|
# print("\n\n")
|
||||||
|
w_list = [item[0] for item in w_list]
|
||||||
|
# w_list = ["tempo bello", "molto", "usciamo fuori"]
|
||||||
|
|
||||||
|
|
||||||
|
# Calculate similarity scores for each w in w_list and create a list of tuples
|
||||||
|
similarity_scores = [(w, nlp(w_target).similarity(nlp(w))) for w in w_list]
|
||||||
|
|
||||||
|
# Sort the list of tuples based on similarity score in descending order
|
||||||
|
sorted_similarity_scores = sorted(similarity_scores, key=lambda x: x[1], reverse=True)
|
||||||
|
|
||||||
|
# Get the best 5 matches from the sorted list
|
||||||
|
best_matches = sorted_similarity_scores[:5]
|
||||||
|
|
||||||
|
# Print the best 5 matches
|
||||||
|
print("\n\n")
|
||||||
|
print("Top 5 matches:")
|
||||||
|
for match, similarity_score in best_matches:
|
||||||
|
print("Match:", match)
|
||||||
|
print("Similarity score:", similarity_score)
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
27
api/limbo/diff.py
Normal file
27
api/limbo/diff.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import difflib
|
||||||
|
import compareText
|
||||||
|
|
||||||
|
def get_similarity_ratio(s1, s2):
|
||||||
|
matcher = difflib.SequenceMatcher(None, s1, s2)
|
||||||
|
return matcher.ratio()
|
||||||
|
|
||||||
|
w_target = "CERTIFICATO DI FIRMA SCADUTO"
|
||||||
|
|
||||||
|
w_list = compareText.getObjectAndDescription('Assistenza Vinicoli','JExp')
|
||||||
|
w2_list = [item[0] for item in w_list]
|
||||||
|
w_list = w2_list
|
||||||
|
# Calculate similarity scores for each w in w_list
|
||||||
|
similarity_scores = [(w, get_similarity_ratio(w_target, w)) for w in w_list]
|
||||||
|
|
||||||
|
# Sort the list of tuples based on similarity score in descending order
|
||||||
|
sorted_similarity_scores = sorted(similarity_scores, key=lambda x: x[1], reverse=True)
|
||||||
|
|
||||||
|
# Get the best 5 matches from the sorted list
|
||||||
|
best_matches = sorted_similarity_scores[:5]
|
||||||
|
|
||||||
|
# Print the best 5 matches
|
||||||
|
print("Top 5 matches:")
|
||||||
|
for match, similarity_score in best_matches:
|
||||||
|
print("Match:", match)
|
||||||
|
print("Similarity score:", similarity_score)
|
||||||
|
print()
|
||||||
64
api/phrase_similarity.py
Normal file
64
api/phrase_similarity.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
|
ROOT_DIR = Path(__file__).resolve().parents[1]
|
||||||
|
CONN_DIR = ROOT_DIR / "conn"
|
||||||
|
if str(CONN_DIR) not in sys.path:
|
||||||
|
sys.path.insert(0, str(CONN_DIR))
|
||||||
|
|
||||||
|
import mysql5
|
||||||
|
|
||||||
|
|
||||||
|
def _legacy_start_guessing_manual(ticket):
|
||||||
|
try:
|
||||||
|
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||||
|
from sklearn.metrics.pairwise import cosine_similarity
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
return []
|
||||||
|
|
||||||
|
competence_origin, product_origin, problem_origin, area_origin, subarea_origin = mysql5.getCompetenceOrProdotto(ticket)
|
||||||
|
w_list = mysql5.getProblemaBYCompetenzaOrProgramma_manul(competence_origin, product_origin, area_origin, subarea_origin)
|
||||||
|
|
||||||
|
if len(w_list) == 0:
|
||||||
|
return []
|
||||||
|
|
||||||
|
phrases = [item[0] for item in w_list]
|
||||||
|
vectorizer = TfidfVectorizer(analyzer="char_wb", ngram_range=(3, 5), lowercase=True)
|
||||||
|
tfidf_matrix = vectorizer.fit_transform([problem_origin] + phrases)
|
||||||
|
similarity_matrix = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:])
|
||||||
|
|
||||||
|
# Keep the real top five. The old code used [-6:-1], which skipped the best result.
|
||||||
|
best_matches_indices = similarity_matrix.argsort()[0][-5:][::-1]
|
||||||
|
|
||||||
|
final_list = []
|
||||||
|
for i, index in enumerate(best_matches_indices, start=1):
|
||||||
|
complete_ticket = mysql5.getTicketByProblema(str(phrases[index]))
|
||||||
|
solution = str(complete_ticket[1])
|
||||||
|
if len(solution) > 400:
|
||||||
|
solution = solution[:400] + "..."
|
||||||
|
|
||||||
|
final_list.append(
|
||||||
|
f"\n\n----- {i}. Metodo legacy -----\n"
|
||||||
|
f"[ /Ticket_dettaglio_{complete_ticket[0]} ]\n"
|
||||||
|
f"https://tsnew.sanmarcoweb.com/it/ticket/index/index/operation/view/id/{complete_ticket[0]}\n"
|
||||||
|
f"SOLUZIONE: {solution}\n"
|
||||||
|
)
|
||||||
|
return final_list
|
||||||
|
|
||||||
|
|
||||||
|
def start_guessing_manual(ticket, user_id=None, filters=None, limit=None, offset=0):
|
||||||
|
try:
|
||||||
|
import ai_retriever
|
||||||
|
|
||||||
|
kwargs = {"user_id": user_id, "filters": filters, "offset": offset}
|
||||||
|
if limit is not None:
|
||||||
|
kwargs["limit"] = limit
|
||||||
|
return ai_retriever.start_guessing_manual(ticket, **kwargs)
|
||||||
|
except Exception:
|
||||||
|
traceback.print_exc()
|
||||||
|
if filters:
|
||||||
|
return []
|
||||||
|
return _legacy_start_guessing_manual(ticket)
|
||||||
39
conn/config.py
Normal file
39
conn/config.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def _env_int(name, default):
|
||||||
|
value = os.getenv(name)
|
||||||
|
if value is None or value == "":
|
||||||
|
return default
|
||||||
|
return int(value)
|
||||||
|
|
||||||
|
|
||||||
|
def _env_bool(name, default):
|
||||||
|
value = os.getenv(name)
|
||||||
|
if value is None or value == "":
|
||||||
|
return default
|
||||||
|
return value.strip().lower() in ("1", "true", "yes", "on")
|
||||||
|
|
||||||
|
|
||||||
|
MYSQL_CONFIG = {
|
||||||
|
"host": os.getenv("TICKET_MYSQL_HOST", "127.0.0.1"),
|
||||||
|
"port": _env_int("TICKET_MYSQL_PORT", 3307),
|
||||||
|
"database": os.getenv("TICKET_MYSQL_DATABASE", "smits"),
|
||||||
|
"user": os.getenv("TICKET_MYSQL_USER", "root"),
|
||||||
|
"password": os.getenv("TICKET_MYSQL_PASSWORD", "localpassword"),
|
||||||
|
"charset": os.getenv("TICKET_MYSQL_CHARSET", "utf8"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
POSTGRES_CONFIG = {
|
||||||
|
"host": os.getenv("TICKET_PG_HOST", "127.0.0.1"),
|
||||||
|
"port": _env_int("TICKET_PG_PORT", 5433),
|
||||||
|
"dbname": os.getenv("TICKET_PG_DATABASE", "ticket"),
|
||||||
|
"user": os.getenv("TICKET_PG_USER", "postgres"),
|
||||||
|
"password": os.getenv("TICKET_PG_PASSWORD", "localpassword"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TELEGRAM_BOT_TOKEN = os.getenv("TICKET_TELEGRAM_TOKEN", os.getenv("TELEGRAM_BOT_TOKEN", ""))
|
||||||
|
TELEGRAM_ADMIN_ID = _env_int("TICKET_ADMIN_ID", 145645559)
|
||||||
|
ENABLE_NOTIFICATIONS = _env_bool("TICKET_ENABLE_NOTIFICATIONS", True)
|
||||||
33
conn/connection.py
Normal file
33
conn/connection.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import psycopg2
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def conn():
|
||||||
|
try:
|
||||||
|
connection = psycopg2.connect(**config.POSTGRES_CONFIG)
|
||||||
|
|
||||||
|
return connection
|
||||||
|
# cursor = connection.cursor()
|
||||||
|
|
||||||
|
# postgres_insert_query = """ INSERT INTO mobile (ID, MODEL, PRICE) VALUES (%s,%s,%s)"""
|
||||||
|
# record_to_insert = (5, 'One Plus 6', 950)
|
||||||
|
# cursor.execute(postgres_insert_query, record_to_insert)
|
||||||
|
|
||||||
|
# connection.commit()
|
||||||
|
# count = cursor.rowcount
|
||||||
|
# print(count, "Record inserted successfully into mobile table")
|
||||||
|
|
||||||
|
except (Exception, psycopg2.Error) as error:
|
||||||
|
print("Failed to insert record into mobile table", error)
|
||||||
|
return False
|
||||||
|
|
||||||
|
# finally:
|
||||||
|
# # closing database connection.
|
||||||
|
# if connection:
|
||||||
|
# connection.cursor().close()
|
||||||
|
# connection.close()
|
||||||
|
# print("PostgreSQL connection is closed")
|
||||||
|
|
||||||
151
conn/filters.py
Normal file
151
conn/filters.py
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
|
||||||
|
import connection
|
||||||
|
|
||||||
|
def getConn():
|
||||||
|
c = connection.conn()
|
||||||
|
return c
|
||||||
|
|
||||||
|
def closeConnection(connection,cursor):
|
||||||
|
if connection:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
# print("POstgres connection closed successfully")
|
||||||
|
# print("Connection was closed before")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Insert a filter if it does not already exist.
|
||||||
|
def insertFilter(tid, sort, sort_value ):
|
||||||
|
if str(sort_value).strip().startswith("_"):
|
||||||
|
sort_value = "-" + (str(sort_value).strip())[1:]
|
||||||
|
if getFilterByParam(tid, sort, sort_value):
|
||||||
|
return False
|
||||||
|
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgres_insert_query = """ INSERT INTO filters (tid, sort, sort_value) VALUES (%s,%s,%s)"""
|
||||||
|
record_to_insert = (tid, sort, sort_value)
|
||||||
|
cursor.execute(postgres_insert_query, record_to_insert)
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
count = cursor.rowcount
|
||||||
|
if count <1:
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return False
|
||||||
|
print(count, "Record inserted successfully into sort table")
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def exists_area_for_user(tid):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from filters where tid =" + str(tid) + " AND sort = 'A'"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return cursor.rowcount > 0
|
||||||
|
|
||||||
|
def exists_sub_area_for_user(tid):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from filters where tid =" + str(tid) + " AND sort = 'S'"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
|
||||||
|
return cursor.rowcount > 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_area_from_tid(tid):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select sort_value from filters where sort = 'A' and tid =" + str(tid)
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
# Returns all the filters inserted by a user
|
||||||
|
def getFilters(tid):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from filters where tid =" + str(tid) + " order by sort"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
# Returns all the filters inserted by a user
|
||||||
|
def getFilterByParam(tid,sort, sort_value):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = """select * from filters where tid = %s and sort= %s and sort_value = %s"""
|
||||||
|
record_to_insert = (tid, sort, sort_value)
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query,record_to_insert)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
filter_exists = cursor.rowcount > 0
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return filter_exists
|
||||||
|
|
||||||
|
# Returns all the filters inserted by a user
|
||||||
|
def getAllFilters():
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from filters "
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
for row in publisher_records:
|
||||||
|
print( row, "\n")
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Delete a single filter
|
||||||
|
def deleteFilter(telid, id):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
# Delete first all the ticket
|
||||||
|
sql_delete_query = """Delete from tickets where fid = %s"""
|
||||||
|
cursor.execute(sql_delete_query, (id,))
|
||||||
|
connection.commit()
|
||||||
|
|
||||||
|
sql_delete_query = """Delete from filters where tid= %s and fid = %s"""
|
||||||
|
cursor.execute(sql_delete_query, (telid,id))
|
||||||
|
connection.commit()
|
||||||
|
count = cursor.rowcount
|
||||||
|
print(count, "Record deleted successfully ")
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return count > 0
|
||||||
|
|
||||||
|
|
||||||
|
#insertFilter(965744443, 'competenza','itech')
|
||||||
|
#getUsers()
|
||||||
|
#isUserRegisterd(222222)
|
||||||
|
|
||||||
|
|
||||||
|
#getFilters(965744443)
|
||||||
|
#deleteFilter(8)
|
||||||
396
conn/mysql5.py
Normal file
396
conn/mysql5.py
Normal file
@@ -0,0 +1,396 @@
|
|||||||
|
import mysql.connector
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
|
def getMySqlConnection():
|
||||||
|
connection = mysql.connector.connect(**config.MYSQL_CONFIG)
|
||||||
|
return connection
|
||||||
|
|
||||||
|
|
||||||
|
def closeConnection(connection,cursor):
|
||||||
|
if connection:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_areas():
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from aree"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
def get_sub_areas(area):
|
||||||
|
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select ID,SOTTOAREA,AREA from sottoaree where area = %s"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query, (area,))
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# print(get_sub_areas(2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getCompetences(competence_id=999999):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from competenze order by ID"
|
||||||
|
if competence_id != 999999:
|
||||||
|
postgreSQL_select_Query += " WHERE ID =" + str(competence_id)
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
def getProducts(product_id=999999):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from prodotti order by ID"
|
||||||
|
if product_id != 999999:
|
||||||
|
postgreSQL_select_Query += " WHERE ID =" + str(product_id)
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getTicket(filter_type="", filter_value=""):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
postgreSQL_select_Query = ""
|
||||||
|
params = ()
|
||||||
|
if filter_type == "":
|
||||||
|
postgreSQL_select_Query = "select * from segnalazioni limit 2"
|
||||||
|
elif filter_type == "C":
|
||||||
|
postgreSQL_select_Query = "select s.TICKET,cl.INTESTATARIO,s.OGGETTO,g.GRAVITA,c.COMPETENZA,p.PRODOTTO,s.APERTURA from segnalazioni as s join prodotti as p on s.PRODOTTO=p.ID join competenze as c on s.COMPETENZA=c.ID join gravita as g on s.GRAVITA=g.ID join clienti as cl on cl.ID=s.CLIENTE where s.COMPETENZA=%s AND DATE(s.APERTURA)=CURDATE()"
|
||||||
|
params = (filter_value,)
|
||||||
|
elif filter_type == "P":
|
||||||
|
postgreSQL_select_Query = "select s.TICKET,cl.INTESTATARIO,s.OGGETTO,g.GRAVITA,c.COMPETENZA,p.PRODOTTO,s.APERTURA from segnalazioni as s join prodotti as p on s.PRODOTTO=p.ID join gravita as g on s.GRAVITA=g.ID join competenze as c on s.COMPETENZA=c.ID join clienti as cl on cl.ID=s.CLIENTE where s.PRODOTTO=%s AND DATE(s.APERTURA)=CURDATE()"
|
||||||
|
params = (filter_value,)
|
||||||
|
elif filter_type == "A":
|
||||||
|
postgreSQL_select_Query = "select s.TICKET,cl.INTESTATARIO,s.OGGETTO,g.GRAVITA,c.COMPETENZA,p.PRODOTTO,s.APERTURA from segnalazioni as s join prodotti as p on s.PRODOTTO=p.ID join gravita as g on s.GRAVITA=g.ID join competenze as c on s.COMPETENZA=c.ID join clienti as cl on cl.ID=s.CLIENTE where s.AREA=%s AND DATE(s.APERTURA)=CURDATE()"
|
||||||
|
params = (filter_value,)
|
||||||
|
elif filter_type == "S":
|
||||||
|
postgreSQL_select_Query = "select s.TICKET,cl.INTESTATARIO,s.OGGETTO,g.GRAVITA,c.COMPETENZA,p.PRODOTTO,s.APERTURA from segnalazioni as s join prodotti as p on s.PRODOTTO=p.ID join gravita as g on s.GRAVITA=g.ID join competenze as c on s.COMPETENZA=c.ID join clienti as cl on cl.ID=s.CLIENTE where s.SOTTOAREA=%s AND DATE(s.APERTURA)=CURDATE()"
|
||||||
|
params = (filter_value,)
|
||||||
|
else:
|
||||||
|
closeConnection(connection, cursor)
|
||||||
|
return []
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query, params)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
def getTicketsByFilterSet(filter_rows):
|
||||||
|
filter_values = {
|
||||||
|
"C": [],
|
||||||
|
"P": [],
|
||||||
|
"A": [],
|
||||||
|
"S": [],
|
||||||
|
}
|
||||||
|
for row in filter_rows:
|
||||||
|
filter_type = str(row[2])
|
||||||
|
if filter_type not in filter_values:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
filter_value = int(row[3])
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
continue
|
||||||
|
if filter_value not in filter_values[filter_type]:
|
||||||
|
filter_values[filter_type].append(filter_value)
|
||||||
|
|
||||||
|
if not any(filter_values.values()):
|
||||||
|
return []
|
||||||
|
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
select_query = """
|
||||||
|
select
|
||||||
|
s.TICKET,
|
||||||
|
cl.INTESTATARIO,
|
||||||
|
s.OGGETTO,
|
||||||
|
g.GRAVITA,
|
||||||
|
c.COMPETENZA,
|
||||||
|
p.PRODOTTO,
|
||||||
|
s.APERTURA
|
||||||
|
from segnalazioni as s
|
||||||
|
join prodotti as p on s.PRODOTTO=p.ID
|
||||||
|
join gravita as g on s.GRAVITA=g.ID
|
||||||
|
join competenze as c on s.COMPETENZA=c.ID
|
||||||
|
join clienti as cl on cl.ID=s.CLIENTE
|
||||||
|
"""
|
||||||
|
column_map = {
|
||||||
|
"C": "s.COMPETENZA",
|
||||||
|
"P": "s.PRODOTTO",
|
||||||
|
"A": "s.AREA",
|
||||||
|
"S": "s.SOTTOAREA",
|
||||||
|
}
|
||||||
|
where_parts = ["DATE(s.APERTURA)=CURDATE()"]
|
||||||
|
params = []
|
||||||
|
for filter_type, values in filter_values.items():
|
||||||
|
if not values:
|
||||||
|
continue
|
||||||
|
placeholders = ",".join(["%s"] * len(values))
|
||||||
|
where_parts.append(f"{column_map[filter_type]} IN ({placeholders})")
|
||||||
|
params.extend(values)
|
||||||
|
|
||||||
|
select_query += " where " + " AND ".join(where_parts)
|
||||||
|
cursor.execute(select_query, tuple(params))
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getProductOrCompetence(type_,value_):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_product = "select prodotto from prodotti WHERE ID="+value_
|
||||||
|
postgreSQL_select_competence = "select COMPETENZA from competenze WHERE ID="+value_
|
||||||
|
postgreSQL_select_area = "select AREA from aree a where ID="+value_
|
||||||
|
postgreSQL_select_sub_area = "select SOTTOAREA from sottoaree where ID="+value_
|
||||||
|
|
||||||
|
if type_ == "P":
|
||||||
|
cursor.execute(postgreSQL_select_product)
|
||||||
|
elif type_ == 'C':
|
||||||
|
cursor.execute(postgreSQL_select_competence)
|
||||||
|
elif type_ == 'A':
|
||||||
|
cursor.execute(postgreSQL_select_area)
|
||||||
|
elif type_ == 'S':
|
||||||
|
cursor.execute(postgreSQL_select_sub_area)
|
||||||
|
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
# print(publisher_records)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
def getCompetenceOrProdotto(ticket):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
select_problem = "SELECT COMPETENZA, PRODOTTO, PROBLEMA, AREA, SOTTOAREA FROM segnalazioni where TICKET = %s"
|
||||||
|
cursor.execute(select_problem, (ticket,))
|
||||||
|
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
|
||||||
|
if not publisher_records:
|
||||||
|
return "", "", "", "", ""
|
||||||
|
|
||||||
|
return str(publisher_records[0][0]) ,str(publisher_records[0][1]) ,str(publisher_records[0][2]) , str(publisher_records[0][3]) ,str(publisher_records[0][4])
|
||||||
|
|
||||||
|
# def getProblemaBYCompetenzaOrProgramma(competence, prodotto):
|
||||||
|
# connection = getMySqlConnection()
|
||||||
|
# cursor = connection.cursor()
|
||||||
|
# # From DB the competence is not null
|
||||||
|
# if prodotto != None and competence != None:
|
||||||
|
# select_problem = "SELECT PROBLEMA FROM segnalazioni where COMPETENZA = " + str(competence) + " AND PRODOTTO = " + str(prodotto)+ ""
|
||||||
|
# elif prodotto == None:
|
||||||
|
# select_problem = "SELECT PROBLEMA FROM segnalazioni where COMPETENZA = " + str(competence) + ""
|
||||||
|
|
||||||
|
# cursor.execute(select_problem)
|
||||||
|
|
||||||
|
# publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
# closeConnection(connection,cursor)
|
||||||
|
# return publisher_records
|
||||||
|
|
||||||
|
def getProblemaBYCompetenzaOrProgramma_manul(competence, prodotto, area, sottoarea):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
where_parts = []
|
||||||
|
params = []
|
||||||
|
|
||||||
|
if prodotto is not None and prodotto.isdigit():
|
||||||
|
print("Trovato prodotto: ", prodotto)
|
||||||
|
where_parts.append("PRODOTTO = %s")
|
||||||
|
params.append(int(prodotto))
|
||||||
|
|
||||||
|
if area is not None and area.isdigit():
|
||||||
|
print("Trovato area: ", area)
|
||||||
|
where_parts.append("AREA = %s")
|
||||||
|
params.append(int(area))
|
||||||
|
|
||||||
|
|
||||||
|
if sottoarea is not None and sottoarea.isdigit():
|
||||||
|
print("Trovato sottoarea: ", sottoarea)
|
||||||
|
where_parts.append("SOTTOAREA = %s")
|
||||||
|
params.append(int(sottoarea))
|
||||||
|
|
||||||
|
# If none of the where condition is satisfied
|
||||||
|
if not where_parts:
|
||||||
|
if competence is not None and str(competence).isdigit():
|
||||||
|
print("Trovato competence: ", competence)
|
||||||
|
where_parts.append("COMPETENZA = %s")
|
||||||
|
params.append(int(competence))
|
||||||
|
else:
|
||||||
|
print("Trovato : ", "Nulla")
|
||||||
|
where_parts.append("FALSE")
|
||||||
|
|
||||||
|
|
||||||
|
main_sql = "SELECT PROBLEMA FROM segnalazioni WHERE " + " AND ".join(where_parts)
|
||||||
|
|
||||||
|
print(main_sql)
|
||||||
|
cursor.execute(main_sql, tuple(params))
|
||||||
|
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
count = cursor.rowcount
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
# if count <1:
|
||||||
|
# print("FFFFFF")
|
||||||
|
# return "Non ho trovato ticket con i filtri del ticket principale."
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
def getTicketByProblema(problem):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
# Use placeholders for the query and pass the value as a parameter
|
||||||
|
select_problem = "SELECT TICKET, SOLUZIONE, PROBLEMA FROM segnalazioni WHERE PROBLEMA = %s"
|
||||||
|
cursor.execute(select_problem, (problem,))
|
||||||
|
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_ticket_context(ticket):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
query = """
|
||||||
|
SELECT
|
||||||
|
s.TICKET AS ticket_id,
|
||||||
|
s.OGGETTO AS subject,
|
||||||
|
s.PROBLEMA AS problem,
|
||||||
|
s.SOLUZIONE AS solution,
|
||||||
|
s.COMPETENZA AS competence_id,
|
||||||
|
c.COMPETENZA AS competence,
|
||||||
|
s.PRODOTTO AS product_id,
|
||||||
|
p.prodotto AS product,
|
||||||
|
s.AREA AS area_id,
|
||||||
|
a.AREA AS area,
|
||||||
|
s.SOTTOAREA AS subarea_id,
|
||||||
|
sa.SOTTOAREA AS subarea,
|
||||||
|
s.CLIENTE AS client_id,
|
||||||
|
cl.INTESTATARIO AS client,
|
||||||
|
s.GRAVITA AS gravity_id,
|
||||||
|
g.GRAVITA AS gravity,
|
||||||
|
s.STATO AS status_id,
|
||||||
|
st.STATO AS status,
|
||||||
|
s.APERTURA AS opened_at,
|
||||||
|
s.CHIUSURA AS closed_at,
|
||||||
|
s.PROGRAMMA AS program,
|
||||||
|
s.TIPO_PROGRAMMA AS program_type,
|
||||||
|
s.VERSIONE AS version_id,
|
||||||
|
s.PATCH AS patch_id,
|
||||||
|
s.CLASSIFICAZIONE AS classification_id,
|
||||||
|
s.SISTEMA_OPERATIVO AS os_id
|
||||||
|
FROM segnalazioni s
|
||||||
|
LEFT JOIN competenze c ON c.ID = s.COMPETENZA
|
||||||
|
LEFT JOIN prodotti p ON p.ID = s.PRODOTTO
|
||||||
|
LEFT JOIN aree a ON a.ID = s.AREA
|
||||||
|
LEFT JOIN sottoaree sa ON sa.ID = s.SOTTOAREA
|
||||||
|
LEFT JOIN clienti cl ON cl.ID = s.CLIENTE
|
||||||
|
LEFT JOIN gravita g ON g.ID = s.GRAVITA
|
||||||
|
LEFT JOIN stati st ON st.ID = s.STATO
|
||||||
|
WHERE s.TICKET = %s
|
||||||
|
"""
|
||||||
|
cursor.execute(query, (ticket,))
|
||||||
|
records = cursor.fetchall()
|
||||||
|
closeConnection(connection, cursor)
|
||||||
|
return records[0] if records else None
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_solved_ticket_batch(last_ticket=0, limit=1000):
|
||||||
|
connection = getMySqlConnection()
|
||||||
|
cursor = connection.cursor(dictionary=True)
|
||||||
|
|
||||||
|
query = """
|
||||||
|
SELECT
|
||||||
|
s.TICKET AS ticket_id,
|
||||||
|
s.OGGETTO AS subject,
|
||||||
|
s.PROBLEMA AS problem,
|
||||||
|
s.SOLUZIONE AS solution,
|
||||||
|
s.COMPETENZA AS competence_id,
|
||||||
|
c.COMPETENZA AS competence,
|
||||||
|
s.PRODOTTO AS product_id,
|
||||||
|
p.prodotto AS product,
|
||||||
|
s.AREA AS area_id,
|
||||||
|
a.AREA AS area,
|
||||||
|
s.SOTTOAREA AS subarea_id,
|
||||||
|
sa.SOTTOAREA AS subarea,
|
||||||
|
s.CLIENTE AS client_id,
|
||||||
|
cl.INTESTATARIO AS client,
|
||||||
|
s.GRAVITA AS gravity_id,
|
||||||
|
g.GRAVITA AS gravity,
|
||||||
|
s.STATO AS status_id,
|
||||||
|
st.STATO AS status,
|
||||||
|
s.APERTURA AS opened_at,
|
||||||
|
s.CHIUSURA AS closed_at,
|
||||||
|
s.PROGRAMMA AS program,
|
||||||
|
s.TIPO_PROGRAMMA AS program_type,
|
||||||
|
s.VERSIONE AS version_id,
|
||||||
|
s.PATCH AS patch_id,
|
||||||
|
s.CLASSIFICAZIONE AS classification_id,
|
||||||
|
s.SISTEMA_OPERATIVO AS os_id
|
||||||
|
FROM segnalazioni s
|
||||||
|
LEFT JOIN competenze c ON c.ID = s.COMPETENZA
|
||||||
|
LEFT JOIN prodotti p ON p.ID = s.PRODOTTO
|
||||||
|
LEFT JOIN aree a ON a.ID = s.AREA
|
||||||
|
LEFT JOIN sottoaree sa ON sa.ID = s.SOTTOAREA
|
||||||
|
LEFT JOIN clienti cl ON cl.ID = s.CLIENTE
|
||||||
|
LEFT JOIN gravita g ON g.ID = s.GRAVITA
|
||||||
|
LEFT JOIN stati st ON st.ID = s.STATO
|
||||||
|
WHERE s.TICKET > %s
|
||||||
|
AND s.SOLUZIONE IS NOT NULL
|
||||||
|
AND TRIM(s.SOLUZIONE) <> ''
|
||||||
|
ORDER BY s.TICKET
|
||||||
|
LIMIT %s
|
||||||
|
"""
|
||||||
|
cursor.execute(query, (last_ticket, limit))
|
||||||
|
records = cursor.fetchall()
|
||||||
|
closeConnection(connection, cursor)
|
||||||
|
return records
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# print(getTicketByProblema("CERCA SABRINA"))
|
||||||
|
# print(getTicketTest("P", "24"))
|
||||||
84
conn/tickets.py
Normal file
84
conn/tickets.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
|
||||||
|
import connection
|
||||||
|
|
||||||
|
def getConn():
|
||||||
|
c = connection.conn()
|
||||||
|
return c
|
||||||
|
|
||||||
|
def closeConnection(connection,cursor):
|
||||||
|
if connection:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
# print("POstgres connection closed successfully")
|
||||||
|
# print("Connection was closed before")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Insert a ticket if not exsists
|
||||||
|
def insertTicket(fid, ticket):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgres_insert_query = """ INSERT INTO tickets (fid, ticket) VALUES (%s,%s)"""
|
||||||
|
record_to_insert = (fid, ticket)
|
||||||
|
cursor.execute(postgres_insert_query, record_to_insert)
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
count = cursor.rowcount
|
||||||
|
if count <1:
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return False
|
||||||
|
print(count, "Record inserted successfully into ticket table")
|
||||||
|
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def getTicketsByTid(tid):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = """select * from tickets join filters on tickets.fid = filters.fid where filters.tid = %s order by filters.tid"""
|
||||||
|
record_to_insert = (tid,)
|
||||||
|
cursor.execute(postgreSQL_select_Query, record_to_insert)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
# Returns all the ticket by filter id and ticket
|
||||||
|
def getTickets(fid, ticket):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = """select * from tickets where tickets.fid = %s and tickets.ticket = %s"""
|
||||||
|
record_to_insert = (fid, ticket)
|
||||||
|
cursor.execute(postgreSQL_select_Query, record_to_insert)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
def getTicketForTid(tid, ticket):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = """
|
||||||
|
select tickets.*
|
||||||
|
from tickets
|
||||||
|
join filters on tickets.fid = filters.fid
|
||||||
|
where filters.tid = %s and tickets.ticket = %s
|
||||||
|
limit 1
|
||||||
|
"""
|
||||||
|
record_to_insert = (tid, ticket)
|
||||||
|
cursor.execute(postgreSQL_select_Query, record_to_insert)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# print(getTicketsByTid(145645559))
|
||||||
92
conn/user.py
Normal file
92
conn/user.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
import connection
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getConn():
|
||||||
|
c = connection.conn()
|
||||||
|
return c
|
||||||
|
|
||||||
|
def closeConnection(connection,cursor):
|
||||||
|
if connection:
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
'''Insert a telegram user if it doesnt exist
|
||||||
|
Return True if user has been inserted successfully, False otherwise
|
||||||
|
'''
|
||||||
|
def insertUser(tid, name, surname, status='P', admin=False ):
|
||||||
|
if getUserByTid(tid):
|
||||||
|
return False
|
||||||
|
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
postgres_insert_query = """ INSERT INTO users (tid, username, surname, status, user_admin) VALUES (%s,%s,%s,%s,%s)"""
|
||||||
|
record_to_insert = (tid, name, surname, status, admin)
|
||||||
|
cursor.execute(postgres_insert_query, record_to_insert)
|
||||||
|
|
||||||
|
connection.commit()
|
||||||
|
count = cursor.rowcount
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
|
||||||
|
if count <1:
|
||||||
|
return False
|
||||||
|
print(count, "Record inserted successfully into users table")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# Returns all the user registered on bot
|
||||||
|
def getUsers():
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select users.tid from users"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
|
||||||
|
''' Gets the user by telegram id '''
|
||||||
|
def getUserByTid(tid):
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_select_Query = "select * from users where tid=" + str(tid)
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_select_Query)
|
||||||
|
publisher_records = cursor.fetchall()
|
||||||
|
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return publisher_records
|
||||||
|
# if not publisher_records:
|
||||||
|
# return False
|
||||||
|
# else:
|
||||||
|
# return True
|
||||||
|
|
||||||
|
|
||||||
|
def approveUser(tid):
|
||||||
|
|
||||||
|
alreadyApproved = getUserByTid(tid)
|
||||||
|
connection = getConn()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
postgreSQL_update_Query = "UPDATE users SET status = 'A' WHERE tid = %s"
|
||||||
|
|
||||||
|
cursor.execute(postgreSQL_update_Query, (tid,))
|
||||||
|
connection.commit()
|
||||||
|
count = cursor.rowcount
|
||||||
|
print(count, "Record updated successfully ")
|
||||||
|
closeConnection(connection,cursor)
|
||||||
|
return count > 0, alreadyApproved
|
||||||
|
|
||||||
|
|
||||||
|
# insertUser(22222, 'boh','bah')
|
||||||
|
#getUsers()
|
||||||
|
# if getUserByTid(145645559):
|
||||||
|
# print(getUserByTid(145645559)[0][3])
|
||||||
|
|
||||||
9
dependencies.txt
Normal file
9
dependencies.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
telepot
|
||||||
|
psycopg2-binary
|
||||||
|
requests
|
||||||
|
pdfkit
|
||||||
|
mysql-connector-python==8.0.26
|
||||||
|
numpy
|
||||||
|
scipy
|
||||||
|
scikit-learn
|
||||||
|
joblib
|
||||||
86
docker-compose.yml
Normal file
86
docker-compose.yml
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:17
|
||||||
|
container_name: ticket-postgres
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ticket
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-localpassword}"
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:5444:5432"
|
||||||
|
volumes:
|
||||||
|
- ticket_postgres_data:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres -d ticket"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 10
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
|
bot:
|
||||||
|
build: .
|
||||||
|
image: ticket-bot:production
|
||||||
|
container_name: ticket-bot
|
||||||
|
restart: unless-stopped
|
||||||
|
network_mode: host
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
TZ: Europe/Rome
|
||||||
|
PYTHONUNBUFFERED: "1"
|
||||||
|
|
||||||
|
TICKET_PG_HOST: "127.0.0.1"
|
||||||
|
TICKET_PG_PORT: "5444"
|
||||||
|
TICKET_PG_DATABASE: "ticket"
|
||||||
|
TICKET_PG_USER: "postgres"
|
||||||
|
TICKET_PG_PASSWORD: "${TICKET_PG_PASSWORD:-localpassword}"
|
||||||
|
|
||||||
|
TICKET_MYSQL_HOST: "${TICKET_MYSQL_HOST:-127.0.0.1}"
|
||||||
|
TICKET_MYSQL_PORT: "${TICKET_MYSQL_PORT:-3307}"
|
||||||
|
TICKET_MYSQL_DATABASE: "${TICKET_MYSQL_DATABASE:-smits}"
|
||||||
|
TICKET_MYSQL_USER: "${TICKET_MYSQL_USER:-reader}"
|
||||||
|
TICKET_MYSQL_PASSWORD: "${TICKET_MYSQL_PASSWORD:-localpassword}"
|
||||||
|
TICKET_MYSQL_CHARSET: "${TICKET_MYSQL_CHARSET:-utf8}"
|
||||||
|
|
||||||
|
TICKET_TELEGRAM_TOKEN: "${TICKET_TELEGRAM_TOKEN:-}"
|
||||||
|
TICKET_ADMIN_ID: "${TICKET_ADMIN_ID:-145645559}"
|
||||||
|
TICKET_ENABLE_NOTIFICATIONS: "${TICKET_ENABLE_NOTIFICATIONS:-true}"
|
||||||
|
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: web/Dockerfile
|
||||||
|
image: ticket-web:production
|
||||||
|
container_name: ticket-web
|
||||||
|
restart: unless-stopped
|
||||||
|
network_mode: host
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
TZ: Europe/Rome
|
||||||
|
PYTHONUNBUFFERED: "1"
|
||||||
|
|
||||||
|
TICKET_PG_HOST: "127.0.0.1"
|
||||||
|
TICKET_PG_PORT: "5444"
|
||||||
|
TICKET_PG_DATABASE: "ticket"
|
||||||
|
TICKET_PG_USER: "postgres"
|
||||||
|
TICKET_PG_PASSWORD: "${TICKET_PG_PASSWORD:-localpassword}"
|
||||||
|
|
||||||
|
TICKET_MYSQL_HOST: "${TICKET_MYSQL_HOST:-127.0.0.1}"
|
||||||
|
TICKET_MYSQL_PORT: "${TICKET_MYSQL_PORT:-3307}"
|
||||||
|
TICKET_MYSQL_DATABASE: "${TICKET_MYSQL_DATABASE:-smits}"
|
||||||
|
TICKET_MYSQL_USER: "${TICKET_MYSQL_USER:-reader}"
|
||||||
|
TICKET_MYSQL_PASSWORD: "${TICKET_MYSQL_PASSWORD:-localpassword}"
|
||||||
|
TICKET_MYSQL_CHARSET: "${TICKET_MYSQL_CHARSET:-utf8}"
|
||||||
|
|
||||||
|
TICKET_WEB_ADMIN_USERNAME: "${TICKET_WEB_ADMIN_USERNAME:-admin}"
|
||||||
|
TICKET_WEB_ADMIN_PASSWORD: "${TICKET_WEB_ADMIN_PASSWORD:-change-me-now}"
|
||||||
|
TICKET_WEB_COOKIE_SECURE: "${TICKET_WEB_COOKIE_SECURE:-false}"
|
||||||
|
TICKET_WEB_SESSION_DAYS: "${TICKET_WEB_SESSION_DAYS:-7}"
|
||||||
|
TICKET_WEB_STATIC_DIR: "/app/web/static"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
ticket_postgres_data:
|
||||||
BIN
gifs/welcome.gif
Normal file
BIN
gifs/welcome.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 865 KiB |
0
json/empty.txt
Normal file
0
json/empty.txt
Normal file
1
node_sid/node_modules/.bin/sshpk-conv
generated
vendored
Symbolic link
1
node_sid/node_modules/.bin/sshpk-conv
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../sshpk/bin/sshpk-conv
|
||||||
1
node_sid/node_modules/.bin/sshpk-sign
generated
vendored
Symbolic link
1
node_sid/node_modules/.bin/sshpk-sign
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../sshpk/bin/sshpk-sign
|
||||||
1
node_sid/node_modules/.bin/sshpk-verify
generated
vendored
Symbolic link
1
node_sid/node_modules/.bin/sshpk-verify
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../sshpk/bin/sshpk-verify
|
||||||
1
node_sid/node_modules/.bin/uuid
generated
vendored
Symbolic link
1
node_sid/node_modules/.bin/uuid
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../uuid/bin/uuid
|
||||||
434
node_sid/node_modules/.package-lock.json
generated
vendored
Normal file
434
node_sid/node_modules/.package-lock.json
generated
vendored
Normal file
@@ -0,0 +1,434 @@
|
|||||||
|
{
|
||||||
|
"name": "node_sid",
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"node_modules/ajv": {
|
||||||
|
"version": "6.12.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
|
||||||
|
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
|
||||||
|
"dependencies": {
|
||||||
|
"fast-deep-equal": "^3.1.1",
|
||||||
|
"fast-json-stable-stringify": "^2.0.0",
|
||||||
|
"json-schema-traverse": "^0.4.1",
|
||||||
|
"uri-js": "^4.2.2"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/epoberezkin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/asn1": {
|
||||||
|
"version": "0.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz",
|
||||||
|
"integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"safer-buffer": "~2.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/assert-plus": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
|
},
|
||||||
|
"node_modules/aws-sign2": {
|
||||||
|
"version": "0.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
|
||||||
|
"integrity": "sha512-08kcGqnYf/YmjoRhfxyu+CLxBjUtHLXLXX/vUfx9l2LYzG3c1m61nrpyFUZI6zeS+Li/wWMMidD9KgrqtGq3mA==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/aws4": {
|
||||||
|
"version": "1.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
|
||||||
|
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
|
||||||
|
},
|
||||||
|
"node_modules/bcrypt-pbkdf": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==",
|
||||||
|
"dependencies": {
|
||||||
|
"tweetnacl": "^0.14.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/caseless": {
|
||||||
|
"version": "0.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
|
||||||
|
"integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw=="
|
||||||
|
},
|
||||||
|
"node_modules/combined-stream": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"dependencies": {
|
||||||
|
"delayed-stream": "~1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/core-util-is": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ=="
|
||||||
|
},
|
||||||
|
"node_modules/dashdash": {
|
||||||
|
"version": "1.14.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||||
|
"integrity": "sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==",
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/delayed-stream": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ecc-jsbn": {
|
||||||
|
"version": "0.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||||
|
"integrity": "sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==",
|
||||||
|
"dependencies": {
|
||||||
|
"jsbn": "~0.1.0",
|
||||||
|
"safer-buffer": "^2.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/extend": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="
|
||||||
|
},
|
||||||
|
"node_modules/extsprintf": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==",
|
||||||
|
"engines": [
|
||||||
|
"node >=0.6.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/fast-deep-equal": {
|
||||||
|
"version": "3.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||||
|
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
|
||||||
|
},
|
||||||
|
"node_modules/fast-json-stable-stringify": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
|
||||||
|
},
|
||||||
|
"node_modules/forever-agent": {
|
||||||
|
"version": "0.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||||
|
"integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/form-data": {
|
||||||
|
"version": "2.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
|
||||||
|
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.6",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/getpass": {
|
||||||
|
"version": "0.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||||
|
"integrity": "sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==",
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/har-schema": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Oqluz6zhGX8cyRaTQlFMPw80bSJVG2x/cFb8ZPhUILGgHka9SsokCCOQgpveePerqidZOrT14ipqfJb7ILcW5Q==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/har-validator": {
|
||||||
|
"version": "5.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz",
|
||||||
|
"integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==",
|
||||||
|
"deprecated": "this library is no longer supported",
|
||||||
|
"dependencies": {
|
||||||
|
"ajv": "^6.12.3",
|
||||||
|
"har-schema": "^2.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/http-signature": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-CAbnr6Rz4CYQkLYUtSNXxQPUH2gK8f3iWexVlsnMeD+GjlsQ0Xsy1cOX+mN3dtxYomRy21CiOzU8Uhw6OwncEQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0",
|
||||||
|
"jsprim": "^1.2.2",
|
||||||
|
"sshpk": "^1.7.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8",
|
||||||
|
"npm": ">=1.3.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/is-typedarray": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA=="
|
||||||
|
},
|
||||||
|
"node_modules/isstream": {
|
||||||
|
"version": "0.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||||
|
"integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g=="
|
||||||
|
},
|
||||||
|
"node_modules/jsbn": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
||||||
|
"integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg=="
|
||||||
|
},
|
||||||
|
"node_modules/json-schema": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA=="
|
||||||
|
},
|
||||||
|
"node_modules/json-schema-traverse": {
|
||||||
|
"version": "0.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||||
|
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
|
||||||
|
},
|
||||||
|
"node_modules/json-stringify-safe": {
|
||||||
|
"version": "5.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
|
||||||
|
"integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA=="
|
||||||
|
},
|
||||||
|
"node_modules/jsprim": {
|
||||||
|
"version": "1.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz",
|
||||||
|
"integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==",
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "1.0.0",
|
||||||
|
"extsprintf": "1.3.0",
|
||||||
|
"json-schema": "0.4.0",
|
||||||
|
"verror": "1.10.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-db": {
|
||||||
|
"version": "1.52.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-types": {
|
||||||
|
"version": "2.1.35",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||||
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||||
|
"dependencies": {
|
||||||
|
"mime-db": "1.52.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/oauth-sign": {
|
||||||
|
"version": "0.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||||
|
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/performance-now": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||||
|
"integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="
|
||||||
|
},
|
||||||
|
"node_modules/psl": {
|
||||||
|
"version": "1.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
|
||||||
|
"integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag=="
|
||||||
|
},
|
||||||
|
"node_modules/punycode": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/qs": {
|
||||||
|
"version": "6.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz",
|
||||||
|
"integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/request": {
|
||||||
|
"version": "2.88.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
|
||||||
|
"integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==",
|
||||||
|
"deprecated": "request has been deprecated, see https://github.com/request/request/issues/3142",
|
||||||
|
"dependencies": {
|
||||||
|
"aws-sign2": "~0.7.0",
|
||||||
|
"aws4": "^1.8.0",
|
||||||
|
"caseless": "~0.12.0",
|
||||||
|
"combined-stream": "~1.0.6",
|
||||||
|
"extend": "~3.0.2",
|
||||||
|
"forever-agent": "~0.6.1",
|
||||||
|
"form-data": "~2.3.2",
|
||||||
|
"har-validator": "~5.1.3",
|
||||||
|
"http-signature": "~1.2.0",
|
||||||
|
"is-typedarray": "~1.0.0",
|
||||||
|
"isstream": "~0.1.2",
|
||||||
|
"json-stringify-safe": "~5.0.1",
|
||||||
|
"mime-types": "~2.1.19",
|
||||||
|
"oauth-sign": "~0.9.0",
|
||||||
|
"performance-now": "^2.1.0",
|
||||||
|
"qs": "~6.5.2",
|
||||||
|
"safe-buffer": "^5.1.2",
|
||||||
|
"tough-cookie": "~2.5.0",
|
||||||
|
"tunnel-agent": "^0.6.0",
|
||||||
|
"uuid": "^3.3.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/safe-buffer": {
|
||||||
|
"version": "5.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||||
|
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/safer-buffer": {
|
||||||
|
"version": "2.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
|
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||||
|
},
|
||||||
|
"node_modules/sshpk": {
|
||||||
|
"version": "1.17.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz",
|
||||||
|
"integrity": "sha512-/9HIEs1ZXGhSPE8X6Ccm7Nam1z8KcoCqPdI7ecm1N33EzAetWahvQWVqLZtaZQ+IDKX4IyA2o0gBzqIMkAagHQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"asn1": "~0.2.3",
|
||||||
|
"assert-plus": "^1.0.0",
|
||||||
|
"bcrypt-pbkdf": "^1.0.0",
|
||||||
|
"dashdash": "^1.12.0",
|
||||||
|
"ecc-jsbn": "~0.1.1",
|
||||||
|
"getpass": "^0.1.1",
|
||||||
|
"jsbn": "~0.1.0",
|
||||||
|
"safer-buffer": "^2.0.2",
|
||||||
|
"tweetnacl": "~0.14.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"sshpk-conv": "bin/sshpk-conv",
|
||||||
|
"sshpk-sign": "bin/sshpk-sign",
|
||||||
|
"sshpk-verify": "bin/sshpk-verify"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tough-cookie": {
|
||||||
|
"version": "2.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
|
||||||
|
"integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
|
||||||
|
"dependencies": {
|
||||||
|
"psl": "^1.1.28",
|
||||||
|
"punycode": "^2.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tunnel-agent": {
|
||||||
|
"version": "0.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
||||||
|
"integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==",
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": "^5.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tweetnacl": {
|
||||||
|
"version": "0.14.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||||
|
"integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA=="
|
||||||
|
},
|
||||||
|
"node_modules/uri-js": {
|
||||||
|
"version": "4.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
|
||||||
|
"integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==",
|
||||||
|
"dependencies": {
|
||||||
|
"punycode": "^2.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/uuid": {
|
||||||
|
"version": "3.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
|
||||||
|
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
|
||||||
|
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
|
||||||
|
"bin": {
|
||||||
|
"uuid": "bin/uuid"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/verror": {
|
||||||
|
"version": "1.10.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
|
||||||
|
"integrity": "sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==",
|
||||||
|
"engines": [
|
||||||
|
"node >=0.6.0"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"assert-plus": "^1.0.0",
|
||||||
|
"core-util-is": "1.0.2",
|
||||||
|
"extsprintf": "^1.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
node_sid/node_modules/ajv/.tonic_example.js
generated
vendored
Normal file
20
node_sid/node_modules/ajv/.tonic_example.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
var Ajv = require('ajv');
|
||||||
|
var ajv = new Ajv({allErrors: true});
|
||||||
|
|
||||||
|
var schema = {
|
||||||
|
"properties": {
|
||||||
|
"foo": { "type": "string" },
|
||||||
|
"bar": { "type": "number", "maximum": 3 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var validate = ajv.compile(schema);
|
||||||
|
|
||||||
|
test({"foo": "abc", "bar": 2});
|
||||||
|
test({"foo": 2, "bar": 4});
|
||||||
|
|
||||||
|
function test(data) {
|
||||||
|
var valid = validate(data);
|
||||||
|
if (valid) console.log('Valid!');
|
||||||
|
else console.log('Invalid: ' + ajv.errorsText(validate.errors));
|
||||||
|
}
|
||||||
22
node_sid/node_modules/ajv/LICENSE
generated
vendored
Normal file
22
node_sid/node_modules/ajv/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015-2017 Evgeny Poberezkin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
1497
node_sid/node_modules/ajv/README.md
generated
vendored
Normal file
1497
node_sid/node_modules/ajv/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
7189
node_sid/node_modules/ajv/dist/ajv.bundle.js
generated
vendored
Normal file
7189
node_sid/node_modules/ajv/dist/ajv.bundle.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
node_sid/node_modules/ajv/dist/ajv.min.js
generated
vendored
Normal file
3
node_sid/node_modules/ajv/dist/ajv.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_sid/node_modules/ajv/dist/ajv.min.js.map
generated
vendored
Normal file
1
node_sid/node_modules/ajv/dist/ajv.min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
397
node_sid/node_modules/ajv/lib/ajv.d.ts
generated
vendored
Normal file
397
node_sid/node_modules/ajv/lib/ajv.d.ts
generated
vendored
Normal file
@@ -0,0 +1,397 @@
|
|||||||
|
declare var ajv: {
|
||||||
|
(options?: ajv.Options): ajv.Ajv;
|
||||||
|
new(options?: ajv.Options): ajv.Ajv;
|
||||||
|
ValidationError: typeof AjvErrors.ValidationError;
|
||||||
|
MissingRefError: typeof AjvErrors.MissingRefError;
|
||||||
|
$dataMetaSchema: object;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace AjvErrors {
|
||||||
|
class ValidationError extends Error {
|
||||||
|
constructor(errors: Array<ajv.ErrorObject>);
|
||||||
|
|
||||||
|
message: string;
|
||||||
|
errors: Array<ajv.ErrorObject>;
|
||||||
|
ajv: true;
|
||||||
|
validation: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MissingRefError extends Error {
|
||||||
|
constructor(baseId: string, ref: string, message?: string);
|
||||||
|
static message: (baseId: string, ref: string) => string;
|
||||||
|
|
||||||
|
message: string;
|
||||||
|
missingRef: string;
|
||||||
|
missingSchema: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace ajv {
|
||||||
|
type ValidationError = AjvErrors.ValidationError;
|
||||||
|
|
||||||
|
type MissingRefError = AjvErrors.MissingRefError;
|
||||||
|
|
||||||
|
interface Ajv {
|
||||||
|
/**
|
||||||
|
* Validate data using schema
|
||||||
|
* Schema will be compiled and cached (using serialized JSON as key, [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize by default).
|
||||||
|
* @param {string|object|Boolean} schemaKeyRef key, ref or schema object
|
||||||
|
* @param {Any} data to be validated
|
||||||
|
* @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
|
||||||
|
*/
|
||||||
|
validate(schemaKeyRef: object | string | boolean, data: any): boolean | PromiseLike<any>;
|
||||||
|
/**
|
||||||
|
* Create validating function for passed schema.
|
||||||
|
* @param {object|Boolean} schema schema object
|
||||||
|
* @return {Function} validating function
|
||||||
|
*/
|
||||||
|
compile(schema: object | boolean): ValidateFunction;
|
||||||
|
/**
|
||||||
|
* Creates validating function for passed schema with asynchronous loading of missing schemas.
|
||||||
|
* `loadSchema` option should be a function that accepts schema uri and node-style callback.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {object|Boolean} schema schema object
|
||||||
|
* @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
|
||||||
|
* @param {Function} callback optional node-style callback, it is always called with 2 parameters: error (or null) and validating function.
|
||||||
|
* @return {PromiseLike<ValidateFunction>} validating function
|
||||||
|
*/
|
||||||
|
compileAsync(schema: object | boolean, meta?: Boolean, callback?: (err: Error, validate: ValidateFunction) => any): PromiseLike<ValidateFunction>;
|
||||||
|
/**
|
||||||
|
* Adds schema to the instance.
|
||||||
|
* @param {object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
|
||||||
|
* @param {string} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
addSchema(schema: Array<object> | object, key?: string): Ajv;
|
||||||
|
/**
|
||||||
|
* Add schema that will be used to validate other schemas
|
||||||
|
* options in META_IGNORE_OPTIONS are alway set to false
|
||||||
|
* @param {object} schema schema object
|
||||||
|
* @param {string} key optional schema key
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
addMetaSchema(schema: object, key?: string): Ajv;
|
||||||
|
/**
|
||||||
|
* Validate schema
|
||||||
|
* @param {object|Boolean} schema schema to validate
|
||||||
|
* @return {Boolean} true if schema is valid
|
||||||
|
*/
|
||||||
|
validateSchema(schema: object | boolean): boolean;
|
||||||
|
/**
|
||||||
|
* Get compiled schema from the instance by `key` or `ref`.
|
||||||
|
* @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
|
||||||
|
* @return {Function} schema validating function (with property `schema`). Returns undefined if keyRef can't be resolved to an existing schema.
|
||||||
|
*/
|
||||||
|
getSchema(keyRef: string): ValidateFunction | undefined;
|
||||||
|
/**
|
||||||
|
* Remove cached schema(s).
|
||||||
|
* If no parameter is passed all schemas but meta-schemas are removed.
|
||||||
|
* If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
|
||||||
|
* Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
|
||||||
|
* @param {string|object|RegExp|Boolean} schemaKeyRef key, ref, pattern to match key/ref or schema object
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv;
|
||||||
|
/**
|
||||||
|
* Add custom format
|
||||||
|
* @param {string} name format name
|
||||||
|
* @param {string|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
addFormat(name: string, format: FormatValidator | FormatDefinition): Ajv;
|
||||||
|
/**
|
||||||
|
* Define custom keyword
|
||||||
|
* @this Ajv
|
||||||
|
* @param {string} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
|
||||||
|
* @param {object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
addKeyword(keyword: string, definition: KeywordDefinition): Ajv;
|
||||||
|
/**
|
||||||
|
* Get keyword definition
|
||||||
|
* @this Ajv
|
||||||
|
* @param {string} keyword pre-defined or custom keyword.
|
||||||
|
* @return {object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
|
||||||
|
*/
|
||||||
|
getKeyword(keyword: string): object | boolean;
|
||||||
|
/**
|
||||||
|
* Remove keyword
|
||||||
|
* @this Ajv
|
||||||
|
* @param {string} keyword pre-defined or custom keyword.
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
removeKeyword(keyword: string): Ajv;
|
||||||
|
/**
|
||||||
|
* Validate keyword
|
||||||
|
* @this Ajv
|
||||||
|
* @param {object} definition keyword definition object
|
||||||
|
* @param {boolean} throwError true to throw exception if definition is invalid
|
||||||
|
* @return {boolean} validation result
|
||||||
|
*/
|
||||||
|
validateKeyword(definition: KeywordDefinition, throwError: boolean): boolean;
|
||||||
|
/**
|
||||||
|
* Convert array of error message objects to string
|
||||||
|
* @param {Array<object>} errors optional array of validation errors, if not passed errors from the instance are used.
|
||||||
|
* @param {object} options optional options with properties `separator` and `dataVar`.
|
||||||
|
* @return {string} human readable string with all errors descriptions
|
||||||
|
*/
|
||||||
|
errorsText(errors?: Array<ErrorObject> | null, options?: ErrorsTextOptions): string;
|
||||||
|
errors?: Array<ErrorObject> | null;
|
||||||
|
_opts: Options;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CustomLogger {
|
||||||
|
log(...args: any[]): any;
|
||||||
|
warn(...args: any[]): any;
|
||||||
|
error(...args: any[]): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ValidateFunction {
|
||||||
|
(
|
||||||
|
data: any,
|
||||||
|
dataPath?: string,
|
||||||
|
parentData?: object | Array<any>,
|
||||||
|
parentDataProperty?: string | number,
|
||||||
|
rootData?: object | Array<any>
|
||||||
|
): boolean | PromiseLike<any>;
|
||||||
|
schema?: object | boolean;
|
||||||
|
errors?: null | Array<ErrorObject>;
|
||||||
|
refs?: object;
|
||||||
|
refVal?: Array<any>;
|
||||||
|
root?: ValidateFunction | object;
|
||||||
|
$async?: true;
|
||||||
|
source?: object;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
$data?: boolean;
|
||||||
|
allErrors?: boolean;
|
||||||
|
verbose?: boolean;
|
||||||
|
jsonPointers?: boolean;
|
||||||
|
uniqueItems?: boolean;
|
||||||
|
unicode?: boolean;
|
||||||
|
format?: false | string;
|
||||||
|
formats?: object;
|
||||||
|
keywords?: object;
|
||||||
|
unknownFormats?: true | string[] | 'ignore';
|
||||||
|
schemas?: Array<object> | object;
|
||||||
|
schemaId?: '$id' | 'id' | 'auto';
|
||||||
|
missingRefs?: true | 'ignore' | 'fail';
|
||||||
|
extendRefs?: true | 'ignore' | 'fail';
|
||||||
|
loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
|
||||||
|
removeAdditional?: boolean | 'all' | 'failing';
|
||||||
|
useDefaults?: boolean | 'empty' | 'shared';
|
||||||
|
coerceTypes?: boolean | 'array';
|
||||||
|
strictDefaults?: boolean | 'log';
|
||||||
|
strictKeywords?: boolean | 'log';
|
||||||
|
strictNumbers?: boolean;
|
||||||
|
async?: boolean | string;
|
||||||
|
transpile?: string | ((code: string) => string);
|
||||||
|
meta?: boolean | object;
|
||||||
|
validateSchema?: boolean | 'log';
|
||||||
|
addUsedSchema?: boolean;
|
||||||
|
inlineRefs?: boolean | number;
|
||||||
|
passContext?: boolean;
|
||||||
|
loopRequired?: number;
|
||||||
|
ownProperties?: boolean;
|
||||||
|
multipleOfPrecision?: boolean | number;
|
||||||
|
errorDataPath?: string,
|
||||||
|
messages?: boolean;
|
||||||
|
sourceCode?: boolean;
|
||||||
|
processCode?: (code: string, schema: object) => string;
|
||||||
|
cache?: object;
|
||||||
|
logger?: CustomLogger | false;
|
||||||
|
nullable?: boolean;
|
||||||
|
serialize?: ((schema: object | boolean) => any) | false;
|
||||||
|
}
|
||||||
|
|
||||||
|
type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);
|
||||||
|
type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);
|
||||||
|
|
||||||
|
interface NumberFormatDefinition {
|
||||||
|
type: "number",
|
||||||
|
validate: NumberFormatValidator;
|
||||||
|
compare?: (data1: number, data2: number) => number;
|
||||||
|
async?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StringFormatDefinition {
|
||||||
|
type?: "string",
|
||||||
|
validate: FormatValidator;
|
||||||
|
compare?: (data1: string, data2: string) => number;
|
||||||
|
async?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;
|
||||||
|
|
||||||
|
interface KeywordDefinition {
|
||||||
|
type?: string | Array<string>;
|
||||||
|
async?: boolean;
|
||||||
|
$data?: boolean;
|
||||||
|
errors?: boolean | string;
|
||||||
|
metaSchema?: object;
|
||||||
|
// schema: false makes validate not to expect schema (ValidateFunction)
|
||||||
|
schema?: boolean;
|
||||||
|
statements?: boolean;
|
||||||
|
dependencies?: Array<string>;
|
||||||
|
modifying?: boolean;
|
||||||
|
valid?: boolean;
|
||||||
|
// one and only one of the following properties should be present
|
||||||
|
validate?: SchemaValidateFunction | ValidateFunction;
|
||||||
|
compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;
|
||||||
|
macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;
|
||||||
|
inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CompilationContext {
|
||||||
|
level: number;
|
||||||
|
dataLevel: number;
|
||||||
|
dataPathArr: string[];
|
||||||
|
schema: any;
|
||||||
|
schemaPath: string;
|
||||||
|
baseId: string;
|
||||||
|
async: boolean;
|
||||||
|
opts: Options;
|
||||||
|
formats: {
|
||||||
|
[index: string]: FormatDefinition | undefined;
|
||||||
|
};
|
||||||
|
keywords: {
|
||||||
|
[index: string]: KeywordDefinition | undefined;
|
||||||
|
};
|
||||||
|
compositeRule: boolean;
|
||||||
|
validate: (schema: object) => boolean;
|
||||||
|
util: {
|
||||||
|
copy(obj: any, target?: any): any;
|
||||||
|
toHash(source: string[]): { [index: string]: true | undefined };
|
||||||
|
equal(obj: any, target: any): boolean;
|
||||||
|
getProperty(str: string): string;
|
||||||
|
schemaHasRules(schema: object, rules: any): string;
|
||||||
|
escapeQuotes(str: string): string;
|
||||||
|
toQuotedString(str: string): string;
|
||||||
|
getData(jsonPointer: string, dataLevel: number, paths: string[]): string;
|
||||||
|
escapeJsonPointer(str: string): string;
|
||||||
|
unescapeJsonPointer(str: string): string;
|
||||||
|
escapeFragment(str: string): string;
|
||||||
|
unescapeFragment(str: string): string;
|
||||||
|
};
|
||||||
|
self: Ajv;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SchemaValidateFunction {
|
||||||
|
(
|
||||||
|
schema: any,
|
||||||
|
data: any,
|
||||||
|
parentSchema?: object,
|
||||||
|
dataPath?: string,
|
||||||
|
parentData?: object | Array<any>,
|
||||||
|
parentDataProperty?: string | number,
|
||||||
|
rootData?: object | Array<any>
|
||||||
|
): boolean | PromiseLike<any>;
|
||||||
|
errors?: Array<ErrorObject>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ErrorsTextOptions {
|
||||||
|
separator?: string;
|
||||||
|
dataVar?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ErrorObject {
|
||||||
|
keyword: string;
|
||||||
|
dataPath: string;
|
||||||
|
schemaPath: string;
|
||||||
|
params: ErrorParameters;
|
||||||
|
// Added to validation errors of propertyNames keyword schema
|
||||||
|
propertyName?: string;
|
||||||
|
// Excluded if messages set to false.
|
||||||
|
message?: string;
|
||||||
|
// These are added with the `verbose` option.
|
||||||
|
schema?: any;
|
||||||
|
parentSchema?: object;
|
||||||
|
data?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
|
||||||
|
DependenciesParams | FormatParams | ComparisonParams |
|
||||||
|
MultipleOfParams | PatternParams | RequiredParams |
|
||||||
|
TypeParams | UniqueItemsParams | CustomParams |
|
||||||
|
PatternRequiredParams | PropertyNamesParams |
|
||||||
|
IfParams | SwitchParams | NoParams | EnumParams;
|
||||||
|
|
||||||
|
interface RefParams {
|
||||||
|
ref: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LimitParams {
|
||||||
|
limit: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AdditionalPropertiesParams {
|
||||||
|
additionalProperty: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DependenciesParams {
|
||||||
|
property: string;
|
||||||
|
missingProperty: string;
|
||||||
|
depsCount: number;
|
||||||
|
deps: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormatParams {
|
||||||
|
format: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ComparisonParams {
|
||||||
|
comparison: string;
|
||||||
|
limit: number | string;
|
||||||
|
exclusive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MultipleOfParams {
|
||||||
|
multipleOf: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PatternParams {
|
||||||
|
pattern: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RequiredParams {
|
||||||
|
missingProperty: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TypeParams {
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface UniqueItemsParams {
|
||||||
|
i: number;
|
||||||
|
j: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CustomParams {
|
||||||
|
keyword: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PatternRequiredParams {
|
||||||
|
missingPattern: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PropertyNamesParams {
|
||||||
|
propertyName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IfParams {
|
||||||
|
failingKeyword: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SwitchParams {
|
||||||
|
caseIndex: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface NoParams { }
|
||||||
|
|
||||||
|
interface EnumParams {
|
||||||
|
allowedValues: Array<any>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export = ajv;
|
||||||
506
node_sid/node_modules/ajv/lib/ajv.js
generated
vendored
Normal file
506
node_sid/node_modules/ajv/lib/ajv.js
generated
vendored
Normal file
@@ -0,0 +1,506 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var compileSchema = require('./compile')
|
||||||
|
, resolve = require('./compile/resolve')
|
||||||
|
, Cache = require('./cache')
|
||||||
|
, SchemaObject = require('./compile/schema_obj')
|
||||||
|
, stableStringify = require('fast-json-stable-stringify')
|
||||||
|
, formats = require('./compile/formats')
|
||||||
|
, rules = require('./compile/rules')
|
||||||
|
, $dataMetaSchema = require('./data')
|
||||||
|
, util = require('./compile/util');
|
||||||
|
|
||||||
|
module.exports = Ajv;
|
||||||
|
|
||||||
|
Ajv.prototype.validate = validate;
|
||||||
|
Ajv.prototype.compile = compile;
|
||||||
|
Ajv.prototype.addSchema = addSchema;
|
||||||
|
Ajv.prototype.addMetaSchema = addMetaSchema;
|
||||||
|
Ajv.prototype.validateSchema = validateSchema;
|
||||||
|
Ajv.prototype.getSchema = getSchema;
|
||||||
|
Ajv.prototype.removeSchema = removeSchema;
|
||||||
|
Ajv.prototype.addFormat = addFormat;
|
||||||
|
Ajv.prototype.errorsText = errorsText;
|
||||||
|
|
||||||
|
Ajv.prototype._addSchema = _addSchema;
|
||||||
|
Ajv.prototype._compile = _compile;
|
||||||
|
|
||||||
|
Ajv.prototype.compileAsync = require('./compile/async');
|
||||||
|
var customKeyword = require('./keyword');
|
||||||
|
Ajv.prototype.addKeyword = customKeyword.add;
|
||||||
|
Ajv.prototype.getKeyword = customKeyword.get;
|
||||||
|
Ajv.prototype.removeKeyword = customKeyword.remove;
|
||||||
|
Ajv.prototype.validateKeyword = customKeyword.validate;
|
||||||
|
|
||||||
|
var errorClasses = require('./compile/error_classes');
|
||||||
|
Ajv.ValidationError = errorClasses.Validation;
|
||||||
|
Ajv.MissingRefError = errorClasses.MissingRef;
|
||||||
|
Ajv.$dataMetaSchema = $dataMetaSchema;
|
||||||
|
|
||||||
|
var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema';
|
||||||
|
|
||||||
|
var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ];
|
||||||
|
var META_SUPPORT_DATA = ['/properties'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates validator instance.
|
||||||
|
* Usage: `Ajv(opts)`
|
||||||
|
* @param {Object} opts optional options
|
||||||
|
* @return {Object} ajv instance
|
||||||
|
*/
|
||||||
|
function Ajv(opts) {
|
||||||
|
if (!(this instanceof Ajv)) return new Ajv(opts);
|
||||||
|
opts = this._opts = util.copy(opts) || {};
|
||||||
|
setLogger(this);
|
||||||
|
this._schemas = {};
|
||||||
|
this._refs = {};
|
||||||
|
this._fragments = {};
|
||||||
|
this._formats = formats(opts.format);
|
||||||
|
|
||||||
|
this._cache = opts.cache || new Cache;
|
||||||
|
this._loadingSchemas = {};
|
||||||
|
this._compilations = [];
|
||||||
|
this.RULES = rules();
|
||||||
|
this._getId = chooseGetId(opts);
|
||||||
|
|
||||||
|
opts.loopRequired = opts.loopRequired || Infinity;
|
||||||
|
if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
|
||||||
|
if (opts.serialize === undefined) opts.serialize = stableStringify;
|
||||||
|
this._metaOpts = getMetaSchemaOptions(this);
|
||||||
|
|
||||||
|
if (opts.formats) addInitialFormats(this);
|
||||||
|
if (opts.keywords) addInitialKeywords(this);
|
||||||
|
addDefaultMetaSchema(this);
|
||||||
|
if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
|
||||||
|
if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
|
||||||
|
addInitialSchemas(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate data using schema
|
||||||
|
* Schema will be compiled and cached (using serialized JSON as key. [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {String|Object} schemaKeyRef key, ref or schema object
|
||||||
|
* @param {Any} data to be validated
|
||||||
|
* @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
|
||||||
|
*/
|
||||||
|
function validate(schemaKeyRef, data) {
|
||||||
|
var v;
|
||||||
|
if (typeof schemaKeyRef == 'string') {
|
||||||
|
v = this.getSchema(schemaKeyRef);
|
||||||
|
if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
|
||||||
|
} else {
|
||||||
|
var schemaObj = this._addSchema(schemaKeyRef);
|
||||||
|
v = schemaObj.validate || this._compile(schemaObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
var valid = v(data);
|
||||||
|
if (v.$async !== true) this.errors = v.errors;
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create validating function for passed schema.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema object
|
||||||
|
* @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
|
||||||
|
* @return {Function} validating function
|
||||||
|
*/
|
||||||
|
function compile(schema, _meta) {
|
||||||
|
var schemaObj = this._addSchema(schema, undefined, _meta);
|
||||||
|
return schemaObj.validate || this._compile(schemaObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds schema to the instance.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
|
||||||
|
* @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
|
||||||
|
* @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
|
||||||
|
* @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
function addSchema(schema, key, _skipValidation, _meta) {
|
||||||
|
if (Array.isArray(schema)){
|
||||||
|
for (var i=0; i<schema.length; i++) this.addSchema(schema[i], undefined, _skipValidation, _meta);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
var id = this._getId(schema);
|
||||||
|
if (id !== undefined && typeof id != 'string')
|
||||||
|
throw new Error('schema id must be string');
|
||||||
|
key = resolve.normalizeId(key || id);
|
||||||
|
checkUnique(this, key);
|
||||||
|
this._schemas[key] = this._addSchema(schema, _skipValidation, _meta, true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add schema that will be used to validate other schemas
|
||||||
|
* options in META_IGNORE_OPTIONS are alway set to false
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema object
|
||||||
|
* @param {String} key optional schema key
|
||||||
|
* @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
function addMetaSchema(schema, key, skipValidation) {
|
||||||
|
this.addSchema(schema, key, skipValidation, true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate schema
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema to validate
|
||||||
|
* @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
|
||||||
|
* @return {Boolean} true if schema is valid
|
||||||
|
*/
|
||||||
|
function validateSchema(schema, throwOrLogError) {
|
||||||
|
var $schema = schema.$schema;
|
||||||
|
if ($schema !== undefined && typeof $schema != 'string')
|
||||||
|
throw new Error('$schema must be a string');
|
||||||
|
$schema = $schema || this._opts.defaultMeta || defaultMeta(this);
|
||||||
|
if (!$schema) {
|
||||||
|
this.logger.warn('meta-schema not available');
|
||||||
|
this.errors = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
var valid = this.validate($schema, schema);
|
||||||
|
if (!valid && throwOrLogError) {
|
||||||
|
var message = 'schema is invalid: ' + this.errorsText();
|
||||||
|
if (this._opts.validateSchema == 'log') this.logger.error(message);
|
||||||
|
else throw new Error(message);
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function defaultMeta(self) {
|
||||||
|
var meta = self._opts.meta;
|
||||||
|
self._opts.defaultMeta = typeof meta == 'object'
|
||||||
|
? self._getId(meta) || meta
|
||||||
|
: self.getSchema(META_SCHEMA_ID)
|
||||||
|
? META_SCHEMA_ID
|
||||||
|
: undefined;
|
||||||
|
return self._opts.defaultMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get compiled schema from the instance by `key` or `ref`.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
|
||||||
|
* @return {Function} schema validating function (with property `schema`).
|
||||||
|
*/
|
||||||
|
function getSchema(keyRef) {
|
||||||
|
var schemaObj = _getSchemaObj(this, keyRef);
|
||||||
|
switch (typeof schemaObj) {
|
||||||
|
case 'object': return schemaObj.validate || this._compile(schemaObj);
|
||||||
|
case 'string': return this.getSchema(schemaObj);
|
||||||
|
case 'undefined': return _getSchemaFragment(this, keyRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _getSchemaFragment(self, ref) {
|
||||||
|
var res = resolve.schema.call(self, { schema: {} }, ref);
|
||||||
|
if (res) {
|
||||||
|
var schema = res.schema
|
||||||
|
, root = res.root
|
||||||
|
, baseId = res.baseId;
|
||||||
|
var v = compileSchema.call(self, schema, root, undefined, baseId);
|
||||||
|
self._fragments[ref] = new SchemaObject({
|
||||||
|
ref: ref,
|
||||||
|
fragment: true,
|
||||||
|
schema: schema,
|
||||||
|
root: root,
|
||||||
|
baseId: baseId,
|
||||||
|
validate: v
|
||||||
|
});
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _getSchemaObj(self, keyRef) {
|
||||||
|
keyRef = resolve.normalizeId(keyRef);
|
||||||
|
return self._schemas[keyRef] || self._refs[keyRef] || self._fragments[keyRef];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove cached schema(s).
|
||||||
|
* If no parameter is passed all schemas but meta-schemas are removed.
|
||||||
|
* If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
|
||||||
|
* Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
function removeSchema(schemaKeyRef) {
|
||||||
|
if (schemaKeyRef instanceof RegExp) {
|
||||||
|
_removeAllSchemas(this, this._schemas, schemaKeyRef);
|
||||||
|
_removeAllSchemas(this, this._refs, schemaKeyRef);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
switch (typeof schemaKeyRef) {
|
||||||
|
case 'undefined':
|
||||||
|
_removeAllSchemas(this, this._schemas);
|
||||||
|
_removeAllSchemas(this, this._refs);
|
||||||
|
this._cache.clear();
|
||||||
|
return this;
|
||||||
|
case 'string':
|
||||||
|
var schemaObj = _getSchemaObj(this, schemaKeyRef);
|
||||||
|
if (schemaObj) this._cache.del(schemaObj.cacheKey);
|
||||||
|
delete this._schemas[schemaKeyRef];
|
||||||
|
delete this._refs[schemaKeyRef];
|
||||||
|
return this;
|
||||||
|
case 'object':
|
||||||
|
var serialize = this._opts.serialize;
|
||||||
|
var cacheKey = serialize ? serialize(schemaKeyRef) : schemaKeyRef;
|
||||||
|
this._cache.del(cacheKey);
|
||||||
|
var id = this._getId(schemaKeyRef);
|
||||||
|
if (id) {
|
||||||
|
id = resolve.normalizeId(id);
|
||||||
|
delete this._schemas[id];
|
||||||
|
delete this._refs[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _removeAllSchemas(self, schemas, regex) {
|
||||||
|
for (var keyRef in schemas) {
|
||||||
|
var schemaObj = schemas[keyRef];
|
||||||
|
if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
|
||||||
|
self._cache.del(schemaObj.cacheKey);
|
||||||
|
delete schemas[keyRef];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* @this Ajv */
|
||||||
|
function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
|
||||||
|
if (typeof schema != 'object' && typeof schema != 'boolean')
|
||||||
|
throw new Error('schema should be object or boolean');
|
||||||
|
var serialize = this._opts.serialize;
|
||||||
|
var cacheKey = serialize ? serialize(schema) : schema;
|
||||||
|
var cached = this._cache.get(cacheKey);
|
||||||
|
if (cached) return cached;
|
||||||
|
|
||||||
|
shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
|
||||||
|
|
||||||
|
var id = resolve.normalizeId(this._getId(schema));
|
||||||
|
if (id && shouldAddSchema) checkUnique(this, id);
|
||||||
|
|
||||||
|
var willValidate = this._opts.validateSchema !== false && !skipValidation;
|
||||||
|
var recursiveMeta;
|
||||||
|
if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
|
||||||
|
this.validateSchema(schema, true);
|
||||||
|
|
||||||
|
var localRefs = resolve.ids.call(this, schema);
|
||||||
|
|
||||||
|
var schemaObj = new SchemaObject({
|
||||||
|
id: id,
|
||||||
|
schema: schema,
|
||||||
|
localRefs: localRefs,
|
||||||
|
cacheKey: cacheKey,
|
||||||
|
meta: meta
|
||||||
|
});
|
||||||
|
|
||||||
|
if (id[0] != '#' && shouldAddSchema) this._refs[id] = schemaObj;
|
||||||
|
this._cache.put(cacheKey, schemaObj);
|
||||||
|
|
||||||
|
if (willValidate && recursiveMeta) this.validateSchema(schema, true);
|
||||||
|
|
||||||
|
return schemaObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* @this Ajv */
|
||||||
|
function _compile(schemaObj, root) {
|
||||||
|
if (schemaObj.compiling) {
|
||||||
|
schemaObj.validate = callValidate;
|
||||||
|
callValidate.schema = schemaObj.schema;
|
||||||
|
callValidate.errors = null;
|
||||||
|
callValidate.root = root ? root : callValidate;
|
||||||
|
if (schemaObj.schema.$async === true)
|
||||||
|
callValidate.$async = true;
|
||||||
|
return callValidate;
|
||||||
|
}
|
||||||
|
schemaObj.compiling = true;
|
||||||
|
|
||||||
|
var currentOpts;
|
||||||
|
if (schemaObj.meta) {
|
||||||
|
currentOpts = this._opts;
|
||||||
|
this._opts = this._metaOpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
var v;
|
||||||
|
try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
|
||||||
|
catch(e) {
|
||||||
|
delete schemaObj.validate;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
schemaObj.compiling = false;
|
||||||
|
if (schemaObj.meta) this._opts = currentOpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
schemaObj.validate = v;
|
||||||
|
schemaObj.refs = v.refs;
|
||||||
|
schemaObj.refVal = v.refVal;
|
||||||
|
schemaObj.root = v.root;
|
||||||
|
return v;
|
||||||
|
|
||||||
|
|
||||||
|
/* @this {*} - custom context, see passContext option */
|
||||||
|
function callValidate() {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var _validate = schemaObj.validate;
|
||||||
|
var result = _validate.apply(this, arguments);
|
||||||
|
callValidate.errors = _validate.errors;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function chooseGetId(opts) {
|
||||||
|
switch (opts.schemaId) {
|
||||||
|
case 'auto': return _get$IdOrId;
|
||||||
|
case 'id': return _getId;
|
||||||
|
default: return _get$Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @this Ajv */
|
||||||
|
function _getId(schema) {
|
||||||
|
if (schema.$id) this.logger.warn('schema $id ignored', schema.$id);
|
||||||
|
return schema.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @this Ajv */
|
||||||
|
function _get$Id(schema) {
|
||||||
|
if (schema.id) this.logger.warn('schema id ignored', schema.id);
|
||||||
|
return schema.$id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _get$IdOrId(schema) {
|
||||||
|
if (schema.$id && schema.id && schema.$id != schema.id)
|
||||||
|
throw new Error('schema $id is different from id');
|
||||||
|
return schema.$id || schema.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert array of error message objects to string
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
|
||||||
|
* @param {Object} options optional options with properties `separator` and `dataVar`.
|
||||||
|
* @return {String} human readable string with all errors descriptions
|
||||||
|
*/
|
||||||
|
function errorsText(errors, options) {
|
||||||
|
errors = errors || this.errors;
|
||||||
|
if (!errors) return 'No errors';
|
||||||
|
options = options || {};
|
||||||
|
var separator = options.separator === undefined ? ', ' : options.separator;
|
||||||
|
var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
|
||||||
|
|
||||||
|
var text = '';
|
||||||
|
for (var i=0; i<errors.length; i++) {
|
||||||
|
var e = errors[i];
|
||||||
|
if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
|
||||||
|
}
|
||||||
|
return text.slice(0, -separator.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add custom format
|
||||||
|
* @this Ajv
|
||||||
|
* @param {String} name format name
|
||||||
|
* @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
|
||||||
|
* @return {Ajv} this for method chaining
|
||||||
|
*/
|
||||||
|
function addFormat(name, format) {
|
||||||
|
if (typeof format == 'string') format = new RegExp(format);
|
||||||
|
this._formats[name] = format;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addDefaultMetaSchema(self) {
|
||||||
|
var $dataSchema;
|
||||||
|
if (self._opts.$data) {
|
||||||
|
$dataSchema = require('./refs/data.json');
|
||||||
|
self.addMetaSchema($dataSchema, $dataSchema.$id, true);
|
||||||
|
}
|
||||||
|
if (self._opts.meta === false) return;
|
||||||
|
var metaSchema = require('./refs/json-schema-draft-07.json');
|
||||||
|
if (self._opts.$data) metaSchema = $dataMetaSchema(metaSchema, META_SUPPORT_DATA);
|
||||||
|
self.addMetaSchema(metaSchema, META_SCHEMA_ID, true);
|
||||||
|
self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addInitialSchemas(self) {
|
||||||
|
var optsSchemas = self._opts.schemas;
|
||||||
|
if (!optsSchemas) return;
|
||||||
|
if (Array.isArray(optsSchemas)) self.addSchema(optsSchemas);
|
||||||
|
else for (var key in optsSchemas) self.addSchema(optsSchemas[key], key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addInitialFormats(self) {
|
||||||
|
for (var name in self._opts.formats) {
|
||||||
|
var format = self._opts.formats[name];
|
||||||
|
self.addFormat(name, format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addInitialKeywords(self) {
|
||||||
|
for (var name in self._opts.keywords) {
|
||||||
|
var keyword = self._opts.keywords[name];
|
||||||
|
self.addKeyword(name, keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkUnique(self, id) {
|
||||||
|
if (self._schemas[id] || self._refs[id])
|
||||||
|
throw new Error('schema with key or id "' + id + '" already exists');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getMetaSchemaOptions(self) {
|
||||||
|
var metaOpts = util.copy(self._opts);
|
||||||
|
for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
|
||||||
|
delete metaOpts[META_IGNORE_OPTIONS[i]];
|
||||||
|
return metaOpts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setLogger(self) {
|
||||||
|
var logger = self._opts.logger;
|
||||||
|
if (logger === false) {
|
||||||
|
self.logger = {log: noop, warn: noop, error: noop};
|
||||||
|
} else {
|
||||||
|
if (logger === undefined) logger = console;
|
||||||
|
if (!(typeof logger == 'object' && logger.log && logger.warn && logger.error))
|
||||||
|
throw new Error('logger must implement log, warn and error methods');
|
||||||
|
self.logger = logger;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
26
node_sid/node_modules/ajv/lib/cache.js
generated
vendored
Normal file
26
node_sid/node_modules/ajv/lib/cache.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
var Cache = module.exports = function Cache() {
|
||||||
|
this._cache = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Cache.prototype.put = function Cache_put(key, value) {
|
||||||
|
this._cache[key] = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Cache.prototype.get = function Cache_get(key) {
|
||||||
|
return this._cache[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Cache.prototype.del = function Cache_del(key) {
|
||||||
|
delete this._cache[key];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Cache.prototype.clear = function Cache_clear() {
|
||||||
|
this._cache = {};
|
||||||
|
};
|
||||||
90
node_sid/node_modules/ajv/lib/compile/async.js
generated
vendored
Normal file
90
node_sid/node_modules/ajv/lib/compile/async.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var MissingRefError = require('./error_classes').MissingRef;
|
||||||
|
|
||||||
|
module.exports = compileAsync;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates validating function for passed schema with asynchronous loading of missing schemas.
|
||||||
|
* `loadSchema` option should be a function that accepts schema uri and returns promise that resolves with the schema.
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema object
|
||||||
|
* @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
|
||||||
|
* @param {Function} callback an optional node-style callback, it is called with 2 parameters: error (or null) and validating function.
|
||||||
|
* @return {Promise} promise that resolves with a validating function.
|
||||||
|
*/
|
||||||
|
function compileAsync(schema, meta, callback) {
|
||||||
|
/* eslint no-shadow: 0 */
|
||||||
|
/* global Promise */
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var self = this;
|
||||||
|
if (typeof this._opts.loadSchema != 'function')
|
||||||
|
throw new Error('options.loadSchema should be a function');
|
||||||
|
|
||||||
|
if (typeof meta == 'function') {
|
||||||
|
callback = meta;
|
||||||
|
meta = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
var p = loadMetaSchemaOf(schema).then(function () {
|
||||||
|
var schemaObj = self._addSchema(schema, undefined, meta);
|
||||||
|
return schemaObj.validate || _compileAsync(schemaObj);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
p.then(
|
||||||
|
function(v) { callback(null, v); },
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
|
||||||
|
|
||||||
|
function loadMetaSchemaOf(sch) {
|
||||||
|
var $schema = sch.$schema;
|
||||||
|
return $schema && !self.getSchema($schema)
|
||||||
|
? compileAsync.call(self, { $ref: $schema }, true)
|
||||||
|
: Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _compileAsync(schemaObj) {
|
||||||
|
try { return self._compile(schemaObj); }
|
||||||
|
catch(e) {
|
||||||
|
if (e instanceof MissingRefError) return loadMissingSchema(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadMissingSchema(e) {
|
||||||
|
var ref = e.missingSchema;
|
||||||
|
if (added(ref)) throw new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved');
|
||||||
|
|
||||||
|
var schemaPromise = self._loadingSchemas[ref];
|
||||||
|
if (!schemaPromise) {
|
||||||
|
schemaPromise = self._loadingSchemas[ref] = self._opts.loadSchema(ref);
|
||||||
|
schemaPromise.then(removePromise, removePromise);
|
||||||
|
}
|
||||||
|
|
||||||
|
return schemaPromise.then(function (sch) {
|
||||||
|
if (!added(ref)) {
|
||||||
|
return loadMetaSchemaOf(sch).then(function () {
|
||||||
|
if (!added(ref)) self.addSchema(sch, ref, undefined, meta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).then(function() {
|
||||||
|
return _compileAsync(schemaObj);
|
||||||
|
});
|
||||||
|
|
||||||
|
function removePromise() {
|
||||||
|
delete self._loadingSchemas[ref];
|
||||||
|
}
|
||||||
|
|
||||||
|
function added(ref) {
|
||||||
|
return self._refs[ref] || self._schemas[ref];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
node_sid/node_modules/ajv/lib/compile/equal.js
generated
vendored
Normal file
5
node_sid/node_modules/ajv/lib/compile/equal.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// do NOT remove this file - it would break pre-compiled schemas
|
||||||
|
// https://github.com/ajv-validator/ajv/issues/889
|
||||||
|
module.exports = require('fast-deep-equal');
|
||||||
34
node_sid/node_modules/ajv/lib/compile/error_classes.js
generated
vendored
Normal file
34
node_sid/node_modules/ajv/lib/compile/error_classes.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var resolve = require('./resolve');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Validation: errorSubclass(ValidationError),
|
||||||
|
MissingRef: errorSubclass(MissingRefError)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function ValidationError(errors) {
|
||||||
|
this.message = 'validation failed';
|
||||||
|
this.errors = errors;
|
||||||
|
this.ajv = this.validation = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MissingRefError.message = function (baseId, ref) {
|
||||||
|
return 'can\'t resolve reference ' + ref + ' from id ' + baseId;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function MissingRefError(baseId, ref, message) {
|
||||||
|
this.message = message || MissingRefError.message(baseId, ref);
|
||||||
|
this.missingRef = resolve.url(baseId, ref);
|
||||||
|
this.missingSchema = resolve.normalizeId(resolve.fullPath(this.missingRef));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function errorSubclass(Subclass) {
|
||||||
|
Subclass.prototype = Object.create(Error.prototype);
|
||||||
|
Subclass.prototype.constructor = Subclass;
|
||||||
|
return Subclass;
|
||||||
|
}
|
||||||
142
node_sid/node_modules/ajv/lib/compile/formats.js
generated
vendored
Normal file
142
node_sid/node_modules/ajv/lib/compile/formats.js
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var util = require('./util');
|
||||||
|
|
||||||
|
var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
||||||
|
var DAYS = [0,31,28,31,30,31,30,31,31,30,31,30,31];
|
||||||
|
var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
|
||||||
|
var HOSTNAME = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
|
||||||
|
var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
||||||
|
var URIREF = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
||||||
|
// uri-template: https://tools.ietf.org/html/rfc6570
|
||||||
|
var URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
|
||||||
|
// For the source: https://gist.github.com/dperini/729294
|
||||||
|
// For test cases: https://mathiasbynens.be/demo/url-regex
|
||||||
|
// @todo Delete current URL in favour of the commented out URL rule when this issue is fixed https://github.com/eslint/eslint/issues/7983.
|
||||||
|
// var URL = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
|
||||||
|
var URL = /^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i;
|
||||||
|
var UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
||||||
|
var JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
||||||
|
var JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
||||||
|
var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = formats;
|
||||||
|
|
||||||
|
function formats(mode) {
|
||||||
|
mode = mode == 'full' ? 'full' : 'fast';
|
||||||
|
return util.copy(formats[mode]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
formats.fast = {
|
||||||
|
// date: http://tools.ietf.org/html/rfc3339#section-5.6
|
||||||
|
date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
|
||||||
|
// date-time: http://tools.ietf.org/html/rfc3339#section-5.6
|
||||||
|
time: /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,
|
||||||
|
'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,
|
||||||
|
// uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
|
||||||
|
uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
|
||||||
|
'uri-reference': /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
|
||||||
|
'uri-template': URITEMPLATE,
|
||||||
|
url: URL,
|
||||||
|
// email (sources from jsen validator):
|
||||||
|
// http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
|
||||||
|
// http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
|
||||||
|
email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
|
||||||
|
hostname: HOSTNAME,
|
||||||
|
// optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
|
||||||
|
ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
|
||||||
|
// optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
|
||||||
|
ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
|
||||||
|
regex: regex,
|
||||||
|
// uuid: http://tools.ietf.org/html/rfc4122
|
||||||
|
uuid: UUID,
|
||||||
|
// JSON-pointer: https://tools.ietf.org/html/rfc6901
|
||||||
|
// uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
|
||||||
|
'json-pointer': JSON_POINTER,
|
||||||
|
'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
|
||||||
|
// relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
|
||||||
|
'relative-json-pointer': RELATIVE_JSON_POINTER
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
formats.full = {
|
||||||
|
date: date,
|
||||||
|
time: time,
|
||||||
|
'date-time': date_time,
|
||||||
|
uri: uri,
|
||||||
|
'uri-reference': URIREF,
|
||||||
|
'uri-template': URITEMPLATE,
|
||||||
|
url: URL,
|
||||||
|
email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
|
||||||
|
hostname: HOSTNAME,
|
||||||
|
ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
|
||||||
|
ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
|
||||||
|
regex: regex,
|
||||||
|
uuid: UUID,
|
||||||
|
'json-pointer': JSON_POINTER,
|
||||||
|
'json-pointer-uri-fragment': JSON_POINTER_URI_FRAGMENT,
|
||||||
|
'relative-json-pointer': RELATIVE_JSON_POINTER
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function isLeapYear(year) {
|
||||||
|
// https://tools.ietf.org/html/rfc3339#appendix-C
|
||||||
|
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function date(str) {
|
||||||
|
// full-date from http://tools.ietf.org/html/rfc3339#section-5.6
|
||||||
|
var matches = str.match(DATE);
|
||||||
|
if (!matches) return false;
|
||||||
|
|
||||||
|
var year = +matches[1];
|
||||||
|
var month = +matches[2];
|
||||||
|
var day = +matches[3];
|
||||||
|
|
||||||
|
return month >= 1 && month <= 12 && day >= 1 &&
|
||||||
|
day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function time(str, full) {
|
||||||
|
var matches = str.match(TIME);
|
||||||
|
if (!matches) return false;
|
||||||
|
|
||||||
|
var hour = matches[1];
|
||||||
|
var minute = matches[2];
|
||||||
|
var second = matches[3];
|
||||||
|
var timeZone = matches[5];
|
||||||
|
return ((hour <= 23 && minute <= 59 && second <= 59) ||
|
||||||
|
(hour == 23 && minute == 59 && second == 60)) &&
|
||||||
|
(!full || timeZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var DATE_TIME_SEPARATOR = /t|\s/i;
|
||||||
|
function date_time(str) {
|
||||||
|
// http://tools.ietf.org/html/rfc3339#section-5.6
|
||||||
|
var dateTime = str.split(DATE_TIME_SEPARATOR);
|
||||||
|
return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var NOT_URI_FRAGMENT = /\/|:/;
|
||||||
|
function uri(str) {
|
||||||
|
// http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
|
||||||
|
return NOT_URI_FRAGMENT.test(str) && URI.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var Z_ANCHOR = /[^\\]\\Z/;
|
||||||
|
function regex(str) {
|
||||||
|
if (Z_ANCHOR.test(str)) return false;
|
||||||
|
try {
|
||||||
|
new RegExp(str);
|
||||||
|
return true;
|
||||||
|
} catch(e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
387
node_sid/node_modules/ajv/lib/compile/index.js
generated
vendored
Normal file
387
node_sid/node_modules/ajv/lib/compile/index.js
generated
vendored
Normal file
@@ -0,0 +1,387 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var resolve = require('./resolve')
|
||||||
|
, util = require('./util')
|
||||||
|
, errorClasses = require('./error_classes')
|
||||||
|
, stableStringify = require('fast-json-stable-stringify');
|
||||||
|
|
||||||
|
var validateGenerator = require('../dotjs/validate');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Functions below are used inside compiled validations function
|
||||||
|
*/
|
||||||
|
|
||||||
|
var ucs2length = util.ucs2length;
|
||||||
|
var equal = require('fast-deep-equal');
|
||||||
|
|
||||||
|
// this error is thrown by async schemas to return validation errors via exception
|
||||||
|
var ValidationError = errorClasses.Validation;
|
||||||
|
|
||||||
|
module.exports = compile;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles schema to validation function
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema object
|
||||||
|
* @param {Object} root object with information about the root schema for this schema
|
||||||
|
* @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
|
||||||
|
* @param {String} baseId base ID for IDs in the schema
|
||||||
|
* @return {Function} validation function
|
||||||
|
*/
|
||||||
|
function compile(schema, root, localRefs, baseId) {
|
||||||
|
/* jshint validthis: true, evil: true */
|
||||||
|
/* eslint no-shadow: 0 */
|
||||||
|
var self = this
|
||||||
|
, opts = this._opts
|
||||||
|
, refVal = [ undefined ]
|
||||||
|
, refs = {}
|
||||||
|
, patterns = []
|
||||||
|
, patternsHash = {}
|
||||||
|
, defaults = []
|
||||||
|
, defaultsHash = {}
|
||||||
|
, customRules = [];
|
||||||
|
|
||||||
|
root = root || { schema: schema, refVal: refVal, refs: refs };
|
||||||
|
|
||||||
|
var c = checkCompiling.call(this, schema, root, baseId);
|
||||||
|
var compilation = this._compilations[c.index];
|
||||||
|
if (c.compiling) return (compilation.callValidate = callValidate);
|
||||||
|
|
||||||
|
var formats = this._formats;
|
||||||
|
var RULES = this.RULES;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var v = localCompile(schema, root, localRefs, baseId);
|
||||||
|
compilation.validate = v;
|
||||||
|
var cv = compilation.callValidate;
|
||||||
|
if (cv) {
|
||||||
|
cv.schema = v.schema;
|
||||||
|
cv.errors = null;
|
||||||
|
cv.refs = v.refs;
|
||||||
|
cv.refVal = v.refVal;
|
||||||
|
cv.root = v.root;
|
||||||
|
cv.$async = v.$async;
|
||||||
|
if (opts.sourceCode) cv.source = v.source;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
} finally {
|
||||||
|
endCompiling.call(this, schema, root, baseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @this {*} - custom context, see passContext option */
|
||||||
|
function callValidate() {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var validate = compilation.validate;
|
||||||
|
var result = validate.apply(this, arguments);
|
||||||
|
callValidate.errors = validate.errors;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function localCompile(_schema, _root, localRefs, baseId) {
|
||||||
|
var isRoot = !_root || (_root && _root.schema == _schema);
|
||||||
|
if (_root.schema != root.schema)
|
||||||
|
return compile.call(self, _schema, _root, localRefs, baseId);
|
||||||
|
|
||||||
|
var $async = _schema.$async === true;
|
||||||
|
|
||||||
|
var sourceCode = validateGenerator({
|
||||||
|
isTop: true,
|
||||||
|
schema: _schema,
|
||||||
|
isRoot: isRoot,
|
||||||
|
baseId: baseId,
|
||||||
|
root: _root,
|
||||||
|
schemaPath: '',
|
||||||
|
errSchemaPath: '#',
|
||||||
|
errorPath: '""',
|
||||||
|
MissingRefError: errorClasses.MissingRef,
|
||||||
|
RULES: RULES,
|
||||||
|
validate: validateGenerator,
|
||||||
|
util: util,
|
||||||
|
resolve: resolve,
|
||||||
|
resolveRef: resolveRef,
|
||||||
|
usePattern: usePattern,
|
||||||
|
useDefault: useDefault,
|
||||||
|
useCustomRule: useCustomRule,
|
||||||
|
opts: opts,
|
||||||
|
formats: formats,
|
||||||
|
logger: self.logger,
|
||||||
|
self: self
|
||||||
|
});
|
||||||
|
|
||||||
|
sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
|
||||||
|
+ vars(defaults, defaultCode) + vars(customRules, customRuleCode)
|
||||||
|
+ sourceCode;
|
||||||
|
|
||||||
|
if (opts.processCode) sourceCode = opts.processCode(sourceCode, _schema);
|
||||||
|
// console.log('\n\n\n *** \n', JSON.stringify(sourceCode));
|
||||||
|
var validate;
|
||||||
|
try {
|
||||||
|
var makeValidate = new Function(
|
||||||
|
'self',
|
||||||
|
'RULES',
|
||||||
|
'formats',
|
||||||
|
'root',
|
||||||
|
'refVal',
|
||||||
|
'defaults',
|
||||||
|
'customRules',
|
||||||
|
'equal',
|
||||||
|
'ucs2length',
|
||||||
|
'ValidationError',
|
||||||
|
sourceCode
|
||||||
|
);
|
||||||
|
|
||||||
|
validate = makeValidate(
|
||||||
|
self,
|
||||||
|
RULES,
|
||||||
|
formats,
|
||||||
|
root,
|
||||||
|
refVal,
|
||||||
|
defaults,
|
||||||
|
customRules,
|
||||||
|
equal,
|
||||||
|
ucs2length,
|
||||||
|
ValidationError
|
||||||
|
);
|
||||||
|
|
||||||
|
refVal[0] = validate;
|
||||||
|
} catch(e) {
|
||||||
|
self.logger.error('Error compiling schema, function code:', sourceCode);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
validate.schema = _schema;
|
||||||
|
validate.errors = null;
|
||||||
|
validate.refs = refs;
|
||||||
|
validate.refVal = refVal;
|
||||||
|
validate.root = isRoot ? validate : _root;
|
||||||
|
if ($async) validate.$async = true;
|
||||||
|
if (opts.sourceCode === true) {
|
||||||
|
validate.source = {
|
||||||
|
code: sourceCode,
|
||||||
|
patterns: patterns,
|
||||||
|
defaults: defaults
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return validate;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveRef(baseId, ref, isRoot) {
|
||||||
|
ref = resolve.url(baseId, ref);
|
||||||
|
var refIndex = refs[ref];
|
||||||
|
var _refVal, refCode;
|
||||||
|
if (refIndex !== undefined) {
|
||||||
|
_refVal = refVal[refIndex];
|
||||||
|
refCode = 'refVal[' + refIndex + ']';
|
||||||
|
return resolvedRef(_refVal, refCode);
|
||||||
|
}
|
||||||
|
if (!isRoot && root.refs) {
|
||||||
|
var rootRefId = root.refs[ref];
|
||||||
|
if (rootRefId !== undefined) {
|
||||||
|
_refVal = root.refVal[rootRefId];
|
||||||
|
refCode = addLocalRef(ref, _refVal);
|
||||||
|
return resolvedRef(_refVal, refCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refCode = addLocalRef(ref);
|
||||||
|
var v = resolve.call(self, localCompile, root, ref);
|
||||||
|
if (v === undefined) {
|
||||||
|
var localSchema = localRefs && localRefs[ref];
|
||||||
|
if (localSchema) {
|
||||||
|
v = resolve.inlineRef(localSchema, opts.inlineRefs)
|
||||||
|
? localSchema
|
||||||
|
: compile.call(self, localSchema, root, localRefs, baseId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v === undefined) {
|
||||||
|
removeLocalRef(ref);
|
||||||
|
} else {
|
||||||
|
replaceLocalRef(ref, v);
|
||||||
|
return resolvedRef(v, refCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addLocalRef(ref, v) {
|
||||||
|
var refId = refVal.length;
|
||||||
|
refVal[refId] = v;
|
||||||
|
refs[ref] = refId;
|
||||||
|
return 'refVal' + refId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeLocalRef(ref) {
|
||||||
|
delete refs[ref];
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceLocalRef(ref, v) {
|
||||||
|
var refId = refs[ref];
|
||||||
|
refVal[refId] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolvedRef(refVal, code) {
|
||||||
|
return typeof refVal == 'object' || typeof refVal == 'boolean'
|
||||||
|
? { code: code, schema: refVal, inline: true }
|
||||||
|
: { code: code, $async: refVal && !!refVal.$async };
|
||||||
|
}
|
||||||
|
|
||||||
|
function usePattern(regexStr) {
|
||||||
|
var index = patternsHash[regexStr];
|
||||||
|
if (index === undefined) {
|
||||||
|
index = patternsHash[regexStr] = patterns.length;
|
||||||
|
patterns[index] = regexStr;
|
||||||
|
}
|
||||||
|
return 'pattern' + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
function useDefault(value) {
|
||||||
|
switch (typeof value) {
|
||||||
|
case 'boolean':
|
||||||
|
case 'number':
|
||||||
|
return '' + value;
|
||||||
|
case 'string':
|
||||||
|
return util.toQuotedString(value);
|
||||||
|
case 'object':
|
||||||
|
if (value === null) return 'null';
|
||||||
|
var valueStr = stableStringify(value);
|
||||||
|
var index = defaultsHash[valueStr];
|
||||||
|
if (index === undefined) {
|
||||||
|
index = defaultsHash[valueStr] = defaults.length;
|
||||||
|
defaults[index] = value;
|
||||||
|
}
|
||||||
|
return 'default' + index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function useCustomRule(rule, schema, parentSchema, it) {
|
||||||
|
if (self._opts.validateSchema !== false) {
|
||||||
|
var deps = rule.definition.dependencies;
|
||||||
|
if (deps && !deps.every(function(keyword) {
|
||||||
|
return Object.prototype.hasOwnProperty.call(parentSchema, keyword);
|
||||||
|
}))
|
||||||
|
throw new Error('parent schema must have all required keywords: ' + deps.join(','));
|
||||||
|
|
||||||
|
var validateSchema = rule.definition.validateSchema;
|
||||||
|
if (validateSchema) {
|
||||||
|
var valid = validateSchema(schema);
|
||||||
|
if (!valid) {
|
||||||
|
var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
|
||||||
|
if (self._opts.validateSchema == 'log') self.logger.error(message);
|
||||||
|
else throw new Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var compile = rule.definition.compile
|
||||||
|
, inline = rule.definition.inline
|
||||||
|
, macro = rule.definition.macro;
|
||||||
|
|
||||||
|
var validate;
|
||||||
|
if (compile) {
|
||||||
|
validate = compile.call(self, schema, parentSchema, it);
|
||||||
|
} else if (macro) {
|
||||||
|
validate = macro.call(self, schema, parentSchema, it);
|
||||||
|
if (opts.validateSchema !== false) self.validateSchema(validate, true);
|
||||||
|
} else if (inline) {
|
||||||
|
validate = inline.call(self, it, rule.keyword, schema, parentSchema);
|
||||||
|
} else {
|
||||||
|
validate = rule.definition.validate;
|
||||||
|
if (!validate) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validate === undefined)
|
||||||
|
throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
|
||||||
|
|
||||||
|
var index = customRules.length;
|
||||||
|
customRules[index] = validate;
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: 'customRule' + index,
|
||||||
|
validate: validate
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the schema is currently compiled
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema to compile
|
||||||
|
* @param {Object} root root object
|
||||||
|
* @param {String} baseId base schema ID
|
||||||
|
* @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
|
||||||
|
*/
|
||||||
|
function checkCompiling(schema, root, baseId) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var index = compIndex.call(this, schema, root, baseId);
|
||||||
|
if (index >= 0) return { index: index, compiling: true };
|
||||||
|
index = this._compilations.length;
|
||||||
|
this._compilations[index] = {
|
||||||
|
schema: schema,
|
||||||
|
root: root,
|
||||||
|
baseId: baseId
|
||||||
|
};
|
||||||
|
return { index: index, compiling: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the schema from the currently compiled list
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema to compile
|
||||||
|
* @param {Object} root root object
|
||||||
|
* @param {String} baseId base schema ID
|
||||||
|
*/
|
||||||
|
function endCompiling(schema, root, baseId) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var i = compIndex.call(this, schema, root, baseId);
|
||||||
|
if (i >= 0) this._compilations.splice(i, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index of schema compilation in the currently compiled list
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} schema schema to compile
|
||||||
|
* @param {Object} root root object
|
||||||
|
* @param {String} baseId base schema ID
|
||||||
|
* @return {Integer} compilation index
|
||||||
|
*/
|
||||||
|
function compIndex(schema, root, baseId) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
for (var i=0; i<this._compilations.length; i++) {
|
||||||
|
var c = this._compilations[i];
|
||||||
|
if (c.schema == schema && c.root == root && c.baseId == baseId) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function patternCode(i, patterns) {
|
||||||
|
return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function defaultCode(i) {
|
||||||
|
return 'var default' + i + ' = defaults[' + i + '];';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function refValCode(i, refVal) {
|
||||||
|
return refVal[i] === undefined ? '' : 'var refVal' + i + ' = refVal[' + i + '];';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function customRuleCode(i) {
|
||||||
|
return 'var customRule' + i + ' = customRules[' + i + '];';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function vars(arr, statement) {
|
||||||
|
if (!arr.length) return '';
|
||||||
|
var code = '';
|
||||||
|
for (var i=0; i<arr.length; i++)
|
||||||
|
code += statement(i, arr);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
270
node_sid/node_modules/ajv/lib/compile/resolve.js
generated
vendored
Normal file
270
node_sid/node_modules/ajv/lib/compile/resolve.js
generated
vendored
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var URI = require('uri-js')
|
||||||
|
, equal = require('fast-deep-equal')
|
||||||
|
, util = require('./util')
|
||||||
|
, SchemaObject = require('./schema_obj')
|
||||||
|
, traverse = require('json-schema-traverse');
|
||||||
|
|
||||||
|
module.exports = resolve;
|
||||||
|
|
||||||
|
resolve.normalizeId = normalizeId;
|
||||||
|
resolve.fullPath = getFullPath;
|
||||||
|
resolve.url = resolveUrl;
|
||||||
|
resolve.ids = resolveIds;
|
||||||
|
resolve.inlineRef = inlineRef;
|
||||||
|
resolve.schema = resolveSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [resolve and compile the references ($ref)]
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Function} compile reference to schema compilation funciton (localCompile)
|
||||||
|
* @param {Object} root object with information about the root schema for the current schema
|
||||||
|
* @param {String} ref reference to resolve
|
||||||
|
* @return {Object|Function} schema object (if the schema can be inlined) or validation function
|
||||||
|
*/
|
||||||
|
function resolve(compile, root, ref) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var refVal = this._refs[ref];
|
||||||
|
if (typeof refVal == 'string') {
|
||||||
|
if (this._refs[refVal]) refVal = this._refs[refVal];
|
||||||
|
else return resolve.call(this, compile, root, refVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
refVal = refVal || this._schemas[ref];
|
||||||
|
if (refVal instanceof SchemaObject) {
|
||||||
|
return inlineRef(refVal.schema, this._opts.inlineRefs)
|
||||||
|
? refVal.schema
|
||||||
|
: refVal.validate || this._compile(refVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = resolveSchema.call(this, root, ref);
|
||||||
|
var schema, v, baseId;
|
||||||
|
if (res) {
|
||||||
|
schema = res.schema;
|
||||||
|
root = res.root;
|
||||||
|
baseId = res.baseId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema instanceof SchemaObject) {
|
||||||
|
v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
|
||||||
|
} else if (schema !== undefined) {
|
||||||
|
v = inlineRef(schema, this._opts.inlineRefs)
|
||||||
|
? schema
|
||||||
|
: compile.call(this, schema, root, undefined, baseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve schema, its root and baseId
|
||||||
|
* @this Ajv
|
||||||
|
* @param {Object} root root object with properties schema, refVal, refs
|
||||||
|
* @param {String} ref reference to resolve
|
||||||
|
* @return {Object} object with properties schema, root, baseId
|
||||||
|
*/
|
||||||
|
function resolveSchema(root, ref) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var p = URI.parse(ref)
|
||||||
|
, refPath = _getFullPath(p)
|
||||||
|
, baseId = getFullPath(this._getId(root.schema));
|
||||||
|
if (Object.keys(root.schema).length === 0 || refPath !== baseId) {
|
||||||
|
var id = normalizeId(refPath);
|
||||||
|
var refVal = this._refs[id];
|
||||||
|
if (typeof refVal == 'string') {
|
||||||
|
return resolveRecursive.call(this, root, refVal, p);
|
||||||
|
} else if (refVal instanceof SchemaObject) {
|
||||||
|
if (!refVal.validate) this._compile(refVal);
|
||||||
|
root = refVal;
|
||||||
|
} else {
|
||||||
|
refVal = this._schemas[id];
|
||||||
|
if (refVal instanceof SchemaObject) {
|
||||||
|
if (!refVal.validate) this._compile(refVal);
|
||||||
|
if (id == normalizeId(ref))
|
||||||
|
return { schema: refVal, root: root, baseId: baseId };
|
||||||
|
root = refVal;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!root.schema) return;
|
||||||
|
baseId = getFullPath(this._getId(root.schema));
|
||||||
|
}
|
||||||
|
return getJsonPointer.call(this, p, baseId, root.schema, root);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* @this Ajv */
|
||||||
|
function resolveRecursive(root, ref, parsedRef) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
var res = resolveSchema.call(this, root, ref);
|
||||||
|
if (res) {
|
||||||
|
var schema = res.schema;
|
||||||
|
var baseId = res.baseId;
|
||||||
|
root = res.root;
|
||||||
|
var id = this._getId(schema);
|
||||||
|
if (id) baseId = resolveUrl(baseId, id);
|
||||||
|
return getJsonPointer.call(this, parsedRef, baseId, schema, root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
|
||||||
|
/* @this Ajv */
|
||||||
|
function getJsonPointer(parsedRef, baseId, schema, root) {
|
||||||
|
/* jshint validthis: true */
|
||||||
|
parsedRef.fragment = parsedRef.fragment || '';
|
||||||
|
if (parsedRef.fragment.slice(0,1) != '/') return;
|
||||||
|
var parts = parsedRef.fragment.split('/');
|
||||||
|
|
||||||
|
for (var i = 1; i < parts.length; i++) {
|
||||||
|
var part = parts[i];
|
||||||
|
if (part) {
|
||||||
|
part = util.unescapeFragment(part);
|
||||||
|
schema = schema[part];
|
||||||
|
if (schema === undefined) break;
|
||||||
|
var id;
|
||||||
|
if (!PREVENT_SCOPE_CHANGE[part]) {
|
||||||
|
id = this._getId(schema);
|
||||||
|
if (id) baseId = resolveUrl(baseId, id);
|
||||||
|
if (schema.$ref) {
|
||||||
|
var $ref = resolveUrl(baseId, schema.$ref);
|
||||||
|
var res = resolveSchema.call(this, root, $ref);
|
||||||
|
if (res) {
|
||||||
|
schema = res.schema;
|
||||||
|
root = res.root;
|
||||||
|
baseId = res.baseId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (schema !== undefined && schema !== root.schema)
|
||||||
|
return { schema: schema, root: root, baseId: baseId };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var SIMPLE_INLINED = util.toHash([
|
||||||
|
'type', 'format', 'pattern',
|
||||||
|
'maxLength', 'minLength',
|
||||||
|
'maxProperties', 'minProperties',
|
||||||
|
'maxItems', 'minItems',
|
||||||
|
'maximum', 'minimum',
|
||||||
|
'uniqueItems', 'multipleOf',
|
||||||
|
'required', 'enum'
|
||||||
|
]);
|
||||||
|
function inlineRef(schema, limit) {
|
||||||
|
if (limit === false) return false;
|
||||||
|
if (limit === undefined || limit === true) return checkNoRef(schema);
|
||||||
|
else if (limit) return countKeys(schema) <= limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkNoRef(schema) {
|
||||||
|
var item;
|
||||||
|
if (Array.isArray(schema)) {
|
||||||
|
for (var i=0; i<schema.length; i++) {
|
||||||
|
item = schema[i];
|
||||||
|
if (typeof item == 'object' && !checkNoRef(item)) return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var key in schema) {
|
||||||
|
if (key == '$ref') return false;
|
||||||
|
item = schema[key];
|
||||||
|
if (typeof item == 'object' && !checkNoRef(item)) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function countKeys(schema) {
|
||||||
|
var count = 0, item;
|
||||||
|
if (Array.isArray(schema)) {
|
||||||
|
for (var i=0; i<schema.length; i++) {
|
||||||
|
item = schema[i];
|
||||||
|
if (typeof item == 'object') count += countKeys(item);
|
||||||
|
if (count == Infinity) return Infinity;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var key in schema) {
|
||||||
|
if (key == '$ref') return Infinity;
|
||||||
|
if (SIMPLE_INLINED[key]) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
item = schema[key];
|
||||||
|
if (typeof item == 'object') count += countKeys(item) + 1;
|
||||||
|
if (count == Infinity) return Infinity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getFullPath(id, normalize) {
|
||||||
|
if (normalize !== false) id = normalizeId(id);
|
||||||
|
var p = URI.parse(id);
|
||||||
|
return _getFullPath(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _getFullPath(p) {
|
||||||
|
return URI.serialize(p).split('#')[0] + '#';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var TRAILING_SLASH_HASH = /#\/?$/;
|
||||||
|
function normalizeId(id) {
|
||||||
|
return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function resolveUrl(baseId, id) {
|
||||||
|
id = normalizeId(id);
|
||||||
|
return URI.resolve(baseId, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* @this Ajv */
|
||||||
|
function resolveIds(schema) {
|
||||||
|
var schemaId = normalizeId(this._getId(schema));
|
||||||
|
var baseIds = {'': schemaId};
|
||||||
|
var fullPaths = {'': getFullPath(schemaId, false)};
|
||||||
|
var localRefs = {};
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
|
||||||
|
if (jsonPtr === '') return;
|
||||||
|
var id = self._getId(sch);
|
||||||
|
var baseId = baseIds[parentJsonPtr];
|
||||||
|
var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
|
||||||
|
if (keyIndex !== undefined)
|
||||||
|
fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
|
||||||
|
|
||||||
|
if (typeof id == 'string') {
|
||||||
|
id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id);
|
||||||
|
|
||||||
|
var refVal = self._refs[id];
|
||||||
|
if (typeof refVal == 'string') refVal = self._refs[refVal];
|
||||||
|
if (refVal && refVal.schema) {
|
||||||
|
if (!equal(sch, refVal.schema))
|
||||||
|
throw new Error('id "' + id + '" resolves to more than one schema');
|
||||||
|
} else if (id != normalizeId(fullPath)) {
|
||||||
|
if (id[0] == '#') {
|
||||||
|
if (localRefs[id] && !equal(sch, localRefs[id]))
|
||||||
|
throw new Error('id "' + id + '" resolves to more than one schema');
|
||||||
|
localRefs[id] = sch;
|
||||||
|
} else {
|
||||||
|
self._refs[id] = fullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
baseIds[jsonPtr] = baseId;
|
||||||
|
fullPaths[jsonPtr] = fullPath;
|
||||||
|
});
|
||||||
|
|
||||||
|
return localRefs;
|
||||||
|
}
|
||||||
66
node_sid/node_modules/ajv/lib/compile/rules.js
generated
vendored
Normal file
66
node_sid/node_modules/ajv/lib/compile/rules.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var ruleModules = require('../dotjs')
|
||||||
|
, toHash = require('./util').toHash;
|
||||||
|
|
||||||
|
module.exports = function rules() {
|
||||||
|
var RULES = [
|
||||||
|
{ type: 'number',
|
||||||
|
rules: [ { 'maximum': ['exclusiveMaximum'] },
|
||||||
|
{ 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
|
||||||
|
{ type: 'string',
|
||||||
|
rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
|
||||||
|
{ type: 'array',
|
||||||
|
rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
|
||||||
|
{ type: 'object',
|
||||||
|
rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
|
||||||
|
{ 'properties': ['additionalProperties', 'patternProperties'] } ] },
|
||||||
|
{ rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
|
||||||
|
];
|
||||||
|
|
||||||
|
var ALL = [ 'type', '$comment' ];
|
||||||
|
var KEYWORDS = [
|
||||||
|
'$schema', '$id', 'id', '$data', '$async', 'title',
|
||||||
|
'description', 'default', 'definitions',
|
||||||
|
'examples', 'readOnly', 'writeOnly',
|
||||||
|
'contentMediaType', 'contentEncoding',
|
||||||
|
'additionalItems', 'then', 'else'
|
||||||
|
];
|
||||||
|
var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
|
||||||
|
RULES.all = toHash(ALL);
|
||||||
|
RULES.types = toHash(TYPES);
|
||||||
|
|
||||||
|
RULES.forEach(function (group) {
|
||||||
|
group.rules = group.rules.map(function (keyword) {
|
||||||
|
var implKeywords;
|
||||||
|
if (typeof keyword == 'object') {
|
||||||
|
var key = Object.keys(keyword)[0];
|
||||||
|
implKeywords = keyword[key];
|
||||||
|
keyword = key;
|
||||||
|
implKeywords.forEach(function (k) {
|
||||||
|
ALL.push(k);
|
||||||
|
RULES.all[k] = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ALL.push(keyword);
|
||||||
|
var rule = RULES.all[keyword] = {
|
||||||
|
keyword: keyword,
|
||||||
|
code: ruleModules[keyword],
|
||||||
|
implements: implKeywords
|
||||||
|
};
|
||||||
|
return rule;
|
||||||
|
});
|
||||||
|
|
||||||
|
RULES.all.$comment = {
|
||||||
|
keyword: '$comment',
|
||||||
|
code: ruleModules.$comment
|
||||||
|
};
|
||||||
|
|
||||||
|
if (group.type) RULES.types[group.type] = group;
|
||||||
|
});
|
||||||
|
|
||||||
|
RULES.keywords = toHash(ALL.concat(KEYWORDS));
|
||||||
|
RULES.custom = {};
|
||||||
|
|
||||||
|
return RULES;
|
||||||
|
};
|
||||||
9
node_sid/node_modules/ajv/lib/compile/schema_obj.js
generated
vendored
Normal file
9
node_sid/node_modules/ajv/lib/compile/schema_obj.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var util = require('./util');
|
||||||
|
|
||||||
|
module.exports = SchemaObject;
|
||||||
|
|
||||||
|
function SchemaObject(obj) {
|
||||||
|
util.copy(obj, this);
|
||||||
|
}
|
||||||
20
node_sid/node_modules/ajv/lib/compile/ucs2length.js
generated
vendored
Normal file
20
node_sid/node_modules/ajv/lib/compile/ucs2length.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// https://mathiasbynens.be/notes/javascript-encoding
|
||||||
|
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
|
||||||
|
module.exports = function ucs2length(str) {
|
||||||
|
var length = 0
|
||||||
|
, len = str.length
|
||||||
|
, pos = 0
|
||||||
|
, value;
|
||||||
|
while (pos < len) {
|
||||||
|
length++;
|
||||||
|
value = str.charCodeAt(pos++);
|
||||||
|
if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
|
||||||
|
// high surrogate, and there is a next character
|
||||||
|
value = str.charCodeAt(pos);
|
||||||
|
if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
};
|
||||||
239
node_sid/node_modules/ajv/lib/compile/util.js
generated
vendored
Normal file
239
node_sid/node_modules/ajv/lib/compile/util.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
copy: copy,
|
||||||
|
checkDataType: checkDataType,
|
||||||
|
checkDataTypes: checkDataTypes,
|
||||||
|
coerceToTypes: coerceToTypes,
|
||||||
|
toHash: toHash,
|
||||||
|
getProperty: getProperty,
|
||||||
|
escapeQuotes: escapeQuotes,
|
||||||
|
equal: require('fast-deep-equal'),
|
||||||
|
ucs2length: require('./ucs2length'),
|
||||||
|
varOccurences: varOccurences,
|
||||||
|
varReplace: varReplace,
|
||||||
|
schemaHasRules: schemaHasRules,
|
||||||
|
schemaHasRulesExcept: schemaHasRulesExcept,
|
||||||
|
schemaUnknownRules: schemaUnknownRules,
|
||||||
|
toQuotedString: toQuotedString,
|
||||||
|
getPathExpr: getPathExpr,
|
||||||
|
getPath: getPath,
|
||||||
|
getData: getData,
|
||||||
|
unescapeFragment: unescapeFragment,
|
||||||
|
unescapeJsonPointer: unescapeJsonPointer,
|
||||||
|
escapeFragment: escapeFragment,
|
||||||
|
escapeJsonPointer: escapeJsonPointer
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function copy(o, to) {
|
||||||
|
to = to || {};
|
||||||
|
for (var key in o) to[key] = o[key];
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkDataType(dataType, data, strictNumbers, negate) {
|
||||||
|
var EQUAL = negate ? ' !== ' : ' === '
|
||||||
|
, AND = negate ? ' || ' : ' && '
|
||||||
|
, OK = negate ? '!' : ''
|
||||||
|
, NOT = negate ? '' : '!';
|
||||||
|
switch (dataType) {
|
||||||
|
case 'null': return data + EQUAL + 'null';
|
||||||
|
case 'array': return OK + 'Array.isArray(' + data + ')';
|
||||||
|
case 'object': return '(' + OK + data + AND +
|
||||||
|
'typeof ' + data + EQUAL + '"object"' + AND +
|
||||||
|
NOT + 'Array.isArray(' + data + '))';
|
||||||
|
case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
|
||||||
|
NOT + '(' + data + ' % 1)' +
|
||||||
|
AND + data + EQUAL + data +
|
||||||
|
(strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
|
||||||
|
case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
|
||||||
|
(strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
|
||||||
|
default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkDataTypes(dataTypes, data, strictNumbers) {
|
||||||
|
switch (dataTypes.length) {
|
||||||
|
case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
|
||||||
|
default:
|
||||||
|
var code = '';
|
||||||
|
var types = toHash(dataTypes);
|
||||||
|
if (types.array && types.object) {
|
||||||
|
code = types.null ? '(': '(!' + data + ' || ';
|
||||||
|
code += 'typeof ' + data + ' !== "object")';
|
||||||
|
delete types.null;
|
||||||
|
delete types.array;
|
||||||
|
delete types.object;
|
||||||
|
}
|
||||||
|
if (types.number) delete types.integer;
|
||||||
|
for (var t in types)
|
||||||
|
code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
|
||||||
|
function coerceToTypes(optionCoerceTypes, dataTypes) {
|
||||||
|
if (Array.isArray(dataTypes)) {
|
||||||
|
var types = [];
|
||||||
|
for (var i=0; i<dataTypes.length; i++) {
|
||||||
|
var t = dataTypes[i];
|
||||||
|
if (COERCE_TO_TYPES[t]) types[types.length] = t;
|
||||||
|
else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
|
||||||
|
}
|
||||||
|
if (types.length) return types;
|
||||||
|
} else if (COERCE_TO_TYPES[dataTypes]) {
|
||||||
|
return [dataTypes];
|
||||||
|
} else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
|
||||||
|
return ['array'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function toHash(arr) {
|
||||||
|
var hash = {};
|
||||||
|
for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
|
||||||
|
var SINGLE_QUOTE = /'|\\/g;
|
||||||
|
function getProperty(key) {
|
||||||
|
return typeof key == 'number'
|
||||||
|
? '[' + key + ']'
|
||||||
|
: IDENTIFIER.test(key)
|
||||||
|
? '.' + key
|
||||||
|
: "['" + escapeQuotes(key) + "']";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function escapeQuotes(str) {
|
||||||
|
return str.replace(SINGLE_QUOTE, '\\$&')
|
||||||
|
.replace(/\n/g, '\\n')
|
||||||
|
.replace(/\r/g, '\\r')
|
||||||
|
.replace(/\f/g, '\\f')
|
||||||
|
.replace(/\t/g, '\\t');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function varOccurences(str, dataVar) {
|
||||||
|
dataVar += '[^0-9]';
|
||||||
|
var matches = str.match(new RegExp(dataVar, 'g'));
|
||||||
|
return matches ? matches.length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function varReplace(str, dataVar, expr) {
|
||||||
|
dataVar += '([^0-9])';
|
||||||
|
expr = expr.replace(/\$/g, '$$$$');
|
||||||
|
return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function schemaHasRules(schema, rules) {
|
||||||
|
if (typeof schema == 'boolean') return !schema;
|
||||||
|
for (var key in schema) if (rules[key]) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function schemaHasRulesExcept(schema, rules, exceptKeyword) {
|
||||||
|
if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
|
||||||
|
for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function schemaUnknownRules(schema, rules) {
|
||||||
|
if (typeof schema == 'boolean') return;
|
||||||
|
for (var key in schema) if (!rules[key]) return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function toQuotedString(str) {
|
||||||
|
return '\'' + escapeQuotes(str) + '\'';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
|
||||||
|
var path = jsonPointers // false by default
|
||||||
|
? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
|
||||||
|
: (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
|
||||||
|
return joinPaths(currentPath, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getPath(currentPath, prop, jsonPointers) {
|
||||||
|
var path = jsonPointers // false by default
|
||||||
|
? toQuotedString('/' + escapeJsonPointer(prop))
|
||||||
|
: toQuotedString(getProperty(prop));
|
||||||
|
return joinPaths(currentPath, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
||||||
|
var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
||||||
|
function getData($data, lvl, paths) {
|
||||||
|
var up, jsonPointer, data, matches;
|
||||||
|
if ($data === '') return 'rootData';
|
||||||
|
if ($data[0] == '/') {
|
||||||
|
if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
|
||||||
|
jsonPointer = $data;
|
||||||
|
data = 'rootData';
|
||||||
|
} else {
|
||||||
|
matches = $data.match(RELATIVE_JSON_POINTER);
|
||||||
|
if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
|
||||||
|
up = +matches[1];
|
||||||
|
jsonPointer = matches[2];
|
||||||
|
if (jsonPointer == '#') {
|
||||||
|
if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
|
||||||
|
return paths[lvl - up];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
|
||||||
|
data = 'data' + ((lvl - up) || '');
|
||||||
|
if (!jsonPointer) return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
var expr = data;
|
||||||
|
var segments = jsonPointer.split('/');
|
||||||
|
for (var i=0; i<segments.length; i++) {
|
||||||
|
var segment = segments[i];
|
||||||
|
if (segment) {
|
||||||
|
data += getProperty(unescapeJsonPointer(segment));
|
||||||
|
expr += ' && ' + data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function joinPaths (a, b) {
|
||||||
|
if (a == '""') return b;
|
||||||
|
return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function unescapeFragment(str) {
|
||||||
|
return unescapeJsonPointer(decodeURIComponent(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function escapeFragment(str) {
|
||||||
|
return encodeURIComponent(escapeJsonPointer(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function escapeJsonPointer(str) {
|
||||||
|
return str.replace(/~/g, '~0').replace(/\//g, '~1');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function unescapeJsonPointer(str) {
|
||||||
|
return str.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||||
|
}
|
||||||
49
node_sid/node_modules/ajv/lib/data.js
generated
vendored
Normal file
49
node_sid/node_modules/ajv/lib/data.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var KEYWORDS = [
|
||||||
|
'multipleOf',
|
||||||
|
'maximum',
|
||||||
|
'exclusiveMaximum',
|
||||||
|
'minimum',
|
||||||
|
'exclusiveMinimum',
|
||||||
|
'maxLength',
|
||||||
|
'minLength',
|
||||||
|
'pattern',
|
||||||
|
'additionalItems',
|
||||||
|
'maxItems',
|
||||||
|
'minItems',
|
||||||
|
'uniqueItems',
|
||||||
|
'maxProperties',
|
||||||
|
'minProperties',
|
||||||
|
'required',
|
||||||
|
'additionalProperties',
|
||||||
|
'enum',
|
||||||
|
'format',
|
||||||
|
'const'
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = function (metaSchema, keywordsJsonPointers) {
|
||||||
|
for (var i=0; i<keywordsJsonPointers.length; i++) {
|
||||||
|
metaSchema = JSON.parse(JSON.stringify(metaSchema));
|
||||||
|
var segments = keywordsJsonPointers[i].split('/');
|
||||||
|
var keywords = metaSchema;
|
||||||
|
var j;
|
||||||
|
for (j=1; j<segments.length; j++)
|
||||||
|
keywords = keywords[segments[j]];
|
||||||
|
|
||||||
|
for (j=0; j<KEYWORDS.length; j++) {
|
||||||
|
var key = KEYWORDS[j];
|
||||||
|
var schema = keywords[key];
|
||||||
|
if (schema) {
|
||||||
|
keywords[key] = {
|
||||||
|
anyOf: [
|
||||||
|
schema,
|
||||||
|
{ $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return metaSchema;
|
||||||
|
};
|
||||||
37
node_sid/node_modules/ajv/lib/definition_schema.js
generated
vendored
Normal file
37
node_sid/node_modules/ajv/lib/definition_schema.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var metaSchema = require('./refs/json-schema-draft-07.json');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
$id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js',
|
||||||
|
definitions: {
|
||||||
|
simpleTypes: metaSchema.definitions.simpleTypes
|
||||||
|
},
|
||||||
|
type: 'object',
|
||||||
|
dependencies: {
|
||||||
|
schema: ['validate'],
|
||||||
|
$data: ['validate'],
|
||||||
|
statements: ['inline'],
|
||||||
|
valid: {not: {required: ['macro']}}
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
type: metaSchema.properties.type,
|
||||||
|
schema: {type: 'boolean'},
|
||||||
|
statements: {type: 'boolean'},
|
||||||
|
dependencies: {
|
||||||
|
type: 'array',
|
||||||
|
items: {type: 'string'}
|
||||||
|
},
|
||||||
|
metaSchema: {type: 'object'},
|
||||||
|
modifying: {type: 'boolean'},
|
||||||
|
valid: {type: 'boolean'},
|
||||||
|
$data: {type: 'boolean'},
|
||||||
|
async: {type: 'boolean'},
|
||||||
|
errors: {
|
||||||
|
anyOf: [
|
||||||
|
{type: 'boolean'},
|
||||||
|
{const: 'full'}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
113
node_sid/node_modules/ajv/lib/dot/_limit.jst
generated
vendored
Normal file
113
node_sid/node_modules/ajv/lib/dot/_limit.jst
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{## def.setExclusiveLimit:
|
||||||
|
$exclusive = true;
|
||||||
|
$errorKeyword = $exclusiveKeyword;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $isMax = $keyword == 'maximum'
|
||||||
|
, $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum'
|
||||||
|
, $schemaExcl = it.schema[$exclusiveKeyword]
|
||||||
|
, $isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data
|
||||||
|
, $op = $isMax ? '<' : '>'
|
||||||
|
, $notOp = $isMax ? '>' : '<'
|
||||||
|
, $errorKeyword = undefined;
|
||||||
|
|
||||||
|
if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
|
||||||
|
throw new Error($keyword + ' must be number');
|
||||||
|
}
|
||||||
|
if (!($isDataExcl || $schemaExcl === undefined
|
||||||
|
|| typeof $schemaExcl == 'number'
|
||||||
|
|| typeof $schemaExcl == 'boolean')) {
|
||||||
|
throw new Error($exclusiveKeyword + ' must be number or boolean');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $isDataExcl }}
|
||||||
|
{{
|
||||||
|
var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr)
|
||||||
|
, $exclusive = 'exclusive' + $lvl
|
||||||
|
, $exclType = 'exclType' + $lvl
|
||||||
|
, $exclIsNumber = 'exclIsNumber' + $lvl
|
||||||
|
, $opExpr = 'op' + $lvl
|
||||||
|
, $opStr = '\' + ' + $opExpr + ' + \'';
|
||||||
|
}}
|
||||||
|
var schemaExcl{{=$lvl}} = {{=$schemaValueExcl}};
|
||||||
|
{{ $schemaValueExcl = 'schemaExcl' + $lvl; }}
|
||||||
|
|
||||||
|
var {{=$exclusive}};
|
||||||
|
var {{=$exclType}} = typeof {{=$schemaValueExcl}};
|
||||||
|
if ({{=$exclType}} != 'boolean' && {{=$exclType}} != 'undefined' && {{=$exclType}} != 'number') {
|
||||||
|
{{ var $errorKeyword = $exclusiveKeyword; }}
|
||||||
|
{{# def.error:'_exclusiveLimit' }}
|
||||||
|
} else if ({{# def.$dataNotType:'number' }}
|
||||||
|
{{=$exclType}} == 'number'
|
||||||
|
? (
|
||||||
|
({{=$exclusive}} = {{=$schemaValue}} === undefined || {{=$schemaValueExcl}} {{=$op}}= {{=$schemaValue}})
|
||||||
|
? {{=$data}} {{=$notOp}}= {{=$schemaValueExcl}}
|
||||||
|
: {{=$data}} {{=$notOp}} {{=$schemaValue}}
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
({{=$exclusive}} = {{=$schemaValueExcl}} === true)
|
||||||
|
? {{=$data}} {{=$notOp}}= {{=$schemaValue}}
|
||||||
|
: {{=$data}} {{=$notOp}} {{=$schemaValue}}
|
||||||
|
)
|
||||||
|
|| {{=$data}} !== {{=$data}}) {
|
||||||
|
var op{{=$lvl}} = {{=$exclusive}} ? '{{=$op}}' : '{{=$op}}=';
|
||||||
|
{{
|
||||||
|
if ($schema === undefined) {
|
||||||
|
$errorKeyword = $exclusiveKeyword;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
||||||
|
$schemaValue = $schemaValueExcl;
|
||||||
|
$isData = $isDataExcl;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{??}}
|
||||||
|
{{
|
||||||
|
var $exclIsNumber = typeof $schemaExcl == 'number'
|
||||||
|
, $opStr = $op; /*used in error*/
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $exclIsNumber && $isData }}
|
||||||
|
{{ var $opExpr = '\'' + $opStr + '\''; /*used in error*/ }}
|
||||||
|
if ({{# def.$dataNotType:'number' }}
|
||||||
|
( {{=$schemaValue}} === undefined
|
||||||
|
|| {{=$schemaExcl}} {{=$op}}= {{=$schemaValue}}
|
||||||
|
? {{=$data}} {{=$notOp}}= {{=$schemaExcl}}
|
||||||
|
: {{=$data}} {{=$notOp}} {{=$schemaValue}} )
|
||||||
|
|| {{=$data}} !== {{=$data}}) {
|
||||||
|
{{??}}
|
||||||
|
{{
|
||||||
|
if ($exclIsNumber && $schema === undefined) {
|
||||||
|
{{# def.setExclusiveLimit }}
|
||||||
|
$schemaValue = $schemaExcl;
|
||||||
|
$notOp += '=';
|
||||||
|
} else {
|
||||||
|
if ($exclIsNumber)
|
||||||
|
$schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
|
||||||
|
|
||||||
|
if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
|
||||||
|
{{# def.setExclusiveLimit }}
|
||||||
|
$notOp += '=';
|
||||||
|
} else {
|
||||||
|
$exclusive = false;
|
||||||
|
$opStr += '=';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var $opExpr = '\'' + $opStr + '\''; /*used in error*/
|
||||||
|
}}
|
||||||
|
|
||||||
|
if ({{# def.$dataNotType:'number' }}
|
||||||
|
{{=$data}} {{=$notOp}} {{=$schemaValue}}
|
||||||
|
|| {{=$data}} !== {{=$data}}) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{ $errorKeyword = $errorKeyword || $keyword; }}
|
||||||
|
{{# def.error:'_limit' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
12
node_sid/node_modules/ajv/lib/dot/_limitItems.jst
generated
vendored
Normal file
12
node_sid/node_modules/ajv/lib/dot/_limitItems.jst
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{# def.numberKeyword }}
|
||||||
|
|
||||||
|
{{ var $op = $keyword == 'maxItems' ? '>' : '<'; }}
|
||||||
|
if ({{# def.$dataNotType:'number' }} {{=$data}}.length {{=$op}} {{=$schemaValue}}) {
|
||||||
|
{{ var $errorKeyword = $keyword; }}
|
||||||
|
{{# def.error:'_limitItems' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
12
node_sid/node_modules/ajv/lib/dot/_limitLength.jst
generated
vendored
Normal file
12
node_sid/node_modules/ajv/lib/dot/_limitLength.jst
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{# def.numberKeyword }}
|
||||||
|
|
||||||
|
{{ var $op = $keyword == 'maxLength' ? '>' : '<'; }}
|
||||||
|
if ({{# def.$dataNotType:'number' }} {{# def.strLength }} {{=$op}} {{=$schemaValue}}) {
|
||||||
|
{{ var $errorKeyword = $keyword; }}
|
||||||
|
{{# def.error:'_limitLength' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
12
node_sid/node_modules/ajv/lib/dot/_limitProperties.jst
generated
vendored
Normal file
12
node_sid/node_modules/ajv/lib/dot/_limitProperties.jst
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{# def.numberKeyword }}
|
||||||
|
|
||||||
|
{{ var $op = $keyword == 'maxProperties' ? '>' : '<'; }}
|
||||||
|
if ({{# def.$dataNotType:'number' }} Object.keys({{=$data}}).length {{=$op}} {{=$schemaValue}}) {
|
||||||
|
{{ var $errorKeyword = $keyword; }}
|
||||||
|
{{# def.error:'_limitProperties' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
32
node_sid/node_modules/ajv/lib/dot/allOf.jst
generated
vendored
Normal file
32
node_sid/node_modules/ajv/lib/dot/allOf.jst
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $currentBaseId = $it.baseId
|
||||||
|
, $allSchemasEmpty = true;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{~ $schema:$sch:$i }}
|
||||||
|
{{? {{# def.nonEmptySchema:$sch }} }}
|
||||||
|
{{
|
||||||
|
$allSchemasEmpty = false;
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + $i;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.insertSubschemaCode }}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{? $allSchemasEmpty }}
|
||||||
|
if (true) {
|
||||||
|
{{??}}
|
||||||
|
{{= $closingBraces.slice(0,-1) }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
46
node_sid/node_modules/ajv/lib/dot/anyOf.jst
generated
vendored
Normal file
46
node_sid/node_modules/ajv/lib/dot/anyOf.jst
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $noEmptySchema = $schema.every(function($sch) {
|
||||||
|
return {{# def.nonEmptySchema:$sch }};
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
{{? $noEmptySchema }}
|
||||||
|
{{ var $currentBaseId = $it.baseId; }}
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
var {{=$valid}} = false;
|
||||||
|
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
|
||||||
|
{{~ $schema:$sch:$i }}
|
||||||
|
{{
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + $i;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.insertSubschemaCode }}
|
||||||
|
|
||||||
|
{{=$valid}} = {{=$valid}} || {{=$nextValid}};
|
||||||
|
|
||||||
|
if (!{{=$valid}}) {
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
{{~}}
|
||||||
|
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
|
||||||
|
{{= $closingBraces }}
|
||||||
|
|
||||||
|
if (!{{=$valid}}) {
|
||||||
|
{{# def.extraError:'anyOf' }}
|
||||||
|
} else {
|
||||||
|
{{# def.resetErrors }}
|
||||||
|
{{? it.opts.allErrors }} } {{?}}
|
||||||
|
{{??}}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if (true) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
51
node_sid/node_modules/ajv/lib/dot/coerce.def
generated
vendored
Normal file
51
node_sid/node_modules/ajv/lib/dot/coerce.def
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{{## def.coerceType:
|
||||||
|
{{
|
||||||
|
var $dataType = 'dataType' + $lvl
|
||||||
|
, $coerced = 'coerced' + $lvl;
|
||||||
|
}}
|
||||||
|
var {{=$dataType}} = typeof {{=$data}};
|
||||||
|
var {{=$coerced}} = undefined;
|
||||||
|
|
||||||
|
{{? it.opts.coerceTypes == 'array' }}
|
||||||
|
if ({{=$dataType}} == 'object' && Array.isArray({{=$data}}) && {{=$data}}.length == 1) {
|
||||||
|
{{=$data}} = {{=$data}}[0];
|
||||||
|
{{=$dataType}} = typeof {{=$data}};
|
||||||
|
if ({{=it.util.checkDataType(it.schema.type, $data, it.opts.strictNumbers)}}) {{=$coerced}} = {{=$data}};
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
if ({{=$coerced}} !== undefined) ;
|
||||||
|
{{~ $coerceToTypes:$type:$i }}
|
||||||
|
{{? $type == 'string' }}
|
||||||
|
else if ({{=$dataType}} == 'number' || {{=$dataType}} == 'boolean')
|
||||||
|
{{=$coerced}} = '' + {{=$data}};
|
||||||
|
else if ({{=$data}} === null) {{=$coerced}} = '';
|
||||||
|
{{?? $type == 'number' || $type == 'integer' }}
|
||||||
|
else if ({{=$dataType}} == 'boolean' || {{=$data}} === null
|
||||||
|
|| ({{=$dataType}} == 'string' && {{=$data}} && {{=$data}} == +{{=$data}}
|
||||||
|
{{? $type == 'integer' }} && !({{=$data}} % 1){{?}}))
|
||||||
|
{{=$coerced}} = +{{=$data}};
|
||||||
|
{{?? $type == 'boolean' }}
|
||||||
|
else if ({{=$data}} === 'false' || {{=$data}} === 0 || {{=$data}} === null)
|
||||||
|
{{=$coerced}} = false;
|
||||||
|
else if ({{=$data}} === 'true' || {{=$data}} === 1)
|
||||||
|
{{=$coerced}} = true;
|
||||||
|
{{?? $type == 'null' }}
|
||||||
|
else if ({{=$data}} === '' || {{=$data}} === 0 || {{=$data}} === false)
|
||||||
|
{{=$coerced}} = null;
|
||||||
|
{{?? it.opts.coerceTypes == 'array' && $type == 'array' }}
|
||||||
|
else if ({{=$dataType}} == 'string' || {{=$dataType}} == 'number' || {{=$dataType}} == 'boolean' || {{=$data}} == null)
|
||||||
|
{{=$coerced}} = [{{=$data}}];
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
else {
|
||||||
|
{{# def.error:'type' }}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ({{=$coerced}} !== undefined) {
|
||||||
|
{{# def.setParentData }}
|
||||||
|
{{=$data}} = {{=$coerced}};
|
||||||
|
{{? !$dataLvl }}if ({{=$parentData}} !== undefined){{?}}
|
||||||
|
{{=$parentData}}[{{=$parentDataProperty}}] = {{=$coerced}};
|
||||||
|
}
|
||||||
|
#}}
|
||||||
9
node_sid/node_modules/ajv/lib/dot/comment.jst
generated
vendored
Normal file
9
node_sid/node_modules/ajv/lib/dot/comment.jst
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
|
||||||
|
{{ var $comment = it.util.toQuotedString($schema); }}
|
||||||
|
{{? it.opts.$comment === true }}
|
||||||
|
console.log({{=$comment}});
|
||||||
|
{{?? typeof it.opts.$comment == 'function' }}
|
||||||
|
self._opts.$comment({{=$comment}}, {{=it.util.toQuotedString($errSchemaPath)}}, validate.root.schema);
|
||||||
|
{{?}}
|
||||||
11
node_sid/node_modules/ajv/lib/dot/const.jst
generated
vendored
Normal file
11
node_sid/node_modules/ajv/lib/dot/const.jst
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{? !$isData }}
|
||||||
|
var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
|
||||||
|
{{?}}
|
||||||
|
var {{=$valid}} = equal({{=$data}}, schema{{=$lvl}});
|
||||||
|
{{# def.checkError:'const' }}
|
||||||
|
{{? $breakOnError }} else { {{?}}
|
||||||
55
node_sid/node_modules/ajv/lib/dot/contains.jst
generated
vendored
Normal file
55
node_sid/node_modules/ajv/lib/dot/contains.jst
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $idx = 'i' + $lvl
|
||||||
|
, $dataNxt = $it.dataLevel = it.dataLevel + 1
|
||||||
|
, $nextData = 'data' + $dataNxt
|
||||||
|
, $currentBaseId = it.baseId
|
||||||
|
, $nonEmptySchema = {{# def.nonEmptySchema:$schema }};
|
||||||
|
}}
|
||||||
|
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
var {{=$valid}};
|
||||||
|
|
||||||
|
{{? $nonEmptySchema }}
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
$it.schema = $schema;
|
||||||
|
$it.schemaPath = $schemaPath;
|
||||||
|
$it.errSchemaPath = $errSchemaPath;
|
||||||
|
}}
|
||||||
|
|
||||||
|
var {{=$nextValid}} = false;
|
||||||
|
|
||||||
|
for (var {{=$idx}} = 0; {{=$idx}} < {{=$data}}.length; {{=$idx}}++) {
|
||||||
|
{{
|
||||||
|
$it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
|
||||||
|
var $passData = $data + '[' + $idx + ']';
|
||||||
|
$it.dataPathArr[$dataNxt] = $idx;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
{{# def.optimizeValidate }}
|
||||||
|
|
||||||
|
if ({{=$nextValid}}) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
{{= $closingBraces }}
|
||||||
|
|
||||||
|
if (!{{=$nextValid}}) {
|
||||||
|
{{??}}
|
||||||
|
if ({{=$data}}.length == 0) {
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{# def.error:'contains' }}
|
||||||
|
} else {
|
||||||
|
{{? $nonEmptySchema }}
|
||||||
|
{{# def.resetErrors }}
|
||||||
|
{{?}}
|
||||||
|
{{? it.opts.allErrors }} } {{?}}
|
||||||
191
node_sid/node_modules/ajv/lib/dot/custom.jst
generated
vendored
Normal file
191
node_sid/node_modules/ajv/lib/dot/custom.jst
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $rule = this
|
||||||
|
, $definition = 'definition' + $lvl
|
||||||
|
, $rDef = $rule.definition
|
||||||
|
, $closingBraces = '';
|
||||||
|
var $validate = $rDef.validate;
|
||||||
|
var $compile, $inline, $macro, $ruleValidate, $validateCode;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $isData && $rDef.$data }}
|
||||||
|
{{
|
||||||
|
$validateCode = 'keywordValidate' + $lvl;
|
||||||
|
var $validateSchema = $rDef.validateSchema;
|
||||||
|
}}
|
||||||
|
var {{=$definition}} = RULES.custom['{{=$keyword}}'].definition;
|
||||||
|
var {{=$validateCode}} = {{=$definition}}.validate;
|
||||||
|
{{??}}
|
||||||
|
{{
|
||||||
|
$ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
|
||||||
|
if (!$ruleValidate) return;
|
||||||
|
$schemaValue = 'validate.schema' + $schemaPath;
|
||||||
|
$validateCode = $ruleValidate.code;
|
||||||
|
$compile = $rDef.compile;
|
||||||
|
$inline = $rDef.inline;
|
||||||
|
$macro = $rDef.macro;
|
||||||
|
}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $ruleErrs = $validateCode + '.errors'
|
||||||
|
, $i = 'i' + $lvl
|
||||||
|
, $ruleErr = 'ruleErr' + $lvl
|
||||||
|
, $asyncKeyword = $rDef.async;
|
||||||
|
|
||||||
|
if ($asyncKeyword && !it.async)
|
||||||
|
throw new Error('async keyword in sync schema');
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? !($inline || $macro) }}{{=$ruleErrs}} = null;{{?}}
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
var {{=$valid}};
|
||||||
|
|
||||||
|
{{## def.callRuleValidate:
|
||||||
|
{{=$validateCode}}.call(
|
||||||
|
{{? it.opts.passContext }}this{{??}}self{{?}}
|
||||||
|
{{? $compile || $rDef.schema === false }}
|
||||||
|
, {{=$data}}
|
||||||
|
{{??}}
|
||||||
|
, {{=$schemaValue}}
|
||||||
|
, {{=$data}}
|
||||||
|
, validate.schema{{=it.schemaPath}}
|
||||||
|
{{?}}
|
||||||
|
, {{# def.dataPath }}
|
||||||
|
{{# def.passParentData }}
|
||||||
|
, rootData
|
||||||
|
)
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{## def.extendErrors:_inline:
|
||||||
|
for (var {{=$i}}={{=$errs}}; {{=$i}}<errors; {{=$i}}++) {
|
||||||
|
var {{=$ruleErr}} = vErrors[{{=$i}}];
|
||||||
|
if ({{=$ruleErr}}.dataPath === undefined)
|
||||||
|
{{=$ruleErr}}.dataPath = (dataPath || '') + {{= it.errorPath }};
|
||||||
|
{{# _inline ? 'if (\{\{=$ruleErr\}\}.schemaPath === undefined) {' : '' }}
|
||||||
|
{{=$ruleErr}}.schemaPath = "{{=$errSchemaPath}}";
|
||||||
|
{{# _inline ? '}' : '' }}
|
||||||
|
{{? it.opts.verbose }}
|
||||||
|
{{=$ruleErr}}.schema = {{=$schemaValue}};
|
||||||
|
{{=$ruleErr}}.data = {{=$data}};
|
||||||
|
{{?}}
|
||||||
|
}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? $isData && $rDef.$data }}
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
if ({{=$schemaValue}} === undefined) {
|
||||||
|
{{=$valid}} = true;
|
||||||
|
} else {
|
||||||
|
{{? $validateSchema }}
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
{{=$valid}} = {{=$definition}}.validateSchema({{=$schemaValue}});
|
||||||
|
if ({{=$valid}}) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $inline }}
|
||||||
|
{{? $rDef.statements }}
|
||||||
|
{{= $ruleValidate.validate }}
|
||||||
|
{{??}}
|
||||||
|
{{=$valid}} = {{= $ruleValidate.validate }};
|
||||||
|
{{?}}
|
||||||
|
{{?? $macro }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
{{
|
||||||
|
$it.schema = $ruleValidate.validate;
|
||||||
|
$it.schemaPath = '';
|
||||||
|
}}
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
{{ var $code = it.validate($it).replace(/validate\.schema/g, $validateCode); }}
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
{{= $code }}
|
||||||
|
{{??}}
|
||||||
|
{{# def.beginDefOut}}
|
||||||
|
{{# def.callRuleValidate }}
|
||||||
|
{{# def.storeDefOut:def_callRuleValidate }}
|
||||||
|
|
||||||
|
{{? $rDef.errors === false }}
|
||||||
|
{{=$valid}} = {{? $asyncKeyword }}await {{?}}{{= def_callRuleValidate }};
|
||||||
|
{{??}}
|
||||||
|
{{? $asyncKeyword }}
|
||||||
|
{{ $ruleErrs = 'customErrors' + $lvl; }}
|
||||||
|
var {{=$ruleErrs}} = null;
|
||||||
|
try {
|
||||||
|
{{=$valid}} = await {{= def_callRuleValidate }};
|
||||||
|
} catch (e) {
|
||||||
|
{{=$valid}} = false;
|
||||||
|
if (e instanceof ValidationError) {{=$ruleErrs}} = e.errors;
|
||||||
|
else throw e;
|
||||||
|
}
|
||||||
|
{{??}}
|
||||||
|
{{=$ruleErrs}} = null;
|
||||||
|
{{=$valid}} = {{= def_callRuleValidate }};
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $rDef.modifying }}
|
||||||
|
if ({{=$parentData}}) {{=$data}} = {{=$parentData}}[{{=$parentDataProperty}}];
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{= $closingBraces }}
|
||||||
|
|
||||||
|
{{## def.notValidationResult:
|
||||||
|
{{? $rDef.valid === undefined }}
|
||||||
|
!{{? $macro }}{{=$nextValid}}{{??}}{{=$valid}}{{?}}
|
||||||
|
{{??}}
|
||||||
|
{{= !$rDef.valid }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{? $rDef.valid }}
|
||||||
|
{{? $breakOnError }} if (true) { {{?}}
|
||||||
|
{{??}}
|
||||||
|
if ({{# def.notValidationResult }}) {
|
||||||
|
{{ $errorKeyword = $rule.keyword; }}
|
||||||
|
{{# def.beginDefOut}}
|
||||||
|
{{# def.error:'custom' }}
|
||||||
|
{{# def.storeDefOut:def_customError }}
|
||||||
|
|
||||||
|
{{? $inline }}
|
||||||
|
{{? $rDef.errors }}
|
||||||
|
{{? $rDef.errors != 'full' }}
|
||||||
|
{{# def.extendErrors:true }}
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
{{? $rDef.errors === false}}
|
||||||
|
{{= def_customError }}
|
||||||
|
{{??}}
|
||||||
|
if ({{=$errs}} == errors) {
|
||||||
|
{{= def_customError }}
|
||||||
|
} else {
|
||||||
|
{{# def.extendErrors:true }}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{?? $macro }}
|
||||||
|
{{# def.extraError:'custom' }}
|
||||||
|
{{??}}
|
||||||
|
{{? $rDef.errors === false}}
|
||||||
|
{{= def_customError }}
|
||||||
|
{{??}}
|
||||||
|
if (Array.isArray({{=$ruleErrs}})) {
|
||||||
|
if (vErrors === null) vErrors = {{=$ruleErrs}};
|
||||||
|
else vErrors = vErrors.concat({{=$ruleErrs}});
|
||||||
|
errors = vErrors.length;
|
||||||
|
{{# def.extendErrors:false }}
|
||||||
|
} else {
|
||||||
|
{{= def_customError }}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
|
{{?}}
|
||||||
47
node_sid/node_modules/ajv/lib/dot/defaults.def
generated
vendored
Normal file
47
node_sid/node_modules/ajv/lib/dot/defaults.def
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{{## def.assignDefault:
|
||||||
|
{{? it.compositeRule }}
|
||||||
|
{{
|
||||||
|
if (it.opts.strictDefaults) {
|
||||||
|
var $defaultMsg = 'default is ignored for: ' + $passData;
|
||||||
|
if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
|
||||||
|
else throw new Error($defaultMsg);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{??}}
|
||||||
|
if ({{=$passData}} === undefined
|
||||||
|
{{? it.opts.useDefaults == 'empty' }}
|
||||||
|
|| {{=$passData}} === null
|
||||||
|
|| {{=$passData}} === ''
|
||||||
|
{{?}}
|
||||||
|
)
|
||||||
|
{{=$passData}} = {{? it.opts.useDefaults == 'shared' }}
|
||||||
|
{{= it.useDefault($sch.default) }}
|
||||||
|
{{??}}
|
||||||
|
{{= JSON.stringify($sch.default) }}
|
||||||
|
{{?}};
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.defaultProperties:
|
||||||
|
{{
|
||||||
|
var $schema = it.schema.properties
|
||||||
|
, $schemaKeys = Object.keys($schema); }}
|
||||||
|
{{~ $schemaKeys:$propertyKey }}
|
||||||
|
{{ var $sch = $schema[$propertyKey]; }}
|
||||||
|
{{? $sch.default !== undefined }}
|
||||||
|
{{ var $passData = $data + it.util.getProperty($propertyKey); }}
|
||||||
|
{{# def.assignDefault }}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.defaultItems:
|
||||||
|
{{~ it.schema.items:$sch:$i }}
|
||||||
|
{{? $sch.default !== undefined }}
|
||||||
|
{{ var $passData = $data + '[' + $i + ']'; }}
|
||||||
|
{{# def.assignDefault }}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
#}}
|
||||||
203
node_sid/node_modules/ajv/lib/dot/definitions.def
generated
vendored
Normal file
203
node_sid/node_modules/ajv/lib/dot/definitions.def
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
{{## def.setupKeyword:
|
||||||
|
{{
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $errorKeyword;
|
||||||
|
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $valid = 'valid' + $lvl;
|
||||||
|
var $errs = 'errs__' + $lvl;
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.setCompositeRule:
|
||||||
|
{{
|
||||||
|
var $wasComposite = it.compositeRule;
|
||||||
|
it.compositeRule = $it.compositeRule = true;
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.resetCompositeRule:
|
||||||
|
{{ it.compositeRule = $it.compositeRule = $wasComposite; }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.setupNextLevel:
|
||||||
|
{{
|
||||||
|
var $it = it.util.copy(it);
|
||||||
|
var $closingBraces = '';
|
||||||
|
$it.level++;
|
||||||
|
var $nextValid = 'valid' + $it.level;
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.ifValid:
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if ({{=$valid}}) {
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.ifResultValid:
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if ({{=$nextValid}}) {
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.elseIfValid:
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
else {
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.nonEmptySchema:_schema:
|
||||||
|
(it.opts.strictKeywords
|
||||||
|
? (typeof _schema == 'object' && Object.keys(_schema).length > 0)
|
||||||
|
|| _schema === false
|
||||||
|
: it.util.schemaHasRules(_schema, it.RULES.all))
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.strLength:
|
||||||
|
{{? it.opts.unicode === false }}
|
||||||
|
{{=$data}}.length
|
||||||
|
{{??}}
|
||||||
|
ucs2length({{=$data}})
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.willOptimize:
|
||||||
|
it.util.varOccurences($code, $nextData) < 2
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.generateSubschemaCode:
|
||||||
|
{{
|
||||||
|
var $code = it.validate($it);
|
||||||
|
$it.baseId = $currentBaseId;
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.insertSubschemaCode:
|
||||||
|
{{= it.validate($it) }}
|
||||||
|
{{ $it.baseId = $currentBaseId; }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def._optimizeValidate:
|
||||||
|
it.util.varReplace($code, $nextData, $passData)
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.optimizeValidate:
|
||||||
|
{{? {{# def.willOptimize}} }}
|
||||||
|
{{= {{# def._optimizeValidate }} }}
|
||||||
|
{{??}}
|
||||||
|
var {{=$nextData}} = {{=$passData}};
|
||||||
|
{{= $code }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.$data:
|
||||||
|
{{
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data
|
||||||
|
, $schemaValue;
|
||||||
|
}}
|
||||||
|
{{? $isData }}
|
||||||
|
var schema{{=$lvl}} = {{= it.util.getData($schema.$data, $dataLvl, it.dataPathArr) }};
|
||||||
|
{{ $schemaValue = 'schema' + $lvl; }}
|
||||||
|
{{??}}
|
||||||
|
{{ $schemaValue = $schema; }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.$dataNotType:_type:
|
||||||
|
{{?$isData}} ({{=$schemaValue}} !== undefined && typeof {{=$schemaValue}} != _type) || {{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.check$dataIsArray:
|
||||||
|
if (schema{{=$lvl}} === undefined) {{=$valid}} = true;
|
||||||
|
else if (!Array.isArray(schema{{=$lvl}})) {{=$valid}} = false;
|
||||||
|
else {
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.numberKeyword:
|
||||||
|
{{? !($isData || typeof $schema == 'number') }}
|
||||||
|
{{ throw new Error($keyword + ' must be number'); }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.beginDefOut:
|
||||||
|
{{
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = '';
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.storeDefOut:_variable:
|
||||||
|
{{
|
||||||
|
var _variable = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.dataPath:(dataPath || ''){{? it.errorPath != '""'}} + {{= it.errorPath }}{{?}}#}}
|
||||||
|
|
||||||
|
{{## def.setParentData:
|
||||||
|
{{
|
||||||
|
var $parentData = $dataLvl ? 'data' + (($dataLvl-1)||'') : 'parentData'
|
||||||
|
, $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{## def.passParentData:
|
||||||
|
{{# def.setParentData }}
|
||||||
|
, {{= $parentData }}
|
||||||
|
, {{= $parentDataProperty }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.iterateProperties:
|
||||||
|
{{? $ownProperties }}
|
||||||
|
{{=$dataProperties}} = {{=$dataProperties}} || Object.keys({{=$data}});
|
||||||
|
for (var {{=$idx}}=0; {{=$idx}}<{{=$dataProperties}}.length; {{=$idx}}++) {
|
||||||
|
var {{=$key}} = {{=$dataProperties}}[{{=$idx}}];
|
||||||
|
{{??}}
|
||||||
|
for (var {{=$key}} in {{=$data}}) {
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.noPropertyInData:
|
||||||
|
{{=$useData}} === undefined
|
||||||
|
{{? $ownProperties }}
|
||||||
|
|| !{{# def.isOwnProperty }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.isOwnProperty:
|
||||||
|
Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($propertyKey)}}')
|
||||||
|
#}}
|
||||||
79
node_sid/node_modules/ajv/lib/dot/dependencies.jst
generated
vendored
Normal file
79
node_sid/node_modules/ajv/lib/dot/dependencies.jst
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.missing }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.propertyInData:
|
||||||
|
{{=$data}}{{= it.util.getProperty($property) }} !== undefined
|
||||||
|
{{? $ownProperties }}
|
||||||
|
&& Object.prototype.hasOwnProperty.call({{=$data}}, '{{=it.util.escapeQuotes($property)}}')
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $schemaDeps = {}
|
||||||
|
, $propertyDeps = {}
|
||||||
|
, $ownProperties = it.opts.ownProperties;
|
||||||
|
|
||||||
|
for ($property in $schema) {
|
||||||
|
if ($property == '__proto__') continue;
|
||||||
|
var $sch = $schema[$property];
|
||||||
|
var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
|
||||||
|
$deps[$property] = $sch;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
|
||||||
|
{{ var $currentErrorPath = it.errorPath; }}
|
||||||
|
|
||||||
|
var missing{{=$lvl}};
|
||||||
|
{{ for (var $property in $propertyDeps) { }}
|
||||||
|
{{ $deps = $propertyDeps[$property]; }}
|
||||||
|
{{? $deps.length }}
|
||||||
|
if ({{# def.propertyInData }}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
&& ({{# def.checkMissingProperty:$deps }})) {
|
||||||
|
{{# def.errorMissingProperty:'dependencies' }}
|
||||||
|
{{??}}
|
||||||
|
) {
|
||||||
|
{{~ $deps:$propertyKey }}
|
||||||
|
{{# def.allErrorsMissingProperty:'dependencies' }}
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
} {{# def.elseIfValid }}
|
||||||
|
{{?}}
|
||||||
|
{{ } }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
it.errorPath = $currentErrorPath;
|
||||||
|
var $currentBaseId = $it.baseId;
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
{{ for (var $property in $schemaDeps) { }}
|
||||||
|
{{ var $sch = $schemaDeps[$property]; }}
|
||||||
|
{{? {{# def.nonEmptySchema:$sch }} }}
|
||||||
|
{{=$nextValid}} = true;
|
||||||
|
|
||||||
|
if ({{# def.propertyInData }}) {
|
||||||
|
{{
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + it.util.getProperty($property);
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.insertSubschemaCode }}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{?}}
|
||||||
|
{{ } }}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{= $closingBraces }}
|
||||||
|
if ({{=$errs}} == errors) {
|
||||||
|
{{?}}
|
||||||
30
node_sid/node_modules/ajv/lib/dot/enum.jst
generated
vendored
Normal file
30
node_sid/node_modules/ajv/lib/dot/enum.jst
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $i = 'i' + $lvl
|
||||||
|
, $vSchema = 'schema' + $lvl;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? !$isData }}
|
||||||
|
var {{=$vSchema}} = validate.schema{{=$schemaPath}};
|
||||||
|
{{?}}
|
||||||
|
var {{=$valid}};
|
||||||
|
|
||||||
|
{{?$isData}}{{# def.check$dataIsArray }}{{?}}
|
||||||
|
|
||||||
|
{{=$valid}} = false;
|
||||||
|
|
||||||
|
for (var {{=$i}}=0; {{=$i}}<{{=$vSchema}}.length; {{=$i}}++)
|
||||||
|
if (equal({{=$data}}, {{=$vSchema}}[{{=$i}}])) {
|
||||||
|
{{=$valid}} = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
{{? $isData }} } {{?}}
|
||||||
|
|
||||||
|
{{# def.checkError:'enum' }}
|
||||||
|
|
||||||
|
{{? $breakOnError }} else { {{?}}
|
||||||
194
node_sid/node_modules/ajv/lib/dot/errors.def
generated
vendored
Normal file
194
node_sid/node_modules/ajv/lib/dot/errors.def
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
|
||||||
|
{{## def._error:_rule:
|
||||||
|
{{ 'istanbul ignore else'; }}
|
||||||
|
{{? it.createErrors !== false }}
|
||||||
|
{
|
||||||
|
keyword: '{{= $errorKeyword || _rule }}'
|
||||||
|
, dataPath: (dataPath || '') + {{= it.errorPath }}
|
||||||
|
, schemaPath: {{=it.util.toQuotedString($errSchemaPath)}}
|
||||||
|
, params: {{# def._errorParams[_rule] }}
|
||||||
|
{{? it.opts.messages !== false }}
|
||||||
|
, message: {{# def._errorMessages[_rule] }}
|
||||||
|
{{?}}
|
||||||
|
{{? it.opts.verbose }}
|
||||||
|
, schema: {{# def._errorSchemas[_rule] }}
|
||||||
|
, parentSchema: validate.schema{{=it.schemaPath}}
|
||||||
|
, data: {{=$data}}
|
||||||
|
{{?}}
|
||||||
|
}
|
||||||
|
{{??}}
|
||||||
|
{}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def._addError:_rule:
|
||||||
|
if (vErrors === null) vErrors = [err];
|
||||||
|
else vErrors.push(err);
|
||||||
|
errors++;
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.addError:_rule:
|
||||||
|
var err = {{# def._error:_rule }};
|
||||||
|
{{# def._addError:_rule }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.error:_rule:
|
||||||
|
{{# def.beginDefOut}}
|
||||||
|
{{# def._error:_rule }}
|
||||||
|
{{# def.storeDefOut:__err }}
|
||||||
|
|
||||||
|
{{? !it.compositeRule && $breakOnError }}
|
||||||
|
{{ 'istanbul ignore if'; }}
|
||||||
|
{{? it.async }}
|
||||||
|
throw new ValidationError([{{=__err}}]);
|
||||||
|
{{??}}
|
||||||
|
validate.errors = [{{=__err}}];
|
||||||
|
return false;
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
var err = {{=__err}};
|
||||||
|
{{# def._addError:_rule }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.extraError:_rule:
|
||||||
|
{{# def.addError:_rule}}
|
||||||
|
{{? !it.compositeRule && $breakOnError }}
|
||||||
|
{{ 'istanbul ignore if'; }}
|
||||||
|
{{? it.async }}
|
||||||
|
throw new ValidationError(vErrors);
|
||||||
|
{{??}}
|
||||||
|
validate.errors = vErrors;
|
||||||
|
return false;
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.checkError:_rule:
|
||||||
|
if (!{{=$valid}}) {
|
||||||
|
{{# def.error:_rule }}
|
||||||
|
}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.resetErrors:
|
||||||
|
errors = {{=$errs}};
|
||||||
|
if (vErrors !== null) {
|
||||||
|
if ({{=$errs}}) vErrors.length = {{=$errs}};
|
||||||
|
else vErrors = null;
|
||||||
|
}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.concatSchema:{{?$isData}}' + {{=$schemaValue}} + '{{??}}{{=$schema}}{{?}}#}}
|
||||||
|
{{## def.appendSchema:{{?$isData}}' + {{=$schemaValue}}{{??}}{{=$schemaValue}}'{{?}}#}}
|
||||||
|
{{## def.concatSchemaEQ:{{?$isData}}' + {{=$schemaValue}} + '{{??}}{{=it.util.escapeQuotes($schema)}}{{?}}#}}
|
||||||
|
|
||||||
|
{{## def._errorMessages = {
|
||||||
|
'false schema': "'boolean schema is false'",
|
||||||
|
$ref: "'can\\\'t resolve reference {{=it.util.escapeQuotes($schema)}}'",
|
||||||
|
additionalItems: "'should NOT have more than {{=$schema.length}} items'",
|
||||||
|
additionalProperties: "'{{? it.opts._errorDataPathProperty }}is an invalid additional property{{??}}should NOT have additional properties{{?}}'",
|
||||||
|
anyOf: "'should match some schema in anyOf'",
|
||||||
|
const: "'should be equal to constant'",
|
||||||
|
contains: "'should contain a valid item'",
|
||||||
|
dependencies: "'should have {{? $deps.length == 1 }}property {{= it.util.escapeQuotes($deps[0]) }}{{??}}properties {{= it.util.escapeQuotes($deps.join(\", \")) }}{{?}} when property {{= it.util.escapeQuotes($property) }} is present'",
|
||||||
|
'enum': "'should be equal to one of the allowed values'",
|
||||||
|
format: "'should match format \"{{#def.concatSchemaEQ}}\"'",
|
||||||
|
'if': "'should match \"' + {{=$ifClause}} + '\" schema'",
|
||||||
|
_limit: "'should be {{=$opStr}} {{#def.appendSchema}}",
|
||||||
|
_exclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'",
|
||||||
|
_limitItems: "'should NOT have {{?$keyword=='maxItems'}}more{{??}}fewer{{?}} than {{#def.concatSchema}} items'",
|
||||||
|
_limitLength: "'should NOT be {{?$keyword=='maxLength'}}longer{{??}}shorter{{?}} than {{#def.concatSchema}} characters'",
|
||||||
|
_limitProperties:"'should NOT have {{?$keyword=='maxProperties'}}more{{??}}fewer{{?}} than {{#def.concatSchema}} properties'",
|
||||||
|
multipleOf: "'should be multiple of {{#def.appendSchema}}",
|
||||||
|
not: "'should NOT be valid'",
|
||||||
|
oneOf: "'should match exactly one schema in oneOf'",
|
||||||
|
pattern: "'should match pattern \"{{#def.concatSchemaEQ}}\"'",
|
||||||
|
propertyNames: "'property name \\'{{=$invalidName}}\\' is invalid'",
|
||||||
|
required: "'{{? it.opts._errorDataPathProperty }}is a required property{{??}}should have required property \\'{{=$missingProperty}}\\'{{?}}'",
|
||||||
|
type: "'should be {{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}'",
|
||||||
|
uniqueItems: "'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)'",
|
||||||
|
custom: "'should pass \"{{=$rule.keyword}}\" keyword validation'",
|
||||||
|
patternRequired: "'should have property matching pattern \\'{{=$missingPattern}}\\''",
|
||||||
|
switch: "'should pass \"switch\" keyword validation'",
|
||||||
|
_formatLimit: "'should be {{=$opStr}} \"{{#def.concatSchemaEQ}}\"'",
|
||||||
|
_formatExclusiveLimit: "'{{=$exclusiveKeyword}} should be boolean'"
|
||||||
|
} #}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.schemaRefOrVal: {{?$isData}}validate.schema{{=$schemaPath}}{{??}}{{=$schema}}{{?}} #}}
|
||||||
|
{{## def.schemaRefOrQS: {{?$isData}}validate.schema{{=$schemaPath}}{{??}}{{=it.util.toQuotedString($schema)}}{{?}} #}}
|
||||||
|
|
||||||
|
{{## def._errorSchemas = {
|
||||||
|
'false schema': "false",
|
||||||
|
$ref: "{{=it.util.toQuotedString($schema)}}",
|
||||||
|
additionalItems: "false",
|
||||||
|
additionalProperties: "false",
|
||||||
|
anyOf: "validate.schema{{=$schemaPath}}",
|
||||||
|
const: "validate.schema{{=$schemaPath}}",
|
||||||
|
contains: "validate.schema{{=$schemaPath}}",
|
||||||
|
dependencies: "validate.schema{{=$schemaPath}}",
|
||||||
|
'enum': "validate.schema{{=$schemaPath}}",
|
||||||
|
format: "{{#def.schemaRefOrQS}}",
|
||||||
|
'if': "validate.schema{{=$schemaPath}}",
|
||||||
|
_limit: "{{#def.schemaRefOrVal}}",
|
||||||
|
_exclusiveLimit: "validate.schema{{=$schemaPath}}",
|
||||||
|
_limitItems: "{{#def.schemaRefOrVal}}",
|
||||||
|
_limitLength: "{{#def.schemaRefOrVal}}",
|
||||||
|
_limitProperties:"{{#def.schemaRefOrVal}}",
|
||||||
|
multipleOf: "{{#def.schemaRefOrVal}}",
|
||||||
|
not: "validate.schema{{=$schemaPath}}",
|
||||||
|
oneOf: "validate.schema{{=$schemaPath}}",
|
||||||
|
pattern: "{{#def.schemaRefOrQS}}",
|
||||||
|
propertyNames: "validate.schema{{=$schemaPath}}",
|
||||||
|
required: "validate.schema{{=$schemaPath}}",
|
||||||
|
type: "validate.schema{{=$schemaPath}}",
|
||||||
|
uniqueItems: "{{#def.schemaRefOrVal}}",
|
||||||
|
custom: "validate.schema{{=$schemaPath}}",
|
||||||
|
patternRequired: "validate.schema{{=$schemaPath}}",
|
||||||
|
switch: "validate.schema{{=$schemaPath}}",
|
||||||
|
_formatLimit: "{{#def.schemaRefOrQS}}",
|
||||||
|
_formatExclusiveLimit: "validate.schema{{=$schemaPath}}"
|
||||||
|
} #}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.schemaValueQS: {{?$isData}}{{=$schemaValue}}{{??}}{{=it.util.toQuotedString($schema)}}{{?}} #}}
|
||||||
|
|
||||||
|
{{## def._errorParams = {
|
||||||
|
'false schema': "{}",
|
||||||
|
$ref: "{ ref: '{{=it.util.escapeQuotes($schema)}}' }",
|
||||||
|
additionalItems: "{ limit: {{=$schema.length}} }",
|
||||||
|
additionalProperties: "{ additionalProperty: '{{=$additionalProperty}}' }",
|
||||||
|
anyOf: "{}",
|
||||||
|
const: "{ allowedValue: schema{{=$lvl}} }",
|
||||||
|
contains: "{}",
|
||||||
|
dependencies: "{ property: '{{= it.util.escapeQuotes($property) }}', missingProperty: '{{=$missingProperty}}', depsCount: {{=$deps.length}}, deps: '{{= it.util.escapeQuotes($deps.length==1 ? $deps[0] : $deps.join(\", \")) }}' }",
|
||||||
|
'enum': "{ allowedValues: schema{{=$lvl}} }",
|
||||||
|
format: "{ format: {{#def.schemaValueQS}} }",
|
||||||
|
'if': "{ failingKeyword: {{=$ifClause}} }",
|
||||||
|
_limit: "{ comparison: {{=$opExpr}}, limit: {{=$schemaValue}}, exclusive: {{=$exclusive}} }",
|
||||||
|
_exclusiveLimit: "{}",
|
||||||
|
_limitItems: "{ limit: {{=$schemaValue}} }",
|
||||||
|
_limitLength: "{ limit: {{=$schemaValue}} }",
|
||||||
|
_limitProperties:"{ limit: {{=$schemaValue}} }",
|
||||||
|
multipleOf: "{ multipleOf: {{=$schemaValue}} }",
|
||||||
|
not: "{}",
|
||||||
|
oneOf: "{ passingSchemas: {{=$passingSchemas}} }",
|
||||||
|
pattern: "{ pattern: {{#def.schemaValueQS}} }",
|
||||||
|
propertyNames: "{ propertyName: '{{=$invalidName}}' }",
|
||||||
|
required: "{ missingProperty: '{{=$missingProperty}}' }",
|
||||||
|
type: "{ type: '{{? $typeIsArray }}{{= $typeSchema.join(\",\") }}{{??}}{{=$typeSchema}}{{?}}' }",
|
||||||
|
uniqueItems: "{ i: i, j: j }",
|
||||||
|
custom: "{ keyword: '{{=$rule.keyword}}' }",
|
||||||
|
patternRequired: "{ missingPattern: '{{=$missingPattern}}' }",
|
||||||
|
switch: "{ caseIndex: {{=$caseIndex}} }",
|
||||||
|
_formatLimit: "{ comparison: {{=$opExpr}}, limit: {{#def.schemaValueQS}}, exclusive: {{=$exclusive}} }",
|
||||||
|
_formatExclusiveLimit: "{}"
|
||||||
|
} #}}
|
||||||
106
node_sid/node_modules/ajv/lib/dot/format.jst
generated
vendored
Normal file
106
node_sid/node_modules/ajv/lib/dot/format.jst
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
|
||||||
|
{{## def.skipFormat:
|
||||||
|
{{? $breakOnError }} if (true) { {{?}}
|
||||||
|
{{ return out; }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{? it.opts.format === false }}{{# def.skipFormat }}{{?}}
|
||||||
|
|
||||||
|
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.$dataCheckFormat:
|
||||||
|
{{# def.$dataNotType:'string' }}
|
||||||
|
({{? $unknownFormats != 'ignore' }}
|
||||||
|
({{=$schemaValue}} && !{{=$format}}
|
||||||
|
{{? $allowUnknown }}
|
||||||
|
&& self._opts.unknownFormats.indexOf({{=$schemaValue}}) == -1
|
||||||
|
{{?}}) ||
|
||||||
|
{{?}}
|
||||||
|
({{=$format}} && {{=$formatType}} == '{{=$ruleType}}'
|
||||||
|
&& !(typeof {{=$format}} == 'function'
|
||||||
|
? {{? it.async}}
|
||||||
|
(async{{=$lvl}} ? await {{=$format}}({{=$data}}) : {{=$format}}({{=$data}}))
|
||||||
|
{{??}}
|
||||||
|
{{=$format}}({{=$data}})
|
||||||
|
{{?}}
|
||||||
|
: {{=$format}}.test({{=$data}}))))
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{## def.checkFormat:
|
||||||
|
{{
|
||||||
|
var $formatRef = 'formats' + it.util.getProperty($schema);
|
||||||
|
if ($isObject) $formatRef += '.validate';
|
||||||
|
}}
|
||||||
|
{{? typeof $format == 'function' }}
|
||||||
|
{{=$formatRef}}({{=$data}})
|
||||||
|
{{??}}
|
||||||
|
{{=$formatRef}}.test({{=$data}})
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $unknownFormats = it.opts.unknownFormats
|
||||||
|
, $allowUnknown = Array.isArray($unknownFormats);
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $isData }}
|
||||||
|
{{
|
||||||
|
var $format = 'format' + $lvl
|
||||||
|
, $isObject = 'isObject' + $lvl
|
||||||
|
, $formatType = 'formatType' + $lvl;
|
||||||
|
}}
|
||||||
|
var {{=$format}} = formats[{{=$schemaValue}}];
|
||||||
|
var {{=$isObject}} = typeof {{=$format}} == 'object'
|
||||||
|
&& !({{=$format}} instanceof RegExp)
|
||||||
|
&& {{=$format}}.validate;
|
||||||
|
var {{=$formatType}} = {{=$isObject}} && {{=$format}}.type || 'string';
|
||||||
|
if ({{=$isObject}}) {
|
||||||
|
{{? it.async}}
|
||||||
|
var async{{=$lvl}} = {{=$format}}.async;
|
||||||
|
{{?}}
|
||||||
|
{{=$format}} = {{=$format}}.validate;
|
||||||
|
}
|
||||||
|
if ({{# def.$dataCheckFormat }}) {
|
||||||
|
{{??}}
|
||||||
|
{{ var $format = it.formats[$schema]; }}
|
||||||
|
{{? !$format }}
|
||||||
|
{{? $unknownFormats == 'ignore' }}
|
||||||
|
{{ it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"'); }}
|
||||||
|
{{# def.skipFormat }}
|
||||||
|
{{?? $allowUnknown && $unknownFormats.indexOf($schema) >= 0 }}
|
||||||
|
{{# def.skipFormat }}
|
||||||
|
{{??}}
|
||||||
|
{{ throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"'); }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{
|
||||||
|
var $isObject = typeof $format == 'object'
|
||||||
|
&& !($format instanceof RegExp)
|
||||||
|
&& $format.validate;
|
||||||
|
var $formatType = $isObject && $format.type || 'string';
|
||||||
|
if ($isObject) {
|
||||||
|
var $async = $format.async === true;
|
||||||
|
$format = $format.validate;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{? $formatType != $ruleType }}
|
||||||
|
{{# def.skipFormat }}
|
||||||
|
{{?}}
|
||||||
|
{{? $async }}
|
||||||
|
{{
|
||||||
|
if (!it.async) throw new Error('async format in sync schema');
|
||||||
|
var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
|
||||||
|
}}
|
||||||
|
if (!(await {{=$formatRef}}({{=$data}}))) {
|
||||||
|
{{??}}
|
||||||
|
if (!{{# def.checkFormat }}) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{# def.error:'format' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
73
node_sid/node_modules/ajv/lib/dot/if.jst
generated
vendored
Normal file
73
node_sid/node_modules/ajv/lib/dot/if.jst
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.validateIfClause:_clause:
|
||||||
|
{{
|
||||||
|
$it.schema = it.schema['_clause'];
|
||||||
|
$it.schemaPath = it.schemaPath + '._clause';
|
||||||
|
$it.errSchemaPath = it.errSchemaPath + '/_clause';
|
||||||
|
}}
|
||||||
|
{{# def.insertSubschemaCode }}
|
||||||
|
{{=$valid}} = {{=$nextValid}};
|
||||||
|
{{? $thenPresent && $elsePresent }}
|
||||||
|
{{ $ifClause = 'ifClause' + $lvl; }}
|
||||||
|
var {{=$ifClause}} = '_clause';
|
||||||
|
{{??}}
|
||||||
|
{{ $ifClause = '\'_clause\''; }}
|
||||||
|
{{?}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $thenSch = it.schema['then']
|
||||||
|
, $elseSch = it.schema['else']
|
||||||
|
, $thenPresent = $thenSch !== undefined && {{# def.nonEmptySchema:$thenSch }}
|
||||||
|
, $elsePresent = $elseSch !== undefined && {{# def.nonEmptySchema:$elseSch }}
|
||||||
|
, $currentBaseId = $it.baseId;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $thenPresent || $elsePresent }}
|
||||||
|
{{
|
||||||
|
var $ifClause;
|
||||||
|
$it.createErrors = false;
|
||||||
|
$it.schema = $schema;
|
||||||
|
$it.schemaPath = $schemaPath;
|
||||||
|
$it.errSchemaPath = $errSchemaPath;
|
||||||
|
}}
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
var {{=$valid}} = true;
|
||||||
|
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
{{# def.insertSubschemaCode }}
|
||||||
|
{{ $it.createErrors = true; }}
|
||||||
|
{{# def.resetErrors }}
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
|
||||||
|
{{? $thenPresent }}
|
||||||
|
if ({{=$nextValid}}) {
|
||||||
|
{{# def.validateIfClause:then }}
|
||||||
|
}
|
||||||
|
{{? $elsePresent }}
|
||||||
|
else {
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
if (!{{=$nextValid}}) {
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $elsePresent }}
|
||||||
|
{{# def.validateIfClause:else }}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
if (!{{=$valid}}) {
|
||||||
|
{{# def.extraError:'if' }}
|
||||||
|
}
|
||||||
|
{{? $breakOnError }} else { {{?}}
|
||||||
|
{{??}}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if (true) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
98
node_sid/node_modules/ajv/lib/dot/items.jst
generated
vendored
Normal file
98
node_sid/node_modules/ajv/lib/dot/items.jst
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.validateItems:startFrom:
|
||||||
|
for (var {{=$idx}} = {{=startFrom}}; {{=$idx}} < {{=$data}}.length; {{=$idx}}++) {
|
||||||
|
{{
|
||||||
|
$it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
|
||||||
|
var $passData = $data + '[' + $idx + ']';
|
||||||
|
$it.dataPathArr[$dataNxt] = $idx;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
{{# def.optimizeValidate }}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if (!{{=$nextValid}}) break;
|
||||||
|
{{?}}
|
||||||
|
}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $idx = 'i' + $lvl
|
||||||
|
, $dataNxt = $it.dataLevel = it.dataLevel + 1
|
||||||
|
, $nextData = 'data' + $dataNxt
|
||||||
|
, $currentBaseId = it.baseId;
|
||||||
|
}}
|
||||||
|
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
var {{=$valid}};
|
||||||
|
|
||||||
|
{{? Array.isArray($schema) }}
|
||||||
|
{{ /* 'items' is an array of schemas */}}
|
||||||
|
{{ var $additionalItems = it.schema.additionalItems; }}
|
||||||
|
{{? $additionalItems === false }}
|
||||||
|
{{=$valid}} = {{=$data}}.length <= {{= $schema.length }};
|
||||||
|
{{
|
||||||
|
var $currErrSchemaPath = $errSchemaPath;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/additionalItems';
|
||||||
|
}}
|
||||||
|
{{# def.checkError:'additionalItems' }}
|
||||||
|
{{ $errSchemaPath = $currErrSchemaPath; }}
|
||||||
|
{{# def.elseIfValid}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{~ $schema:$sch:$i }}
|
||||||
|
{{? {{# def.nonEmptySchema:$sch }} }}
|
||||||
|
{{=$nextValid}} = true;
|
||||||
|
|
||||||
|
if ({{=$data}}.length > {{=$i}}) {
|
||||||
|
{{
|
||||||
|
var $passData = $data + '[' + $i + ']';
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + $i;
|
||||||
|
$it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
|
||||||
|
$it.dataPathArr[$dataNxt] = $i;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
{{# def.optimizeValidate }}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
|
||||||
|
{{? typeof $additionalItems == 'object' && {{# def.nonEmptySchema:$additionalItems }} }}
|
||||||
|
{{
|
||||||
|
$it.schema = $additionalItems;
|
||||||
|
$it.schemaPath = it.schemaPath + '.additionalItems';
|
||||||
|
$it.errSchemaPath = it.errSchemaPath + '/additionalItems';
|
||||||
|
}}
|
||||||
|
{{=$nextValid}} = true;
|
||||||
|
|
||||||
|
if ({{=$data}}.length > {{= $schema.length }}) {
|
||||||
|
{{# def.validateItems: $schema.length }}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{?? {{# def.nonEmptySchema:$schema }} }}
|
||||||
|
{{ /* 'items' is a single schema */}}
|
||||||
|
{{
|
||||||
|
$it.schema = $schema;
|
||||||
|
$it.schemaPath = $schemaPath;
|
||||||
|
$it.errSchemaPath = $errSchemaPath;
|
||||||
|
}}
|
||||||
|
{{# def.validateItems: 0 }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{= $closingBraces }}
|
||||||
|
if ({{=$errs}} == errors) {
|
||||||
|
{{?}}
|
||||||
39
node_sid/node_modules/ajv/lib/dot/missing.def
generated
vendored
Normal file
39
node_sid/node_modules/ajv/lib/dot/missing.def
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{{## def.checkMissingProperty:_properties:
|
||||||
|
{{~ _properties:$propertyKey:$i }}
|
||||||
|
{{?$i}} || {{?}}
|
||||||
|
{{
|
||||||
|
var $prop = it.util.getProperty($propertyKey)
|
||||||
|
, $useData = $data + $prop;
|
||||||
|
}}
|
||||||
|
( ({{# def.noPropertyInData }}) && (missing{{=$lvl}} = {{= it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop) }}) )
|
||||||
|
{{~}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.errorMissingProperty:_error:
|
||||||
|
{{
|
||||||
|
var $propertyPath = 'missing' + $lvl
|
||||||
|
, $missingProperty = '\' + ' + $propertyPath + ' + \'';
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.opts.jsonPointers
|
||||||
|
? it.util.getPathExpr($currentErrorPath, $propertyPath, true)
|
||||||
|
: $currentErrorPath + ' + ' + $propertyPath;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{# def.error:_error }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.allErrorsMissingProperty:_error:
|
||||||
|
{{
|
||||||
|
var $prop = it.util.getProperty($propertyKey)
|
||||||
|
, $missingProperty = it.util.escapeQuotes($propertyKey)
|
||||||
|
, $useData = $data + $prop;
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
if ({{# def.noPropertyInData }}) {
|
||||||
|
{{# def.addError:_error }}
|
||||||
|
}
|
||||||
|
#}}
|
||||||
22
node_sid/node_modules/ajv/lib/dot/multipleOf.jst
generated
vendored
Normal file
22
node_sid/node_modules/ajv/lib/dot/multipleOf.jst
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{# def.numberKeyword }}
|
||||||
|
|
||||||
|
var division{{=$lvl}};
|
||||||
|
if ({{?$isData}}
|
||||||
|
{{=$schemaValue}} !== undefined && (
|
||||||
|
typeof {{=$schemaValue}} != 'number' ||
|
||||||
|
{{?}}
|
||||||
|
(division{{=$lvl}} = {{=$data}} / {{=$schemaValue}},
|
||||||
|
{{? it.opts.multipleOfPrecision }}
|
||||||
|
Math.abs(Math.round(division{{=$lvl}}) - division{{=$lvl}}) > 1e-{{=it.opts.multipleOfPrecision}}
|
||||||
|
{{??}}
|
||||||
|
division{{=$lvl}} !== parseInt(division{{=$lvl}})
|
||||||
|
{{?}}
|
||||||
|
)
|
||||||
|
{{?$isData}} ) {{?}} ) {
|
||||||
|
{{# def.error:'multipleOf' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
43
node_sid/node_modules/ajv/lib/dot/not.jst
generated
vendored
Normal file
43
node_sid/node_modules/ajv/lib/dot/not.jst
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
{{? {{# def.nonEmptySchema:$schema }} }}
|
||||||
|
{{
|
||||||
|
$it.schema = $schema;
|
||||||
|
$it.schemaPath = $schemaPath;
|
||||||
|
$it.errSchemaPath = $errSchemaPath;
|
||||||
|
}}
|
||||||
|
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
$it.createErrors = false;
|
||||||
|
var $allErrorsOption;
|
||||||
|
if ($it.opts.allErrors) {
|
||||||
|
$allErrorsOption = $it.opts.allErrors;
|
||||||
|
$it.opts.allErrors = false;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{= it.validate($it) }}
|
||||||
|
{{
|
||||||
|
$it.createErrors = true;
|
||||||
|
if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
|
||||||
|
if ({{=$nextValid}}) {
|
||||||
|
{{# def.error:'not' }}
|
||||||
|
} else {
|
||||||
|
{{# def.resetErrors }}
|
||||||
|
{{? it.opts.allErrors }} } {{?}}
|
||||||
|
{{??}}
|
||||||
|
{{# def.addError:'not' }}
|
||||||
|
{{? $breakOnError}}
|
||||||
|
if (false) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
54
node_sid/node_modules/ajv/lib/dot/oneOf.jst
generated
vendored
Normal file
54
node_sid/node_modules/ajv/lib/dot/oneOf.jst
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $currentBaseId = $it.baseId
|
||||||
|
, $prevValid = 'prevValid' + $lvl
|
||||||
|
, $passingSchemas = 'passingSchemas' + $lvl;
|
||||||
|
}}
|
||||||
|
|
||||||
|
var {{=$errs}} = errors
|
||||||
|
, {{=$prevValid}} = false
|
||||||
|
, {{=$valid}} = false
|
||||||
|
, {{=$passingSchemas}} = null;
|
||||||
|
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
|
||||||
|
{{~ $schema:$sch:$i }}
|
||||||
|
{{? {{# def.nonEmptySchema:$sch }} }}
|
||||||
|
{{
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + $i;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.insertSubschemaCode }}
|
||||||
|
{{??}}
|
||||||
|
var {{=$nextValid}} = true;
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $i }}
|
||||||
|
if ({{=$nextValid}} && {{=$prevValid}}) {
|
||||||
|
{{=$valid}} = false;
|
||||||
|
{{=$passingSchemas}} = [{{=$passingSchemas}}, {{=$i}}];
|
||||||
|
} else {
|
||||||
|
{{ $closingBraces += '}'; }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
if ({{=$nextValid}}) {
|
||||||
|
{{=$valid}} = {{=$prevValid}} = true;
|
||||||
|
{{=$passingSchemas}} = {{=$i}};
|
||||||
|
}
|
||||||
|
{{~}}
|
||||||
|
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
|
||||||
|
{{= $closingBraces }}
|
||||||
|
|
||||||
|
if (!{{=$valid}}) {
|
||||||
|
{{# def.extraError:'oneOf' }}
|
||||||
|
} else {
|
||||||
|
{{# def.resetErrors }}
|
||||||
|
{{? it.opts.allErrors }} } {{?}}
|
||||||
14
node_sid/node_modules/ajv/lib/dot/pattern.jst
generated
vendored
Normal file
14
node_sid/node_modules/ajv/lib/dot/pattern.jst
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $regexp = $isData
|
||||||
|
? '(new RegExp(' + $schemaValue + '))'
|
||||||
|
: it.usePattern($schema);
|
||||||
|
}}
|
||||||
|
|
||||||
|
if ({{# def.$dataNotType:'string' }} !{{=$regexp}}.test({{=$data}}) ) {
|
||||||
|
{{# def.error:'pattern' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
245
node_sid/node_modules/ajv/lib/dot/properties.jst
generated
vendored
Normal file
245
node_sid/node_modules/ajv/lib/dot/properties.jst
generated
vendored
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.validateAdditional:
|
||||||
|
{{ /* additionalProperties is schema */
|
||||||
|
$it.schema = $aProperties;
|
||||||
|
$it.schemaPath = it.schemaPath + '.additionalProperties';
|
||||||
|
$it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
|
||||||
|
$it.errorPath = it.opts._errorDataPathProperty
|
||||||
|
? it.errorPath
|
||||||
|
: it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
|
||||||
|
var $passData = $data + '[' + $key + ']';
|
||||||
|
$it.dataPathArr[$dataNxt] = $key;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
{{# def.optimizeValidate }}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $key = 'key' + $lvl
|
||||||
|
, $idx = 'idx' + $lvl
|
||||||
|
, $dataNxt = $it.dataLevel = it.dataLevel + 1
|
||||||
|
, $nextData = 'data' + $dataNxt
|
||||||
|
, $dataProperties = 'dataProperties' + $lvl;
|
||||||
|
|
||||||
|
var $schemaKeys = Object.keys($schema || {}).filter(notProto)
|
||||||
|
, $pProperties = it.schema.patternProperties || {}
|
||||||
|
, $pPropertyKeys = Object.keys($pProperties).filter(notProto)
|
||||||
|
, $aProperties = it.schema.additionalProperties
|
||||||
|
, $someProperties = $schemaKeys.length || $pPropertyKeys.length
|
||||||
|
, $noAdditional = $aProperties === false
|
||||||
|
, $additionalIsSchema = typeof $aProperties == 'object'
|
||||||
|
&& Object.keys($aProperties).length
|
||||||
|
, $removeAdditional = it.opts.removeAdditional
|
||||||
|
, $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional
|
||||||
|
, $ownProperties = it.opts.ownProperties
|
||||||
|
, $currentBaseId = it.baseId;
|
||||||
|
|
||||||
|
var $required = it.schema.required;
|
||||||
|
if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
|
||||||
|
var $requiredHash = it.util.toHash($required);
|
||||||
|
}
|
||||||
|
|
||||||
|
function notProto(p) { return p !== '__proto__'; }
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
var {{=$nextValid}} = true;
|
||||||
|
{{? $ownProperties }}
|
||||||
|
var {{=$dataProperties}} = undefined;
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $checkAdditional }}
|
||||||
|
{{# def.iterateProperties }}
|
||||||
|
{{? $someProperties }}
|
||||||
|
var isAdditional{{=$lvl}} = !(false
|
||||||
|
{{? $schemaKeys.length }}
|
||||||
|
{{? $schemaKeys.length > 8 }}
|
||||||
|
|| validate.schema{{=$schemaPath}}.hasOwnProperty({{=$key}})
|
||||||
|
{{??}}
|
||||||
|
{{~ $schemaKeys:$propertyKey }}
|
||||||
|
|| {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{? $pPropertyKeys.length }}
|
||||||
|
{{~ $pPropertyKeys:$pProperty:$i }}
|
||||||
|
|| {{= it.usePattern($pProperty) }}.test({{=$key}})
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isAdditional{{=$lvl}}) {
|
||||||
|
{{?}}
|
||||||
|
{{? $removeAdditional == 'all' }}
|
||||||
|
delete {{=$data}}[{{=$key}}];
|
||||||
|
{{??}}
|
||||||
|
{{
|
||||||
|
var $currentErrorPath = it.errorPath;
|
||||||
|
var $additionalProperty = '\' + ' + $key + ' + \'';
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{? $noAdditional }}
|
||||||
|
{{? $removeAdditional }}
|
||||||
|
delete {{=$data}}[{{=$key}}];
|
||||||
|
{{??}}
|
||||||
|
{{=$nextValid}} = false;
|
||||||
|
{{
|
||||||
|
var $currErrSchemaPath = $errSchemaPath;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/additionalProperties';
|
||||||
|
}}
|
||||||
|
{{# def.error:'additionalProperties' }}
|
||||||
|
{{ $errSchemaPath = $currErrSchemaPath; }}
|
||||||
|
{{? $breakOnError }} break; {{?}}
|
||||||
|
{{?}}
|
||||||
|
{{?? $additionalIsSchema }}
|
||||||
|
{{? $removeAdditional == 'failing' }}
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
|
||||||
|
{{# def.validateAdditional }}
|
||||||
|
|
||||||
|
if (!{{=$nextValid}}) {
|
||||||
|
errors = {{=$errs}};
|
||||||
|
if (validate.errors !== null) {
|
||||||
|
if (errors) validate.errors.length = errors;
|
||||||
|
else validate.errors = null;
|
||||||
|
}
|
||||||
|
delete {{=$data}}[{{=$key}}];
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
{{??}}
|
||||||
|
{{# def.validateAdditional }}
|
||||||
|
{{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{ it.errorPath = $currentErrorPath; }}
|
||||||
|
{{?}}
|
||||||
|
{{? $someProperties }}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
|
||||||
|
|
||||||
|
{{? $schemaKeys.length }}
|
||||||
|
{{~ $schemaKeys:$propertyKey }}
|
||||||
|
{{ var $sch = $schema[$propertyKey]; }}
|
||||||
|
|
||||||
|
{{? {{# def.nonEmptySchema:$sch}} }}
|
||||||
|
{{
|
||||||
|
var $prop = it.util.getProperty($propertyKey)
|
||||||
|
, $passData = $data + $prop
|
||||||
|
, $hasDefault = $useDefaults && $sch.default !== undefined;
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + $prop;
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
|
||||||
|
$it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
|
||||||
|
$it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
|
||||||
|
{{? {{# def.willOptimize }} }}
|
||||||
|
{{
|
||||||
|
$code = {{# def._optimizeValidate }};
|
||||||
|
var $useData = $passData;
|
||||||
|
}}
|
||||||
|
{{??}}
|
||||||
|
{{ var $useData = $nextData; }}
|
||||||
|
var {{=$nextData}} = {{=$passData}};
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $hasDefault }}
|
||||||
|
{{= $code }}
|
||||||
|
{{??}}
|
||||||
|
{{? $requiredHash && $requiredHash[$propertyKey] }}
|
||||||
|
if ({{# def.noPropertyInData }}) {
|
||||||
|
{{=$nextValid}} = false;
|
||||||
|
{{
|
||||||
|
var $currentErrorPath = it.errorPath
|
||||||
|
, $currErrSchemaPath = $errSchemaPath
|
||||||
|
, $missingProperty = it.util.escapeQuotes($propertyKey);
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
||||||
|
}
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/required';
|
||||||
|
}}
|
||||||
|
{{# def.error:'required' }}
|
||||||
|
{{ $errSchemaPath = $currErrSchemaPath; }}
|
||||||
|
{{ it.errorPath = $currentErrorPath; }}
|
||||||
|
} else {
|
||||||
|
{{??}}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if ({{# def.noPropertyInData }}) {
|
||||||
|
{{=$nextValid}} = true;
|
||||||
|
} else {
|
||||||
|
{{??}}
|
||||||
|
if ({{=$useData}} !== undefined
|
||||||
|
{{? $ownProperties }}
|
||||||
|
&& {{# def.isOwnProperty }}
|
||||||
|
{{?}}
|
||||||
|
) {
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{= $code }}
|
||||||
|
}
|
||||||
|
{{?}} {{ /* $hasDefault */ }}
|
||||||
|
{{?}} {{ /* def.nonEmptySchema */ }}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $pPropertyKeys.length }}
|
||||||
|
{{~ $pPropertyKeys:$pProperty }}
|
||||||
|
{{ var $sch = $pProperties[$pProperty]; }}
|
||||||
|
|
||||||
|
{{? {{# def.nonEmptySchema:$sch}} }}
|
||||||
|
{{
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
|
||||||
|
$it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
|
||||||
|
+ it.util.escapeFragment($pProperty);
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.iterateProperties }}
|
||||||
|
if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
|
||||||
|
{{
|
||||||
|
$it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
|
||||||
|
var $passData = $data + '[' + $key + ']';
|
||||||
|
$it.dataPathArr[$dataNxt] = $key;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
{{# def.optimizeValidate }}
|
||||||
|
|
||||||
|
{{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
|
||||||
|
}
|
||||||
|
{{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{# def.ifResultValid }}
|
||||||
|
{{?}} {{ /* def.nonEmptySchema */ }}
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{= $closingBraces }}
|
||||||
|
if ({{=$errs}} == errors) {
|
||||||
|
{{?}}
|
||||||
52
node_sid/node_modules/ajv/lib/dot/propertyNames.jst
generated
vendored
Normal file
52
node_sid/node_modules/ajv/lib/dot/propertyNames.jst
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
|
||||||
|
var {{=$errs}} = errors;
|
||||||
|
|
||||||
|
{{? {{# def.nonEmptySchema:$schema }} }}
|
||||||
|
{{
|
||||||
|
$it.schema = $schema;
|
||||||
|
$it.schemaPath = $schemaPath;
|
||||||
|
$it.errSchemaPath = $errSchemaPath;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $key = 'key' + $lvl
|
||||||
|
, $idx = 'idx' + $lvl
|
||||||
|
, $i = 'i' + $lvl
|
||||||
|
, $invalidName = '\' + ' + $key + ' + \''
|
||||||
|
, $dataNxt = $it.dataLevel = it.dataLevel + 1
|
||||||
|
, $nextData = 'data' + $dataNxt
|
||||||
|
, $dataProperties = 'dataProperties' + $lvl
|
||||||
|
, $ownProperties = it.opts.ownProperties
|
||||||
|
, $currentBaseId = it.baseId;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $ownProperties }}
|
||||||
|
var {{=$dataProperties}} = undefined;
|
||||||
|
{{?}}
|
||||||
|
{{# def.iterateProperties }}
|
||||||
|
var startErrs{{=$lvl}} = errors;
|
||||||
|
|
||||||
|
{{ var $passData = $key; }}
|
||||||
|
{{# def.setCompositeRule }}
|
||||||
|
{{# def.generateSubschemaCode }}
|
||||||
|
{{# def.optimizeValidate }}
|
||||||
|
{{# def.resetCompositeRule }}
|
||||||
|
|
||||||
|
if (!{{=$nextValid}}) {
|
||||||
|
for (var {{=$i}}=startErrs{{=$lvl}}; {{=$i}}<errors; {{=$i}}++) {
|
||||||
|
vErrors[{{=$i}}].propertyName = {{=$key}};
|
||||||
|
}
|
||||||
|
{{# def.extraError:'propertyNames' }}
|
||||||
|
{{? $breakOnError }} break; {{?}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{= $closingBraces }}
|
||||||
|
if ({{=$errs}} == errors) {
|
||||||
|
{{?}}
|
||||||
85
node_sid/node_modules/ajv/lib/dot/ref.jst
generated
vendored
Normal file
85
node_sid/node_modules/ajv/lib/dot/ref.jst
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
|
||||||
|
{{## def._validateRef:_v:
|
||||||
|
{{? it.opts.passContext }}
|
||||||
|
{{=_v}}.call(this,
|
||||||
|
{{??}}
|
||||||
|
{{=_v}}(
|
||||||
|
{{?}}
|
||||||
|
{{=$data}}, {{# def.dataPath }}{{# def.passParentData }}, rootData)
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{ var $async, $refCode; }}
|
||||||
|
{{? $schema == '#' || $schema == '#/' }}
|
||||||
|
{{
|
||||||
|
if (it.isRoot) {
|
||||||
|
$async = it.async;
|
||||||
|
$refCode = 'validate';
|
||||||
|
} else {
|
||||||
|
$async = it.root.schema.$async === true;
|
||||||
|
$refCode = 'root.refVal[0]';
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
{{??}}
|
||||||
|
{{ var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); }}
|
||||||
|
{{? $refVal === undefined }}
|
||||||
|
{{ var $message = it.MissingRefError.message(it.baseId, $schema); }}
|
||||||
|
{{? it.opts.missingRefs == 'fail' }}
|
||||||
|
{{ it.logger.error($message); }}
|
||||||
|
{{# def.error:'$ref' }}
|
||||||
|
{{? $breakOnError }} if (false) { {{?}}
|
||||||
|
{{?? it.opts.missingRefs == 'ignore' }}
|
||||||
|
{{ it.logger.warn($message); }}
|
||||||
|
{{? $breakOnError }} if (true) { {{?}}
|
||||||
|
{{??}}
|
||||||
|
{{ throw new it.MissingRefError(it.baseId, $schema, $message); }}
|
||||||
|
{{?}}
|
||||||
|
{{?? $refVal.inline }}
|
||||||
|
{{# def.setupNextLevel }}
|
||||||
|
{{
|
||||||
|
$it.schema = $refVal.schema;
|
||||||
|
$it.schemaPath = '';
|
||||||
|
$it.errSchemaPath = $schema;
|
||||||
|
}}
|
||||||
|
{{ var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); }}
|
||||||
|
{{= $code }}
|
||||||
|
{{? $breakOnError}}
|
||||||
|
if ({{=$nextValid}}) {
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
{{
|
||||||
|
$async = $refVal.$async === true || (it.async && $refVal.$async !== false);
|
||||||
|
$refCode = $refVal.code;
|
||||||
|
}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $refCode }}
|
||||||
|
{{# def.beginDefOut}}
|
||||||
|
{{# def._validateRef:$refCode }}
|
||||||
|
{{# def.storeDefOut:__callValidate }}
|
||||||
|
|
||||||
|
{{? $async }}
|
||||||
|
{{ if (!it.async) throw new Error('async schema referenced by sync schema'); }}
|
||||||
|
{{? $breakOnError }} var {{=$valid}}; {{?}}
|
||||||
|
try {
|
||||||
|
await {{=__callValidate}};
|
||||||
|
{{? $breakOnError }} {{=$valid}} = true; {{?}}
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof ValidationError)) throw e;
|
||||||
|
if (vErrors === null) vErrors = e.errors;
|
||||||
|
else vErrors = vErrors.concat(e.errors);
|
||||||
|
errors = vErrors.length;
|
||||||
|
{{? $breakOnError }} {{=$valid}} = false; {{?}}
|
||||||
|
}
|
||||||
|
{{? $breakOnError }} if ({{=$valid}}) { {{?}}
|
||||||
|
{{??}}
|
||||||
|
if (!{{=__callValidate}}) {
|
||||||
|
if (vErrors === null) vErrors = {{=$refCode}}.errors;
|
||||||
|
else vErrors = vErrors.concat({{=$refCode}}.errors);
|
||||||
|
errors = vErrors.length;
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
108
node_sid/node_modules/ajv/lib/dot/required.jst
generated
vendored
Normal file
108
node_sid/node_modules/ajv/lib/dot/required.jst
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.missing }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
{{ var $vSchema = 'schema' + $lvl; }}
|
||||||
|
|
||||||
|
{{## def.setupLoop:
|
||||||
|
{{? !$isData }}
|
||||||
|
var {{=$vSchema}} = validate.schema{{=$schemaPath}};
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $i = 'i' + $lvl
|
||||||
|
, $propertyPath = 'schema' + $lvl + '[' + $i + ']'
|
||||||
|
, $missingProperty = '\' + ' + $propertyPath + ' + \'';
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{## def.isRequiredOwnProperty:
|
||||||
|
Object.prototype.hasOwnProperty.call({{=$data}}, {{=$vSchema}}[{{=$i}}])
|
||||||
|
#}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? !$isData }}
|
||||||
|
{{? $schema.length < it.opts.loopRequired &&
|
||||||
|
it.schema.properties && Object.keys(it.schema.properties).length }}
|
||||||
|
{{ var $required = []; }}
|
||||||
|
{{~ $schema:$property }}
|
||||||
|
{{ var $propertySch = it.schema.properties[$property]; }}
|
||||||
|
{{? !($propertySch && {{# def.nonEmptySchema:$propertySch}}) }}
|
||||||
|
{{ $required[$required.length] = $property; }}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
{{??}}
|
||||||
|
{{ var $required = $schema; }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? $isData || $required.length }}
|
||||||
|
{{
|
||||||
|
var $currentErrorPath = it.errorPath
|
||||||
|
, $loopRequired = $isData || $required.length >= it.opts.loopRequired
|
||||||
|
, $ownProperties = it.opts.ownProperties;
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
var missing{{=$lvl}};
|
||||||
|
{{? $loopRequired }}
|
||||||
|
{{# def.setupLoop }}
|
||||||
|
var {{=$valid}} = true;
|
||||||
|
|
||||||
|
{{?$isData}}{{# def.check$dataIsArray }}{{?}}
|
||||||
|
|
||||||
|
for (var {{=$i}} = 0; {{=$i}} < {{=$vSchema}}.length; {{=$i}}++) {
|
||||||
|
{{=$valid}} = {{=$data}}[{{=$vSchema}}[{{=$i}}]] !== undefined
|
||||||
|
{{? $ownProperties }}
|
||||||
|
&& {{# def.isRequiredOwnProperty }}
|
||||||
|
{{?}};
|
||||||
|
if (!{{=$valid}}) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
{{? $isData }} } {{?}}
|
||||||
|
|
||||||
|
{{# def.checkError:'required' }}
|
||||||
|
else {
|
||||||
|
{{??}}
|
||||||
|
if ({{# def.checkMissingProperty:$required }}) {
|
||||||
|
{{# def.errorMissingProperty:'required' }}
|
||||||
|
} else {
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
{{? $loopRequired }}
|
||||||
|
{{# def.setupLoop }}
|
||||||
|
{{? $isData }}
|
||||||
|
if ({{=$vSchema}} && !Array.isArray({{=$vSchema}})) {
|
||||||
|
{{# def.addError:'required' }}
|
||||||
|
} else if ({{=$vSchema}} !== undefined) {
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
for (var {{=$i}} = 0; {{=$i}} < {{=$vSchema}}.length; {{=$i}}++) {
|
||||||
|
if ({{=$data}}[{{=$vSchema}}[{{=$i}}]] === undefined
|
||||||
|
{{? $ownProperties }}
|
||||||
|
|| !{{# def.isRequiredOwnProperty }}
|
||||||
|
{{?}}) {
|
||||||
|
{{# def.addError:'required' }}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{? $isData }} } {{?}}
|
||||||
|
{{??}}
|
||||||
|
{{~ $required:$propertyKey }}
|
||||||
|
{{# def.allErrorsMissingProperty:'required' }}
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{ it.errorPath = $currentErrorPath; }}
|
||||||
|
|
||||||
|
{{?? $breakOnError }}
|
||||||
|
if (true) {
|
||||||
|
{{?}}
|
||||||
62
node_sid/node_modules/ajv/lib/dot/uniqueItems.jst
generated
vendored
Normal file
62
node_sid/node_modules/ajv/lib/dot/uniqueItems.jst
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{# def.$data }}
|
||||||
|
|
||||||
|
|
||||||
|
{{? ($schema || $isData) && it.opts.uniqueItems !== false }}
|
||||||
|
{{? $isData }}
|
||||||
|
var {{=$valid}};
|
||||||
|
if ({{=$schemaValue}} === false || {{=$schemaValue}} === undefined)
|
||||||
|
{{=$valid}} = true;
|
||||||
|
else if (typeof {{=$schemaValue}} != 'boolean')
|
||||||
|
{{=$valid}} = false;
|
||||||
|
else {
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
var i = {{=$data}}.length
|
||||||
|
, {{=$valid}} = true
|
||||||
|
, j;
|
||||||
|
if (i > 1) {
|
||||||
|
{{
|
||||||
|
var $itemType = it.schema.items && it.schema.items.type
|
||||||
|
, $typeIsArray = Array.isArray($itemType);
|
||||||
|
}}
|
||||||
|
{{? !$itemType || $itemType == 'object' || $itemType == 'array' ||
|
||||||
|
($typeIsArray && ($itemType.indexOf('object') >= 0 || $itemType.indexOf('array') >= 0)) }}
|
||||||
|
outer:
|
||||||
|
for (;i--;) {
|
||||||
|
for (j = i; j--;) {
|
||||||
|
if (equal({{=$data}}[i], {{=$data}}[j])) {
|
||||||
|
{{=$valid}} = false;
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{{??}}
|
||||||
|
var itemIndices = {}, item;
|
||||||
|
for (;i--;) {
|
||||||
|
var item = {{=$data}}[i];
|
||||||
|
{{ var $method = 'checkDataType' + ($typeIsArray ? 's' : ''); }}
|
||||||
|
if ({{= it.util[$method]($itemType, 'item', it.opts.strictNumbers, true) }}) continue;
|
||||||
|
{{? $typeIsArray}}
|
||||||
|
if (typeof item == 'string') item = '"' + item;
|
||||||
|
{{?}}
|
||||||
|
if (typeof itemIndices[item] == 'number') {
|
||||||
|
{{=$valid}} = false;
|
||||||
|
j = itemIndices[item];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
itemIndices[item] = i;
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{? $isData }} } {{?}}
|
||||||
|
|
||||||
|
if (!{{=$valid}}) {
|
||||||
|
{{# def.error:'uniqueItems' }}
|
||||||
|
} {{? $breakOnError }} else { {{?}}
|
||||||
|
{{??}}
|
||||||
|
{{? $breakOnError }} if (true) { {{?}}
|
||||||
|
{{?}}
|
||||||
276
node_sid/node_modules/ajv/lib/dot/validate.jst
generated
vendored
Normal file
276
node_sid/node_modules/ajv/lib/dot/validate.jst
generated
vendored
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
{{# def.definitions }}
|
||||||
|
{{# def.errors }}
|
||||||
|
{{# def.defaults }}
|
||||||
|
{{# def.coerce }}
|
||||||
|
|
||||||
|
{{ /**
|
||||||
|
* schema compilation (render) time:
|
||||||
|
* it = { schema, RULES, _validate, opts }
|
||||||
|
* it.validate - this template function,
|
||||||
|
* it is used recursively to generate code for subschemas
|
||||||
|
*
|
||||||
|
* runtime:
|
||||||
|
* "validate" is a variable name to which this function will be assigned
|
||||||
|
* validateRef etc. are defined in the parent scope in index.js
|
||||||
|
*/ }}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $async = it.schema.$async === true
|
||||||
|
, $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref')
|
||||||
|
, $id = it.self._getId(it.schema);
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
if (it.opts.strictKeywords) {
|
||||||
|
var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords);
|
||||||
|
if ($unknownKwd) {
|
||||||
|
var $keywordsMsg = 'unknown keyword: ' + $unknownKwd;
|
||||||
|
if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg);
|
||||||
|
else throw new Error($keywordsMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{? it.isTop }}
|
||||||
|
var validate = {{?$async}}{{it.async = true;}}async {{?}}function(data, dataPath, parentData, parentDataProperty, rootData) {
|
||||||
|
'use strict';
|
||||||
|
{{? $id && (it.opts.sourceCode || it.opts.processCode) }}
|
||||||
|
{{= '/\*# sourceURL=' + $id + ' */' }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref) }}
|
||||||
|
{{ var $keyword = 'false schema'; }}
|
||||||
|
{{# def.setupKeyword }}
|
||||||
|
{{? it.schema === false}}
|
||||||
|
{{? it.isTop}}
|
||||||
|
{{ $breakOnError = true; }}
|
||||||
|
{{??}}
|
||||||
|
var {{=$valid}} = false;
|
||||||
|
{{?}}
|
||||||
|
{{# def.error:'false schema' }}
|
||||||
|
{{??}}
|
||||||
|
{{? it.isTop}}
|
||||||
|
{{? $async }}
|
||||||
|
return data;
|
||||||
|
{{??}}
|
||||||
|
validate.errors = null;
|
||||||
|
return true;
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
var {{=$valid}} = true;
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? it.isTop}}
|
||||||
|
};
|
||||||
|
return validate;
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{ return out; }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? it.isTop }}
|
||||||
|
{{
|
||||||
|
var $top = it.isTop
|
||||||
|
, $lvl = it.level = 0
|
||||||
|
, $dataLvl = it.dataLevel = 0
|
||||||
|
, $data = 'data';
|
||||||
|
it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
|
||||||
|
it.baseId = it.baseId || it.rootId;
|
||||||
|
delete it.isTop;
|
||||||
|
|
||||||
|
it.dataPathArr = [""];
|
||||||
|
|
||||||
|
if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) {
|
||||||
|
var $defaultMsg = 'default is ignored in the schema root';
|
||||||
|
if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg);
|
||||||
|
else throw new Error($defaultMsg);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
var vErrors = null; {{ /* don't edit, used in replace */ }}
|
||||||
|
var errors = 0; {{ /* don't edit, used in replace */ }}
|
||||||
|
if (rootData === undefined) rootData = data; {{ /* don't edit, used in replace */ }}
|
||||||
|
{{??}}
|
||||||
|
{{
|
||||||
|
var $lvl = it.level
|
||||||
|
, $dataLvl = it.dataLevel
|
||||||
|
, $data = 'data' + ($dataLvl || '');
|
||||||
|
|
||||||
|
if ($id) it.baseId = it.resolve.url(it.baseId, $id);
|
||||||
|
|
||||||
|
if ($async && !it.async) throw new Error('async schema in sync schema');
|
||||||
|
}}
|
||||||
|
|
||||||
|
var errs_{{=$lvl}} = errors;
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
var $valid = 'valid' + $lvl
|
||||||
|
, $breakOnError = !it.opts.allErrors
|
||||||
|
, $closingBraces1 = ''
|
||||||
|
, $closingBraces2 = '';
|
||||||
|
|
||||||
|
var $errorKeyword;
|
||||||
|
var $typeSchema = it.schema.type
|
||||||
|
, $typeIsArray = Array.isArray($typeSchema);
|
||||||
|
|
||||||
|
if ($typeSchema && it.opts.nullable && it.schema.nullable === true) {
|
||||||
|
if ($typeIsArray) {
|
||||||
|
if ($typeSchema.indexOf('null') == -1)
|
||||||
|
$typeSchema = $typeSchema.concat('null');
|
||||||
|
} else if ($typeSchema != 'null') {
|
||||||
|
$typeSchema = [$typeSchema, 'null'];
|
||||||
|
$typeIsArray = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($typeIsArray && $typeSchema.length == 1) {
|
||||||
|
$typeSchema = $typeSchema[0];
|
||||||
|
$typeIsArray = false;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{## def.checkType:
|
||||||
|
{{
|
||||||
|
var $schemaPath = it.schemaPath + '.type'
|
||||||
|
, $errSchemaPath = it.errSchemaPath + '/type'
|
||||||
|
, $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
|
||||||
|
}}
|
||||||
|
|
||||||
|
if ({{= it.util[$method]($typeSchema, $data, it.opts.strictNumbers, true) }}) {
|
||||||
|
#}}
|
||||||
|
|
||||||
|
{{? it.schema.$ref && $refKeywords }}
|
||||||
|
{{? it.opts.extendRefs == 'fail' }}
|
||||||
|
{{ throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)'); }}
|
||||||
|
{{?? it.opts.extendRefs !== true }}
|
||||||
|
{{
|
||||||
|
$refKeywords = false;
|
||||||
|
it.logger.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
|
||||||
|
}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? it.schema.$comment && it.opts.$comment }}
|
||||||
|
{{= it.RULES.all.$comment.code(it, '$comment') }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $typeSchema }}
|
||||||
|
{{? it.opts.coerceTypes }}
|
||||||
|
{{ var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema); }}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{ var $rulesGroup = it.RULES.types[$typeSchema]; }}
|
||||||
|
{{? $coerceToTypes || $typeIsArray || $rulesGroup === true ||
|
||||||
|
($rulesGroup && !$shouldUseGroup($rulesGroup)) }}
|
||||||
|
{{
|
||||||
|
var $schemaPath = it.schemaPath + '.type'
|
||||||
|
, $errSchemaPath = it.errSchemaPath + '/type';
|
||||||
|
}}
|
||||||
|
{{# def.checkType }}
|
||||||
|
{{? $coerceToTypes }}
|
||||||
|
{{# def.coerceType }}
|
||||||
|
{{??}}
|
||||||
|
{{# def.error:'type' }}
|
||||||
|
{{?}}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
|
||||||
|
{{? it.schema.$ref && !$refKeywords }}
|
||||||
|
{{= it.RULES.all.$ref.code(it, '$ref') }}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
}
|
||||||
|
if (errors === {{?$top}}0{{??}}errs_{{=$lvl}}{{?}}) {
|
||||||
|
{{ $closingBraces2 += '}'; }}
|
||||||
|
{{?}}
|
||||||
|
{{??}}
|
||||||
|
{{~ it.RULES:$rulesGroup }}
|
||||||
|
{{? $shouldUseGroup($rulesGroup) }}
|
||||||
|
{{? $rulesGroup.type }}
|
||||||
|
if ({{= it.util.checkDataType($rulesGroup.type, $data, it.opts.strictNumbers) }}) {
|
||||||
|
{{?}}
|
||||||
|
{{? it.opts.useDefaults }}
|
||||||
|
{{? $rulesGroup.type == 'object' && it.schema.properties }}
|
||||||
|
{{# def.defaultProperties }}
|
||||||
|
{{?? $rulesGroup.type == 'array' && Array.isArray(it.schema.items) }}
|
||||||
|
{{# def.defaultItems }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{~ $rulesGroup.rules:$rule }}
|
||||||
|
{{? $shouldUseRule($rule) }}
|
||||||
|
{{ var $code = $rule.code(it, $rule.keyword, $rulesGroup.type); }}
|
||||||
|
{{? $code }}
|
||||||
|
{{= $code }}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{ $closingBraces1 += '}'; }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
{{? $breakOnError }}
|
||||||
|
{{= $closingBraces1 }}
|
||||||
|
{{ $closingBraces1 = ''; }}
|
||||||
|
{{?}}
|
||||||
|
{{? $rulesGroup.type }}
|
||||||
|
}
|
||||||
|
{{? $typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes }}
|
||||||
|
else {
|
||||||
|
{{
|
||||||
|
var $schemaPath = it.schemaPath + '.type'
|
||||||
|
, $errSchemaPath = it.errSchemaPath + '/type';
|
||||||
|
}}
|
||||||
|
{{# def.error:'type' }}
|
||||||
|
}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $breakOnError }}
|
||||||
|
if (errors === {{?$top}}0{{??}}errs_{{=$lvl}}{{?}}) {
|
||||||
|
{{ $closingBraces2 += '}'; }}
|
||||||
|
{{?}}
|
||||||
|
{{?}}
|
||||||
|
{{~}}
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{? $breakOnError }} {{= $closingBraces2 }} {{?}}
|
||||||
|
|
||||||
|
{{? $top }}
|
||||||
|
{{? $async }}
|
||||||
|
if (errors === 0) return data; {{ /* don't edit, used in replace */ }}
|
||||||
|
else throw new ValidationError(vErrors); {{ /* don't edit, used in replace */ }}
|
||||||
|
{{??}}
|
||||||
|
validate.errors = vErrors; {{ /* don't edit, used in replace */ }}
|
||||||
|
return errors === 0; {{ /* don't edit, used in replace */ }}
|
||||||
|
{{?}}
|
||||||
|
};
|
||||||
|
|
||||||
|
return validate;
|
||||||
|
{{??}}
|
||||||
|
var {{=$valid}} = errors === errs_{{=$lvl}};
|
||||||
|
{{?}}
|
||||||
|
|
||||||
|
{{
|
||||||
|
function $shouldUseGroup($rulesGroup) {
|
||||||
|
var rules = $rulesGroup.rules;
|
||||||
|
for (var i=0; i < rules.length; i++)
|
||||||
|
if ($shouldUseRule(rules[i]))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function $shouldUseRule($rule) {
|
||||||
|
return it.schema[$rule.keyword] !== undefined ||
|
||||||
|
($rule.implements && $ruleImplementsSomeKeyword($rule));
|
||||||
|
}
|
||||||
|
|
||||||
|
function $ruleImplementsSomeKeyword($rule) {
|
||||||
|
var impl = $rule.implements;
|
||||||
|
for (var i=0; i < impl.length; i++)
|
||||||
|
if (it.schema[impl[i]] !== undefined)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}}
|
||||||
3
node_sid/node_modules/ajv/lib/dotjs/README.md
generated
vendored
Normal file
3
node_sid/node_modules/ajv/lib/dotjs/README.md
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
These files are compiled dot templates from dot folder.
|
||||||
|
|
||||||
|
Do NOT edit them directly, edit the templates and run `npm run build` from main ajv folder.
|
||||||
163
node_sid/node_modules/ajv/lib/dotjs/_limit.js
generated
vendored
Normal file
163
node_sid/node_modules/ajv/lib/dotjs/_limit.js
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate__limit(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $errorKeyword;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
var $isMax = $keyword == 'maximum',
|
||||||
|
$exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
|
||||||
|
$schemaExcl = it.schema[$exclusiveKeyword],
|
||||||
|
$isDataExcl = it.opts.$data && $schemaExcl && $schemaExcl.$data,
|
||||||
|
$op = $isMax ? '<' : '>',
|
||||||
|
$notOp = $isMax ? '>' : '<',
|
||||||
|
$errorKeyword = undefined;
|
||||||
|
if (!($isData || typeof $schema == 'number' || $schema === undefined)) {
|
||||||
|
throw new Error($keyword + ' must be number');
|
||||||
|
}
|
||||||
|
if (!($isDataExcl || $schemaExcl === undefined || typeof $schemaExcl == 'number' || typeof $schemaExcl == 'boolean')) {
|
||||||
|
throw new Error($exclusiveKeyword + ' must be number or boolean');
|
||||||
|
}
|
||||||
|
if ($isDataExcl) {
|
||||||
|
var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
|
||||||
|
$exclusive = 'exclusive' + $lvl,
|
||||||
|
$exclType = 'exclType' + $lvl,
|
||||||
|
$exclIsNumber = 'exclIsNumber' + $lvl,
|
||||||
|
$opExpr = 'op' + $lvl,
|
||||||
|
$opStr = '\' + ' + $opExpr + ' + \'';
|
||||||
|
out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
|
||||||
|
$schemaValueExcl = 'schemaExcl' + $lvl;
|
||||||
|
out += ' var ' + ($exclusive) + '; var ' + ($exclType) + ' = typeof ' + ($schemaValueExcl) + '; if (' + ($exclType) + ' != \'boolean\' && ' + ($exclType) + ' != \'undefined\' && ' + ($exclType) + ' != \'number\') { ';
|
||||||
|
var $errorKeyword = $exclusiveKeyword;
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += ' } else if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||||
|
}
|
||||||
|
out += ' ' + ($exclType) + ' == \'number\' ? ( (' + ($exclusive) + ' = ' + ($schemaValue) + ' === undefined || ' + ($schemaValueExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ') ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValueExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) : ( (' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\'; ';
|
||||||
|
if ($schema === undefined) {
|
||||||
|
$errorKeyword = $exclusiveKeyword;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
||||||
|
$schemaValue = $schemaValueExcl;
|
||||||
|
$isData = $isDataExcl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var $exclIsNumber = typeof $schemaExcl == 'number',
|
||||||
|
$opStr = $op;
|
||||||
|
if ($exclIsNumber && $isData) {
|
||||||
|
var $opExpr = '\'' + $opStr + '\'';
|
||||||
|
out += ' if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||||
|
}
|
||||||
|
out += ' ( ' + ($schemaValue) + ' === undefined || ' + ($schemaExcl) + ' ' + ($op) + '= ' + ($schemaValue) + ' ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaExcl) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' ) || ' + ($data) + ' !== ' + ($data) + ') { ';
|
||||||
|
} else {
|
||||||
|
if ($exclIsNumber && $schema === undefined) {
|
||||||
|
$exclusive = true;
|
||||||
|
$errorKeyword = $exclusiveKeyword;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
||||||
|
$schemaValue = $schemaExcl;
|
||||||
|
$notOp += '=';
|
||||||
|
} else {
|
||||||
|
if ($exclIsNumber) $schemaValue = Math[$isMax ? 'min' : 'max']($schemaExcl, $schema);
|
||||||
|
if ($schemaExcl === ($exclIsNumber ? $schemaValue : true)) {
|
||||||
|
$exclusive = true;
|
||||||
|
$errorKeyword = $exclusiveKeyword;
|
||||||
|
$errSchemaPath = it.errSchemaPath + '/' + $exclusiveKeyword;
|
||||||
|
$notOp += '=';
|
||||||
|
} else {
|
||||||
|
$exclusive = false;
|
||||||
|
$opStr += '=';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var $opExpr = '\'' + $opStr + '\'';
|
||||||
|
out += ' if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||||
|
}
|
||||||
|
out += ' ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') { ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$errorKeyword = $errorKeyword || $keyword;
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should be ' + ($opStr) + ' ';
|
||||||
|
if ($isData) {
|
||||||
|
out += '\' + ' + ($schemaValue);
|
||||||
|
} else {
|
||||||
|
out += '' + ($schemaValue) + '\'';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: ';
|
||||||
|
if ($isData) {
|
||||||
|
out += 'validate.schema' + ($schemaPath);
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
80
node_sid/node_modules/ajv/lib/dotjs/_limitItems.js
generated
vendored
Normal file
80
node_sid/node_modules/ajv/lib/dotjs/_limitItems.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate__limitItems(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $errorKeyword;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
if (!($isData || typeof $schema == 'number')) {
|
||||||
|
throw new Error($keyword + ' must be number');
|
||||||
|
}
|
||||||
|
var $op = $keyword == 'maxItems' ? '>' : '<';
|
||||||
|
out += 'if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||||
|
}
|
||||||
|
out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
|
||||||
|
var $errorKeyword = $keyword;
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should NOT have ';
|
||||||
|
if ($keyword == 'maxItems') {
|
||||||
|
out += 'more';
|
||||||
|
} else {
|
||||||
|
out += 'fewer';
|
||||||
|
}
|
||||||
|
out += ' than ';
|
||||||
|
if ($isData) {
|
||||||
|
out += '\' + ' + ($schemaValue) + ' + \'';
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' items\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: ';
|
||||||
|
if ($isData) {
|
||||||
|
out += 'validate.schema' + ($schemaPath);
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += '} ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
85
node_sid/node_modules/ajv/lib/dotjs/_limitLength.js
generated
vendored
Normal file
85
node_sid/node_modules/ajv/lib/dotjs/_limitLength.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate__limitLength(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $errorKeyword;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
if (!($isData || typeof $schema == 'number')) {
|
||||||
|
throw new Error($keyword + ' must be number');
|
||||||
|
}
|
||||||
|
var $op = $keyword == 'maxLength' ? '>' : '<';
|
||||||
|
out += 'if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||||
|
}
|
||||||
|
if (it.opts.unicode === false) {
|
||||||
|
out += ' ' + ($data) + '.length ';
|
||||||
|
} else {
|
||||||
|
out += ' ucs2length(' + ($data) + ') ';
|
||||||
|
}
|
||||||
|
out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
|
||||||
|
var $errorKeyword = $keyword;
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should NOT be ';
|
||||||
|
if ($keyword == 'maxLength') {
|
||||||
|
out += 'longer';
|
||||||
|
} else {
|
||||||
|
out += 'shorter';
|
||||||
|
}
|
||||||
|
out += ' than ';
|
||||||
|
if ($isData) {
|
||||||
|
out += '\' + ' + ($schemaValue) + ' + \'';
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' characters\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: ';
|
||||||
|
if ($isData) {
|
||||||
|
out += 'validate.schema' + ($schemaPath);
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += '} ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
80
node_sid/node_modules/ajv/lib/dotjs/_limitProperties.js
generated
vendored
Normal file
80
node_sid/node_modules/ajv/lib/dotjs/_limitProperties.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $errorKeyword;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
if (!($isData || typeof $schema == 'number')) {
|
||||||
|
throw new Error($keyword + ' must be number');
|
||||||
|
}
|
||||||
|
var $op = $keyword == 'maxProperties' ? '>' : '<';
|
||||||
|
out += 'if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
|
||||||
|
}
|
||||||
|
out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
|
||||||
|
var $errorKeyword = $keyword;
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should NOT have ';
|
||||||
|
if ($keyword == 'maxProperties') {
|
||||||
|
out += 'more';
|
||||||
|
} else {
|
||||||
|
out += 'fewer';
|
||||||
|
}
|
||||||
|
out += ' than ';
|
||||||
|
if ($isData) {
|
||||||
|
out += '\' + ' + ($schemaValue) + ' + \'';
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' properties\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: ';
|
||||||
|
if ($isData) {
|
||||||
|
out += 'validate.schema' + ($schemaPath);
|
||||||
|
} else {
|
||||||
|
out += '' + ($schema);
|
||||||
|
}
|
||||||
|
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += '} ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
42
node_sid/node_modules/ajv/lib/dotjs/allOf.js
generated
vendored
Normal file
42
node_sid/node_modules/ajv/lib/dotjs/allOf.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_allOf(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $it = it.util.copy(it);
|
||||||
|
var $closingBraces = '';
|
||||||
|
$it.level++;
|
||||||
|
var $nextValid = 'valid' + $it.level;
|
||||||
|
var $currentBaseId = $it.baseId,
|
||||||
|
$allSchemasEmpty = true;
|
||||||
|
var arr1 = $schema;
|
||||||
|
if (arr1) {
|
||||||
|
var $sch, $i = -1,
|
||||||
|
l1 = arr1.length - 1;
|
||||||
|
while ($i < l1) {
|
||||||
|
$sch = arr1[$i += 1];
|
||||||
|
if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
|
||||||
|
$allSchemasEmpty = false;
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + $i;
|
||||||
|
out += ' ' + (it.validate($it)) + ' ';
|
||||||
|
$it.baseId = $currentBaseId;
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (' + ($nextValid) + ') { ';
|
||||||
|
$closingBraces += '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($breakOnError) {
|
||||||
|
if ($allSchemasEmpty) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
} else {
|
||||||
|
out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
73
node_sid/node_modules/ajv/lib/dotjs/anyOf.js
generated
vendored
Normal file
73
node_sid/node_modules/ajv/lib/dotjs/anyOf.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_anyOf(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $valid = 'valid' + $lvl;
|
||||||
|
var $errs = 'errs__' + $lvl;
|
||||||
|
var $it = it.util.copy(it);
|
||||||
|
var $closingBraces = '';
|
||||||
|
$it.level++;
|
||||||
|
var $nextValid = 'valid' + $it.level;
|
||||||
|
var $noEmptySchema = $schema.every(function($sch) {
|
||||||
|
return (it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all));
|
||||||
|
});
|
||||||
|
if ($noEmptySchema) {
|
||||||
|
var $currentBaseId = $it.baseId;
|
||||||
|
out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
|
||||||
|
var $wasComposite = it.compositeRule;
|
||||||
|
it.compositeRule = $it.compositeRule = true;
|
||||||
|
var arr1 = $schema;
|
||||||
|
if (arr1) {
|
||||||
|
var $sch, $i = -1,
|
||||||
|
l1 = arr1.length - 1;
|
||||||
|
while ($i < l1) {
|
||||||
|
$sch = arr1[$i += 1];
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + $i;
|
||||||
|
out += ' ' + (it.validate($it)) + ' ';
|
||||||
|
$it.baseId = $currentBaseId;
|
||||||
|
out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
|
||||||
|
$closingBraces += '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.compositeRule = $it.compositeRule = $wasComposite;
|
||||||
|
out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should match some schema in anyOf\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError(vErrors); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = vErrors; return false; ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
|
||||||
|
if (it.opts.allErrors) {
|
||||||
|
out += ' } ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
14
node_sid/node_modules/ajv/lib/dotjs/comment.js
generated
vendored
Normal file
14
node_sid/node_modules/ajv/lib/dotjs/comment.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_comment(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $comment = it.util.toQuotedString($schema);
|
||||||
|
if (it.opts.$comment === true) {
|
||||||
|
out += ' console.log(' + ($comment) + ');';
|
||||||
|
} else if (typeof it.opts.$comment == 'function') {
|
||||||
|
out += ' self._opts.$comment(' + ($comment) + ', ' + (it.util.toQuotedString($errSchemaPath)) + ', validate.root.schema);';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
56
node_sid/node_modules/ajv/lib/dotjs/const.js
generated
vendored
Normal file
56
node_sid/node_modules/ajv/lib/dotjs/const.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_const(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $valid = 'valid' + $lvl;
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
if (!$isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
|
||||||
|
}
|
||||||
|
out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('const') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValue: schema' + ($lvl) + ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should be equal to constant\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += ' }';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
81
node_sid/node_modules/ajv/lib/dotjs/contains.js
generated
vendored
Normal file
81
node_sid/node_modules/ajv/lib/dotjs/contains.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_contains(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $valid = 'valid' + $lvl;
|
||||||
|
var $errs = 'errs__' + $lvl;
|
||||||
|
var $it = it.util.copy(it);
|
||||||
|
var $closingBraces = '';
|
||||||
|
$it.level++;
|
||||||
|
var $nextValid = 'valid' + $it.level;
|
||||||
|
var $idx = 'i' + $lvl,
|
||||||
|
$dataNxt = $it.dataLevel = it.dataLevel + 1,
|
||||||
|
$nextData = 'data' + $dataNxt,
|
||||||
|
$currentBaseId = it.baseId,
|
||||||
|
$nonEmptySchema = (it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all));
|
||||||
|
out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
|
||||||
|
if ($nonEmptySchema) {
|
||||||
|
var $wasComposite = it.compositeRule;
|
||||||
|
it.compositeRule = $it.compositeRule = true;
|
||||||
|
$it.schema = $schema;
|
||||||
|
$it.schemaPath = $schemaPath;
|
||||||
|
$it.errSchemaPath = $errSchemaPath;
|
||||||
|
out += ' var ' + ($nextValid) + ' = false; for (var ' + ($idx) + ' = 0; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
|
||||||
|
$it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
|
||||||
|
var $passData = $data + '[' + $idx + ']';
|
||||||
|
$it.dataPathArr[$dataNxt] = $idx;
|
||||||
|
var $code = it.validate($it);
|
||||||
|
$it.baseId = $currentBaseId;
|
||||||
|
if (it.util.varOccurences($code, $nextData) < 2) {
|
||||||
|
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
|
||||||
|
} else {
|
||||||
|
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
|
||||||
|
}
|
||||||
|
out += ' if (' + ($nextValid) + ') break; } ';
|
||||||
|
it.compositeRule = $it.compositeRule = $wasComposite;
|
||||||
|
out += ' ' + ($closingBraces) + ' if (!' + ($nextValid) + ') {';
|
||||||
|
} else {
|
||||||
|
out += ' if (' + ($data) + '.length == 0) {';
|
||||||
|
}
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('contains') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should contain a valid item\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += ' } else { ';
|
||||||
|
if ($nonEmptySchema) {
|
||||||
|
out += ' errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
|
||||||
|
}
|
||||||
|
if (it.opts.allErrors) {
|
||||||
|
out += ' } ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
228
node_sid/node_modules/ajv/lib/dotjs/custom.js
generated
vendored
Normal file
228
node_sid/node_modules/ajv/lib/dotjs/custom.js
generated
vendored
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_custom(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $errorKeyword;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $valid = 'valid' + $lvl;
|
||||||
|
var $errs = 'errs__' + $lvl;
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
var $rule = this,
|
||||||
|
$definition = 'definition' + $lvl,
|
||||||
|
$rDef = $rule.definition,
|
||||||
|
$closingBraces = '';
|
||||||
|
var $compile, $inline, $macro, $ruleValidate, $validateCode;
|
||||||
|
if ($isData && $rDef.$data) {
|
||||||
|
$validateCode = 'keywordValidate' + $lvl;
|
||||||
|
var $validateSchema = $rDef.validateSchema;
|
||||||
|
out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
|
||||||
|
} else {
|
||||||
|
$ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
|
||||||
|
if (!$ruleValidate) return;
|
||||||
|
$schemaValue = 'validate.schema' + $schemaPath;
|
||||||
|
$validateCode = $ruleValidate.code;
|
||||||
|
$compile = $rDef.compile;
|
||||||
|
$inline = $rDef.inline;
|
||||||
|
$macro = $rDef.macro;
|
||||||
|
}
|
||||||
|
var $ruleErrs = $validateCode + '.errors',
|
||||||
|
$i = 'i' + $lvl,
|
||||||
|
$ruleErr = 'ruleErr' + $lvl,
|
||||||
|
$asyncKeyword = $rDef.async;
|
||||||
|
if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
|
||||||
|
if (!($inline || $macro)) {
|
||||||
|
out += '' + ($ruleErrs) + ' = null;';
|
||||||
|
}
|
||||||
|
out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
|
||||||
|
if ($isData && $rDef.$data) {
|
||||||
|
$closingBraces += '}';
|
||||||
|
out += ' if (' + ($schemaValue) + ' === undefined) { ' + ($valid) + ' = true; } else { ';
|
||||||
|
if ($validateSchema) {
|
||||||
|
$closingBraces += '}';
|
||||||
|
out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') { ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($inline) {
|
||||||
|
if ($rDef.statements) {
|
||||||
|
out += ' ' + ($ruleValidate.validate) + ' ';
|
||||||
|
} else {
|
||||||
|
out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
|
||||||
|
}
|
||||||
|
} else if ($macro) {
|
||||||
|
var $it = it.util.copy(it);
|
||||||
|
var $closingBraces = '';
|
||||||
|
$it.level++;
|
||||||
|
var $nextValid = 'valid' + $it.level;
|
||||||
|
$it.schema = $ruleValidate.validate;
|
||||||
|
$it.schemaPath = '';
|
||||||
|
var $wasComposite = it.compositeRule;
|
||||||
|
it.compositeRule = $it.compositeRule = true;
|
||||||
|
var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
|
||||||
|
it.compositeRule = $it.compositeRule = $wasComposite;
|
||||||
|
out += ' ' + ($code);
|
||||||
|
} else {
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = '';
|
||||||
|
out += ' ' + ($validateCode) + '.call( ';
|
||||||
|
if (it.opts.passContext) {
|
||||||
|
out += 'this';
|
||||||
|
} else {
|
||||||
|
out += 'self';
|
||||||
|
}
|
||||||
|
if ($compile || $rDef.schema === false) {
|
||||||
|
out += ' , ' + ($data) + ' ';
|
||||||
|
} else {
|
||||||
|
out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
|
||||||
|
}
|
||||||
|
out += ' , (dataPath || \'\')';
|
||||||
|
if (it.errorPath != '""') {
|
||||||
|
out += ' + ' + (it.errorPath);
|
||||||
|
}
|
||||||
|
var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
|
||||||
|
$parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
|
||||||
|
out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
|
||||||
|
var def_callRuleValidate = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if ($rDef.errors === false) {
|
||||||
|
out += ' ' + ($valid) + ' = ';
|
||||||
|
if ($asyncKeyword) {
|
||||||
|
out += 'await ';
|
||||||
|
}
|
||||||
|
out += '' + (def_callRuleValidate) + '; ';
|
||||||
|
} else {
|
||||||
|
if ($asyncKeyword) {
|
||||||
|
$ruleErrs = 'customErrors' + $lvl;
|
||||||
|
out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = await ' + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
|
||||||
|
} else {
|
||||||
|
out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($rDef.modifying) {
|
||||||
|
out += ' if (' + ($parentData) + ') ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
|
||||||
|
}
|
||||||
|
out += '' + ($closingBraces);
|
||||||
|
if ($rDef.valid) {
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' if ( ';
|
||||||
|
if ($rDef.valid === undefined) {
|
||||||
|
out += ' !';
|
||||||
|
if ($macro) {
|
||||||
|
out += '' + ($nextValid);
|
||||||
|
} else {
|
||||||
|
out += '' + ($valid);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' ' + (!$rDef.valid) + ' ';
|
||||||
|
}
|
||||||
|
out += ') { ';
|
||||||
|
$errorKeyword = $rule.keyword;
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = '';
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
var def_customError = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if ($inline) {
|
||||||
|
if ($rDef.errors) {
|
||||||
|
if ($rDef.errors != 'full') {
|
||||||
|
out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($rDef.errors === false) {
|
||||||
|
out += ' ' + (def_customError) + ' ';
|
||||||
|
} else {
|
||||||
|
out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
|
||||||
|
}
|
||||||
|
out += ' } } ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ($macro) {
|
||||||
|
out += ' var err = '; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError(vErrors); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = vErrors; return false; ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($rDef.errors === false) {
|
||||||
|
out += ' ' + (def_customError) + ' ';
|
||||||
|
} else {
|
||||||
|
out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors = vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
|
||||||
|
}
|
||||||
|
out += ' } } else { ' + (def_customError) + ' } ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
168
node_sid/node_modules/ajv/lib/dotjs/dependencies.js
generated
vendored
Normal file
168
node_sid/node_modules/ajv/lib/dotjs/dependencies.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_dependencies(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $errs = 'errs__' + $lvl;
|
||||||
|
var $it = it.util.copy(it);
|
||||||
|
var $closingBraces = '';
|
||||||
|
$it.level++;
|
||||||
|
var $nextValid = 'valid' + $it.level;
|
||||||
|
var $schemaDeps = {},
|
||||||
|
$propertyDeps = {},
|
||||||
|
$ownProperties = it.opts.ownProperties;
|
||||||
|
for ($property in $schema) {
|
||||||
|
if ($property == '__proto__') continue;
|
||||||
|
var $sch = $schema[$property];
|
||||||
|
var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
|
||||||
|
$deps[$property] = $sch;
|
||||||
|
}
|
||||||
|
out += 'var ' + ($errs) + ' = errors;';
|
||||||
|
var $currentErrorPath = it.errorPath;
|
||||||
|
out += 'var missing' + ($lvl) + ';';
|
||||||
|
for (var $property in $propertyDeps) {
|
||||||
|
$deps = $propertyDeps[$property];
|
||||||
|
if ($deps.length) {
|
||||||
|
out += ' if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
|
||||||
|
if ($ownProperties) {
|
||||||
|
out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
|
||||||
|
}
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' && ( ';
|
||||||
|
var arr1 = $deps;
|
||||||
|
if (arr1) {
|
||||||
|
var $propertyKey, $i = -1,
|
||||||
|
l1 = arr1.length - 1;
|
||||||
|
while ($i < l1) {
|
||||||
|
$propertyKey = arr1[$i += 1];
|
||||||
|
if ($i) {
|
||||||
|
out += ' || ';
|
||||||
|
}
|
||||||
|
var $prop = it.util.getProperty($propertyKey),
|
||||||
|
$useData = $data + $prop;
|
||||||
|
out += ' ( ( ' + ($useData) + ' === undefined ';
|
||||||
|
if ($ownProperties) {
|
||||||
|
out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
|
||||||
|
}
|
||||||
|
out += ') && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? $propertyKey : $prop)) + ') ) ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out += ')) { ';
|
||||||
|
var $propertyPath = 'missing' + $lvl,
|
||||||
|
$missingProperty = '\' + ' + $propertyPath + ' + \'';
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
|
||||||
|
}
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should have ';
|
||||||
|
if ($deps.length == 1) {
|
||||||
|
out += 'property ' + (it.util.escapeQuotes($deps[0]));
|
||||||
|
} else {
|
||||||
|
out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
|
||||||
|
}
|
||||||
|
out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' ) { ';
|
||||||
|
var arr2 = $deps;
|
||||||
|
if (arr2) {
|
||||||
|
var $propertyKey, i2 = -1,
|
||||||
|
l2 = arr2.length - 1;
|
||||||
|
while (i2 < l2) {
|
||||||
|
$propertyKey = arr2[i2 += 1];
|
||||||
|
var $prop = it.util.getProperty($propertyKey),
|
||||||
|
$missingProperty = it.util.escapeQuotes($propertyKey),
|
||||||
|
$useData = $data + $prop;
|
||||||
|
if (it.opts._errorDataPathProperty) {
|
||||||
|
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
||||||
|
}
|
||||||
|
out += ' if ( ' + ($useData) + ' === undefined ';
|
||||||
|
if ($ownProperties) {
|
||||||
|
out += ' || ! Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($propertyKey)) + '\') ';
|
||||||
|
}
|
||||||
|
out += ') { var err = '; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should have ';
|
||||||
|
if ($deps.length == 1) {
|
||||||
|
out += 'property ' + (it.util.escapeQuotes($deps[0]));
|
||||||
|
} else {
|
||||||
|
out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
|
||||||
|
}
|
||||||
|
out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
$closingBraces += '}';
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.errorPath = $currentErrorPath;
|
||||||
|
var $currentBaseId = $it.baseId;
|
||||||
|
for (var $property in $schemaDeps) {
|
||||||
|
var $sch = $schemaDeps[$property];
|
||||||
|
if ((it.opts.strictKeywords ? (typeof $sch == 'object' && Object.keys($sch).length > 0) || $sch === false : it.util.schemaHasRules($sch, it.RULES.all))) {
|
||||||
|
out += ' ' + ($nextValid) + ' = true; if ( ' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
|
||||||
|
if ($ownProperties) {
|
||||||
|
out += ' && Object.prototype.hasOwnProperty.call(' + ($data) + ', \'' + (it.util.escapeQuotes($property)) + '\') ';
|
||||||
|
}
|
||||||
|
out += ') { ';
|
||||||
|
$it.schema = $sch;
|
||||||
|
$it.schemaPath = $schemaPath + it.util.getProperty($property);
|
||||||
|
$it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
|
||||||
|
out += ' ' + (it.validate($it)) + ' ';
|
||||||
|
$it.baseId = $currentBaseId;
|
||||||
|
out += ' } ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (' + ($nextValid) + ') { ';
|
||||||
|
$closingBraces += '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
66
node_sid/node_modules/ajv/lib/dotjs/enum.js
generated
vendored
Normal file
66
node_sid/node_modules/ajv/lib/dotjs/enum.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_enum(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
var $valid = 'valid' + $lvl;
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
var $i = 'i' + $lvl,
|
||||||
|
$vSchema = 'schema' + $lvl;
|
||||||
|
if (!$isData) {
|
||||||
|
out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
|
||||||
|
}
|
||||||
|
out += 'var ' + ($valid) + ';';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
|
||||||
|
}
|
||||||
|
out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' } ';
|
||||||
|
}
|
||||||
|
out += ' if (!' + ($valid) + ') { ';
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should be equal to one of the allowed values\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += ' }';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
150
node_sid/node_modules/ajv/lib/dotjs/format.js
generated
vendored
Normal file
150
node_sid/node_modules/ajv/lib/dotjs/format.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
'use strict';
|
||||||
|
module.exports = function generate_format(it, $keyword, $ruleType) {
|
||||||
|
var out = ' ';
|
||||||
|
var $lvl = it.level;
|
||||||
|
var $dataLvl = it.dataLevel;
|
||||||
|
var $schema = it.schema[$keyword];
|
||||||
|
var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
|
||||||
|
var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
|
||||||
|
var $breakOnError = !it.opts.allErrors;
|
||||||
|
var $data = 'data' + ($dataLvl || '');
|
||||||
|
if (it.opts.format === false) {
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
var $isData = it.opts.$data && $schema && $schema.$data,
|
||||||
|
$schemaValue;
|
||||||
|
if ($isData) {
|
||||||
|
out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
|
||||||
|
$schemaValue = 'schema' + $lvl;
|
||||||
|
} else {
|
||||||
|
$schemaValue = $schema;
|
||||||
|
}
|
||||||
|
var $unknownFormats = it.opts.unknownFormats,
|
||||||
|
$allowUnknown = Array.isArray($unknownFormats);
|
||||||
|
if ($isData) {
|
||||||
|
var $format = 'format' + $lvl,
|
||||||
|
$isObject = 'isObject' + $lvl,
|
||||||
|
$formatType = 'formatType' + $lvl;
|
||||||
|
out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var ' + ($isObject) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; var ' + ($formatType) + ' = ' + ($isObject) + ' && ' + ($format) + '.type || \'string\'; if (' + ($isObject) + ') { ';
|
||||||
|
if (it.async) {
|
||||||
|
out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
|
||||||
|
}
|
||||||
|
out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
|
||||||
|
if ($isData) {
|
||||||
|
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
|
||||||
|
}
|
||||||
|
out += ' (';
|
||||||
|
if ($unknownFormats != 'ignore') {
|
||||||
|
out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
|
||||||
|
if ($allowUnknown) {
|
||||||
|
out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
|
||||||
|
}
|
||||||
|
out += ') || ';
|
||||||
|
}
|
||||||
|
out += ' (' + ($format) + ' && ' + ($formatType) + ' == \'' + ($ruleType) + '\' && !(typeof ' + ($format) + ' == \'function\' ? ';
|
||||||
|
if (it.async) {
|
||||||
|
out += ' (async' + ($lvl) + ' ? await ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
|
||||||
|
} else {
|
||||||
|
out += ' ' + ($format) + '(' + ($data) + ') ';
|
||||||
|
}
|
||||||
|
out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
|
||||||
|
} else {
|
||||||
|
var $format = it.formats[$schema];
|
||||||
|
if (!$format) {
|
||||||
|
if ($unknownFormats == 'ignore') {
|
||||||
|
it.logger.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else if ($allowUnknown && $unknownFormats.indexOf($schema) >= 0) {
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
|
||||||
|
var $formatType = $isObject && $format.type || 'string';
|
||||||
|
if ($isObject) {
|
||||||
|
var $async = $format.async === true;
|
||||||
|
$format = $format.validate;
|
||||||
|
}
|
||||||
|
if ($formatType != $ruleType) {
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' if (true) { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
if ($async) {
|
||||||
|
if (!it.async) throw new Error('async format in sync schema');
|
||||||
|
var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
|
||||||
|
out += ' if (!(await ' + ($formatRef) + '(' + ($data) + '))) { ';
|
||||||
|
} else {
|
||||||
|
out += ' if (! ';
|
||||||
|
var $formatRef = 'formats' + it.util.getProperty($schema);
|
||||||
|
if ($isObject) $formatRef += '.validate';
|
||||||
|
if (typeof $format == 'function') {
|
||||||
|
out += ' ' + ($formatRef) + '(' + ($data) + ') ';
|
||||||
|
} else {
|
||||||
|
out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
|
||||||
|
}
|
||||||
|
out += ') { ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var $$outStack = $$outStack || [];
|
||||||
|
$$outStack.push(out);
|
||||||
|
out = ''; /* istanbul ignore else */
|
||||||
|
if (it.createErrors !== false) {
|
||||||
|
out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
|
||||||
|
if ($isData) {
|
||||||
|
out += '' + ($schemaValue);
|
||||||
|
} else {
|
||||||
|
out += '' + (it.util.toQuotedString($schema));
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
if (it.opts.messages !== false) {
|
||||||
|
out += ' , message: \'should match format "';
|
||||||
|
if ($isData) {
|
||||||
|
out += '\' + ' + ($schemaValue) + ' + \'';
|
||||||
|
} else {
|
||||||
|
out += '' + (it.util.escapeQuotes($schema));
|
||||||
|
}
|
||||||
|
out += '"\' ';
|
||||||
|
}
|
||||||
|
if (it.opts.verbose) {
|
||||||
|
out += ' , schema: ';
|
||||||
|
if ($isData) {
|
||||||
|
out += 'validate.schema' + ($schemaPath);
|
||||||
|
} else {
|
||||||
|
out += '' + (it.util.toQuotedString($schema));
|
||||||
|
}
|
||||||
|
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
} else {
|
||||||
|
out += ' {} ';
|
||||||
|
}
|
||||||
|
var __err = out;
|
||||||
|
out = $$outStack.pop();
|
||||||
|
if (!it.compositeRule && $breakOnError) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (it.async) {
|
||||||
|
out += ' throw new ValidationError([' + (__err) + ']); ';
|
||||||
|
} else {
|
||||||
|
out += ' validate.errors = [' + (__err) + ']; return false; ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
|
||||||
|
}
|
||||||
|
out += ' } ';
|
||||||
|
if ($breakOnError) {
|
||||||
|
out += ' else { ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user