Skip to content

Commit 7253d02

Browse files
committed
feat: add api + interfaces
0 parents  commit 7253d02

19 files changed

+12763
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Setup Node Environment'
2+
description: 'Setup Node, cache and clean install'
3+
4+
inputs:
5+
registry-url:
6+
description: 'the url for the registry (github or npm)'
7+
required: false
8+
default: 'https://registry.npmjs.org'
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Set up Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: '20'
17+
registry-url: ${{ inputs.registry-url }}
18+
19+
- name: Cache Node Modules
20+
id: cache-node-modules
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
node_modules
25+
key: modules-${{ hashFiles('package-lock.json') }}
26+
27+
- name: Cache Playwright Binaries
28+
id: cache-playwright
29+
uses: actions/cache@v4
30+
with:
31+
path: |
32+
~/.cache/ms-playwright
33+
key: playwright-${{ hashFiles('package-lock.json') }}
34+
35+
- name: Install dependencies
36+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
37+
run: npm ci
38+
shell: bash
39+
40+
- name: Install playwright browsers
41+
if: steps.cache-playwright.outputs.cache-hit != 'true'
42+
run: npx playwright install --with-deps
43+
shell: bash
44+
45+
- name: Install system dependencies for WebKit
46+
# Some WebKit dependencies seem to lay outside the cache and will need to be installed separately
47+
if: steps.cache-playwright.outputs.cache-hit == 'true'
48+
run: npx playwright install-deps webkit
49+
shell: bash
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: release-please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release-please:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
release_created: ${{ steps.release.outputs.release_created }}
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
issues: write
17+
steps:
18+
- uses: googleapis/release-please-action@v4
19+
id: release
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
config-file: release-please-config.json
23+
manifest-file: .release-please-manifest.json
24+
25+
npm-publish:
26+
needs: release-please
27+
if: ${{ needs.release-please.outputs.release_created }}
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
id-token: write
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: ./.github/actions/setup-node-env
35+
with:
36+
registry-url: "https://registry.npmjs.org"
37+
- run: npm publish --provenance --access public
38+
env:
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Test
2+
on: [push, pull_request, workflow_dispatch]
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v4
10+
11+
- uses: ./.github/actions/setup-node-env
12+
13+
- name: Build
14+
run: npm run-script build
15+
16+
- name: Run unit tests
17+
run: npm run-script test

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
node_modules
2+
*.js
3+
*.map
4+
*.d.ts
5+
*.tsbuildinfo
6+
7+
## editors
8+
/.idea
9+
/.vscode
10+
11+
## build artifacts
12+
dist
13+
coverage
14+
15+

.release-please-manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ ".": "0.0.1" }

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# OpenSCD API
2+
3+
This package defines a common set of APIs, types, and interfaces for use by [OpenSCD](https://openscd.org) distributions and plugins.
4+
It does **not** contain any business logic or implementation—only the shared contracts that enable interoperability between OpenSCD core, plugins, and distribution builders.
5+
6+
## Purpose
7+
8+
- **For Plugin Developers:**
9+
Provides the types and event interfaces needed to build plugins that integrate seamlessly with OpenSCD core.
10+
See [docs/plugin-api.md](docs/plugin-api.md) for a detailed description of the plugin API.
11+
12+
- **For Distribution Builders:**
13+
Supplies the types and interfaces for the OpenSCD root element and other extension points.
14+
_API documentation for the OpenSCD root element and constraints for `plugin.json` will be provided in future docs._
15+
16+
## Documentation
17+
18+
- [Plugin API](docs/plugin-api.md):
19+
Comprehensive guide for plugin authors, including property contracts, event types, and theming.
20+
21+
- _Additional documentation (e.g., for the OpenSCD root element and `plugin.json` constraints) will be added soon._
22+
23+
## License
24+
25+
[Apache-2.0](LICENSE)

Transactor.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export type CommitOptions = {
2+
/** An optional human-readable description of the committed change */
3+
title?: string;
4+
/**
5+
* If true, the commit will be squashed into the previous commit,
6+
* overriding the previous title if a title is also provided.
7+
*/
8+
squash?: boolean;
9+
};
10+
/** Record of changes committed */
11+
export interface Commit<Change> {
12+
/** The inverse of the changes that were committed */
13+
undo: Change[];
14+
/** The changes that were committed */
15+
redo: Change[];
16+
/** An optional human-readable description of the committed changes */
17+
title?: string;
18+
}
19+
export type TransactedCallback<Change> = (txRecord: Commit<Change>) => void;
20+
/**
21+
* Transactor is an interface that defines a transaction manager for managing
22+
* changes in a system. It provides methods to commit changes, undo and redo
23+
* changes, and subscribe to transaction events.
24+
* @template Change - The type of changes that can be committed.
25+
*/
26+
export interface Transactor<Change> {
27+
/** Commits a change, returning the resultant record. */
28+
commit(change: Change, options?: CommitOptions): Commit<Change>;
29+
/** Undoes the most reset `past` `Commit`, if any, returning it. */
30+
undo(): Commit<Change> | undefined;
31+
/** Redoes the most recent `future` `Commit`, if any, returning it. */
32+
redo(): Commit<Change> | undefined;
33+
/** All changes that have been committed and not yet undone. */
34+
past: Commit<Change>[];
35+
/** All changes that have been undone and can be redone. */
36+
future: Commit<Change>[];
37+
/**
38+
* Registers `txCallback`, which will be called on every new `commit`.
39+
* @returns a function that will **unsubscribe** the callback, returning it.
40+
*/
41+
subscribe(
42+
txCallback: TransactedCallback<Change>,
43+
): () => TransactedCallback<Change>;
44+
}

0 commit comments

Comments
 (0)