Skip to content

Commit

Permalink
utils migration and lodash to peer dependencies conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
steveswork committed Jun 2, 2024
1 parent ec79635 commit 0f1a79f
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 377 deletions.
63 changes: 49 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"steveswork <stephen.isienyi@gmail.com> (https://github.com/steveswork)"
],
"dependencies": {
"@webkrafters/get-property": "^1.1.2",
"lodash": "^4.17.21"
"@webkrafters/clone-total": "^1.0.1",
"@webkrafters/get-property": "^1.1.2"
},
"description": "Auto Immutable - self enforcing immutable data structure",
"devDependencies": {
Expand All @@ -24,9 +24,12 @@
"@babel/preset-env": "^7.20.2",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.0",
"@types/node": "^20.11.28",
"@types/node": "^20.13.0",
"babel-loader": "^8.2.5",
"jest": "^29.7.0",
"lodash.isempty": "^4.4.0",
"lodash.isequal": "^4.5.0",
"lodash.isplainobject": "^4.0.6",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.2"
Expand All @@ -44,6 +47,11 @@
"license": "MIT",
"main": "dist/index.js",
"name": "@webkrafters/auto-immutable",
"peerDependencies": {
"lodash.isempty": ">= 0.1.0",
"lodash.isequal": ">= 0.1.0",
"lodash.isplainobject": ">= 0.8.0"
},
"publishConfig": {
"access": "public"
},
Expand All @@ -60,5 +68,5 @@
"test:watch": "jest --updateSnapshot --watchAll"
},
"types": "dist/index.d.ts",
"version": "1.0.0"
"version": "1.0.1-rc.0"
}
14 changes: 8 additions & 6 deletions post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ var fs = require( 'fs' );
var path = require( 'path' );
const { promisify } = require( 'util' );

const copyFile = promisify( fs.copyFile );
const read = promisify( fs.readFile );
const write = promisify( fs.writeFile );

const LOGO_FILENAME = 'logo.svg';

const LOGO_SOURCEPATH = path.join( 'docs-dev', 'src', 'images', LOGO_FILENAME );

const fOpts = { encoding: 'utf8' };

