Skip to content

Commit b9c2507

Browse files
committed
v2.0
1 parent 7c432ba commit b9c2507

9 files changed

Lines changed: 2145 additions & 932 deletions

File tree

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
6+
7+
## [2.0.0] - 2025-10-16
8+
### Added
9+
- First-class TypeScript definitions (`index.d.ts`) for the full public API:
10+
- `createDataContext`, `parse`, `stringify`, `syncData`, `stringifyChanges`, event APIs, and helpers.
11+
- Strongly-typed `DataContext<T>` with recursive typing for objects and arrays.
12+
- `ChangeEvent`, `StringifyOptions`, `WatchJsonFileOptions`, and `JSONReplacer` types.
13+
- `stringify` option `includeBOM` to prefix output with BOM when needed.
14+
- `ignoreMetadata` toggle exposed as a public property to include/exclude metadata comments globally.
15+
- Node helper `watchJsonFile` type surfaced (returns an opaque handle to avoid forcing Node types).
16+
17+
### Changed
18+
- Stabilized public API surface and clarified event contract:
19+
- Property events: `new`, `set`, `reposition`, `delete`
20+
- Aggregate events: `-` (bubbled) and `-change` (debounced)
21+
- Improved docs and JSDoc within code to reflect v2 behavior.
22+
23+
### Fixed
24+
- Consistent handling of non-enumerable metadata keys during parse/stringify.
25+
- Safer overwriting semantics when parsing into an existing DataContext.
26+
27+
### Migration notes
28+
- No breaking API changes are intended versus 1.x. If you relied on undocumented internals, prefer the public methods and properties reflected in the new typings.
29+
- `watchJsonFile` is Node-only; in browser environments it is a no-op and typings reflect an opaque return value.
30+
31+
[2.0.0]: https://github.com/your-repo/data-context/releases/tag/v2.0.0

README.html

Lines changed: 1369 additions & 379 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 107 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
1-
<div class="row w-100">
2-
<div class="col-12 text-center">
1+
<p>
2+
<img src="logo/logo-432x260.png" alt="data-context logo" width="440" style="background-color:#333;border-radius:4em;border-color: #999;border-width: 0.5em;border-style: dashed;">
3+
</p>
34

45
# data-context
56

