Skip to content

Commit

Permalink
feat: create npm package
Browse files Browse the repository at this point in the history
- Use tsdx to set up an npm package
- Use quicktype to generate typescript types for context schemas
- Reorganize API type files, create root fdc3 module (index.ts)
- Add some placeholder tests
- Remove old svg in footerimg
- Remove old examples
  • Loading branch information
rikoe committed Oct 5, 2020
1 parent 56d2868 commit e162dd2
Show file tree
Hide file tree
Showing 27 changed files with 10,504 additions and 368 deletions.
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# http://editorconfig.org

# A special property that should be specified at the top of the file outside of
# any sections. Set to true to stop .editor config file search on current file
root = true

[*]
# Indentation style
# Possible values - tab, space
indent_style = space

# Indentation size in single-spaced characters
# Possible values - an integer, tab
indent_size = 2

# Line ending file format
# Possible values - lf, crlf, cr
end_of_line = lf

# File character encoding
# Possible values - latin1, utf-8, utf-16be, utf-16le
charset = utf-8

# Denotes whether to trim whitespace at the end of lines
# Possible values - true, false
trim_trailing_whitespace = true

# Denotes whether file should end with a newline
# Possible values - true, false
insert_final_newline = true
38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ["10.x", "12.x", "14.x"]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: yarn lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2

- name: Build
run: yarn build
12 changes: 12 additions & 0 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: size
on: [pull_request]
jobs:
size:
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.log
.DS_Store

node_modules
dist

lib/core/metadata.js
lib/core/MetadataBlog.js
Expand Down
15 changes: 0 additions & 15 deletions examples/intents/application_example.json

This file was deleted.

24 changes: 0 additions & 24 deletions footerimg/finos_wordmark.svg

This file was deleted.

57 changes: 57 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@finos/fdc3",
"version": "1.1.0-alpha.1",
"author": "Fintech Open Source Foundation (FINOS)",
"repository": "git@github.com:finos/FDC3.git",
"license": "Apache-2.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/fdc3.esm.js",
"files": [
"dist",
"src"
],
"engines": {
"node": ">=10"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
"analyze": "size-limit --why",
"typegen": "cd src/context && quicktype -s schema --src-urls schemas.json -o ContextTypes.ts"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"semi": true,
"singleQuote": true,
"arrowParens": "avoid"
},
"size-limit": [
{
"path": "dist/fdc3.cjs.production.min.js",
"limit": "10 KB"
},
{
"path": "dist/fdc3.esm.js",
"limit": "10 KB"
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^4.6.0",
"husky": "^4.3.0",
"quicktype": "^15.0.258",
"size-limit": "^4.6.0",
"tsdx": "^0.14.0",
"tslib": "^2.0.1",
"typescript": "^4.0.3"
}
}
15 changes: 9 additions & 6 deletions src/api/AppIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* Copyright 2019 FINOS FDC3 contributors - see NOTICE file
*/

import { AppMetadata } from './AppMetadata';
import { IntentMetadata } from './IntentMetadata';

/**
* An interface that relates an intent to apps
*/
interface AppIntent {
intent: IntentMetadata;
apps: Array<AppMetadata>;
}
* An interface that relates an intent to apps
*/
export interface AppIntent {
readonly intent: IntentMetadata;
readonly apps: Array<AppMetadata>;
}
37 changes: 18 additions & 19 deletions src/api/AppMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
/**
* App definition as provided by the application directory
*/
interface AppMetadata {
export interface AppMetadata {
/** The unique app name that can be used with the open and raiseIntent calls. */
readonly name: string;

/** The unique app name that can be used with the open and raiseIntent calls. */
name: string;

/** A more user-friendly application title that can be used to render UI elements */
title?: string;

/** A tooltip for the application that can be used to render UI elements */
tooltip?: string;

/** A longer, multi-paragraph description for the application that could include markup */
description?: string;

/** A list of icon URLs for the application that can be used to render UI elements */
icons?: Array<string>;

/** A list of image URLs for the application that can be used to render UI elements */
images?: Array<string>;
}
/** A more user-friendly application title that can be used to render UI elements */
readonly title?: string;

/** A tooltip for the application that can be used to render UI elements */
readonly tooltip?: string;

/** A longer, multi-paragraph description for the application that could include markup */
readonly description?: string;

/** A list of icon URLs for the application that can be used to render UI elements */
readonly icons?: Array<string>;

/** A list of image URLs for the application that can be used to render UI elements */
readonly images?: Array<string>;
}
116 changes: 60 additions & 56 deletions src/api/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,66 @@
* Copyright 2019 FINOS FDC3 contributors - see NOTICE file
*/

