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

@latitude-data/sql-compiler

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@latitude-data/sql-compiler

Compiler for Latitude's custom sql sintax based on svelte

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-71.74%
Maintainers
4
Weekly downloads
 
Created
Source

import { emptyMetadata, readMetadata } from '..' import CompileError from '../error/error' import { describe, it, expect, beforeEach, vi } from 'vitest'

describe('config tags', async () => { it('extracts defined configurations correctly', async () => { const query = {@config foo = 5} {@config bar = "foo"} {@config baz = true} Rest of the query const { config } = await readMetadata({ query })

expect(config).toEqual({
  foo: 5,
  bar: 'foo',
  baz: true,
})

})

it('fails when a config tag is not at root level', async () => { const query = {#if true} {@config foo = 5} {/if}

try {
  await readMetadata({ query })
} catch (e) {
  expect(e).toBeInstanceOf(CompileError)
  expect((e as CompileError).code).toBe('config-inside-block')
}

})

it('fails when a config tag is not a valid assignment expression', async () => { const query = {@config foo 5}

try {
  await readMetadata({ query })
} catch (e) {
  expect(e).toBeInstanceOf(CompileError)
  expect((e as CompileError).code).toBe('invalid-config-args')
}

})

it('fails when a config value is not a literal', async () => { const query = {@config foo = 5 + 5}

try {
  await readMetadata({ query })
} catch (e) {
  expect(e).toBeInstanceOf(CompileError)
  expect((e as CompileError).code).toBe('invalid-config-value')
}

})

it('fails when a config is already defined', async () => { const query = {@config foo = 5} {@config foo = 10} try { await readMetadata({ query }) } catch (e) { expect(e).toBeInstanceOf(CompileError) expect((e as CompileError).code).toBe('config-already-defined') } }) })

describe('supported methods', async () => { function mockSupportedMethod() { return { requirements: {}, resolve: vi.fn(() => Promise.resolve()), readMetadata: vi.fn(() => Promise.resolve(emptyMetadata())), } }

beforeEach(() => { vi.clearAllMocks() })

it('extracts supported methods present in the query correctly', async () => { const query = {foo()} {bar()} {baz()}

const supportedMethods = {
  foo: mockSupportedMethod(),
  bar: mockSupportedMethod(),
}

const { methods } = await readMetadata({ query, supportedMethods })
expect(methods).toContain('foo')
expect(methods).toContain('bar')

})

it('does not extract method calls that are not from supported methods', async () => { const query = {foo()} {bar()} {baz()} const supportedMethods = { foo: mockSupportedMethod(), }

const { methods } = await readMetadata({ query, supportedMethods })
expect(methods).toContain('foo')
expect(methods).not.toContain('bar')
expect(methods).not.toContain('baz')

})

it('does not extract supported methods that are not present in the query', async () => { const query = {foo()} const supportedMethods = { foo: mockSupportedMethod(), bar: mockSupportedMethod(), }

const { methods } = await readMetadata({ query, supportedMethods })
expect(methods).toContain('foo')
expect(methods).not.toContain('bar')

})

it('does not actually run extracted methods', async () => { const query = {foo()} const supportedMethods = { foo: mockSupportedMethod(), bar: mockSupportedMethod(), }

const { methods } = await readMetadata({ query, supportedMethods })
expect(methods).toContain('foo')
expect(supportedMethods.foo.resolve).not.toHaveBeenCalled()

}) })

FAQs

Package last updated on 10 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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