Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@furystack/core

Package Overview
Dependencies
Maintainers
1
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@furystack/core - npm Package Compare versions

Comparing version 11.1.1 to 11.2.0

35

dist/create-physical-store-tests.js

@@ -392,2 +392,37 @@ "use strict";

}
if (!options.skipStringTests) {
it('filter should return the corresponding entries with $startsWith', async () => {
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
const store = options.createStore(i);
await store.add((0, exports.createMockEntity)({ id: 1, stringValue1: 'asd' }), (0, exports.createMockEntity)({ id: 2, stringValue1: 'aaa' }), (0, exports.createMockEntity)({ id: 3, stringValue1: 'bbb' }));
const result = await store.find({ filter: { stringValue1: { $startsWith: 'aa' } } });
expect(result.length).toBe(1);
expect(result.map((r) => r.stringValue1)).toEqual(['aaa']);
});
});
it('filter should return the corresponding entries with $endsWith', async () => {
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
const store = options.createStore(i);
await store.add((0, exports.createMockEntity)({ id: 1, stringValue1: 'asd' }), (0, exports.createMockEntity)({ id: 2, stringValue1: 'aaa' }), (0, exports.createMockEntity)({ id: 3, stringValue1: 'bbb' }));
const result = await store.find({ filter: { stringValue1: { $endsWith: 'bb' } } });
expect(result.length).toBe(1);
expect(result.map((r) => r.stringValue1)).toEqual(['bbb']);
});
});
it('filter should return the corresponding entries with $like', async () => {
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
const store = options.createStore(i);
await store.add((0, exports.createMockEntity)({ id: 1, stringValue1: 'asd' }), (0, exports.createMockEntity)({ id: 2, stringValue1: 'aaa' }), (0, exports.createMockEntity)({ id: 3, stringValue1: 'bbb' }));
const result = await store.find({ filter: { stringValue1: { $like: '%a%' } } });
expect(result.length).toBe(2);
expect(result.map((r) => r.stringValue1)).toEqual(['asd', 'aaa']);
const endsWithAResult = await store.find({ filter: { stringValue1: { $like: '%a' } } });
expect(endsWithAResult.length).toBe(1);
expect(endsWithAResult.map((r) => r.stringValue1)).toEqual(['aaa']);
const startsWithAResult = await store.find({ filter: { stringValue1: { $like: 'a%' } } });
expect(startsWithAResult.length).toBe(2);
expect(startsWithAResult.map((r) => r.stringValue1)).toEqual(['asd', 'aaa']);
});
});
}
});

@@ -394,0 +429,0 @@ describe('Count', () => {

@@ -19,2 +19,6 @@ "use strict";

};
this.evaluateLike = (value, likeString) => {
const likeRegex = `^${likeString.replace(/%/g, '.*')}$`;
return value.match(new RegExp(likeRegex, 'i'));
};
this.primaryKey = options.primaryKey;

@@ -115,2 +119,17 @@ this.model = options.model;

break;
case '$startsWith':
if (!itemValue.startsWith(filterValue)) {
return false;
}
break;
case '$endsWith':
if (!itemValue.endsWith(filterValue)) {
return false;
}
break;
case '$like':
if (!this.evaluateLike(itemValue, filterValue)) {
return false;
}
break;
default:

@@ -117,0 +136,0 @@ throw new Error(`The expression (${filterKey}) is not supported by '${this.constructor.name}'!`);

5

dist/models/physical-store.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectFields = exports.t = exports.isOperator = exports.isLogicalOperator = exports.allOperators = exports.LogicalOperators = exports.ArrayComparisonOperators = exports.SingleComparisonOperators = exports.NumberComparisonOperators = void 0;
exports.selectFields = exports.t = exports.isOperator = exports.isLogicalOperator = exports.allOperators = exports.LogicalOperators = exports.ArrayComparisonOperators = exports.SingleComparisonOperators = exports.StringComparisonOperators = exports.NumberComparisonOperators = void 0;
exports.NumberComparisonOperators = ['$gt', '$gte', '$lt', '$lte'];
exports.StringComparisonOperators = ['$startsWith', '$endsWith', '$like', '$regex'];
exports.SingleComparisonOperators = ['$eq', '$ne'];

@@ -13,3 +14,3 @@ exports.ArrayComparisonOperators = ['$in', '$nin'];

...exports.LogicalOperators,
'$regex',
...exports.StringComparisonOperators,
];

