npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fm-gofer

v1.10.0

Published

Framework for calling FileMaker scripts from a webviewer and retrieving results using callback promises.

Downloads

213

Readme

fm-gofer

Promises in FM Web Viewers!

It's like fetch() for FileMaker! Go'fer some data. Call FileMaker scripts from JavaScript in a web viewer and get the response back using async/await.

Try it

Check out ./example/FMGofer.fmp12. This example demostrates the callback, resolve, reject, and timeout capabilities of the library. You can rebuild the example code used in the fm file by running npm run build && npm run build:example. This will output an html file in example/dist/index.html, which can be used in a FM webviewer.

Install fm-gofer in your JS project

npm install --save fm-gofer

Usage

Import fm-gofer

import syntax

import FMGofer, { Option } from 'fm-gofer';

require syntax

const FMGofer = require('fm-gofer');
const { Option } = FMGofer;

Via CDN for convenience

<!-- This will set a global window property FMGofer -->
<script src="https://unpkg.com/fm-gofer/dist/fm-gofer.umd.cjs"></script>

Or copy into yout HTML if you really want

<script>
  // This will set a global window property FMGofer
  (copy of ./dist/fm-gofer.umd.cjs)
</script>

Use fm-gofer

In your JS

import FMGofer, { Option } from 'fm-gofer';

const a = await FMGofer.PerformScript('FM Script', param);
// use the Option enum to specify the script option in human-readable form:
const b = await FMGofer.PerformScriptWithOption(
  'FM Script',
  param,
  Option.SuspendAndResume
);

// Set a custom timeout/timeout message if the default to wait indefinitely is too long
import FMGofer, { Option } from 'fm-gofer';

const c = await FMGofer.PerformScript('FM Script', param, 5000, 'timed out!');
const d = await FMGofer.PerformScriptWithOption(
  'FM Script',
  param,
  Option.SuspendAndResume,
  5000,
  'timed out!'
);

// or set the timeout to zero to wait forever
const e = await FMGofer.PerformScript('FM Script', param, 0);

In your FileMaker script

To return data to JS, extract callbackName and promiseID from Get ( ScriptParameter ), and use it to call back to JS and resolve/reject the promise. Pass True as the last param ("failed") to reject the promise.

Set Variable [ $callbackName ; JSONGetElement ( Get(ScriptParameter) ; "callbackName" ) ]
Set Variable [ $promiseID ; JSONGetElement ( Get(ScriptParameter) ; "promiseID" ) ]
# this contains param data sent from JS
Set Variable [ $parameter ; JSONGetElement ( Get(ScriptParameter) ; "parameter" ) ]

# callback to JS like: $callbackName($promiseID, <dataToReturn>, <trueToReject>)
# (leave the third argument empty or False to indicate a success. Or set to True to indicate an error)
Perform JavaScript in Web Viewer [ Object Name: "myWebview" ; Function Name: $callbackName ; Parameters: $promiseID, 'Success! Hello from FM!' ]

TypeScript support

// You can assert the shape of the result returned from FM using typescript!
interface MyResult {
  name: string;
  age: number;
}
const j = await FMGofer.PerformScript('FM Script', param).json<MyResult>();
// Nested properties auto-complete in VSCode now!
const name = j.name;
const age = j.age;

MISC

Test

npm test

Build

npm run build

Contribute

If you see anything that should be improved please feel free to let me know or send pull requests.