initial commit. phase 1 complete

This commit is contained in:
2026-05-05 20:45:19 +02:00
parent d9c68313a0
commit 89e058ffac
20631 changed files with 3224610 additions and 43 deletions
+40
View File
@@ -0,0 +1,40 @@
# =============================================================
# LabGraph Environment Variables
# Copy this file to .env and fill in all required values.
# Values marked (required) have no default and MUST be set.
# =============================================================
# --- Django ---
DJANGO_SETTINGS_MODULE=config.settings.development
SECRET_KEY=39viQnJn0IF0WZfgPYu3GA68YXufPFzaW_Uiz_tlIzoBmpfe3XnlZVJ2y02ntT0JrTY
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
# --- PostgreSQL (used by both docker-compose and Django) ---
POSTGRES_DB=labgraph
POSTGRES_USER=labgraph
POSTGRES_PASSWORD=labgraph
# --- Database URL (used by django-environ) ---
# Format: postgres://USER:PASSWORD@HOST:PORT/DBNAME
DATABASE_URL=postgres://labgraph:labgraph@db:5432/labgraph
# --- Redis ---
# Note: URL format uses colon before password, no username: redis://:PASSWORD@host:port/db
REDIS_PASSWORD=QuietProfe55ion@!
REDIS_URL=redis://:QuietProfe55ion@!@redis:6379/0
# --- Celery Broker ---
CELERY_BROKER_URL=redis://:QuietProfe55ion@!@redis:6379/0
# --- CORS ---
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
# --- Flower (Celery monitoring dashboard) ---
FLOWER_USER=admin
FLOWER_PASSWORD=QuietProfe55ion@!
# --- Discovery Credentials (Phase 2) ---
PROXMOX_URL=
PROXMOX_TOKEN_NAME=
PROXMOX_TOKEN_VALUE=
+34 -9
View File
@@ -1,15 +1,40 @@
# Django Settings
# =============================================================
# LabGraph Environment Variables
# Copy this file to .env and fill in all required values.
# Values marked (required) have no default and MUST be set.
# =============================================================
# --- Django ---
DJANGO_SETTINGS_MODULE=config.settings.development
SECRET_KEY=change-me-generate-with-python-secrets-token-urlsafe-50
DEBUG=True
SECRET_KEY=O+6Pr9xDz5/BxDMVxGtivAMkOHbRaAHLA5kc7P05a/4=
ALLOWED_HOSTS=localhost,127.0.0.1
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
# Database
DATABASE_URL=postgres://postgres:password@db:5432/labgraph
# --- PostgreSQL (used by both docker-compose and Django) ---
POSTGRES_DB=labgraph
POSTGRES_USER=labgraph
POSTGRES_PASSWORD=changeme-required
# Redis & Celery
REDIS_URL=redis://redis:6379/0
# --- Database URL (used by django-environ) ---
# Format: postgres://USER:PASSWORD@HOST:PORT/DBNAME
DATABASE_URL=postgres://labgraph:changeme-required@db:5432/labgraph
# Discovery Credentials (Optional for Phase 1)
# --- Redis ---
# Note: URL format uses colon before password, no username: redis://:PASSWORD@host:port/db
REDIS_PASSWORD=changeme-required
REDIS_URL=redis://:changeme-required@redis:6379/0
# --- Celery Broker ---
CELERY_BROKER_URL=redis://:changeme-required@redis:6379/0
# --- CORS ---
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
# --- Flower (Celery monitoring dashboard) ---
FLOWER_USER=admin
FLOWER_PASSWORD=changeme-required
# --- Discovery Credentials (Phase 2) ---
PROXMOX_URL=
PROXMOX_TOKEN_NAME=
PROXMOX_TOKEN_VALUE=
PROXMOX_TOKEN_VALUE=
+15
View File
@@ -0,0 +1,15 @@
.git
__pycache__
*.pyc
*.pyo
*.pyd
.env
.env.*
!.env.example
staticfiles/
mediafiles/
wiki_store/
*.sqlite3
.pytest_cache/
.mypy_cache/
htmlcov/
+64
View File
@@ -0,0 +1,64 @@
# =============================================================================
# LabGraph — Multi-stage Dockerfile
# Stages: base → development → production
# docker-compose uses target: development for all services
# =============================================================================
# -----------------------------------------------------------------------------
# base — shared OS deps, non-root user, Python dependencies
# -----------------------------------------------------------------------------
FROM python:3.12-slim AS base
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# curl: required by docker-compose web healthcheck (curl http://localhost:8000/api/health/)
# nmap: required by python-nmap discovery tasks (Phase 2)
# libpq-dev + build-essential: required to compile psycopg[binary]
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
curl \
nmap \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd --gid 1000 appuser && \
useradd --uid 1000 --gid appuser --shell /bin/bash --create-home appuser
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
# -----------------------------------------------------------------------------
# development — volume-mounted source, no CMD (docker-compose provides it)
# -----------------------------------------------------------------------------
FROM base AS development
RUN pip install watchdog
EXPOSE 8000
# -----------------------------------------------------------------------------
# production — source baked in, runs as non-root, gunicorn CMD
# -----------------------------------------------------------------------------
FROM base AS production
COPY . .
RUN python manage.py collectstatic --noinput
USER appuser
EXPOSE 8000
CMD ["gunicorn", "config.wsgi:application", \
"--bind", "0.0.0.0:8000", \
"--workers", "4", \
"--worker-class", "gthread", \
"--threads", "2", \
"--timeout", "120", \
"--access-logfile", "-", \
"--error-logfile", "-"]
View File
View File
+50
View File
@@ -0,0 +1,50 @@
"""Django admin registration for all core models."""
from django.contrib import admin
from .models import Edge, HeartbeatLog, Network, Node, WikiPage
@admin.register(Node)
class NodeAdmin(admin.ModelAdmin): # type: ignore[type-arg]
list_display = ("label", "node_type", "status", "ip_address", "discovery_source", "updated_at")
list_filter = ("node_type", "status", "discovery_source")
search_fields = ("label", "ip_address", "mac_address", "external_id")
readonly_fields = ("id", "created_at", "updated_at")
ordering = ("label",)
list_per_page = 50
@admin.register(Edge)
class EdgeAdmin(admin.ModelAdmin): # type: ignore[type-arg]
list_display = ("source", "target", "edge_type", "weight", "created_at")
list_filter = ("edge_type",)
raw_id_fields = ("source", "target")
readonly_fields = ("id", "created_at")
list_per_page = 50
@admin.register(Network)
class NetworkAdmin(admin.ModelAdmin): # type: ignore[type-arg]
list_display = ("name", "cidr", "vlan_id", "gateway", "created_at")
search_fields = ("name", "cidr")
readonly_fields = ("id", "created_at", "updated_at")
list_per_page = 50
@admin.register(WikiPage)
class WikiPageAdmin(admin.ModelAdmin): # type: ignore[type-arg]
list_display = ("node", "last_edited_by", "updated_at")
raw_id_fields = ("node", "last_edited_by")
readonly_fields = ("id", "created_at", "updated_at")
list_per_page = 50
@admin.register(HeartbeatLog)
class HeartbeatLogAdmin(admin.ModelAdmin): # type: ignore[type-arg]
list_display = ("node", "status", "check_type", "response_time_ms", "timestamp")
list_filter = ("status", "check_type")
raw_id_fields = ("node",)
readonly_fields = ("id", "timestamp")
date_hierarchy = "timestamp"
list_per_page = 100
+52
View File
@@ -0,0 +1,52 @@
"""
Core app configuration.
Connects a post_migrate signal to enable PostgreSQL Row-Level Security
on the core_node table. The policy is permissive for now (allow all);
Phase 2+ can tighten it for multi-user support.
"""
import logging
from django.apps import AppConfig
logger = logging.getLogger(__name__)
class CoreConfig(AppConfig):
name = "apps.core"
verbose_name = "Infrastructure Core"
default_auto_field = "django.db.models.BigAutoField"
def ready(self) -> None:
from django.db.models.signals import post_migrate
post_migrate.connect(_enable_node_rls, sender=self)
def _enable_node_rls(sender: AppConfig, **kwargs: object) -> None:
"""Enable PostgreSQL RLS on the node table after migrations complete."""
from django.db import connection
from django.db.utils import OperationalError, ProgrammingError
try:
with connection.cursor() as cursor:
# Bail out early if core_node doesn't exist yet (fires before core migrations)
cursor.execute(
"SELECT EXISTS ("
" SELECT 1 FROM information_schema.tables WHERE table_name = 'core_node'"
");"
)
row = cursor.fetchone()
if row is None or not row[0]:
return
cursor.execute("ALTER TABLE core_node ENABLE ROW LEVEL SECURITY;")
cursor.execute(
"DO $$ BEGIN "
" IF NOT EXISTS (SELECT 1 FROM pg_policies WHERE tablename = 'core_node' AND policyname = 'allow_all_for_now') THEN "
" CREATE POLICY allow_all_for_now ON core_node USING (true) WITH CHECK (true); "
" END IF; "
"END $$;"
)
except (OperationalError, ProgrammingError):
logger.debug("core_node table not yet available for RLS setup; will apply on next migrate.")
+260
View File
@@ -0,0 +1,260 @@
"""
Core graph models for LabGraph.
Graph structure:
Node — vertices (any infrastructure component)
Edge — directed relationships between nodes
Network — IP network segments (VLANs/subnets)
WikiPage — Markdown documentation anchored to a node
HeartbeatLog — time-series liveness records per node
"""
import uuid
import markdown as md
from django.db import models
class Node(models.Model):
"""
Polymorphic infrastructure node — the vertex type in the LabGraph.
node_type drives rendering and determines what metadata keys are
expected in the JSONField. Pydantic schemas in schemas.py validate
metadata content at the API boundary before writes reach the ORM.
"""
class NodeType(models.TextChoices):
LOCATION = "location", "Physical Location"
HARDWARE = "hardware", "Physical Hardware"
HYPERVISOR = "hypervisor", "Hypervisor Host"
VM = "vm", "Virtual Machine"
CONTAINER = "container", "Container"
APPLICATION = "application", "Application / Service"
NETWORK_DEVICE = "network_device", "Network Device"
class Status(models.TextChoices):
ONLINE = "online", "Online"
OFFLINE = "offline", "Offline"
DEGRADED = "degraded", "Degraded"
UNKNOWN = "unknown", "Unknown"
MAINTENANCE = "maintenance", "Maintenance"
class DiscoverySource(models.TextChoices):
MANUAL = "manual", "Manually Added"
PROXMOX = "proxmox", "Proxmox API"
NMAP = "nmap", "Nmap Scan"
SNMP = "snmp", "SNMP"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
label = models.CharField(max_length=255, db_index=True)
node_type = models.CharField(
max_length=30, choices=NodeType.choices, db_index=True
)
status = models.CharField(
max_length=20,
choices=Status.choices,
default=Status.UNKNOWN,
db_index=True,
)
ip_address = models.GenericIPAddressField(null=True, blank=True, db_index=True)
# Stored as colon-separated hex: "aa:bb:cc:dd:ee:ff"
mac_address = models.CharField(max_length=17, null=True, blank=True)
# Rated power draw in watts — used by the power cost estimator (Phase 3)
wattage = models.DecimalField(max_digits=8, decimal_places=2, null=True, blank=True)
# Flexible per-type data; validated by Pydantic at the API boundary
metadata = models.JSONField(default=dict, blank=True)
discovery_source = models.CharField(
max_length=20,
choices=DiscoverySource.choices,
default=DiscoverySource.MANUAL,
)
# ID in the originating external system, e.g. Proxmox VMID or Docker container ID
external_id = models.CharField(max_length=255, null=True, blank=True, db_index=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["label"]
indexes = [
models.Index(fields=["node_type", "status"]),
models.Index(fields=["discovery_source", "external_id"]),
]
verbose_name = "Node"
verbose_name_plural = "Nodes"
def __str__(self) -> str:
return f"{self.label} ({self.get_node_type_display()})"
class Edge(models.Model):
"""
Directed edge between two Nodes in the infrastructure graph.
Direction: source → target.
Multiple edge types allow different relationship semantics to coexist
(e.g. a VM has a parent_child edge to its hypervisor AND a network
edge to a switch).
"""
class EdgeType(models.TextChoices):
PARENT_CHILD = "parent_child", "Parent / Child"
NETWORK = "network", "Network Connection"
DEPENDENCY = "dependency", "Software Dependency"
PHYSICAL = "physical", "Physical Connection"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
source = models.ForeignKey(
Node, on_delete=models.CASCADE, related_name="outgoing_edges"
)
target = models.ForeignKey(
Node, on_delete=models.CASCADE, related_name="incoming_edges"
)
edge_type = models.CharField(
max_length=20, choices=EdgeType.choices, db_index=True
)
weight = models.FloatField(default=1.0)
label = models.CharField(max_length=255, blank=True)
metadata = models.JSONField(default=dict, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = [("source", "target", "edge_type")]
indexes = [models.Index(fields=["edge_type"])]
verbose_name = "Edge"
verbose_name_plural = "Edges"
def __str__(self) -> str:
return f"{self.source.label}{self.target.label} [{self.edge_type}]"
class Network(models.Model):
"""
An IP network segment that nodes attach to.
Nodes reference Networks via metadata or a future ManyToMany through-model
(Phase 2 IPAM). Networks are separate entities from Nodes so that VLAN
and subnet data can be managed independently.
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255)
vlan_id = models.PositiveSmallIntegerField(
null=True,
blank=True,
help_text="802.1Q VLAN tag (14094)",
)
# CIDR notation, e.g. "192.168.10.0/24"
cidr = models.CharField(max_length=43, db_index=True)
gateway = models.GenericIPAddressField(null=True, blank=True)
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["cidr"]
verbose_name = "Network"
verbose_name_plural = "Networks"
def __str__(self) -> str:
vlan_str = f" (VLAN {self.vlan_id})" if self.vlan_id else ""
return f"{self.name} {self.cidr}{vlan_str}"
class WikiPage(models.Model):
"""
Human-authored documentation anchored to a single Node.
Content is stored as raw Markdown. rendered_html() converts it to
safe HTML at render time using the Markdown package.
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
node = models.OneToOneField(
Node, on_delete=models.CASCADE, related_name="wiki_page"
)
content = models.TextField(blank=True, help_text="Markdown content")
last_edited_by = models.ForeignKey(
"auth.User",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="wiki_edits",
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = "Wiki Page"
verbose_name_plural = "Wiki Pages"
def __str__(self) -> str:
return f"Wiki: {self.node.label}"
def rendered_html(self) -> str:
"""Convert Markdown content to safe HTML."""
return md.markdown(
self.content,
extensions=["fenced_code", "tables", "nl2br"],
)
class HeartbeatLog(models.Model):
"""
Time-series liveness record for a Node.
Written by tasks/heartbeat.py on every check cycle. High-volume —
records accumulate fast. The maintenance task prunes rows older than
30 days nightly.
"""
class CheckType(models.TextChoices):
ICMP = "icmp", "ICMP Ping"
TCP = "tcp", "TCP Port Check"
HTTP = "http", "HTTP/S Check"
SNMP = "snmp", "SNMP Poll"
class HeartbeatStatus(models.TextChoices):
UP = "up", "Up"
DOWN = "down", "Down"
TIMEOUT = "timeout", "Timeout"
ERROR = "error", "Error"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
node = models.ForeignKey(
Node, on_delete=models.CASCADE, related_name="heartbeat_logs"
)
timestamp = models.DateTimeField(auto_now_add=True, db_index=True)
status = models.CharField(
max_length=10, choices=HeartbeatStatus.choices, db_index=True
)
check_type = models.CharField(max_length=10, choices=CheckType.choices)
# Null on timeout or error — response never completed
response_time_ms = models.PositiveIntegerField(null=True, blank=True)
error_message = models.TextField(blank=True)
class Meta:
ordering = ["-timestamp"]
indexes = [
models.Index(fields=["node", "-timestamp"]),
models.Index(fields=["status", "-timestamp"]),
]
verbose_name = "Heartbeat Log"
verbose_name_plural = "Heartbeat Logs"
def __str__(self) -> str:
return f"{self.node.label} [{self.status}] @ {self.timestamp:%Y-%m-%d %H:%M:%S}"
+144
View File
@@ -0,0 +1,144 @@
"""
Pydantic v2 input validation schemas for the LabGraph API.
These schemas validate incoming request data at the API boundary BEFORE
it reaches the Django ORM. A ValidationError here is converted to an
HTTP 400 in the view layer (Phase 2).
Keeping validation here (not in DRF serializers) means the same schemas
can be reused by Celery discovery tasks when upserting auto-discovered nodes.
"""
import ipaddress
import re
import uuid
from typing import Any
from pydantic import BaseModel, Field, field_validator
_MAC_PATTERN = re.compile(r"^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
VALID_NODE_TYPES = {
"location", "hardware", "hypervisor", "vm",
"container", "application", "network_device",
}
VALID_EDGE_TYPES = {"parent_child", "network", "dependency", "physical"}
VALID_DISCOVERY_SOURCES = {"manual", "proxmox", "nmap", "snmp"}
class NodeCreateSchema(BaseModel):
"""Validates POST /api/v1/nodes/ request body."""
label: str = Field(min_length=1, max_length=255)
node_type: str
ip_address: str | None = None
mac_address: str | None = None
wattage: float | None = Field(default=None, gt=0)
metadata: dict[str, Any] = Field(default_factory=dict)
discovery_source: str = "manual"
external_id: str | None = Field(default=None, max_length=255)
@field_validator("node_type")
@classmethod
def validate_node_type(cls, v: str) -> str:
if v not in VALID_NODE_TYPES:
raise ValueError(f"node_type must be one of: {sorted(VALID_NODE_TYPES)}")
return v
@field_validator("ip_address")
@classmethod
def validate_ip_address(cls, v: str | None) -> str | None:
if v is None:
return v
try:
ipaddress.ip_address(v)
except ValueError:
raise ValueError(f"Invalid IP address: {v!r}")
return v
@field_validator("mac_address")
@classmethod
def validate_mac_address(cls, v: str | None) -> str | None:
if v is None:
return v
if not _MAC_PATTERN.match(v):
raise ValueError("MAC address must be in aa:bb:cc:dd:ee:ff format")
return v.lower()
@field_validator("discovery_source")
@classmethod
def validate_discovery_source(cls, v: str) -> str:
if v not in VALID_DISCOVERY_SOURCES:
raise ValueError(f"discovery_source must be one of: {sorted(VALID_DISCOVERY_SOURCES)}")
return v
class NodeUpdateSchema(NodeCreateSchema):
"""Validates PATCH /api/v1/nodes/<id>/ — all fields optional."""
label: str = Field(default=None, min_length=1, max_length=255) # type: ignore[assignment]
node_type: str | None = None # type: ignore[assignment]
discovery_source: str = "manual"
class EdgeCreateSchema(BaseModel):
"""Validates POST /api/v1/edges/ request body."""
source: uuid.UUID
target: uuid.UUID
edge_type: str
weight: float = Field(default=1.0, gt=0)
label: str = Field(default="", max_length=255)
metadata: dict[str, Any] = Field(default_factory=dict)
@field_validator("edge_type")
@classmethod
def validate_edge_type(cls, v: str) -> str:
if v not in VALID_EDGE_TYPES:
raise ValueError(f"edge_type must be one of: {sorted(VALID_EDGE_TYPES)}")
return v
@field_validator("target")
@classmethod
def source_and_target_differ(cls, v: uuid.UUID, info: Any) -> uuid.UUID:
if "source" in info.data and v == info.data["source"]:
raise ValueError("source and target must be different nodes")
return v
class NetworkCreateSchema(BaseModel):
"""Validates POST /api/v1/networks/ request body."""
name: str = Field(min_length=1, max_length=255)
cidr: str
vlan_id: int | None = Field(default=None, ge=1, le=4094)
gateway: str | None = None
description: str = ""
@field_validator("cidr")
@classmethod
def validate_cidr(cls, v: str) -> str:
try:
ipaddress.ip_network(v, strict=False)
except ValueError:
raise ValueError(f"Invalid CIDR notation: {v!r}")
return v
@field_validator("gateway")
@classmethod
def validate_gateway(cls, v: str | None) -> str | None:
if v is None:
return v
try:
ipaddress.ip_address(v)
except ValueError:
raise ValueError(f"Invalid gateway IP address: {v!r}")
return v
class WikiPageUpdateSchema(BaseModel):
"""Validates PATCH /api/v1/wiki/<node_id>/ request body."""
content: str = ""
+7
View File
@@ -0,0 +1,7 @@
from django.urls import include, path
from .views import router
urlpatterns = [
path("", include(router.urls)),
]
+17
View File
@@ -0,0 +1,17 @@
"""
Core API ViewSets — Phase 1 stub.
The DRF router is registered here; viewsets will be added in Phase 2
alongside full CRUD and graph traversal endpoints.
"""
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
# Phase 2 additions:
# from .viewsets import NodeViewSet, EdgeViewSet, NetworkViewSet, WikiPageViewSet
# router.register("nodes", NodeViewSet, basename="node")
# router.register("edges", EdgeViewSet, basename="edge")
# router.register("networks", NetworkViewSet, basename="network")
# router.register("wiki", WikiPageViewSet, basename="wiki")
View File
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class HealthConfig(AppConfig):
name = "apps.health"
verbose_name = "Health Check"
+7
View File
@@ -0,0 +1,7 @@
from django.urls import path
from .views import HealthCheckView
urlpatterns = [
path("", HealthCheckView.as_view(), name="health-check"),
]
+74
View File
@@ -0,0 +1,74 @@
"""
Health check endpoint required by the docker-compose web service healthcheck:
test: ["CMD-SHELL", "curl -fs http://localhost:8000/api/health/ || exit 1"]
Does NOT require authentication — the docker daemon calls this, not users.
Returns HTTP 200 when all services are healthy, HTTP 503 on any failure.
"""
import logging
from django.core.cache import cache
from django.db import OperationalError, connection
from django.http import JsonResponse
from django.views import View
logger = logging.getLogger(__name__)
VERSION = "1.0.0"
class HealthCheckView(View):
"""
Synchronous health check for web, database, and Redis.
Response body:
{
"status": "ok" | "degraded",
"version": "1.0.0",
"services": {
"database": "ok" | "error",
"redis": "ok" | "error"
}
}
"""
def get(self, request) -> JsonResponse: # type: ignore[override]
db_status = _check_database()
redis_status = _check_redis()
all_ok = db_status == "ok" and redis_status == "ok"
http_status = 200 if all_ok else 503
return JsonResponse(
{
"status": "ok" if all_ok else "degraded",
"version": VERSION,
"services": {
"database": db_status,
"redis": redis_status,
},
},
status=http_status,
)
def _check_database() -> str:
try:
with connection.cursor() as cursor:
cursor.execute("SELECT 1")
return "ok"
except OperationalError:
logger.exception("Database health check failed")
return "error"
def _check_redis() -> str:
try:
cache.set("_health_check", "1", timeout=5)
if cache.get("_health_check") != "1":
raise RuntimeError("Redis round-trip failed")
return "ok"
except Exception:
logger.exception("Redis health check failed")
return "error"
View File
+13
View File
@@ -0,0 +1,13 @@
"""
ASGI config for LabGraph.
Kept for future WebSocket support (Phase 3+ real-time status updates).
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.development")
application = get_asgi_application()
+62
View File
@@ -0,0 +1,62 @@
"""
Celery application for LabGraph.
Referenced by docker-compose as: celery -A config.celery <subcommand>
Queues:
discovery — Proxmox API polling, nmap network scans
heartbeat — Periodic ICMP/TCP liveness checks
default — Maintenance, cleanup, housekeeping
"""
import os
from celery import Celery
from celery.schedules import crontab
from kombu import Exchange, Queue
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.development")
app = Celery("labgraph")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks(["tasks"])
# Explicit queue definitions (mirrors --queues flag in docker-compose worker command)
app.conf.task_queues = (
Queue("default", Exchange("default"), routing_key="default"),
Queue("discovery", Exchange("discovery"), routing_key="discovery"),
Queue("heartbeat", Exchange("heartbeat"), routing_key="heartbeat"),
)
app.conf.task_default_queue = "default"
app.conf.task_default_exchange = "default"
app.conf.task_default_routing_key = "default"
# Route tasks to queues by module prefix
app.conf.task_routes = {
"tasks.discovery.*": {"queue": "discovery"},
"tasks.heartbeat.*": {"queue": "heartbeat"},
"tasks.maintenance.*": {"queue": "default"},
}
app.conf.beat_schedule = {
"heartbeat-all-nodes": {
"task": "tasks.heartbeat.check_all_nodes",
"schedule": 60.0,
"queue": "heartbeat",
# Drop task if not picked up before the next run fires
"options": {"expires": 55},
},
"discovery-scan-networks": {
"task": "tasks.discovery.scan_all_networks",
"schedule": crontab(minute="*/15"),
"queue": "discovery",
},
"maintenance-prune-heartbeat-logs": {
"task": "tasks.maintenance.prune_old_heartbeat_logs",
"schedule": crontab(hour=3, minute=0),
"queue": "default",
},
}
View File
+191
View File
@@ -0,0 +1,191 @@
"""
Base settings shared across all LabGraph environments.
Never imported directly — always imported via development.py or production.py.
All secrets are read from environment variables; missing required vars raise
ImproperlyConfigured immediately on startup.
"""
from pathlib import Path
import environ
BASE_DIR = Path(__file__).resolve().parent.parent.parent # backend/
env = environ.Env(
DEBUG=(bool, False),
ALLOWED_HOSTS=(list, ["localhost", "127.0.0.1"]),
)
environ.Env.read_env(BASE_DIR.parent / ".env")
# =============================================================================
# Security — no defaults for secrets; missing value raises ImproperlyConfigured
# =============================================================================
SECRET_KEY = env("SECRET_KEY")
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")
# =============================================================================
# Application definition
# =============================================================================
DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]
THIRD_PARTY_APPS = [
"rest_framework",
"corsheaders",
"django_celery_beat",
"django_celery_results",
"drf_spectacular",
"django_filters",
]
LOCAL_APPS = [
"apps.core",
"apps.health",
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# =============================================================================
# Middleware — CorsMiddleware must be first
# =============================================================================
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "config.urls"
WSGI_APPLICATION = "config.wsgi.application"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
# =============================================================================
# Database — parsed from DATABASE_URL env var by django-environ
# =============================================================================
DATABASES = {
"default": env.db("DATABASE_URL")
}
# Ensure Django uses UTC-aware datetimes in queries
DATABASES["default"]["OPTIONS"] = {"options": "-c timezone=UTC"}
# =============================================================================
# Cache — Redis
# =============================================================================
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": env("REDIS_URL"),
}
}
# =============================================================================
# Celery — all CELERY_* prefixed settings are picked up by
# app.config_from_object("django.conf:settings", namespace="CELERY")
# =============================================================================
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
CELERY_RESULT_BACKEND = "django-db"
CELERY_CACHE_BACKEND = "default"
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TIMEZONE = "UTC"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 300
CELERY_TASK_SOFT_TIME_LIMIT = 270
CELERY_WORKER_MAX_TASKS_PER_CHILD = 100
# =============================================================================
# Django REST Framework
# =============================================================================
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.SessionAuthentication",
],
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticated",
],
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.SearchFilter",
"rest_framework.filters.OrderingFilter",
],
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 50,
}
# =============================================================================
# drf-spectacular — OpenAPI schema
# =============================================================================
SPECTACULAR_SETTINGS = {
"TITLE": "LabGraph API",
"DESCRIPTION": "HomeLab infrastructure documentation engine — graph-based inventory and monitoring.",
"VERSION": "1.0.0",
"SERVE_INCLUDE_SCHEMA": False,
}
# =============================================================================
# CORS
# =============================================================================
CORS_ALLOW_CREDENTIALS = True
# =============================================================================
# Static & media files
# =============================================================================
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "mediafiles"
# =============================================================================
# Internationalisation
# =============================================================================
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# =============================================================================
# Default primary key
# =============================================================================
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
# =============================================================================
# Password validation
# =============================================================================
AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
+50
View File
@@ -0,0 +1,50 @@
"""
Development settings for LabGraph.
Inherits all base settings and adds:
- DEBUG = True
- Relaxed CORS (localhost:3000 allowed by default)
- Console email backend
- Verbose DEBUG-level logging for apps and Celery
"""
from .base import * # noqa: F401, F403
from .base import env
DEBUG = True
CORS_ALLOWED_ORIGINS = env.list(
"CORS_ALLOWED_ORIGINS",
default=["http://localhost:3000", "http://127.0.0.1:3000"],
)
INTERNAL_IPS = ["127.0.0.1"]
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "[{levelname}] {asctime} {name}: {message}",
"style": "{",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "verbose",
},
},
"root": {
"handlers": ["console"],
"level": "INFO",
},
"loggers": {
"django": {"handlers": ["console"], "level": "INFO", "propagate": False},
"celery": {"handlers": ["console"], "level": "DEBUG", "propagate": False},
"apps": {"handlers": ["console"], "level": "DEBUG", "propagate": False},
"tasks": {"handlers": ["console"], "level": "DEBUG", "propagate": False},
},
}
+57
View File
@@ -0,0 +1,57 @@
"""
Production settings for LabGraph.
Inherits all base settings and adds:
- DEBUG = False
- Strict CORS (origins required from env, no default)
- HSTS + secure cookies + SSL redirect
- WhiteNoise compressed static files
- JSON-formatted structured logging at WARNING level
"""
from .base import * # noqa: F401, F403
from .base import env
DEBUG = False
# Production CORS must be explicitly set — no default
CORS_ALLOWED_ORIGINS = env.list("CORS_ALLOWED_ORIGINS")
# Security hardening
SECURE_HSTS_SECONDS = 31_536_000 # 1 year
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_SSL_REDIRECT = env.bool("SECURE_SSL_REDIRECT", default=True)
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = "DENY"
# WhiteNoise: compress + fingerprint static files for long-lived caching
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"json": {
"()": "logging.Formatter",
"fmt": '{"time": "%(asctime)s", "level": "%(levelname)s", "name": "%(name)s", "message": "%(message)s"}',
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "json",
},
},
"root": {
"handlers": ["console"],
"level": "WARNING",
},
"loggers": {
"django": {"handlers": ["console"], "level": "WARNING", "propagate": False},
"celery": {"handlers": ["console"], "level": "WARNING", "propagate": False},
},
}
+21
View File
@@ -0,0 +1,21 @@
"""
Root URL configuration for LabGraph.
Routes:
/admin/ — Django admin interface
/api/health/ — Health check (required by docker-compose healthcheck)
/api/v1/ — DRF router (viewsets registered in Phase 2)
/api/schema/ — OpenAPI schema (drf-spectacular)
"""
from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
urlpatterns = [
path("admin/", admin.site.urls),
path("api/health/", include("apps.health.urls")),
path("api/v1/", include("apps.core.urls")),
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
path("api/docs/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui"),
]
+14
View File
@@ -0,0 +1,14 @@
"""
WSGI config for LabGraph.
Entry point used by Gunicorn in docker-compose:
gunicorn config.wsgi:application
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.development")
application = get_wsgi_application()
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main() -> None:
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.development")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()
+28
View File
@@ -0,0 +1,28 @@
# Web Framework & API
django>=5.0,<5.1
djangorestframework
django-cors-headers
django-environ
drf-spectacular
django-filter
# Database & Task Queue
psycopg[binary]
celery[redis]
django-celery-results
django-celery-beat
redis
# Data Validation & Logic
pydantic>=2.0
requests
python-nmap
icmplib
Markdown
# Production Server
gunicorn
whitenoise
# Utilities
python-dotenv
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
set -e
python manage.py migrate --noinput
python manage.py collectstatic --noinput
exec gunicorn config.wsgi:application \
--bind 0.0.0.0:8000 \
--workers 4 \
--worker-class gthread \
--threads 2 \
--timeout 120 \
--access-logfile - \
--error-logfile -
+9
View File
@@ -0,0 +1,9 @@
-- LabGraph PostgreSQL initialization script.
-- Runs once when the postgres volume is first created (via docker-entrypoint-initdb.d).
-- Must execute before Django migrations.
-- uuid_generate_v4() used as default for all UUIDField primary keys
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- GIN index support for fuzzy text search on Node.label
CREATE EXTENSION IF NOT EXISTS "pg_trgm";
View File
+27
View File
@@ -0,0 +1,27 @@
"""
Discovery task stubs — Phase 1 scaffolding.
Phase 2 implementations will:
scan_all_networks — iterate Network queryset, run nmap per CIDR, upsert Nodes
poll_proxmox — call Proxmox API, upsert VM/container Nodes via PROXMOX_URL/TOKEN env vars
"""
import logging
from config.celery import app
logger = logging.getLogger(__name__)
@app.task(name="tasks.discovery.scan_all_networks", bind=True, max_retries=3)
def scan_all_networks(self) -> dict: # type: ignore[type-arg]
"""Stub: scan all configured Network CIDRs for live hosts."""
logger.info("discovery.scan_all_networks: stub — Phase 2 not yet implemented")
return {"status": "stub", "message": "Phase 2 not yet implemented"}
@app.task(name="tasks.discovery.poll_proxmox", bind=True, max_retries=3)
def poll_proxmox(self) -> dict: # type: ignore[type-arg]
"""Stub: poll Proxmox API for VMs and containers."""
logger.info("discovery.poll_proxmox: stub — Phase 2 not yet implemented")
return {"status": "stub", "message": "Phase 2 not yet implemented"}
+29
View File
@@ -0,0 +1,29 @@
"""
Heartbeat task stubs — Phase 1 scaffolding.
Phase 2 implementations will:
check_all_nodes — query Node.objects.filter(ip_address__isnull=False),
dispatch check_single_node subtasks via Celery group()
check_single_node — icmplib.ping() for ICMP, socket.connect_ex() for TCP,
httpx.get() for HTTP; write HeartbeatLog record
"""
import logging
from config.celery import app
logger = logging.getLogger(__name__)
@app.task(name="tasks.heartbeat.check_all_nodes", bind=True)
def check_all_nodes(self) -> dict: # type: ignore[type-arg]
"""Stub: ICMP/TCP liveness check for all nodes that have an IP address."""
logger.debug("heartbeat.check_all_nodes: stub — Phase 2 not yet implemented")
return {"status": "stub", "checked": 0}
@app.task(name="tasks.heartbeat.check_single_node", bind=True, max_retries=2)
def check_single_node(self, node_id: str, check_type: str = "icmp") -> dict: # type: ignore[type-arg]
"""Stub: check a single node and write a HeartbeatLog record."""
logger.debug("heartbeat.check_single_node: stub for node_id=%s", node_id)
return {"status": "stub", "node_id": node_id, "check_type": check_type}
+35
View File
@@ -0,0 +1,35 @@
"""
Maintenance tasks — cleanup and housekeeping.
Scheduled via Celery Beat to run daily at 03:00 UTC.
"""
import logging
from datetime import timedelta
from django.utils import timezone
from config.celery import app
logger = logging.getLogger(__name__)
@app.task(name="tasks.maintenance.prune_old_heartbeat_logs", bind=True)
def prune_old_heartbeat_logs(self, days: int = 30) -> dict: # type: ignore[type-arg]
"""
Delete HeartbeatLog records older than `days` days.
Returns the count of deleted rows for monitoring/alerting.
Runs as a single bulk DELETE to avoid row-by-row overhead.
"""
from apps.core.models import HeartbeatLog
cutoff = timezone.now() - timedelta(days=days)
deleted_count, _ = HeartbeatLog.objects.filter(timestamp__lt=cutoff).delete()
logger.info(
"maintenance.prune_old_heartbeat_logs: deleted %d records older than %d days",
deleted_count,
days,
)
return {"status": "ok", "deleted": deleted_count, "cutoff_days": days}
+1 -13
View File
@@ -1,5 +1,3 @@
version: "3.9"
# =============================================================================
# LabGraph — Docker Compose Orchestration
# Services: web (Django/Gunicorn), db (PostgreSQL), redis, celery-worker,
@@ -75,17 +73,7 @@ services:
container_name: labgraph_web
restart: unless-stopped
<<: *django-env
command: >
sh -c "python manage.py migrate --noinput &&
python manage.py collectstatic --noinput &&
gunicorn config.wsgi:application
--bind 0.0.0.0:8000
--workers 4
--worker-class gthread
--threads 2
--timeout 120
--access-logfile -
--error-logfile -"
command: sh /app/scripts/entrypoint.sh
volumes:
- ./backend:/app
- static_volume:/app/staticfiles
+8
View File
@@ -0,0 +1,8 @@
# Copy to .env.local and fill in values.
# NextAuth — required for session signing
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=change-me-generate-with-openssl-rand-base64-32
# Django backend URL (used by next.config.ts rewrites + api.ts)
NEXT_PUBLIC_API_URL=http://localhost:8000
+7
View File
@@ -0,0 +1,7 @@
{
"extends": ["next/core-web-vitals"],
"rules": {
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
}
}
+18
View File
@@ -0,0 +1,18 @@
import type { NextConfig } from "next";
const DJANGO_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
const nextConfig: NextConfig = {
// Proxy /backend/* requests to the Django API so the frontend never
// exposes the backend origin to the browser (avoids CORS in production).
async rewrites() {
return [
{
source: "/backend/:path*",
destination: `${DJANGO_URL}/:path*`,
},
];
},
};
export default nextConfig;
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../acorn/bin/acorn
+1
View File
@@ -0,0 +1 @@
../autoprefixer/bin/autoprefixer
+1
View File
@@ -0,0 +1 @@
../baseline-browser-mapping/dist/cli.cjs
+1
View File
@@ -0,0 +1 @@
../browserslist/cli.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../cssesc/bin/cssesc
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../eslint/bin/eslint.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../glob/dist/esm/bin.mjs
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../jiti/bin/jiti.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../js-yaml/bin/js-yaml.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../json5/lib/cli.js
+1
View File
@@ -0,0 +1 @@
../loose-envify/cli.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../nanoid/bin/nanoid.cjs
+1
View File
@@ -0,0 +1 @@
../napi-postinstall/lib/cli.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../next/dist/bin/next
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../which/bin/node-which
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../resolve/bin/resolve
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../rimraf/bin.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../semver/bin/semver.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../sucrase/bin/sucrase
+1
View File
@@ -0,0 +1 @@
../sucrase/bin/sucrase-node
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../tailwindcss/lib/cli.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../tailwindcss/lib/cli.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../typescript/bin/tsc
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../typescript/bin/tsserver
+1
View File
@@ -0,0 +1 @@
../update-browserslist-db/cli.js
Generated Vendored Symlink
+1
View File
@@ -0,0 +1 @@
../uuid/dist/bin/uuid
+5924
View File
File diff suppressed because it is too large Load Diff
+128
View File
@@ -0,0 +1,128 @@
declare namespace QuickLRU {
interface Options<KeyType, ValueType> {
/**
The maximum number of milliseconds an item should remain in the cache.
@default Infinity
By default, `maxAge` will be `Infinity`, which means that items will never expire.
Lazy expiration upon the next write or read call.
Individual expiration of an item can be specified by the `set(key, value, maxAge)` method.
*/
readonly maxAge?: number;
/**
The maximum number of items before evicting the least recently used items.
*/
readonly maxSize: number;
/**
Called right before an item is evicted from the cache.
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
*/
onEviction?: (key: KeyType, value: ValueType) => void;
}
}
declare class QuickLRU<KeyType, ValueType>
implements Iterable<[KeyType, ValueType]> {
/**
The stored item count.
*/
readonly size: number;
/**
Simple ["Least Recently Used" (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29).
The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
@example
```
import QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 1000});
lru.set('🦄', '🌈');
lru.has('🦄');
//=> true
lru.get('🦄');
//=> '🌈'
```
*/
constructor(options: QuickLRU.Options<KeyType, ValueType>);
[Symbol.iterator](): IterableIterator<[KeyType, ValueType]>;
/**
Set an item. Returns the instance.
Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified in the constructor, otherwise the item will never expire.
@returns The list instance.
*/
set(key: KeyType, value: ValueType, options?: {maxAge?: number}): this;
/**
Get an item.
@returns The stored item or `undefined`.
*/
get(key: KeyType): ValueType | undefined;
/**
Check if an item exists.
*/
has(key: KeyType): boolean;
/**
Get an item without marking it as recently used.
@returns The stored item or `undefined`.
*/
peek(key: KeyType): ValueType | undefined;
/**
Delete an item.
@returns `true` if the item is removed or `false` if the item doesn't exist.
*/
delete(key: KeyType): boolean;
/**
Delete all items.
*/
clear(): void;
/**
Update the `maxSize` in-place, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
Useful for on-the-fly tuning of cache sizes in live systems.
*/
resize(maxSize: number): void;
/**
Iterable for all the keys.
*/
keys(): IterableIterator<KeyType>;
/**
Iterable for all the values.
*/
values(): IterableIterator<ValueType>;
/**
Iterable for all entries, starting with the oldest (ascending in recency).
*/
entriesAscending(): IterableIterator<[KeyType, ValueType]>;
/**
Iterable for all entries, starting with the newest (descending in recency).
*/
entriesDescending(): IterableIterator<[KeyType, ValueType]>;
}
export = QuickLRU;
+263
View File
@@ -0,0 +1,263 @@
'use strict';
class QuickLRU {
constructor(options = {}) {
if (!(options.maxSize && options.maxSize > 0)) {
throw new TypeError('`maxSize` must be a number greater than 0');
}
if (typeof options.maxAge === 'number' && options.maxAge === 0) {
throw new TypeError('`maxAge` must be a number greater than 0');
}
this.maxSize = options.maxSize;
this.maxAge = options.maxAge || Infinity;
this.onEviction = options.onEviction;
this.cache = new Map();
this.oldCache = new Map();
this._size = 0;
}
_emitEvictions(cache) {
if (typeof this.onEviction !== 'function') {
return;
}
for (const [key, item] of cache) {
this.onEviction(key, item.value);
}
}
_deleteIfExpired(key, item) {
if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
if (typeof this.onEviction === 'function') {
this.onEviction(key, item.value);
}
return this.delete(key);
}
return false;
}
_getOrDeleteIfExpired(key, item) {
const deleted = this._deleteIfExpired(key, item);
if (deleted === false) {
return item.value;
}
}
_getItemValue(key, item) {
return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
}
_peek(key, cache) {
const item = cache.get(key);
return this._getItemValue(key, item);
}
_set(key, value) {
this.cache.set(key, value);
this._size++;
if (this._size >= this.maxSize) {
this._size = 0;
this._emitEvictions(this.oldCache);
this.oldCache = this.cache;
this.cache = new Map();
}
}
_moveToRecent(key, item) {
this.oldCache.delete(key);
this._set(key, item);
}
* _entriesAscending() {
for (const item of this.oldCache) {
const [key, value] = item;
if (!this.cache.has(key)) {
const deleted = this._deleteIfExpired(key, value);
if (deleted === false) {
yield item;
}
}
}
for (const item of this.cache) {
const [key, value] = item;
const deleted = this._deleteIfExpired(key, value);
if (deleted === false) {
yield item;
}
}
}
get(key) {
if (this.cache.has(key)) {
const item = this.cache.get(key);
return this._getItemValue(key, item);
}
if (this.oldCache.has(key)) {
const item = this.oldCache.get(key);
if (this._deleteIfExpired(key, item) === false) {
this._moveToRecent(key, item);
return item.value;
}
}
}
set(key, value, {maxAge = this.maxAge === Infinity ? undefined : Date.now() + this.maxAge} = {}) {
if (this.cache.has(key)) {
this.cache.set(key, {
value,
maxAge
});
} else {
this._set(key, {value, expiry: maxAge});
}
}
has(key) {
if (this.cache.has(key)) {
return !this._deleteIfExpired(key, this.cache.get(key));
}
if (this.oldCache.has(key)) {
return !this._deleteIfExpired(key, this.oldCache.get(key));
}
return false;
}
peek(key) {
if (this.cache.has(key)) {
return this._peek(key, this.cache);
}
if (this.oldCache.has(key)) {
return this._peek(key, this.oldCache);
}
}
delete(key) {
const deleted = this.cache.delete(key);
if (deleted) {
this._size--;
}
return this.oldCache.delete(key) || deleted;
}
clear() {
this.cache.clear();
this.oldCache.clear();
this._size = 0;
}
resize(newSize) {
if (!(newSize && newSize > 0)) {
throw new TypeError('`maxSize` must be a number greater than 0');
}
const items = [...this._entriesAscending()];
const removeCount = items.length - newSize;
if (removeCount < 0) {
this.cache = new Map(items);
this.oldCache = new Map();
this._size = items.length;
} else {
if (removeCount > 0) {
this._emitEvictions(items.slice(0, removeCount));
}
this.oldCache = new Map(items.slice(removeCount));
this.cache = new Map();
this._size = 0;
}
this.maxSize = newSize;
}
* keys() {
for (const [key] of this) {
yield key;
}
}
* values() {
for (const [, value] of this) {
yield value;
}
}
* [Symbol.iterator]() {
for (const item of this.cache) {
const [key, value] = item;
const deleted = this._deleteIfExpired(key, value);
if (deleted === false) {
yield [key, value.value];
}
}
for (const item of this.oldCache) {
const [key, value] = item;
if (!this.cache.has(key)) {
const deleted = this._deleteIfExpired(key, value);
if (deleted === false) {
yield [key, value.value];
}
}
}
}
* entriesDescending() {
let items = [...this.cache];
for (let i = items.length - 1; i >= 0; --i) {
const item = items[i];
const [key, value] = item;
const deleted = this._deleteIfExpired(key, value);
if (deleted === false) {
yield [key, value.value];
}
}
items = [...this.oldCache];
for (let i = items.length - 1; i >= 0; --i) {
const item = items[i];
const [key, value] = item;
if (!this.cache.has(key)) {
const deleted = this._deleteIfExpired(key, value);
if (deleted === false) {
yield [key, value.value];
}
}
}
}
* entriesAscending() {
for (const [key, value] of this._entriesAscending()) {
yield [key, value.value];
}
}
get size() {
if (!this._size) {
return this.oldCache.size;
}
let oldCacheSize = 0;
for (const key of this.oldCache.keys()) {
if (!this.cache.has(key)) {
oldCacheSize++;
}
}
return Math.min(this._size + oldCacheSize, this.maxSize);
}
}
module.exports = QuickLRU;
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
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.
+43
View File
@@ -0,0 +1,43 @@
{
"name": "@alloc/quick-lru",
"version": "5.2.0",
"description": "Simple “Least Recently Used” (LRU) cache",
"license": "MIT",
"repository": "sindresorhus/quick-lru",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=10"
},
"scripts": {
"test": "xo && nyc ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"lru",
"quick",
"cache",
"caching",
"least",
"recently",
"used",
"fast",
"map",
"hash",
"buffer"
],
"devDependencies": {
"ava": "^2.0.0",
"coveralls": "^3.0.3",
"nyc": "^15.0.0",
"tsd": "^0.11.0",
"xo": "^0.26.0"
}
}
+139
View File
@@ -0,0 +1,139 @@
# quick-lru [![Build Status](https://travis-ci.org/sindresorhus/quick-lru.svg?branch=master)](https://travis-ci.org/sindresorhus/quick-lru) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/quick-lru/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/quick-lru?branch=master)
> Simple [“Least Recently Used” (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)
Useful when you need to cache something and limit memory usage.
Inspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.
## Install
```
$ npm install quick-lru
```
## Usage
```js
const QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 1000});
lru.set('🦄', '🌈');
lru.has('🦄');
//=> true
lru.get('🦄');
//=> '🌈'
```
## API
### new QuickLRU(options?)
Returns a new instance.
### options
Type: `object`
#### maxSize
*Required*\
Type: `number`
The maximum number of items before evicting the least recently used items.
#### maxAge
Type: `number`\
Default: `Infinity`
The maximum number of milliseconds an item should remain in cache.
By default maxAge will be Infinity, which means that items will never expire.
Lazy expiration happens upon the next `write` or `read` call.
Individual expiration of an item can be specified by the `set(key, value, options)` method.
#### onEviction
*Optional*\
Type: `(key, value) => void`
Called right before an item is evicted from the cache.
Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
### Instance
The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
Both `key` and `value` can be of any type.
#### .set(key, value, options?)
Set an item. Returns the instance.
Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified on the constructor, otherwise the item will never expire.
#### .get(key)
Get an item.
#### .has(key)
Check if an item exists.
#### .peek(key)
Get an item without marking it as recently used.
#### .delete(key)
Delete an item.
Returns `true` if the item is removed or `false` if the item doesn't exist.
#### .clear()
Delete all items.
#### .resize(maxSize)
Update the `maxSize`, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
Useful for on-the-fly tuning of cache sizes in live systems.
#### .keys()
Iterable for all the keys.
#### .values()
Iterable for all the values.
#### .entriesAscending()
Iterable for all entries, starting with the oldest (ascending in recency).
#### .entriesDescending()
Iterable for all entries, starting with the newest (descending in recency).
#### .size
The stored item count.
---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-quick-lru?utm_source=npm-quick-lru&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
+22
View File
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
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.
+19
View File
@@ -0,0 +1,19 @@
# @babel/runtime
> babel's modular runtime helpers
See our website [@babel/runtime](https://babeljs.io/docs/babel-runtime) for more information.
## Install
Using npm:
```sh
npm install --save @babel/runtime
```
or using yarn:
```sh
yarn add @babel/runtime
```
+4
View File
@@ -0,0 +1,4 @@
function _AwaitValue(t) {
this.wrapped = t;
}
module.exports = _AwaitValue, module.exports.__esModule = true, module.exports["default"] = module.exports;
+4
View File
@@ -0,0 +1,4 @@
function _OverloadYield(e, d) {
this.v = e, this.k = d;
}
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,9 @@
function _applyDecoratedDescriptor(i, e, r, n, l) {
var a = {};
return Object.keys(n).forEach(function (i) {
a[i] = n[i];
}), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) {
return n(i, e, r) || r;
}, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a;
}
module.exports = _applyDecoratedDescriptor, module.exports.__esModule = true, module.exports["default"] = module.exports;
+236
View File
@@ -0,0 +1,236 @@
var _typeof = require("./typeof.js")["default"];
var setFunctionName = require("./setFunctionName.js");
var toPropertyKey = require("./toPropertyKey.js");
function old_createMetadataMethodsForProperty(e, t, a, r) {
return {
getMetadata: function getMetadata(o) {
old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o);
var i = e[o];
if (void 0 !== i) if (1 === t) {
var n = i["public"];
if (void 0 !== n) return n[a];
} else if (2 === t) {
var l = i["private"];
if (void 0 !== l) return l.get(a);
} else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor;
},
setMetadata: function setMetadata(o, i) {
old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o);
var n = e[o];
if (void 0 === n && (n = e[o] = {}), 1 === t) {
var l = n["public"];
void 0 === l && (l = n["public"] = {}), l[a] = i;
} else if (2 === t) {
var s = n.priv;
void 0 === s && (s = n["private"] = new Map()), s.set(a, i);
} else n.constructor = i;
}
};
}
function old_convertMetadataMapToFinal(e, t) {
var a = e[Symbol.metadata || Symbol["for"]("Symbol.metadata")],
r = Object.getOwnPropertySymbols(t);
if (0 !== r.length) {
for (var o = 0; o < r.length; o++) {
var i = r[o],
n = t[i],
l = a ? a[i] : null,
s = n["public"],
c = l ? l["public"] : null;
s && c && Object.setPrototypeOf(s, c);
var d = n["private"];
if (d) {
var u = Array.from(d.values()),
f = l ? l["private"] : null;
f && (u = u.concat(f)), n["private"] = u;
}
l && Object.setPrototypeOf(n, l);
}
a && Object.setPrototypeOf(t, a), e[Symbol.metadata || Symbol["for"]("Symbol.metadata")] = t;
}
}
function old_createAddInitializerMethod(e, t) {
return function (a) {
old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a);
};
}
function old_memberDec(e, t, a, r, o, i, n, l, s) {
var c;
switch (i) {
case 1:
c = "accessor";
break;
case 2:
c = "method";
break;
case 3:
c = "getter";
break;
case 4:
c = "setter";
break;
default:
c = "field";
}
var d,
u,
f = {
kind: c,
name: l ? "#" + t : toPropertyKey(t),
isStatic: n,
isPrivate: l
},
p = {
v: !1
};
if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) {
d = 2, u = Symbol(t);
var v = {};
0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () {
return a.value;
} : (1 !== i && 3 !== i || (v.get = function () {
return a.get.call(this);
}), 1 !== i && 4 !== i || (v.set = function (e) {
a.set.call(this, e);
})), f.access = v;
} else d = 1, u = t;
try {
return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p)));
} finally {
p.v = !0;
}
}
function old_assertNotFinished(e, t) {
if (e.v) throw Error("attempted to call " + t + " after decoration was finished");
}
function old_assertMetadataKey(e) {
if ("symbol" != _typeof(e)) throw new TypeError("Metadata keys must be symbols, received: " + e);
}
function old_assertCallable(e, t) {
if ("function" != typeof e) throw new TypeError(t + " must be a function");
}
function old_assertValidReturnValue(e, t) {
var a = _typeof(t);
if (1 === e) {
if ("object" !== a || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
void 0 !== t.get && old_assertCallable(t.get, "accessor.get"), void 0 !== t.set && old_assertCallable(t.set, "accessor.set"), void 0 !== t.init && old_assertCallable(t.init, "accessor.init"), void 0 !== t.initializer && old_assertCallable(t.initializer, "accessor.initializer");
} else if ("function" !== a) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
}
function old_getInit(e) {
var t;
return null == (t = e.init) && (t = e.initializer) && void 0 !== console && console.warn(".initializer has been renamed to .init as of March 2022"), t;
}
function old_applyMemberDec(e, t, a, r, o, i, n, l, s) {
var c,
d,
u,
f,
p,
v,
y,
h = a[0];
if (n ? (0 === o || 1 === o ? (c = {
get: a[3],
set: a[4]
}, u = "get") : 3 === o ? (c = {
get: a[3]
}, u = "get") : 4 === o ? (c = {
set: a[3]
}, u = "set") : c = {
value: a[3]
}, 0 !== o && (1 === o && setFunctionName(a[4], "#" + r, "set"), setFunctionName(a[3], "#" + r, u))) : 0 !== o && (c = Object.getOwnPropertyDescriptor(t, r)), 1 === o ? f = {
get: c.get,
set: c.set
} : 2 === o ? f = c.value : 3 === o ? f = c.get : 4 === o && (f = c.set), "function" == typeof h) void 0 !== (p = old_memberDec(h, r, c, l, s, o, i, n, f)) && (old_assertValidReturnValue(o, p), 0 === o ? d = p : 1 === o ? (d = old_getInit(p), v = p.get || f.get, y = p.set || f.set, f = {
get: v,
set: y
}) : f = p);else for (var m = h.length - 1; m >= 0; m--) {
var b;
void 0 !== (p = old_memberDec(h[m], r, c, l, s, o, i, n, f)) && (old_assertValidReturnValue(o, p), 0 === o ? b = p : 1 === o ? (b = old_getInit(p), v = p.get || f.get, y = p.set || f.set, f = {
get: v,
set: y
}) : f = p, void 0 !== b && (void 0 === d ? d = b : "function" == typeof d ? d = [d, b] : d.push(b)));
}
if (0 === o || 1 === o) {
if (void 0 === d) d = function d(e, t) {
return t;
};else if ("function" != typeof d) {
var g = d;
d = function d(e, t) {
for (var a = t, r = 0; r < g.length; r++) a = g[r].call(e, a);
return a;
};
} else {
var _ = d;
d = function d(e, t) {
return _.call(e, t);
};
}
e.push(d);
}
0 !== o && (1 === o ? (c.get = f.get, c.set = f.set) : 2 === o ? c.value = f : 3 === o ? c.get = f : 4 === o && (c.set = f), n ? 1 === o ? (e.push(function (e, t) {
return f.get.call(e, t);
}), e.push(function (e, t) {
return f.set.call(e, t);
})) : 2 === o ? e.push(f) : e.push(function (e, t) {
return f.call(e, t);
}) : Object.defineProperty(t, r, c));
}
function old_applyMemberDecs(e, t, a, r, o) {
for (var i, n, l = new Map(), s = new Map(), c = 0; c < o.length; c++) {
var d = o[c];
if (Array.isArray(d)) {
var u,
f,
p,
v = d[1],
y = d[2],
h = d.length > 3,
m = v >= 5;
if (m ? (u = t, f = r, 0 != (v -= 5) && (p = n = n || [])) : (u = t.prototype, f = a, 0 !== v && (p = i = i || [])), 0 !== v && !h) {
var b = m ? s : l,
g = b.get(y) || 0;
if (!0 === g || 3 === g && 4 !== v || 4 === g && 3 !== v) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + y);
!g && v > 2 ? b.set(y, v) : b.set(y, !0);
}
old_applyMemberDec(e, u, d, y, v, m, h, f, p);
}
}
old_pushInitializers(e, i), old_pushInitializers(e, n);
}
function old_pushInitializers(e, t) {
t && e.push(function (e) {
for (var a = 0; a < t.length; a++) t[a].call(e);
return e;
});
}
function old_applyClassDecs(e, t, a, r) {
if (r.length > 0) {
for (var o = [], i = t, n = t.name, l = r.length - 1; l >= 0; l--) {
var s = {
v: !1
};
try {
var c = Object.assign({
kind: "class",
name: n,
addInitializer: old_createAddInitializerMethod(o, s)
}, old_createMetadataMethodsForProperty(a, 0, n, s)),
d = r[l](i, c);
} finally {
s.v = !0;
}
void 0 !== d && (old_assertValidReturnValue(10, d), i = d);
}
e.push(i, function () {
for (var e = 0; e < o.length; e++) o[e].call(i);
});
}
}
function applyDecs(e, t, a) {
var r = [],
o = {},
i = {};
return old_applyMemberDecs(r, e, i, o, t), old_convertMetadataMapToFinal(e.prototype, i), old_applyClassDecs(r, e, o, a), old_convertMetadataMapToFinal(e, o), r;
}
module.exports = applyDecs, module.exports.__esModule = true, module.exports["default"] = module.exports;
+184
View File
@@ -0,0 +1,184 @@
var _typeof = require("./typeof.js")["default"];
function applyDecs2203Factory() {
function createAddInitializerMethod(e, t) {
return function (r) {
!function (e) {
if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
}(t), assertCallable(r, "An initializer"), e.push(r);
};
}
function memberDec(e, t, r, a, n, i, s, o) {
var c;
switch (n) {
case 1:
c = "accessor";
break;
case 2:
c = "method";
break;
case 3:
c = "getter";
break;
case 4:
c = "setter";
break;
default:
c = "field";
}
var l,
u,
f = {
kind: c,
name: s ? "#" + t : t,
"static": i,
"private": s
},
p = {
v: !1
};
0 !== n && (f.addInitializer = createAddInitializerMethod(a, p)), 0 === n ? s ? (l = r.get, u = r.set) : (l = function l() {
return this[t];
}, u = function u(e) {
this[t] = e;
}) : 2 === n ? l = function l() {
return r.value;
} : (1 !== n && 3 !== n || (l = function l() {
return r.get.call(this);
}), 1 !== n && 4 !== n || (u = function u(e) {
r.set.call(this, e);
})), f.access = l && u ? {
get: l,
set: u
} : l ? {
get: l
} : {
set: u
};
try {
return e(o, f);
} finally {
p.v = !0;
}
}
function assertCallable(e, t) {
if ("function" != typeof e) throw new TypeError(t + " must be a function");
}
function assertValidReturnValue(e, t) {
var r = _typeof(t);
if (1 === e) {
if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
} else if ("function" !== r) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
}
function applyMemberDec(e, t, r, a, n, i, s, o) {
var c,
l,
u,
f,
p,
d,
h = r[0];
if (s ? c = 0 === n || 1 === n ? {
get: r[3],
set: r[4]
} : 3 === n ? {
get: r[3]
} : 4 === n ? {
set: r[3]
} : {
value: r[3]
} : 0 !== n && (c = Object.getOwnPropertyDescriptor(t, a)), 1 === n ? u = {
get: c.get,
set: c.set
} : 2 === n ? u = c.value : 3 === n ? u = c.get : 4 === n && (u = c.set), "function" == typeof h) void 0 !== (f = memberDec(h, a, c, o, n, i, s, u)) && (assertValidReturnValue(n, f), 0 === n ? l = f : 1 === n ? (l = f.init, p = f.get || u.get, d = f.set || u.set, u = {
get: p,
set: d
}) : u = f);else for (var v = h.length - 1; v >= 0; v--) {
var g;
void 0 !== (f = memberDec(h[v], a, c, o, n, i, s, u)) && (assertValidReturnValue(n, f), 0 === n ? g = f : 1 === n ? (g = f.init, p = f.get || u.get, d = f.set || u.set, u = {
get: p,
set: d
}) : u = f, void 0 !== g && (void 0 === l ? l = g : "function" == typeof l ? l = [l, g] : l.push(g)));
}
if (0 === n || 1 === n) {
if (void 0 === l) l = function l(e, t) {
return t;
};else if ("function" != typeof l) {
var y = l;
l = function l(e, t) {
for (var r = t, a = 0; a < y.length; a++) r = y[a].call(e, r);
return r;
};
} else {
var m = l;
l = function l(e, t) {
return m.call(e, t);
};
}
e.push(l);
}
0 !== n && (1 === n ? (c.get = u.get, c.set = u.set) : 2 === n ? c.value = u : 3 === n ? c.get = u : 4 === n && (c.set = u), s ? 1 === n ? (e.push(function (e, t) {
return u.get.call(e, t);
}), e.push(function (e, t) {
return u.set.call(e, t);
})) : 2 === n ? e.push(u) : e.push(function (e, t) {
return u.call(e, t);
}) : Object.defineProperty(t, a, c));
}
function pushInitializers(e, t) {
t && e.push(function (e) {
for (var r = 0; r < t.length; r++) t[r].call(e);
return e;
});
}
return function (e, t, r) {
var a = [];
return function (e, t, r) {
for (var a, n, i = new Map(), s = new Map(), o = 0; o < r.length; o++) {
var c = r[o];
if (Array.isArray(c)) {
var l,
u,
f = c[1],
p = c[2],
d = c.length > 3,
h = f >= 5;
if (h ? (l = t, 0 != (f -= 5) && (u = n = n || [])) : (l = t.prototype, 0 !== f && (u = a = a || [])), 0 !== f && !d) {
var v = h ? s : i,
g = v.get(p) || 0;
if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + p);
!g && f > 2 ? v.set(p, f) : v.set(p, !0);
}
applyMemberDec(e, l, c, p, f, h, d, u);
}
}
pushInitializers(e, a), pushInitializers(e, n);
}(a, e, t), function (e, t, r) {
if (r.length > 0) {
for (var a = [], n = t, i = t.name, s = r.length - 1; s >= 0; s--) {
var o = {
v: !1
};
try {
var c = r[s](n, {
kind: "class",
name: i,
addInitializer: createAddInitializerMethod(a, o)
});
} finally {
o.v = !0;
}
void 0 !== c && (assertValidReturnValue(10, c), n = c);
}
e.push(n, function () {
for (var e = 0; e < a.length; e++) a[e].call(n);
});
}
}(a, e, r), a;
};
}
var applyDecs2203Impl;
function applyDecs2203(e, t, r) {
return (applyDecs2203Impl = applyDecs2203Impl || applyDecs2203Factory())(e, t, r);
}
module.exports = applyDecs2203, module.exports.__esModule = true, module.exports["default"] = module.exports;
+191
View File
@@ -0,0 +1,191 @@
var _typeof = require("./typeof.js")["default"];
var setFunctionName = require("./setFunctionName.js");
var toPropertyKey = require("./toPropertyKey.js");
function applyDecs2203RFactory() {
function createAddInitializerMethod(e, t) {
return function (r) {
!function (e) {
if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
}(t), assertCallable(r, "An initializer"), e.push(r);
};
}
function memberDec(e, t, r, n, a, i, o, s) {
var c;
switch (a) {
case 1:
c = "accessor";
break;
case 2:
c = "method";
break;
case 3:
c = "getter";
break;
case 4:
c = "setter";
break;
default:
c = "field";
}
var l,
u,
f = {
kind: c,
name: o ? "#" + t : toPropertyKey(t),
"static": i,
"private": o
},
p = {
v: !1
};
0 !== a && (f.addInitializer = createAddInitializerMethod(n, p)), 0 === a ? o ? (l = r.get, u = r.set) : (l = function l() {
return this[t];
}, u = function u(e) {
this[t] = e;
}) : 2 === a ? l = function l() {
return r.value;
} : (1 !== a && 3 !== a || (l = function l() {
return r.get.call(this);
}), 1 !== a && 4 !== a || (u = function u(e) {
r.set.call(this, e);
})), f.access = l && u ? {
get: l,
set: u
} : l ? {
get: l
} : {
set: u
};
try {
return e(s, f);
} finally {
p.v = !0;
}
}
function assertCallable(e, t) {
if ("function" != typeof e) throw new TypeError(t + " must be a function");
}
function assertValidReturnValue(e, t) {
var r = _typeof(t);
if (1 === e) {
if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
} else if ("function" !== r) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
}
function applyMemberDec(e, t, r, n, a, i, o, s) {
var c,
l,
u,
f,
p,
d,
h,
v = r[0];
if (o ? (0 === a || 1 === a ? (c = {
get: r[3],
set: r[4]
}, u = "get") : 3 === a ? (c = {
get: r[3]
}, u = "get") : 4 === a ? (c = {
set: r[3]
}, u = "set") : c = {
value: r[3]
}, 0 !== a && (1 === a && setFunctionName(r[4], "#" + n, "set"), setFunctionName(r[3], "#" + n, u))) : 0 !== a && (c = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? f = {
get: c.get,
set: c.set
} : 2 === a ? f = c.value : 3 === a ? f = c.get : 4 === a && (f = c.set), "function" == typeof v) void 0 !== (p = memberDec(v, n, c, s, a, i, o, f)) && (assertValidReturnValue(a, p), 0 === a ? l = p : 1 === a ? (l = p.init, d = p.get || f.get, h = p.set || f.set, f = {
get: d,
set: h
}) : f = p);else for (var g = v.length - 1; g >= 0; g--) {
var y;
void 0 !== (p = memberDec(v[g], n, c, s, a, i, o, f)) && (assertValidReturnValue(a, p), 0 === a ? y = p : 1 === a ? (y = p.init, d = p.get || f.get, h = p.set || f.set, f = {
get: d,
set: h
}) : f = p, void 0 !== y && (void 0 === l ? l = y : "function" == typeof l ? l = [l, y] : l.push(y)));
}
if (0 === a || 1 === a) {
if (void 0 === l) l = function l(e, t) {
return t;
};else if ("function" != typeof l) {
var m = l;
l = function l(e, t) {
for (var r = t, n = 0; n < m.length; n++) r = m[n].call(e, r);
return r;
};
} else {
var b = l;
l = function l(e, t) {
return b.call(e, t);
};
}
e.push(l);
}
0 !== a && (1 === a ? (c.get = f.get, c.set = f.set) : 2 === a ? c.value = f : 3 === a ? c.get = f : 4 === a && (c.set = f), o ? 1 === a ? (e.push(function (e, t) {
return f.get.call(e, t);
}), e.push(function (e, t) {
return f.set.call(e, t);
})) : 2 === a ? e.push(f) : e.push(function (e, t) {
return f.call(e, t);
}) : Object.defineProperty(t, n, c));
}
function applyMemberDecs(e, t) {
for (var r, n, a = [], i = new Map(), o = new Map(), s = 0; s < t.length; s++) {
var c = t[s];
if (Array.isArray(c)) {
var l,
u,
f = c[1],
p = c[2],
d = c.length > 3,
h = f >= 5;
if (h ? (l = e, 0 != (f -= 5) && (u = n = n || [])) : (l = e.prototype, 0 !== f && (u = r = r || [])), 0 !== f && !d) {
var v = h ? o : i,
g = v.get(p) || 0;
if (!0 === g || 3 === g && 4 !== f || 4 === g && 3 !== f) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + p);
!g && f > 2 ? v.set(p, f) : v.set(p, !0);
}
applyMemberDec(a, l, c, p, f, h, d, u);
}
}
return pushInitializers(a, r), pushInitializers(a, n), a;
}
function pushInitializers(e, t) {
t && e.push(function (e) {
for (var r = 0; r < t.length; r++) t[r].call(e);
return e;
});
}
return function (e, t, r) {
return {
e: applyMemberDecs(e, t),
get c() {
return function (e, t) {
if (t.length > 0) {
for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) {
var o = {
v: !1
};
try {
var s = t[i](n, {
kind: "class",
name: a,
addInitializer: createAddInitializerMethod(r, o)
});
} finally {
o.v = !0;
}
void 0 !== s && (assertValidReturnValue(10, s), n = s);
}
return [n, function () {
for (var e = 0; e < r.length; e++) r[e].call(n);
}];
}
}(e, r);
}
};
};
}
function applyDecs2203R(e, t, r) {
return (module.exports = applyDecs2203R = applyDecs2203RFactory(), module.exports.__esModule = true, module.exports["default"] = module.exports)(e, t, r);
}
module.exports = applyDecs2203R, module.exports.__esModule = true, module.exports["default"] = module.exports;
+222
View File
@@ -0,0 +1,222 @@
var _typeof = require("./typeof.js")["default"];
var checkInRHS = require("./checkInRHS.js");
var setFunctionName = require("./setFunctionName.js");
var toPropertyKey = require("./toPropertyKey.js");
function applyDecs2301Factory() {
function createAddInitializerMethod(e, t) {
return function (r) {
!function (e) {
if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
}(t), assertCallable(r, "An initializer"), e.push(r);
};
}
function assertInstanceIfPrivate(e, t) {
if (!e(t)) throw new TypeError("Attempted to access private element on non-instance");
}
function memberDec(e, t, r, n, a, i, s, o, c) {
var u;
switch (a) {
case 1:
u = "accessor";
break;
case 2:
u = "method";
break;
case 3:
u = "getter";
break;
case 4:
u = "setter";
break;
default:
u = "field";
}
var l,
f,
p = {
kind: u,
name: s ? "#" + t : toPropertyKey(t),
"static": i,
"private": s
},
d = {
v: !1
};
if (0 !== a && (p.addInitializer = createAddInitializerMethod(n, d)), s || 0 !== a && 2 !== a) {
if (2 === a) l = function l(e) {
return assertInstanceIfPrivate(c, e), r.value;
};else {
var h = 0 === a || 1 === a;
(h || 3 === a) && (l = s ? function (e) {
return assertInstanceIfPrivate(c, e), r.get.call(e);
} : function (e) {
return r.get.call(e);
}), (h || 4 === a) && (f = s ? function (e, t) {
assertInstanceIfPrivate(c, e), r.set.call(e, t);
} : function (e, t) {
r.set.call(e, t);
});
}
} else l = function l(e) {
return e[t];
}, 0 === a && (f = function f(e, r) {
e[t] = r;
});
var v = s ? c.bind() : function (e) {
return t in e;
};
p.access = l && f ? {
get: l,
set: f,
has: v
} : l ? {
get: l,
has: v
} : {
set: f,
has: v
};
try {
return e(o, p);
} finally {
d.v = !0;
}
}
function assertCallable(e, t) {
if ("function" != typeof e) throw new TypeError(t + " must be a function");
}
function assertValidReturnValue(e, t) {
var r = _typeof(t);
if (1 === e) {
if ("object" !== r || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
void 0 !== t.get && assertCallable(t.get, "accessor.get"), void 0 !== t.set && assertCallable(t.set, "accessor.set"), void 0 !== t.init && assertCallable(t.init, "accessor.init");
} else if ("function" !== r) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
}
function curryThis2(e) {
return function (t) {
e(this, t);
};
}
function applyMemberDec(e, t, r, n, a, i, s, o, c) {
var u,
l,
f,
p,
d,
h,
v,
y,
g = r[0];
if (s ? (0 === a || 1 === a ? (u = {
get: (d = r[3], function () {
return d(this);
}),
set: curryThis2(r[4])
}, f = "get") : 3 === a ? (u = {
get: r[3]
}, f = "get") : 4 === a ? (u = {
set: r[3]
}, f = "set") : u = {
value: r[3]
}, 0 !== a && (1 === a && setFunctionName(u.set, "#" + n, "set"), setFunctionName(u[f || "value"], "#" + n, f))) : 0 !== a && (u = Object.getOwnPropertyDescriptor(t, n)), 1 === a ? p = {
get: u.get,
set: u.set
} : 2 === a ? p = u.value : 3 === a ? p = u.get : 4 === a && (p = u.set), "function" == typeof g) void 0 !== (h = memberDec(g, n, u, o, a, i, s, p, c)) && (assertValidReturnValue(a, h), 0 === a ? l = h : 1 === a ? (l = h.init, v = h.get || p.get, y = h.set || p.set, p = {
get: v,
set: y
}) : p = h);else for (var m = g.length - 1; m >= 0; m--) {
var b;
void 0 !== (h = memberDec(g[m], n, u, o, a, i, s, p, c)) && (assertValidReturnValue(a, h), 0 === a ? b = h : 1 === a ? (b = h.init, v = h.get || p.get, y = h.set || p.set, p = {
get: v,
set: y
}) : p = h, void 0 !== b && (void 0 === l ? l = b : "function" == typeof l ? l = [l, b] : l.push(b)));
}
if (0 === a || 1 === a) {
if (void 0 === l) l = function l(e, t) {
return t;
};else if ("function" != typeof l) {
var I = l;
l = function l(e, t) {
for (var r = t, n = 0; n < I.length; n++) r = I[n].call(e, r);
return r;
};
} else {
var w = l;
l = function l(e, t) {
return w.call(e, t);
};
}
e.push(l);
}
0 !== a && (1 === a ? (u.get = p.get, u.set = p.set) : 2 === a ? u.value = p : 3 === a ? u.get = p : 4 === a && (u.set = p), s ? 1 === a ? (e.push(function (e, t) {
return p.get.call(e, t);
}), e.push(function (e, t) {
return p.set.call(e, t);
})) : 2 === a ? e.push(p) : e.push(function (e, t) {
return p.call(e, t);
}) : Object.defineProperty(t, n, u));
}
function applyMemberDecs(e, t, r) {
for (var n, a, i, s = [], o = new Map(), c = new Map(), u = 0; u < t.length; u++) {
var l = t[u];
if (Array.isArray(l)) {
var f,
p,
d = l[1],
h = l[2],
v = l.length > 3,
y = d >= 5,
g = r;
if (y ? (f = e, 0 != (d -= 5) && (p = a = a || []), v && !i && (i = function i(t) {
return checkInRHS(t) === e;
}), g = i) : (f = e.prototype, 0 !== d && (p = n = n || [])), 0 !== d && !v) {
var m = y ? c : o,
b = m.get(h) || 0;
if (!0 === b || 3 === b && 4 !== d || 4 === b && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
!b && d > 2 ? m.set(h, d) : m.set(h, !0);
}
applyMemberDec(s, f, l, h, d, y, v, p, g);
}
}
return pushInitializers(s, n), pushInitializers(s, a), s;
}
function pushInitializers(e, t) {
t && e.push(function (e) {
for (var r = 0; r < t.length; r++) t[r].call(e);
return e;
});
}
return function (e, t, r, n) {
return {
e: applyMemberDecs(e, t, n),
get c() {
return function (e, t) {
if (t.length > 0) {
for (var r = [], n = e, a = e.name, i = t.length - 1; i >= 0; i--) {
var s = {
v: !1
};
try {
var o = t[i](n, {
kind: "class",
name: a,
addInitializer: createAddInitializerMethod(r, s)
});
} finally {
s.v = !0;
}
void 0 !== o && (assertValidReturnValue(10, o), n = o);
}
return [n, function () {
for (var e = 0; e < r.length; e++) r[e].call(n);
}];
}
}(e, r);
}
};
};
}
function applyDecs2301(e, t, r, n) {
return (module.exports = applyDecs2301 = applyDecs2301Factory(), module.exports.__esModule = true, module.exports["default"] = module.exports)(e, t, r, n);
}
module.exports = applyDecs2301, module.exports.__esModule = true, module.exports["default"] = module.exports;
+133
View File
@@ -0,0 +1,133 @@
var _typeof = require("./typeof.js")["default"];
var checkInRHS = require("./checkInRHS.js");
var setFunctionName = require("./setFunctionName.js");
var toPropertyKey = require("./toPropertyKey.js");
function applyDecs2305(e, t, r, n, o, a) {
function i(e, t, r) {
return function (n, o) {
return r && r(n), e[t].call(n, o);
};
}
function c(e, t) {
for (var r = 0; r < e.length; r++) e[r].call(t);
return t;
}
function s(e, t, r, n) {
if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined"));
return e;
}
function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) {
function m(e) {
if (!h(e)) throw new TypeError("Attempted to access private element on non-instance");
}
var y,
v = t[0],
g = t[3],
b = !u;
if (!b) {
r || Array.isArray(v) || (v = [v]);
var w = {},
S = [],
A = 3 === o ? "get" : 4 === o || d ? "set" : "value";
f ? (p || d ? w = {
get: setFunctionName(function () {
return g(this);
}, n, "get"),
set: function set(e) {
t[4](this, e);
}
} : w[A] = g, p || setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n));
}
for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) {
var D = v[j],
E = r ? v[j - 1] : void 0,
I = {},
O = {
kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
name: n,
metadata: a,
addInitializer: function (e, t) {
if (e.v) throw Error("attempted to call addInitializer after decoration was finished");
s(t, "An initializer", "be", !0), c.push(t);
}.bind(null, I)
};
try {
if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else {
var k, F;
O["static"] = l, O["private"] = f, f ? 2 === o ? k = function k(e) {
return m(e), w.value;
} : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function k(e) {
return e[n];
}, (o < 2 || 4 === o) && (F = function F(e, t) {
e[n] = t;
}));
var N = O.access = {
has: f ? h.bind() : function (e) {
return n in e;
}
};
if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? {
get: w.get,
set: w.set
} : w[A], O), d) {
if ("object" == _typeof(P) && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
} else s(P, (p ? "field" : "method") + " decorators", "return") && (p ? S.push(P) : w[A] = P);
}
} finally {
I.v = !0;
}
}
return (p || d) && u.push(function (e, t) {
for (var r = S.length - 1; r >= 0; r--) t = S[r].call(e, t);
return t;
}), p || b || (f ? d ? u.push(i(w, "get"), i(w, "set")) : u.push(2 === o ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e, n, w)), P;
}
function u(e, t) {
return Object.defineProperty(e, Symbol.metadata || Symbol["for"]("Symbol.metadata"), {
configurable: !0,
enumerable: !0,
value: t
});
}
if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol["for"]("Symbol.metadata")];
var f = Object.create(null == l ? null : l),
p = function (e, t, r, n) {
var o,
a,
i = [],
s = function s(t) {
return checkInRHS(t) === e;
},
u = new Map();
function l(e) {
e && i.push(c.bind(null, e));
}
for (var f = 0; f < t.length; f++) {
var p = t[f];
if (Array.isArray(p)) {
var d = p[1],
h = p[2],
m = p.length > 3,
y = 16 & d,
v = !!(8 & d),
g = 0 == (d &= 7),
b = h + "/" + v;
if (!g && !m) {
var w = u.get(b);
if (!0 === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h);
u.set(b, !(d > 2) || d);
}
applyDec(v ? e : e.prototype, p, y, m ? "#" + h : toPropertyKey(h), d, n, v ? a = a || [] : o = o || [], i, v, m, g, 1 === d, v && m ? s : r);
}
}
return l(o), l(a), i;
}(e, t, o, f);
return r.length || u(e, f), {
e: p,
get c() {
var t = [];
return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t), f), c.bind(null, t, e)];
}
};
}
module.exports = applyDecs2305, module.exports.__esModule = true, module.exports["default"] = module.exports;
+124
View File
@@ -0,0 +1,124 @@
var _typeof = require("./typeof.js")["default"];
var checkInRHS = require("./checkInRHS.js");
var setFunctionName = require("./setFunctionName.js");
var toPropertyKey = require("./toPropertyKey.js");
function applyDecs2311(e, t, n, r, o, i) {
var a,
c,
u,
s,
f,
l,
p,
d = Symbol.metadata || Symbol["for"]("Symbol.metadata"),
m = Object.defineProperty,
h = Object.create,
y = [h(null), h(null)],
v = t.length;
function g(t, n, r) {
return function (o, i) {
n && (i = o, o = e);
for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []);
return r ? i : o;
};
}
function b(e, t, n, r) {
if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
return e;
}
function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
function d(e) {
if (!p(e)) throw new TypeError("Attempted to access private element on non-instance");
}
var h = [].concat(t[0]),
v = t[3],
w = !u,
D = 1 === o,
S = 3 === o,
j = 4 === o,
E = 2 === o;
function I(t, n, r) {
return function (o, i) {
return n && (i = o, o = e), r && r(o), P[t].call(o, i);
};
}
if (!w) {
var P = {},
k = [],
F = S ? "get" : j || D ? "set" : "value";
if (f ? (l || D ? P = {
get: setFunctionName(function () {
return v(this);
}, r, "get"),
set: function set(e) {
t[4](this, e);
}
} : P[F] = v, l || setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
if ((c = y[+s][r]) && 7 !== (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
y[+s][r] = o < 3 ? 1 : o;
}
}
for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
var T = b(h[O], "A decorator", "be", !0),
z = n ? h[O - 1] : void 0,
A = {},
H = {
kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
name: r,
metadata: a,
addInitializer: function (e, t) {
if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
b(t, "An initializer", "be", !0), i.push(t);
}.bind(null, A)
};
if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);else if (H["static"] = s, H["private"] = f, c = H.access = {
has: f ? p.bind() : function (e) {
return r in e;
}
}, j || (c.get = f ? E ? function (e) {
return d(e), P.value;
} : I("get", 0, d) : function (e) {
return e[r];
}), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
e[r] = t;
}), N = T.call(z, D ? {
get: P.get,
set: P.set
} : P[F], H), A.v = 1, D) {
if ("object" == _typeof(N) && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
} else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
}
return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
}
function w(e) {
return m(e, d, {
configurable: !0,
enumerable: !0,
value: a
});
}
return void 0 !== i && (a = i[d]), a = h(null == a ? null : a), f = [], l = function l(e) {
e && f.push(g(e));
}, p = function p(t, r) {
for (var i = 0; i < n.length; i++) {
var a = n[i],
c = a[1],
l = 7 & c;
if ((8 & c) == t && !l == r) {
var p = a[2],
d = !!a[3],
m = 16 & c;
applyDec(t ? e : e.prototype, a, m, d ? "#" + p : toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) {
return checkInRHS(t) === e;
} : o);
}
}
}, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
e: c,
get c() {
var n = [];
return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
}
};
}
module.exports = applyDecs2311, module.exports.__esModule = true, module.exports["default"] = module.exports;
+6
View File
@@ -0,0 +1,6 @@
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
+4
View File
@@ -0,0 +1,4 @@
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
+5
View File
@@ -0,0 +1,5 @@
var arrayLikeToArray = require("./arrayLikeToArray.js");
function _arrayWithoutHoles(r) {
if (Array.isArray(r)) return arrayLikeToArray(r);
}
module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
+5
View File
@@ -0,0 +1,5 @@
function _assertClassBrand(e, t, n) {
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
throw new TypeError("Private element is not present on this object");
}
module.exports = _assertClassBrand, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,5 @@
function _assertThisInitialized(e) {
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return e;
}
module.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports["default"] = module.exports;
+24
View File
@@ -0,0 +1,24 @@
var OverloadYield = require("./OverloadYield.js");
function _asyncGeneratorDelegate(t) {
var e = {},
n = !1;
function pump(e, r) {
return n = !0, r = new Promise(function (n) {
n(t[e](r));
}), {
done: !1,
value: new OverloadYield(r, 1)
};
}
return e["undefined" != typeof Symbol && Symbol.iterator || "@@iterator"] = function () {
return this;
}, e.next = function (t) {
return n ? (n = !1, t) : pump("next", t);
}, "function" == typeof t["throw"] && (e["throw"] = function (t) {
if (n) throw n = !1, t;
return pump("throw", t);
}), "function" == typeof t["return"] && (e["return"] = function (t) {
return n ? (n = !1, t) : pump("return", t);
}), e;
}
module.exports = _asyncGeneratorDelegate, module.exports.__esModule = true, module.exports["default"] = module.exports;
+45
View File
@@ -0,0 +1,45 @@
function _asyncIterator(r) {
var n,
t,
o,
e = 2;
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
if (t && null != (n = r[t])) return n.call(r);
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
t = "@@asyncIterator", o = "@@iterator";
}
throw new TypeError("Object is not async iterable");
}
function AsyncFromSyncIterator(r) {
function AsyncFromSyncIteratorContinuation(r) {
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
var n = r.done;
return Promise.resolve(r.value).then(function (r) {
return {
value: r,
done: n
};
});
}
return AsyncFromSyncIterator = function AsyncFromSyncIterator(r) {
this.s = r, this.n = r.next;
}, AsyncFromSyncIterator.prototype = {
s: null,
n: null,
next: function next() {
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
},
"return": function _return(r) {
var n = this.s["return"];
return void 0 === n ? Promise.resolve({
value: r,
done: !0
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
},
"throw": function _throw(r) {
var n = this.s["return"];
return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
}
}, new AsyncFromSyncIterator(r);
}
module.exports = _asyncIterator, module.exports.__esModule = true, module.exports["default"] = module.exports;
+26
View File
@@ -0,0 +1,26 @@
function asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c),
u = i.value;
} catch (n) {
return void e(n);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function () {
var t = this,
e = arguments;
return new Promise(function (r, o) {
var a = n.apply(t, e);
function _next(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
}
function _throw(n) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
}
_next(void 0);
});
};
}
module.exports = _asyncToGenerator, module.exports.__esModule = true, module.exports["default"] = module.exports;
+5
View File
@@ -0,0 +1,5 @@
var OverloadYield = require("./OverloadYield.js");
function _awaitAsyncGenerator(e) {
return new OverloadYield(e, 0);
}
module.exports = _awaitAsyncGenerator, module.exports.__esModule = true, module.exports["default"] = module.exports;
+7
View File
@@ -0,0 +1,7 @@
var getPrototypeOf = require("./getPrototypeOf.js");
var isNativeReflectConstruct = require("./isNativeReflectConstruct.js");
var possibleConstructorReturn = require("./possibleConstructorReturn.js");
function _callSuper(t, o, e) {
return o = getPrototypeOf(o), possibleConstructorReturn(t, isNativeReflectConstruct() ? Reflect.construct(o, e || [], getPrototypeOf(t).constructor) : o.apply(t, e));
}
module.exports = _callSuper, module.exports.__esModule = true, module.exports["default"] = module.exports;
+6
View File
@@ -0,0 +1,6 @@
var _typeof = require("./typeof.js")["default"];
function _checkInRHS(e) {
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? _typeof(e) : "null"));
return e;
}
module.exports = _checkInRHS, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,4 @@
function _checkPrivateRedeclaration(e, t) {
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
}
module.exports = _checkPrivateRedeclaration, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,10 @@
function _classApplyDescriptorDestructureSet(e, t) {
if (t.set) return "__destrObj" in t || (t.__destrObj = {
set value(r) {
t.set.call(e, r);
}
}), t.__destrObj;
if (!t.writable) throw new TypeError("attempted to set read only private field");
return t;
}
module.exports = _classApplyDescriptorDestructureSet, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,4 @@
function _classApplyDescriptorGet(e, t) {
return t.get ? t.get.call(e) : t.value;
}
module.exports = _classApplyDescriptorGet, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,7 @@
function _classApplyDescriptorSet(e, t, l) {
if (t.set) t.set.call(e, l);else {
if (!t.writable) throw new TypeError("attempted to set read only private field");
t.value = l;
}
}
module.exports = _classApplyDescriptorSet, module.exports.__esModule = true, module.exports["default"] = module.exports;
+4
View File
@@ -0,0 +1,4 @@
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
module.exports = _classCallCheck, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,5 @@
var assertClassBrand = require("./assertClassBrand.js");
function _classCheckPrivateStaticAccess(s, a, r) {
return assertClassBrand(a, s, r);
}
module.exports = _classCheckPrivateStaticAccess, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,4 @@
function _classCheckPrivateStaticFieldDescriptor(t, e) {
if (void 0 === t) throw new TypeError("attempted to " + e + " private static field before its declaration");
}
module.exports = _classCheckPrivateStaticFieldDescriptor, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,5 @@
var classPrivateFieldGet2 = require("./classPrivateFieldGet2.js");
function _classExtractFieldDescriptor(e, t) {
return classPrivateFieldGet2(t, e);
}
module.exports = _classExtractFieldDescriptor, module.exports.__esModule = true, module.exports["default"] = module.exports;

Some files were not shown because too many files have changed in this diff Show More