Giter Site home page Giter Site logo

jwillinghalpern / fm-gofer Goto Github PK

View Code? Open in Web Editor NEW
13.0 6.0 2.0 1.76 MB

An easy fetch-like promise library for FileMaker WebViewer apps and widgets.

License: ISC License

JavaScript 0.60% HTML 7.80% CSS 12.96% TypeScript 71.55% Dockerfile 7.09%
filemaker filemaker-scripts browser webviewer filemaker-webviewer-apps javascript javascript-library

fm-gofer's People

Contributors

jwillinghalpern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

ayescas

fm-gofer's Issues

fm-mock.d.ts' is not a module.

I'm seeing this in Problems in VSCode:
File '/Volumes/Macintosh HD/Users/JoshStorage/Downloads/wv-codes/node_modules/fm-mock/dist/fm-mock.d.ts' is not a module.

consider removing trycatch in runCallback

Think more about this. The main reason I added this was so it would be obvious when you misconfigure your callback. For example if you pass in a non-existent callback id, then the promise variable will return undefined. Then promise.timeoutID will throw an error because you can't get a property of undefined.

We should add an explicit error message for when typeof promise === 'undefined'.

Then decide if we should actually log an error and alert(), or if we should let the exception bubble up.

Missing promiseID shouldn't show an alert dialog

This behavior is useful when you're developing but it can be disruptive in production.

For example, if you webviewer app calls a FM script onload, if you're flipping through records quickly, the FM script called by the WV on one record could theoretically try to callback to a webviewer instance on a different record. This will result in frequent error alerts saying the supplied promiseID couldn't be found.

Maybe just console.log instead.

Consider making this toggleable

add suggestions to default timeout message

"The FM script call timed out"

Consider mentioning the optional timeout param directly in this message so developers can try increasing that value for slow FM scripts.

functionToCall typed wrong

mockScript should be typed more like:

 export declare function mockScript(scriptName: string, functionToCall: (param: string) => void): void;

research whether we should use a named export

I keep seeing mention of named vs default exports as they relate to webpack/rollup tree shaking. If memory serves treeshaking requires named exports by default. Anyway, just something to check.

Support AbortController to cancel requests

It would be nice to be able to cancel a request made to filemaker, if for example a React useEffect hook initiates a request but the component is then unmounted. We could use the abort controller to tell FMGofer to stop waiting for a response and prevent it from logging the timeout error in the console. I.e. cancel the promise.

Reference article from Fabio: https://spencerfeng.medium.com/create-an-abortable-api-using-abortcontroller-and-abortsignal-d774bed40701

Output filename

It might be better to name it something like fm-gofer.umd.js and fm-gofer.cjs.js instead of "main".

This wouldn't matter in an nom context where you use the module name, but for using the umd in a script tag src attribute, a descriptive name would be preferable.

Write tests

Look into some kind of test coverage analyzer tool. "Coveralls"?

Rename

Change all code that references the old name.

Export type for the parameter that fm-gofer sends to FileMaker scripts

That way, when using fm-gofer and fm-mock together, you can declare the parameter passed into the mock FM script and it makes writing mocks easier, with more autocomplete.

One thing... I'm not sure if you can declare a type for a stringified JSON object and validate the various keys.

Reading this thread, this might be a bit beyond my current grasp of Typescript.

Add support for new `options` parameter syntax

Ideally we'd remain backward compatibility by overloading the call signature. something like:

/**
 * @enum {number}
 * @member Default - Default is same as Continue.
 * @member Continue - After a currently running FileMaker script has completed, queued FileMaker scripts are run in order. If FileMaker script execution is canceled, the queue is cleared. (This is the behavior if option is not specified. This is also the default behavior for FileMaker.PerformScript().)
 * @member Halt - Execution of a currently running FileMaker script is halted, and all other pending scripts (queued or in the call stack) are canceled. Then script is run.
 * @member Exit - A currently paused FileMaker script is exited. If the current FileMaker script was called by another FileMaker script, control returns to the calling FileMaker script until no more scripts remain in the call stack. Then script is run.
 * @member Resume - A paused FileMaker script is resumed. After the resumed script is completed, script is run.
 * @member Pause - A paused FileMaker script remains paused. If the paused script is resumed and completed, then script is run.
 * @member Suspend - and Resume A currently running FileMaker script is suspended and script is run. When script is completed, the suspended script resumes with the next script step. A paused script remains paused while script is run.
 */
export enum ScriptOption {
	Default = 0,
	Continue = 0,
	Halt = 1,
	Exit = 2,
	Resume = 3,
	Pause = 4,
	SuspendAndResume = 5,
}

ScriptOption.Halt
type ScriptOptionString = '0' | '1' | '2' | '3' | '4' | '5';

interface FMGoferType {
	PerformScript (script: string, options: {
		parameter?: any,
		option?: ScriptOption | ScriptOptionString,
		timeoutMs?: number,
		timeoutMessage?: string,
	})
}

// extend window with FMGofer
declare global {
	interface Window {
		FMGofer: FMGoferType
	}
}

window.FMGofer.PerformScript('hello world', {
	option: ScriptOption.Halt,
	parameter: 'hello world',
	timeoutMs: 1000,
	timeoutMessage: 'oh no!',
})

FileMaker interface should have more detailed types for PerformScript and PSWO

current (ok):

interface Window {
        FileMaker: {
            PerformScript: Function;
            PerformScriptWithOption: Function;
        };

proposed (better):

interface Window {
        FileMaker: {
            PerformScript: (scriptName: string, parameter?: string) => void;
            PerformScriptWithOption: (scriptName: string, parameter?: string, timeoutInSeconds?: number | string) => void;
        };

use generic to type the FMGofer response?

FMGofer.PerformScript<T>

I'm not sure if this is possible since types are compiled away, but maybe the type could also tell FMGofer whether it should try to parse the response automatically or not. I don't think that's possible, just spitballing. Even if not, I still like the idea.

export GoferParam interface

Something like this should appear in fm-gofer.d.ts

export interface GoferParam {
    parameter?: any;
    callbackName: string;
    promiseID: string;
}

The point is so that in projects that use fm-gofer and fm-mock together, you can type the params passed to your mock functions. If you're not using fm-mock, it doesn't matter because no JS functions will receive the input of FMGofer, only the FM script called will.

This is more for me than anyone else.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.