Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@getlang/get

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@getlang/get - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

26

dist/errors.d.ts
export declare abstract class RuntimeError extends Error {
name: string;
constructor(...args: any[]);
}
export declare class FatalError extends RuntimeError {
name: string;
constructor(...args: any[]);
constructor(options?: ErrorOptions);
}
export declare class SyntaxError extends RuntimeError {
export declare class GetSyntaxError extends RuntimeError {
name: string;
}
export declare class TypeError extends RuntimeError {
export declare class GetTypeError extends RuntimeError {
name: string;

@@ -17,31 +15,31 @@ }

name: string;
constructor(...args: any[]);
constructor(options?: ErrorOptions);
}
export declare class SliceSyntaxError extends RuntimeError {
name: string;
constructor(...args: any[]);
constructor(options?: ErrorOptions);
}
export declare class ConversionError extends RuntimeError {
name: string;
constructor(type: string, ...args: any[]);
constructor(type: string, options?: ErrorOptions);
}
export declare class SelectorSyntaxError extends RuntimeError {
name: string;
constructor(type: string, selector: string, ...args: any[]);
constructor(type: string, selector: string, options?: ErrorOptions);
}
export declare class NullSelectionError extends RuntimeError {
name: string;
constructor(selector: string, ...args: any[]);
constructor(selector: string, options?: ErrorOptions);
}
export declare class NullInputError extends RuntimeError {
name: string;
constructor(inputName: string, ...args: any[]);
constructor(inputName: string, options?: ErrorOptions);
}
export declare class RequestError extends RuntimeError {
name: string;
constructor(url: string, ...args: any[]);
constructor(url: string, options?: ErrorOptions);
}
export declare class ReferenceError extends RuntimeError {
export declare class GetReferenceError extends RuntimeError {
name: string;
constructor(varName: string, ...args: any[]);
constructor(varName: string, options?: ErrorOptions);
}

@@ -48,0 +46,0 @@ export declare class ImportError extends RuntimeError {

export class RuntimeError extends Error {
name = 'RuntimeError';
constructor(...args) {
super(...args);
// workaround: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, RuntimeError.prototype);
}
}
export class FatalError extends RuntimeError {
name = 'FatalError';
constructor(...args) {
super('A fatal runtime error occurred', ...args);
constructor(options) {
super('A fatal runtime error occurred', options);
}
}
export class SyntaxError extends RuntimeError {
export class GetSyntaxError extends RuntimeError {
name = 'SyntaxError';
}
export class TypeError extends RuntimeError {
export class GetTypeError extends RuntimeError {
name = 'TypeError';

@@ -23,4 +17,4 @@ }

name = 'SliceError';
constructor(...args) {
super('An exception was thrown by the client-side slice', ...args);
constructor(options) {
super('An exception was thrown by the client-side slice', options);
}

@@ -30,4 +24,4 @@ }

name = 'SliceSyntaxError';
constructor(...args) {
super('Could not parse slice', ...args);
constructor(options) {
super('Could not parse slice', options);
}

@@ -37,4 +31,4 @@ }

name = 'ConversionError';
constructor(type, ...args) {
super(`Attempted to convert unsupported type to value: ${type}`, ...args);
constructor(type, options) {
super(`Attempted to convert unsupported type to value: ${type}`, options);
}

@@ -44,4 +38,4 @@ }

name = 'SelectorSyntaxError';
constructor(type, selector, ...args) {
super(`Could not parse ${type} selector '${selector}'`, ...args);
constructor(type, selector, options) {
super(`Could not parse ${type} selector '${selector}'`, options);
}

@@ -51,4 +45,4 @@ }

name = 'NullSelectionError';
constructor(selector, ...args) {
super(`The selector '${selector}' did not produce a result`, args);
constructor(selector, options) {
super(`The selector '${selector}' did not produce a result`, options);
}

@@ -58,4 +52,4 @@ }

name = 'NullInputError';
constructor(inputName, ...args) {
super(`Required input '${inputName}' not provided`, ...args);
constructor(inputName, options) {
super(`Required input '${inputName}' not provided`, options);
}

@@ -65,10 +59,10 @@ }

name = 'RequestError';
constructor(url, ...args) {
super(`Request to url failed: ${url}`, ...args);
constructor(url, options) {
super(`Request to url failed: ${url}`, options);
}
}
export class ReferenceError extends RuntimeError {
export class GetReferenceError extends RuntimeError {
name = 'ReferenceError';
constructor(varName, ...args) {
super(`Unable to locate variable: ${varName}`, ...args);
constructor(varName, options) {
super(`Unable to locate variable: ${varName}`, options);
}

@@ -81,4 +75,4 @@ }

if (!condition) {
throw typeof err === 'string' ? new FatalError(err) : err;
throw typeof err === 'string' ? new FatalError({ cause: err }) : err;
}
}

@@ -1,2 +0,2 @@

import type { Program } from '../ast/ast';
import type { Program } from '@getlang/parser';
import * as http from './net/http';

@@ -3,0 +3,0 @@ export type InternalHooks = {

@@ -1,7 +0,5 @@

import { visit, SKIP } from '../ast/visitor';
import { NodeKind, t } from '../ast/ast';
import { createToken } from '../ast/desugar/utils';
import { visit, SKIP, NodeKind, t, createToken } from '@getlang/parser';
import { RootScope } from './scope';
import * as type from './value';
import { invariant, NullSelectionError, ReferenceError, SyntaxError, ImportError, } from '../errors';
import { invariant, NullSelectionError, GetReferenceError, GetSyntaxError, ImportError, } from '../errors';
import * as http from './net/http';

@@ -21,3 +19,4 @@ import * as html from './values/html';

import(module) {
return (this.cache[module] ??= this.importHook(module));
this.cache[module] ??= this.importHook(module);
return this.cache[module];
}

@@ -30,24 +29,22 @@ get(module) {

function toValue(value) {
if (value instanceof type.Html) {
if (value instanceof type.HtmlValue) {
return html.getValue(value.raw);
}
else if (value instanceof type.Js) {
if (value instanceof type.JsValue) {
return js.getValue(value.raw);
}
else if (value instanceof type.Headers) {
if (value instanceof type.HeadersValue) {
return Object.fromEntries(value.raw);
}
else if (value instanceof type.CookieSet) {
if (value instanceof type.CookieSetValue) {
return Object.fromEntries(Object.entries(value.raw).map(e => [e[0], e[1].value]));
}
else if (value instanceof type.List) {
if (value instanceof type.ListValue) {
return value.raw.map(item => toValue(item));
}
else {
return value.raw;
}
return value.raw;
}
export async function execute(program, inputs, hooks, modules = new Modules(hooks.import)) {
const scope = new RootScope();
let optional = [false];
const optional = [false];
const allowNull = () => optional.at(-1) === true;

@@ -67,3 +64,3 @@ const visitor = {

const external = await modules.get(module);
invariant(external, new ReferenceError(module));
invariant(external, new GetReferenceError(module));
const output = await execute(external, node.args.raw, hooks, modules);

@@ -76,12 +73,12 @@ return new type.Value(output, null);

LiteralExpr(node) {
return new type.String(node.value.value, null);
return new type.StringValue(node.value.value, null);
},
TemplateExpr(node) {
const { elements: els } = node;
return new type.String(els.map(v => v.raw).join(''), (els.length === 1 && els[0]?.base) || null, els.some(v => v.raw === null || v.raw === undefined));
return new type.StringValue(els.map(v => v.raw).join(''), (els.length === 1 && els[0]?.base) || null, els.some(v => v.raw === null || v.raw === undefined));
},
IdentifierExpr(node) {
const value = scope.vars[node.value.value];
invariant(value, new ReferenceError(node.value.value));
if (value instanceof type.Null) {
invariant(value, new GetReferenceError(node.value.value));
if (value instanceof type.NullValue) {
invariant(allowNull(), new NullSelectionError(value.selector));

@@ -96,3 +93,3 @@ }

return value === null
? new type.Null(fauxSelector)
? new type.NullValue(fauxSelector)
: new type.Value(value, null);

@@ -103,9 +100,9 @@ },

// ensure simplified ast
invariant(node.target !== 'context', new SyntaxError('Unresolved context drill'));
invariant(node.target !== 'context', new GetSyntaxError('Unresolved context drill'));
const context = await visit(node.target);
if (context instanceof type.Null) {
if (context instanceof type.NullValue) {
invariant(allowNull(), new NullSelectionError(context.selector));
return context;
}
const isListContext = context instanceof type.List;
const isListContext = context instanceof type.ListValue;
const isSelector = node.bit.kind === NodeKind.TemplateExpr;

@@ -126,3 +123,3 @@ if ((node.expand && !isSelector) || isListContext) {

}
return new type.List(values, context.base);
return new type.ListValue(values, context.base);
}

@@ -142,3 +139,3 @@ scope.pushContext(context);

const { context } = scope;
invariant(context, new ReferenceError('Modifier failed to locate context'));
invariant(context, new GetReferenceError('Modifier failed to locate context'));
const doc = toValue(context);

@@ -148,19 +145,19 @@ invariant(typeof doc === 'string', new TypeError('Modifier requires string input'));

case 'html':
return new type.Html(html.parse(doc), context.base);
return new type.HtmlValue(html.parse(doc), context.base);
case 'js':
return new type.Js(js.parse(doc), context.base);
return new type.JsValue(js.parse(doc), context.base);
case 'json':
return new type.Value(json.parse(doc), context.base);
case 'cookies':
return new type.CookieSet(cookies.parse(doc), context.base);
return new type.CookieSetValue(cookies.parse(doc), context.base);
case 'link': {
const resolved = http.constructUrl(context.raw, context.base ?? undefined);
if (resolved) {
return new type.String(resolved, null);
return new type.StringValue(resolved, null);
}
invariant(allowNull(), new NullSelectionError('@link'));
return new type.Null('@link');
return new type.NullValue('@link');
}
default:
throw new ReferenceError(`Unsupported modifier: ${mod}`);
throw new GetReferenceError(`Unsupported modifier: ${mod}`);
}

@@ -176,4 +173,4 @@ },

optional.pop();
invariant(key instanceof type.String, new TypeError('Only string keys are supported'));
if (value instanceof type.Null) {
invariant(key instanceof type.StringValue, new TypeError('Only string keys are supported'));
if (value instanceof type.NullValue) {
continue;

@@ -244,3 +241,3 @@ }

const res = await http.request(method, url, headers, blocks, body, hooks.request);
scope.pushContext(new type.Value({ ...res, headers: new type.Headers(res.headers, url) }, url));
scope.pushContext(new type.Value({ ...res, headers: new type.HeadersValue(res.headers, url) }, url));
},

@@ -247,0 +244,0 @@ },

export declare const runSlice: (slice: string, context?: Record<string, unknown>) => Promise<any>;
export declare const selectInput: (input: any, inputName: string, optional: boolean) => any;
export declare const selectInput: (input: Record<string, unknown>, inputName: string, optional: boolean) => any;

@@ -1,2 +0,1 @@

/// <reference types="node" />
import type { Element } from 'domhandler';

@@ -3,0 +2,0 @@ type StringMap = Record<string, string>;

@@ -40,5 +40,5 @@ import { RequestError } from '../../errors';

if (blocks.query) {
Object.entries(blocks.query).forEach(entry => {
for (const entry of Object.entries(blocks.query)) {
finalUrl.searchParams.append(...entry);
});
}
}

@@ -45,0 +45,0 @@ const urlString = finalUrl.toString();

@@ -1,2 +0,2 @@

import { invariant, ReferenceError } from '../errors';
import { invariant, GetReferenceError } from '../errors';
class Scope {

@@ -15,3 +15,3 @@ vars;

const scope = this.scopeStack.at(-1);
invariant(scope, new ReferenceError('Corrupted scope stack'));
invariant(scope, new GetReferenceError('Corrupted scope stack'));
return scope;

@@ -38,2 +38,3 @@ }

else {
// biome-ignore lint/performance/noDelete: remove shadow value
delete this.vars[''];

@@ -40,0 +41,0 @@ }

@@ -7,3 +7,3 @@ import * as html from './values/html';

import * as type from './value';
import { invariant, TypeError } from '../errors';
import { invariant, GetTypeError } from '../errors';
function selectValue(ValueType, fn, context, ...args) {

@@ -13,22 +13,22 @@ const result = fn(context.raw, ...args);

if (expand) {
invariant(Array.isArray(result), new TypeError('Expanding selector encountered non-array'));
return new type.List(result.map(x => new ValueType(x, context.base)), context.base);
invariant(Array.isArray(result), new GetTypeError('Expanding selector encountered non-array'));
return new type.ListValue(result.map(x => new ValueType(x, context.base)), context.base);
}
else if (result !== undefined) {
if (result !== undefined) {
return new ValueType(result, context.base);
}
return new type.Null(args[0]);
return new type.NullValue(args[0]);
}
export function select(context, ...args) {
if (context instanceof type.Html) {
return selectValue(type.Html, html.select, context, ...args);
if (context instanceof type.HtmlValue) {
return selectValue(type.HtmlValue, html.select, context, ...args);
}
else if (context instanceof type.Js) {
return selectValue(type.Js, js.select, context, ...args);
if (context instanceof type.JsValue) {
return selectValue(type.JsValue, js.select, context, ...args);
}
else if (context instanceof type.Headers) {
return selectValue(type.String, headers.select, context, ...args);
if (context instanceof type.HeadersValue) {
return selectValue(type.StringValue, headers.select, context, ...args);
}
else if (context instanceof type.CookieSet) {
return selectValue(type.String, cookies.select, context, ...args);
if (context instanceof type.CookieSetValue) {
return selectValue(type.StringValue, cookies.select, context, ...args);
}

@@ -35,0 +35,0 @@ const result = selectValue(type.Value, json.select, context, ...args);

@@ -1,2 +0,1 @@

/// <reference types="node" />
import type { AnyHtmlNode } from 'domhandler';

@@ -11,3 +10,3 @@ import type { AnyNode as AnyJsNode } from 'acorn';

}
export declare class String extends Value {
export declare class StringValue extends Value {
raw: string;

@@ -17,19 +16,19 @@ _hasUndefined: boolean;

}
export declare class Html extends Value {
export declare class HtmlValue extends Value {
raw: AnyHtmlNode;
constructor(raw: AnyHtmlNode, base: string | null);
}
export declare class Js extends Value {
export declare class JsValue extends Value {
raw: AnyJsNode;
constructor(raw: AnyJsNode, base: string | null);
}
export declare class Headers extends Value {
raw: globalThis.Headers;
constructor(raw: globalThis.Headers, base: string | null);
export declare class HeadersValue extends Value {
raw: Headers;
constructor(raw: Headers, base: string | null);
}
export declare class CookieSet extends Value {
export declare class CookieSetValue extends Value {
raw: CookieMap;
constructor(raw: CookieMap, base: string | null);
}
export declare class Null extends Value {
export declare class NullValue extends Value {
selector: string;

@@ -39,5 +38,5 @@ raw: null;

}
export declare class List<T extends Value> extends Value {
export declare class ListValue<T extends Value> extends Value {
raw: T[];
constructor(raw: T[], base: string | null);
}

@@ -9,6 +9,6 @@ export class Value {

get hasUndefined() {
return this instanceof String && this._hasUndefined;
return this instanceof StringValue && this._hasUndefined;
}
}
export class String extends Value {
export class StringValue extends Value {
raw;

@@ -22,3 +22,3 @@ _hasUndefined;

}
export class Html extends Value {
export class HtmlValue extends Value {
raw;

@@ -30,3 +30,3 @@ constructor(raw, base) {

}
export class Js extends Value {
export class JsValue extends Value {
raw;

@@ -38,3 +38,3 @@ constructor(raw, base) {

}
export class Headers extends Value {
export class HeadersValue extends Value {
raw;

@@ -46,3 +46,3 @@ constructor(raw, base) {

}
export class CookieSet extends Value {
export class CookieSetValue extends Value {
raw;

@@ -54,3 +54,3 @@ constructor(raw, base) {

}
export class Null extends Value {
export class NullValue extends Value {
selector;

@@ -63,3 +63,3 @@ raw = null;

}
export class List extends Value {
export class ListValue extends Value {
raw;

@@ -66,0 +66,0 @@ constructor(raw, base) {

import * as scp from 'set-cookie-parser';
import { NullSelectionError, SyntaxError, invariant } from '../../errors';
import { NullSelectionError, GetSyntaxError, invariant } from '../../errors';
export const parse = (from) => {

@@ -8,3 +8,3 @@ const cookie = scp.splitCookiesString(from);

export const select = (cookies, path, expand, allowNull) => {
invariant(!expand, new SyntaxError('Cannot expand cookies selector'));
invariant(!expand, new GetSyntaxError('Cannot expand cookies selector'));
const result = cookies[path]?.value;

@@ -11,0 +11,0 @@ if (result !== undefined) {

@@ -1,3 +0,2 @@

/// <reference types="node" />
import type { SelectFn } from './types';
export declare const select: SelectFn<Headers, string>;

@@ -10,3 +10,3 @@ import { NullSelectionError, invariant } from '../../errors';

}
else if (result !== null) {
if (result !== null) {
return result;

@@ -13,0 +13,0 @@ }

@@ -23,3 +23,3 @@ import { parse as parse5 } from 'parse5';

// Document -> HtmlElement
const html = el.childNodes.find(x => x.nodeType === 1 && x.name == 'html');
const html = el.childNodes.find(x => x.nodeType === 1 && x.name === 'html');
invariant(html, new NullSelectionError(selector));

@@ -32,3 +32,3 @@ root = html;

}
else if (result.length) {
if (result.length) {
return result[0];

@@ -49,3 +49,3 @@ }

}
else if (result !== null) {
if (result !== null) {
return result;

@@ -52,0 +52,0 @@ }

@@ -13,3 +13,3 @@ import { parse as acorn } from 'acorn';

}
else if (matches.length) {
if (matches.length) {
return matches[0];

@@ -16,0 +16,0 @@ }

@@ -1,9 +0,5 @@

import { desugar } from './ast/simplified';
import { print } from './ast/print';
import type { Program } from './ast/ast';
import type { Program } from '@getlang/parser';
import type { InternalHooks } from './execute/execute';
export type { Program };
export { NodeKind } from './ast/ast';
export { RuntimeError } from './errors';
declare function parse(source: string): Program;
export * as errors from './errors';
export type RequestHook = InternalHooks['request'];

@@ -15,4 +11,3 @@ export type ImportHook = (module: string) => string | Promise<string>;

}>;
declare function execute(source: string, inputs?: Record<string, unknown>, hooks?: Hooks): Promise<unknown>;
declare function executeAST(ast: Program, inputs?: Record<string, unknown>, hooks?: Hooks): Promise<unknown>;
export { parse, desugar, execute, print, executeAST };
export declare function execute(source: string, inputs?: Record<string, unknown>, hooks?: Hooks): Promise<unknown>;
export declare function executeAST(ast: Program, inputs?: Record<string, unknown>, hooks?: Hooks): Promise<unknown>;

@@ -1,28 +0,8 @@

import nearley from 'nearley';
import grammar from './grammar';
import lexer from './parse/lexer';
import { desugar } from './ast/simplified';
import { print } from './ast/print';
import { wait } from '@getlang/utils';
import { parse, desugar } from '@getlang/parser';
import { execute as exec } from './execute/execute';
import * as http from './execute/net/http';
import { SyntaxError, ImportError, invariant } from './errors';
import { wait } from './utils';
export { NodeKind } from './ast/ast';
import { ImportError } from './errors';
export { RuntimeError } from './errors';
function parse(source) {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
try {
parser.feed(source);
}
catch (e) {
if (typeof e === 'object' && e && 'token' in e) {
throw new SyntaxError(lexer.formatError(e.token, 'SyntaxError: Invalid token'));
}
throw e;
}
const { results } = parser;
invariant(results.length !== 0, new SyntaxError('Unexpected end of input'));
invariant(results.length === 1, new SyntaxError('Unexpected parsing error'));
return results[0];
}
export * as errors from './errors';
function buildHooks(hooks = {}) {

@@ -39,3 +19,3 @@ return {

}
function execute(source, inputs = {}, hooks) {
export function execute(source, inputs = {}, hooks) {
const ast = parse(source);

@@ -45,5 +25,4 @@ const simplified = desugar(ast);

}
function executeAST(ast, inputs = {}, hooks) {
export function executeAST(ast, inputs = {}, hooks) {
return exec(ast, inputs, buildHooks(hooks));
}
export { parse, desugar, execute, print, executeAST };
{
"name": "@getlang/get",
"version": "0.0.6",
"version": "0.0.7",
"license": "Apache-2.0",
"type": "module",
"main": "dist",
"files": [
"dist"
],
"files": ["dist"],
"bugs": {

@@ -15,8 +13,10 @@ "url": "https://github.com/getlang-dev/get/issues"

"type": "git",
"url": "git+https://github.com/getlang-dev/get.git"
"url": "git+https://github.com/getlang-dev/get.git",
"directory": "packages/get"
},
"dependencies": {
"@getlang/parser": "workspace:*",
"@getlang/utils": "workspace:*",
"@getlang/xpath": "0.0.35-0",
"acorn": "^8.12.0",
"acorn-globals": "^7.0.1",
"css-select": "^5.1.0",

@@ -28,37 +28,11 @@ "css-what": "^6.1.0",

"esquery": "^1.5.0",
"globals": "^15.6.0",
"lodash-es": "^4.17.21",
"moo": "^0.5.2",
"nearley": "^2.20.1",
"parse5": "^7.1.2",
"parse5-htmlparser2-tree-adapter": "^7.0.0",
"prettier": "^3.3.2",
"set-cookie-parser": "^2.6.0"
},
"devDependencies": {
"@types/estree": "^1.0.5",
"@types/lodash-es": "^4.17.12",
"@types/moo": "^0.5.9",
"@types/nearley": "^2.11.5",
"@types/node": "^20.14.6",
"@types/set-cookie-parser": "^2.4.9",
"dedent": "^1.5.3",
"tsx": "^4.15.6",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vitest": "^1.6.0"
},
"prettier": {
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "avoid"
},
"scripts": {
"compile": "nearleyc src/parse/getlang.ne -o src/grammar.ts",
"railroad": "nearley-railroad src/parse/getlang.ne -o grammar.html && open grammar.html",
"test": "pnpm compile && tsx src",
"typecheck": "tsc --noEmit -p src",
"build": "tsc -p src"
"@types/set-cookie-parser": "^2.4.9"
}
}
}
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./assets/hero.dark.png">
<img alt="GETlang hero banner" src="./assets/hero.png">
<source media="(prefers-color-scheme: dark)" srcset="../../assets/hero.dark.png">
<img alt="GETlang hero banner" src="../../assets/hero.png">
</picture>
Visit [getlang.dev](https://getlang.dev) to view examples, take a guided tour, or try your first GET query!
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc