From cefd968bfef34ffdd778f88582797cce4ee71358 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Fri, 13 Sep 2019 15:51:06 +0100 Subject: [PATCH 1/4] Set up Sauce Labs --- .travis.yml | 9 ++++++++- package.json | 4 ++++ test-ie.html | 4 ++++ test-saucelabs.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 test-ie.html create mode 100644 test-saucelabs.js diff --git a/.travis.yml b/.travis.yml index 90f0247..792378a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,12 @@ language: node_js -node_js: node +node_js: 10 dist: xenial +addons: + firefox: latest + sauce_connect: true +before_script: + - npm run http-server & + - sleep 2 +script: npm run ci services: - xvfb diff --git a/package.json b/package.json index b1e6fbf..78e2d89 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "url": "donejs.com" }, "scripts": { + "ci": "npm run test && node test-saucelabs.js", + "http-server": "http-server -p 3000 --silent", "preversion": "npm test", "postpublish": "git push --tags && git push", "testee": "testee test.html --browsers firefox", @@ -51,10 +53,12 @@ "devDependencies": { "can-define": "^2.0.3", "can-test-helpers": "^1.1.2", + "http-server": "^0.11.0", "jshint": "^2.9.1", "steal": "^2.2.1", "steal-qunit": "^2.0.0", "steal-tools": "^2.2.1", + "test-saucelabs": "^0.0.6", "testee": "^0.9.0" }, "license": "MIT" diff --git a/test-ie.html b/test-ie.html new file mode 100644 index 0000000..0105f6c --- /dev/null +++ b/test-ie.html @@ -0,0 +1,4 @@ + +can-query-logic + +
diff --git a/test-saucelabs.js b/test-saucelabs.js new file mode 100644 index 0000000..fb08cc4 --- /dev/null +++ b/test-saucelabs.js @@ -0,0 +1,51 @@ +"use strict"; + +var SauceLabs = require("test-saucelabs"); + +var maxDuration = 10800; // seconds, default 1800, max 10800 +var commandTimeout = 600; // seconds, default 300, max 600 +var idleTimeout = 1000; // seconds, default 90, max 1000 + +// https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities +var platforms = [{ + browserName: "safari", + platform: "OS X 10.13", + version: "11" +}, { + browserName: "MicrosoftEdge", + platform: "Windows 10" +}, { + browserName: "firefox", + platform: "Windows 10", + version: "latest" +}, { + browserName: "googlechrome", + platform: "Windows 10" +}, { + browserName: "Safari", + "appium-version": "1.12.1", + platformName: "iOS", + platformVersion: "12.2", + deviceName: "iPhone XS Simulator" +}]; + +SauceLabs({ + urls: [{ + name: "can-query-logic", + url : 'http://localhost:3000/test-ie.html?hidepassed', + platforms: [{ + browserName: 'internet explorer', + platform: 'Windows 10', + version: '11.0', + maxDuration: maxDuration, + commandTimeout: commandTimeout, + idleTimeout: idleTimeout + }] + }, { + name: "can-query-logic", + url: "http://localhost:3000/test.html?hidepassed", + platforms: platforms + }], + runInSeries: true, + zeroAssertionsPass: false +}); From 3039b3d143d19706bfef348d31e2e2d754d07589 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Sat, 14 Sep 2019 11:21:07 +0100 Subject: [PATCH 2/4] Fix JSHint config and linting errors --- compat/compat.js | 6 +- compat/prop_tests/sort_test.js | 26 ++-- doc/examples/date-string-example.js | 2 +- doc/examples/searchable-todo-example.js | 3 +- package.json | 2 +- src/serializers/basic-query-test.js | 4 +- src/serializers/comparisons-test.js | 5 +- src/serializers/comparisons.js | 53 ++++---- src/types/array-comparisons.js | 4 +- src/types/basic-query-filter-from-test.js | 6 +- src/types/basic-query-merge-test.js | 2 +- src/types/basic-query-sorting-test.js | 3 +- src/types/basic-query-test.js | 5 +- src/types/basic-query.js | 9 +- src/types/comparisons-common.js | 2 - src/types/comparisons-test.js | 25 ++-- src/types/comparisons.js | 126 ++++++------------ src/types/keys-and.js | 10 +- src/types/make-enum-test.js | 2 - src/types/make-maybe-test.js | 2 +- src/types/make-maybe.js | 8 +- src/types/make-real-number-range-inclusive.js | 4 +- src/types/values-not.js | 4 +- src/types/values-or-test.js | 3 - test/maybe-type-test.js | 10 +- test/special-comparison-logic-test.js | 4 +- 26 files changed, 137 insertions(+), 193 deletions(-) diff --git a/compat/compat.js b/compat/compat.js index 77d9fed..c98b4ca 100644 --- a/compat/compat.js +++ b/compat/compat.js @@ -76,7 +76,7 @@ var set = { if(mutators[prop]) { mutators[prop].push(value[prop]); } else { - throw new Error("can-query-logic: This type of configuration is not supported. Please use can-query-logic directly.") + throw new Error("can-query-logic: This type of configuration is not supported. Please use can-query-logic directly."); } } @@ -123,7 +123,7 @@ var set = { var filter = data.filter || {}; if(hasKey(filter, { "$ne": true, - "$in": function(val){ return val["$in"]; } + "$in": function(val){ return val.$in; } })) { return SET.UNDEFINABLE; } @@ -167,7 +167,7 @@ var set = { return query; } } - } + }; }, props: { diff --git a/compat/prop_tests/sort_test.js b/compat/prop_tests/sort_test.js index ae9a601..70c8535 100644 --- a/compat/prop_tests/sort_test.js +++ b/compat/prop_tests/sort_test.js @@ -141,12 +141,12 @@ QUnit.test('set.isSubset with range', function(assert) { // same // right // left - var addSort = function(set, value){ + var addSort = function(set, value) { set.sort = value; }; var sort = { - left: function(setA, setB) { + left: function(setA) { addSort(setA, "prop"); }, right: function(setA, setB) { @@ -167,46 +167,46 @@ QUnit.test('set.isSubset with range', function(assert) { }; var range = { - left: function(setA,setB){ + left: function(setA) { addRange(setA, 0,9); }, - right: function(setA,setB){ + right: function(setA,setB) { addRange(setB, 0,9); }, - same: function(setA,setB){ + same: function(setA,setB) { addRange(setA, 0,9); addRange(setB, 0,9); }, - superLeft: function(setA,setB){ + superLeft: function(setA,setB) { addRange(setA, 0,9); addRange(setB, 3,7); }, - superRight: function(setA,setB){ + superRight: function(setA,setB) { addRange(setB, 0,9); addRange(setA, 3,7); } }; var sets = { - same: function(setA, setB){ }, - superLeft: function(setA, setB){ + same: function() { }, + superLeft: function(setA, setB) { setB.type = "apples"; }, - superRight: function(setA, setB){ + superRight: function(setA) { setA.type = "apples"; } }; - var make = function(){ + var make = function() { var setA = {}, setB = {}; - canReflect.eachIndex(arguments, function(method){ + canReflect.eachIndex(arguments, function(method) { method(setA, setB); }); return {left: setA, right: setB}; }; - var assertSubset = function(methods, result){ + var assertSubset = function(methods, result) { var sets = make.apply(null, methods); assert.equal( algebra.isSubset(sets.left, sets.right), result, JSON.stringify(sets.left)+" ⊂ "+JSON.stringify(sets.right)+" = "+result ); }; diff --git a/doc/examples/date-string-example.js b/doc/examples/date-string-example.js index 7d7a241..bafabe0 100644 --- a/doc/examples/date-string-example.js +++ b/doc/examples/date-string-example.js @@ -1,4 +1,4 @@ -import {DefineMap, QueryLogic, Reflect as canReflect} from "can"; +import {DefineMap, QueryLogic } from "can"; class DateStringSet { constructor(value){ diff --git a/doc/examples/searchable-todo-example.js b/doc/examples/searchable-todo-example.js index 7744af7..b255507 100644 --- a/doc/examples/searchable-todo-example.js +++ b/doc/examples/searchable-todo-example.js @@ -96,5 +96,4 @@ const result = queryLogic.filterMembers({ filter: {name: "important"} }, todos); -console.log( todos ); //->[{id: 1, name: "important meeting"},{id: 3, name: "find out what important means"}] - +console.log( result ); //->[{id: 1, name: "important meeting"},{id: 3, name: "find out what important means"}] diff --git a/package.json b/package.json index 78e2d89..b7f3514 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "postpublish": "git push --tags && git push", "testee": "testee test.html --browsers firefox", "test": "npm run jshint && npm run testee", - "jshint": "jshint ./*.js src/**.js --config", + "jshint": "jshint --config .jshintrc --exclude ./node_modules,./dist .", "release:patch": "npm version patch && npm publish", "release:minor": "npm version minor && npm publish", "release:major": "npm version major && npm publish", diff --git a/src/serializers/basic-query-test.js b/src/serializers/basic-query-test.js index 30eb9bb..986f580 100644 --- a/src/serializers/basic-query-test.js +++ b/src/serializers/basic-query-test.js @@ -54,7 +54,7 @@ QUnit.test("nested properties", function(assert) { QUnit.test("$or with the same types unify into maybe", function(assert) { - var MaybeSet = makeMaybe([null]) + var MaybeSet = makeMaybe([null]); var converter = makeBasicQueryConvert({ identity: ["id"], @@ -222,7 +222,7 @@ QUnit.test("basicquery with no sort", function(assert) { }); var basicQuery = converter.hydrate(query); - var objs = [{id: 0}, {id: 2}] + var objs = [{id: 0}, {id: 2}]; var item = {id: 1}; var res = basicQuery.index(item, objs); diff --git a/src/serializers/comparisons-test.js b/src/serializers/comparisons-test.js index 35034fb..a76cdbb 100644 --- a/src/serializers/comparisons-test.js +++ b/src/serializers/comparisons-test.js @@ -1,7 +1,6 @@ var QUnit = require("steal-qunit"); var comparisons = require("./comparisons"); var canReflect = require("can-reflect"); -var is = require("../types/comparisons"); var ValuesNot = require("../types/values-not"); QUnit.module("can-query-logic/serializers/comparisons"); @@ -15,7 +14,7 @@ QUnit.test("hydrate and serialize with custom types that work with operators", f "can.serialize": function(){ return this.value; } - }) + }); var hydrated = comparisons.hydrate({$in: [1,2]}, function(value){ return new Type(value); @@ -37,7 +36,7 @@ QUnit.test("unknown hydrator is called in all cases", function(assert) { var hydrated = []; var addToHydrated = function(value){ hydrated.push(value); - } + }; comparisons.hydrate({$in: [1,2]}, addToHydrated); comparisons.hydrate("abc", addToHydrated); diff --git a/src/serializers/comparisons.js b/src/serializers/comparisons.js index ecc1a21..c497cbe 100644 --- a/src/serializers/comparisons.js +++ b/src/serializers/comparisons.js @@ -2,10 +2,9 @@ var is = require("../types/comparisons"); var Serializer = require("../serializer"); var canReflect = require("can-reflect"); var ValuesNot = require("../types/values-not"); -var ValuesAnd = require("../types/values-and"); function makeNew(Constructor) { - return function(value){ + return function(value) { return new Constructor(value); }; } @@ -24,7 +23,7 @@ function addHydrateFromValues(key, hydrate) { hydrateMap[key] = function(value, unknownHydrator) { var clones = value[key]; if(unknownHydrator) { - clones = clones.map(function(value){ + clones = clones.map(function(value) { return unknownHydrator(value); }); } @@ -37,10 +36,10 @@ function addHydrateFromValues(key, hydrate) { } // https://docs.mongodb.com/manual/reference/operator/query-comparison/ -addHydrateFrom("$eq", function(value){ +addHydrateFrom("$eq", function(value) { return new is.In([value]); }); -addHydrateFrom("$ne", function(value){ +addHydrateFrom("$ne", function(value) { return new is.NotIn([value]); }); @@ -63,9 +62,9 @@ var oppositeTypeMap = { NotIn: { Type: is.In, prop: "values" } }; -hydrateMap["$not"] = function(value, unknownHydrator) { +hydrateMap.$not = function(value, unknownHydrator) { // Many nots can be hydrated to their opposite. - var hydratedValue = hydrateValue(value["$not"], unknownHydrator); + var hydratedValue = hydrateValue(value.$not, unknownHydrator); var typeName = hydratedValue.constructor.name; if(oppositeTypeMap[typeName]) { @@ -83,54 +82,58 @@ addHydrateFromValues("$nin", makeNew(is.NotIn)); var serializer = new Serializer([ - [is.In,function(isIn, serialize){ + [is.In,function(isIn, serialize) { return isIn.values.length === 1 ? serialize(isIn.values[0]) : {$in: isIn.values.map(serialize)}; }], - [is.NotIn,function(notIn, serialize){ + [is.NotIn,function(notIn, serialize) { return notIn.values.length === 1 ? {$ne: serialize(notIn.values[0])} : {$nin: notIn.values.map(serialize)}; }], - [is.GreaterThan, function(gt, serialize){ return {$gt: serialize(gt.value) }; }], - [is.GreaterThanEqual, function(gte, serialize){ return {$gte: serialize(gte.value) }; }], - [is.LessThan, function(lt, serialize){ return {$lt: serialize(lt.value) }; }], - [is.LessThanEqual, function(lt, serialize){ return {$lte: serialize(lt.value) }; }], - [is.And, function(and, serialize){ + [is.GreaterThan, function(gt, serialize) { return {$gt: serialize(gt.value) }; }], + [is.GreaterThanEqual, function(gte, serialize) { return {$gte: serialize(gte.value) }; }], + [is.LessThan, function(lt, serialize) { return {$lt: serialize(lt.value) }; }], + [is.LessThanEqual, function(lt, serialize) { return {$lte: serialize(lt.value) }; }], + [is.And, function(and, serialize) { var obj = {}; - and.values.forEach(function(clause){ + and.values.forEach(function(clause) { canReflect.assignMap(obj, serialize(clause) ); }); return obj; }], - [is.All, function(all, serialize) { return {$all: serialize(all.values)}}] - /*[is.Or, function(or, serialize){ + [is.All, function(all, serialize) { return { - $or: or.values.map(function(value){ + $all: serialize(all.values) + }; + }] + /*[is.Or, function(or, serialize) { + return { + $or: or.values.map(function(value) { return serialize(value, serialize); }) }; }]*/ ]); -function hydrateValue(value, hydrateUnknown){ +function hydrateValue(value, hydrateUnknown) { if(!hydrateUnknown) { - hydrateUnknown = function(){ + hydrateUnknown = function() { throw new Error("can-query-logic doesn't recognize operator: "+JSON.stringify(value)); - } + }; } if(Array.isArray(value)) { - return new is.In(value.map(function(value){ + return new is.In(value.map(function(value) { return hydrateUnknown(value); })); } else if(value && typeof value === "object") { var keys = Object.keys(value); - var allKeysAreComparisons = keys.every(function(key){ - return hydrateMap[key] + var allKeysAreComparisons = keys.every(function(key) { + return hydrateMap[key]; }); if(allKeysAreComparisons) { - var andClauses = keys.map(function(key){ + var andClauses = keys.map(function(key) { var part = {}; part[key] = value[key]; var hydrator = hydrateMap[key]; diff --git a/src/types/array-comparisons.js b/src/types/array-comparisons.js index b22d73f..7da311e 100644 --- a/src/types/array-comparisons.js +++ b/src/types/array-comparisons.js @@ -24,7 +24,7 @@ comparisons.All.test = function(allValues, recordValues) { function makeThrowCannotCompare(type, left, right) { return function() { throw new Error("can-query-logic: Cannot perform " + type + " between " + left + " and " + right); - } + }; } function throwComparatorAllTypes(type1, type2) { @@ -73,7 +73,7 @@ var comparators = { And_All: throwComparatorAllTypes("And", "All"), All_Or: throwComparatorDifference("All", "Or"), Or_All: throwComparatorAllTypes("Or", "All") -} +}; exports.comparisons = comparisons; exports.comparators = comparators; diff --git a/src/types/basic-query-filter-from-test.js b/src/types/basic-query-filter-from-test.js index be98764..40ffa7c 100644 --- a/src/types/basic-query-filter-from-test.js +++ b/src/types/basic-query-filter-from-test.js @@ -124,9 +124,11 @@ QUnit.test("returns undefined against incompatible set", function(assert) { var fromQuery = new BasicQuery({ filter: new BasicQuery.KeysAnd({ type: 'critical' }) }); + var res; try{ - var res = query.filterFrom(items, fromQuery); + res = query.filterFrom(items, fromQuery); } catch(e) { - assert.ok(true, "throws an error") + assert.ok(true, "throws an error"); } + assert.notOk(res, "did not throw an error"); }); diff --git a/src/types/basic-query-merge-test.js b/src/types/basic-query-merge-test.js index 77171af..07f6ced 100644 --- a/src/types/basic-query-merge-test.js +++ b/src/types/basic-query-merge-test.js @@ -104,7 +104,7 @@ QUnit.test("unionMembers filters for uniqueness", function(assert) { assert.deepEqual(union, unionItems); // BREAK - var union = b.merge(a,bItems,aItems, getId ); + union = b.merge(a,bItems,aItems, getId ); assert.deepEqual(union, unionItems); }); diff --git a/src/types/basic-query-sorting-test.js b/src/types/basic-query-sorting-test.js index c492794..c3ea742 100644 --- a/src/types/basic-query-sorting-test.js +++ b/src/types/basic-query-sorting-test.js @@ -235,9 +235,8 @@ QUnit.test('rangeInclusive legacyUnion', function(assert) { * * X U Y = X */ - res = legacyUnion({}, { start: 0, end: 10 }); + var res = legacyUnion({}, { start: 0, end: 10 }); assert.deepEqual(res, {}, "universal set"); - return; /* * X = [A100, ..., A199] * Y = [A200, ..., A299] diff --git a/src/types/basic-query-test.js b/src/types/basic-query-test.js index 2f1204b..72bda30 100644 --- a/src/types/basic-query-test.js +++ b/src/types/basic-query-test.js @@ -1,5 +1,4 @@ var BasicQuery = require("./basic-query"); -var canSymbol = require("can-symbol"); var QUnit = require("steal-qunit"); var KeysAnd = require("./keys-and"); var ValuesAnd = require("./values-and"); @@ -9,7 +8,7 @@ QUnit.module("can-query-logic/types/basic-query filterMembersAndGetCount"); QUnit.test("Able to filter on a universal set", function(assert) { var parent = new BasicQuery({ filter: new KeysAnd({}) - }) + }); var bData = [{},{}]; var FooType = function(value) { this.value = value; }; @@ -30,7 +29,7 @@ QUnit.test("Able to filter on a universal set", function(assert) { QUnit.test("Page is a universal set", function(assert) { var parent = new BasicQuery({ filter: new KeysAnd({}) - }) + }); var bData = [{},{}]; var FooType = function(value) { this.value = value; }; diff --git a/src/types/basic-query.js b/src/types/basic-query.js index 99a465b..977a95a 100644 --- a/src/types/basic-query.js +++ b/src/types/basic-query.js @@ -5,8 +5,6 @@ var canReflect = require("can-reflect"); var andOrNot = require("./and-or-not"); var helpers = require("../helpers"); var defineLazyValue = require("can-define-lazy-value"); -var canSymbol = require("can-symbol"); -var isMemberSymbol = canSymbol.for("can.isMember"); // TYPES FOR FILTERING var KeysAnd = andOrNot.KeysAnd, @@ -69,7 +67,7 @@ function makeSort(schema, hydrateAndValue) { $eq: valueA }, key, schemaProp, helpers.valueHydrator); - return $gt[isMemberSymbol](hydratedIn.values[0]);*/ + return $gt[require("can-symbol").for("can.isMember")](hydratedIn.values[0]);*/ }, $lt: function(valueA, valueB) { if(valueA == null || valueB == null) { @@ -94,7 +92,7 @@ function makeSort(schema, hydrateAndValue) { $eq: valueA }, key, schemaProp, helpers.valueHydrator); - return $lt[isMemberSymbol](hydratedValue);*/ + return $lt[require("can-symbol").for("can.isMember")](hydratedValue);*/ /* // This doesn't work because of maybe types. @@ -102,7 +100,7 @@ function makeSort(schema, hydrateAndValue) { $eq: valueA }, key, schemaProp, helpers.valueHydrator); - return $lt[isMemberSymbol](hydratedIn.values[0]); */ + return $lt[require("can-symbol").for("can.isMember")](hydratedIn.values[0]); */ } }; }); @@ -477,6 +475,7 @@ set.defineComparison(BasicQuery, BasicQuery, { } + break; case "page": case "filter": { diff --git a/src/types/comparisons-common.js b/src/types/comparisons-common.js index 0e22b08..c01a049 100644 --- a/src/types/comparisons-common.js +++ b/src/types/comparisons-common.js @@ -1,5 +1,3 @@ -var set = require("../set"); - function isMemberThatUsesTestOnValues(value) { return this.constructor.test(this.values, value); } diff --git a/src/types/comparisons-test.js b/src/types/comparisons-test.js index 9ffbb93..8f89de0 100644 --- a/src/types/comparisons-test.js +++ b/src/types/comparisons-test.js @@ -3,7 +3,7 @@ var set = require("../set"); var is = compare; var ValuesNot = require("./values-not"); -QUnit.module("can-query-logic/types/comparisons") +QUnit.module("can-query-logic/types/comparisons"); var tests = { // In @@ -3375,9 +3375,8 @@ var tests = { }, And_Or: { union: function(assert) { - var a, b; - a = new is.Or([new is.LessThanEqual(0), new is.GreaterThanEqual(6)]), - b = new is.And([new is.GreaterThan(0), new is.LessThan(6)]); + var a = new is.Or([new is.LessThanEqual(0), new is.GreaterThanEqual(6)]); + var b = new is.And([new is.GreaterThan(0), new is.LessThan(6)]); assert.deepEqual( set.union(a, b), @@ -3853,7 +3852,7 @@ var tests = { assert.deepEqual( set.union(a, b), new is.Or([new is.All(["a"]), new is.All(["b"])]) - ) + ); } }, In_All: { @@ -3903,7 +3902,7 @@ var tests = { var b = new is.All(["b"]); assert.throws(function() { set.union(b, a); - }, ); + }, "unable to compare"); } }, And_All: { @@ -3912,7 +3911,7 @@ var tests = { var a = new is.And([{a:"b"}]); var b = new is.All(["b"]); assert.throws(function() { - set.union(a, b) + set.union(a, b); }, "unable to compare"); }, difference: function(assert) { @@ -3920,7 +3919,7 @@ var tests = { var a = new is.And([{a:"b"}]); var b = new is.All(["b"]); assert.throws(function() { - set.difference(a, b) + set.difference(a, b); }, "unable to compare"); }, intersection: function(assert) { @@ -3928,7 +3927,7 @@ var tests = { var a = new is.And([{a:"b"}]); var b = new is.All(["b"]); assert.throws(function() { - set.intersection(a, b) + set.intersection(a, b); }, "unable to compare"); } }, @@ -3938,7 +3937,7 @@ var tests = { var a = new is.Or([{a:"b"}]); var b = new is.All(["b"]); assert.throws(function() { - set.union(a, b) + set.union(a, b); }, "unable to compare"); }, difference: function(assert) { @@ -3946,7 +3945,7 @@ var tests = { var a = new is.Or([{a:"b"}]); var b = new is.All(["b"]); assert.throws(function() { - set.difference(a, b) + set.difference(a, b); }, "unable to compare"); }, intersection: function(assert) { @@ -3954,7 +3953,7 @@ var tests = { var a = new is.Or([{a:"b"}]); var b = new is.All(["b"]); assert.throws(function() { - set.intersection(a, b) + set.intersection(a, b); }, "unable to compare"); } } @@ -4140,4 +4139,4 @@ QUnit.test("All on arrays", function(assert){ */ -}) +}); diff --git a/src/types/comparisons.js b/src/types/comparisons.js index bfc1fa1..8b13712 100644 --- a/src/types/comparisons.js +++ b/src/types/comparisons.js @@ -55,7 +55,7 @@ comparisons.Or.prototype.orValues = function() { comparisons.In.test = function(values, b) { return values.some(function(value) { - var values = set.ownAndMemberValue(value, b) + var values = set.ownAndMemberValue(value, b); return values.own === values.member; }); }; @@ -124,18 +124,18 @@ comparisons.Or.prototype.isMember = function(value) { return and.isMember(value); }); }; -Object.keys(comparisons).forEach(function(name){ +Object.keys(comparisons).forEach(function(name) { comparisons[name].prototype[isMemberSymbol] = comparisons[name].prototype.isMember; }); - +var is = comparisons; function makeNot(Type) { return { test: function(vA, vB) { return !Type.test(vA, vB); } - } + }; } @@ -150,13 +150,9 @@ function makeEnum(type, Type, emptyResult) { }; } -function isUniversal(aSet) { - return set.isEqual(set.UNIVERSAL, aSet); -} - function swapArgs(fn) { return function(a, b) { - return fn(b, a) + return fn(b, a); }; } @@ -214,31 +210,11 @@ function make_filterFirstValueAgainstSecond(Comparison, Type, defaultReturn) { }; } -function make_filterFirstValues(Comparison, Type, defaultReturn) { - return function(inSet, gt) { - var values = inSet.values.filter(function(value) { - return Comparison.test(value, gt.value); - }); - return values.length ? - new Type(values) : defaultReturn || set.EMPTY; - }; -} - var isMemberTest = { test: function isMemberTest(set, value) { return set.isMember(value); } }; -var returnTrue = { - test: function returnTrue() { - return true; - } -}; -var returnFalse = { - test: function returnFalse() { - return false; - } -}; function isOr(value) { return (value instanceof is.Or); @@ -256,23 +232,13 @@ function isAndOrOr(value) { // `value` - has a test function to check values // `with` - the type we use to combined with the "other" value. // `combinedUsing` - If there are values, how do we stick it together with `with` -function combineFilterFirstValues(options) { - return function(inSet, gt) { - var values = inSet.values.filter(function(value) { - return options.values.test(value, gt.value); - }); - var range = options.with ? new options.with(gt.value) : gt; - return values.length ? - options.combinedUsing([new options.arePut(values), range]) : range; - }; -} function combineFilterFirstValuesAgainstSecond(options) { return function(inSet, gt) { var values = inSet.values.filter(function(value) { return options.values.test(gt, value); }); - var range + var range; if (options.complement) { range = set.difference(set.UNIVERSAL, gt); } else if (options.with) { @@ -292,7 +258,7 @@ function makeOrUnless(Comparison, result) { } else { return makeOr([setA, setB]); } - } + }; } function makeAndUnless(Comparison, result) { @@ -302,7 +268,7 @@ function makeAndUnless(Comparison, result) { } else { return makeAnd([setA, setB]); } - } + }; } function makeComplementSecondArgIf(Comparison) { @@ -312,7 +278,7 @@ function makeComplementSecondArgIf(Comparison) { } else { return setA; } - } + }; } @@ -324,18 +290,16 @@ function makeOr(ors) { return comparisons.Or ? new comparisons.Or(ors) : set.UNDEFINABLE; } -var is = comparisons; - -function combineValueWithRangeCheck(inSet, rangeSet, RangeOrEqType){ +function combineValueWithRangeCheck(inSet, rangeSet, RangeOrEqType) { var gte = new RangeOrEqType(rangeSet.value); - var leftValues = inSet.values.filter(function(value){ + var leftValues = inSet.values.filter(function(value) { return !gte.isMember(value); }); - if(!leftValues.length) { + if (!leftValues.length) { return gte; } - if(leftValues.length < inSet.values.length) { + if (leftValues.length < inSet.values.length) { return makeOr([new is.In(leftValues), gte]); } else { return makeOr([inSet, rangeSet]); @@ -344,21 +308,21 @@ function combineValueWithRangeCheck(inSet, rangeSet, RangeOrEqType){ // This tries to unify In([1]) with GT(1) -> GTE(1) function makeOrWithInAndRange(inSet, rangeSet) { - if(rangeSet instanceof is.Or) { + if (rangeSet instanceof is.Or) { var firstResult = makeOrWithInAndRange(inSet, rangeSet.values[0]); - if( !(firstResult instanceof is.Or) ) { + if ( !(firstResult instanceof is.Or) ) { return set.union(firstResult, rangeSet.values[1]); } var secondResult = makeOrWithInAndRange(inSet, rangeSet.values[1]); - if( !(secondResult instanceof is.Or) ) { + if ( !(secondResult instanceof is.Or) ) { return set.union(secondResult, rangeSet.values[0]); } return makeOr([inSet, rangeSet]); } else { - if(rangeSet instanceof is.GreaterThan) { + if (rangeSet instanceof is.GreaterThan) { return combineValueWithRangeCheck(inSet, rangeSet, is.GreaterThanEqual); } - if(rangeSet instanceof is.LessThan) { + if (rangeSet instanceof is.LessThan) { return combineValueWithRangeCheck(inSet, rangeSet, is.LessThanEqual); } return makeOr([inSet, rangeSet]); @@ -369,7 +333,7 @@ var In_RANGE = { union: combineFilterFirstValuesAgainstSecond({ values: makeNot(isMemberTest), arePut: is.In, - combinedUsing: function(ors){ + combinedUsing: function(ors) { return makeOrWithInAndRange(ors[0], ors[1]); } }), @@ -398,7 +362,7 @@ var NotIn_RANGE = function() { combinedUsing: makeAnd, complement: true }) - } + }; }; var RANGE_NotIn = { difference: swapArgs(make_filterFirstValueAgainstSecond(isMemberTest, is.In, set.EMPTY)) @@ -508,18 +472,6 @@ var Or_RANGE = { } }; -function unknowable() { - return set.UNKNOWABLE; -} - -// I don't know anything... -var noNothing = { - union: unknowable, - difference: unknowable, - intersection: unknowable -}; - - var comparators = canReflect.assign(arrayComparisons.comparators, { // In In_In: { @@ -608,15 +560,15 @@ var comparators = canReflect.assign(arrayComparisons.comparators, { }, GreaterThan_LessThan: { - union: (function(){ + union: (function() { var makeOrUnlessLessThan = makeOrUnless(is.LessThan); - return function greaterThan_lessThan_union(a, b){ - if( comparisons.In.test([a.value], b.value) ) { + return function greaterThan_lessThan_union(a, b) { + if ( comparisons.In.test([a.value], b.value) ) { return new is.NotIn([a.value]); } else { return makeOrUnlessLessThan(a, b); } - } + }; })(), intersection: makeAndUnless(is.GreaterThan), difference: makeComplementSecondArgIf(is.LessThan) @@ -673,7 +625,7 @@ var comparators = canReflect.assign(arrayComparisons.comparators, { return function gte_lte_intersection(gte, lte) { var inSet = new is.In([gte.value]); if (inSet.isMember(lte.value)) { - return inSet + return inSet; } else { return makeAnd(gte, lte); } @@ -786,10 +738,14 @@ var comparators = canReflect.assign(arrayComparisons.comparators, { set.union(and1.values[0], and2.values[1]), set.union(and1.values[1], and2.values[0]) ]; - if(combo1.every(isUniversal)) { + if (combo1.every(function(aSet) { + return set.isEqual(set.UNIVERSAL, aSet); + })) { return set.intersection.apply(set, combo2); } - if(combo2.every(isUniversal)) { + if (combo2.every(function(aSet) { + return set.isEqual(set.UNIVERSAL, aSet); + })) { return set.intersection.apply(set, combo1); } return new is.Or([and1, and2]);*/ @@ -821,24 +777,24 @@ var comparators = canReflect.assign(arrayComparisons.comparators, { var d1 = set.difference(and1, and2.values[0]); var d2 = set.difference(and1, and2.values[1]); return set.union(d1, d2); - } + }; /* function getDiffIfPartnerIsEmptyAndOtherComboNotDisjoint(inOrderDiffs, reverseOrderDiffs, diffedAnd) { var diff; - if(inOrderDiffs[0] === set.EMPTY) { + if (inOrderDiffs[0] === set.EMPTY) { diff = inOrderDiffs[1]; } - if(inOrderDiffs[1] === set.EMPTY) { + if (inOrderDiffs[1] === set.EMPTY) { diff = inOrderDiffs[0]; } - if(diff) { + if (diff) { // check if a diff equals itself (and therefor is disjoint) - if(set.isEqual(diffedAnd.values[0], reverseOrderDiffs[0] ) ) { + if (set.isEqual(diffedAnd.values[0], reverseOrderDiffs[0] ) ) { // is disjoint return diffedAnd; } - if( set.isEqual(diffedAnd.values[1], reverseOrderDiffs[1] ) ) { + if ( set.isEqual(diffedAnd.values[1], reverseOrderDiffs[1] ) ) { return diffedAnd; } return diff; @@ -855,17 +811,17 @@ var comparators = canReflect.assign(arrayComparisons.comparators, { ]; var diff = getDiffIfPartnerIsEmptyAndOtherComboNotDisjoint(inOrderDiffs, reverseOrderDiffs, and1); - if(diff) { + if (diff) { return diff; } diff = getDiffIfPartnerIsEmptyAndOtherComboNotDisjoint(reverseOrderDiffs, inOrderDiffs, and1); - if(diff) { + if (diff) { return diff; } else { // if one is a double And ... that's the outer \\ inner - if(isAndOrOr(inOrderDiffs[0]) && isAndOrOr(inOrderDiffs[1])) { + if (isAndOrOr(inOrderDiffs[0]) && isAndOrOr(inOrderDiffs[1])) { return new is.Or([inOrderDiffs[0], inOrderDiffs[1]]); - } else if( isAndOrOr(reverseOrderDiffs[0]) && isAndOrOr(reverseOrderDiffs[1]) ) { + } else if ( isAndOrOr(reverseOrderDiffs[0]) && isAndOrOr(reverseOrderDiffs[1]) ) { return new is.Or([reverseOrderDiffs[0], reverseOrderDiffs[1]]); } return set.UNKNOWABLE; diff --git a/src/types/keys-and.js b/src/types/keys-and.js index 33e466d..d81ecfe 100644 --- a/src/types/keys-and.js +++ b/src/types/keys-and.js @@ -118,14 +118,14 @@ function difference(objA, objB) { sharedKeysAndValues[key] = valuesA[key]; } else { var intersection = set.intersection(valuesA[key], valuesB[key]); - var isProductable = intersection !== set.EMPTY + var isProductable = intersection !== set.EMPTY; if (isProductable) { productAbleKeysAndData[key] = { // Products with `difference U intersection` would be subtracted // from produts with `intersection` difference: difference, intersection: intersection - } + }; } else { disjointKeysAndValues[key] = valuesA[key]; } @@ -207,7 +207,7 @@ function difference(objA, objB) { }).filter(notEmpty); if (productAbleOr) { - ands.push(new KeysAnd(productAbleOr)) + ands.push(new KeysAnd(productAbleOr)); } // {c: "g"} @@ -228,7 +228,7 @@ function difference(objA, objB) { // {name: "Justin"} \\ {age: 35} -> {name: "Justin", age: NOT(35)} if (aOnlyKeys.length > 0 && bOnlyKeys.length > 0) { if (productAbleKeys.length) { - throw new Error("Can't handle any productable keys right now") + throw new Error("Can't handle any productable keys right now"); } // add everything in sA into the result: aOnlyKeys.forEach(function(key) { @@ -272,7 +272,7 @@ set.defineComparison(KeysAnd, KeysAnd, { diff.aAndBKeys.forEach(function(key) { if (!set.isEqual(objA.values[key], objB.values[key])) { - aAndBKeysThatAreNotEqual.push(key) + aAndBKeysThatAreNotEqual.push(key); } else { sameKeys[key] = objA.values[key]; } diff --git a/src/types/make-enum-test.js b/src/types/make-enum-test.js index b6dfb0e..3aec727 100644 --- a/src/types/make-enum-test.js +++ b/src/types/make-enum-test.js @@ -1,8 +1,6 @@ var QUnit = require("steal-qunit"); var makeEnum = require("./make-enum"); -var set = require("../set"); -var canReflect = require("can-reflect"); var canSymbol = require("can-symbol"); QUnit.module("can-query-logic/types/make-enum"); diff --git a/src/types/make-maybe-test.js b/src/types/make-maybe-test.js index ad8bc6e..fb55619 100644 --- a/src/types/make-maybe-test.js +++ b/src/types/make-maybe-test.js @@ -5,7 +5,7 @@ var is = require("./comparisons"); var set = require("../set"); var canReflect = require("can-reflect"); -QUnit.module("can-query-logic/types/make-maybe") +QUnit.module("can-query-logic/types/make-maybe"); function DateStringSet(value) { this.value = value; diff --git a/src/types/make-maybe.js b/src/types/make-maybe.js index 4bb5ea2..2751f49 100644 --- a/src/types/make-maybe.js +++ b/src/types/make-maybe.js @@ -113,7 +113,7 @@ function makeMaybe(inValues, makeChildType) { var rangeIsMember = this.range[isMemberSymbol] || this.range.isMember, enumIsMember = this.enum[isMemberSymbol] || this.enum.isMember; return rangeIsMember.apply(this.range, arguments) || enumIsMember.apply(this.enum, arguments); - } + }; @@ -186,7 +186,7 @@ function makeMaybe(inValues, makeChildType) { }); makeChildType = makeChildType || function(v) { return v; - } + }; Maybe.hydrate = function(value, childHydrate) { return new Maybe({ @@ -238,7 +238,7 @@ makeMaybe.makeMaybeSetTypes = function(Type) { } else { ComparisonSetType = function(value) { - this.value = canReflect.new(Type, value) + this.value = canReflect.new(Type, value); }; ComparisonSetType.prototype.valueOf = function() { return this.value; @@ -262,7 +262,7 @@ makeMaybe.makeMaybeSetTypes = function(Type) { return new ComparisonSetType(value); }), ComparisonSetType: ComparisonSetType - } + }; }; diff --git a/src/types/make-real-number-range-inclusive.js b/src/types/make-real-number-range-inclusive.js index ace05a4..e47425b 100644 --- a/src/types/make-real-number-range-inclusive.js +++ b/src/types/make-real-number-range-inclusive.js @@ -15,7 +15,7 @@ module.exports = function(min, max) { this.range = new is.And([ new is.GreaterThanEqual( this.start ), new is.LessThanEqual( this.end ) - ]) + ]); } var universeRange = new RealNumberRangeInclusive( min , max ); @@ -39,7 +39,7 @@ module.exports = function(min, max) { if(value instanceof is.LessThan) { values.end = value.value-1; } - }) + }); if("start" in values && "end" in values) { return new RealNumberRangeInclusive(values.start, values.end ); } diff --git a/src/types/values-not.js b/src/types/values-not.js index 2dca4ab..d8b2a9e 100644 --- a/src/types/values-not.js +++ b/src/types/values-not.js @@ -86,10 +86,10 @@ NotIdentity.prototype.isMember = function(value){ if(this.value && typeof this.value.isMember === "function") { return !this.value.isMember(value); } else { - var values = set.ownAndMemberValue(this.value, value) + var values = set.ownAndMemberValue(this.value, value); return values.own !== values.member; } -} +}; module.exports = keysLogic.Not = NotIdentity; diff --git a/src/types/values-or-test.js b/src/types/values-or-test.js index 1777b50..e69de29 100644 --- a/src/types/values-or-test.js +++ b/src/types/values-or-test.js @@ -1,3 +0,0 @@ -var ValuesOr = require("./values-or"); -var KeysAnd = require("./keys-and"); -var valueIs = require("./comparisons"); diff --git a/test/maybe-type-test.js b/test/maybe-type-test.js index ffa5c7f..2a03c2a 100644 --- a/test/maybe-type-test.js +++ b/test/maybe-type-test.js @@ -24,15 +24,13 @@ QUnit.test("basics", function(assert) { } }); - var res; - var todoQueryLogic = new QueryLogic({ keys: { age: MaybeNumber } }); /* - res = todoQueryLogic.difference( + var res = todoQueryLogic.difference( {}, {filter: {age: {$gt: 5}}}); @@ -116,8 +114,6 @@ QUnit.test("MaybeDate", function(assert) { "can.ComparisonSetType": DateStringSet }); - var res; - var todoQueryLogic = new QueryLogic({ keys: { due: MaybeDate @@ -126,7 +122,7 @@ QUnit.test("MaybeDate", function(assert) { /* var date1982_10_20 = new Date(1982,9,20).toString(); - res = todoQueryLogic.difference( + var res = todoQueryLogic.difference( {}, {filter: {due: {$gt: date1982_10_20}}}); @@ -186,7 +182,7 @@ QUnit.test("MaybeDate", function(assert) { id: 4, due: null } - ] + ]; var results = todoQueryLogic.filterMembers({ sort: "due" diff --git a/test/special-comparison-logic-test.js b/test/special-comparison-logic-test.js index e45df48..4ab8124 100644 --- a/test/special-comparison-logic-test.js +++ b/test/special-comparison-logic-test.js @@ -247,7 +247,7 @@ QUnit.test("value type", function(assert) { {id: 3, date: new Date(1983,9,20).toString()} ]); - var ids = result.map(function(item){ return item.id}); + var ids = result.map(function(item){ return item.id; }); assert.deepEqual(ids,[1,2,3,4], "sorted correctly"); var index = queryLogic.index({ @@ -261,7 +261,7 @@ QUnit.test("value type", function(assert) { ], {id: 4, date: new Date(2018,4,24).toString()}); //F - assert.equal(index, 4, "added at the end") + assert.equal(index, 4, "added at the end"); }); QUnit.test("sort a type that is similar to the member values (#31)", function(assert) { From 525686391f8ebb8d995646c9fc4c9732c006643e Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Sat, 14 Sep 2019 12:52:33 +0100 Subject: [PATCH 3/4] Fix the $not hydrator in IE This works around constructor names not being available in IE. Closes https://github.com/canjs/can-query-logic/issues/54 --- src/serializers/comparisons.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serializers/comparisons.js b/src/serializers/comparisons.js index c497cbe..3f40804 100644 --- a/src/serializers/comparisons.js +++ b/src/serializers/comparisons.js @@ -65,7 +65,7 @@ var oppositeTypeMap = { hydrateMap.$not = function(value, unknownHydrator) { // Many nots can be hydrated to their opposite. var hydratedValue = hydrateValue(value.$not, unknownHydrator); - var typeName = hydratedValue.constructor.name; + var typeName = hydratedValue.constructor.name || hydratedValue.constructor.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]; if(oppositeTypeMap[typeName]) { var options = oppositeTypeMap[typeName]; From 60a4109dfe8913f5ccce4df2f12598b4d1667f63 Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Mon, 16 Sep 2019 16:23:32 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Update=20based=20on=20Kevin=E2=80=99s=20fee?= =?UTF-8?q?dback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/canjs/can-query-logic/pull/55#pullrequestreview-288679246 --- doc/can-query-logic.md | 2 +- doc/examples/date-string-example.js | 2 +- doc/examples/recipe-example.js | 2 +- doc/examples/searchable-todo-example.js | 2 +- doc/prototype/identity-keys.md | 2 +- doc/static/makeEnum.md | 2 +- src/types/basic-query-filter-from-test.js | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/can-query-logic.md b/doc/can-query-logic.md index 048fb72..9448770 100644 --- a/doc/can-query-logic.md +++ b/doc/can-query-logic.md @@ -679,7 +679,7 @@ The following is a more complex query and what it gets hydrated to: ```js -import {QueryLogic, Reflect as canReflect} from "can"; +import {canReflect, QueryLogic} from "can"; //query const queryLogic = new QueryLogic({ filter: { diff --git a/doc/examples/date-string-example.js b/doc/examples/date-string-example.js index bafabe0..d72283c 100644 --- a/doc/examples/date-string-example.js +++ b/doc/examples/date-string-example.js @@ -1,4 +1,4 @@ -import {DefineMap, QueryLogic } from "can"; +import {DefineMap, QueryLogic} from "can"; class DateStringSet { constructor(value){ diff --git a/doc/examples/recipe-example.js b/doc/examples/recipe-example.js index 0469c0f..e9d35f1 100644 --- a/doc/examples/recipe-example.js +++ b/doc/examples/recipe-example.js @@ -1,4 +1,4 @@ -import {QueryLogic, Reflect as canReflect} from "can"; +import {canReflect, QueryLogic} from "can"; // Takes the value of `name` (ex: `"chicken"`) function SearchableStringSet(value) { diff --git a/doc/examples/searchable-todo-example.js b/doc/examples/searchable-todo-example.js index b255507..2d9007d 100644 --- a/doc/examples/searchable-todo-example.js +++ b/doc/examples/searchable-todo-example.js @@ -1,4 +1,4 @@ -import {DefineMap, QueryLogic, Reflect as canReflect} from "can"; +import {canReflect, DefineMap, QueryLogic} from "can"; // Takes the value of `name` (ex: `"chicken"`) function SearchableStringSet(value) { diff --git a/doc/prototype/identity-keys.md b/doc/prototype/identity-keys.md index c1db2b7..26f743a 100644 --- a/doc/prototype/identity-keys.md +++ b/doc/prototype/identity-keys.md @@ -37,7 +37,7 @@ Using [canReflect.getSchema().identity](can-reflect.getSchema.html): ```js -import {QueryLogic, Reflect as canReflect} from "can"; +import {canReflect, QueryLogic} from "can"; const queryLogic = new QueryLogic({ identity: ["_id"] diff --git a/doc/static/makeEnum.md b/doc/static/makeEnum.md index 0f49ea7..d0e5432 100644 --- a/doc/static/makeEnum.md +++ b/doc/static/makeEnum.md @@ -49,7 +49,7 @@ Create a schema type that represents a finite set of values. Instead of using `makeEnum`, an enum type can be defined the following: ```js -import {Reflect as canReflect} from "can"; +import {canReflect} from "can"; const Status = canReflect.assignSymbols({}, { "can.new": function(val){ diff --git a/src/types/basic-query-filter-from-test.js b/src/types/basic-query-filter-from-test.js index 40ffa7c..8398fc0 100644 --- a/src/types/basic-query-filter-from-test.js +++ b/src/types/basic-query-filter-from-test.js @@ -124,8 +124,8 @@ QUnit.test("returns undefined against incompatible set", function(assert) { var fromQuery = new BasicQuery({ filter: new BasicQuery.KeysAnd({ type: 'critical' }) }); - var res; - try{ + var res; + try { res = query.filterFrom(items, fromQuery); } catch(e) { assert.ok(true, "throws an error");