|
| 1 | +import { util } from '../index.js'; |
| 2 | +import * as rds from '../rds/index.js'; |
| 3 | +import * as dynamodb from '../dynamodb/index.js'; |
| 4 | + |
| 5 | +class Namespace { |
| 6 | + constructor(name, obj) { |
| 7 | + this.name = name; |
| 8 | + this.obj = obj; |
| 9 | + } |
| 10 | +}; |
| 11 | + |
| 12 | +const partialImplementations = { |
| 13 | + 'util.appendError': { |
| 14 | + message: "the function exists but errors are not yet captured", |
| 15 | + }, |
| 16 | +}; |
| 17 | + |
| 18 | +// ns must be a Namespace type |
| 19 | +function evaluateNamespace(ns) { |
| 20 | + for (const [key, value] of Object.entries(ns.obj)) { |
| 21 | + switch (typeof value) { |
| 22 | + case 'function': { |
| 23 | + const qualifiedName = `${ns.name}.${key}`; |
| 24 | + let message = `* \`${qualifiedName}\``; |
| 25 | + if (partialImplementations[qualifiedName] !== undefined) { |
| 26 | + const partialDescription = partialImplementations[qualifiedName].message; |
| 27 | + message = `${message} _(partial, ${partialDescription})_`; |
| 28 | + } else { |
| 29 | + }; |
| 30 | + console.log(message); |
| 31 | + break; |
| 32 | + }; |
| 33 | + case "object": { |
| 34 | + const newNs = new Namespace(`${ns.name}.${key}`, value); |
| 35 | + evaluateNamespace(newNs); |
| 36 | + break; |
| 37 | + }; |
| 38 | + default: { |
| 39 | + console.error(`Unhandled type ${typeof value}`); |
| 40 | + break; |
| 41 | + }; |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function printImportMessage(text) { |
| 47 | + console.log(` |
| 48 | +Assuming the following import: |
| 49 | +
|
| 50 | +\`\`\`javascript |
| 51 | +${text} |
| 52 | +\`\`\` |
| 53 | + `); |
| 54 | +} |
| 55 | + |
| 56 | +printImportMessage(`import { util } from '@aws-appsync/utils'`); |
| 57 | +evaluateNamespace(new Namespace("util", util)); |
| 58 | + |
| 59 | +printImportMessage(`import * as rds from '@aws-appsync/utils/rds'`); |
| 60 | +evaluateNamespace(new Namespace("rds", rds)); |
| 61 | + |
| 62 | +printImportMessage(`import * as dynamodb from '@aws-appsync/utils/dynamodb'`); |
| 63 | +evaluateNamespace(new Namespace("dynamodb", dynamodb)); |
| 64 | + |
0 commit comments