6-
Watch data changes in the browser and node.js<br>
7-
This manual is also available in [HTML5](https://manuel-lohmus.github.io/data-context/README.html).<br>
8-
9-
</div>
10-
</div>
11-
<div class="row w-100">
12-
<div class="col-lg-3 d-lg-inline">
13-
<div class="sticky-top overflow-auto vh-lg-100">
14-
<div id="list-headers" class="list-group mt-2 ms-lg-2 ms-4">
15-
16-
#### Table of contents
17-
- [**Introduction**](#introduction)
18-
- [**Features**](#features)
19-
- [**Installation**](#installation)
20-
- [**Testing**](#testing)
21-
- [**Usage**](#usage)
22-
- [nodejs example](#nodejs-example)
23-
- [browser example](#browser-example)
24-
- [**References**](#references)
25-
- [createDataContext(data, propertyName, parent)](#createdatacontextdata-propertyname-parent)
26-
- [DataContext](#datacontext)
27-
- [EventListener(event)](#eventlistenerevent)
28-
- [EventObject](#eventobject)
29-
- [PropertyName](#propertyname)
30-
- [Reviver](#reviver)
31-
- [**License**](#license)
32-
33-
</div>
34-
</div>
35-
</div>
36-
37-
<div class="col-lg-9 mt-2">
38-
<div class="ps-4 markdown-body" data-bs-spy="scroll" data-bs-target="#list-headers" data-bs-offset="0" tabindex="0">
39-
40-
41-
## Introduction
7+
Watch data changes in the browser and node.js
8+
9+
## 📚 Table of contents
10+
11+
- [✨ Features](#-features)
12+
- [📋 Description](#-description)
13+
- [📦 Installation](#-installation)
14+
- [🧪 Testing](#-testing)
15+
- [🚀 Usage](#-usage)
16+
- [📖 API Reference](#-api-reference)
17+
- [📜 License](#-license)
18+
19+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
20+
21+
---
22+
23+
## ✨ Features
24+
25+
- Create a context from the data.
26+
- Listen for change events.
27+
- Update the context.
28+
- Parse JSON data to the context.
29+
- Stringify changes to JSON.
30+
- Used extended JSON data format. Metadata and comments are supported.
31+
32+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
33+
34+
---
35+
36+
## 📋 Description
37+
38+
The 'data-context' module provides a way to create a data context that can watch for changes in the data.
4239

4340
It is a simple and easy-to-use library that can be used in the browser or in node.js.
4441
You can create a context from the data, then listen for change events and stringify changes.
@@ -104,28 +101,38 @@ Here are some potential use cases:
104101
- **Description**: Handle incremental updates to JSON data, including metadata and comments.
105102
- **Example**: Use the library to parse, modify, and serialize JSON data with support for incremental updates and metadata.
106103

107-
## Features
104+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
108105

109-
- Create a context from the data.
110-
- Listen for change events.
111-
- Update the context.
112-
- Parse JSON data to the context.
113-
- Stringify changes to JSON.
114-
- Used extended JSON data format. Metadata and comments are supported.
106+
---
107+
108+
## 📦 Installation
115109

116-
## Installation
110+
[Available on npm](https://www.npmjs.com/package/data-context)
117111

118112
### nodejs:
119-
`npm install data-context`
113+
```bash
114+
npm install data-context
115+
```
120116

121117
### browser:
122-
`<script src="https://cdn.jsdelivr.net/npm/data-context@2" ></script>`
118+
or use CDN (for an HTML page hosted on the server):
119+
```html
120+
<script src="./node_modules/data-context/borwser.js" type="text/javascript"></script>
121+
```
122+
or use CDN (for a standalone HTML page):
123+
```html
124+
<script src="https://cdn.jsdelivr.net/npm/data-context" type="text/javascript"></script>
125+
```
126+
or use 'tiny-https-server':
127+
```html
128+
<script async src="node_modules/data-context@2"></script>
129+
```
123130

124-
### Using tiny-https-server router:
125-
or use ['tiny-https-server'](https://www.npmjs.com/package/tiny-https-server) router:
126-
`<script async src="node_modules/data-context@2"></script>`
131+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
127132

128-
## Testing
133+
---
134+
135+
## 🧪 Testing
129136

130137
You can test `data-context` on your system using this command:
131138

@@ -139,7 +146,11 @@ or open in your browser:
139146

140147
`./node_modules/data-context/index.test.html`
141148

142-
## Usage
149+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
150+
151+
---
152+
153+
## 🚀 Usage
143154

144155
### nodejs example:
145156
```javascript
@@ -335,7 +346,16 @@ intervalId = setInterval(() => {
335346
</html>
336347
```
337348

338-
## References
349+
## 📖 API Reference
350+
351+
- [createDataContext(data, propertyName, parent)](#createdatacontextdata-propertyname-parent)
352+
- [DataContext](#datacontext)
353+
- [EventListener(event)](#eventlistenerevent)
354+
- [EventObject](#eventobject)
355+
- [PropertyName](#propertyname)
356+
- [Reviver](#reviver)
357+
358+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
339359

340360
### *createDataContext(data, propertyName, parent)*
341361

@@ -357,6 +377,11 @@ Create a data context from the data.
357377
- `parse` {(str: string, reviver?: [Reviver](#reviver)) => [DataContext](#datacontext)} - Parse JSON string to the data context.
358378
- `stringify` {(data: any, replacer?: Replacer, space?: number) => string} - Stringify the data to JSON string.
359379

380+
<p align="right"><a href="#-api-reference">Back to API Reference ↑</a></p>
381+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
382+
383+
---
384+
360385
### *DataContext*
361386

362387
The data context Proxy object.
@@ -382,6 +407,11 @@ The data context Proxy object.
382407
- `overwritingData` {(text: string, reviver?: [Reviver](#reviver) ) => void} - Overwrite the data.
383408
- `stringifyChanges` {(reviver?: [Reviver](#reviver), space?: number|string, onlyModified?: boolean, setUnmodified?: boolean) => string} - Stringify the changes.
384409

410+
<p align="right"><a href="#-api-reference">Back to API Reference ↑</a></p>
411+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
412+
413+
---
414+
385415
### *EventListener(event)*
386416

387417
The event listener function.
@@ -394,6 +424,11 @@ The event listener function.
394424
**Returns:**
395425
- {boolean} - The flag that indicates that the listener is alive.
396426

427+
<p align="right"><a href="#-api-reference">Back to API Reference ↑</a></p>
428+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
429+
430+
---
431+
397432
### *EventObject*
398433

399434
The event object.
@@ -413,32 +448,39 @@ The event object.
413448
- `oldValue` {any} - The old value.
414449
- `newValue` {any} - The new value.
415450

451+
<p align="right"><a href="#-api-reference">Back to API Reference ↑</a></p>
452+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
453+
454+
---
455+
416456
### *PropertyName*
417457

418458
The property name.
419459

420460
**Type:** `string`
421461

462+
<p align="right"><a href="#-api-reference">Back to API Reference ↑</a></p>
463+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
464+
465+
---
466+
422467
### *Reviver*
423468

424469
The reviver function.
425470

426471
**Type:** [`reviver`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#reviver)
427472
or [`createDataContext`](#createdatacontextdata-propertyname-parent) or `null`
428473

429-
## License
474+
<p align="right"><a href="#-api-reference">Back to API Reference ↑</a></p>
475+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
430476

431-
This project is licensed under the MIT License.
477+
---
432478

433-
Copyright &copy; Manuel Lõhmus
479+
## 📜 License
434480

435-
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/donate?hosted_button_id=TMZURGNWWYUBW)
481+
This project is licensed under the MIT License.<br>
482+
Copyright &copy; Manuel Lõhmus
436483

437-
Donations are welcome and will go towards further development of this project.
484+
<p align="right"><a href="#data-context">Back to top ↑</a></p>
438485

439-
<br>
440-
<br>
441-
<br>
442-
</div>
443-
</div>
444-
</div>
486+
---

config-sets.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* Configuration settings for application. */
2+
{
3+
/* Set to true to use production settings, */
4+
/* false for development settings. Default is true. */
5+
"isProduction": true,
6+
/* Settings used in production mode. */
7+
/* These settings are saved to "config-sets.json" file. */
8+
"production": {
9+
"port": 8000,
10+
"parallelism": 1,
11+
"tiny-https-server": {
12+
"isDebug": false,
13+
"host": "0.0.0.0",
14+
"port": 8000,
15+
"exclusive": false,
16+
"logDir": "./log/tiny-https-server",
17+
"directory_index": "index.html",
18+
"primary_domain": {
19+
"document_root": "./",
20+
"service_worker_version": "0",
21+
"service_worker_version_update": true,
22+
"is_new_service_worker_reload_browser": false,
23+
"service_worker_disabled": false,
24+
"precache_urls": null,
25+
"headers": {
26+
"default": {
27+
"server": "tiny-https-server"
28+
}
29+
},
30+
"sitemap_update": true
31+
},
32+
"subdomains": {},
33+
"cache_control": {
34+
"fileTypes": {
35+
"webp": "max-age=2592000",
36+
"bmp": "max-age=2592000",
37+
"jpeg": "max-age=2592000",
38+
"jpg": "max-age=2592000",
39+
"png": "max-age=2592000",
40+
"svg": "max-age=2592000",
41+
"pdf": "max-age=2592000",
42+
"woff2": "max-age=2592000",
43+
"woff": "max-age=2592000",
44+
"image/svg+xml": "max-age=2592000",
45+
"html": "max-age=86400",
46+
"css": "max-age=86400",
47+
"js": "max-age=86400"
48+
}
49+
},
50+
"pathToBlacklistFile": "./log/tiny-https-server/blacklist.json",
51+
"bad_path_validation_regex_patterns": [
52+
".php$|.asmx$"
53+
],
54+
"contact_email": "default@laptop-l6kf75di",
55+
"maxConnections": 100,
56+
"maxRequestsPerSocket": 100,
57+
"pathToPrivkey": ,
58+
"pathToCert":
59+
},
60+
"web-cluster": {
61+
"isDebug": false,
62+
"parallelism": 1,
63+
"httpToHttpsRedirect": true
64+
}
65+
},
66+
/* Settings used in development mode. */
67+
/* These settings are not saved to file and are created from production settings. */
68+
/* You can override these settings using command line arguments. */
69+
/* Set only the settings you want to change. */
70+
"development": {}
71+
}

0 commit comments

Comments
 (0)