Promise
.allSettled([
read(
path.join( 'docs-dev', 'src', 'images', 'logo.svg' ),
fOpts
),
read( 'logo.svg', fOpts )
read( LOGO_SOURCEPATH, fOpts ),
read( LOGO_FILENAME, fOpts )
])
.then(([ officialLogo, appLogo ]) => {
if( officialLogo.reason ) {
throw new Error( officialLogo.reason );
}
if( appLogo.reason ) { appLogo.value = '' }
if( appLogo.value === officialLogo.value ) { return }
write( 'logo.svg', officialLogo.value, fOpts );
return copyFile( LOGO_SOURCEPATH, LOGO_FILENAME );
})
.catch( e => {
console.log( 'FAILED TO PROCESS LOGO TRANSFER\n', e );
Expand Down
12 changes: 10 additions & 2 deletions src/connection.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
beforeAll,
describe,
expect,
jest,
test
} from '@jest/globals';

import AccessorCache from './model/accessor-cache';
import { Immutable } from './main';
import { deps, Connection } from './connection';
Expand Down Expand Up @@ -100,7 +108,7 @@ describe( 'Connection class', () => {
.spyOn( deps, 'setValue' )
.mockReturnValue( undefined );

connection.get( expect.any( Array ) );
connection.get( expect.any( Array ) as unknown as string );
expect( cacheGetSpy ).toHaveBeenCalledTimes( 1 );
connection.set( {} );
expect( setSpy ).toHaveBeenCalledTimes( 1 );
Expand All @@ -111,7 +119,7 @@ describe( 'Connection class', () => {
connection.disconnect();

expect( connection.disconnected ).toBe( true );
connection.get( expect.any( Array ) );
connection.get( expect.any( Array ) as unknown as string );
expect( cacheGetSpy ).not.toHaveBeenCalled();
connection.set( {} );
expect( setSpy ).not.toHaveBeenCalled();
Expand Down
8 changes: 8 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {
beforeAll,
describe,
expect,
jest,
test
} from '@jest/globals';

import { Connection } from './connection';
import { Closable, Immutable } from './main';

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Value } from '.';

import * as _constants from './constants';

import { clonedeep } from './utils';
import clonedeep from '@webkrafters/clone-total';

import AccessorCache from './model/accessor-cache';

Expand Down
18 changes: 16 additions & 2 deletions src/model/accessor-cache/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import {
afterAll,
beforeAll,
describe,
expect,
jest,
test
} from '@jest/globals';

import type { SourceData } from '../../test-artifacts/data/create-data-obj';

type Value = Partial<SourceData>;

import clonedeep from '@webkrafters/clone-total';

import * as constants from '../../constants';
import { clonedeep } from '../../utils';

import AccessorCache from '.';

import _createSourceData from '../../test-artifacts/data/create-data-obj';
Expand Down Expand Up @@ -177,7 +188,10 @@ describe( 'AccessorCache class', () => {
},
'tags[4]': 'ullamco'
};
const retVal = cache.get( expect.any( String ), ...accessorPaths[ 0 ] );
const retVal = cache.get(
expect.any( String ) as unknown as string,
...accessorPaths[ 0 ]
);
test( 'is a compiled slice of value object as referenced in the propertyPaths', () => {
expect( retVal ).toEqual( retValExpected );
} );
Expand Down
4 changes: 2 additions & 2 deletions src/model/accessor-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ interface PropertyOriginInfo {
import isEmpty from 'lodash.isempty';
import isEqual from 'lodash.isequal';

import { GLOBAL_SELECTOR } from '../../constants';
import getProperty from '@webkrafters/get-property';

import { getProperty } from '../../utils';
import { GLOBAL_SELECTOR } from '../../constants';

import Atom from '../atom';
import Accessor from '../accessor';
Expand Down
22 changes: 15 additions & 7 deletions src/model/accessor/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { getProperty } from '../../../utils';
import {
beforeAll,
describe,
expect,
test
} from '@jest/globals';

import getProperty from '@webkrafters/get-property';

import Atom from '../../atom';

import Accessor from '..';
Expand Down Expand Up @@ -66,13 +74,13 @@ describe( 'Accessor class', () => {
describe( 'addClient(...)', () => {
test( 'adds new client id to `clients`', () => {
const numClients = accessor.numClients;
const id = expect.any( String );
const id = expect.any( String ) as unknown as string;
accessor.addClient( id );
expect( accessor.numClients ).toBe( numClients + 1 );
accessor.removeClient( id );
} );
test( 'ignores requests to add existing clients', () => {
const id = expect.any( String );
const id = expect.any( String ) as unknown as string;
accessor.addClient( id );
const numClients = accessor.numClients;
accessor.addClient( id );
Expand All @@ -83,27 +91,27 @@ describe( 'Accessor class', () => {
} );
describe( 'hasClient(...)', () => {
test( 'returns `false` if client not found in `clients`', () => {
const id = expect.any( String );
const id = expect.any( String ) as unknown as string;
accessor.removeClient( id );
expect( accessor.hasClient( id ) ).toBe( false );
} );
test( 'returns `true` if client found in `clients`', () => {
const id = expect.any( String );
const id = expect.any( String ) as unknown as string;
accessor.addClient( id );
expect( accessor.hasClient( id ) ).toBe( true );
accessor.removeClient( id );
} );
} );
describe( 'removeClient(...)', () => {
test( 'removes client id from `clients`', () => {
const id = expect.any( String );
const id = expect.any( String ) as unknown as string;
accessor.addClient( id );
const numClients = accessor.numClients;
accessor.removeClient( id );
expect( accessor.numClients ).toBe( numClients - 1 );
} );
test( 'ignores requests to remove non-existing clients', () => {
const id = expect.any( String );
const id = expect.any( String ) as unknown as string;
accessor.addClient( id );
accessor.removeClient( id );
const numClients = accessor.numClients;
Expand Down
7 changes: 7 additions & 0 deletions src/model/atom/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
beforeAll,
describe,
expect,
test
} from '@jest/globals';

import Atom from '.';

describe( 'Atom class', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/model/atom/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { clonedeep, makeReadonly } from '../../utils';
import clonedeep from '@webkrafters/clone-total';

import { makeReadonly } from '../../utils';

const isFunction = (() => {
const toString = Function.prototype.toString;
Expand Down
Loading

0 comments on commit 0f1a79f

Please sign in to comment.