Skip to content

Commit

Permalink
fix: template engine
Browse files Browse the repository at this point in the history
PR: #14
  • Loading branch information
gurza authored Oct 28, 2023
2 parents bec8061 + 4938ef0 commit 210202f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@esseswann/lev",
"version": "0.0.12",
"version": "0.0.13",
"repository": {
"urL": "git+https://github.com/esseswann/lev.git",
"type": "git"
Expand All @@ -13,7 +13,7 @@
"lib",
"package.json",
"README.md"
],
],
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
Expand Down Expand Up @@ -47,4 +47,4 @@
"ydb-codegen": "0.2.7",
"ydb-sdk": "5.1.1"
}
}
}
4 changes: 3 additions & 1 deletion src/metadata/compileTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export const compileTemplates = (
) => {
const matches = template.content.matchAll(IMPORT_REGEX)
const result = extractSections(template.content)
let compiledTemplates = ''
for (const match of matches) {
const compiled = compileTemplate(templates, new Set(path), match[1])
if (compiled) {
result.declares = mergeDeclares(result.declares, compiled.declares)
result.body = compiled.body + result.body
compiledTemplates += compiled.body
}
}
result.body = compiledTemplates + result.body
return result
}

Expand Down
3 changes: 3 additions & 0 deletions tests/metadata/basicTemplates/templates/access.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- import connection.sql

$access = 'access';
5 changes: 4 additions & 1 deletion tests/metadata/basicTemplates/templates/role.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
-- import connection.sql

declare $input as Struct<
from: Optional<Datetime>,
to: Optional<Datetime>,
limit: Optional<Uint64>
>;

declare $kek as Optional<List<Struct< test: Utf8, plest: Utf8 >>>;declare $role as Utf8
declare $kek as Optional<List<Struct< test: Utf8, plest: Utf8 >>>;declare $role as Utf8;

$role = 'role';
1 change: 1 addition & 0 deletions tests/metadata/basicTemplates/views/view.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- import role.sql
-- import access.sql

select $role;
2 changes: 1 addition & 1 deletion tests/metadata/compileView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('compile view', () => {
for await (const { result } of compileViews(viewsPath, templatesPath))
views.push(result)
const targetViews = [
'declare $connectionId as Utf8;declare $role as Utf8;declare $kek as Optional<List<Struct<test:Utf8,plest:Utf8>>>;declare $input as Struct<from:Optional<Datetime>,to:Optional<Datetime>,limit:Optional<Uint64>>;select $connectionId;select $role;'
`declare $connectionId as Utf8;declare $role as Utf8;declare $kek as Optional<List<Struct<test:Utf8,plest:Utf8>>>;declare $input as Struct<from:Optional<Datetime>,to:Optional<Datetime>,limit:Optional<Uint64>>;select $connectionId;$role = 'role';$access = 'access';select $role;`
]
expect(views).toEqual(targetViews)
})
Expand Down

0 comments on commit 210202f

Please sign in to comment.