summaryrefslogtreecommitdiff
path: root/skunk_shared.js
blob: a6c7958ea8dda1c1776f9221e0760ca51db6c7a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";

const SharedSkunkState = (function() {
    // String Catalog
    const kStringCatalog = [
        "foo",
        "bar",
        "baz",
        "qux",
        "quux",
        "corge",
        "grault",
        "garply",
        "waldo",
        "fred",
        "plugh",
        "xyzzy",
        "thud"
    ];

    // Maximum value for the integer fields, minimum is 0
    const kMaxInt = 20;

    const kTemplateDoc = {
        field1: "",
        field2: "",
        field3: "",
        field4: 1,
        attributes: {
            attr1: "",
            attr2: "",
            attr3: 1,
            attr4: 1,
            attr5: 1,
            attr6: 1,
            attr7: 1,
            attr8: "",
            attr9: "",
            attr10: ""
        }
    };

    const kAttributeTemplateDoc = {
        field1: "",
        field2: "",
        field3: "",
        field4: 1,
        attributes: [
            {k: "attr1", v: ""},
            {k: "attr2", v: ""},
            {k: "attr3", v: 1},
            {k: "attr4", v: 1},
            {k: "attr5", v: 1},
            {k: "attr6", v: 1},
            {k: "attr7", v: 1},
            {k: "attr8", v: ""},
            {k: "attr9", v: ""},
            {k: "attr10", v: ""},
        ]
    };

    const kEqualityQueryTemplate = {
        "field1": "",
        "field2": "",
        "field3": "",
        "attributes": {
            "attr1": "",
            "attr2": "",
            "attr3": 1,
            "attr4": 1,
            "attr5": 1,
            "attr6": 1,
            "attr7": 1,
            "attr8": "",
            "attr9": "",
            "attr10": ""
        }
    };

    // name of the attrbiute field
    const kAttributesField = "attributes";

    const kAttributesToQuery = 10;

    /**
     * Generates a random dictated by the type of 'exampleValue'.
     */
    function getRandomValue(exampleValue) {
        switch (typeof exampleValue) {
            case "number":
                return Random.randInt(kMaxInt);

            case "boolean":
                return Random.randInt() % 2 == 0;

            case "object":
                if (exampleValue == null) {
                    return null
                }
                if (exampleValue instanceof Date) {
                    return new Date(kBaseDate.getTime() + (Random.rand() * kMaximumSeconds));
                }
                throw Error("Unknown type");

            case "string":
                return kStringCatalog[Random.randInt(kStringCatalog.length)];
        }
        throw Error("Unknown type");
    }

    // Randomness generator
    Random.setRandomSeed();
    return {
        getRandomValue: getRandomValue,
        kTemplateDoc: kTemplateDoc,
        kAttributeTemplateDoc: kAttributeTemplateDoc,
        kAttributesField: kAttributesField,
    };
})();

/*
let query = {
    "$and": [
        {"field1": "qux"},
        {"field2": "waldo"},
        {"field3": "baz"},
        {"attributes": {"$elemMatch": {"k": "attr4", "v": 5}}},
        {"attributes": {"$elemMatch": {"k": "attr7", "v": 13}}}
    ]
};
*/