diff --git a/.gitignore b/.gitignore index 8b605a0..24d7f74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -.nyc_output/ +/.nyc_output/ node_modules/ -build/ -coverage/ -lib/ -types/ -test/fixtures/access-denied.tpl +/build/ +/coverage/ +/lib/ +/types/ +/test/fixtures/access-denied.tpl diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d853582 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,38 @@ +sudo: false +notifications: + email: + on_success: never + on_failure: always +language: node_js +branches: + only: + - master + - /^v\d+\.\d+\.\d+$/ +stages: + - test + - deploy +jobs: + include: + - stage: test + node_js: 10 + script: ./scripts/test.bash :unit + - stage: test + node_js: 8 + before_script: npm install coveralls + script: + - ./scripts/test.bash :coverage + - ./scripts/lint.bash + after_script: nyc report --reporter=text-lcov | coveralls + - stage: deploy + node_js: 8 + skip_cleanup: true + script: ./scripts/build.bash + deploy: + provider: npm + email: mitmaro@gmail.com + skip_cleanup: true + api_key: + secure: "CMpOGrptULWS3VnGi8slkp6Wf3FlSVJRfsvJmQgOExF+sq19yctF33jXg0cfRPbjDZSxVzdq0PR4py+6AspMTuo0AQVT4XhKOIYARPE8POsUPv0z88Ik8r5tKhbIDiwvdvhxPqBV1iI1jWK9rMNduOibSCJpEr3F4jd/yajsUjePvj3kO11ic6JtyjIqIQ9Et6bHtMbD0Hnhd+na8wGKdVJYWx6CSGtHB1dNK8gKwDyfZa/itlGSBFGBno1K2yI9LoOAAHilt/bMGwZ2EjjljQEhdqAUUn7xMUVPt30EPt0K8rzcLoUOZGCwmEG8sa0Rk9VDS6pmHQFu9WTxIquLfiVkLnB4KQd7OdxIh0z9BM+2Ho+wZSXulgHoRkkEa3VvwEee5le6IbayAbBLkDt0o8g+qHmvC2nMDkUxxwmjlLjJtaI3pi+UyYyI9sCRcDHfTyZlJ4N4rjnN9piWGeL/9i+Oo977hNDwTFjlVUfY5B9fQ7uJ6mhaLJKVsFVDfnq2g5Y5ENJ5WXCQKPPyATvN2EKxbHqNYdDMDancA+hVT7CmDI13fGT+YDLMvoLp4Yjh6D7ziVb2SSnKTnJhulpeNZ/B+h7VQX/STD0D5JrbAMicplNkbN6Ej5X1lZQUAZ8c8uPocAgZKx0cYVk98XBC67C7OOhnLt+LOZaBfz02yCY=" + on: + tags: true + repo: MitMaro/node-sql-template-engine diff --git a/package.json b/package.json index 61eb6db..ea9cb49 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,26 @@ { - "name": "sql-templates", - "version": "0.0.1", + "name": "@mitmaro/sql-template-engine", + "version": "0.1.0", "description": "A SQL template engine", - "main": "src/index.js", + "main": "lib/index.js", + "files": [ + "lib", + "types" + ], "directories": { "test": "test" }, + "types": "types/index.d.ts", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git@github.com:MitMaro/node-sql-template-engine.git" + }, + "engines": { + "node": ">= 8" + }, "scripts": { "build": "scripts/build.bash", "build:docs": "scripts/docs.bash", @@ -14,7 +29,7 @@ "test:unit": "scripts/test.bash :unit", "test:coverage": "scripts/test.bash :coverage" }, - "author": "Tim Oram ", + "author": "Tim Oram ", "license": "ISC", "devDependencies": { "@mitmaro/build-scripts": "^0.1.5", diff --git a/src/lib/memory-cache.ts b/src/lib/memory-cache.ts new file mode 100644 index 0000000..54686dc --- /dev/null +++ b/src/lib/memory-cache.ts @@ -0,0 +1,25 @@ +import {AbstractSyntaxTree} from '../abstract-syntax-tree'; +import {AbstractSyntaxTreeCache} from '../abstract-syntax-tree-cache'; + +/** + * Create an in-memory cache for the compiled templates + * @returns A cache instance + */ +export function createMemoryCache(): AbstractSyntaxTreeCache { + const cache = new Map(); + + return { + /** + * Get or create a value for the key + * @param key The key of this entry + * @param factory A function to call to create the value if it is missing + * @returns Resolves with the compiled template as an abstract syntax tree + */ + async entry(key: string, factory: () => Promise): Promise { + if (!cache.has(key)) { + cache.set(key, await factory()); + } + return cache.get(key)!; + }, + }; +}