import { Context } from '../context/ContextTypes';
import { ContextHandler } from './ContextHandler';
import { DisplayMetadata } from './DisplayMetadata';
import { Listener } from './Listener';

/**
* Object representing a context channel.
*/
interface Channel {
/**
* Constant that uniquely identifies this channel.
*/
public readonly id: string;

/**
* Uniquely defines each channel type.
*/
public readonly type: string;

/**
* Channels may be visualized and selectable by users. DisplayMetadata may be used to provide hints on how to see them.
* For app channels, displayMetadata would typically not be present
*/
public readonly displayMetadata?: DisplayMetadata;

/**
* Broadcasts the given context on this channel. This is equivalent to joining the channel and then calling the
* top-level FDC3 `broadcast` function.
*
* Note that this function can be used without first joining the channel, allowing applications to broadcast on
* channels that they aren't a member of.
*
* `Error` with a string from the `ChannelError` enumeration.
*/
public broadcast(context: Context): void;

/**
* Returns the last context that was broadcast on this channel. All channels initially have no context, until a
* context is broadcast on the channel. If there is not yet any context on the channel, this method
* will return `null`.
*
* The context of a channel will be captured regardless of how the context is broadcasted on this channel - whether
* using the top-level FDC3 `broadcast` function, or using the channel-level {@link broadcast} function on this
* object.
*
* Optionally a {@link contextType} can be provided, in which case the current context of the matching type will
* be returned (if any). Desktop agent implementations may decide to record contexts by type, in which case it will
* be possible to get the most recent context of the type specified, but this is not guaranteed.
*
* `Error` with a string from the `ChannelError` enumeration.
*/
public getCurrentContext(contextType?: string): Promise<Context|null>;

/**
* Adds a listener for incoming contexts whenever a broadcast happens on this channel.
*/
public addContextListener(handler: ContextHandler): Listener;

/**
* Adds a listener for incoming contexts of the specified context type whenever a broadcast happens on this channel.
*/
public addContextListener(contextType: string, handler: ContextHandler): Listener;
}

export interface Channel {
/**
* Constant that uniquely identifies this channel.
*/
readonly id: string;

/**
* Uniquely defines each channel type.
*/
readonly type: string;

/**
* Channels may be visualized and selectable by users. DisplayMetadata may be used to provide hints on how to see them.
* For app channels, displayMetadata would typically not be present
*/
readonly displayMetadata?: DisplayMetadata;

/**
* Broadcasts the given context on this channel. This is equivalent to joining the channel and then calling the
* top-level FDC3 `broadcast` function.
*
* Note that this function can be used without first joining the channel, allowing applications to broadcast on
* channels that they aren't a member of.
*
* `Error` with a string from the `ChannelError` enumeration.
*/
broadcast(context: Context): void;

/**
* Returns the last context that was broadcast on this channel. All channels initially have no context, until a
* context is broadcast on the channel. If there is not yet any context on the channel, this method
* will return `null`.
*
* The context of a channel will be captured regardless of how the context is broadcasted on this channel - whether
* using the top-level FDC3 `broadcast` function, or using the channel-level {@link broadcast} function on this
* object.
*
* Optionally a {@link contextType} can be provided, in which case the current context of the matching type will
* be returned (if any). Desktop agent implementations may decide to record contexts by type, in which case it will
* be possible to get the most recent context of the type specified, but this is not guaranteed.
*
* `Error` with a string from the `ChannelError` enumeration.
*/
getCurrentContext(contextType?: string): Promise<Context | null>;

/**
* Adds a listener for incoming contexts whenever a broadcast happens on this channel.
*/
addContextListener(handler: ContextHandler): Listener;

/**
* Adds a listener for incoming contexts of the specified context type whenever a broadcast happens on this channel.
*/
addContextListener(contextType: string, handler: ContextHandler): Listener;
}
8 changes: 8 additions & 0 deletions src/api/ContextHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 FINOS FDC3 contributors - see NOTICE file
*/

import { Context } from '../context/ContextTypes';

export type ContextHandler = (context: Context) => void;
Loading

0 comments on commit e162dd2

Please sign in to comment.