generated from Ed-Fi-Exchange-OSS/Template-for-GitHub
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62d4cb2
commit 654abfa
Showing
15 changed files
with
337 additions
and
288 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Meadowlark-js/packages/meadowlark-core/src/api-schema/ApiSchemaLoader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import { writeDebugMessage, writeErrorToLog } from '../Logger'; | ||
import { ApiSchema, NoApiSchema } from '../model/api-schema/ApiSchema'; | ||
import { TraceId } from '../model/IdTypes'; | ||
import { ProjectNamespace } from '../model/api-schema/ProjectNamespace'; | ||
|
||
const moduleName = 'ApiSchemaFinder'; | ||
|
||
const dataStandard50pre1Path: string = path.resolve(__dirname, '../ds-schemas/DataStandard-5.0.0-pre.1.json'); | ||
|
||
export const projectNamespaceEdfi: ProjectNamespace = 'ed-fi' as ProjectNamespace; | ||
|
||
/** | ||
* This is a simple cache implementation that works in Lambdas, see: https://rewind.io/blog/simple-caching-in-aws-lambda-functions/ | ||
*/ | ||
let apiSchemaCache: ApiSchema | null = null; | ||
|
||
/** | ||
* Loads ApiSchema from an ApiSchema JSON file | ||
*/ | ||
async function loadApiSchemaFromFile(filePath: string, traceId: TraceId): Promise<ApiSchema> { | ||
const apiSchema: ApiSchema = (await fs.readJson(filePath)) as ApiSchema; | ||
apiSchemaCache = apiSchema; | ||
writeDebugMessage(moduleName, 'loadApiSchemaFromFile', traceId, `Loading ApiSchema from ${filePath}`); | ||
return apiSchema; | ||
} | ||
|
||
/** | ||
* Entry point for loading ApiSchemas from a file | ||
*/ | ||
export async function findApiSchema(traceId: TraceId): Promise<ApiSchema> { | ||
if (apiSchemaCache != null) return apiSchemaCache; | ||
|
||
try { | ||
return await loadApiSchemaFromFile(dataStandard50pre1Path, traceId); | ||
} catch (e) { | ||
writeErrorToLog(moduleName, traceId, 'getApiSchema', e); | ||
} | ||
return NoApiSchema; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.