Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build: node_modules
# Generate the .d.ts files
node_modules/.bin/tsc --project tsconfig.json --checkJs false --emitDeclarationOnly || true
# TODO: Loop through everything in the lib folder to create the flow types
flowgen --add-flow-header lib/runtimeHelpers.d.ts --output-file lib/runtimeHelpers.js.flow
yarn flowgen --add-flow-header lib/runtimeHelpers.d.ts --output-file lib/runtimeHelpers.js.flow

.PHONY: test
test: build venv node_modules
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@
"files": [
"lib",
"schema.json"
]
],
"engines": {
"node": ">=10"
}
}
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface GlobalConfig {
resources: any;
}

interface BatchResourceConfig {
export interface BatchResourceConfig {
isBatchResource: true;
batchKey: string;
newKey: string;
Expand All @@ -27,7 +27,7 @@ interface BatchResourceConfig {
isResponseDictionary?: boolean;
}

interface NonBatchResourceConfig {
export interface NonBatchResourceConfig {
isBatchResource: false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/genTypeFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const resourceReference = (resourcePath: ReadonlyArray<string>) => ['resources',
*/
export function getResourceTypeReference(resourceConfig: ResourceConfig, resourcePath: ReadonlyArray<string>) {
function toPropertyTypePath(path: ReadonlyArray<string>): string {
assert(path.length >= 1);
assert(path.length >= 1, 'expected resource path to be a not empty array');

if (path.length === 1) {
return path[0];
Expand Down Expand Up @@ -63,7 +63,7 @@ export function getLoaderTypeVal(resourceConfig: ResourceConfig, resourcePath: R
>`;

if (resourceConfig.isBatchResource) {
retVal = `$ElementType<${retVal}, 0>`;
retVal = resourceConfig.isResponseDictionary ? `$Values<${retVal}>` : `$ElementType<${retVal}, 0>`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch that this needs fixing :)

}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/implementation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResourceConfig } from './config';
import { ResourceConfig, BatchResourceConfig, NonBatchResourceConfig } from './config';
import assert from './assert';
import { getLoaderTypeKey, getLoaderTypeVal } from './genTypeFlow';

Expand Down Expand Up @@ -27,7 +27,7 @@ function getLoaderComment(resourceConfig: ResourceConfig, resourcePath: Readonly
`;
}

function getBatchLoader(resourceConfig: ResourceConfig, resourcePath: ReadonlyArray<string>) {
function getBatchLoader(resourceConfig: BatchResourceConfig, resourcePath: ReadonlyArray<string>) {
assert(
resourceConfig.isBatchResource === true,
`${errorPrefix(resourcePath)} Expected getBatchLoader to be called with a batch resource config`,
Expand Down Expand Up @@ -355,7 +355,7 @@ function getBatchLoader(resourceConfig: ResourceConfig, resourcePath: ReadonlyAr
)`;
}

function getNonBatchLoader(resourceConfig: ResourceConfig, resourcePath: ReadonlyArray<string>) {
function getNonBatchLoader(resourceConfig: NonBatchResourceConfig, resourcePath: ReadonlyArray<string>) {
assert(
resourceConfig.isBatchResource === false,
`${errorPrefix(resourcePath)} Expected getNonBatchLoader to be called with a non-batch endpoint config`,
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import codegen from './codegen';
import { getConfig } from './config';

interface CLIArgs {
config?: string;
output?: string;
config: string;
output: string;
}

function writeLoaders(args: CLIArgs) {
const config = getConfig(args.config);
const output = codegen(config);

assert(typeof args.config === 'string', 'expected args.config to be set!');
assert(typeof args.output === 'string', 'expected args.output to be set!');
fs.writeFileSync(args.output, output);
}

Expand Down
3 changes: 2 additions & 1 deletion src/runtimeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ export function sortByKeys<V>({

itemsMap.set(String(reorderResultsByValue), item);
} else {
// TODO: Work how to tell typescript item[prop] exists
// @ts-ignore: TODO: Work how to tell typescript item[prop] exists
invariant(item[prop] != null, `${errorPrefix(resourcePath)} Could not find property "${prop}" in item`);
// @ts-ignore: TODO: Work how to tell typescript item[prop] exists
itemsMap.set(String(item[prop]), item);
}
});
Expand Down