@@ -16,0 +17,0 @@ const isLogicalOperator = (propertyString) => exports.LogicalOperators.includes(propertyString);

8

package.json
{
"name": "@furystack/core",
"version": "11.1.1",
"version": "11.2.0",
"description": "Core FuryStack package",

@@ -29,8 +29,8 @@ "main": "dist/index.js",

"devDependencies": {
"@types/jest": "^29.2.1",
"@types/jest": "^29.2.2",
"@types/node": "^18.11.9"
},
"dependencies": {
"@furystack/inject": "^7.1.1",
"@furystack/utils": "^3.1.1",
"@furystack/inject": "^7.1.2",
"@furystack/utils": "^3.1.2",
"semaphore-async-await": "^1.5.1"

@@ -37,0 +37,0 @@ },

@@ -32,2 +32,3 @@ import type { PhysicalStore } from './models/physical-store'

skipRegexTests?: boolean
skipStringTests?: boolean
}

@@ -529,2 +530,56 @@

}
if (!options.skipStringTests) {
it('filter should return the corresponding entries with $startsWith', async () => {
await usingAsync(new Injector(), async (i) => {
const store = options.createStore(i)
await store.add(
createMockEntity({ id: 1, stringValue1: 'asd' }),
createMockEntity({ id: 2, stringValue1: 'aaa' }),
createMockEntity({ id: 3, stringValue1: 'bbb' }),
)
const result = await store.find({ filter: { stringValue1: { $startsWith: 'aa' } } })
expect(result.length).toBe(1)
expect(result.map((r) => r.stringValue1)).toEqual(['aaa'])
})
})
it('filter should return the corresponding entries with $endsWith', async () => {
await usingAsync(new Injector(), async (i) => {
const store = options.createStore(i)
await store.add(
createMockEntity({ id: 1, stringValue1: 'asd' }),
createMockEntity({ id: 2, stringValue1: 'aaa' }),
createMockEntity({ id: 3, stringValue1: 'bbb' }),
)
const result = await store.find({ filter: { stringValue1: { $endsWith: 'bb' } } })
expect(result.length).toBe(1)
expect(result.map((r) => r.stringValue1)).toEqual(['bbb'])
})
})
it('filter should return the corresponding entries with $like', async () => {
await usingAsync(new Injector(), async (i) => {
const store = options.createStore(i)
await store.add(
createMockEntity({ id: 1, stringValue1: 'asd' }),
createMockEntity({ id: 2, stringValue1: 'aaa' }),
createMockEntity({ id: 3, stringValue1: 'bbb' }),
)
const result = await store.find({ filter: { stringValue1: { $like: '%a%' } } })
expect(result.length).toBe(2)
expect(result.map((r) => r.stringValue1)).toEqual(['asd', 'aaa'])
const endsWithAResult = await store.find({ filter: { stringValue1: { $like: '%a' } } })
expect(endsWithAResult.length).toBe(1)
expect(endsWithAResult.map((r) => r.stringValue1)).toEqual(['aaa'])
const startsWithAResult = await store.find({ filter: { stringValue1: { $like: 'a%' } } })
expect(startsWithAResult.length).toBe(2)
expect(startsWithAResult.map((r) => r.stringValue1)).toEqual(['asd', 'aaa'])
})
})
}
})

@@ -531,0 +586,0 @@

@@ -39,2 +39,7 @@ import type { Constructable } from '@furystack/inject'

