@latitude-data/source-manager
Advanced tools
Comparing version 0.1.0 to 0.1.1
# @latitude-data/source-manager | ||
## 0.1.1 | ||
### Patch Changes | ||
- 61916ed: fixes regression that caused nested queries to not be found | ||
## 0.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -13,3 +13,6 @@ import 'dotenv/config'; | ||
*/ | ||
loadFromQuery(query: string): Promise<Source>; | ||
loadFromQuery(query: string): Promise<{ | ||
source: Source; | ||
sourceFilePath: string; | ||
}>; | ||
/** | ||
@@ -16,0 +19,0 @@ * Loads a source from a source configuration file |
@@ -204,11 +204,14 @@ import 'dotenv/config'; | ||
} | ||
const sourceFile = await findSourceConfigFromQuery({ | ||
const sourceFilePath = await findSourceConfigFromQuery({ | ||
query, | ||
queriesDir: this.queriesDir, | ||
}); | ||
if (!this.instances[sourceFile]) { | ||
const config = readSourceConfig(sourceFile); | ||
this.instances[sourceFile] = new Source(sourceFile, config); | ||
if (!this.instances[sourceFilePath]) { | ||
const config = readSourceConfig(sourceFilePath); | ||
this.instances[sourceFilePath] = new Source(sourceFilePath, config); | ||
} | ||
return this.instances[sourceFile]; | ||
return { | ||
source: this.instances[sourceFilePath], | ||
sourceFilePath: sourceFilePath, | ||
}; | ||
} | ||
@@ -215,0 +218,0 @@ /** |
{ | ||
"name": "@latitude-data/source-manager", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "LGPL", | ||
@@ -5,0 +5,0 @@ "description": "Manage Latitude sources", |
@@ -50,6 +50,6 @@ import { it, describe, beforeEach, afterEach, expect, vi } from 'vitest' | ||
expect(readFileSpy).toHaveBeenCalledOnce() // Only read config file once | ||
expect(connector1).toBe(connector2) | ||
expect(connector1.source).toBe(connector2.source) | ||
await connector1.compileQuery({ queryPath: query1Path }) | ||
await connector1.compileQuery({ queryPath: query2Path }) | ||
await connector1.source.compileQuery({ queryPath: query1Path }) | ||
await connector1.source.compileQuery({ queryPath: query2Path }) | ||
expect(mockCreateConnector).toHaveBeenCalledOnce() // Only instanced once | ||
@@ -83,3 +83,3 @@ }) | ||
const sourceManager = new SourceManager('/path/to/queries') | ||
const connector = await sourceManager.loadFromQuery('query') | ||
const { source: connector } = await sourceManager.loadFromQuery('query') | ||
expect(connector).toBeDefined() | ||
@@ -90,4 +90,4 @@ }) | ||
const sourceManager = new SourceManager('/path/to/queries') | ||
const connector = await sourceManager.loadFromQuery('query') | ||
const nestedConnector = | ||
const { source: connector } = await sourceManager.loadFromQuery('query') | ||
const { source: nestedConnector } = | ||
await sourceManager.loadFromQuery('nestedQuery/query') | ||
@@ -101,4 +101,4 @@ expect(connector).toBeDefined() | ||
const sourceManager = new SourceManager('/path/to/queries') | ||
const connector = await sourceManager.loadFromQuery('query') | ||
const nestedConnector = | ||
const { source: connector } = await sourceManager.loadFromQuery('query') | ||
const { source: nestedConnector } = | ||
await sourceManager.loadFromQuery('nestedSource/query') | ||
@@ -105,0 +105,0 @@ expect(connector).toBeDefined() |
@@ -27,3 +27,5 @@ import 'dotenv/config' | ||
*/ | ||
async loadFromQuery(query: string): Promise<Source> { | ||
async loadFromQuery( | ||
query: string, | ||
): Promise<{ source: Source; sourceFilePath: string }> { | ||
const filePath = path.join( | ||
@@ -44,3 +46,3 @@ this.queriesDir, | ||
const sourceFile = await findSourceConfigFromQuery({ | ||
const sourceFilePath = await findSourceConfigFromQuery({ | ||
query, | ||
@@ -50,8 +52,11 @@ queriesDir: this.queriesDir, | ||
if (!this.instances[sourceFile]) { | ||
const config = readSourceConfig(sourceFile) | ||
this.instances[sourceFile] = new Source(sourceFile, config) | ||
if (!this.instances[sourceFilePath]) { | ||
const config = readSourceConfig(sourceFilePath) | ||
this.instances[sourceFilePath] = new Source(sourceFilePath, config) | ||
} | ||
return this.instances[sourceFile]! | ||
return { | ||
source: this.instances[sourceFilePath]!, | ||
sourceFilePath: sourceFilePath, | ||
} | ||
} | ||
@@ -58,0 +63,0 @@ |
@@ -24,2 +24,8 @@ import { describe, it, expect, afterEach, beforeEach } from 'vitest' | ||
'query.sql': 'Some nested query', | ||
nnested: { | ||
'source.yml': 'Nested source config file', | ||
sql: { | ||
'test.sql': 'Some very nested query', | ||
}, | ||
}, | ||
}, | ||
@@ -39,3 +45,3 @@ }, | ||
it('finds the correct source config file from any query', async () => { | ||
it('finds the correct source config file from root query', async () => { | ||
const result = await findSourceConfigFromQuery({ | ||
@@ -45,2 +51,8 @@ queriesDir: ROOT_FOLDER, | ||
}) | ||
const sourcePath = `${ROOT_FOLDER}/valid/source.yml` | ||
expect(result).toEqual(sourcePath) | ||
}) | ||
it('finds correct source config from nested query', async () => { | ||
const sourcePath = `${ROOT_FOLDER}/valid/source.yml` | ||
const nestedResult = await findSourceConfigFromQuery({ | ||
@@ -50,7 +62,17 @@ queriesDir: ROOT_FOLDER, | ||
}) | ||
const sourcePath = `${ROOT_FOLDER}/valid/source.yml` | ||
expect(result).toEqual(sourcePath) | ||
expect(nestedResult).toEqual(sourcePath) | ||
}) | ||
it('finds correct nexted source config from nested query', async () => { | ||
const veryNestedResult = await findSourceConfigFromQuery({ | ||
queriesDir: ROOT_FOLDER, | ||
query: 'valid/nested/nnested/sql/test', | ||
}) | ||
expect(veryNestedResult).toEqual( | ||
`${ROOT_FOLDER}/valid/nested/nnested/source.yml`, | ||
) | ||
}) | ||
it('should throw a QueryNotFoundError if the .sql file does not exist', async () => { | ||
@@ -57,0 +79,0 @@ await expect( |
@@ -55,3 +55,3 @@ import { it, describe, beforeEach, afterEach, expect, vi } from 'vitest' | ||
it('initializes with the correct path and config', async () => { | ||
const source = await sourceManager.loadFromQuery('query') | ||
const { source } = await sourceManager.loadFromQuery('query') | ||
@@ -64,3 +64,3 @@ expect(source.path).toBe(`${QUERIES_DIR}/source.yml`) | ||
it('does not instantiate the connector until it is needed', async () => { | ||
const source = await sourceManager.loadFromQuery('query') | ||
const { source } = await sourceManager.loadFromQuery('query') | ||
expect(mockCreateConnector).not.toHaveBeenCalled() | ||
@@ -73,3 +73,3 @@ | ||
it('reuses the same connector for multiple queries', async () => { | ||
const source = await sourceManager.loadFromQuery('query') | ||
const { source } = await sourceManager.loadFromQuery('query') | ||
await source.compileQuery({ queryPath: 'query', params: {} }) | ||
@@ -82,3 +82,3 @@ await source.compileQuery({ queryPath: 'nested/query', params: {} }) | ||
it('returns the source config when compiling a query', async () => { | ||
const source = await sourceManager.loadFromQuery('query') | ||
const { source } = await sourceManager.loadFromQuery('query') | ||
const compiledQuery = await source.compileQuery({ | ||
@@ -94,3 +94,3 @@ queryPath: 'query', | ||
fs.writeFileSync(`${QUERIES_DIR}/query.sql`, `{@config ttl = 12345}`) | ||
const source = await sourceManager.loadFromQuery('query') | ||
const { source } = await sourceManager.loadFromQuery('query') | ||
const compiledQuery = await source.compileQuery({ | ||
@@ -97,0 +97,0 @@ queryPath: 'query', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69087
1091