Skip to content

Commit 3f2b9e5

Browse files
committed
feat: migrate to es modules, upgrade all packages, migrate to Svelte 5
1 parent f97294a commit 3f2b9e5

File tree

158 files changed

+8054
-5082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+8054
-5082
lines changed

package-lock.json

+5,027-2,749
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
"packages/*"
3434
],
3535
"devDependencies": {
36-
"@commitlint/cli": "^18.2.0",
37-
"@commitlint/config-conventional": "^18.1.0",
38-
"husky": "^8.0.3",
39-
"lerna": "^8.1.3",
40-
"lint-staged": "^15.0.2",
41-
"prettier": "3.0.3",
42-
"prettier-plugin-svelte": "^3.0.3",
43-
"typedoc": "^0.25.3",
44-
"typescript": "^5.2.2"
36+
"@commitlint/cli": "^19.5.0",
37+
"@commitlint/config-conventional": "^19.5.0",
38+
"husky": "^9.1.7",
39+
"lerna": "^8.1.9",
40+
"lint-staged": "^15.2.10",
41+
"prettier": "3.3.3",
42+
"prettier-plugin-svelte": "^3.2.8",
43+
"typedoc": "^0.26.11",
44+
"typescript": "^5.6.3"
4545
},
4646
"lint-staged": {
4747
"**/*": "prettier --write --ignore-unknown"

packages/client-node/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Nymph Node Client lets you do everything the Nymph Client does, but from Nod
1010
npm install --save @nymphjs/client-node
1111
```
1212

13-
This package is the Nymph client for Node.js. You can find CJS in `dist`, or TS source in `src`. There is also a **[browser client](https://github.com/sciactive/nymphjs/packages/client)**.
13+
This package is the Nymph client for Node.js. You can find ES modules in `dist`, or TS source in `src`. There is also a **[browser client](https://github.com/sciactive/nymphjs/packages/client)**.
1414

1515
This package provides fetch and WebSocket ponyfills to Nymph and handles Tilmeld auth tokens.
1616

packages/client-node/jest.config.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import { createDefaultEsmPreset } from 'ts-jest';
2+
3+
const presetConfig = createDefaultEsmPreset();
4+
15
/** @type {import('ts-jest').JestConfigWithTsJest} */
2-
module.exports = {
3-
preset: 'ts-jest',
6+
const jestConfig = {
7+
...presetConfig,
48
testEnvironment: 'node',
59
rootDir: 'src/',
10+
moduleNameMapper: {
11+
'^(\\.|\\.\\.)\\/(.+)\\.js': '$1/$2',
12+
},
613
};
14+
15+
export default jestConfig;

packages/client-node/package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@nymphjs/client-node",
33
"version": "1.0.0-beta.81",
44
"description": "Nymph.js - Node Client",
5+
"type": "module",
56
"main": "dist/index.js",
67
"types": "dist/index.d.ts",
78
"keywords": [
@@ -14,8 +15,8 @@
1415
"build": "tsc",
1516
"watch": "tsc --watch",
1617
"prepublish": "npm run clean && npm run build",
17-
"test": "jest",
18-
"test:watch": "jest --watch"
18+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
19+
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch"
1920
},
2021
"publishConfig": {
2122
"access": "public"
@@ -31,16 +32,17 @@
3132
"license": "Apache-2.0",
3233
"dependencies": {
3334
"@nymphjs/client": "^1.0.0-beta.81",
34-
"node-fetch": "^2.7.0",
35-
"websocket": "^1.0.34"
35+
"node-fetch": "^3.3.2",
36+
"websocket": "^1.0.35"
3637
},
3738
"devDependencies": {
38-
"@tsconfig/recommended": "^1.0.3",
39-
"@types/jest": "^29.5.12",
40-
"@types/node-fetch": "^2.6.11",
39+
"@tsconfig/recommended": "^1.0.8",
40+
"@types/jest": "^29.5.14",
41+
"@types/node-fetch": "^2.6.12",
4142
"@types/websocket": "^1.0.10",
4243
"jest": "^29.7.0",
43-
"ts-jest": "^29.1.2",
44-
"typescript": "^5.3.3"
44+
"ts-jest": "^29.2.5",
45+
"ts-node": "^10.9.2",
46+
"typescript": "^5.7.2"
4547
}
4648
}

packages/client-node/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Nymph expects fetch and WebSocket.
2-
import { w3cwebsocket } from 'websocket';
2+
import ws from 'websocket';
33
import fetch from 'node-fetch';
44
import { Nymph, PubSub, type NymphOptions } from '@nymphjs/client';
55

@@ -34,7 +34,7 @@ class NodePubSub extends PubSub {
3434
constructor(nymphOptions: NymphOptions, nymph: Nymph) {
3535
super(
3636
{
37-
WebSocket: w3cwebsocket as unknown as typeof WebSocket,
37+
WebSocket: ws.w3cwebsocket as unknown as typeof WebSocket,
3838
...nymphOptions,
3939
},
4040
nymph,

packages/client-node/tsconfig.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"extends": "@tsconfig/recommended/tsconfig.json",
33

44
"compilerOptions": {
5-
"lib": ["DOM", "ES2021"],
6-
"target": "ES2021",
5+
"module": "ES2022",
6+
"moduleResolution": "node",
7+
"lib": ["DOM", "ES2022"],
8+
"target": "ES2022",
79
"noImplicitAny": true,
810
"removeComments": false,
911
"sourceMap": true,

packages/client/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ The Nymph Client allows you to query and push data to a Nymph REST server from t
1010
npm install --save @nymphjs/client
1111
```
1212

13-
This package is the Nymph client for browsers. You can find UMD in `dist`, or TS source in `src`. There is also a **[Node.js client](https://github.com/sciactive/nymphjs/packages/client-node)**.
13+
This package is the Nymph client for browsers. You can find ES modules in `dist`, or TS source in `src`. There is also a **[Node.js client](https://github.com/sciactive/nymphjs/packages/client-node)**.
1414

1515
## Usage
1616

1717
Here's an overview:
1818

1919
```ts
2020
import { Nymph, PubSub } from '@nymphjs/client';
21-
import TodoClass from 'Todo';
21+
import TodoClass from './Todo.js';
2222

2323
const nymphOptions = {
2424
restUrl: 'https://yournymphrestserver/path/to/your/endpoint',

packages/client/jest.config.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import { createDefaultEsmPreset } from 'ts-jest';
2+
3+
const presetConfig = createDefaultEsmPreset();
4+
15
/** @type {import('ts-jest').JestConfigWithTsJest} */
2-
module.exports = {
3-
preset: 'ts-jest',
6+
const jestConfig = {
7+
...presetConfig,
48
testEnvironment: 'node',
59
rootDir: 'src/',
10+
moduleNameMapper: {
11+
'^(\\.|\\.\\.)\\/(.+)\\.js': '$1/$2',
12+
},
613
};
14+
15+
export default jestConfig;

packages/client/package.json

+18-25
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22
"name": "@nymphjs/client",
33
"version": "1.0.0-beta.81",
44
"description": "Nymph.js - Client",
5-
"browser": "dist/index.js",
6-
"main": "lib/index.js",
7-
"types": "lib/index.d.ts",
5+
"type": "module",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
88
"keywords": [
99
"nymph",
1010
"ORM",
1111
"object relational mapper"
1212
],
1313
"scripts": {
14-
"clean": "npm run clean:ts && npm run clean:js",
15-
"clean:ts": "test -d lib && rm -r lib || true",
16-
"clean:js": "test -d dist && rm -r dist || true",
17-
"build": "npm run build:ts && npm run build:js",
18-
"build:ts": "tsc",
19-
"build:js": "webpack",
20-
"watch:ts": "tsc --watch",
21-
"watch:js": "webpack --watch",
14+
"clean": "test -d dist && rm -r dist || true",
15+
"build": "tsc",
16+
"watch": "tsc --watch",
2217
"prepublish": "npm run clean && npm run build",
23-
"test": "jest --detectOpenHandles",
24-
"test:watch": "jest --watch"
18+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
19+
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch"
2520
},
2621
"publishConfig": {
2722
"access": "public"
@@ -35,19 +30,17 @@
3530
"url": "https://github.com/sciactive/nymphjs/issues"
3631
},
3732
"license": "Apache-2.0",
38-
"devDependencies": {
39-
"@tsconfig/recommended": "^1.0.3",
40-
"@types/jest": "^29.5.12",
41-
"@types/lodash": "^4.14.202",
42-
"jest": "^29.7.0",
43-
"ts-jest": "^29.1.2",
44-
"ts-loader": "^9.5.1",
45-
"typescript": "^5.3.3",
46-
"webpack": "^5.90.3",
47-
"webpack-cli": "^5.1.4"
48-
},
4933
"dependencies": {
5034
"fetch-event-source-hperrin": "^3.0.0",
51-
"lodash": "^4.17.21"
35+
"lodash-es": "^4.17.21"
36+
},
37+
"devDependencies": {
38+
"@tsconfig/recommended": "^1.0.8",
39+
"@types/jest": "^29.5.14",
40+
"@types/lodash-es": "^4.17.12",
41+
"jest": "^29.7.0",
42+
"ts-jest": "^29.2.5",
43+
"ts-node": "^10.9.2",
44+
"typescript": "^5.7.2"
5245
}
5346
}

packages/client/src/Entity.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { difference, isEqual } from 'lodash';
1+
import { difference, isEqual } from 'lodash-es';
22

3-
import type Nymph from './Nymph';
3+
import type Nymph from './Nymph.js';
44
import {
55
EntityConstructor,
66
EntityData,
77
EntityInterface,
88
EntityJson,
99
EntityPatch,
1010
EntityReference,
11-
} from './Entity.types';
11+
} from './Entity.types.js';
1212
import {
1313
uniqueStrings,
1414
entitiesToReferences,
1515
referencesToEntities,
1616
sortObj,
17-
} from './utils';
17+
} from './utils.js';
1818

19-
export type EntityDataType<T> = T extends Entity<infer DataType>
20-
? DataType
21-
: never;
19+
export type EntityDataType<T> =
20+
T extends Entity<infer DataType> ? DataType : never;
2221

2322
export type EntityInstanceType<T extends EntityConstructor> =
2423
T extends new () => infer E ? E & EntityDataType<E> : never;
@@ -538,6 +537,10 @@ export default class Entity<T extends EntityData = EntityData>
538537
return true;
539538
}
540539

540+
public $isDirty(property: string) {
541+
return property in this.$dirty ? this.$dirty[property] : null;
542+
}
543+
541544
public $inArray(array: any[], strict = false) {
542545
return this.$arraySearch(array, strict) !== -1;
543546
}

packages/client/src/Entity.types.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type Nymph from './Nymph';
2-
import type Entity from './Entity';
1+
import type Nymph from './Nymph.js';
2+
import type Entity from './Entity.js';
33

44
export type ServerCallResponse = {
55
return: any;
@@ -156,6 +156,24 @@ export interface EntityInterface extends DataObjectInterface {
156156
* @returns True or false.
157157
*/
158158
$hasTag(...tags: string[]): boolean;
159+
/**
160+
* Check whether a property is dirty.
161+
*
162+
* To be a dirty property, it must have been set or deleted since the entity
163+
* was initialized. A clean property existed on initialization and hasn't been
164+
* set or deleted. An untracked property didn't exist on initialization and
165+
* hasn't been set or deleted.
166+
*
167+
* Note that this doesn't necessarily mean the property has changed. It could
168+
* have been set to the same value, or created and then deleted.
169+
*
170+
* Entities are initialized when they are pulled from the server or saved.
171+
* This is done with the `$init` method.
172+
*
173+
* @param property The name of a property.
174+
* @returns True if it's dirty, false if not, and null if it's not tracked.
175+
*/
176+
$isDirty(property: string): boolean | null;
159177
/**
160178
* Initialize this entity from a JSON representation.
161179
*

packages/client/src/EntityWeakCache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EntityConstructor, EntityInterface } from './Entity.types';
1+
import { EntityConstructor, EntityInterface } from './Entity.types.js';
22

33
export default class EntityWeakCache {
44
private references: WeakMap<

0 commit comments

Comments
 (0)