private evaluateLike = (value: string, likeString: string) => {
const likeRegex = `^${likeString.replace(/%/g, '.*')}$`
return value.match(new RegExp(likeRegex, 'i'))
}
private filterInternal(values: T[], filter?: FilterType<T>): T[] {

@@ -114,2 +119,17 @@ if (!filter) {

break
case '$startsWith':
if (!itemValue.startsWith(filterValue)) {
return false
}
break
case '$endsWith':
if (!itemValue.endsWith(filterValue)) {
return false
}
break
case '$like':
if (!this.evaluateLike(itemValue, filterValue)) {
return false
}
break
default:

@@ -116,0 +136,0 @@ throw new Error(`The expression (${filterKey}) is not supported by '${this.constructor.name}'!`)

@@ -5,2 +5,4 @@ import type { Constructable } from '@furystack/inject'

export const NumberComparisonOperators = ['$gt', '$gte', '$lt', '$lte'] as const
export const StringComparisonOperators = ['$startsWith', '$endsWith', '$like', '$regex'] as const
export const SingleComparisonOperators = ['$eq', '$ne'] as const

@@ -16,3 +18,3 @@

...LogicalOperators,
'$regex',
...StringComparisonOperators,
] as const

@@ -22,3 +24,3 @@

[K in keyof T]?:
| (T[K] extends string ? { $regex?: string } : never)
| (T[K] extends string ? { [SCO in typeof StringComparisonOperators[number]]?: T[K] } : never)
| (T[K] extends number ? { [SCO in typeof NumberComparisonOperators[number]]?: T[K] } : never)

@@ -25,0 +27,0 @@ | { [SCO in typeof SingleComparisonOperators[number]]?: T[K] }

@@ -17,4 +17,5 @@ import type { PhysicalStore } from './models/physical-store';

skipRegexTests?: boolean;
skipStringTests?: boolean;
}
export declare const createStoreTest: (options: StoreTestOptions<TestClass, 'id'>) => void;
//# sourceMappingURL=create-physical-store-tests.d.ts.map

@@ -12,2 +12,3 @@ import type { Constructable } from '@furystack/inject';

get: (key: T[TPrimaryKey], select?: Array<keyof T>) => Promise<T | undefined>;
private evaluateLike;
private filterInternal;

@@ -14,0 +15,0 @@ find<TFields extends Array<keyof T>>(searchOptions: FindOptions<T, TFields>): Promise<PartialResult<T, TFields>[]>;

import type { Constructable } from '@furystack/inject';
import type { Disposable } from '@furystack/utils';
export declare const NumberComparisonOperators: readonly ["$gt", "$gte", "$lt", "$lte"];
export declare const StringComparisonOperators: readonly ["$startsWith", "$endsWith", "$like", "$regex"];
export declare const SingleComparisonOperators: readonly ["$eq", "$ne"];
export declare const ArrayComparisonOperators: readonly ["$in", "$nin"];
export declare const LogicalOperators: readonly ["$and", "$not", "$nor", "$or"];
export declare const allOperators: readonly ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte", "$in", "$nin", "$and", "$not", "$nor", "$or", "$regex"];
export declare const allOperators: readonly ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte", "$in", "$nin", "$and", "$not", "$nor", "$or", "$startsWith", "$endsWith", "$like", "$regex"];
export declare type FilterType<T> = {
[K in keyof T]?: (T[K] extends string ? {
$regex?: string;
[SCO in typeof StringComparisonOperators[number]]?: T[K];
} : never) | (T[K] extends number ? {

@@ -22,3 +23,3 @@ [SCO in typeof NumberComparisonOperators[number]]?: T[K];

export declare const isLogicalOperator: (propertyString: string) => propertyString is "$and" | "$not" | "$nor" | "$or";
export declare const isOperator: (propertyString: string) => propertyString is "$gt" | "$gte" | "$lt" | "$lte" | "$eq" | "$ne" | "$in" | "$nin" | "$and" | "$not" | "$nor" | "$or" | "$regex";
export declare const isOperator: (propertyString: string) => propertyString is "$gt" | "$gte" | "$lt" | "$lte" | "$startsWith" | "$endsWith" | "$like" | "$regex" | "$eq" | "$ne" | "$in" | "$nin" | "$and" | "$not" | "$nor" | "$or";
export declare const t: FilterType<{

@@ -25,0 +26,0 @@ a: number;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc